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

@ -24,13 +24,13 @@
#include "net/JobResults.h"
#include "backend/common/Tags.h"
#include "base/io/Async.h"
#include "base/io/log/Log.h"
#include "base/tools/Handle.h"
#include "base/kernel/interfaces/IAsyncListener.h"
#include "base/tools/Object.h"
#include "net/interfaces/IJobResultListener.h"
#include "net/JobResult.h"
#include "backend/common/Tags.h"
#ifdef XMRIG_ALGO_RANDOMX
@ -57,6 +57,7 @@
#include <cassert>
#include <list>
#include <memory>
#include <mutex>
#include <uv.h>
@ -193,7 +194,7 @@ static void getResults(JobBundle &bundle, std::vector<JobResult> &results, uint3
#endif
class JobResultsPrivate
class JobResultsPrivate : public IAsyncListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(JobResultsPrivate)
@ -202,17 +203,11 @@ public:
m_hwAES(hwAES),
m_listener(listener)
{
m_async = new uv_async_t;
m_async->data = this;
uv_async_init(uv_default_loop(), m_async, JobResultsPrivate::onResult);
m_async = std::make_shared<Async>(this);
}
inline ~JobResultsPrivate()
{
Handle::close(m_async);
}
~JobResultsPrivate() override = default;
inline void submit(const JobResult &result)
@ -220,7 +215,7 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
m_results.push_back(result);
uv_async_send(m_async);
m_async->send();
}
@ -230,11 +225,15 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
m_bundles.emplace_back(job, results, count, device_index);
uv_async_send(m_async);
m_async->send();
}
# endif
protected:
inline void onAsync() override { submit(); }
private:
static void onResult(uv_async_t *handle) { static_cast<JobResultsPrivate*>(handle->data)->submit(); }
@ -300,7 +299,7 @@ private:
IJobResultListener *m_listener;
std::list<JobResult> m_results;
std::mutex m_mutex;
uv_async_t *m_async;
std::shared_ptr<Async> m_async;
# if defined(XMRIG_FEATURE_OPENCL) || defined(XMRIG_FEATURE_CUDA)
std::list<JobBundle> m_bundles;