|
|
|
@ -30,7 +30,6 @@ ctor(void * _this, va_list * params) |
|
|
|
long psize = sysconf(_SC_PAGESIZE); |
|
|
|
size_t size; |
|
|
|
int shm; |
|
|
|
void * shm_addr; |
|
|
|
|
|
|
|
this->shm_name = malloc(strlen(shm_name) + 1); |
|
|
|
strcpy(this->shm_name, shm_name); |
|
|
|
@ -52,25 +51,24 @@ ctor(void * _this, va_list * params) |
|
|
|
ftruncate(shm, this->bsize); |
|
|
|
} |
|
|
|
|
|
|
|
shm_addr = mmap (0, this->bsize<<1, |
|
|
|
PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
|
|
|
if (shm_addr == MAP_FAILED) |
|
|
|
break; |
|
|
|
|
|
|
|
munmap(shm_addr, this->bsize<<1); |
|
|
|
|
|
|
|
this->buffer = mmap (shm_addr, this->bsize, |
|
|
|
this->buffer = mmap (0, this->bsize<<1, |
|
|
|
PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
|
|
|
if (this->buffer == MAP_FAILED) { |
|
|
|
shm_addr = NULL; |
|
|
|
this->buffer = NULL; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
this->mirror = mmap (shm_addr + this->bsize, this->bsize, |
|
|
|
this->mirror = mmap (this->buffer + this->bsize, this->bsize, |
|
|
|
PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
|
|
|
if (this->mirror != shm_addr + this->bsize) { |
|
|
|
shm_addr = NULL; |
|
|
|
break; |
|
|
|
if (this->mirror != this->buffer + this->bsize) { |
|
|
|
if (this->mirror == this->buffer - this->bsize) { |
|
|
|
this->buffer = this->mirror; |
|
|
|
this->mirror += this->bsize; |
|
|
|
} |
|
|
|
else { |
|
|
|
this->mirror = NULL; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
state = 1; |
|
|
|
@ -82,10 +80,6 @@ ctor(void * _this, va_list * params) |
|
|
|
} |
|
|
|
|
|
|
|
if (1 != state) { |
|
|
|
if (shm_addr) { |
|
|
|
munmap(shm_addr, this->bsize<<1); |
|
|
|
} |
|
|
|
|
|
|
|
dtor(this); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -100,12 +94,12 @@ dtor(void * _this) |
|
|
|
free(this->shm_name); |
|
|
|
} |
|
|
|
|
|
|
|
if (this->buffer) { |
|
|
|
if (NULL != this->buffer) { |
|
|
|
munmap(this->buffer, this->bsize); |
|
|
|
this->buffer = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
if (this->mirror) { |
|
|
|
if (NULL != this->mirror) { |
|
|
|
munmap(this->mirror, this->bsize); |
|
|
|
this->mirror = NULL; |
|
|
|
} |
|
|
|
|