91int qshm_init(
const char *keyfile,
int keyid,
size_t size,
bool recreate) {
96 if (keyfile != NULL) {
97 semkey = ftok(keyfile, keyid);
101 semkey = IPC_PRIVATE;
105 if ((shmid = shmget(semkey, size, IPC_CREAT | IPC_EXCL | 0666)) == -1) {
106 if (recreate ==
false)
110 if ((shmid =
qshm_getid(keyfile, keyid)) >= 0)
112 if ((shmid = shmget(semkey, size, IPC_CREAT | IPC_EXCL | 0666)) == -1)
131 key_t semkey = ftok(keyfile, keyid);
136 if ((shmid = shmget(semkey, 0, 0)) == -1)
154 pShm = shmat(shmid, 0, 0);
155 if (pShm == (
void *) -1)
170 if (shmctl(shmid, IPC_RMID, 0) != 0)
void * qshm_get(int shmid)
Get a pointer of shared memory.
int qshm_init(const char *keyfile, int keyid, size_t size, bool recreate)
Initialize shared-memory.
int qshm_getid(const char *keyfile, int keyid)
Get shared memory identifier by keyfile and keyid for existing shared memory.
bool qshm_free(int shmid)
De-allocate shared memory.