MSVC doesn't like them as static members of classes with DLL interface.
namespace Msp::Game {
-thread_local AccessGuard *AccessGuard::instance = nullptr;
-
AccessGuard::AccessGuard()
{
+ AccessGuard *&instance = get_instance_ptr();
if(!instance)
instance = this;
}
AccessGuard::AccessGuard(AccessGuard &&other):
flags(std::move(other.flags))
{
+ AccessGuard *&instance = get_instance_ptr();
if(&other==instance)
instance = this;
}
AccessGuard &AccessGuard::operator=(AccessGuard &&other)
{
+ AccessGuard *&instance = get_instance_ptr();
flags = std::move(other.flags);
if(&other==instance)
instance = this;
AccessGuard::~AccessGuard()
{
+ AccessGuard *&instance = get_instance_ptr();
if(this==instance)
instance = nullptr;
}
AccessGuard &AccessGuard::get_instance()
{
+ AccessGuard *&instance = get_instance_ptr();
if(!instance)
throw std::logic_error("no AccessGuard instance");
return *instance;
}
+AccessGuard *&AccessGuard::get_instance_ptr()
+{
+ static thread_local AccessGuard *instance = nullptr;
+ return instance;
+}
+
void AccessGuard::block_all()
{
default_flag = BLOCKED;
std::uint8_t default_flag = UNBLOCKED;
std::vector<std::uint8_t> flags;
- static thread_local AccessGuard *instance;
-
public:
AccessGuard();
AccessGuard(AccessGuard &&);
~AccessGuard();
static AccessGuard &get_instance();
+private:
+ static AccessGuard *&get_instance_ptr();
+public:
void block_all();
void unblock_all();
namespace Msp::Game {
-thread_local System *System::active = nullptr;
+System *&System::get_active_ptr()
+{
+ thread_local System *active = nullptr;
+ return active;
+}
void System::begin_tick()
{
+ System *&active = get_active_ptr();
if(active)
throw logic_error("System::active != nullptr");
active = this;
#endif
}
+ System *&active = get_active_ptr();
if(active==this)
active = nullptr;
}
std::vector<std::function<void()>> deferred_queue;
std::vector<Dependency> dependencies;
- static thread_local System *active;
-
System(Stage &s): stage(s) { }
public:
virtual ~System() = default;
public:
const std::vector<Dependency> &get_dependencies() const { return dependencies; }
+private:
+ static System *&get_active_ptr();
+
+public:
void begin_tick();
virtual void tick(Time::TimeDelta) = 0;
void end_tick();