MCPcopy Create free account
hub / github.com/apache/brpc / id_create_impl

Function id_create_impl

src/bthread/id.cpp:325–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323const int ID_MAX_RANGE = 1024;
324
325static int id_create_impl(
326 bthread_id_t* id, void* data,
327 int (*on_error)(bthread_id_t, void*, int),
328 int (*on_error2)(bthread_id_t, void*, int, const std::string&)) {
329 IdResourceId slot;
330 Id* const meta = get_resource(&slot);
331 if (meta) {
332 meta->data = data;
333 meta->on_error = on_error;
334 meta->on_error2 = on_error2;
335 CHECK(meta->pending_q.empty());
336 uint32_t* butex = meta->butex;
337 if (0 == *butex || *butex + ID_MAX_RANGE + 2 < *butex) {
338 // Skip 0 so that bthread_id_t is never 0
339 // avoid overflow to make comparisons simpler.
340 *butex = 1;
341 }
342 *meta->join_butex = *butex;
343 meta->first_ver = *butex;
344 meta->locked_ver = *butex + 1;
345 *id = make_id(*butex, slot);
346 return 0;
347 }
348 return ENOMEM;
349}
350
351static int id_create_ranged_impl(
352 bthread_id_t* id, void* data,

Callers 2

bthread_id_createFunction · 0.85
bthread_id_create2Function · 0.85

Calls 3

make_idFunction · 0.70
get_resourceFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected