|
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 |
3 | 4 | // Distributed under the MIT/X11 software license, see the accompanying
|
4 | 5 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 |
| - |
6 | 6 | #ifndef BITCOIN_UTIL_H
|
7 | 7 | #define BITCOIN_UTIL_H
|
8 | 8 |
|
| 9 | +#include "uint256.h" |
| 10 | + |
9 | 11 | #ifndef WIN32
|
10 | 12 | #include <sys/types.h>
|
11 | 13 | #include <sys/time.h>
|
|
33 | 35 |
|
34 | 36 | class uint256;
|
35 | 37 |
|
| 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 | + |
36 | 44 | static const int64_t COIN = 100000000;
|
37 | 45 | static const int64_t CENT = 1000000;
|
38 | 46 |
|
@@ -65,6 +73,13 @@ static const int64_t CENT = 1000000;
|
65 | 73 | #define PRIpdx "tx"
|
66 | 74 | #define PRIpdu "tu"
|
67 | 75 | #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" |
68 | 83 | #endif
|
69 | 84 |
|
70 | 85 | // 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)
|
94 | 109 | #endif
|
95 | 110 | #else
|
96 | 111 | #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 | +} |
97 | 118 | #endif
|
98 | 119 |
|
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))) |
103 | 126 | #else
|
104 |
| - boost::this_thread::sleep(boost::posix_time::milliseconds(n)); |
| 127 | +#define ATTR_WARN_PRINTF(X,Y) |
105 | 128 | #endif
|
106 |
| -} |
| 129 | + |
107 | 130 |
|
108 | 131 |
|
109 | 132 |
|
@@ -205,11 +228,21 @@ int GetRandInt(int nMax);
|
205 | 228 | uint64_t GetRand(uint64_t nMax);
|
206 | 229 | uint256 GetRandHash();
|
207 | 230 | int64_t GetTime();
|
| 231 | +int64_t GetTimeMillis(); |
| 232 | +int64_t GetTimeMicros(); |
208 | 233 | void SetMockTime(int64_t nMockTimeIn);
|
209 | 234 | std::string FormatFullVersion();
|
210 | 235 | std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
|
211 | 236 | void runCommand(std::string strCommand);
|
212 | 237 |
|
| 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 | + |
213 | 246 |
|
214 | 247 |
|
215 | 248 |
|
@@ -511,6 +544,11 @@ inline void SetThreadPriority(int nPriority)
|
511 | 544 | setpriority(PRIO_PROCESS, 0, nPriority);
|
512 | 545 | #endif
|
513 | 546 | }
|
| 547 | + |
| 548 | +inline void ExitThread(size_t nExitCode) |
| 549 | +{ |
| 550 | + pthread_exit((void*)nExitCode); |
| 551 | +} |
514 | 552 | #endif
|
515 | 553 |
|
516 | 554 | void RenameThread(const char* name);
|
|
0 commit comments