Skip to content

Instantly share code, notes, and snippets.

@handicraftsman
Created June 23, 2018 15:54
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 handicraftsman/c9180ab154772bd9a3f9fe366667e161 to your computer and use it in GitHub Desktop.
Save handicraftsman/c9180ab154772bd9a3f9fe366667e161 to your computer and use it in GitHub Desktop.
#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