Created
June 23, 2018 15:54
-
-
Save handicraftsman/c9180ab154772bd9a3f9fe366667e161 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
#pragma once | |
#include <functional> | |
#include <memory> | |
#include <mutex> | |
template<class T> | |
class room { | |
public: | |
typedef std::shared_ptr<T> ptr; | |
private: | |
ptr value; | |
std::mutex mtx; | |
public: | |
room(ptr v) | |
: value(v) | |
{} | |
room(T* v) | |
: value(v) | |
{} | |
void use(std::function<void(ptr)> f) { | |
std::lock_guard<std::mutex> lock(mtx); | |
f(value); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment