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

Function borrow_keytable

src/bthread/key.cpp:329–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327};
328
329KeyTable* borrow_keytable(bthread_keytable_pool_t* pool) {
330 if (pool != NULL && (pool->list || pool->free_keytables)) {
331 KeyTable* p;
332 pthread_rwlock_rdlock(&pool->rwlock);
333 auto list = (butil::ThreadLocal<bthread::KeyTableList>*)pool->list;
334 if (list) {
335 p = list->get()->remove_front();
336 if (p) {
337 pthread_rwlock_unlock(&pool->rwlock);
338 return p;
339 }
340 }
341 pthread_rwlock_unlock(&pool->rwlock);
342 if (pool->free_keytables) {
343 pthread_rwlock_wrlock(&pool->rwlock);
344 p = (KeyTable*)pool->free_keytables;
345 if (list) {
346 for (uint32_t i = 0; i < FLAGS_borrow_from_globle_size; ++i) {
347 if (p) {
348 pool->free_keytables = p->next;
349 list->get()->append(p);
350 p = (KeyTable*)pool->free_keytables;
351 --pool->size;
352 } else {
353 break;
354 }
355 }
356 KeyTable* result = list->get()->remove_front();
357 pthread_rwlock_unlock(&pool->rwlock);
358 return result;
359 } else {
360 if (p) {
361 pool->free_keytables = p->next;
362 pthread_rwlock_unlock(&pool->rwlock);
363 return p;
364 }
365 }
366 pthread_rwlock_unlock(&pool->rwlock);
367 }
368 }
369 return NULL;
370}
371
372// Referenced in task_group.cpp, must be extern.
373// Caller of this function must hold the KeyTable

Callers 2

borrow_thread_implFunction · 0.85
bthread_getspecificFunction · 0.85

Calls 2

getMethod · 0.45
appendMethod · 0.45

Tested by 1

borrow_thread_implFunction · 0.68