Skip to content

Instantly share code, notes, and snippets.

@ak110
Last active December 20, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak110/6045063 to your computer and use it in GitHub Desktop.
Save ak110/6045063 to your computer and use it in GitHub Desktop.
std::lock_guard<std::mutex>の中で一時的にロックを解除したくなった時に作ったクラス。
#pragma once
#include <boost/noncopyable.hpp>
namespace {
/// 一時的にロックを解除するためのクラス
template<class Mutex>
class unlock_guard : private boost::noncopyable {
Mutex& m;
public:
typedef Mutex mutex_type;
/// unlock()
explicit unlock_guard(Mutex& m) : m(m) { m.unlock(); }
/// lock()
~unlock_guard() { m.lock(); }
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment