Skip to content

Commit a0761d7

Browse files
authored
Update util.h
1 parent ffaa438 commit a0761d7

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

src/util.h

+47-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Copyright (c) 2009-2022 Satoshi Nakamoto
2-
// Copyright (c) 2009-2022 The Bitcoin developers
1+
// Copyright (c) 2009-2024 Satoshi Nakamoto
2+
// Copyright (c) 2009-2024 The Bitcoin developers
3+
// Copyright (c) 2009-2024 The Litedoge developers
34
// Distributed under the MIT/X11 software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
66
#ifndef BITCOIN_UTIL_H
77
#define BITCOIN_UTIL_H
88

9+
#include "uint256.h"
10+
911
#ifndef WIN32
1012
#include <sys/types.h>
1113
#include <sys/time.h>
@@ -33,6 +35,12 @@
3335

3436
class uint256;
3537

38+
#include "netbase.h" // for AddTimeData
39+
40+
static const int32_t nOneHour = 60 * 60;
41+
static const int32_t nOneDay = 24 * 60 * 60;
42+
static const int64_t nOneWeek = 7 * 24 * 60 * 60;
43+
3644
static const int64_t COIN = 100000000;
3745
static const int64_t CENT = 1000000;
3846

@@ -65,6 +73,13 @@ static const int64_t CENT = 1000000;
6573
#define PRIpdx "tx"
6674
#define PRIpdu "tu"
6775
#define PRIpdd "td"
76+
#undef PRIu64
77+
#undef PRId64
78+
#undef PRIx64
79+
80+
#define PRIu64 "I64u"
81+
#define PRId64 "I64d"
82+
#define PRIx64 "I64x"
6883
#endif
6984

7085
// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
@@ -94,16 +109,24 @@ T* alignup(T* p)
94109
#endif
95110
#else
96111
#define MAX_PATH 1024
112+
inline void Sleep(int64_t n)
113+
{
114+
/*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
115+
So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
116+
boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
117+
}
97118
#endif
98119

99-
inline void MilliSleep(int64_t n)
100-
{
101-
#if BOOST_VERSION >= 105000
102-
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
120+
/* This GNU C extension enables the compiler to check the format string against the parameters provided.
121+
* X is the number of the "format string" parameter, and Y is the number of the first variadic parameter.
122+
* Parameters count from 1.
123+
*/
124+
#ifdef __GNUC__
125+
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y)))
103126
#else
104-
boost::this_thread::sleep(boost::posix_time::milliseconds(n));
127+
#define ATTR_WARN_PRINTF(X,Y)
105128
#endif
106-
}
129+
107130

108131

109132

@@ -205,11 +228,21 @@ int GetRandInt(int nMax);
205228
uint64_t GetRand(uint64_t nMax);
206229
uint256 GetRandHash();
207230
int64_t GetTime();
231+
int64_t GetTimeMillis();
232+
int64_t GetTimeMicros();
208233
void SetMockTime(int64_t nMockTimeIn);
209234
std::string FormatFullVersion();
210235
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
211236
void runCommand(std::string strCommand);
212237

238+
int64_t GetAdjustedTime();
239+
int64_t GetTimeOffset();
240+
int64_t GetNodesOffset();
241+
std::string FormatFullVersion();
242+
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
243+
void AddTimeData(const CNetAddr& ip, int64_t nTime);
244+
void runCommand(std::string strCommand);
245+
213246

214247

215248

@@ -511,6 +544,11 @@ inline void SetThreadPriority(int nPriority)
511544
setpriority(PRIO_PROCESS, 0, nPriority);
512545
#endif
513546
}
547+
548+
inline void ExitThread(size_t nExitCode)
549+
{
550+
pthread_exit((void*)nExitCode);
551+
}
514552
#endif
515553

516554
void RenameThread(const char* name);

0 commit comments

Comments
 (0)