Browse Source

Remove usages of boost::thread

Just C++11 threads...
cl-refactor
Paweł Bylica 8 years ago
parent
commit
a876fa7388
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 2
      cmake/EthDependencies.cmake
  2. 23
      libdevcore/Guards.h
  3. 23
      libdevcore/Log.cpp
  4. 3
      libethcore/EthashAux.cpp
  5. 4
      libethcore/EthashAux.h
  6. 19
      libethcore/Farm.h
  7. 10
      libstratum/EthStratumClient.cpp

2
cmake/EthDependencies.cmake

@ -93,7 +93,7 @@ elseif (UNIX)
endif()
find_package(Boost 1.54.0 REQUIRED COMPONENTS thread date_time system regex chrono filesystem unit_test_framework program_options random)
find_package(Boost 1.54.0 REQUIRED COMPONENTS random)
message(" - boost header: ${Boost_INCLUDE_DIRS}")
message(" - boost lib : ${Boost_LIBRARIES}")

23
libdevcore/Guards.h

@ -36,15 +36,10 @@ namespace dev
using Mutex = std::mutex;
using RecursiveMutex = std::recursive_mutex;
using SharedMutex = boost::shared_mutex;
using Guard = std::lock_guard<std::mutex>;
using UniqueGuard = std::unique_lock<std::mutex>;
using RecursiveGuard = std::lock_guard<std::recursive_mutex>;
using ReadGuard = boost::shared_lock<boost::shared_mutex>;
using UpgradableGuard = boost::upgrade_lock<boost::shared_mutex>;
using UpgradeGuard = boost::upgrade_to_unique_lock<boost::shared_mutex>;
using WriteGuard = boost::unique_lock<boost::shared_mutex>;
template <class GuardType, class MutexType>
struct GenericGuardBool: GuardType
@ -52,22 +47,6 @@ struct GenericGuardBool: GuardType
GenericGuardBool(MutexType& _m): GuardType(_m) {}
bool b = true;
};
template <class MutexType>
struct GenericUnguardBool
{
GenericUnguardBool(MutexType& _m): m(_m) { m.unlock(); }
~GenericUnguardBool() { m.lock(); }
bool b = true;
MutexType& m;
};
template <class MutexType>
struct GenericUnguardSharedBool
{
GenericUnguardSharedBool(MutexType& _m): m(_m) { m.unlock_shared(); }
~GenericUnguardSharedBool() { m.lock_shared(); }
bool b = true;
MutexType& m;
};
/** @brief Simple lock that waits for release without making context switch */
class SpinLock
@ -143,7 +122,5 @@ private:
#define DEV_GUARDED(MUTEX) \
for (GenericGuardBool<Guard, Mutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
#define DEV_READ_GUARDED(MUTEX) \
for (GenericGuardBool<ReadGuard, SharedMutex> __eth_l(MUTEX); __eth_l.b; __eth_l.b = false)
}

23
libdevcore/Log.cpp

