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

Function bthread_rwlock_init

src/bthread/rwlock.cpp:295–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293} // namespace bthread
294
295__BEGIN_DECLS
296
297int bthread_rwlock_init(bthread_rwlock_t* __restrict rwlock,
298 const bthread_rwlockattr_t* __restrict) {
299 int rc = bthread_sem_init(&rwlock->reader_sema, 0);
300 if (BAIDU_UNLIKELY(0 != rc)) {
301 return rc;
302 }
303 bthread_sem_disable_csite(&rwlock->reader_sema);
304 rc = bthread_sem_init(&rwlock->writer_sema, 0);
305 if (BAIDU_UNLIKELY(0 != rc)) {
306 bthread_sem_destroy(&rwlock->reader_sema);
307 return rc;
308 }
309 bthread_sem_disable_csite(&rwlock->writer_sema);
310
311 rwlock->reader_count = 0;
312 rwlock->reader_wait = 0;
313 rwlock->wlock_flag = false;
314
315 bthread_mutexattr_t attr;
316 bthread_mutexattr_init(&attr);
317 bthread_mutexattr_disable_csite(&attr);
318 rc = bthread_mutex_init(&rwlock->write_queue_mutex, &attr);
319 if (BAIDU_UNLIKELY(0 != rc)) {
320 bthread_sem_destroy(&rwlock->reader_sema);
321 bthread_sem_destroy(&rwlock->writer_sema);
322 return rc;
323 }
324 bthread_mutexattr_destroy(&attr);
325
326 bthread::make_contention_site_invalid(&rwlock->writer_csite);
327
328 return 0;
329}
330
331int bthread_rwlock_destroy(bthread_rwlock_t* rwlock) {
332 bthread_sem_destroy(&rwlock->reader_sema);

Callers 3

TESTFunction · 0.85
PerfTestFunction · 0.85
RWLockMethod · 0.85

Calls 8

bthread_sem_initFunction · 0.85
bthread_sem_destroyFunction · 0.85
bthread_mutexattr_initFunction · 0.85
bthread_mutex_initFunction · 0.85

Tested by 2

TESTFunction · 0.68
PerfTestFunction · 0.68