summaryrefslogtreecommitdiffstats
path: root/package/vlc/0007-posix-remove-ancient-run-time-fallback-to-real-time-.patch
blob: 4fc639e2229c8e6579a5e97814a6b4059380b782 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
From 5d561e1e2dcde3c9fca4d925f12447009d0d4a4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
Date: Wed, 18 Apr 2018 17:23:57 +0300
Subject: [PATCH] posix: remove ancient run-time fallback to real-time clock
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

posix: remove ancient run-time fallback to real-time clock

For hysterical raisins, GNU/Linux and possibly some other OSes still
report that monotonic clock must be checked at run-time, although I
doubt that VLC or even current glibc would run on such old kernel.

Drop that to simplify and avoid the systematic one-time init check.

Downloaded from upstream commit to fix build error on m68k:

posix/thread.c:79:5: warning: #warning Monotonic clock not available. Expect timing issues. [-Wcpp]
 #   warning Monotonic clock not available. Expect timing issues.
     ^~~~~~~
posix/thread.c: In function ‘vlc_clock_setup_once’:
posix/thread.c:88:18: error: lvalue required as left operand of assignment
     vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;

Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
---
 src/posix/thread.c | 96 +++++++-----------------------------------------------
 1 file changed, 11 insertions(+), 85 deletions(-)

diff --git a/src/posix/thread.c b/src/posix/thread.c
index dab8b71f97..8878941913 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -51,62 +51,16 @@
 # include <sys/pset.h>
 #endif
 
-#if !defined (_POSIX_TIMERS)
-# define _POSIX_TIMERS (-1)
-#endif
-#if !defined (_POSIX_CLOCK_SELECTION)
-/* Clock selection was defined in 2001 and became mandatory in 2008. */
-# define _POSIX_CLOCK_SELECTION (-1)
-#endif
-#if !defined (_POSIX_MONOTONIC_CLOCK)
-# define _POSIX_MONOTONIC_CLOCK (-1)
-#endif
-
-#if (_POSIX_TIMERS > 0)
 static unsigned vlc_clock_prec;
 
-# if (_POSIX_MONOTONIC_CLOCK > 0) && (_POSIX_CLOCK_SELECTION > 0)
-/* Compile-time POSIX monotonic clock support */
-#  define vlc_clock_id (CLOCK_MONOTONIC)
-
-# elif (_POSIX_MONOTONIC_CLOCK == 0) && (_POSIX_CLOCK_SELECTION > 0)
-/* Run-time POSIX monotonic clock support (see clock_setup() below) */
-static clockid_t vlc_clock_id;
-
-# else
-/* No POSIX monotonic clock support */
-#   define vlc_clock_id (CLOCK_REALTIME)
-#   warning Monotonic clock not available. Expect timing issues.
-
-# endif /* _POSIX_MONOTONIC_CLOKC */
-
 static void vlc_clock_setup_once (void)
 {
-# if (_POSIX_MONOTONIC_CLOCK == 0)
-    long val = sysconf (_SC_MONOTONIC_CLOCK);
-    assert (val != 0);
-    vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;
-# endif
-
     struct timespec res;
-    if (unlikely(clock_getres (vlc_clock_id, &res) != 0 || res.tv_sec != 0))
+    if (unlikely(clock_getres(CLOCK_MONOTONIC, &res) != 0 || res.tv_sec != 0))
         abort ();
     vlc_clock_prec = (res.tv_nsec + 500) / 1000;
 }
 
-static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
-
-# define vlc_clock_setup() \
-    pthread_once(&vlc_clock_once, vlc_clock_setup_once)
-
-#else /* _POSIX_TIMERS */
-
-# include <sys/time.h> /* gettimeofday() */
-
-# define vlc_clock_setup() (void)0
-# warning Monotonic clock not available. Expect timing issues.
-#endif /* _POSIX_TIMERS */
-
 static struct timespec mtime_to_ts (mtime_t date)
 {
     lldiv_t d = lldiv (date, CLOCK_FREQ);
@@ -233,14 +187,11 @@ void vlc_cond_init (vlc_cond_t *p_condvar)
 {
     pthread_condattr_t attr;
 
-    if (unlikely(pthread_condattr_init (&attr)))
-        abort ();
-#if (_POSIX_CLOCK_SELECTION > 0)
-    vlc_clock_setup ();
-    pthread_condattr_setclock (&attr, vlc_clock_id);
-#endif
-    if (unlikely(pthread_cond_init (p_condvar, &attr)))
+    if (unlikely(pthread_condattr_init (&attr))
+     || unlikely(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
+     || unlikely(pthread_cond_init (p_condvar, &attr)))
         abort ();
+
     pthread_condattr_destroy (&attr);
 }
 
@@ -625,44 +576,27 @@ void vlc_control_cancel (int cmd, ...)
 
 mtime_t mdate (void)
 {
-#if (_POSIX_TIMERS > 0)
     struct timespec ts;
 
-    vlc_clock_setup ();
-    if (unlikely(clock_gettime (vlc_clock_id, &ts) != 0))
+    if (unlikely(clock_gettime(CLOCK_MONOTONIC, &ts) != 0))
         abort ();
 
     return (INT64_C(1000000) * ts.tv_sec) + (ts.tv_nsec / 1000);
-
-#else
-    struct timeval tv;
-
-    if (unlikely(gettimeofday (&tv, NULL) != 0))
-        abort ();
-    return (INT64_C(1000000) * tv.tv_sec) + tv.tv_usec;
-
-#endif
 }
 
 #undef mwait
 void mwait (mtime_t deadline)
 {
-#if (_POSIX_CLOCK_SELECTION > 0)
-    vlc_clock_setup ();
+    static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
+
     /* If the deadline is already elapsed, or within the clock precision,
      * do not even bother the system timer. */
+    pthread_once(&vlc_clock_once, vlc_clock_setup_once);
     deadline -= vlc_clock_prec;
 
     struct timespec ts = mtime_to_ts (deadline);
 
-    while (clock_nanosleep (vlc_clock_id, TIMER_ABSTIME, &ts, NULL) == EINTR);
-
-#else
-    deadline -= mdate ();
-    if (deadline > 0)
-        msleep (deadline);
-
-#endif
+    while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) == EINTR);
 }
 
 #undef msleep
@@ -670,15 +604,7 @@ void msleep (mtime_t delay)
 {
     struct timespec ts = mtime_to_ts (delay);
 
-#if (_POSIX_CLOCK_SELECTION > 0)
-    vlc_clock_setup ();
-    while (clock_nanosleep (vlc_clock_id, 0, &ts, &ts) == EINTR);
-
-#else
-    while (nanosleep (&ts, &ts) == -1)
-        assert (errno == EINTR);
-
-#endif
+    while (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts) == EINTR);
 }
 
 unsigned vlc_GetCPUCount(void)
-- 
2.14.4

OpenPOWER on IntegriCloud