mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Split thread and range stuff out of utils
This commit is contained in:
@@ -68,6 +68,39 @@ namespace boost
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VFALCO: Maybe not the best place for this but it sort of makes sense here
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
#include "memory/ripple_ByteOrder.cpp"
|
#include "memory/ripple_ByteOrder.cpp"
|
||||||
|
|
||||||
#include "system/ripple_RandomNumbers.cpp"
|
#include "system/ripple_RandomNumbers.cpp"
|
||||||
|
#include "system/ripple_ThreadName.cpp"
|
||||||
|
#include "system/ripple_Time.cpp"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
//#pragma warning (pop)
|
//#pragma warning (pop)
|
||||||
|
|||||||
@@ -38,6 +38,11 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/version.hpp>
|
||||||
|
#if BOOST_VERSION < 104700
|
||||||
|
#error Boost 1.47 or later is required
|
||||||
|
#endif
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
// Forward declaration
|
// Forward declaration
|
||||||
@@ -68,6 +73,9 @@ namespace boost {
|
|||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
// RippleTime
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
// ByteOrder
|
// ByteOrder
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// (nothing)
|
// (nothing)
|
||||||
@@ -103,5 +111,7 @@ namespace boost {
|
|||||||
|
|
||||||
#include "system/ripple_PlatformMacros.h"
|
#include "system/ripple_PlatformMacros.h"
|
||||||
#include "system/ripple_RandomNumbers.h"
|
#include "system/ripple_RandomNumbers.h"
|
||||||
|
#include "system/ripple_ThreadName.h"
|
||||||
|
#include "system/ripple_Time.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
82
modules/ripple_basics/system/ripple_ThreadName.cpp
Normal file
82
modules/ripple_basics/system/ripple_ThreadName.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
// VFALCO: TODO, use VFLIB_MSVC macro instead
|
||||||
|
#if _MSC_VER
|
||||||
|
|
||||||
|
void setCallingThreadName (char const* threadName)
|
||||||
|
{
|
||||||
|
struct ThreadInfo
|
||||||
|
{
|
||||||
|
DWORD dwType;
|
||||||
|
LPCSTR szName;
|
||||||
|
DWORD dwThreadID;
|
||||||
|
DWORD dwFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
ThreadInfo info;
|
||||||
|
|
||||||
|
info.dwType = 0x1000;
|
||||||
|
info.szName = threadName;
|
||||||
|
info.dwThreadID = GetCurrentThreadId ();
|
||||||
|
info.dwFlags = 0;
|
||||||
|
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
// This is a VisualStudio specific exception
|
||||||
|
RaiseException (0x406d1388, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
|
||||||
|
}
|
||||||
|
__except (EXCEPTION_CONTINUE_EXECUTION)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#ifdef PR_SET_NAME
|
||||||
|
#define HAVE_NAME_THREAD
|
||||||
|
extern void setCallingThreadName (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 setCallingThreadName(const char*)
|
||||||
|
{ ; }
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
24
modules/ripple_basics/system/ripple_ThreadName.h
Normal file
24
modules/ripple_basics/system/ripple_ThreadName.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef RIPPLE_THREADNAME_H
|
||||||
|
#define RIPPLE_THREADNAME_H
|
||||||
|
|
||||||
|
extern void setCallingThreadName (char const*);
|
||||||
|
|
||||||
|
#endif
|
||||||
54
modules/ripple_basics/system/ripple_Time.cpp
Normal file
54
modules/ripple_basics/system/ripple_Time.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
27
modules/ripple_basics/system/ripple_Time.h
Normal file
27
modules/ripple_basics/system/ripple_Time.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef RIPPLE_TIME_H
|
||||||
|
#define RIPPLE_TIME_H
|
||||||
|
|
||||||
|
boost::posix_time::ptime ptEpoch();
|
||||||
|
int iToSeconds(boost::posix_time::ptime ptWhen);
|
||||||
|
boost::posix_time::ptime ptFromSeconds(int iSeconds);
|
||||||
|
uint64_t utFromSeconds(int iSeconds);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -216,6 +216,18 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\system\ripple_ThreadName.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\system\ripple_Time.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="modules\ripple_client\ripple_client.cpp" />
|
<ClCompile Include="modules\ripple_client\ripple_client.cpp" />
|
||||||
<ClCompile Include="modules\ripple_db\ripple_db.cpp" />
|
<ClCompile Include="modules\ripple_db\ripple_db.cpp" />
|
||||||
<ClCompile Include="modules\ripple_json\json\json_reader.cpp">
|
<ClCompile Include="modules\ripple_json\json\json_reader.cpp">
|
||||||
@@ -1198,6 +1210,8 @@
|
|||||||
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
||||||
<ClInclude Include="modules\ripple_basics\system\ripple_PlatformMacros.h" />
|
<ClInclude Include="modules\ripple_basics\system\ripple_PlatformMacros.h" />
|
||||||
<ClInclude Include="modules\ripple_basics\system\ripple_RandomNumbers.h" />
|
<ClInclude Include="modules\ripple_basics\system\ripple_RandomNumbers.h" />
|
||||||
|
<ClInclude Include="modules\ripple_basics\system\ripple_ThreadName.h" />
|
||||||
|
<ClInclude Include="modules\ripple_basics\system\ripple_Time.h" />
|
||||||
<ClInclude Include="modules\ripple_basics\types\ripple_IntegerTypes.h" />
|
<ClInclude Include="modules\ripple_basics\types\ripple_IntegerTypes.h" />
|
||||||
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
||||||
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
||||||
|
|||||||
@@ -765,6 +765,12 @@
|
|||||||
<ClCompile Include="modules\ripple_basics\system\ripple_RandomNumbers.cpp">
|
<ClCompile Include="modules\ripple_basics\system\ripple_RandomNumbers.cpp">
|
||||||
<Filter>1. Modules\ripple_basics\system</Filter>
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\system\ripple_Time.cpp">
|
||||||
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\system\ripple_ThreadName.cpp">
|
||||||
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="database\sqlite3ext.h">
|
<ClInclude Include="database\sqlite3ext.h">
|
||||||
@@ -1424,6 +1430,12 @@
|
|||||||
<ClInclude Include="modules\ripple_basics\system\ripple_RandomNumbers.h">
|
<ClInclude Include="modules\ripple_basics\system\ripple_RandomNumbers.h">
|
||||||
<Filter>1. Modules\ripple_basics\system</Filter>
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="modules\ripple_basics\system\ripple_Time.h">
|
||||||
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="modules\ripple_basics\system\ripple_ThreadName.h">
|
||||||
|
<Filter>1. Modules\ripple_basics\system</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="SConstruct" />
|
<None Include="SConstruct" />
|
||||||
|
|||||||
@@ -112,13 +112,13 @@ void sigIntHandler(int)
|
|||||||
|
|
||||||
static void runAux(boost::asio::io_service& svc)
|
static void runAux(boost::asio::io_service& svc)
|
||||||
{
|
{
|
||||||
NameThread("aux");
|
setCallingThreadName("aux");
|
||||||
svc.run();
|
svc.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runIO(boost::asio::io_service& io)
|
static void runIO(boost::asio::io_service& io)
|
||||||
{
|
{
|
||||||
NameThread("io");
|
setCallingThreadName("io");
|
||||||
io.run();
|
io.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ void JobQueue::IOThread(boost::mutex::scoped_lock& sl)
|
|||||||
{ // call with a lock
|
{ // call with a lock
|
||||||
++mIOThreadCount;
|
++mIOThreadCount;
|
||||||
sl.unlock();
|
sl.unlock();
|
||||||
NameThread("IO+");
|
setCallingThreadName("IO+");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mIOService.poll();
|
mIOService.poll();
|
||||||
@@ -282,7 +282,7 @@ void JobQueue::IOThread(boost::mutex::scoped_lock& sl)
|
|||||||
{
|
{
|
||||||
WriteLog (lsWARNING, JobQueue) << "Exception in IOThread";
|
WriteLog (lsWARNING, JobQueue) << "Exception in IOThread";
|
||||||
}
|
}
|
||||||
NameThread("waiting");
|
setCallingThreadName("waiting");
|
||||||
sl.lock();
|
sl.lock();
|
||||||
--mIOThreadCount;
|
--mIOThreadCount;
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ void JobQueue::threadEntry()
|
|||||||
boost::mutex::scoped_lock sl(mJobLock);
|
boost::mutex::scoped_lock sl(mJobLock);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
NameThread("waiting");
|
setCallingThreadName("waiting");
|
||||||
// bool didIO = false;
|
// bool didIO = false;
|
||||||
while (mJobSet.empty() && !mShuttingDown)
|
while (mJobSet.empty() && !mShuttingDown)
|
||||||
{
|
{
|
||||||
@@ -325,7 +325,7 @@ void JobQueue::threadEntry()
|
|||||||
|
|
||||||
++(mJobCounts[type].second);
|
++(mJobCounts[type].second);
|
||||||
sl.unlock();
|
sl.unlock();
|
||||||
NameThread(Job::toString(type));
|
setCallingThreadName(Job::toString(type));
|
||||||
WriteLog (lsTRACE, JobQueue) << "Doing " << Job::toString(type) << " job";
|
WriteLog (lsTRACE, JobQueue) << "Doing " << Job::toString(type) << " job";
|
||||||
job.doJob();
|
job.doJob();
|
||||||
} // must destroy job without holding lock
|
} // must destroy job without holding lock
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ static void LogDeadLock(int dlTime)
|
|||||||
|
|
||||||
void LoadManager::threadEntry()
|
void LoadManager::threadEntry()
|
||||||
{
|
{
|
||||||
NameThread("loadmgr");
|
setCallingThreadName("loadmgr");
|
||||||
boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time();
|
boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time();
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ DECLARE_INSTANCE(WebSocketConnection);
|
|||||||
|
|
||||||
void WSDoor::startListening()
|
void WSDoor::startListening()
|
||||||
{
|
{
|
||||||
NameThread("websocket");
|
setCallingThreadName("websocket");
|
||||||
// Generate a single SSL context for use by all connections.
|
// Generate a single SSL context for use by all connections.
|
||||||
boost::shared_ptr<boost::asio::ssl::context> mCtx;
|
boost::shared_ptr<boost::asio::ssl::context> mCtx;
|
||||||
mCtx = boost::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
|
mCtx = boost::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ void printHelp(const po::options_description& desc)
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
NameThread("main");
|
setCallingThreadName("main");
|
||||||
int iResult = 0;
|
int iResult = 0;
|
||||||
po::variables_map vm; // Map of options.
|
po::variables_map vm; // Map of options.
|
||||||
|
|
||||||
@@ -269,14 +269,14 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
// No arguments. Run server.
|
// No arguments. Run server.
|
||||||
setupServer();
|
setupServer();
|
||||||
NameThread("io");
|
setCallingThreadName("io");
|
||||||
startServer();
|
startServer();
|
||||||
InstanceType::shutdown();
|
InstanceType::shutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Have a RPC command.
|
// Have a RPC command.
|
||||||
NameThread("rpc");
|
setCallingThreadName("rpc");
|
||||||
std::vector<std::string> vCmd = vm["parameters"].as<std::vector<std::string> >();
|
std::vector<std::string> vCmd = vm["parameters"].as<std::vector<std::string> >();
|
||||||
|
|
||||||
iResult = commandLineRPC(vCmd);
|
iResult = commandLineRPC(vCmd);
|
||||||
|
|||||||
@@ -28,43 +28,6 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "uint256.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
|
// DH support
|
||||||
//
|
//
|
||||||
@@ -97,39 +60,6 @@ DH* DH_der_load(const std::string& strDer)
|
|||||||
return d2i_DHparams(NULL, &pbuf, strDer.size());
|
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__
|
#ifdef __unix__
|
||||||
|
|
||||||
static pid_t pManager = static_cast<pid_t>(0);
|
static pid_t pManager = static_cast<pid_t>(0);
|
||||||
@@ -175,14 +105,14 @@ std::string DoSustain()
|
|||||||
_exit(0);
|
_exit(0);
|
||||||
if (pChild == 0)
|
if (pChild == 0)
|
||||||
{
|
{
|
||||||
NameThread("main");
|
setCallingThreadName("main");
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
signal(SIGUSR1, SIG_DFL);
|
signal(SIGUSR1, SIG_DFL);
|
||||||
signal(SIGUSR2, SIG_DFL);
|
signal(SIGUSR2, SIG_DFL);
|
||||||
return str(boost::format("Launching child %d") % childCount);;
|
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
|
do
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
#ifndef __UTILS__
|
#ifndef __UTILS__
|
||||||
#define __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>
|
#include <openssl/dh.h>
|
||||||
|
|
||||||
#define nothing() do {} while (0)
|
#define nothing() do {} while (0)
|
||||||
@@ -18,47 +11,9 @@
|
|||||||
|
|
||||||
#define isSetBit(x,y) (!!((x) & (y)))
|
#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);
|
DH* DH_der_load(const std::string& strDer);
|
||||||
std::string DH_der_gen(int iKeyLength);
|
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 bool HaveSustain();
|
||||||
extern std::string StopSustain();
|
extern std::string StopSustain();
|
||||||
extern std::string DoSustain();
|
extern std::string DoSustain();
|
||||||
|
|||||||
Reference in New Issue
Block a user