New Async wrapper.

This commit is contained in:
XMRig 2020-10-21 08:09:44 +07:00
parent 6860450147
commit 87b4d97798
No known key found for this signature in database
GPG key ID: 446A53638BE94409
7 changed files with 157 additions and 37 deletions

View file

@ -27,9 +27,9 @@
#include "crypto/rx/RxQueue.h"
#include "backend/common/interfaces/IRxListener.h"
#include "base/io/Async.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/tools/Handle.h"
#include "crypto/rx/RxBasicStorage.h"
@ -41,11 +41,7 @@
xmrig::RxQueue::RxQueue(IRxListener *listener) :
m_listener(listener)
{
m_async = new uv_async_t;
m_async->data = this;
uv_async_init(uv_default_loop(), m_async, [](uv_async_t *handle) { static_cast<RxQueue *>(handle->data)->onReady(); });
m_async = std::make_shared<Async>(this);
m_thread = std::thread(&RxQueue::backgroundInit, this);
}
@ -61,8 +57,6 @@ xmrig::RxQueue::~RxQueue()
m_thread.join();
delete m_storage;
Handle::close(m_async);
}
@ -167,7 +161,7 @@ void xmrig::RxQueue::backgroundInit()
}
m_state = STATE_IDLE;
uv_async_send(m_async);
m_async->send();
}
}

View file

@ -28,7 +28,7 @@
#define XMRIG_RX_QUEUE_H
#include "base/io/Async.h"
#include "base/kernel/interfaces/IAsyncListener.h"
#include "base/tools/Object.h"
#include "crypto/common/HugePagesInfo.h"
#include "crypto/rx/RxConfig.h"
@ -40,9 +40,6 @@
#include <thread>
using uv_async_t = struct uv_async_s;
namespace xmrig
{
@ -75,19 +72,22 @@ public:
};
class RxQueue
class RxQueue : public IAsyncListener
{
public:
XMRIG_DISABLE_COPY_MOVE(RxQueue);
RxQueue(IRxListener *listener);
~RxQueue();
~RxQueue() override;
HugePagesInfo hugePages();
RxDataset *dataset(const Job &job, uint32_t nodeId);
template<typename T> bool isReady(const T &seed);
void enqueue(const RxSeed &seed, const std::vector<uint32_t> &nodeset, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode, int priority);
protected:
inline void onAsync() override { onReady(); }
private:
enum State {
STATE_IDLE,
@ -105,9 +105,9 @@ private:
State m_state = STATE_IDLE;
std::condition_variable m_cv;
std::mutex m_mutex;
std::shared_ptr<Async> m_async;
std::thread m_thread;
std::vector<RxQueueItem> m_queue;
uv_async_t *m_async = nullptr;
};