2019-01-14 23:01:11 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019 tevador
|
|
|
|
|
|
|
|
This file is part of RandomX.
|
|
|
|
|
|
|
|
RandomX is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
RandomX is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-01-18 16:57:47 +00:00
|
|
|
//#define TRACE
|
2019-01-14 23:01:11 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <array>
|
2019-01-18 16:57:47 +00:00
|
|
|
#ifdef TRACE
|
|
|
|
#include "Stopwatch.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
2019-01-14 23:01:11 +00:00
|
|
|
|
|
|
|
namespace RandomX {
|
|
|
|
|
|
|
|
using DatasetLine = std::array<uint64_t, CacheLineSize / sizeof(uint64_t)>;
|
|
|
|
|
|
|
|
class LightClientAsyncWorker : public ILightClientAsyncWorker {
|
|
|
|
public:
|
2019-03-10 22:14:03 +00:00
|
|
|
LightClientAsyncWorker(const Cache&);
|
2019-01-14 23:01:11 +00:00
|
|
|
void prepareBlock(addr_t) final;
|
|
|
|
void prepareBlocks(void* out, uint32_t startBlock, uint32_t blockCount) final;
|
|
|
|
const uint64_t* getBlock(addr_t) final;
|
|
|
|
void getBlocks(void* out, uint32_t startBlock, uint32_t blockCount) final;
|
|
|
|
void sync() final;
|
|
|
|
private:
|
|
|
|
void runWorker();
|
|
|
|
std::condition_variable notifier;
|
|
|
|
std::mutex mutex;
|
2019-01-18 16:57:47 +00:00
|
|
|
alignas(16) DatasetLine currentLine;
|
2019-01-14 23:01:11 +00:00
|
|
|
void* output;
|
|
|
|
uint32_t startBlock, blockCount;
|
|
|
|
bool hasWork;
|
2019-01-18 16:57:47 +00:00
|
|
|
#ifdef TRACE
|
|
|
|
Stopwatch sw;
|
|
|
|
#endif
|
2019-01-14 23:01:11 +00:00
|
|
|
std::thread workerThread;
|
|
|
|
};
|
|
|
|
}
|