0012-Work-around-lack-of-__thread-storage-qualifier-on-ol.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. From a01e2597158342b2959e3b541e09cc55f3f3e1ff Mon Sep 17 00:00:00 2001
  2. From: Carola Nitz <nitz.carola@googlemail.com>
  3. Date: Fri, 23 Feb 2018 13:16:41 +0100
  4. Subject: [PATCH 12/24] Work around lack of __thread storage qualifier on old
  5. macOS
  6. ---
  7. configure.ac | 4 +-
  8. include/vlc_fixups.h | 7 +++-
  9. po/POTFILES.in | 1 +
  10. src/Makefile.am | 1 +
  11. {compat => src/extras}/tdestroy.c | 67 ++++++++++++++++++-------------
  12. 5 files changed, 48 insertions(+), 32 deletions(-)
  13. rename {compat => src/extras}/tdestroy.c (59%)
  14. diff --git a/configure.ac b/configure.ac
  15. index a6ff64595e..b9c2a95c20 100644
  16. --- a/configure.ac
  17. +++ b/configure.ac
  18. @@ -591,8 +591,8 @@ dnl Check for system libs needed
  19. need_libc=false
  20. dnl Check for usual libc functions
  21. -AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap newlocale open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime uselocale])
  22. -AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get strverscmp pathconf])
  23. +AC_CHECK_FUNCS([accept4 daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pipe2 pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime tdestroy uselocale])
  24. +AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp pathconf])
  25. AC_REPLACE_FUNCS([gettimeofday])
  26. AC_CHECK_FUNC(fdatasync,,
  27. [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
  28. diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
  29. index 239cad4d77..e1a1d13e1e 100644
  30. --- a/include/vlc_fixups.h
  31. +++ b/include/vlc_fixups.h
  32. @@ -495,9 +495,12 @@ void *tdelete( const void *key, void **rootp, int(*cmp)(const void *, const void
  33. void twalk( const void *root, void(*action)(const void *nodep, VISIT which, int depth) );
  34. void *lfind( const void *key, const void *base, size_t *nmemb,
  35. size_t size, int(*cmp)(const void *, const void *) );
  36. -#endif /* HAVE_SEARCH_H */
  37. -#ifndef HAVE_TDESTROY
  38. void tdestroy( void *root, void (*free_node)(void *nodep) );
  39. +#else // HAVE_SEARCH_H
  40. +# ifndef HAVE_TDESTROY
  41. +void vlc_tdestroy( void *, void (*)(void *) );
  42. +# define tdestroy vlc_tdestroy
  43. +# endif
  44. #endif
  45. /* Random numbers */
  46. diff --git a/po/POTFILES.in b/po/POTFILES.in
  47. index 2b4319f140..cb7f3948e9 100644
  48. --- a/po/POTFILES.in
  49. +++ b/po/POTFILES.in
  50. @@ -68,6 +68,7 @@ src/config/help.c
  51. src/config/intf.c
  52. src/darwin/error.c
  53. src/extras/libc.c
  54. +src/extras/tdestroy.c
  55. src/input/access.c
  56. src/input/clock.c
  57. src/input/clock.h
  58. diff --git a/src/Makefile.am b/src/Makefile.am
  59. index 502990c70c..044169156c 100644
  60. --- a/src/Makefile.am
  61. +++ b/src/Makefile.am
  62. @@ -200,6 +200,7 @@ libvlccore_la_SOURCES = \
  63. config/getopt.c \
  64. config/vlc_getopt.h \
  65. extras/libc.c \
  66. + extras/tdestroy.c \
  67. modules/modules.h \
  68. modules/modules.c \
  69. modules/bank.c \
  70. diff --git a/compat/tdestroy.c b/src/extras/tdestroy.c
  71. similarity index 59%
  72. rename from compat/tdestroy.c
  73. rename to src/extras/tdestroy.c
  74. index 6bb3480957..5c54881553 100644
  75. --- a/compat/tdestroy.c
  76. +++ b/src/extras/tdestroy.c
  77. @@ -3,7 +3,7 @@
  78. * @brief replacement for GNU tdestroy()
  79. */
  80. /*****************************************************************************
  81. - * Copyright (C) 2009, 2018 Rémi Denis-Courmont
  82. + * Copyright (C) 2009 Rémi Denis-Courmont
  83. *
  84. * This program is free software; you can redistribute it and/or modify it
  85. * under the terms of the GNU Lesser General Public License as published by
  86. @@ -24,77 +24,88 @@
  87. # include "config.h"
  88. #endif
  89. -#include <assert.h>
  90. +#if defined(HAVE_SEARCH_H) && !defined(HAVE_TDESTROY) && defined(HAVE_TFIND)
  91. +
  92. #include <stdlib.h>
  93. -#ifdef HAVE_SEARCH_H
  94. -# include <search.h>
  95. -#endif
  96. +#include <assert.h>
  97. -#ifdef HAVE_TFIND
  98. -static __thread struct
  99. +#include <vlc_common.h>
  100. +#include <search.h>
  101. +
  102. +static struct
  103. {
  104. const void **tab;
  105. size_t count;
  106. -} list = { NULL, 0 };
  107. + vlc_mutex_t lock;
  108. +} list = { NULL, 0, VLC_STATIC_MUTEX };
  109. -static void list_nodes(const void *node, const VISIT which, const int depth)
  110. +static void list_nodes (const void *node, const VISIT which, const int depth)
  111. {
  112. (void) depth;
  113. if (which != postorder && which != leaf)
  114. return;
  115. - const void **tab = realloc(list.tab, sizeof (*tab) * (list.count + 1));
  116. - if (tab == NULL)
  117. - abort();
  118. + const void **tab = realloc (list.tab, sizeof (*tab) * (list.count + 1));
  119. + if (unlikely(tab == NULL))
  120. + abort ();
  121. tab[list.count] = *(const void **)node;
  122. list.tab = tab;
  123. list.count++;
  124. }
  125. -static __thread const void *smallest;
  126. +static struct
  127. +{
  128. + const void *node;
  129. + vlc_mutex_t lock;
  130. +} smallest = { NULL, VLC_STATIC_MUTEX };
  131. -static int cmp_smallest(const void *a, const void *b)
  132. +static int cmp_smallest (const void *a, const void *b)
  133. {
  134. if (a == b)
  135. return 0;
  136. - if (a == smallest)
  137. + if (a == smallest.node)
  138. return -1;
  139. - if (b == smallest)
  140. + if (likely(b == smallest.node))
  141. return +1;
  142. - abort();
  143. + abort ();
  144. }
  145. -void tdestroy(void *root, void (*freenode)(void *))
  146. +void vlc_tdestroy (void *root, void (*freenode) (void *))
  147. {
  148. const void **tab;
  149. size_t count;
  150. - assert(freenode != NULL);
  151. + assert (freenode != NULL);
  152. /* Enumerate nodes in order */
  153. - assert(list.count == 0);
  154. - twalk(root, list_nodes);
  155. + vlc_mutex_lock (&list.lock);
  156. + assert (list.count == 0);
  157. + twalk (root, list_nodes);
  158. tab = list.tab;
  159. count = list.count;
  160. list.tab = NULL;
  161. list.count = 0;
  162. + vlc_mutex_unlock (&list.lock);
  163. /* Destroy the tree */
  164. + vlc_mutex_lock (&smallest.lock);
  165. for (size_t i = 0; i < count; i++)
  166. {
  167. - void *node = (void *)(tab[i]);
  168. + void *node = tab[i];
  169. - smallest = node;
  170. - node = tdelete(node, &root, cmp_smallest);
  171. - assert(node != NULL);
  172. + smallest.node = node;
  173. + node = tdelete (node, &root, cmp_smallest);
  174. + assert (node != NULL);
  175. }
  176. + vlc_mutex_unlock (&smallest.lock);
  177. assert (root == NULL);
  178. /* Destroy the nodes */
  179. for (size_t i = 0; i < count; i++)
  180. - freenode((void *)(tab[i]));
  181. - free(tab);
  182. + freenode ((void *)(tab[i]));
  183. + free (tab);
  184. }
  185. -#endif /* HAVE_TFIND */
  186. +
  187. +#endif
  188. --
  189. 2.19.1