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

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


The following commit(s) were added to refs/heads/master by this push:
     new 43b1af7  mutex: throw system_error when constuctor failed and lock 
failed
     new 238d4a4  Merge pull request #651 from choleraehyq/master
43b1af7 is described below

commit 43b1af7228512f73c20be25e85411baebb940b15
Author: Cholerae Hu <cholerae...@gmail.com>
AuthorDate: Thu Feb 14 14:05:13 2019 +0800

    mutex: throw system_error when constuctor failed and lock failed
    
    Signed-off-by: Cholerae Hu <cholerae...@gmail.com>
---
 src/bthread/mutex.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/bthread/mutex.h b/src/bthread/mutex.h
index a1941aa..a1c8ec0 100644
--- a/src/bthread/mutex.h
+++ b/src/bthread/mutex.h
@@ -42,10 +42,20 @@ namespace bthread {
 class Mutex {
 public:
     typedef bthread_mutex_t* native_handler_type;
-    Mutex() { CHECK_EQ(0, bthread_mutex_init(&_mutex, NULL)); }
+    Mutex() {
+        int ec = bthread_mutex_init(&_mutex, NULL);
+        if (ec != 0) {
+            throw std::system_error(std::error_code(ec, 
std::system_category()), "Mutex constructor failed");
+        }
+    }
     ~Mutex() { CHECK_EQ(0, bthread_mutex_destroy(&_mutex)); }
     native_handler_type native_handler() { return &_mutex; }
-    void lock() { bthread_mutex_lock(&_mutex); }
+    void lock() {
+        int ec = bthread_mutex_lock(&_mutex);
+        if (ec != 0) {
+            throw std::system_error(std::error_code(ec, 
std::system_category()), "Mutex lock failed");
+        }
+    }
     void unlock() { bthread_mutex_unlock(&_mutex); }
     bool try_lock() { return !bthread_mutex_trylock(&_mutex); }
     // TODO(chenzhangyi01): Complement interfaces for C++11


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

Reply via email to