use atom inc for object id counter

This commit is contained in:
Cloud Wu
2015-06-24 18:57:47 +08:00
parent f3536bfc53
commit 0fb2b21ed5

View File

@@ -1135,15 +1135,18 @@ lobjectid(lua_State *L) {
}
} else {
time_t ti = time(NULL);
uint32_t id = oid_counter;
// old_counter is a static var, use atom inc.
__sync_add_and_fetch(&oid_counter,1);
oid[2] = (ti>>24) & 0xff;
oid[3] = (ti>>16) & 0xff;
oid[4] = (ti>>8) & 0xff;
oid[5] = ti & 0xff;
memcpy(oid+6 , oid_header, 5);
oid[11] = (oid_counter>>16) & 0xff;
oid[12] = (oid_counter>>8) & 0xff;
oid[13] = oid_counter & 0xff;
++oid_counter;
oid[11] = (id>>16) & 0xff;
oid[12] = (id>>8) & 0xff;
oid[13] = id & 0xff;
}
lua_pushlstring( L, (const char *)oid, 14);