| 255 | } |
| 256 | |
| 257 | static inline int rwlock_unwrlock(bthread_rwlock_t* rwlock) { |
| 258 | rwlock->wlock_flag = false; |
| 259 | |
| 260 | // Announce to readers there is no active writer. |
| 261 | int reader_count = ((butil::atomic<int>*)&rwlock->reader_count)->fetch_add( |
| 262 | RWLockMaxReaders, butil::memory_order_release) + RWLockMaxReaders; |
| 263 | if (BAIDU_UNLIKELY(reader_count >= RWLockMaxReaders)) { |
| 264 | CHECK(false) << "rwlock_unwlock of unlocked rwlock"; |
| 265 | return EINVAL; |
| 266 | } |
| 267 | |
| 268 | bool is_valid = bthread::is_contention_site_valid(rwlock->writer_csite); |
| 269 | if (BAIDU_UNLIKELY(is_valid)) { |
| 270 | bthread_contention_site_t saved_csite = rwlock->writer_csite; |
| 271 | bthread::make_contention_site_invalid(&rwlock->writer_csite); |
| 272 | |
| 273 | const int64_t unlock_start_ns = butil::cpuwide_time_ns(); |
| 274 | rwlock_unwrlock_slow(rwlock, reader_count); |
| 275 | const int64_t unlock_end_ns = butil::cpuwide_time_ns(); |
| 276 | saved_csite.duration_ns += unlock_end_ns - unlock_start_ns; |
| 277 | bthread::submit_contention(saved_csite, unlock_end_ns); |
| 278 | } else { |
| 279 | rwlock_unwrlock_slow(rwlock, reader_count); |
| 280 | } |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static inline int rwlock_unlock(bthread_rwlock_t* rwlock) { |
| 286 | if (rwlock->wlock_flag) { |
no test coverage detected