#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
-#include <boost/date_time/gregorian/gregorian_types.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
#endif
#include <stdarg.h>
#define UBEGIN(a) ((unsigned char*)&(a))
#define UEND(a) ((unsigned char*)&((&(a))[1]))
-#define UVOIDBEGIN(a) ((void*)&(a))
-#define CVOIDBEGIN(a) ((const void*)&(a))
-#define UINTBEGIN(a) ((uint32_t*)&(a))
-#define CUINTBEGIN(a) ((const uint32_t*)&(a))
-
#ifndef THROW_WITH_STACKTRACE
#define THROW_WITH_STACKTRACE(exception) \
{ \
#define MAX_PATH 1024
inline void Sleep(int64_t n)
{
- this_thread::sleep_for(std::chrono::milliseconds(n));
+ /*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
+ So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
+ boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
}
#endif
int GetRandInt(int nMax);
uint64_t GetRand(uint64_t nMax);
uint256 GetRandHash();
+void FillRand(uint8_t *buffer, size_t nCount);
int64_t GetTime();
int64_t GetTimeMillis();
int64_t GetTimeMicros();
return strprintf("%" PRId64, n);
}
-inline std::string itostr(int n)
-{
- return strprintf("%d", n);
-}
-
-inline int64_t atoi64(const char* psz)
+inline int64_t strtoll(const char* psz)
{
-#ifdef _MSC_VER
- return _atoi64(psz);
-#else
return strtoll(psz, NULL, 10);
-#endif
}
-inline int64_t atoi64(const std::string& str)
+inline int64_t strtoll(const std::string& str)
{
-#ifdef _MSC_VER
- return _atoi64(str.c_str());
-#else
return strtoll(str.c_str(), NULL, 10);
-#endif
}
inline int32_t strtol(const char* psz)
inline int64_t GetTimeMillis()
{
- return (boost::posix_time::microsec_clock::universal_time() -
- boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
+ return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
inline int64_t GetTimeMicros()
{
- return (boost::posix_time::microsec_clock::universal_time() -
- boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
+ return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);