History

timer: remove unused code

Kacper Michajłow committed 3 years ago

Commit 71e888c1 parent 751790c3 files · +0 −53Browse files

Unified · Split

3 files
  1. osdep/timer.c +0 −30
  2. osdep/timer.h +0 −7
  3. test/timer.c +0 −16
osdep/timer.c+0−30
@@ -16,7 +16,6 @@ · 15 unmodified lines
16 */16 */
17 17
18#include <stdlib.h>18#include <stdlib.h>
19#include <pthread.h>
20#include <time.h>19#include <time.h>
21#include <unistd.h>20#include <unistd.h>
22#include <sys/time.h>21#include <sys/time.h>
@@ -66,32 +65,3 @@ int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec) · 43 unmodified lines
66 return 1;65 return 1;
67 return time_ns + ti;66 return time_ns + ti;
68}67}
69
70#if !HAVE_WIN32_THREADS
71
72struct timespec mp_time_ns_to_realtime(int64_t time_ns)
73{
74 struct timespec ts = {0};
75 if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
76 return ts;
77 int64_t time_rel = time_ns - mp_time_ns();
78
79 // clamp to 1000 days in the future
80 time_rel = MPMIN(time_rel, 1000 * 24 * 60 * 60 * INT64_C(1000000000));
81 ts.tv_sec += time_rel / INT64_C(1000000000);
82 ts.tv_nsec += time_rel % INT64_C(1000000000);
83
84 if (ts.tv_nsec >= INT64_C(1000000000)) {
85 ts.tv_sec++;
86 ts.tv_nsec -= INT64_C(1000000000);
87 }
88
89 return ts;
90}
91
92struct timespec mp_rel_time_to_timespec(double timeout_sec)
93{
94 return mp_time_ns_to_realtime(mp_time_ns_add(mp_time_ns(), timeout_sec));
95}
96
97#endif
osdep/timer.h+0−7
@@ -60,11 +60,4 @@ void mp_end_hires_timers(int resolution_ms); · 59 unmodified lines
60// Takes care of possible overflows. Never returns a negative or 0 time.60// Takes care of possible overflows. Never returns a negative or 0 time.
61int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec);61int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec);
62 62
63// Convert the mp time in nanoseconds to a timespec using CLOCK_REALTIME.
64struct timespec mp_time_ns_to_realtime(int64_t time_ns);
65
66// Convert the relative timeout in seconds to a timespec.
67// The timespec is absolute, using CLOCK_REALTIME.
68struct timespec mp_rel_time_to_timespec(double timeout_sec);
69
70#endif /* MPLAYER_TIMER_H */63#endif /* MPLAYER_TIMER_H */
test/timer.c+0−16
@@ -1,7 +1,6 @@
1#include "common/common.h"1#include "common/common.h"
2#include "osdep/timer.h"2#include "osdep/timer.h"
3#include "test_utils.h"3#include "test_utils.h"
4#include "config.h"
5 4
6#include <time.h>5#include <time.h>
7#include <sys/time.h>6#include <sys/time.h>
@@ -38,20 +37,5 @@ int main(void) · 30 unmodified lines
38 assert_int_equal(mp_time_ns_add(test2, 20.44), INT64_MAX);37 assert_int_equal(mp_time_ns_add(test2, 20.44), INT64_MAX);
39 }38 }
40 39
41#if !HAVE_WIN32_THREADS
42 /* conversion */
43 {
44 struct timeval tv;
45 struct timespec ts;
46 gettimeofday(&tv, NULL);
47 ts = mp_time_ns_to_realtime(mp_time_ns());
48 assert_true(llabs(tv.tv_sec - ts.tv_sec) <= 1);
49
50 gettimeofday(&tv, NULL);
51 ts = mp_rel_time_to_timespec(0.0);
52 assert_true(llabs(tv.tv_sec - ts.tv_sec) <= 1);
53 }
54#endif
55
56 return 0;40 return 0;
57}41}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t