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

Function bthread_sem_trywait

src/bthread/semaphore.cpp:33–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31extern void submit_contention(const bthread_contention_site_t& csite, int64_t now_ns);
32
33static inline int bthread_sem_trywait(bthread_sem_t* sema) {
34 auto whole = (butil::atomic<unsigned>*)sema->butex;
35 while (true) {
36 unsigned num = whole->load(butil::memory_order_relaxed);
37 if (num == 0) {
38 return EAGAIN;
39 }
40 if (whole->compare_exchange_weak(num, num - 1,
41 butil::memory_order_acquire,
42 butil::memory_order_relaxed)) {
43 return 0;
44 }
45 }
46
47}
48
49static int bthread_sem_wait_impl(bthread_sem_t* sem, const struct timespec* abstime) {
50 bool queue_lifo = false;

Callers 3

do_trywaitFunction · 0.85
TESTFunction · 0.85
rwlock.cppFile · 0.85

Calls 2

loadMethod · 0.45
compare_exchange_weakMethod · 0.45

Tested by 2

do_trywaitFunction · 0.68
TESTFunction · 0.68