The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #13224 from MisterDA/macros-fresh-identifier-__COUNTER__

Clarify barriers and spin macros with delayed expansion

authored by

David Allsopp and committed by
GitHub
3760ec11 9c1ed0f4

+41 -27
+3
Changes
··· 472 472 into a match in typetexp. 473 473 (Samuel Vivien, review by Gabriel Scherer) 474 474 475 + - #13224: Clarify barriers and spin macros with delayed expansion. 476 + (Antonin Décimo, review by David Allsopp and Gabriel Scherer) 477 + 475 478 ### Build system: 476 479 477 480 - #13705: Cache test results of custom Autoconf tests from aclocal.m4.
+14 -10
runtime/caml/domain.h
··· 243 243 Note: this expands to an [if] and [for] header, do not exit the body using 244 244 jumps or returns, and do not put an [else] immediately after. 245 245 */ 246 - #define Caml_global_barrier_if_final(num_participating) \ 246 + #define Caml_global_barrier_if_final_(/* symbols */ alone, b, go, \ 247 + /* params */ num_participating) \ 247 248 /* fast path when alone */ \ 248 - int CAML_GENSYM(alone) = (num_participating) == 1; \ 249 - barrier_status CAML_GENSYM(b) = 0; \ 250 - if (CAML_GENSYM(alone) || \ 251 - (CAML_GENSYM(b) \ 252 - = caml_global_barrier_and_check_final(num_participating))) \ 253 - for (int CAML_GENSYM(continue) = 1; CAML_GENSYM(continue); \ 249 + bool alone = (num_participating) == 1; \ 250 + barrier_status b = 0; \ 251 + if (alone || \ 252 + (b = caml_global_barrier_and_check_final(num_participating))) \ 253 + for (bool go = true; go; \ 254 254 /* release the barrier after the body has executed once */ \ 255 - ((CAML_GENSYM(alone) ? (void)0 : \ 256 - caml_global_barrier_release_as_final(CAML_GENSYM(b))), \ 257 - CAML_GENSYM(continue) = 0)) 255 + (alone ? (void)0 : \ 256 + caml_global_barrier_release_as_final(b)), \ 257 + go = false) 258 + 259 + #define Caml_global_barrier_if_final(num_participating) \ 260 + Caml_global_barrier_if_final_(CAML_GENSYM(alone), CAML_GENSYM(b), \ 261 + CAML_GENSYM(go), (num_participating)) 258 262 259 263 /* 260 264 * Termination helpers.
+4 -4
runtime/caml/misc.h
··· 781 781 # endif 782 782 #endif 783 783 784 - /* Generate a named symbol that is unique within the current macro expansion */ 785 - #define CAML_GENSYM_3(name, l) caml__##name##_##l 786 - #define CAML_GENSYM_2(name, l) CAML_GENSYM_3(name, l) 787 - #define CAML_GENSYM(name) CAML_GENSYM_2(name, __LINE__) 784 + /* Generate a named symbol that is unique */ 785 + #define CAML_GENSYM__(name, id) caml__##name##_##id 786 + #define CAML_GENSYM_(name, id) CAML_GENSYM__(name, id) 787 + #define CAML_GENSYM(name) CAML_GENSYM_(name, __COUNTER__) 788 788 789 789 #define MSEC_PER_SEC UINT64_C(1000) 790 790 #define USEC_PER_MSEC UINT64_C(1000)
+20 -13
runtime/caml/platform.h
··· 33 33 34 34 #include <errno.h> 35 35 #include <string.h> 36 + #include <stdbool.h> 36 37 #include "config.h" 37 38 #include "mlvalues.h" 38 39 #include "sys.h" ··· 552 553 #define Max_spins_medium 300 553 554 #define Max_spins_short 30 554 555 555 - #define SPIN_WAIT_NTIMES(N) \ 556 - unsigned CAML_GENSYM(spins) = 0; \ 557 - unsigned CAML_GENSYM(max_spins) = (N); \ 558 - for (; CAML_GENSYM(spins) < CAML_GENSYM(max_spins); \ 559 - cpu_relax(), ++CAML_GENSYM(spins)) 556 + #define SPIN_WAIT_NTIMES_(/* symbols */ spins, max_spins, /* params */ N) \ 557 + const unsigned max_spins = (N); \ 558 + for (unsigned spins = 0; spins < max_spins; cpu_relax(), ++spins) 559 + 560 + #define SPIN_WAIT_NTIMES(N) \ 561 + SPIN_WAIT_NTIMES_(CAML_GENSYM(spins), CAML_GENSYM(max_spins), (N)) 562 + 560 563 #define SPIN_WAIT_BOUNDED SPIN_WAIT_NTIMES(Max_spins_medium) 561 564 #define SPIN_WAIT SPIN_WAIT_BACK_OFF(Max_spins_long) 562 565 ··· 585 588 } 586 589 } 587 590 588 - #define SPIN_WAIT_BACK_OFF(max_spins) \ 589 - unsigned CAML_GENSYM(spins) = 0; \ 590 - unsigned CAML_GENSYM(max_spins) = (max_spins); \ 591 - static const struct caml_plat_srcloc CAML_GENSYM(loc) = { \ 592 - __FILE__, __LINE__, __func__ \ 593 - }; \ 594 - for (; 1; CAML_GENSYM(spins) = caml_plat_spin_step( \ 595 - CAML_GENSYM(spins), CAML_GENSYM(max_spins), &CAML_GENSYM(loc))) 591 + #define SPIN_WAIT_BACK_OFF_(/* symbols */ spins, max_spins, loc, \ 592 + /* params */ N) \ 593 + const unsigned max_spins = (N); \ 594 + static const struct caml_plat_srcloc loc = \ 595 + { __FILE__, __LINE__, __func__ }; \ 596 + for (unsigned spins = 0; \ 597 + true; \ 598 + spins = caml_plat_spin_step(spins, max_spins, &loc)) 599 + 600 + #define SPIN_WAIT_BACK_OFF(N) \ 601 + SPIN_WAIT_BACK_OFF_(CAML_GENSYM(spins), CAML_GENSYM(max_spins), \ 602 + CAML_GENSYM(loc), (N)) 596 603 597 604 /* Memory management primitives (mmap) */ 598 605