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

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