@ -82,7 +82,7 @@ LogOutputStreamBase::LogOutputStreamBase(char const* _id, std::type_info const*
{
Guard l(x_logOverride);
auto it = s_logOverride.find(_info);
if ((it != s_logOverride.end() && it->second == true) || (it == s_logOverride.end() && (int)_v <= g_logVerbosity))
if ((it != s_logOverride.end() && it->second) || (it == s_logOverride.end() && (int)_v <= g_logVerbosity))
{
time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char buf[24];
@ -104,10 +104,14 @@ void LogOutputStreamBase::append(boost::asio::ip::basic_endpoint<boost::asio::ip
/// Associate a name with each thread for nice logging.
struct ThreadLocalLogName
{
ThreadLocalLogName(std::string const& _name) { m_name.reset(new string(_name)); }
boost::thread_specific_ptr<std::string> m_name;
ThreadLocalLogName(char const* _name) { name = _name; }
thread_local static char const* name;
};
thread_local char const* ThreadLocalLogName::name;
thread_local static std::vector<std::string> logContexts;
/// Associate a name with each thread for nice logging.
struct ThreadLocalLogContext
{
@ -115,26 +119,21 @@ struct ThreadLocalLogContext
void push(std::string const& _name)
{
if (!m_contexts.get())
m_contexts.reset(new vector<string>);
m_contexts->push_back(_name);
logContexts.push_back(_name);
}
void pop()
{
m_contexts->pop_back();
logContexts.pop_back();
}
string join(string const& _prior)
{
string ret;
if (m_contexts.get())
for (auto const& i: *m_contexts)
ret += _prior + i;
for (auto const& i: logContexts)
ret += _prior + i;
return ret;
}
boost::thread_specific_ptr<std::vector<std::string>> m_contexts;
};
ThreadLocalLogContext g_logThreadContext;

3
libethcore/EthashAux.cpp

@ -113,10 +113,9 @@ uint64_t EthashAux::number(h256 const& _seedHash)
EthashAux::LightType EthashAux::light(h256 const& _seedHash)
{
UpgradableGuard l(get()->x_lights);
Guard l(get()->x_lights);
if (get()->m_lights.count(_seedHash))
return get()->m_lights.at(_seedHash);
UpgradeGuard l2(l);
return (get()->m_lights[_seedHash] = make_shared<LightAllocation>(_seedHash));
}

4
libethcore/EthashAux.h

@ -142,7 +142,7 @@ private:
static EthashAux* s_this;
static char s_dagDirName[256];
SharedMutex x_lights;
Mutex x_lights;
std::unordered_map<h256, std::shared_ptr<LightAllocation>> m_lights;
Mutex x_fulls;
@ -154,8 +154,6 @@ private:
Mutex x_epochs;
std::unordered_map<h256, unsigned> m_epochs;
h256s m_seedHashes;
};
}

19
libethcore/Farm.h

@ -66,7 +66,7 @@ public:
*/
void setWork(WorkPackage const& _wp)
{
WriteGuard l(x_minerWork);
Guard l(x_minerWork);
if (_wp.headerHash == m_work.headerHash && _wp.startNonce == m_work.startNonce)
return;
m_work = _wp;
@ -82,7 +82,7 @@ public:
*/
bool start(std::string const& _sealer, bool mixed)
{
WriteGuard l(x_minerWork);
Guard l(x_minerWork);
if (!m_miners.empty() && m_lastSealer == _sealer)
return true;
if (!m_sealers.count(_sealer))
@ -119,7 +119,7 @@ public:
*/
void stop()
{
WriteGuard l(x_minerWork);
Guard l(x_minerWork);
m_miners.clear();
m_work.reset();
m_isMining = false;
@ -139,11 +139,11 @@ public:
WorkingProgress p;
p.ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_lastStart).count();
{
ReadGuard l2(x_minerWork);
Guard l2(x_minerWork);
for (auto const& i: m_miners)
p.hashes += i->hashCount();
}
ReadGuard l(x_progress);
Guard l(x_progress);
m_progress = p;
return m_progress;
}
@ -153,7 +153,7 @@ public:
*/
void resetMiningProgress()
{
DEV_READ_GUARDED(x_minerWork)
DEV_GUARDED(x_minerWork)
for (auto const& i: m_miners)
i->resetHashCount();
resetTimer();
@ -198,7 +198,7 @@ public:
*/
void onSolutionFound(SolutionFound const& _handler) { m_onSolutionFound = _handler; }
WorkPackage work() const { ReadGuard l(x_minerWork); return m_work; }
WorkPackage work() const { Guard l(x_minerWork); return m_work; }
private:
/**
@ -229,13 +229,13 @@ private:
m_lastStart = std::chrono::steady_clock::now();
}
mutable SharedMutex x_minerWork;
mutable Mutex x_minerWork;
std::vector<std::shared_ptr<Miner>> m_miners;
WorkPackage m_work;
std::atomic<bool> m_isMining = {false};
mutable SharedMutex x_progress;
mutable Mutex x_progress;
mutable WorkingProgress m_progress;
std::chrono::steady_clock::time_point m_lastStart;
@ -244,7 +244,6 @@ private:
std::map<std::string, SealerDescriptor> m_sealers;
std::string m_lastSealer;
mutable SharedMutex x_solutionStats;
mutable SolutionStats m_solutionStats;
};

10
libstratum/EthStratumClient.cpp

@ -72,18 +72,16 @@ void EthStratumClient::setFailover(string const & host, string const & port, str
void EthStratumClient::connect()
{
tcp::resolver r(m_io_service);
tcp::resolver::query q(p_active->host, p_active->port);
r.async_resolve(q, boost::bind(&EthStratumClient::resolve_handler,
this, boost::asio::placeholders::error,
boost::asio::placeholders::iterator));
this, boost::asio::placeholders::error,
boost::asio::placeholders::iterator));
cnote << "Connecting to stratum server " << p_active->host + ":" + p_active->port;
boost::thread t(boost::bind(&boost::asio::io_service::run, &m_io_service));
std::thread t(boost::bind(&boost::asio::io_service::run, &m_io_service));
}
#define BOOST_ASIO_ENABLE_CANCELIO

Loading…
Cancel
Save