You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2017/05/31 16:45:16 UTC

[trafficserver] branch master updated: Add RAII support for ink_mutex.

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

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

The following commit(s) were added to refs/heads/master by this push:
       new  7dfa864   Add RAII support for ink_mutex.
7dfa864 is described below

commit 7dfa864ea7284826c345be007a8fc8ed278b9a2d
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Tue May 30 11:00:38 2017 -0500

    Add RAII support for ink_mutex.
---
 lib/ts/ink_mutex.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/ts/ink_mutex.h b/lib/ts/ink_mutex.h
index d58722e..d0cd7e9 100644
--- a/lib/ts/ink_mutex.h
+++ b/lib/ts/ink_mutex.h
@@ -68,4 +68,27 @@ ink_mutex_try_acquire(ink_mutex *m)
   return pthread_mutex_trylock(m) == 0;
 }
 
+/** RAII class for locking a @c ink_mutex.
+
+    @code
+    ink_mutex m;
+    // ...
+    {
+       ink_mutex_lock lock(m);
+       // code under lock.
+    }
+    // code not under lock
+    @endcode
+ */
+class ink_mutex_lock
+{
+private:
+  ink_mutex &_m;
+
+public:
+  ink_mutex_lock(ink_mutex *m) : _m(*m) { ink_mutex_acquire(&_m); }
+  ink_mutex_lock(ink_mutex &m) : _m(m) { ink_mutex_acquire(&_m); }
+  ~ink_mutex_lock() { ink_mutex_release(&_m); }
+};
+
 #endif /* _ink_mutex_h_ */

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].