Skip to content

Commit

Permalink
Make bthread semaphore and rwlock noncopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright committed Sep 29, 2024
1 parent f17048e commit c0866b5
Showing 1 changed file with 12 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

0 comments on commit c0866b5

Please sign in to comment.