Browse Source

Condition variables rather than polling FTW.

cl-refactor
Gav Wood 10 years ago
parent
commit
84ecbaff9e
  1. 7
      libethereum/Client.cpp
  2. 7
      libethereum/Client.h

7
libethereum/Client.cpp

@ -658,8 +658,6 @@ void Client::noteChanged(h256Set const& _filters)
void Client::doWork()
{
// TODO: Use condition variable rather than this rubbish.
bool t = true;
if (m_syncBlockQueue.compare_exchange_strong(t, false))
syncBlockQueue();
@ -671,7 +669,10 @@ void Client::doWork()
tick();
if (!m_syncBlockQueue && !m_syncTransactionQueue)
this_thread::sleep_for(chrono::milliseconds(20));
{
std::unique_lock<std::mutex> l(x_signalled);
m_signalled.wait_for(l, chrono::seconds(1));
}
}
void Client::tick()

7
libethereum/Client.h

@ -22,6 +22,7 @@
#pragma once
#include <thread>
#include <condition_variable>
#include <mutex>
#include <list>
#include <atomic>
@ -258,10 +259,10 @@ private:
void syncTransactionQueue();
/// Magically called when m_tq needs syncing. Be nice and don't block.
void onTransactionQueueReady() { m_syncTransactionQueue = true; }
void onTransactionQueueReady() { m_syncTransactionQueue = true; m_signalled.notify_all(); }
/// Magically called when m_tq needs syncing. Be nice and don't block.
void onBlockQueueReady() { m_syncBlockQueue = true; }
void onBlockQueueReady() { m_syncBlockQueue = true; m_signalled.notify_all(); }
/// Called when the post state has changed (i.e. when more transactions are in it or we're mining on a new block).
/// This updates m_miningInfo.
@ -309,6 +310,8 @@ private:
ActivityReport m_report;
// TODO!!!!!! REPLACE WITH A PROPER X-THREAD ASIO SIGNAL SYSTEM (could just be condition variables)
std::condition_variable m_signalled;
Mutex x_signalled;
std::atomic<bool> m_syncTransactionQueue = {false};
std::atomic<bool> m_syncBlockQueue = {false};
};

Loading…
Cancel
Save