Browse Source

Remove unnecessary code

cl-refactor
Paweł Bylica 8 years ago
parent
commit
53d4888589
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 19
      ethminer/MinerAux.h
  2. 26
      libdevcore/Common.cpp
  3. 61
      libdevcore/Common.h
  4. 21
      libdevcore/Worker.cpp
  5. 2
      libethash-cl/ethash_cl_miner.h
  6. 6
      libethcore/Miner.h

19
ethminer/MinerAux.h

@ -62,25 +62,6 @@ using namespace boost::algorithm;
#undef RETURN #undef RETURN
bool isTrue(std::string const& _m)
{
return _m == "on" || _m == "yes" || _m == "true" || _m == "1";
}
bool isFalse(std::string const& _m)
{
return _m == "off" || _m == "no" || _m == "false" || _m == "0";
}
inline std::string credits()
{
std::ostringstream out;
out
<< "Ethereum (++) " << dev::Version << endl
<< " Code by Gav Wood et al, (c) 2013, 2014, 2015." << endl;
return out.str();
}
class BadArgument: public Exception {}; class BadArgument: public Exception {};
struct MiningChannel: public LogChannel struct MiningChannel: public LogChannel
{ {

26
libdevcore/Common.cpp

@ -33,30 +33,4 @@ char const* Version = ETH_PROJECT_VERSION;
const u256 UndefinedU256 = ~(u256)0; const u256 UndefinedU256 = ~(u256)0;
void InvariantChecker::checkInvariants(HasInvariants const* _this, char const* _fn, char const* _file, int _line, bool _pre)
{
if (!_this->invariants())
{
cwarn << (_pre ? "Pre" : "Post") << "invariant failed in" << _fn << "at" << _file << ":" << _line;
::boost::exception_detail::throw_exception_(FailedInvariant(), _fn, _file, _line);
}
}
struct TimerChannel: public LogChannel { static const char* name(); static const int verbosity = 0; };
#ifdef _WIN32
const char* TimerChannel::name() { return EthRed " ! "; }
#else
const char* TimerChannel::name() { return EthRed ""; }
#endif
TimerHelper::~TimerHelper()
{
auto e = std::chrono::high_resolution_clock::now() - m_t;
if (!m_ms || e > chrono::milliseconds(m_ms))
{
clog(TimerChannel) << m_id << chrono::duration_cast<chrono::milliseconds>(e).count() << "ms";
}
}
} }

61
libdevcore/Common.h

