From 4eac7e3e4fc443d3ad058d245f88f52ae7a1a817 Mon Sep 17 00:00:00 2001 From: danielkr Date: Sat, 17 Aug 2013 22:55:04 +0300 Subject: [PATCH] Add scoped_lock_t syntactic sugar --- src/mutex.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/mutex.hpp b/src/mutex.hpp index 6533450a..308f5eff 100644 --- a/src/mutex.hpp +++ b/src/mutex.hpp @@ -128,4 +128,30 @@ namespace zmq #endif + +namespace zmq +{ + struct scoped_lock_t + { + scoped_lock_t (mutex_t& mutex_) + : mutex (mutex_) + { + mutex.lock (); + } + + ~scoped_lock_t () + { + mutex.unlock (); + } + + private: + + mutex_t& mutex; + + // Disable copy construction and assignment. + scoped_lock_t (const scoped_lock_t&); + const scoped_lock_t &operator = (const scoped_lock_t&); + }; +} + #endif