mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
use atom inc for object id counter
This commit is contained in:
@@ -1135,15 +1135,18 @@ lobjectid(lua_State *L) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
time_t ti = time(NULL);
|
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[2] = (ti>>24) & 0xff;
|
||||||
oid[3] = (ti>>16) & 0xff;
|
oid[3] = (ti>>16) & 0xff;
|
||||||
oid[4] = (ti>>8) & 0xff;
|
oid[4] = (ti>>8) & 0xff;
|
||||||
oid[5] = ti & 0xff;
|
oid[5] = ti & 0xff;
|
||||||
memcpy(oid+6 , oid_header, 5);
|
memcpy(oid+6 , oid_header, 5);
|
||||||
oid[11] = (oid_counter>>16) & 0xff;
|
oid[11] = (id>>16) & 0xff;
|
||||||
oid[12] = (oid_counter>>8) & 0xff;
|
oid[12] = (id>>8) & 0xff;
|
||||||
oid[13] = oid_counter & 0xff;
|
oid[13] = id & 0xff;
|
||||||
++oid_counter;
|
|
||||||
}
|
}
|
||||||
lua_pushlstring( L, (const char *)oid, 14);
|
lua_pushlstring( L, (const char *)oid, 14);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user