Skip to content

Commit a799240

Browse files
fuhsnnnobu
authored andcommitted
atomic.h: Use explicit logic for 32-bit #else branches
These branches are only active for 32-bit Windows and Solaris platforms, codify the fact by changing `#else` to `#elif`'s that explicitly include those targets and `#error`-out otherwise.
1 parent 7a3b6d3 commit a799240

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

include/ruby/atomic.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,14 @@ rbimpl_atomic_size_fetch_add(volatile size_t *ptr, size_t val)
436436
RBIMPL_ASSERT_OR_ASSUME(val <= LONG_MAX);
437437
atomic_add_long(ptr, val);
438438

439-
#else
439+
#elif defined(__sun) && defined(HAVE_ATOMIC_H)
440440
RBIMPL_STATIC_ASSERT(size_of_rb_atomic_t, sizeof *ptr == sizeof(rb_atomic_t));
441441

442442
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
443443
rbimpl_atomic_fetch_add(tmp, val);
444444

445+
#else
446+
# error Unsupported platform.
445447
#endif
446448
}
447449

@@ -505,12 +507,14 @@ rbimpl_atomic_size_add(volatile size_t *ptr, size_t val)
505507
RBIMPL_ASSERT_OR_ASSUME(val <= LONG_MAX);
506508
atomic_add_long(ptr, val);
507509

508-
#else
510+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
509511
RBIMPL_STATIC_ASSERT(size_of_rb_atomic_t, sizeof *ptr == sizeof(rb_atomic_t));
510512

511513
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
512514
rbimpl_atomic_add(tmp, val);
513515

516+
#else
517+
# error Unsupported platform.
514518
#endif
515519
}
516520

@@ -532,8 +536,7 @@ rbimpl_atomic_inc(volatile rb_atomic_t *ptr)
532536
atomic_inc_uint(ptr);
533537

534538
#else
535-
rbimpl_atomic_add(ptr, 1);
536-
539+
# error Unsupported platform.
537540
#endif
538541
}
539542

@@ -554,11 +557,13 @@ rbimpl_atomic_size_inc(volatile size_t *ptr)
554557
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
555558
atomic_inc_ulong(ptr);
556559

557-
#else
560+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
558561
RBIMPL_STATIC_ASSERT(size_of_size_t, sizeof *ptr == sizeof(rb_atomic_t));
559562

560563
rbimpl_atomic_size_add(ptr, 1);
561564

565+
#else
566+
# error Unsupported platform.
562567
#endif
563568
}
564569

@@ -641,12 +646,14 @@ rbimpl_atomic_size_sub(volatile size_t *ptr, size_t val)
641646
RBIMPL_ASSERT_OR_ASSUME(val <= LONG_MAX);
642647
atomic_add_long(ptr, neg * val);
643648

644-
#else
649+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
645650
RBIMPL_STATIC_ASSERT(size_of_rb_atomic_t, sizeof *ptr == sizeof(rb_atomic_t));
646651

647652
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
648653
rbimpl_atomic_sub(tmp, val);
649654

655+
#else
656+
# error Unsupported platform.
650657
#endif
651658
}
652659

@@ -668,8 +675,7 @@ rbimpl_atomic_dec(volatile rb_atomic_t *ptr)
668675
atomic_dec_uint(ptr);
669676

670677
#else
671-
rbimpl_atomic_sub(ptr, 1);
672-
678+
# error Unsupported platform.
673679
#endif
674680
}
675681

@@ -690,11 +696,13 @@ rbimpl_atomic_size_dec(volatile size_t *ptr)
690696
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
691697
atomic_dec_ulong(ptr);
692698

693-
#else
699+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
694700
RBIMPL_STATIC_ASSERT(size_of_size_t, sizeof *ptr == sizeof(rb_atomic_t));
695701

696702
rbimpl_atomic_size_sub(ptr, 1);
697703

704+
#else
705+
# error Unsupported platform.
698706
#endif
699707
}
700708

@@ -790,13 +798,15 @@ rbimpl_atomic_size_exchange(volatile size_t *ptr, size_t val)
790798
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
791799
return atomic_swap_ulong(ptr, val);
792800

793-
#else
801+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
794802
RBIMPL_STATIC_ASSERT(size_of_size_t, sizeof *ptr == sizeof(rb_atomic_t));
795803

796804
volatile rb_atomic_t *const tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
797805
const rb_atomic_t ret = rbimpl_atomic_exchange(tmp, val);
798806
return RBIMPL_CAST((size_t)ret);
799807

808+
#else
809+
# error Unsupported platform.
800810
#endif
801811
}
802812

@@ -983,12 +993,14 @@ rbimpl_atomic_size_cas(volatile size_t *ptr, size_t oldval, size_t newval)
983993
#elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
984994
return atomic_cas_ulong(ptr, oldval, newval);
985995

986-
#else
996+
#elif defined(_WIN32) || (defined(__sun) && defined(HAVE_ATOMIC_H))
987997
RBIMPL_STATIC_ASSERT(size_of_size_t, sizeof *ptr == sizeof(rb_atomic_t));
988998

989999
volatile rb_atomic_t *tmp = RBIMPL_CAST((volatile rb_atomic_t *)ptr);
9901000
return rbimpl_atomic_cas(tmp, oldval, newval);
9911001

1002+
#else
1003+
# error Unsupported platform.
9921004
#endif
9931005
}
9941006

0 commit comments

Comments
 (0)