Skip to content

Instantly share code, notes, and snippets.

@jrhemstad
Last active May 30, 2019 13:37
Show Gist options
  • Save jrhemstad/66b74024c2a5d78294035a6905b65ff8 to your computer and use it in GitHub Desktop.
Save jrhemstad/66b74024c2a5d78294035a6905b65ff8 to your computer and use it in GitHub Desktop.
namespace detail
{
inline memory_resource* default_resource(){
static memory_resource res();
return &res;
}
inline std::atomic<memory_resource*>& get_global()
{
static std::atomic<memory_resource*> global{default_resource()};
return global;
}
}
inline memory_resource<> * get_global_resource()
{
return std::atomic_load_explicit(&get_global(), std::memory_order::memory_order_acquire);
}
inline void set_global_resource(memory_resource * new_res)
{
std::atomic_exchange_explicit(&get_global(), new_res, std::memory_order::memory_order_acq_rel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment