|
|
|
@ -1,5 +1,6 @@ |
|
|
|
#define _POSIX_SOURCE |
|
|
|
#define _POSIX_C_SOURCE 200112L |
|
|
|
#define _GNU_SOURCE |
|
|
|
|
|
|
|
#include <sys/types.h> |
|
|
|
#include <sys/stat.h> |
|
|
|
@ -28,6 +29,7 @@ ctor(void * _this, va_list * params) |
|
|
|
long psize = sysconf(_SC_PAGESIZE); |
|
|
|
size_t size; |
|
|
|
int shm; |
|
|
|
char * data; |
|
|
|
|
|
|
|
this->shm_name = malloc(strlen(shm_name) + 7 + 2); |
|
|
|
sprintf(this->shm_name, "/%06d_%s", getpid(), shm_name); |
|
|
|
@ -51,25 +53,22 @@ ctor(void * _this, va_list * params) |
|
|
|
} |
|
|
|
|
|
|
|
this->data = mmap (0, this->bsize << 1, |
|
|
|
PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
|
|
|
PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
|
|
|
if (this->data == MAP_FAILED) { |
|
|
|
this->data = NULL; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
munmap(this->data + this->bsize, this->bsize); |
|
|
|
|
|
|
|
this->mirror = mmap (this->data + this->bsize, this->bsize, |
|
|
|
PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); |
|
|
|
if (this->mirror != this->data + this->bsize) { |
|
|
|
if (this->mirror == this->data - this->bsize) { |
|
|
|
this->data = this->mirror; |
|
|
|
this->mirror += this->bsize; |
|
|
|
} |
|
|
|
else { |
|
|
|
this->mirror = NULL; |
|
|
|
data = mmap (this->data, this->bsize, |
|
|
|
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0); |
|
|
|
if (data != this->data) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
data = mmap (this->data + this->bsize, this->bsize, |
|
|
|
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0); |
|
|
|
if (data != this->data + this->bsize) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
state = 1; |
|
|
|
@ -93,18 +92,14 @@ dtor(void * _this) |
|
|
|
|
|
|
|
if (NULL != this->shm_name) { |
|
|
|
free(this->shm_name); |
|
|
|
this->shm_name = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
if (NULL != this->data) { |
|
|
|
munmap(this->data, this->bsize); |
|
|
|
this->data = NULL; |
|
|
|
if (NULL != this->data && MAP_FAILED != this->data) { |
|
|
|
munmap(this->data, this->bsize << 1); |
|
|
|
} |
|
|
|
|
|
|
|
if (NULL != this->mirror) { |
|
|
|
munmap(this->mirror, this->bsize); |
|
|
|
this->mirror = NULL; |
|
|
|
} |
|
|
|
this->shm_name = NULL; |
|
|
|
this->data = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
INIT_IFACE(Class, ctor, dtor, NULL); |
|
|
|
|