| 109 | } |
| 110 | |
| 111 | static inline int bthread_sem_post(bthread_sem_t* sem, size_t num) { |
| 112 | if (num > 0) { |
| 113 | unsigned n = ((butil::atomic<unsigned>*)sem->butex) |
| 114 | ->fetch_add(num, butil::memory_order_relaxed); |
| 115 | const size_t sampling_range = NULL != bthread::g_cp && sem->enable_csite ? |
| 116 | bvar::is_collectable(&bthread::g_cp_sl) : bvar::INVALID_SAMPLING_RANGE; |
| 117 | const int64_t start_ns = bvar::is_sampling_range_valid(sampling_range) ? |
| 118 | butil::cpuwide_time_ns() : -1; |
| 119 | bthread::butex_wake_n(sem->butex, n); |
| 120 | if (start_ns > 0) { |
| 121 | const int64_t end_ns = butil::cpuwide_time_ns(); |
| 122 | const bthread_contention_site_t csite{end_ns - start_ns, sampling_range}; |
| 123 | bthread::submit_contention(csite, end_ns); |
| 124 | } |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | } // namespace bthread |
| 130 | |