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));
62 DbRetVal
GlobalUniqueID::open()
64 if (ptr
!= NULL
) return OK
;
65 int key
= Conf::config
.getShmIDKey();
66 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
68 printError(ErrOS
, "Unable to create shared memory");
70 ptr
= os::shm_attach(id
, NULL
, 0);
71 if ((void*)-1 == ptr
) {
72 printError(ErrOS
, "Unable to create shared memory");
77 DbRetVal
GlobalUniqueID::destroy()
79 int key
= Conf::config
.getShmIDKey();
80 int id
= os::shm_open(key
, MAX_UNIQUE_ID
*sizeof(int), 0666);
82 // printError(ErrOS, "Unable to open shared memory");
89 int GlobalUniqueID::getID(UniqueIDType type
)
91 InUse
*id
= (int*)(((char*)ptr
) + sizeof(int) * type
);
93 InUse newVal
= oldVal
+ 1;
94 int ret
= Mutex::CASGen(id
, oldVal
, newVal
);