Browse Source

Use std::call_once instead of a mutex

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
b75514756a
  1. 8
      libethcore/EthashAux.cpp
  2. 3
      libethcore/EthashAux.h

8
libethcore/EthashAux.cpp

@ -43,13 +43,19 @@ using namespace eth;
const char* DAGChannel::name() { return EthGreen "DAG"; } const char* DAGChannel::name() { return EthGreen "DAG"; }
Mutex dev::eth::EthashAux::x_this;
EthashAux* dev::eth::EthashAux::s_this = nullptr; EthashAux* dev::eth::EthashAux::s_this = nullptr;
EthashAux::~EthashAux() EthashAux::~EthashAux()
{ {
} }
EthashAux* EthashAux::get()
{
static std::once_flag flag;
std::call_once(flag, []{s_this = new EthashAux();});
return s_this;
}
uint64_t EthashAux::cacheSize(BlockInfo const& _header) uint64_t EthashAux::cacheSize(BlockInfo const& _header)
{ {
return ethash_get_cachesize((uint64_t)_header.number); return ethash_get_cachesize((uint64_t)_header.number);

3
libethcore/EthashAux.h

@ -38,7 +38,7 @@ class EthashAux
public: public:
~EthashAux(); ~EthashAux();
static EthashAux* get() {Guard l(x_this);if (!s_this) s_this = new EthashAux(); return s_this; } static EthashAux* get();
struct LightAllocation struct LightAllocation
{ {
@ -89,7 +89,6 @@ private:
void killCache(h256 const& _s); void killCache(h256 const& _s);
static Mutex x_this;
static EthashAux* s_this; static EthashAux* s_this;
SharedMutex x_lights; SharedMutex x_lights;

Loading…
Cancel
Save