From: Razvan Becheriu Date: Mon, 25 Mar 2019 16:42:51 +0000 (+0200) Subject: added LockGuard X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ba1546a11fac7693a3d7a36dcb5f0d66f72f53e;p=thirdparty%2Fkea.git added LockGuard --- diff --git a/src/lib/util/threads/lock_guard.h b/src/lib/util/threads/lock_guard.h new file mode 100644 index 0000000000..6c949a29f6 --- /dev/null +++ b/src/lib/util/threads/lock_guard.h @@ -0,0 +1,39 @@ +#ifndef LOCK_GUARD_H +#define LOCK_GUARD_H + +#include + +namespace isc { +namespace util { +namespace thread { + +template +class LockGuard { +public: + LockGuard(Lock* lock) : lk_(lock) { + if (lk_) { + lk_->lock(); + } + } + + ~LockGuard() { + if (lk_) { + lk_->unlock(); + } + } + + LockGuard(const LockGuard&) = delete; + LockGuard& operator=(const LockGuard&) = delete; + + LockGuard(LockGuard&&) = delete; + LockGuard& operator=(LockGuard&&) = delete; + +private: + Lock* lk_; +}; + +} // namespace thread +} // namespace util +} // namespace isc + +#endif // LOCK_GUARD_H