|
|
|
@ -202,43 +202,6 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message
@@ -202,43 +202,6 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message
|
|
|
|
|
void SetThreadPriority(int nPriority); |
|
|
|
|
void RenameThread(const char* name); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Standard wrapper for do-something-forever thread functions. |
|
|
|
|
* "Forever" really means until the thread is interrupted. |
|
|
|
|
* Use it like: |
|
|
|
|
* new boost::thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 900000)); |
|
|
|
|
* or maybe: |
|
|
|
|
* boost::function<void()> f = boost::bind(&FunctionWithArg, argument); |
|
|
|
|
* threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "nothing", f, milliseconds)); |
|
|
|
|
*/ |
|
|
|
|
template <typename Callable> void LoopForever(const char* name, Callable func, int64_t msecs) |
|
|
|
|
{ |
|
|
|
|
std::string s = strprintf("bitcoin-%s", name); |
|
|
|
|
RenameThread(s.c_str()); |
|
|
|
|
LogPrintf("%s thread start\n", name); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
while (1) |
|
|
|
|
{ |
|
|
|
|
MilliSleep(msecs); |
|
|
|
|
func(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (const boost::thread_interrupted&) |
|
|
|
|
{ |
|
|
|
|
LogPrintf("%s thread stop\n", name); |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
catch (const std::exception& e) { |
|
|
|
|
PrintExceptionContinue(&e, name); |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
catch (...) { |
|
|
|
|
PrintExceptionContinue(NULL, name); |
|
|
|
|
throw; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* .. and a wrapper that just calls func once |
|
|
|
|
*/ |
|
|
|
|