Implement job result submitting.
This commit is contained in:
parent
a0a8711dab
commit
6774f86fcd
8 changed files with 92 additions and 6 deletions
|
@ -21,11 +21,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
#include "workers/Handle.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
IJobResultListener *Workers::m_listener = nullptr;
|
||||
Job Workers::m_job;
|
||||
pthread_mutex_t Workers::m_mutex;
|
||||
pthread_rwlock_t Workers::m_rwlock;
|
||||
|
@ -107,4 +109,10 @@ void Workers::onResult(uv_async_t *handle)
|
|||
m_queue.pop_front();
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
|
||||
class Handle;
|
||||
class IJobResultListener;
|
||||
|
||||
|
||||
class Workers
|
||||
|
@ -46,15 +47,17 @@ public:
|
|||
static void start(int threads, int64_t affinity, bool nicehash);
|
||||
static void submit(const JobResult &result);
|
||||
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_paused = 1; }
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_paused = 1; }
|
||||
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
||||
|
||||
private:
|
||||
static void *onReady(void *arg);
|
||||
static void onResult(uv_async_t *handle);
|
||||
|
||||
static IJobResultListener *m_listener;
|
||||
static Job m_job;
|
||||
static pthread_mutex_t m_mutex;
|
||||
static pthread_rwlock_t m_rwlock;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue