This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 249bc514 Make bthread semaphore and rwlock noncopyable (#2773)
249bc514 is described below

commit 249bc514b2e7d0cb4015fea9aaec98efbd9ec962
Author: Bright Chen <chenguangmin...@foxmail.com>
AuthorDate: Mon Oct 7 14:52:20 2024 +0800

    Make bthread semaphore and rwlock noncopyable (#2773)
---
 src/bthread/types.h | 15 ++++++++++++---
 test/BUILD.bazel    |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/bthread/types.h b/src/bthread/types.h
index d177ea72..ff99bb1c 100644
--- a/src/bthread/types.h
+++ b/src/bthread/types.h
@@ -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;
diff --git a/test/BUILD.bazel b/test/BUILD.bazel
index b8c3b3d2..7f49fe71 100644
--- a/test/BUILD.bazel
+++ b/test/BUILD.bazel
@@ -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": [


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to