0007-posix-remove-ancient-run-time-fallback-to-real-time-.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. From 5d561e1e2dcde3c9fca4d925f12447009d0d4a4c Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
  3. Date: Wed, 18 Apr 2018 17:23:57 +0300
  4. Subject: [PATCH] posix: remove ancient run-time fallback to real-time clock
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. posix: remove ancient run-time fallback to real-time clock
  9. For hysterical raisins, GNU/Linux and possibly some other OSes still
  10. report that monotonic clock must be checked at run-time, although I
  11. doubt that VLC or even current glibc would run on such old kernel.
  12. Drop that to simplify and avoid the systematic one-time init check.
  13. Downloaded from upstream commit to fix build error on m68k:
  14. posix/thread.c:79:5: warning: #warning Monotonic clock not available. Expect timing issues. [-Wcpp]
  15. # warning Monotonic clock not available. Expect timing issues.
  16. ^~~~~~~
  17. posix/thread.c: In function ‘vlc_clock_setup_once’:
  18. posix/thread.c:88:18: error: lvalue required as left operand of assignment
  19. vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;
  20. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  21. ---
  22. src/posix/thread.c | 96 +++++++-----------------------------------------------
  23. 1 file changed, 11 insertions(+), 85 deletions(-)
  24. diff --git a/src/posix/thread.c b/src/posix/thread.c
  25. index dab8b71f97..8878941913 100644
  26. --- a/src/posix/thread.c
  27. +++ b/src/posix/thread.c
  28. @@ -51,62 +51,16 @@
  29. # include <sys/pset.h>
  30. #endif
  31. -#if !defined (_POSIX_TIMERS)
  32. -# define _POSIX_TIMERS (-1)
  33. -#endif
  34. -#if !defined (_POSIX_CLOCK_SELECTION)
  35. -/* Clock selection was defined in 2001 and became mandatory in 2008. */
  36. -# define _POSIX_CLOCK_SELECTION (-1)
  37. -#endif
  38. -#if !defined (_POSIX_MONOTONIC_CLOCK)
  39. -# define _POSIX_MONOTONIC_CLOCK (-1)
  40. -#endif
  41. -
  42. -#if (_POSIX_TIMERS > 0)
  43. static unsigned vlc_clock_prec;
  44. -# if (_POSIX_MONOTONIC_CLOCK > 0) && (_POSIX_CLOCK_SELECTION > 0)
  45. -/* Compile-time POSIX monotonic clock support */
  46. -# define vlc_clock_id (CLOCK_MONOTONIC)
  47. -
  48. -# elif (_POSIX_MONOTONIC_CLOCK == 0) && (_POSIX_CLOCK_SELECTION > 0)
  49. -/* Run-time POSIX monotonic clock support (see clock_setup() below) */
  50. -static clockid_t vlc_clock_id;
  51. -
  52. -# else
  53. -/* No POSIX monotonic clock support */
  54. -# define vlc_clock_id (CLOCK_REALTIME)
  55. -# warning Monotonic clock not available. Expect timing issues.
  56. -
  57. -# endif /* _POSIX_MONOTONIC_CLOKC */
  58. -
  59. static void vlc_clock_setup_once (void)
  60. {
  61. -# if (_POSIX_MONOTONIC_CLOCK == 0)
  62. - long val = sysconf (_SC_MONOTONIC_CLOCK);
  63. - assert (val != 0);
  64. - vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;
  65. -# endif
  66. -
  67. struct timespec res;
  68. - if (unlikely(clock_getres (vlc_clock_id, &res) != 0 || res.tv_sec != 0))
  69. + if (unlikely(clock_getres(CLOCK_MONOTONIC, &res) != 0 || res.tv_sec != 0))
  70. abort ();
  71. vlc_clock_prec = (res.tv_nsec + 500) / 1000;
  72. }
  73. -static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
  74. -
  75. -# define vlc_clock_setup() \
  76. - pthread_once(&vlc_clock_once, vlc_clock_setup_once)
  77. -
  78. -#else /* _POSIX_TIMERS */
  79. -
  80. -# include <sys/time.h> /* gettimeofday() */
  81. -
  82. -# define vlc_clock_setup() (void)0
  83. -# warning Monotonic clock not available. Expect timing issues.
  84. -#endif /* _POSIX_TIMERS */
  85. -
  86. static struct timespec mtime_to_ts (mtime_t date)
  87. {
  88. lldiv_t d = lldiv (date, CLOCK_FREQ);
  89. @@ -233,14 +187,11 @@ void vlc_cond_init (vlc_cond_t *p_condvar)
  90. {
  91. pthread_condattr_t attr;
  92. - if (unlikely(pthread_condattr_init (&attr)))
  93. - abort ();
  94. -#if (_POSIX_CLOCK_SELECTION > 0)
  95. - vlc_clock_setup ();
  96. - pthread_condattr_setclock (&attr, vlc_clock_id);
  97. -#endif
  98. - if (unlikely(pthread_cond_init (p_condvar, &attr)))
  99. + if (unlikely(pthread_condattr_init (&attr))
  100. + || unlikely(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
  101. + || unlikely(pthread_cond_init (p_condvar, &attr)))
  102. abort ();
  103. +
  104. pthread_condattr_destroy (&attr);
  105. }
  106. @@ -625,44 +576,27 @@ void vlc_control_cancel (int cmd, ...)
  107. mtime_t mdate (void)
  108. {
  109. -#if (_POSIX_TIMERS > 0)
  110. struct timespec ts;
  111. - vlc_clock_setup ();
  112. - if (unlikely(clock_gettime (vlc_clock_id, &ts) != 0))
  113. + if (unlikely(clock_gettime(CLOCK_MONOTONIC, &ts) != 0))
  114. abort ();
  115. return (INT64_C(1000000) * ts.tv_sec) + (ts.tv_nsec / 1000);
  116. -
  117. -#else
  118. - struct timeval tv;
  119. -
  120. - if (unlikely(gettimeofday (&tv, NULL) != 0))
  121. - abort ();
  122. - return (INT64_C(1000000) * tv.tv_sec) + tv.tv_usec;
  123. -
  124. -#endif
  125. }
  126. #undef mwait
  127. void mwait (mtime_t deadline)
  128. {
  129. -#if (_POSIX_CLOCK_SELECTION > 0)
  130. - vlc_clock_setup ();
  131. + static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
  132. +
  133. /* If the deadline is already elapsed, or within the clock precision,
  134. * do not even bother the system timer. */
  135. + pthread_once(&vlc_clock_once, vlc_clock_setup_once);
  136. deadline -= vlc_clock_prec;
  137. struct timespec ts = mtime_to_ts (deadline);
  138. - while (clock_nanosleep (vlc_clock_id, TIMER_ABSTIME, &ts, NULL) == EINTR);
  139. -
  140. -#else
  141. - deadline -= mdate ();
  142. - if (deadline > 0)
  143. - msleep (deadline);
  144. -
  145. -#endif
  146. + while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) == EINTR);
  147. }
  148. #undef msleep
  149. @@ -670,15 +604,7 @@ void msleep (mtime_t delay)
  150. {
  151. struct timespec ts = mtime_to_ts (delay);
  152. -#if (_POSIX_CLOCK_SELECTION > 0)
  153. - vlc_clock_setup ();
  154. - while (clock_nanosleep (vlc_clock_id, 0, &ts, &ts) == EINTR);
  155. -
  156. -#else
  157. - while (nanosleep (&ts, &ts) == -1)
  158. - assert (errno == EINTR);
  159. -
  160. -#endif
  161. + while (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts) == EINTR);
  162. }
  163. unsigned vlc_GetCPUCount(void)
  164. --
  165. 2.14.4