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);
31 printError(ErrOS
, "Unable to create shared memory");
34 ptr
= os::shm_attach(id
, NULL
, 0);
35 if ((void*)-1 == ptr
) {
36 printError(ErrOS
, "Unable to attach shared memory");
39 memset(ptr
, 0, MAX_UNIQUE_ID
*sizeof(int));
42 DbRetVal
GlobalUniqueID::open()
44 if (ptr
!= NULL
) return OK
;
45 int key
= Conf::config
.getShmIDKey();
46 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
48 printError(ErrOS
, "Unable to create shared memory");
50 ptr
= os::shm_attach(id
, NULL
, 0);
51 if ((void*)-1 == ptr
) {
52 printError(ErrOS
, "Unable to create shared memory");
57 DbRetVal
GlobalUniqueID::destroy()
59 int key
= Conf::config
.getShmIDKey();
60 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
62 // printError(ErrOS, "Unable to open shared memory");
65 os::shmctl(id
, IPC_RMID
);
68 int GlobalUniqueID::getID(UniqueIDType type
)
70 int *id
= (int*)(((char*)ptr
) + sizeof(int) * type
);
72 int newVal
= oldVal
+ 1;
73 int ret
= Mutex::CAS(id
, oldVal
, newVal
);