Created
March 7, 2012 11:45
-
-
Save lcapaldo/1992678 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class resource { | |
mutex m_; | |
condition_variable cv_; | |
public: | |
resource() {} | |
void with_do(std::function<void()> body) | |
{ | |
m_.lock(); | |
at_scope_exit u( [&]() { cv_.notify_all(); m_.unlock(); } ); | |
body(); | |
} | |
void with_when_do(std::function<bool()> cond, std::function<void()> body) | |
{ | |
with_do( [&]() { | |
while( !cond() ) | |
{ | |
cv_.wait(m_); | |
} | |
body(); }); | |
} | |
private: | |
resource(const resource&); | |
resource& operator=(resource); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment