32 #include <lib$routines.h> 58 int *cnt = (
int *) mutex;
64 volatile int *cnt = (
int *) mutex;
84 int *cnt = (
int *) mutex;
85 if(*cnt > 0) (*cnt)--;
96 name =
new char[strlen(shmname)+1];
98 _size = Size +
sizeof(*mutex);
101 fdlock = open(
name, O_RDWR | O_CREAT, rwmode );
106 sprintf(buf,
"could not write shm=%s\n",shmname);
107 ret =
::write(1,buf,strlen(buf));
108 if(ret < 0) exit(-1);
109 sprintf(buf,
"you have to run this program as root !!!\n");
110 ret =
::write(1,buf,strlen(buf));
111 if(ret < 0) exit(-1);
128 base_adr = (
char *) shmat(
id,NULL,0);
135 flock(fdlock,LOCK_UN);
139 int file_existed = 0;
140 long ret,fd,page_size,pagelets,pagelet_size,file_block_size,flags,item,ident[2];
143 struct dsc$descriptor_s section_name;
147 name =
new char[strlen(shmname)+1];
148 strcpy(
name,shmname);
149 _size = Size +
sizeof(*mutex);
151 file_block_size = 512;
153 item = SYI$_PAGE_SIZE;
154 ret = lib$getsyi( &item ,
163 section_name.dsc$w_length = strlen(
name);
164 section_name.dsc$a_pointer =
name;
165 section_name.dsc$b_dtype = DSC$K_DTYPE_T;
166 section_name.dsc$b_class = DSC$K_CLASS_S;
170 if(
_size % page_size == 0) pagelets =
_size / pagelet_size;
171 else pagelets = (
_size / page_size + 1) * (page_size / pagelet_size);
172 ret = sys$expreg(pagelets,&add_ret,0,0);
181 fab.fab$b_fac = fab.fab$b_fac | FAB$M_PUT | FAB$M_DEL | FAB$M_GET | FAB$M_UPD;
182 fab.fab$l_fna =
name;
183 fab.fab$b_fns = strlen(
name);
184 fab.fab$l_fop = fab.fab$l_fop
188 fab.fab$b_shr = fab.fab$b_shr
191 fab.fab$l_alq = pagelets * pagelet_size / file_block_size;
193 ret = sys$create (&fab);
194 if(ret != RMS$_NORMAL && ret != RMS$_CREATED)
210 flags = SEC$M_GBL | SEC$M_WRT | SEC$M_PERM;
212 ret = sys$crmpsc(&add_in ,&add_ret,
224 if(ret != SS$_NORMAL && ret != SS$_CREATED)
238 ret = sys$close(&fab);
240 if(file_existed == 0) myinit(
mutex);
248 name =
new char[strlen(shmname)+1];
249 strcpy(
name,shmname);
250 _size = Size +
sizeof(HANDLE);
254 GENERIC_READ | GENERIC_WRITE,
255 FILE_SHARE_READ | FILE_SHARE_WRITE,
258 FILE_ATTRIBUTE_NORMAL,
265 GENERIC_READ | GENERIC_WRITE,
266 FILE_SHARE_READ | FILE_SHARE_WRITE,
269 FILE_ATTRIBUTE_NORMAL,
283 hShmem = CreateFileMapping(
307 if(rwmode == 0)
return;
316 CloseHandle((HANDLE)
id);
317 CloseHandle((HANDLE)
shmkey);
318 #elif defined(RLUNIX) 319 if(fdlock >= 0) close(fdlock);
329 flock(fdlock,LOCK_UN);
330 shmctl(
id, IPC_RMID, &buf);
338 struct dsc$descriptor_s section_name;
343 section_name.dsc$w_length = strlen(
name);
344 section_name.dsc$a_pointer =
name;
345 section_name.dsc$b_dtype = DSC$K_DTYPE_T;
346 section_name.dsc$b_class = DSC$K_CLASS_S;
348 ret = sys$dgblsc(0,§ion_name,0);
349 if(ret != SS$_NORMAL)
return -1;
354 ret = sys$deltva(&add_in,&add_ret,0);
355 if(ret != SS$_NORMAL)
return -1;
365 CloseHandle((HANDLE)
id);
366 CloseHandle((HANDLE)
shmkey);
378 if(len <= 0)
return -1;
379 if(offset+len >
_size)
return -1;
383 #elif defined(RLUNIX) 384 flock(fdlock,LOCK_EX);
391 #elif defined(RLUNIX) 392 flock(fdlock,LOCK_UN);
403 if(len <= 0)
return -1;
404 if(offset+len >
_size)
return -1;
408 #elif defined(RLUNIX) 409 flock(fdlock,LOCK_EX);
416 #elif defined(RLUNIX) 417 flock(fdlock,LOCK_UN);
427 if(index < 0)
return -1;
428 read(offset+index*
sizeof(val),&val,
sizeof(val));
435 if(index < 0)
return -1;
436 read(offset+index*
sizeof(val),&val,
sizeof(val));
443 if(index < 0)
return -1;
444 read(offset+index*
sizeof(val),&val,
sizeof(val));
451 if(index < 0)
return -1;
452 read(offset+index*
sizeof(val),&val,
sizeof(val));
459 if(index < 0)
return -1;
460 ret =
write(offset+index*
sizeof(val),&val,
sizeof(val));
469 if(index < 0)
return -1;
470 val2 = (
short int) val;
471 ret =
write(offset+index*
sizeof(val2),&val2,
sizeof(val2));
478 if(index < 0)
return -1;
479 ret =
write(offset+index*
sizeof(val),&val,
sizeof(val));
486 if(index < 0)
return -1;
487 ret =
write(offset+index*
sizeof(val),&val,
sizeof(val));
int read(unsigned long offset, void *buf, int len)
int rlwthread_mutex_destroy(pthread_mutex_t *mptr)
virtual ~rlSharedMemory()
rlSharedMemory(const char *name, unsigned long size, int rwmode=0600)
float readFloat(unsigned long offset, int index)
int writeInt(unsigned long offset, int index, int val)
int readShort(unsigned long offset, int index)
int writeShort(unsigned long offset, int index, int val)
int writeFloat(unsigned long offset, int index, float val)
int readByte(unsigned long offset, int index)
int write(unsigned long offset, const void *buf, int len)
int writeByte(unsigned long offset, int index, unsigned char val)
int readInt(unsigned long offset, int index)
int rlwthread_sleep(long msec)