0015-Work-around-lack-of-__thread-storage-qualifier-on-ol.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. From 4e3308deb6b68b4d27c23abc6ee4df18345412c3 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 15/17] Work around lack of __thread storage qualifier on old
  5. macOS
  6. ---
  7. configure.ac | 4 +-
  8. include/vlc_fixups.h | 6 ++-
  9. po/POTFILES.in | 1 +
  10. src/Makefile.am | 1 +
  11. {compat => src/extras}/tdestroy.c | 67 ++++++++++++++++++-------------
  12. 5 files changed, 47 insertions(+), 32 deletions(-)
  13. rename {compat => src/extras}/tdestroy.c (59%)
  14. diff --git a/configure.ac b/configure.ac
  15. index 0d7af8a01e..97e61f716f 100644
  16. --- a/configure.ac
  17. +++ b/configure.ac
  18. @@ -647,8 +647,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 fstatat fstatvfs fork getmntent_r getenv getpwuid_r isatty memalign mkostemp mmap open_memstream newlocale pipe2 pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale])
  22. -AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll posix_memalign 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 fstatat fstatvfs fork getmntent_r getenv getpwuid_r isatty memalign mkostemp mmap open_memstream pipe2 pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale])
  24. +AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll posix_memalign 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 8fd01da0ce..16282aae9e 100644
  30. --- a/include/vlc_fixups.h
  31. +++ b/include/vlc_fixups.h
  32. @@ -505,9 +505,11 @@ void *lfind( const void *key, const void *base, size_t *nmemb,
  33. lfind((a),(b), &(unsigned){ (*(c) > UINT_MAX) ? UINT_MAX : *(c) }, (d),(e))
  34. #endif /* _WIN64 */
  35. -#ifndef HAVE_TDESTROY
  36. void tdestroy( void *root, void (*free_node)(void *nodep) );
  37. -#endif
  38. +# ifndef HAVE_TDESTROY
  39. +void vlc_tdestroy( void *, void (*)(void *) );
  40. +# define tdestroy vlc_tdestroy
  41. +# endif
  42. /* Random numbers */
  43. #ifndef HAVE_NRAND48
  44. diff --git a/po/POTFILES.in b/po/POTFILES.in
  45. index 0cc772061a..55aaba6901 100644
  46. --- a/po/POTFILES.in
  47. +++ b/po/POTFILES.in
  48. @@ -66,6 +66,7 @@ src/config/help.c
  49. src/config/intf.c
  50. src/darwin/error.c
  51. src/extras/libc.c
  52. +src/extras/tdestroy.c
  53. src/input/access.c
  54. src/input/decoder.c
  55. src/input/decoder.h
  56. diff --git a/src/Makefile.am b/src/Makefile.am
  57. index b6c5996837..978a0674b1 100644
  58. --- a/src/Makefile.am
  59. +++ b/src/Makefile.am
  60. @@ -210,6 +210,7 @@ libvlccore_la_SOURCES = \
  61. config/getopt.c \
  62. config/vlc_getopt.h \
  63. extras/libc.c \
  64. + extras/tdestroy.c \
  65. media_source/media_source.c \
  66. media_source/media_source.h \
  67. media_source/media_tree.c \
  68. diff --git a/compat/tdestroy.c b/src/extras/tdestroy.c
  69. similarity index 59%
  70. rename from compat/tdestroy.c
  71. rename to src/extras/tdestroy.c
  72. index 6bb3480957..5c54881553 100644
  73. --- a/compat/tdestroy.c
  74. +++ b/src/extras/tdestroy.c
  75. @@ -3,7 +3,7 @@
  76. * @brief replacement for GNU tdestroy()
  77. */
  78. /*****************************************************************************
  79. - * Copyright (C) 2009, 2018 Rémi Denis-Courmont
  80. + * Copyright (C) 2009 Rémi Denis-Courmont
  81. *
  82. * This program is free software; you can redistribute it and/or modify it
  83. * under the terms of the GNU Lesser General Public License as published by
  84. @@ -24,77 +24,88 @@
  85. # include "config.h"
  86. #endif
  87. -#include <assert.h>
  88. +#if defined(HAVE_SEARCH_H) && !defined(HAVE_TDESTROY) && defined(HAVE_TFIND)
  89. +
  90. #include <stdlib.h>
  91. -#ifdef HAVE_SEARCH_H
  92. -# include <search.h>
  93. -#endif
  94. +#include <assert.h>
  95. -#ifdef HAVE_TFIND
  96. -static __thread struct
  97. +#include <vlc_common.h>
  98. +#include <search.h>
  99. +
  100. +static struct
  101. {
  102. const void **tab;
  103. size_t count;
  104. -} list = { NULL, 0 };
  105. + vlc_mutex_t lock;
  106. +} list = { NULL, 0, VLC_STATIC_MUTEX };
  107. -static void list_nodes(const void *node, const VISIT which, const int depth)
  108. +static void list_nodes (const void *node, const VISIT which, const int depth)
  109. {
  110. (void) depth;
  111. if (which != postorder && which != leaf)
  112. return;
  113. - const void **tab = realloc(list.tab, sizeof (*tab) * (list.count + 1));
  114. - if (tab == NULL)
  115. - abort();
  116. + const void **tab = realloc (list.tab, sizeof (*tab) * (list.count + 1));
  117. + if (unlikely(tab == NULL))
  118. + abort ();
  119. tab[list.count] = *(const void **)node;
  120. list.tab = tab;
  121. list.count++;
  122. }
  123. -static __thread const void *smallest;
  124. +static struct
  125. +{
  126. + const void *node;
  127. + vlc_mutex_t lock;
  128. +} smallest = { NULL, VLC_STATIC_MUTEX };
  129. -static int cmp_smallest(const void *a, const void *b)
  130. +static int cmp_smallest (const void *a, const void *b)
  131. {
  132. if (a == b)
  133. return 0;
  134. - if (a == smallest)
  135. + if (a == smallest.node)
  136. return -1;
  137. - if (b == smallest)
  138. + if (likely(b == smallest.node))
  139. return +1;
  140. - abort();
  141. + abort ();
  142. }
  143. -void tdestroy(void *root, void (*freenode)(void *))
  144. +void vlc_tdestroy (void *root, void (*freenode) (void *))
  145. {
  146. const void **tab;
  147. size_t count;
  148. - assert(freenode != NULL);
  149. + assert (freenode != NULL);
  150. /* Enumerate nodes in order */
  151. - assert(list.count == 0);
  152. - twalk(root, list_nodes);
  153. + vlc_mutex_lock (&list.lock);
  154. + assert (list.count == 0);
  155. + twalk (root, list_nodes);
  156. tab = list.tab;
  157. count = list.count;
  158. list.tab = NULL;
  159. list.count = 0;
  160. + vlc_mutex_unlock (&list.lock);
  161. /* Destroy the tree */
  162. + vlc_mutex_lock (&smallest.lock);
  163. for (size_t i = 0; i < count; i++)
  164. {
  165. - void *node = (void *)(tab[i]);
  166. + void *node = tab[i];
  167. - smallest = node;
  168. - node = tdelete(node, &root, cmp_smallest);
  169. - assert(node != NULL);
  170. + smallest.node = node;
  171. + node = tdelete (node, &root, cmp_smallest);
  172. + assert (node != NULL);
  173. }
  174. + vlc_mutex_unlock (&smallest.lock);
  175. assert (root == NULL);
  176. /* Destroy the nodes */
  177. for (size_t i = 0; i < count; i++)
  178. - freenode((void *)(tab[i]));
  179. - free(tab);
  180. + freenode ((void *)(tab[i]));
  181. + free (tab);
  182. }
  183. -#endif /* HAVE_TFIND */
  184. +
  185. +#endif
  186. --
  187. 2.21.1 (Apple Git-122.3)