File tree Expand file tree Collapse file tree 3 files changed +3
-27
lines changed Expand file tree Collapse file tree 3 files changed +3
-27
lines changed Original file line number Diff line number Diff line change @@ -58,18 +58,11 @@ class ConditionVariable {
5858 // Returns true otherwise
5959 template <class Predicate >
6060 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 ));
6963 while (!predicate () && current_time_ms < end_time_ms) {
7064 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 ));
7366 }
7467 // If time isn't up, AND the predicate is true, then we return true.
7568 // False otherwise.
Original file line number Diff line number Diff line change @@ -63,12 +63,6 @@ inline void Sleep(int64_t milliseconds) {
6363}
6464
6565#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-
7266// Utility function, for converting a timespec struct into milliseconds.
7367inline int64_t TimespecToMs (timespec tm) {
7468 return tm.tv_sec * firebase::internal::kMillisecondsPerSecond +
Original file line number Diff line number Diff line change 2424namespace {
2525
2626#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-
3827// Test the various conversions to and from timespecs.
3928TEST (TimeTests, ConversionTests) {
4029 timespec t;
You can’t perform that action at this time.
0 commit comments