| 31 | extern void submit_contention(const bthread_contention_site_t& csite, int64_t now_ns); |
| 32 | |
| 33 | static 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 | |
| 49 | static int bthread_sem_wait_impl(bthread_sem_t* sem, const struct timespec* abstime) { |
| 50 | bool queue_lifo = false; |