0003-thread-Posix-Mutex-Cond-use-constexpr-only-with-glib.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From 42a5f0c4435757505bd515b68c2a27e8f7565f34 Mon Sep 17 00:00:00 2001
  2. From: Max Kellermann <max@duempel.org>
  3. Date: Tue, 25 Aug 2015 12:46:12 +0200
  4. Subject: [PATCH] thread/Posix{Mutex,Cond}: use "constexpr" only with glibc
  5. Apparently all other C libraries are not compatible with "constexpr".
  6. Those which are not will get a performance penalty, but at least they
  7. work at all.
  8. [Thomas: taken from upstream commit 75dff6445063d9b49cca126fd661c9abbd680977.]
  9. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  10. ---
  11. src/thread/PosixCond.hxx | 16 ++++++++--------
  12. src/thread/PosixMutex.hxx | 16 ++++++++--------
  13. 2 files changed, 16 insertions(+), 16 deletions(-)
  14. diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx
  15. index b3fe204..73dbe02 100644
  16. --- a/src/thread/PosixCond.hxx
  17. +++ b/src/thread/PosixCond.hxx
  18. @@ -1,5 +1,5 @@
  19. /*
  20. - * Copyright (C) 2009-2013 Max Kellermann <max@duempel.org>
  21. + * Copyright (C) 2009-2015 Max Kellermann <max@duempel.org>
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. @@ -41,9 +41,13 @@ class PosixCond {
  26. pthread_cond_t cond;
  27. public:
  28. -#if defined(__NetBSD__) || defined(__BIONIC__)
  29. - /* NetBSD's PTHREAD_COND_INITIALIZER is not compatible with
  30. - "constexpr" */
  31. +#ifdef __GLIBC__
  32. + /* optimized constexpr constructor for pthread implementations
  33. + that support it */
  34. + constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {}
  35. +#else
  36. + /* slow fallback for pthread implementations that are not
  37. + compatible with "constexpr" */
  38. PosixCond() {
  39. pthread_cond_init(&cond, nullptr);
  40. }
  41. @@ -51,10 +55,6 @@ public:
  42. ~PosixCond() {
  43. pthread_cond_destroy(&cond);
  44. }
  45. -#else
  46. - /* optimized constexpr constructor for sane POSIX
  47. - implementations */
  48. - constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {}
  49. #endif
  50. PosixCond(const PosixCond &other) = delete;
  51. diff --git a/src/thread/PosixMutex.hxx b/src/thread/PosixMutex.hxx
  52. index 5805158..e0fd614 100644
  53. --- a/src/thread/PosixMutex.hxx
  54. +++ b/src/thread/PosixMutex.hxx
  55. @@ -1,5 +1,5 @@
  56. /*
  57. - * Copyright (C) 2009-2013 Max Kellermann <max@duempel.org>
  58. + * Copyright (C) 2009-2015 Max Kellermann <max@duempel.org>
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. @@ -41,9 +41,13 @@ class PosixMutex {
  63. pthread_mutex_t mutex;
  64. public:
  65. -#if defined(__NetBSD__) || defined(__BIONIC__)
  66. - /* NetBSD's PTHREAD_MUTEX_INITIALIZER is not compatible with
  67. - "constexpr" */
  68. +#ifdef __GLIBC__
  69. + /* optimized constexpr constructor for pthread implementations
  70. + that support it */
  71. + constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
  72. +#else
  73. + /* slow fallback for pthread implementations that are not
  74. + compatible with "constexpr" */
  75. PosixMutex() {
  76. pthread_mutex_init(&mutex, nullptr);
  77. }
  78. @@ -51,10 +55,6 @@ public:
  79. ~PosixMutex() {
  80. pthread_mutex_destroy(&mutex);
  81. }
  82. -#else
  83. - /* optimized constexpr constructor for sane POSIX
  84. - implementations */
  85. - constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
  86. #endif
  87. PosixMutex(const PosixMutex &other) = delete;
  88. --
  89. 2.6.4