File tree 3 files changed +3
-27
lines changed
3 files changed +3
-27
lines changed Original file line number Diff line number Diff line change @@ -58,18 +58,11 @@ class ConditionVariable {
58
58
// Returns true otherwise
59
59
template <class Predicate >
60
60
bool TimedWait (pthread_mutex_t * lock, Predicate predicate, int milliseconds) {
61
- timespec end_time, current_time;
62
- clock_gettime (CLOCK_REALTIME, &end_time);
63
- end_time.tv_nsec += milliseconds * kNanosecondsPerMillisecond ;
64
- int64_t end_time_ms = TimespecToMs (end_time);
65
- NormalizeTimespec (&end_time);
66
-
67
- clock_gettime (CLOCK_REALTIME, ¤t_time);
68
- int64_t current_time_ms = TimespecToMs (current_time);
61
+ int64_t end_time_ms = TimespecToMs (MsToAbsoluteTimespec (milliseconds));
62
+ int64_t current_time_ms = TimespecToMs (MsToAbsoluteTimespec (0 ));
69
63
while (!predicate () && current_time_ms < end_time_ms) {
70
64
TimedWait (lock, end_time_ms - current_time_ms);
71
- clock_gettime (CLOCK_REALTIME, ¤t_time);
72
- current_time_ms = TimespecToMs (current_time);
65
+ current_time_ms = TimespecToMs (MsToAbsoluteTimespec (0 ));
73
66
}
74
67
// If time isn't up, AND the predicate is true, then we return true.
75
68
// False otherwise.
Original file line number Diff line number Diff line change @@ -63,12 +63,6 @@ inline void Sleep(int64_t milliseconds) {
63
63
}
64
64
65
65
#if !FIREBASE_PLATFORM_WINDOWS
66
- // Utility function for normalizing a timespec.
67
- inline void NormalizeTimespec (timespec * t) {
68
- t->tv_sec += t->tv_nsec / kNanosecondsPerSecond ;
69
- t->tv_nsec %= kNanosecondsPerSecond ;
70
- }
71
-
72
66
// Utility function, for converting a timespec struct into milliseconds.
73
67
inline int64_t TimespecToMs (timespec tm ) {
74
68
return tm .tv_sec * firebase::internal::kMillisecondsPerSecond +
Original file line number Diff line number Diff line change 24
24
namespace {
25
25
26
26
#ifndef WIN32
27
- // Test that the normalize function works, for timespecs
28
- TEST (TimeTests, NormalizeTest) {
29
- timespec t;
30
- t.tv_sec = 2 ;
31
- t.tv_nsec = firebase::internal::kNanosecondsPerSecond * 5.5 ;
32
- firebase::internal::NormalizeTimespec (&t);
33
-
34
- EXPECT_EQ (t.tv_sec , 7 );
35
- EXPECT_EQ (t.tv_nsec , firebase::internal::kNanosecondsPerSecond * 0.5 );
36
- }
37
-
38
27
// Test the various conversions to and from timespecs.
39
28
TEST (TimeTests, ConversionTests) {
40
29
timespec t;
You can’t perform that action at this time.
0 commit comments