Skip to content

Commit

Permalink
Make bthread semaphore and rwlock noncopyable (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright authored Oct 7, 2024
1 parent 2c74ab5 commit 249bc51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/bthread/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,26 @@ typedef struct bthread_cond_t {
typedef struct {
} bthread_condattr_t;

typedef struct {
typedef struct bthread_sem_t {
#if defined(__cplusplus)
bthread_sem_t() : butex(NULL), enable_csite(true) {}
DISALLOW_COPY_AND_ASSIGN(bthread_sem_t);
#endif
unsigned* butex;
bool enable_csite;
} bthread_sem_t;

typedef struct {
typedef struct bthread_rwlock_t {
#if defined(__cplusplus)
bthread_rwlock_t()
: reader_count(0), reader_wait(0), wlock_flag(false), writer_csite{} {}
DISALLOW_COPY_AND_ASSIGN(bthread_rwlock_t);
#endif
bthread_sem_t reader_sema; // Semaphore for readers to wait for completing writers.
bthread_sem_t writer_sema; // Semaphore for writers to wait for completing readers.
int reader_count; // Number of pending readers.
int reader_wait; // Number of departing readers.
bool wlock_flag; // Flag used to indicate that a write lock has been hold.
bool wlock_flag; // Flag used to indicate that a write lock has been held.
bthread_mutex_t write_queue_mutex; // Held if there are pending writers.
bthread_contention_site_t writer_csite;
} bthread_rwlock_t;
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ TEST_BUTIL_SOURCES = [
#"popen_unittest.cpp",
"bounded_queue_unittest.cc",
"butil_unittest_main.cpp",
"scope_guard_unittest.cc",
] + select({
"@bazel_tools//tools/osx:darwin_x86_64": [],
"//conditions:default": [
Expand Down

0 comments on commit 249bc51

Please sign in to comment.