diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index fb5f201b6..79024e2ad 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -466,7 +466,7 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook m_queue.enqueueNDRangeKernel(m_searchKernel, cl::NullRange, m_batchSize, m_workgroupSize); unsigned ms = t.elapsed() * 1000; if (ms > _msPerBatch * 1.1) - m_batchSize = max(128, m_batchSize * 9 / 10); + m_batchSize = max(128, m_batchSize * 9 / 10); else if (ms < _msPerBatch * 0.9) m_batchSize = m_batchSize * 10 / 9; diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index fbc7d4dce..46e41017c 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -225,23 +225,26 @@ std::string Ethash::CPUMiner::platformInfo() #if ETH_ETHASHCL || !ETH_TRUE +using UniqueGuard = std::unique_lock; + template class Notified { public: Notified() {} Notified(N const& _v): m_value(_v) {} - Notified& operator=(N const& _v) { std::unique_lock l(m_mutex); m_value = _v; m_cv.notify_all(); return *this; } + Notified(Notified const&) = delete; + Notified& operator=(N const& _v) { UniqueGuard l(m_mutex); m_value = _v; m_cv.notify_all(); return *this; } - operator N() const { std::unique_lock l(m_mutex); return m_value; } + operator N() const { UniqueGuard l(m_mutex); return m_value; } - void wait() const { std::unique_lock l(m_mutex); m_cv.wait(l); } - void wait(N const& _v) const { std::unique_lock l(m_mutex); m_cv.wait(l, [&](){return m_value == _v;}); } - template void wait(F const& _f) const { std::unique_lock l(m_mutex); m_cv.wait(l, _f); } + void wait() const { UniqueGuard l(m_mutex); m_cv.wait(l); } + void wait(N const& _v) const { UniqueGuard l(m_mutex); m_cv.wait(l, [&](){return m_value == _v;}); } + template void wait(F const& _f) const { UniqueGuard l(m_mutex); m_cv.wait(l, _f); } private: - Mutex m_mutex; - std::condition_variable m_cv; + mutable Mutex m_mutex; + mutable std::condition_variable m_cv; N m_value; }; @@ -249,10 +252,11 @@ class EthashCLHook: public ethash_cl_miner::search_hook { public: EthashCLHook(Ethash::GPUMiner* _owner): m_owner(_owner) {} + EthashCLHook(EthashCLHook const&) = delete; void abort() { - std::unique_lock l(x_all); + UniqueGuard l(x_all); if (m_aborted) return; // cdebug << "Attempting to abort"; @@ -270,7 +274,7 @@ public: void reset() { - Mutex l(x_all); + UniqueGuard l(x_all); m_aborted = m_abort = false; } @@ -286,7 +290,7 @@ protected: virtual bool searched(uint64_t _startNonce, uint32_t _count) override { - Mutex l(x_all); + UniqueGuard l(x_all); // std::cerr << "Searched " << _count << " from " << _startNonce << std::endl; m_owner->accumulateHashes(_count); m_last = _startNonce + _count;