File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 9
9
10
10
#include " utiltime.h"
11
11
12
+ #include < atomic>
13
+
12
14
#include < boost/date_time/posix_time/posix_time.hpp>
13
15
#include < boost/thread.hpp>
14
16
15
- static int64_t nMockTime = 0 ; // !< For unit testing
17
+ static std::atomic< int64_t > nMockTime ( 0 ) ; // !< For unit testing
16
18
17
19
int64_t GetTime ()
18
20
{
19
- if (nMockTime) return nMockTime;
21
+ int64_t mocktime = nMockTime.load (std::memory_order_relaxed);
22
+ if (mocktime) return mocktime;
20
23
21
24
time_t now = time (NULL );
22
25
assert (now > 0 );
@@ -25,7 +28,7 @@ int64_t GetTime()
25
28
26
29
void SetMockTime (int64_t nMockTimeIn)
27
30
{
28
- nMockTime = nMockTimeIn;
31
+ nMockTime. store ( nMockTimeIn, std::memory_order_relaxed) ;
29
32
}
30
33
31
34
int64_t GetTimeMillis ()
@@ -52,7 +55,8 @@ int64_t GetSystemTimeInSeconds()
52
55
/* * Return a time useful for the debug log */
53
56
int64_t GetLogTimeMicros ()
54
57
{
55
- if (nMockTime) return nMockTime*1000000 ;
58
+ int64_t mocktime = nMockTime.load (std::memory_order_relaxed);
59
+ if (mocktime) return mocktime*1000000 ;
56
60
57
61
return GetTimeMicros ();
58
62
}
You can’t perform that action at this time.
0 commit comments