@ -237,73 +237,12 @@ private:
#define DEV_INVARIANT_CHECK_HERE (void)0; #define DEV_INVARIANT_CHECK_HERE (void)0;
#endif #endif
/// Simple scope-based timer helper.
class TimerHelper
{
public:
TimerHelper(std::string const& _id, unsigned _msReportWhenGreater = 0): m_t(std::chrono::high_resolution_clock::now()), m_id(_id), m_ms(_msReportWhenGreater) {}
~TimerHelper();
private:
std::chrono::high_resolution_clock::time_point m_t;
std::string m_id;
unsigned m_ms;
};
class Timer
{
public:
Timer() { restart(); }
std::chrono::high_resolution_clock::duration duration() const { return std::chrono::high_resolution_clock::now() - m_t; }
double elapsed() const { return std::chrono::duration_cast<std::chrono::microseconds>(duration()).count() / 1000000.0; }
void restart() { m_t = std::chrono::high_resolution_clock::now(); }
private:
std::chrono::high_resolution_clock::time_point m_t;
};
#define DEV_TIMED(S) for (::std::pair<::dev::TimerHelper, bool> __eth_t(S, true); __eth_t.second; __eth_t.second = false)
#define DEV_TIMED_SCOPE(S) ::dev::TimerHelper __eth_t(S)
#if WIN32
#define DEV_TIMED_FUNCTION DEV_TIMED_SCOPE(__FUNCSIG__)
#else
#define DEV_TIMED_FUNCTION DEV_TIMED_SCOPE(__PRETTY_FUNCTION__)
#endif
#define DEV_TIMED_ABOVE(S, MS) for (::std::pair<::dev::TimerHelper, bool> __eth_t(::dev::TimerHelper(S, MS), true); __eth_t.second; __eth_t.second = false)
#define DEV_TIMED_SCOPE_ABOVE(S, MS) ::dev::TimerHelper __eth_t(S, MS)
#if WIN32
#define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__FUNCSIG__, MS)
#else
#define DEV_TIMED_FUNCTION_ABOVE(MS) DEV_TIMED_SCOPE_ABOVE(__PRETTY_FUNCTION__, MS)
#endif
#ifdef _MSC_VER
// TODO.
#define DEV_UNUSED
#else
#define DEV_UNUSED __attribute__((unused))
#endif
enum class WithExisting: int
{
Trust = 0,
Verify,
Rescue,
Kill
};
} }
namespace std namespace std
{ {
inline dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
{
return static_cast<dev::WithExisting>(max(static_cast<int>(_a), static_cast<int>(_b)));
}
template <> struct hash<dev::u256> template <> struct hash<dev::u256>
{ {
size_t operator()(dev::u256 const& _a) const size_t operator()(dev::u256 const& _a) const

21
libdevcore/Worker.cpp

@ -69,17 +69,14 @@ void Worker::startWorking()
if (ex == WorkerState::Killing || ex == WorkerState::Starting) if (ex == WorkerState::Killing || ex == WorkerState::Starting)
m_state.exchange(ex); m_state.exchange(ex);
// cnote << "Waiting until not Stopped..."; while (m_state == WorkerState::Stopped)
DEV_TIMED_ABOVE("Worker stopping", 100) this_thread::sleep_for(chrono::milliseconds(20));
while (m_state == WorkerState::Stopped)
this_thread::sleep_for(chrono::milliseconds(20));
} }
})); }));
// cnote << "Spawning" << m_name; // cnote << "Spawning" << m_name;
} }
DEV_TIMED_ABOVE("Start worker", 100) while (m_state == WorkerState::Starting)
while (m_state == WorkerState::Starting) this_thread::sleep_for(chrono::microseconds(20));
this_thread::sleep_for(chrono::microseconds(20));
} }
void Worker::stopWorking() void Worker::stopWorking()
@ -90,9 +87,8 @@ void Worker::stopWorking()
WorkerState ex = WorkerState::Started; WorkerState ex = WorkerState::Started;
m_state.compare_exchange_strong(ex, WorkerState::Stopping); m_state.compare_exchange_strong(ex, WorkerState::Stopping);
DEV_TIMED_ABOVE("Stop worker", 100) while (m_state != WorkerState::Stopped)
while (m_state != WorkerState::Stopped) this_thread::sleep_for(chrono::microseconds(20));
this_thread::sleep_for(chrono::microseconds(20));
} }
} }
@ -103,10 +99,7 @@ void Worker::terminate()
if (m_work) if (m_work)
{ {
m_state.exchange(WorkerState::Killing); m_state.exchange(WorkerState::Killing);
m_work->join();
DEV_TIMED_ABOVE("Terminate worker", 100)
m_work->join();
m_work.reset(); m_work.reset();
} }
} }

2
libethash-cl/ethash_cl_miner.h

@ -1,7 +1,7 @@
#pragma once #pragma once
#define __CL_ENABLE_EXCEPTIONS #define __CL_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push

6
libethcore/Miner.h

@ -165,10 +165,8 @@ public:
} }
if (!!_work) if (!!_work)
{ {
DEV_TIMED_ABOVE("pause", 250) pause();
pause(); kickOff();
DEV_TIMED_ABOVE("kickOff", 250)
kickOff();
} }
else if (!_work && !!old) else if (!_work && !!old)
pause(); pause();

Loading…
Cancel
Save