Split thread and range stuff out of utils

This commit is contained in:
Vinnie Falco
2013-05-27 10:05:49 -07:00
parent 9b5d047c90
commit 90bc0c1a8c
16 changed files with 271 additions and 128 deletions

View File

@@ -112,13 +112,13 @@ void sigIntHandler(int)
static void runAux(boost::asio::io_service& svc)
{
NameThread("aux");
setCallingThreadName("aux");
svc.run();
}
static void runIO(boost::asio::io_service& io)
{
NameThread("io");
setCallingThreadName("io");
io.run();
}

View File

@@ -273,7 +273,7 @@ void JobQueue::IOThread(boost::mutex::scoped_lock& sl)
{ // call with a lock
++mIOThreadCount;
sl.unlock();
NameThread("IO+");
setCallingThreadName("IO+");
try
{
mIOService.poll();
@@ -282,7 +282,7 @@ void JobQueue::IOThread(boost::mutex::scoped_lock& sl)
{
WriteLog (lsWARNING, JobQueue) << "Exception in IOThread";
}
NameThread("waiting");
setCallingThreadName("waiting");
sl.lock();
--mIOThreadCount;
}
@@ -292,7 +292,7 @@ void JobQueue::threadEntry()
boost::mutex::scoped_lock sl(mJobLock);
while (1)
{
NameThread("waiting");
setCallingThreadName("waiting");
// bool didIO = false;
while (mJobSet.empty() && !mShuttingDown)
{
@@ -325,7 +325,7 @@ void JobQueue::threadEntry()
++(mJobCounts[type].second);
sl.unlock();
NameThread(Job::toString(type));
setCallingThreadName(Job::toString(type));
WriteLog (lsTRACE, JobQueue) << "Doing " << Job::toString(type) << " job";
job.doJob();
} // must destroy job without holding lock

View File

@@ -324,7 +324,7 @@ static void LogDeadLock(int dlTime)
void LoadManager::threadEntry()
{
NameThread("loadmgr");
setCallingThreadName("loadmgr");
boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time();
while (1)
{

View File

@@ -41,7 +41,7 @@ DECLARE_INSTANCE(WebSocketConnection);
void WSDoor::startListening()
{
NameThread("websocket");
setCallingThreadName("websocket");
// Generate a single SSL context for use by all connections.
boost::shared_ptr<boost::asio::ssl::context> mCtx;
mCtx = boost::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);

View File

@@ -128,7 +128,7 @@ void printHelp(const po::options_description& desc)
int main(int argc, char* argv[])
{
NameThread("main");
setCallingThreadName("main");
int iResult = 0;
po::variables_map vm; // Map of options.
@@ -269,14 +269,14 @@ int main(int argc, char* argv[])
{
// No arguments. Run server.
setupServer();
NameThread("io");
setCallingThreadName("io");
startServer();
InstanceType::shutdown();
}
else
{
// Have a RPC command.
NameThread("rpc");
setCallingThreadName("rpc");
std::vector<std::string> vCmd = vm["parameters"].as<std::vector<std::string> >();
iResult = commandLineRPC(vCmd);

View File

@@ -28,43 +28,6 @@
#include "utils.h"
#include "uint256.h"
//
// Time support
// We have our own epoch.
//
boost::posix_time::ptime ptEpoch()
{
return boost::posix_time::ptime(boost::gregorian::date(2000, boost::gregorian::Jan, 1));
}
int iToSeconds(boost::posix_time::ptime ptWhen)
{
return ptWhen.is_not_a_date_time()
? -1
: (ptWhen-ptEpoch()).total_seconds();
}
// Convert our time in seconds to a ptime.
boost::posix_time::ptime ptFromSeconds(int iSeconds)
{
return iSeconds < 0
? boost::posix_time::ptime(boost::posix_time::not_a_date_time)
: ptEpoch() + boost::posix_time::seconds(iSeconds);
}
// Convert from our time to UNIX time in seconds.
uint64_t utFromSeconds(int iSeconds)
{
boost::posix_time::time_duration tdDelta =
boost::posix_time::ptime(boost::gregorian::date(2000, boost::gregorian::Jan, 1))
-boost::posix_time::ptime(boost::gregorian::date(1970, boost::gregorian::Jan, 1))
+boost::posix_time::seconds(iSeconds)
;
return tdDelta.total_seconds();
}
//
// DH support
//
@@ -97,39 +60,6 @@ DH* DH_der_load(const std::string& strDer)
return d2i_DHparams(NULL, &pbuf, strDer.size());
}
#ifdef PR_SET_NAME
#define HAVE_NAME_THREAD
extern void NameThread(const char* n)
{
static std::string pName;
if (pName.empty())
{
std::ifstream cLine("/proc/self/cmdline", std::ios::in);
cLine >> pName;
if (pName.empty())
pName = "rippled";
else
{
size_t zero = pName.find_first_of('\0');
if ((zero != std::string::npos) && (zero != 0))
pName = pName.substr(0, zero);
size_t slash = pName.find_last_of('/');
if (slash != std::string::npos)
pName = pName.substr(slash + 1);
}
pName += " ";
}
prctl(PR_SET_NAME, (pName + n).c_str(), 0, 0, 0);
}
#endif
#ifndef HAVE_NAME_THREAD
extern void NameThread(const char*)
{ ; }
#endif
#ifdef __unix__
static pid_t pManager = static_cast<pid_t>(0);
@@ -175,14 +105,14 @@ std::string DoSustain()
_exit(0);
if (pChild == 0)
{
NameThread("main");
setCallingThreadName("main");
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
return str(boost::format("Launching child %d") % childCount);;
}
NameThread(boost::str(boost::format("#%d") % childCount).c_str());
setCallingThreadName(boost::str(boost::format("#%d") % childCount).c_str());
do
{
int i;

View File

@@ -1,13 +1,6 @@
#ifndef __UTILS__
#define __UTILS__
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 104700
#error Boost 1.47 or later is required
#endif
#include <openssl/dh.h>
#define nothing() do {} while (0)
@@ -18,47 +11,9 @@
#define isSetBit(x,y) (!!((x) & (y)))
boost::posix_time::ptime ptEpoch();
int iToSeconds(boost::posix_time::ptime ptWhen);
boost::posix_time::ptime ptFromSeconds(int iSeconds);
uint64_t utFromSeconds(int iSeconds);
DH* DH_der_load(const std::string& strDer);
std::string DH_der_gen(int iKeyLength);
// VFALCO: NOTE, these three are unused.
/*
template<typename T> T range_check(const T& value, const T& minimum, const T& maximum)
{
if ((value < minimum) || (value > maximum))
throw std::runtime_error("Value out of range");
return value;
}
template<typename T> T range_check_min(const T& value, const T& minimum)
{
if (value < minimum)
throw std::runtime_error("Value out of range");
return value;
}
template<typename T> T range_check_max(const T& value, const T& maximum)
{
if (value > maximum)
throw std::runtime_error("Value out of range");
return value;
}
*/
template<typename T, typename U> T range_check_cast(const U& value, const T& minimum, const T& maximum)
{
if ((value < minimum) || (value > maximum))
throw std::runtime_error("Value out of range");
return static_cast<T>(value);
}
extern void NameThread(const char *);
extern bool HaveSustain();
extern std::string StopSustain();
extern std::string DoSustain();