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 unsigned int Util::hashString(char *strVal
)
33 hval
+= (unsigned int) *str
++;
34 g
= hval
& ((unsigned int) 0xf << (32 - 4));
37 hval
^= g
>> (32 - 8);
44 DbRetVal
GlobalUniqueID::create()
46 int key
= Conf::config
.getShmIDKey();
47 int id
= os::shm_create(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
50 printError(ErrOS
, "Unable to create shared memory");
53 ptr
= os::shm_attach(id
, NULL
, 0);
54 if ((void*)-1 == ptr
) {
55 printError(ErrOS
, "Unable to attach shared memory");
58 memset(ptr
, 0, MAX_UNIQUE_ID
*sizeof(int));
61 DbRetVal
GlobalUniqueID::open()
63 if (ptr
!= NULL
) return OK
;
64 int key
= Conf::config
.getShmIDKey();
65 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
67 printError(ErrOS
, "Unable to create shared memory");
69 ptr
= os::shm_attach(id
, NULL
, 0);
70 if ((void*)-1 == ptr
) {
71 printError(ErrOS
, "Unable to create shared memory");
76 DbRetVal
GlobalUniqueID::destroy()
78 int key
= Conf::config
.getShmIDKey();
79 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
81 // printError(ErrOS, "Unable to open shared memory");
84 os::shmctl(id
, IPC_RMID
);
87 int GlobalUniqueID::getID(UniqueIDType type
)
89 InUse
*id
= (int*)(((char*)ptr
) + sizeof(int) * type
);
91 InUse newVal
= oldVal
+ 1;
92 int ret
= Mutex::CASGen(id
, oldVal
, newVal
);