@@ -11,6 +11,38 @@ fn bool_() {
11
11
assert_eq ! ( a. compare_exchange( false , true , SeqCst , SeqCst ) , Ok ( false ) ) ;
12
12
}
13
13
14
+ #[ test]
15
+ #[ should_panic = "there is no such thing as an acquire store" ]
16
+ fn store_illegal_rt_store_acquire_ordering ( ) {
17
+ let a = AtomicBool :: new ( false ) ;
18
+ let ord = Ordering :: Acquire ;
19
+ a. store ( true , ord) ;
20
+ }
21
+
22
+ #[ test]
23
+ #[ should_panic = "there is no such thing as an acquire-release store" ]
24
+ fn store_illegal_rt_store_acq_rel_ordering ( ) {
25
+ let a = AtomicBool :: new ( false ) ;
26
+ let ord = Ordering :: AcqRel ;
27
+ a. store ( true , ord) ;
28
+ }
29
+
30
+ #[ test]
31
+ #[ should_panic = "there is no such thing as a release load" ]
32
+ fn store_illegal_rt_load_release_ordering ( ) {
33
+ let a = AtomicBool :: new ( false ) ;
34
+ let ord = Ordering :: Release ;
35
+ a. load ( ord) ;
36
+ }
37
+
38
+ #[ test]
39
+ #[ should_panic = "there is no such thing as an acquire-release load" ]
40
+ fn store_illegal_rt_load_acq_rel_ordering ( ) {
41
+ let a = AtomicBool :: new ( false ) ;
42
+ let ord = Ordering :: AcqRel ;
43
+ a. load ( ord) ;
44
+ }
45
+
14
46
#[ test]
15
47
fn bool_and ( ) {
16
48
let a = AtomicBool :: new ( true ) ;
@@ -283,25 +315,229 @@ fn atomic_compare_exchange() {
283
315
static ATOMIC : AtomicIsize = AtomicIsize :: new ( 0 ) ;
284
316
285
317
ATOMIC . compare_exchange ( 0 , 1 , Relaxed , Relaxed ) . ok ( ) ;
318
+ ATOMIC . compare_exchange ( 0 , 1 , Relaxed , Acquire ) . ok ( ) ;
319
+ ATOMIC . compare_exchange ( 0 , 1 , Relaxed , SeqCst ) . ok ( ) ;
286
320
ATOMIC . compare_exchange ( 0 , 1 , Acquire , Relaxed ) . ok ( ) ;
321
+ ATOMIC . compare_exchange ( 0 , 1 , Acquire , Acquire ) . ok ( ) ;
322
+ ATOMIC . compare_exchange ( 0 , 1 , Acquire , SeqCst ) . ok ( ) ;
287
323
ATOMIC . compare_exchange ( 0 , 1 , Release , Relaxed ) . ok ( ) ;
324
+ ATOMIC . compare_exchange ( 0 , 1 , Release , Acquire ) . ok ( ) ;
325
+ ATOMIC . compare_exchange ( 0 , 1 , Release , SeqCst ) . ok ( ) ;
288
326
ATOMIC . compare_exchange ( 0 , 1 , AcqRel , Relaxed ) . ok ( ) ;
289
- ATOMIC . compare_exchange ( 0 , 1 , SeqCst , Relaxed ) . ok ( ) ;
290
- ATOMIC . compare_exchange ( 0 , 1 , Acquire , Acquire ) . ok ( ) ;
291
327
ATOMIC . compare_exchange ( 0 , 1 , AcqRel , Acquire ) . ok ( ) ;
328
+ ATOMIC . compare_exchange ( 0 , 1 , AcqRel , SeqCst ) . ok ( ) ;
329
+ ATOMIC . compare_exchange ( 0 , 1 , SeqCst , Relaxed ) . ok ( ) ;
292
330
ATOMIC . compare_exchange ( 0 , 1 , SeqCst , Acquire ) . ok ( ) ;
293
331
ATOMIC . compare_exchange ( 0 , 1 , SeqCst , SeqCst ) . ok ( ) ;
294
332
ATOMIC . compare_exchange_weak ( 0 , 1 , Relaxed , Relaxed ) . ok ( ) ;
333
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Relaxed , Acquire ) . ok ( ) ;
334
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Relaxed , SeqCst ) . ok ( ) ;
295
335
ATOMIC . compare_exchange_weak ( 0 , 1 , Acquire , Relaxed ) . ok ( ) ;
336
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Acquire , Acquire ) . ok ( ) ;
337
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Acquire , SeqCst ) . ok ( ) ;
296
338
ATOMIC . compare_exchange_weak ( 0 , 1 , Release , Relaxed ) . ok ( ) ;
339
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Release , Acquire ) . ok ( ) ;
340
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Release , SeqCst ) . ok ( ) ;
297
341
ATOMIC . compare_exchange_weak ( 0 , 1 , AcqRel , Relaxed ) . ok ( ) ;
298
- ATOMIC . compare_exchange_weak ( 0 , 1 , SeqCst , Relaxed ) . ok ( ) ;
299
- ATOMIC . compare_exchange_weak ( 0 , 1 , Acquire , Acquire ) . ok ( ) ;
300
342
ATOMIC . compare_exchange_weak ( 0 , 1 , AcqRel , Acquire ) . ok ( ) ;
343
+ ATOMIC . compare_exchange_weak ( 0 , 1 , AcqRel , SeqCst ) . ok ( ) ;
344
+ ATOMIC . compare_exchange_weak ( 0 , 1 , SeqCst , Relaxed ) . ok ( ) ;
301
345
ATOMIC . compare_exchange_weak ( 0 , 1 , SeqCst , Acquire ) . ok ( ) ;
302
346
ATOMIC . compare_exchange_weak ( 0 , 1 , SeqCst , SeqCst ) . ok ( ) ;
303
347
}
304
348
349
+ #[ test]
350
+ #[ should_panic = "there is no such thing as an acquire-release failure ordering" ]
351
+ fn atomic_compare_exchange_illegal_acq_rel ( ) {
352
+ use Ordering :: * ;
353
+
354
+ static ATOMIC : AtomicIsize = AtomicIsize :: new ( 0 ) ;
355
+
356
+ let failure = AcqRel ;
357
+
358
+ ATOMIC . compare_exchange ( 0 , 1 , Relaxed , failure) . ok ( ) ;
359
+ }
360
+
361
+ #[ test]
362
+ #[ should_panic = "there is no such thing as a release failure ordering" ]
363
+ fn atomic_compare_exchange_illegal_release ( ) {
364
+ use Ordering :: * ;
365
+
366
+ static ATOMIC : AtomicIsize = AtomicIsize :: new ( 0 ) ;
367
+
368
+ let failure = Release ;
369
+
370
+ ATOMIC . compare_exchange ( 0 , 1 , Relaxed , failure) . ok ( ) ;
371
+ }
372
+
373
+ #[ test]
374
+ #[ should_panic = "there is no such thing as an acquire-release failure ordering" ]
375
+ fn atomic_compare_exchange_weak_illegal_acq_rel ( ) {
376
+ use Ordering :: * ;
377
+
378
+ static ATOMIC : AtomicIsize = AtomicIsize :: new ( 0 ) ;
379
+
380
+ let failure = AcqRel ;
381
+
382
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Relaxed , failure) . ok ( ) ;
383
+ }
384
+
385
+ #[ test]
386
+ #[ should_panic = "there is no such thing as a release failure ordering" ]
387
+ fn atomic_compare_exchange_weak_illegal_release ( ) {
388
+ use Ordering :: * ;
389
+
390
+ static ATOMIC : AtomicIsize = AtomicIsize :: new ( 0 ) ;
391
+
392
+ let failure = Release ;
393
+
394
+ ATOMIC . compare_exchange_weak ( 0 , 1 , Relaxed , failure) . ok ( ) ;
395
+ }
396
+
397
+ #[ test]
398
+ fn atomic_swap ( ) {
399
+ use Ordering :: * ;
400
+
401
+ static ATOMIC : AtomicBool = AtomicBool :: new ( false ) ;
402
+
403
+ assert_eq ! ( ATOMIC . swap( true , Relaxed ) , false ) ;
404
+ assert_eq ! ( ATOMIC . swap( false , Acquire ) , true ) ;
405
+ assert_eq ! ( ATOMIC . swap( true , Release ) , false ) ;
406
+ assert_eq ! ( ATOMIC . swap( false , AcqRel ) , true ) ;
407
+ assert_eq ! ( ATOMIC . swap( true , SeqCst ) , false ) ;
408
+ }
409
+
410
+ #[ test]
411
+ fn atomic_add ( ) {
412
+ use Ordering :: * ;
413
+
414
+ static ATOMIC : AtomicU8 = AtomicU8 :: new ( 0 ) ;
415
+
416
+ assert_eq ! ( ATOMIC . fetch_add( 1 , Relaxed ) , 0 ) ;
417
+ assert_eq ! ( ATOMIC . fetch_add( 1 , Acquire ) , 1 ) ;
418
+ assert_eq ! ( ATOMIC . fetch_add( 1 , Release ) , 2 ) ;
419
+ assert_eq ! ( ATOMIC . fetch_add( 1 , AcqRel ) , 3 ) ;
420
+ assert_eq ! ( ATOMIC . fetch_add( 1 , SeqCst ) , 4 ) ;
421
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 5 ) ;
422
+ }
423
+
424
+ #[ test]
425
+ fn atomic_sub ( ) {
426
+ use Ordering :: * ;
427
+
428
+ static ATOMIC : AtomicU8 = AtomicU8 :: new ( 5 ) ;
429
+
430
+ assert_eq ! ( ATOMIC . fetch_sub( 1 , Relaxed ) , 5 ) ;
431
+ assert_eq ! ( ATOMIC . fetch_sub( 1 , Acquire ) , 4 ) ;
432
+ assert_eq ! ( ATOMIC . fetch_sub( 1 , Release ) , 3 ) ;
433
+ assert_eq ! ( ATOMIC . fetch_sub( 1 , AcqRel ) , 2 ) ;
434
+ assert_eq ! ( ATOMIC . fetch_sub( 1 , SeqCst ) , 1 ) ;
435
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 0 ) ;
436
+ }
437
+
438
+ #[ test]
439
+ fn atomic_and_or ( ) {
440
+ use Ordering :: * ;
441
+
442
+ static ATOMIC : AtomicBool = AtomicBool :: new ( false ) ;
443
+
444
+ assert_eq ! ( ATOMIC . fetch_or( true , Relaxed ) , false ) ;
445
+ assert_eq ! ( ATOMIC . fetch_and( false , Relaxed ) , true ) ;
446
+ assert_eq ! ( ATOMIC . fetch_or( true , Acquire ) , false ) ;
447
+ assert_eq ! ( ATOMIC . fetch_and( false , Acquire ) , true ) ;
448
+ assert_eq ! ( ATOMIC . fetch_or( true , Release ) , false ) ;
449
+ assert_eq ! ( ATOMIC . fetch_and( false , Release ) , true ) ;
450
+ assert_eq ! ( ATOMIC . fetch_or( true , AcqRel ) , false ) ;
451
+ assert_eq ! ( ATOMIC . fetch_and( false , AcqRel ) , true ) ;
452
+ assert_eq ! ( ATOMIC . fetch_or( true , SeqCst ) , false ) ;
453
+ assert_eq ! ( ATOMIC . fetch_and( false , SeqCst ) , true ) ;
454
+ assert_eq ! ( ATOMIC . load( Relaxed ) , false ) ;
455
+ }
456
+
457
+ #[ test]
458
+ fn atomic_nand ( ) {
459
+ use Ordering :: * ;
460
+
461
+ static ATOMIC : AtomicU8 = AtomicU8 :: new ( 0x13 ) ;
462
+
463
+ assert_eq ! ( ATOMIC . fetch_nand( 0x13 , Relaxed ) , 0x13 ) ;
464
+ assert_eq ! ( ATOMIC . fetch_nand( 0xec , Acquire ) , 0xec ) ;
465
+ assert_eq ! ( ATOMIC . fetch_nand( 0x13 , Release ) , 0x13 ) ;
466
+ assert_eq ! ( ATOMIC . fetch_nand( 0xec , AcqRel ) , 0xec ) ;
467
+ assert_eq ! ( ATOMIC . fetch_nand( 0x13 , SeqCst ) , 0x13 ) ;
468
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 0xec ) ;
469
+ }
470
+
471
+ #[ test]
472
+ fn atomic_xor ( ) {
473
+ use Ordering :: * ;
474
+
475
+ static ATOMIC : AtomicBool = AtomicBool :: new ( false ) ;
476
+
477
+ assert_eq ! ( ATOMIC . fetch_xor( true , Relaxed ) , false ) ;
478
+ assert_eq ! ( ATOMIC . fetch_xor( true , Acquire ) , true ) ;
479
+ assert_eq ! ( ATOMIC . fetch_xor( true , Release ) , false ) ;
480
+ assert_eq ! ( ATOMIC . fetch_xor( true , AcqRel ) , true ) ;
481
+ assert_eq ! ( ATOMIC . fetch_xor( true , SeqCst ) , false ) ;
482
+ assert_eq ! ( ATOMIC . load( Relaxed ) , true ) ;
483
+ }
484
+
485
+ #[ test]
486
+ fn atomic_max ( ) {
487
+ use Ordering :: * ;
488
+
489
+ static ATOMIC : AtomicI8 = AtomicI8 :: new ( 0 ) ;
490
+
491
+ assert_eq ! ( ATOMIC . fetch_max( 1 , Relaxed ) , 0 ) ;
492
+ assert_eq ! ( ATOMIC . fetch_max( 2 , Acquire ) , 1 ) ;
493
+ assert_eq ! ( ATOMIC . fetch_max( 3 , Release ) , 2 ) ;
494
+ assert_eq ! ( ATOMIC . fetch_max( 4 , AcqRel ) , 3 ) ;
495
+ assert_eq ! ( ATOMIC . fetch_max( 5 , SeqCst ) , 4 ) ;
496
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 5 ) ;
497
+ }
498
+
499
+ #[ test]
500
+ fn atomic_umax ( ) {
501
+ use Ordering :: * ;
502
+
503
+ static ATOMIC : AtomicU8 = AtomicU8 :: new ( 0 ) ;
504
+
505
+ assert_eq ! ( ATOMIC . fetch_max( 1 , Relaxed ) , 0 ) ;
506
+ assert_eq ! ( ATOMIC . fetch_max( 2 , Acquire ) , 1 ) ;
507
+ assert_eq ! ( ATOMIC . fetch_max( 3 , Release ) , 2 ) ;
508
+ assert_eq ! ( ATOMIC . fetch_max( 4 , AcqRel ) , 3 ) ;
509
+ assert_eq ! ( ATOMIC . fetch_max( 5 , SeqCst ) , 4 ) ;
510
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 5 ) ;
511
+ }
512
+
513
+ #[ test]
514
+ fn atomic_min ( ) {
515
+ use Ordering :: * ;
516
+
517
+ static ATOMIC : AtomicI8 = AtomicI8 :: new ( 5 ) ;
518
+
519
+ assert_eq ! ( ATOMIC . fetch_min( 4 , Relaxed ) , 5 ) ;
520
+ assert_eq ! ( ATOMIC . fetch_min( 3 , Acquire ) , 4 ) ;
521
+ assert_eq ! ( ATOMIC . fetch_min( 2 , Release ) , 3 ) ;
522
+ assert_eq ! ( ATOMIC . fetch_min( 1 , AcqRel ) , 2 ) ;
523
+ assert_eq ! ( ATOMIC . fetch_min( 0 , SeqCst ) , 1 ) ;
524
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 0 ) ;
525
+ }
526
+
527
+ #[ test]
528
+ fn atomic_umin ( ) {
529
+ use Ordering :: * ;
530
+
531
+ static ATOMIC : AtomicU8 = AtomicU8 :: new ( 5 ) ;
532
+
533
+ assert_eq ! ( ATOMIC . fetch_min( 4 , Relaxed ) , 5 ) ;
534
+ assert_eq ! ( ATOMIC . fetch_min( 3 , Acquire ) , 4 ) ;
535
+ assert_eq ! ( ATOMIC . fetch_min( 2 , Release ) , 3 ) ;
536
+ assert_eq ! ( ATOMIC . fetch_min( 1 , AcqRel ) , 2 ) ;
537
+ assert_eq ! ( ATOMIC . fetch_min( 0 , SeqCst ) , 1 ) ;
538
+ assert_eq ! ( ATOMIC . load( Relaxed ) , 0 ) ;
539
+ }
540
+
305
541
/* FIXME(#110395)
306
542
#[test]
307
543
fn atomic_const_from() {
0 commit comments