24 #define _POSIX_C_SOURCE 200112L
27 #include <sys/types.h>
50 char * shm_name = va_arg(*params,
char*);
51 long psize = sysconf(_SC_PAGESIZE);
56 this->shm_name =
memMalloc(strlen(shm_name) + 7 + 2);
57 sprintf(this->shm_name,
"/%06d_%s", getpid(), shm_name);
63 size = va_arg(*params,
size_t);
64 size = (0 >=
size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize;
65 this->bsize = psize *
size;
68 shm = shm_open(this->shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
73 if (-1 == ftruncate(shm, this->bsize)) {
77 this->data = mmap (0, this->bsize << 1,
78 PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
79 if (this->data == MAP_FAILED) {
84 data = mmap (this->data, this->bsize,
85 PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0);
86 if (data != this->data) {
90 data = mmap (this->data + this->bsize, this->bsize,
91 PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0);
92 if (data != this->data + this->bsize) {
100 shm_unlink(this->shm_name);
115 if (NULL != this->
data && MAP_FAILED != this->
data) {
116 munmap(this->
data, this->bsize << 1);
CREATE_CLASS(Cbuf, NULL, IFACE(Class))
static void cbufDtor(void *)
INIT_IFACE(Class, cbufCtor, cbufDtor, NULL)
static int cbufCtor(void *_this, va_list *params)