]> code.ossystems Code Review - openembedded-core.git/blob
f69e4f21f3e09ecd79d9b7f420764c296a052eda
[openembedded-core.git] /
1 From 7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b Mon Sep 17 00:00:00 2001
2 From: jzmaddock <john@johnmaddock.co.uk>
3 Date: Wed, 1 Sep 2021 20:31:53 +0100
4 Subject: [PATCH] Make no atomics a soft failure in bernoulli_details.hpp.
5  Include an "escape macro" so thread safety can be disabled if certain
6  bernoulli features are to be used in a no-atomics environment. Fixes
7  https://github.com/boostorg/math/issues/673.
8
9 [buildroot@heine.tech:
10   - backport from boostorg/math 7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b
11   - alter path to match boost release
12 ]
13 Signed-off-by: Michael Nosthoff <buildroot@heine.tech>
14 ---
15 Upstream-Status: Backport [https://github.com/boostorg/math/pull/684/commits/7d482f6ebc356e6ec455ccb5f51a23971bf6ce5b]
16  .../detail/bernoulli_details.hpp                 | 10 +++++++---
17  libs/math/test/Jamfile.v2                        |  3 +++
18  test/compile_test/bernoulli_no_atomic_d.cpp      | 14 ++++++++++++++
19  test/compile_test/bernoulli_no_atomic_fail.cpp   | 15 +++++++++++++++
20  test/compile_test/bernoulli_no_atomic_mp.cpp     | 16 ++++++++++++++++
21  5 files changed, 55 insertions(+), 3 deletions(-)
22  create mode 100644 test/compile_test/bernoulli_no_atomic_d.cpp
23  create mode 100644 test/compile_test/bernoulli_no_atomic_fail.cpp
24  create mode 100644 test/compile_test/bernoulli_no_atomic_mp.cpp
25
26 diff --git a/boost/math/special_functions/detail/bernoulli_details.hpp b/boost/math/special_functions/detail/bernoulli_details.hpp
27 index cf35545264..8519b7c89c 100644
28 --- a/boost/math/special_functions/detail/bernoulli_details.hpp
29 +++ b/boost/math/special_functions/detail/bernoulli_details.hpp
30 @@ -360,7 +360,7 @@ class bernoulli_numbers_cache
31           return out;
32        }
33  
34 -      #ifndef BOOST_HAS_THREADS
35 +      #if !defined(BOOST_HAS_THREADS) || defined(BOOST_MATH_BERNOULLI_UNTHREADED)
36        //
37        // Single threaded code, very simple:
38        //
39 @@ -382,6 +382,8 @@ class bernoulli_numbers_cache
40           *out = (i >= m_overflow_limit) ? policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[i];
41           ++out;
42        }
43 +      #elif defined(BOOST_MATH_NO_ATOMIC_INT)
44 +      static_assert(sizeof(T) == 1, "Unsupported configuration: your platform appears to have no atomic integers.  If you are happy with thread-unsafe code, then you may define BOOST_MATH_BERNOULLI_UNTHREADED to suppress this error.");
45        #else
46        //
47        // Double-checked locking pattern, lets us access cached already cached values
48 @@ -464,7 +466,7 @@ class bernoulli_numbers_cache
49           return out;
50        }
51  
52 -      #ifndef BOOST_HAS_THREADS
53 +      #if !defined(BOOST_HAS_THREADS) || defined(BOOST_MATH_BERNOULLI_UNTHREADED)
54        //
55        // Single threaded code, very simple:
56        //
57 @@ -494,6 +496,8 @@ class bernoulli_numbers_cache
58           }
59           ++out;
60        }
61 +      #elif defined(BOOST_MATH_NO_ATOMIC_INT)
62 +      static_assert(sizeof(T) == 1, "Unsupported configuration: your platform appears to have no atomic integers.  If you are happy with thread-unsafe code, then you may define BOOST_MATH_BERNOULLI_UNTHREADED to suppress this error.");
63        #else
64        //
65        // Double-checked locking pattern, lets us access cached already cached values
66 @@ -555,7 +559,7 @@ class bernoulli_numbers_cache
67     // The value at which we know overflow has already occurred for the Bn:
68     std::size_t m_overflow_limit;
69  
70 -   #ifdef BOOST_HAS_THREADS
71 +   #if defined(BOOST_HAS_THREADS) && !defined(BOOST_MATH_NO_ATOMIC_INT)
72     std::mutex m_mutex;
73     atomic_counter_type m_counter, m_current_precision;
74     #else
75 diff --git a/libs/math/test/Jamfile.v2 b/libs/math/test/Jamfile.v2
76 index 52fb87f5e5..3ac63f9279 100644
77 --- a/libs/math/test/Jamfile.v2
78 +++ b/libs/math/test/Jamfile.v2
79 @@ -1137,6 +1137,9 @@ test-suite misc :
80  
81  #   [ run __temporary_test.cpp test_instances//test_instances : : : <test-info>always_show_run_output <pch>off ]
82     [ compile test_no_long_double_policy.cpp ]
83 +   [ compile compile_test/bernoulli_no_atomic_d.cpp ]
84 +   [ compile compile_test/bernoulli_no_atomic_mp.cpp ]
85 +   [ compile-fail compile_test/bernoulli_no_atomic_fail.cpp ]
86  ;
87  
88  test-suite interpolators :
89 diff --git a/test/compile_test/bernoulli_no_atomic_d.cpp b/test/compile_test/bernoulli_no_atomic_d.cpp
90 new file mode 100644
91 index 0000000000..61926f7e1f
92 --- /dev/null
93 +++ b/test/compile_test/bernoulli_no_atomic_d.cpp
94 @@ -0,0 +1,14 @@
95 +//  (C) Copyright John Maddock 2021.
96 +//  Use, modification and distribution are subject to the
97 +//  Boost Software License, Version 1.0. (See accompanying file
98 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
99 +
100 +#define BOOST_MATH_NO_ATOMIC_INT
101 +
102 +#include <boost/math/special_functions/bernoulli.hpp>
103 +#include "test_compile_result.hpp"
104 +
105 +void compile_and_link_test()
106 +{
107 +   check_result<double>(boost::math::bernoulli_b2n<double>(4));
108 +}
109 diff --git a/test/compile_test/bernoulli_no_atomic_fail.cpp b/test/compile_test/bernoulli_no_atomic_fail.cpp
110 new file mode 100644
111 index 0000000000..bbd7152412
112 --- /dev/null
113 +++ b/test/compile_test/bernoulli_no_atomic_fail.cpp
114 @@ -0,0 +1,15 @@
115 +//  (C) Copyright John Maddock 2021.
116 +//  Use, modification and distribution are subject to the
117 +//  Boost Software License, Version 1.0. (See accompanying file
118 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
119 +
120 +#define BOOST_MATH_NO_ATOMIC_INT
121 +
122 +#include <boost/math/special_functions/bernoulli.hpp>
123 +#include <boost/multiprecision/cpp_bin_float.hpp>
124 +#include "test_compile_result.hpp"
125 +
126 +void compile_and_link_test()
127 +{
128 +   check_result<boost::multiprecision::cpp_bin_float_50>(boost::math::bernoulli_b2n<boost::multiprecision::cpp_bin_float_50>(4));
129 +}
130 diff --git a/test/compile_test/bernoulli_no_atomic_mp.cpp b/test/compile_test/bernoulli_no_atomic_mp.cpp
131 new file mode 100644
132 index 0000000000..8d5a6e78e6
133 --- /dev/null
134 +++ b/test/compile_test/bernoulli_no_atomic_mp.cpp
135 @@ -0,0 +1,16 @@
136 +//  (C) Copyright John Maddock 2021.
137 +//  Use, modification and distribution are subject to the
138 +//  Boost Software License, Version 1.0. (See accompanying file
139 +//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
140 +
141 +#define BOOST_MATH_NO_ATOMIC_INT
142 +#define BOOST_MATH_BERNOULLI_UNTHREADED
143 +
144 +#include <boost/math/special_functions/bernoulli.hpp>
145 +#include <boost/multiprecision/cpp_bin_float.hpp>
146 +#include "test_compile_result.hpp"
147 +
148 +void compile_and_link_test()
149 +{
150 +   check_result<boost::multiprecision::cpp_bin_float_50>(boost::math::bernoulli_b2n<boost::multiprecision::cpp_bin_float_50>(4));
151 +}