1010
1111// *****************************************************************
1212// Enable/disable debug instrumentation and statistics printing here
13- constexpr inline auto debug_instrumentation = false ;
13+ constexpr inline auto debug_instrumentation = true ;
14+
15+ // Try with/without m_o_relaxed
16+ #define M_O_RELAXED , std::memory_order_relaxed
17+ #define M_O_RELAXED_NOCOMMA std::memory_order_relaxed
18+ // #define M_O_RELAXED
19+ // #define M_O_RELAXED_NOCOMMA
1420// *****************************************************************
1521
1622#include < algorithm>
@@ -125,7 +131,7 @@ class extrinsic_storage {
125131 auto find_or_insert (void * pobj) noexcept -> Value* {
126132 if constexpr (debug_instrumentation) {
127133 // m_o_relaxed is enough, inc order doesn't matter for totals
128- instrument_access_count.fetch_add (1 , std::memory_order_relaxed );
134+ instrument_access_count.fetch_add (1 M_O_RELAXED );
129135 }
130136 return lookup (pobj, lookup_mode::find_or_insert);
131137 }
@@ -136,7 +142,7 @@ class extrinsic_storage {
136142 auto find (void * pobj) noexcept -> Value* {
137143 if constexpr (debug_instrumentation) {
138144 // m_o_relaxed is enough, inc order doesn't matter for totals
139- instrument_access_count.fetch_add (1 , std::memory_order_relaxed );
145+ instrument_access_count.fetch_add (1 M_O_RELAXED );
140146 }
141147 return lookup (pobj, lookup_mode::find);
142148 }
@@ -147,7 +153,7 @@ class extrinsic_storage {
147153 auto erase (void * pobj) noexcept -> void {
148154 if constexpr (debug_instrumentation) {
149155 // m_o_relaxed is enough, inc order doesn't matter for totals
150- instrument_erase_count.fetch_add (1 , std::memory_order_relaxed );
156+ instrument_erase_count.fetch_add (1 M_O_RELAXED );
151157 }
152158 lookup (pobj, lookup_mode::erase);
153159 }
@@ -202,7 +208,7 @@ class extrinsic_storage {
202208 assert ( 0 <= hash && hash < Buckets );
203209 if constexpr (debug_instrumentation) {
204210 // m_o_relaxed is enough, inc order doesn't matter for totals
205- instrument_bucket_access[hash].fetch_add (1 , std::memory_order_relaxed );
211+ instrument_bucket_access[hash].fetch_add (1 M_O_RELAXED );
206212 }
207213
208214 // 1. If we find key==pobj, we're done
@@ -212,9 +218,9 @@ class extrinsic_storage {
212218 // (*) m_o_relaxed is enough, equality means we own the slot
213219 // and so this thread already has exclusive access to *pobj
214220 // and its .values data
215- if (pchunk->keys [i].load (std::memory_order_relaxed ) == pobj) {
221+ if (pchunk->keys [i].load (M_O_RELAXED_NOCOMMA ) == pobj) {
216222 if (mode == lookup_mode::erase) {
217- pchunk->keys [i].store (nullptr , std::memory_order_relaxed );
223+ pchunk->keys [i].store (nullptr M_O_RELAXED );
218224 return nullptr ;
219225 }
220226 // Else
@@ -225,7 +231,7 @@ class extrinsic_storage {
225231 // it is first set to non-null, and if a new chunk(s) was just
226232 // concurrently added by a different thread then that new
227233 // chunk(s) cannot contain an entry for pobj
228- pchunk = pchunk->next .load (std::memory_order_relaxed );
234+ pchunk = pchunk->next .load (M_O_RELAXED_NOCOMMA );
229235 }
230236
231237 // 2. Otherwise, if we're not allowed to insert we're done
@@ -234,7 +240,7 @@ class extrinsic_storage {
234240 if constexpr (debug_instrumentation) {
235241 if (mode == lookup_mode::erase) {
236242 // m_o_relaxed is enough, inc order doesn't matter for totals
237- instrument_erase_fail_count.fetch_add (1 , std::memory_order_relaxed );
243+ instrument_erase_fail_count.fetch_add (1 M_O_RELAXED );
238244 }
239245 }
240246 return nullptr ;
@@ -249,22 +255,22 @@ class extrinsic_storage {
249255 void * null = nullptr ;
250256 if (
251257 // m_o_relaxed is enough for this first load...
252- pchunk->keys [i].load (std::memory_order_relaxed ) == nullptr
258+ pchunk->keys [i].load (M_O_RELAXED_NOCOMMA ) == nullptr
253259 // ... because it's just a best-effort optimization to
254260 // avoid this maybe-unneeded c_e_weak (which is safely SC)
255261 && pchunk->keys [i].compare_exchange_weak ( null, pobj )
256262 ) {
257263 if constexpr (debug_instrumentation) {
258264 // m_o_relaxed is enough, inc order doesn't matter for totals
259- instrument_insert_count.fetch_add (1 , std::memory_order_relaxed );
265+ instrument_insert_count.fetch_add (1 M_O_RELAXED );
260266 }
261267 return &pchunk->values [i];
262268 }
263269 }
264270 // (*) m_o_relaxed is enough here, because if a new chunk(s)
265271 // was just concurrently added by a different thread then we'll
266272 // just add an extra chunk which is fine
267- if ( pchunk->next .load (std::memory_order_relaxed ) == nullptr ) {
273+ if ( pchunk->next .load (M_O_RELAXED_NOCOMMA ) == nullptr ) {
268274 break ;
269275 }
270276 pchunk = pchunk->next .load ();
@@ -290,7 +296,7 @@ class extrinsic_storage {
290296
291297 if constexpr (debug_instrumentation) {
292298 // m_o_relaxed is enough, inc order doesn't matter for totals
293- instrument_alloc_count.fetch_add (1 , std::memory_order_relaxed );
299+ instrument_alloc_count.fetch_add (1 M_O_RELAXED );
294300 }
295301 return ret;
296302 }
0 commit comments