4 unsigned int Util::hashBinary(char *strVal
, int length
)
10 while (iter
!= length
)
13 hval
+= (unsigned int) *str
++;
14 g
= hval
& ((unsigned int) 0xf << (32 - 4));
17 hval
^= g
>> (32 - 8);
25 DbRetVal
GlobalUniqueID::create()
27 int key
= Conf::config
.getShmIDKey();
28 int id
= os::shm_create(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
30 printError(ErrOS
, "Unable to create shared memory");
33 ptr
= os::shm_attach(id
, NULL
, 0);
34 if ((void*)-1 == ptr
) {
35 printError(ErrOS
, "Unable to attach shared memory");
38 memset(ptr
, 0, MAX_UNIQUE_ID
*sizeof(int));
41 DbRetVal
GlobalUniqueID::open()
43 if (ptr
!= NULL
) return OK
;
44 int key
= Conf::config
.getShmIDKey();
45 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
47 printError(ErrOS
, "Unable to create shared memory");
49 ptr
= os::shm_attach(id
, NULL
, 0);
50 if ((void*)-1 == ptr
) {
51 printError(ErrOS
, "Unable to create shared memory");
56 DbRetVal
GlobalUniqueID::destroy()
58 int key
= Conf::config
.getShmIDKey();
59 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
61 printError(ErrOS
, "Unable to open shared memory");
64 os::shmctl(id
, IPC_RMID
);
67 int GlobalUniqueID::getID(UniqueIDType type
)
69 int *id
= (int*)(((char*)ptr
) + sizeof(int) * type
);
71 int newVal
= oldVal
+ 1;
72 int ret
= Mutex::CAS(id
, oldVal
, newVal
);