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

Function rwlock_unwrlock

src/bthread/rwlock.cpp:257–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257static 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
285static inline int rwlock_unlock(bthread_rwlock_t* rwlock) {
286 if (rwlock->wlock_flag) {

Callers 1

rwlock_unlockFunction · 0.85

Calls 6

is_contention_site_validFunction · 0.85
cpuwide_time_nsFunction · 0.85
rwlock_unwrlock_slowFunction · 0.85
submit_contentionFunction · 0.85
fetch_addMethod · 0.80

Tested by

no test coverage detected