aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_smp.h
blob: 797378b315348795575fd1c991eeecabc768ef64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
/*
 * %CopyrightBegin%
 *
 * Copyright Ericsson AB 2005-2010. All Rights Reserved.
 *
 * The contents of this file are subject to the Erlang Public License,
 * Version 1.1, (the "License"); you may not use this file except in
 * compliance with the License. You should have received a copy of the
 * Erlang Public License along with this software. If not, it can be
 * retrieved online at http://www.erlang.org/.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * %CopyrightEnd%
 */
/*
 * SMP interface to ethread library.
 * This is essentially "sed s/erts_/erts_smp_/g < erl_threads.h > erl_smp.h",
 * plus changes to NOP operations when ERTS_SMP is disabled.
 * Author: Mikael Pettersson
 */
#ifndef ERL_SMP_H
#define ERL_SMP_H
#include "erl_threads.h"

#ifdef ERTS_ENABLE_LOCK_COUNT
#define erts_smp_mtx_lock(L) erts_smp_mtx_lock_x(L, __FILE__, __LINE__)
#define erts_smp_spin_lock(L) erts_smp_spin_lock_x(L, __FILE__, __LINE__)
#define erts_smp_rwmtx_rlock(L) erts_smp_rwmtx_rlock_x(L, __FILE__, __LINE__)
#define erts_smp_rwmtx_rwlock(L) erts_smp_rwmtx_rwlock_x(L, __FILE__, __LINE__)
#define erts_smp_read_lock(L) erts_smp_read_lock_x(L, __FILE__, __LINE__)
#define erts_smp_write_lock(L) erts_smp_write_lock_x(L, __FILE__, __LINE__)
#endif


#ifdef ERTS_SMP
#define ERTS_SMP_THR_OPTS_DEFAULT_INITER ERTS_THR_OPTS_DEFAULT_INITER
typedef erts_thr_opts_t erts_smp_thr_opts_t;
typedef erts_thr_init_data_t erts_smp_thr_init_data_t;
typedef erts_tid_t erts_smp_tid_t;
typedef erts_mtx_t erts_smp_mtx_t;
typedef erts_cnd_t erts_smp_cnd_t;
#define ERTS_SMP_RWMTX_OPT_DEFAULT_INITER ERTS_RWMTX_OPT_DEFAULT_INITER
#define ERTS_SMP_RWMTX_TYPE_NORMAL ERTS_RWMTX_TYPE_NORMAL
#define ERTS_SMP_RWMTX_TYPE_FREQUENT_READ ERTS_RWMTX_TYPE_FREQUENT_READ
#define ERTS_SMP_RWMTX_TYPE_EXTREMELY_FREQUENT_READ \
  ERTS_RWMTX_TYPE_EXTREMELY_FREQUENT_READ
#define ERTS_SMP_RWMTX_LONG_LIVED ERTS_RWMTX_LONG_LIVED
#define ERTS_SMP_RWMTX_SHORT_LIVED ERTS_RWMTX_SHORT_LIVED
#define ERTS_SMP_RWMTX_UNKNOWN_LIVED ERTS_RWMTX_UNKNOWN_LIVED
typedef erts_rwmtx_opt_t erts_smp_rwmtx_opt_t;
typedef erts_rwmtx_t erts_smp_rwmtx_t;
typedef erts_tsd_key_t erts_smp_tsd_key_t;
#define erts_smp_dw_atomic_t erts_dw_atomic_t
#define erts_smp_atomic_t erts_atomic_t
#define erts_smp_atomic32_t erts_atomic32_t
typedef erts_spinlock_t erts_smp_spinlock_t;
typedef erts_rwlock_t erts_smp_rwlock_t;
void erts_thr_fatal_error(int, char *); /* implemented in erl_init.c */

#else /* #ifdef ERTS_SMP */

#define ERTS_SMP_THR_OPTS_DEFAULT_INITER {0}
typedef int erts_smp_thr_opts_t;
typedef int erts_smp_thr_init_data_t;
typedef int erts_smp_tid_t;
typedef int erts_smp_mtx_t;
typedef int erts_smp_cnd_t;
#define ERTS_SMP_RWMTX_OPT_DEFAULT_INITER {0}
#define ERTS_SMP_RWMTX_TYPE_NORMAL 0
#define ERTS_SMP_RWMTX_TYPE_FREQUENT_READ 0
#define ERTS_SMP_RWMTX_TYPE_EXTREMELY_FREQUENT_READ 0
#define ERTS_SMP_RWMTX_LONG_LIVED 0
#define ERTS_SMP_RWMTX_SHORT_LIVED 0
#define ERTS_SMP_RWMTX_UNKNOWN_LIVED 0
typedef struct {
    char type;
    char lived;
    int main_spincount;
    int aux_spincount;
} erts_smp_rwmtx_opt_t;
typedef int erts_smp_rwmtx_t;
typedef int erts_smp_tsd_key_t;
#define erts_smp_dw_atomic_t erts_no_dw_atomic_t
#define erts_smp_atomic_t erts_no_atomic_t
#define erts_smp_atomic32_t erts_no_atomic32_t
#if __GNUC__ > 2
typedef struct { } erts_smp_spinlock_t;
typedef struct { } erts_smp_rwlock_t;
#else
typedef struct { int gcc_is_buggy; } erts_smp_spinlock_t;
typedef struct { int gcc_is_buggy; } erts_smp_rwlock_t;
#endif

#endif /* #ifdef ERTS_SMP */

ERTS_GLB_INLINE void erts_smp_thr_init(erts_smp_thr_init_data_t *id);
ERTS_GLB_INLINE void erts_smp_thr_create(erts_smp_tid_t *tid,
					 void * (*func)(void *),
					 void *arg,
					 erts_smp_thr_opts_t *opts);
ERTS_GLB_INLINE void erts_smp_thr_join(erts_smp_tid_t tid, void **thr_res);
ERTS_GLB_INLINE void erts_smp_thr_detach(erts_smp_tid_t tid);
ERTS_GLB_INLINE void erts_smp_thr_exit(void *res);
ERTS_GLB_INLINE void erts_smp_install_exit_handler(void (*exit_handler)(void));
ERTS_GLB_INLINE erts_smp_tid_t erts_smp_thr_self(void);
ERTS_GLB_INLINE int erts_smp_equal_tids(erts_smp_tid_t x, erts_smp_tid_t y);
#ifdef ERTS_HAVE_REC_MTX_INIT
#define ERTS_SMP_HAVE_REC_MTX_INIT 1
ERTS_GLB_INLINE void erts_smp_rec_mtx_init(erts_smp_mtx_t *mtx);
#endif
ERTS_GLB_INLINE void erts_smp_mtx_init_x(erts_smp_mtx_t *mtx,
					 char *name,
					 Eterm extra);
ERTS_GLB_INLINE void erts_smp_mtx_init_locked_x(erts_smp_mtx_t *mtx,
						char *name,
						Eterm extra);
ERTS_GLB_INLINE void erts_smp_mtx_init(erts_smp_mtx_t *mtx, char *name);
ERTS_GLB_INLINE void erts_smp_mtx_init_locked(erts_smp_mtx_t *mtx, char *name);
ERTS_GLB_INLINE void erts_smp_mtx_destroy(erts_smp_mtx_t *mtx);
ERTS_GLB_INLINE int erts_smp_mtx_trylock(erts_smp_mtx_t *mtx);
#ifdef ERTS_ENABLE_LOCK_COUNT
ERTS_GLB_INLINE void erts_smp_mtx_lock_x(erts_smp_mtx_t *mtx, char *file, int line);
#else
ERTS_GLB_INLINE void erts_smp_mtx_lock(erts_smp_mtx_t *mtx);
#endif
ERTS_GLB_INLINE void erts_smp_mtx_unlock(erts_smp_mtx_t *mtx);
ERTS_GLB_INLINE int erts_smp_lc_mtx_is_locked(erts_smp_mtx_t *mtx);
ERTS_GLB_INLINE void erts_smp_cnd_init(erts_smp_cnd_t *cnd);
ERTS_GLB_INLINE void erts_smp_cnd_destroy(erts_smp_cnd_t *cnd);
ERTS_GLB_INLINE void erts_smp_cnd_wait(erts_smp_cnd_t *cnd,
					   erts_smp_mtx_t *mtx);
ERTS_GLB_INLINE void erts_smp_cnd_signal(erts_smp_cnd_t *cnd);
ERTS_GLB_INLINE void erts_smp_cnd_broadcast(erts_smp_cnd_t *cnd);
ERTS_GLB_INLINE void erts_smp_rwmtx_set_reader_group(int no);
ERTS_GLB_INLINE void erts_smp_rwmtx_init_opt_x(erts_smp_rwmtx_t *rwmtx,
					       erts_smp_rwmtx_opt_t *opt,
					       char *name,
					       Eterm extra);
ERTS_GLB_INLINE void erts_smp_rwmtx_init_x(erts_smp_rwmtx_t *rwmtx,
					   char *name,
					   Eterm extra);
ERTS_GLB_INLINE void erts_smp_rwmtx_init_opt(erts_smp_rwmtx_t *rwmtx,
					     erts_smp_rwmtx_opt_t *opt,
					     char *name);
ERTS_GLB_INLINE void erts_smp_rwmtx_init(erts_smp_rwmtx_t *rwmtx,
					 char *name);
ERTS_GLB_INLINE void erts_smp_rwmtx_destroy(erts_smp_rwmtx_t *rwmtx);
ERTS_GLB_INLINE int erts_smp_rwmtx_tryrlock(erts_smp_rwmtx_t *rwmtx);
#ifdef ERTS_ENABLE_LOCK_COUNT
ERTS_GLB_INLINE void erts_smp_rwmtx_rlock_x(erts_smp_rwmtx_t *rwmtx, char *file, unsigned int line);
ERTS_GLB_INLINE void erts_smp_rwmtx_rwlock_x(erts_smp_rwmtx_t *rwmtx, char *file, unsigned int line);
#else
ERTS_GLB_INLINE void erts_smp_rwmtx_rlock(erts_smp_rwmtx_t *rwmtx);
ERTS_GLB_INLINE void erts_smp_rwmtx_rwlock(erts_smp_rwmtx_t *rwmtx);
#endif
ERTS_GLB_INLINE void erts_smp_rwmtx_runlock(erts_smp_rwmtx_t *rwmtx);
ERTS_GLB_INLINE int erts_smp_rwmtx_tryrwlock(erts_smp_rwmtx_t *rwmtx);
ERTS_GLB_INLINE void erts_smp_rwmtx_rwunlock(erts_smp_rwmtx_t *rwmtx);
ERTS_GLB_INLINE int erts_smp_lc_rwmtx_is_rlocked(erts_smp_rwmtx_t *mtx);
ERTS_GLB_INLINE int erts_smp_lc_rwmtx_is_rwlocked(erts_smp_rwmtx_t *mtx);
ERTS_GLB_INLINE void erts_smp_spinlock_init_x(erts_smp_spinlock_t *lock,
					      char *name,
					      Eterm extra);
ERTS_GLB_INLINE void erts_smp_spinlock_init(erts_smp_spinlock_t *lock,
					    char *name);
ERTS_GLB_INLINE void erts_smp_spinlock_destroy(erts_smp_spinlock_t *lock);
ERTS_GLB_INLINE void erts_smp_spin_unlock(erts_smp_spinlock_t *lock);
#ifdef ERTS_ENABLE_LOCK_COUNT
ERTS_GLB_INLINE void erts_smp_spin_lock_x(erts_smp_spinlock_t *lock, char *file, unsigned int line);
#else
ERTS_GLB_INLINE void erts_smp_spin_lock(erts_smp_spinlock_t *lock);
#endif
ERTS_GLB_INLINE int erts_smp_lc_spinlock_is_locked(erts_smp_spinlock_t *lock);
ERTS_GLB_INLINE void erts_smp_rwlock_init_x(erts_smp_rwlock_t *lock,
					    char *name,
					    Eterm extra);
ERTS_GLB_INLINE void erts_smp_rwlock_init(erts_smp_rwlock_t *lock,
					  char *name);
ERTS_GLB_INLINE void erts_smp_rwlock_destroy(erts_smp_rwlock_t *lock);
ERTS_GLB_INLINE void erts_smp_read_unlock(erts_smp_rwlock_t *lock);
#ifdef ERTS_ENABLE_LOCK_COUNT
ERTS_GLB_INLINE void erts_smp_read_lock_x(erts_smp_rwlock_t *lock, char *file, unsigned int line);
ERTS_GLB_INLINE void erts_smp_write_lock_x(erts_smp_rwlock_t *lock, char *file, unsigned int line);
#else
ERTS_GLB_INLINE void erts_smp_read_lock(erts_smp_rwlock_t *lock);
ERTS_GLB_INLINE void erts_smp_write_lock(erts_smp_rwlock_t *lock);
#endif
ERTS_GLB_INLINE void erts_smp_write_unlock(erts_smp_rwlock_t *lock);
ERTS_GLB_INLINE int erts_smp_lc_rwlock_is_rlocked(erts_smp_rwlock_t *lock);
ERTS_GLB_INLINE int erts_smp_lc_rwlock_is_rwlocked(erts_smp_rwlock_t *lock);
ERTS_GLB_INLINE void erts_smp_tsd_key_create(erts_smp_tsd_key_t *keyp);
ERTS_GLB_INLINE void erts_smp_tsd_key_delete(erts_smp_tsd_key_t key);
ERTS_GLB_INLINE void erts_smp_tsd_set(erts_smp_tsd_key_t key, void *value);
ERTS_GLB_INLINE void * erts_smp_tsd_get(erts_smp_tsd_key_t key);

#ifdef ERTS_THR_HAVE_SIG_FUNCS
#define ERTS_SMP_THR_HAVE_SIG_FUNCS 1
ERTS_GLB_INLINE void erts_smp_thr_sigmask(int how,
					  const sigset_t *set,
					  sigset_t *oset);
ERTS_GLB_INLINE void erts_smp_thr_sigwait(const sigset_t *set, int *sig);
#endif /* #ifdef ERTS_THR_HAVE_SIG_FUNCS */

/*
 * Functions implementing atomic operations with with no (nob),
 * full (mb), acquire (acqb), release (relb), read (rb), and
 * write (wb) memory barriers.
 *
 * If SMP support has been disabled, they are mapped to functions
 * that performs the same operation, but aren't atomic and don't
 * imply memory barriers.
 */

#ifdef ERTS_SMP

/* Double word size atomics */

#define erts_smp_dw_atomic_init_nob erts_dw_atomic_init_nob
#define erts_smp_dw_atomic_set_nob erts_dw_atomic_set_nob
#define erts_smp_dw_atomic_read_nob erts_dw_atomic_read_nob
#define erts_smp_dw_atomic_cmpxchg_nob erts_dw_atomic_cmpxchg_nob

#define erts_smp_dw_atomic_init_mb erts_dw_atomic_init_mb
#define erts_smp_dw_atomic_set_mb erts_dw_atomic_set_mb
#define erts_smp_dw_atomic_read_mb erts_dw_atomic_read_mb
#define erts_smp_dw_atomic_cmpxchg_mb erts_dw_atomic_cmpxchg_mb

#define erts_smp_dw_atomic_init_acqb erts_dw_atomic_init_acqb
#define erts_smp_dw_atomic_set_acqb erts_dw_atomic_set_acqb
#define erts_smp_dw_atomic_read_acqb erts_dw_atomic_read_acqb
#define erts_smp_dw_atomic_cmpxchg_acqb erts_dw_atomic_cmpxchg_acqb

#define erts_smp_dw_atomic_init_relb erts_dw_atomic_init_relb
#define erts_smp_dw_atomic_set_relb erts_dw_atomic_set_relb
#define erts_smp_dw_atomic_read_relb erts_dw_atomic_read_relb
#define erts_smp_dw_atomic_cmpxchg_relb erts_dw_atomic_cmpxchg_relb

#define erts_smp_dw_atomic_init_rb erts_dw_atomic_init_rb
#define erts_smp_dw_atomic_set_rb erts_dw_atomic_set_rb
#define erts_smp_dw_atomic_read_rb erts_dw_atomic_read_rb
#define erts_smp_dw_atomic_cmpxchg_rb erts_dw_atomic_cmpxchg_rb

#define erts_smp_dw_atomic_init_wb erts_dw_atomic_init_wb
#define erts_smp_dw_atomic_set_wb erts_dw_atomic_set_wb
#define erts_smp_dw_atomic_read_wb erts_dw_atomic_read_wb
#define erts_smp_dw_atomic_cmpxchg_wb erts_dw_atomic_cmpxchg_wb

/* Word size atomics */

#define erts_smp_atomic_init_nob erts_atomic_init_nob
#define erts_smp_atomic_set_nob erts_atomic_set_nob
#define erts_smp_atomic_read_nob erts_atomic_read_nob
#define erts_smp_atomic_inc_read_nob erts_atomic_inc_read_nob
#define erts_smp_atomic_dec_read_nob erts_atomic_dec_read_nob
#define erts_smp_atomic_inc_nob erts_atomic_inc_nob
#define erts_smp_atomic_dec_nob erts_atomic_dec_nob
#define erts_smp_atomic_add_read_nob erts_atomic_add_read_nob
#define erts_smp_atomic_add_nob erts_atomic_add_nob
#define erts_smp_atomic_read_bor_nob erts_atomic_read_bor_nob
#define erts_smp_atomic_read_band_nob erts_atomic_read_band_nob
#define erts_smp_atomic_xchg_nob erts_atomic_xchg_nob
#define erts_smp_atomic_cmpxchg_nob erts_atomic_cmpxchg_nob

#define erts_smp_atomic_init_mb erts_atomic_init_mb
#define erts_smp_atomic_set_mb erts_atomic_set_mb
#define erts_smp_atomic_read_mb erts_atomic_read_mb
#define erts_smp_atomic_inc_read_mb erts_atomic_inc_read_mb
#define erts_smp_atomic_dec_read_mb erts_atomic_dec_read_mb
#define erts_smp_atomic_inc_mb erts_atomic_inc_mb
#define erts_smp_atomic_dec_mb erts_atomic_dec_mb
#define erts_smp_atomic_add_read_mb erts_atomic_add_read_mb
#define erts_smp_atomic_add_mb erts_atomic_add_mb
#define erts_smp_atomic_read_bor_mb erts_atomic_read_bor_mb
#define erts_smp_atomic_read_band_mb erts_atomic_read_band_mb
#define erts_smp_atomic_xchg_mb erts_atomic_xchg_mb
#define erts_smp_atomic_cmpxchg_mb erts_atomic_cmpxchg_mb

#define erts_smp_atomic_init_acqb erts_atomic_init_acqb
#define erts_smp_atomic_set_acqb erts_atomic_set_acqb
#define erts_smp_atomic_read_acqb erts_atomic_read_acqb
#define erts_smp_atomic_inc_read_acqb erts_atomic_inc_read_acqb
#define erts_smp_atomic_dec_read_acqb erts_atomic_dec_read_acqb
#define erts_smp_atomic_inc_acqb erts_atomic_inc_acqb
#define erts_smp_atomic_dec_acqb erts_atomic_dec_acqb
#define erts_smp_atomic_add_read_acqb erts_atomic_add_read_acqb
#define erts_smp_atomic_add_acqb erts_atomic_add_acqb
#define erts_smp_atomic_read_bor_acqb erts_atomic_read_bor_acqb
#define erts_smp_atomic_read_band_acqb erts_atomic_read_band_acqb
#define erts_smp_atomic_xchg_acqb erts_atomic_xchg_acqb
#define erts_smp_atomic_cmpxchg_acqb erts_atomic_cmpxchg_acqb

#define erts_smp_atomic_init_relb erts_atomic_init_relb
#define erts_smp_atomic_set_relb erts_atomic_set_relb
#define erts_smp_atomic_read_relb erts_atomic_read_relb
#define erts_smp_atomic_inc_read_relb erts_atomic_inc_read_relb
#define erts_smp_atomic_dec_read_relb erts_atomic_dec_read_relb
#define erts_smp_atomic_inc_relb erts_atomic_inc_relb
#define erts_smp_atomic_dec_relb erts_atomic_dec_relb
#define erts_smp_atomic_add_read_relb erts_atomic_add_read_relb
#define erts_smp_atomic_add_relb erts_atomic_add_relb
#define erts_smp_atomic_read_bor_relb erts_atomic_read_bor_relb
#define erts_smp_atomic_read_band_relb erts_atomic_read_band_relb
#define erts_smp_atomic_xchg_relb erts_atomic_xchg_relb
#define erts_smp_atomic_cmpxchg_relb erts_atomic_cmpxchg_relb

#define erts_smp_atomic_init_rb erts_atomic_init_rb
#define erts_smp_atomic_set_rb erts_atomic_set_rb
#define erts_smp_atomic_read_rb erts_atomic_read_rb
#define erts_smp_atomic_inc_read_rb erts_atomic_inc_read_rb
#define erts_smp_atomic_dec_read_rb erts_atomic_dec_read_rb
#define erts_smp_atomic_inc_rb erts_atomic_inc_rb
#define erts_smp_atomic_dec_rb erts_atomic_dec_rb
#define erts_smp_atomic_add_read_rb erts_atomic_add_read_rb
#define erts_smp_atomic_add_rb erts_atomic_add_rb
#define erts_smp_atomic_read_bor_rb erts_atomic_read_bor_rb
#define erts_smp_atomic_read_band_rb erts_atomic_read_band_rb
#define erts_smp_atomic_xchg_rb erts_atomic_xchg_rb
#define erts_smp_atomic_cmpxchg_rb erts_atomic_cmpxchg_rb

#define erts_smp_atomic_init_wb erts_atomic_init_wb
#define erts_smp_atomic_set_wb erts_atomic_set_wb
#define erts_smp_atomic_read_wb erts_atomic_read_wb
#define erts_smp_atomic_inc_read_wb erts_atomic_inc_read_wb
#define erts_smp_atomic_dec_read_wb erts_atomic_dec_read_wb
#define erts_smp_atomic_inc_wb erts_atomic_inc_wb
#define erts_smp_atomic_dec_wb erts_atomic_dec_wb
#define erts_smp_atomic_add_read_wb erts_atomic_add_read_wb
#define erts_smp_atomic_add_wb erts_atomic_add_wb
#define erts_smp_atomic_read_bor_wb erts_atomic_read_bor_wb
#define erts_smp_atomic_read_band_wb erts_atomic_read_band_wb
#define erts_smp_atomic_xchg_wb erts_atomic_xchg_wb
#define erts_smp_atomic_cmpxchg_wb erts_atomic_cmpxchg_wb

/* 32-bit atomics */

#define erts_smp_atomic32_init_nob erts_atomic32_init_nob
#define erts_smp_atomic32_set_nob erts_atomic32_set_nob
#define erts_smp_atomic32_read_nob erts_atomic32_read_nob
#define erts_smp_atomic32_inc_read_nob erts_atomic32_inc_read_nob
#define erts_smp_atomic32_dec_read_nob erts_atomic32_dec_read_nob
#define erts_smp_atomic32_inc_nob erts_atomic32_inc_nob
#define erts_smp_atomic32_dec_nob erts_atomic32_dec_nob
#define erts_smp_atomic32_add_read_nob erts_atomic32_add_read_nob
#define erts_smp_atomic32_add_nob erts_atomic32_add_nob
#define erts_smp_atomic32_read_bor_nob erts_atomic32_read_bor_nob
#define erts_smp_atomic32_read_band_nob erts_atomic32_read_band_nob
#define erts_smp_atomic32_xchg_nob erts_atomic32_xchg_nob
#define erts_smp_atomic32_cmpxchg_nob erts_atomic32_cmpxchg_nob

#define erts_smp_atomic32_init_mb erts_atomic32_init_mb
#define erts_smp_atomic32_set_mb erts_atomic32_set_mb
#define erts_smp_atomic32_read_mb erts_atomic32_read_mb
#define erts_smp_atomic32_inc_read_mb erts_atomic32_inc_read_mb
#define erts_smp_atomic32_dec_read_mb erts_atomic32_dec_read_mb
#define erts_smp_atomic32_inc_mb erts_atomic32_inc_mb
#define erts_smp_atomic32_dec_mb erts_atomic32_dec_mb
#define erts_smp_atomic32_add_read_mb erts_atomic32_add_read_mb
#define erts_smp_atomic32_add_mb erts_atomic32_add_mb
#define erts_smp_atomic32_read_bor_mb erts_atomic32_read_bor_mb
#define erts_smp_atomic32_read_band_mb erts_atomic32_read_band_mb
#define erts_smp_atomic32_xchg_mb erts_atomic32_xchg_mb
#define erts_smp_atomic32_cmpxchg_mb erts_atomic32_cmpxchg_mb

#define erts_smp_atomic32_init_acqb erts_atomic32_init_acqb
#define erts_smp_atomic32_set_acqb erts_atomic32_set_acqb
#define erts_smp_atomic32_read_acqb erts_atomic32_read_acqb
#define erts_smp_atomic32_inc_read_acqb erts_atomic32_inc_read_acqb
#define erts_smp_atomic32_dec_read_acqb erts_atomic32_dec_read_acqb
#define erts_smp_atomic32_inc_acqb erts_atomic32_inc_acqb
#define erts_smp_atomic32_dec_acqb erts_atomic32_dec_acqb
#define erts_smp_atomic32_add_read_acqb erts_atomic32_add_read_acqb
#define erts_smp_atomic32_add_acqb erts_atomic32_add_acqb
#define erts_smp_atomic32_read_bor_acqb erts_atomic32_read_bor_acqb
#define erts_smp_atomic32_read_band_acqb erts_atomic32_read_band_acqb
#define erts_smp_atomic32_xchg_acqb erts_atomic32_xchg_acqb
#define erts_smp_atomic32_cmpxchg_acqb erts_atomic32_cmpxchg_acqb

#define erts_smp_atomic32_init_relb erts_atomic32_init_relb
#define erts_smp_atomic32_set_relb erts_atomic32_set_relb
#define erts_smp_atomic32_read_relb erts_atomic32_read_relb
#define erts_smp_atomic32_inc_read_relb erts_atomic32_inc_read_relb
#define erts_smp_atomic32_dec_read_relb erts_atomic32_dec_read_relb
#define erts_smp_atomic32_inc_relb erts_atomic32_inc_relb
#define erts_smp_atomic32_dec_relb erts_atomic32_dec_relb
#define erts_smp_atomic32_add_read_relb erts_atomic32_add_read_relb
#define erts_smp_atomic32_add_relb erts_atomic32_add_relb
#define erts_smp_atomic32_read_bor_relb erts_atomic32_read_bor_relb
#define erts_smp_atomic32_read_band_relb erts_atomic32_read_band_relb
#define erts_smp_atomic32_xchg_relb erts_atomic32_xchg_relb
#define erts_smp_atomic32_cmpxchg_relb erts_atomic32_cmpxchg_relb

#define erts_smp_atomic32_init_rb erts_atomic32_init_rb
#define erts_smp_atomic32_set_rb erts_atomic32_set_rb
#define erts_smp_atomic32_read_rb erts_atomic32_read_rb
#define erts_smp_atomic32_inc_read_rb erts_atomic32_inc_read_rb
#define erts_smp_atomic32_dec_read_rb erts_atomic32_dec_read_rb
#define erts_smp_atomic32_inc_rb erts_atomic32_inc_rb
#define erts_smp_atomic32_dec_rb erts_atomic32_dec_rb
#define erts_smp_atomic32_add_read_rb erts_atomic32_add_read_rb
#define erts_smp_atomic32_add_rb erts_atomic32_add_rb
#define erts_smp_atomic32_read_bor_rb erts_atomic32_read_bor_rb
#define erts_smp_atomic32_read_band_rb erts_atomic32_read_band_rb
#define erts_smp_atomic32_xchg_rb erts_atomic32_xchg_rb
#define erts_smp_atomic32_cmpxchg_rb erts_atomic32_cmpxchg_rb

#define erts_smp_atomic32_init_wb erts_atomic32_init_wb
#define erts_smp_atomic32_set_wb erts_atomic32_set_wb
#define erts_smp_atomic32_read_wb erts_atomic32_read_wb
#define erts_smp_atomic32_inc_read_wb erts_atomic32_inc_read_wb
#define erts_smp_atomic32_dec_read_wb erts_atomic32_dec_read_wb
#define erts_smp_atomic32_inc_wb erts_atomic32_inc_wb
#define erts_smp_atomic32_dec_wb erts_atomic32_dec_wb
#define erts_smp_atomic32_add_read_wb erts_atomic32_add_read_wb
#define erts_smp_atomic32_add_wb erts_atomic32_add_wb
#define erts_smp_atomic32_read_bor_wb erts_atomic32_read_bor_wb
#define erts_smp_atomic32_read_band_wb erts_atomic32_read_band_wb
#define erts_smp_atomic32_xchg_wb erts_atomic32_xchg_wb
#define erts_smp_atomic32_cmpxchg_wb erts_atomic32_cmpxchg_wb

#else /* !ERTS_SMP */

/* Double word size atomics */

#define erts_smp_dw_atomic_init_nob erts_no_dw_atomic_set
#define erts_smp_dw_atomic_set_nob erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_nob erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_nob erts_no_dw_atomic_cmpxchg

#define erts_smp_dw_atomic_init_mb erts_no_dw_atomic_init
#define erts_smp_dw_atomic_set_mb erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_mb erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_mb erts_no_dw_atomic_cmpxchg

#define erts_smp_dw_atomic_init_acqb erts_no_dw_atomic_init
#define erts_smp_dw_atomic_set_acqb erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_acqb erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_acqb erts_no_dw_atomic_cmpxchg

#define erts_smp_dw_atomic_init_relb erts_no_dw_atomic_init
#define erts_smp_dw_atomic_set_relb erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_relb erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_relb erts_no_dw_atomic_cmpxchg

#define erts_smp_dw_atomic_init_rb erts_no_dw_atomic_init
#define erts_smp_dw_atomic_set_rb erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_rb erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_rb erts_no_dw_atomic_cmpxchg

#define erts_smp_dw_atomic_init_wb erts_no_dw_atomic_init
#define erts_smp_dw_atomic_set_wb erts_no_dw_atomic_set
#define erts_smp_dw_atomic_read_wb erts_no_dw_atomic_read
#define erts_smp_dw_atomic_cmpxchg_wb erts_no_dw_atomic_cmpxchg

/* Word size atomics */

#define erts_smp_atomic_init_nob erts_no_atomic_set
#define erts_smp_atomic_set_nob erts_no_atomic_set
#define erts_smp_atomic_read_nob erts_no_atomic_read
#define erts_smp_atomic_inc_read_nob erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_nob erts_no_atomic_dec_read
#define erts_smp_atomic_inc_nob erts_no_atomic_inc
#define erts_smp_atomic_dec_nob erts_no_atomic_dec
#define erts_smp_atomic_add_read_nob erts_no_atomic_add_read
#define erts_smp_atomic_add_nob erts_no_atomic_add
#define erts_smp_atomic_read_bor_nob erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_nob erts_no_atomic_read_band
#define erts_smp_atomic_xchg_nob erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_nob erts_no_atomic_cmpxchg

#define erts_smp_atomic_init_mb erts_no_atomic_set
#define erts_smp_atomic_set_mb erts_no_atomic_set
#define erts_smp_atomic_read_mb erts_no_atomic_read
#define erts_smp_atomic_inc_read_mb erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_mb erts_no_atomic_dec_read
#define erts_smp_atomic_inc_mb erts_no_atomic_inc
#define erts_smp_atomic_dec_mb erts_no_atomic_dec
#define erts_smp_atomic_add_read_mb erts_no_atomic_add_read
#define erts_smp_atomic_add_mb erts_no_atomic_add
#define erts_smp_atomic_read_bor_mb erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_mb erts_no_atomic_read_band
#define erts_smp_atomic_xchg_mb erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_mb erts_no_atomic_cmpxchg

#define erts_smp_atomic_init_acqb erts_no_atomic_set
#define erts_smp_atomic_set_acqb erts_no_atomic_set
#define erts_smp_atomic_read_acqb erts_no_atomic_read
#define erts_smp_atomic_inc_read_acqb erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_acqb erts_no_atomic_dec_read
#define erts_smp_atomic_inc_acqb erts_no_atomic_inc
#define erts_smp_atomic_dec_acqb erts_no_atomic_dec
#define erts_smp_atomic_add_read_acqb erts_no_atomic_add_read
#define erts_smp_atomic_add_acqb erts_no_atomic_add
#define erts_smp_atomic_read_bor_acqb erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_acqb erts_no_atomic_read_band
#define erts_smp_atomic_xchg_acqb erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_acqb erts_no_atomic_cmpxchg

#define erts_smp_atomic_init_relb erts_no_atomic_set
#define erts_smp_atomic_set_relb erts_no_atomic_set
#define erts_smp_atomic_read_relb erts_no_atomic_read
#define erts_smp_atomic_inc_read_relb erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_relb erts_no_atomic_dec_read
#define erts_smp_atomic_inc_relb erts_no_atomic_inc
#define erts_smp_atomic_dec_relb erts_no_atomic_dec
#define erts_smp_atomic_add_read_relb erts_no_atomic_add_read
#define erts_smp_atomic_add_relb erts_no_atomic_add
#define erts_smp_atomic_read_bor_relb erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_relb erts_no_atomic_read_band
#define erts_smp_atomic_xchg_relb erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_relb erts_no_atomic_cmpxchg

#define erts_smp_atomic_init_rb erts_no_atomic_set
#define erts_smp_atomic_set_rb erts_no_atomic_set
#define erts_smp_atomic_read_rb erts_no_atomic_read
#define erts_smp_atomic_inc_read_rb erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_rb erts_no_atomic_dec_read
#define erts_smp_atomic_inc_rb erts_no_atomic_inc
#define erts_smp_atomic_dec_rb erts_no_atomic_dec
#define erts_smp_atomic_add_read_rb erts_no_atomic_add_read
#define erts_smp_atomic_add_rb erts_no_atomic_add
#define erts_smp_atomic_read_bor_rb erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_rb erts_no_atomic_read_band
#define erts_smp_atomic_xchg_rb erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_rb erts_no_atomic_cmpxchg

#define erts_smp_atomic_init_wb erts_no_atomic_set
#define erts_smp_atomic_set_wb erts_no_atomic_set
#define erts_smp_atomic_read_wb erts_no_atomic_read
#define erts_smp_atomic_inc_read_wb erts_no_atomic_inc_read
#define erts_smp_atomic_dec_read_wb erts_no_atomic_dec_read
#define erts_smp_atomic_inc_wb erts_no_atomic_inc
#define erts_smp_atomic_dec_wb erts_no_atomic_dec
#define erts_smp_atomic_add_read_wb erts_no_atomic_add_read
#define erts_smp_atomic_add_wb erts_no_atomic_add
#define erts_smp_atomic_read_bor_wb erts_no_atomic_read_bor
#define erts_smp_atomic_read_band_wb erts_no_atomic_read_band
#define erts_smp_atomic_xchg_wb erts_no_atomic_xchg
#define erts_smp_atomic_cmpxchg_wb erts_no_atomic_cmpxchg

/* 32-bit atomics */

#define erts_smp_atomic32_init_nob erts_no_atomic32_set
#define erts_smp_atomic32_set_nob erts_no_atomic32_set
#define erts_smp_atomic32_read_nob erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_nob erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_nob erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_nob erts_no_atomic32_inc
#define erts_smp_atomic32_dec_nob erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_nob erts_no_atomic32_add_read
#define erts_smp_atomic32_add_nob erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_nob erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_nob erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_nob erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_nob erts_no_atomic32_cmpxchg

#define erts_smp_atomic32_init_mb erts_no_atomic32_set
#define erts_smp_atomic32_set_mb erts_no_atomic32_set
#define erts_smp_atomic32_read_mb erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_mb erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_mb erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_mb erts_no_atomic32_inc
#define erts_smp_atomic32_dec_mb erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_mb erts_no_atomic32_add_read
#define erts_smp_atomic32_add_mb erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_mb erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_mb erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_mb erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_mb erts_no_atomic32_cmpxchg

#define erts_smp_atomic32_init_acqb erts_no_atomic32_set
#define erts_smp_atomic32_set_acqb erts_no_atomic32_set
#define erts_smp_atomic32_read_acqb erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_acqb erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_acqb erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_acqb erts_no_atomic32_inc
#define erts_smp_atomic32_dec_acqb erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_acqb erts_no_atomic32_add_read
#define erts_smp_atomic32_add_acqb erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_acqb erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_acqb erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_acqb erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_acqb erts_no_atomic32_cmpxchg

#define erts_smp_atomic32_init_relb erts_no_atomic32_set
#define erts_smp_atomic32_set_relb erts_no_atomic32_set
#define erts_smp_atomic32_read_relb erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_relb erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_relb erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_relb erts_no_atomic32_inc
#define erts_smp_atomic32_dec_relb erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_relb erts_no_atomic32_add_read
#define erts_smp_atomic32_add_relb erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_relb erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_relb erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_relb erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_relb erts_no_atomic32_cmpxchg

#define erts_smp_atomic32_init_rb erts_no_atomic32_set
#define erts_smp_atomic32_set_rb erts_no_atomic32_set
#define erts_smp_atomic32_read_rb erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_rb erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_rb erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_rb erts_no_atomic32_inc
#define erts_smp_atomic32_dec_rb erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_rb erts_no_atomic32_add_read
#define erts_smp_atomic32_add_rb erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_rb erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_rb erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_rb erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_rb erts_no_atomic32_cmpxchg

#define erts_smp_atomic32_init_wb erts_no_atomic32_set
#define erts_smp_atomic32_set_wb erts_no_atomic32_set
#define erts_smp_atomic32_read_wb erts_no_atomic32_read
#define erts_smp_atomic32_inc_read_wb erts_no_atomic32_inc_read
#define erts_smp_atomic32_dec_read_wb erts_no_atomic32_dec_read
#define erts_smp_atomic32_inc_wb erts_no_atomic32_inc
#define erts_smp_atomic32_dec_wb erts_no_atomic32_dec
#define erts_smp_atomic32_add_read_wb erts_no_atomic32_add_read
#define erts_smp_atomic32_add_wb erts_no_atomic32_add
#define erts_smp_atomic32_read_bor_wb erts_no_atomic32_read_bor
#define erts_smp_atomic32_read_band_wb erts_no_atomic32_read_band
#define erts_smp_atomic32_xchg_wb erts_no_atomic32_xchg
#define erts_smp_atomic32_cmpxchg_wb erts_no_atomic32_cmpxchg

#endif /* !ERTS_SMP */

#ifndef ERTS_NO_DEPRECATED_ATOMICS

/* Deprecated functions to replace */

#define erts_smp_atomic_init erts_smp_atomic_init_nob
#define erts_smp_atomic_set erts_smp_atomic_set_nob
#define erts_smp_atomic_read erts_smp_atomic_read_nob
#define erts_smp_atomic_inctest erts_smp_atomic_inc_read_mb
#define erts_smp_atomic_dectest erts_smp_atomic_dec_read_mb
#define erts_smp_atomic_inc erts_smp_atomic_inc_mb
#define erts_smp_atomic_dec erts_smp_atomic_dec_mb
#define erts_smp_atomic_addtest erts_smp_atomic_add_read_mb
#define erts_smp_atomic_add erts_smp_atomic_add_mb
#define erts_smp_atomic_xchg erts_smp_atomic_xchg_mb
#define erts_smp_atomic_cmpxchg erts_smp_atomic_cmpxchg_mb
#define erts_smp_atomic_bor erts_smp_atomic_read_bor_mb
#define erts_smp_atomic_band erts_smp_atomic_read_band_mb

#define erts_smp_atomic32_init erts_smp_atomic32_init_nob
#define erts_smp_atomic32_set erts_smp_atomic32_set_nob
#define erts_smp_atomic32_read erts_smp_atomic32_read_nob
#define erts_smp_atomic32_inctest erts_smp_atomic32_inc_read_mb
#define erts_smp_atomic32_dectest erts_smp_atomic32_dec_read_mb
#define erts_smp_atomic32_inc erts_smp_atomic32_inc_mb
#define erts_smp_atomic32_dec erts_smp_atomic32_dec_mb
#define erts_smp_atomic32_addtest erts_smp_atomic32_add_read_mb
#define erts_smp_atomic32_add erts_smp_atomic32_add_mb
#define erts_smp_atomic32_xchg erts_smp_atomic32_xchg_mb
#define erts_smp_atomic32_cmpxchg erts_smp_atomic32_cmpxchg_mb
#define erts_smp_atomic32_bor erts_smp_atomic32_read_bor_mb
#define erts_smp_atomic32_band erts_smp_atomic32_read_band_mb

#endif


#if ERTS_GLB_INLINE_INCL_FUNC_DEF

ERTS_GLB_INLINE void
erts_smp_thr_init(erts_smp_thr_init_data_t *id)
{
#ifdef ERTS_SMP
    erts_thr_init(id);
#endif
}

ERTS_GLB_INLINE void
erts_smp_thr_create(erts_smp_tid_t *tid, void * (*func)(void *), void *arg,
		    erts_smp_thr_opts_t *opts)
{
#ifdef ERTS_SMP
    erts_thr_create(tid, func, arg, opts);
#endif
}

ERTS_GLB_INLINE void
erts_smp_thr_join(erts_smp_tid_t tid, void **thr_res)
{
#ifdef ERTS_SMP
    erts_thr_join(tid, thr_res);
#endif
}


ERTS_GLB_INLINE void
erts_smp_thr_detach(erts_smp_tid_t tid)
{
#ifdef ERTS_SMP
    erts_thr_detach(tid);
#endif
}


ERTS_GLB_INLINE void
erts_smp_thr_exit(void *res)
{
#ifdef ERTS_SMP
    erts_thr_exit(res);
#endif
}

ERTS_GLB_INLINE void
erts_smp_install_exit_handler(void (*exit_handler)(void))
{
#ifdef ERTS_SMP
    erts_thr_install_exit_handler(exit_handler);
#endif
}

ERTS_GLB_INLINE erts_smp_tid_t
erts_smp_thr_self(void)
{
#ifdef ERTS_SMP
    return erts_thr_self();
#else
    return 0;
#endif
}


ERTS_GLB_INLINE int
erts_smp_equal_tids(erts_smp_tid_t x, erts_smp_tid_t y)
{
#ifdef ERTS_SMP
    return erts_equal_tids(x, y);
#else
    return 1;
#endif
}


#ifdef ERTS_HAVE_REC_MTX_INIT
ERTS_GLB_INLINE void
erts_smp_rec_mtx_init(erts_smp_mtx_t *mtx)
{
#ifdef ERTS_SMP
    erts_rec_mtx_init(mtx);
#endif
}
#endif

ERTS_GLB_INLINE void
erts_smp_mtx_init_x(erts_smp_mtx_t *mtx, char *name, Eterm extra)
{
#ifdef ERTS_SMP
    erts_mtx_init_x(mtx, name, extra);
#endif
}

ERTS_GLB_INLINE void
erts_smp_mtx_init_locked_x(erts_smp_mtx_t *mtx, char *name, Eterm extra)
{
#ifdef ERTS_SMP
    erts_mtx_init_locked_x(mtx, name, extra);
#endif
}

ERTS_GLB_INLINE void
erts_smp_mtx_init(erts_smp_mtx_t *mtx, char *name)
{
#ifdef ERTS_SMP
    erts_mtx_init(mtx, name);
#endif
}

ERTS_GLB_INLINE void
erts_smp_mtx_init_locked(erts_smp_mtx_t *mtx, char *name)
{
#ifdef ERTS_SMP
    erts_mtx_init_locked(mtx, name);
#endif
}

ERTS_GLB_INLINE void
erts_smp_mtx_destroy(erts_smp_mtx_t *mtx)
{
#ifdef ERTS_SMP
    erts_mtx_destroy(mtx);
#endif
}

ERTS_GLB_INLINE int
erts_smp_mtx_trylock(erts_smp_mtx_t *mtx)
{
#ifdef ERTS_SMP
    return erts_mtx_trylock(mtx);
#else
    return 0;
#endif

}


ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_mtx_lock_x(erts_smp_mtx_t *mtx, char *file, int line)
#else
erts_smp_mtx_lock(erts_smp_mtx_t *mtx)
#endif
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_COUNT)
    erts_mtx_lock_x(mtx, file, line);
#elif defined(ERTS_SMP)
    erts_mtx_lock(mtx);
#endif
}

ERTS_GLB_INLINE void
erts_smp_mtx_unlock(erts_smp_mtx_t *mtx)
{
#ifdef ERTS_SMP
    erts_mtx_unlock(mtx);
#endif
}

ERTS_GLB_INLINE int
erts_smp_lc_mtx_is_locked(erts_smp_mtx_t *mtx)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_mtx_is_locked(mtx);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
erts_smp_cnd_init(erts_smp_cnd_t *cnd)
{
#ifdef ERTS_SMP
    erts_cnd_init(cnd);
#endif
}

ERTS_GLB_INLINE void
erts_smp_cnd_destroy(erts_smp_cnd_t *cnd)
{
#ifdef ERTS_SMP
    erts_cnd_destroy(cnd);
#endif
}

ERTS_GLB_INLINE void
erts_smp_cnd_wait(erts_smp_cnd_t *cnd, erts_smp_mtx_t *mtx)
{
#ifdef ERTS_SMP
    erts_cnd_wait(cnd, mtx);
#endif
}

ERTS_GLB_INLINE void
erts_smp_cnd_signal(erts_smp_cnd_t *cnd)
{
#ifdef ERTS_SMP
    erts_cnd_signal(cnd);
#endif
}


ERTS_GLB_INLINE void
erts_smp_cnd_broadcast(erts_smp_cnd_t *cnd)
{
#ifdef ERTS_SMP
    erts_cnd_broadcast(cnd);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_set_reader_group(int no)
{
#ifdef ERTS_SMP
    erts_rwmtx_set_reader_group(no);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_init_opt_x(erts_smp_rwmtx_t *rwmtx,
			  erts_smp_rwmtx_opt_t *opt,
			  char *name,
			  Eterm extra)
{
#ifdef ERTS_SMP
    erts_rwmtx_init_opt_x(rwmtx, opt, name, extra);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_init_x(erts_smp_rwmtx_t *rwmtx, char *name, Eterm extra)
{
#ifdef ERTS_SMP
    erts_rwmtx_init_x(rwmtx, name, extra);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_init_opt(erts_smp_rwmtx_t *rwmtx,
			erts_smp_rwmtx_opt_t *opt,
			char *name)
{
#ifdef ERTS_SMP
    erts_rwmtx_init_opt(rwmtx, opt, name);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_init(erts_smp_rwmtx_t *rwmtx, char *name)
{
#ifdef ERTS_SMP
    erts_rwmtx_init(rwmtx, name);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_destroy(erts_smp_rwmtx_t *rwmtx)
{
#ifdef ERTS_SMP
    erts_rwmtx_destroy(rwmtx);
#endif
}

ERTS_GLB_INLINE int
erts_smp_rwmtx_tryrlock(erts_smp_rwmtx_t *rwmtx)
{
#ifdef ERTS_SMP
    return erts_rwmtx_tryrlock(rwmtx);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_rwmtx_rlock_x(erts_smp_rwmtx_t *rwmtx, char *file, unsigned int line)
#else
erts_smp_rwmtx_rlock(erts_smp_rwmtx_t *rwmtx)
#endif
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_COUNT)
    erts_rwmtx_rlock_x(rwmtx, file, line);
#elif defined(ERTS_SMP)
    erts_rwmtx_rlock(rwmtx);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_runlock(erts_smp_rwmtx_t *rwmtx)
{
#ifdef ERTS_SMP
    erts_rwmtx_runlock(rwmtx);
#endif
}


ERTS_GLB_INLINE int
erts_smp_rwmtx_tryrwlock(erts_smp_rwmtx_t *rwmtx)
{
#ifdef ERTS_SMP
    return erts_rwmtx_tryrwlock(rwmtx);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_rwmtx_rwlock_x(erts_smp_rwmtx_t *rwmtx, char *file, unsigned int line)
#else
erts_smp_rwmtx_rwlock(erts_smp_rwmtx_t *rwmtx)
#endif
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_COUNT)
    erts_rwmtx_rwlock_x(rwmtx, file, line);
#elif defined(ERTS_SMP)
    erts_rwmtx_rwlock(rwmtx);
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwmtx_rwunlock(erts_smp_rwmtx_t *rwmtx)
{
#ifdef ERTS_SMP
    erts_rwmtx_rwunlock(rwmtx);
#endif
}

#if 0 /* The following rwmtx function names are
	 reserved for potential future use. */ 

/* Try upgrade from r-locked state to rw-locked state */
ERTS_GLB_INLINE int
erts_smp_rwmtx_trywlock(erts_smp_rwmtx_t *rwmtx)
{
    return 0;
}

/* Upgrade from r-locked state to rw-locked state */
ERTS_GLB_INLINE void
erts_smp_rwmtx_wlock(erts_smp_rwmtx_t *rwmtx)
{

}

/* Downgrade from rw-locked state to r-locked state */
ERTS_GLB_INLINE void
erts_smp_rwmtx_wunlock(erts_smp_rwmtx_t *rwmtx)
{

}

#endif

ERTS_GLB_INLINE int
erts_smp_lc_rwmtx_is_rlocked(erts_smp_rwmtx_t *mtx)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_rwmtx_is_rlocked(mtx);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE int
erts_smp_lc_rwmtx_is_rwlocked(erts_smp_rwmtx_t *mtx)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_rwmtx_is_rwlocked(mtx);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
erts_smp_spinlock_init_x(erts_smp_spinlock_t *lock, char *name, Eterm extra)
{
#ifdef ERTS_SMP
    erts_spinlock_init_x(lock, name, extra);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_spinlock_init(erts_smp_spinlock_t *lock, char *name)
{
#ifdef ERTS_SMP
    erts_spinlock_init(lock, name);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_spinlock_destroy(erts_smp_spinlock_t *lock)
{
#ifdef ERTS_SMP
    erts_spinlock_destroy(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_spin_unlock(erts_smp_spinlock_t *lock)
{
#ifdef ERTS_SMP
    erts_spin_unlock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_spin_lock_x(erts_smp_spinlock_t *lock, char *file, unsigned int line)
#else
erts_smp_spin_lock(erts_smp_spinlock_t *lock)
#endif
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_COUNT)
    erts_spin_lock_x(lock, file, line);
#elif defined(ERTS_SMP)
    erts_spin_lock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE int
erts_smp_lc_spinlock_is_locked(erts_smp_spinlock_t *lock)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_spinlock_is_locked(lock);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwlock_init_x(erts_smp_rwlock_t *lock, char *name, Eterm extra)
{
#ifdef ERTS_SMP
    erts_rwlock_init_x(lock, name, extra);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwlock_init(erts_smp_rwlock_t *lock, char *name)
{
#ifdef ERTS_SMP
    erts_rwlock_init(lock, name);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_rwlock_destroy(erts_smp_rwlock_t *lock)
{
#ifdef ERTS_SMP
    erts_rwlock_destroy(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_read_unlock(erts_smp_rwlock_t *lock)
{
#ifdef ERTS_SMP
    erts_read_unlock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_read_lock_x(erts_smp_rwlock_t *lock, char *file, unsigned int line)
#else
erts_smp_read_lock(erts_smp_rwlock_t *lock)
#endif 
{
#if defined(ERTS_ENABLE_LOCK_COUNT) && defined(ERTS_SMP)
    erts_read_lock_x(lock, file, line);
#elif defined(ERTS_SMP)
    erts_read_lock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
erts_smp_write_unlock(erts_smp_rwlock_t *lock)
{
#ifdef ERTS_SMP
    erts_write_unlock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE void
#ifdef ERTS_ENABLE_LOCK_COUNT
erts_smp_write_lock_x(erts_smp_rwlock_t *lock, char *file, unsigned int line)
#else
erts_smp_write_lock(erts_smp_rwlock_t *lock)
#endif 
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_COUNT)
    erts_write_lock_x(lock, file, line);
#elif defined(ERTS_SMP)
    erts_write_lock(lock);
#else
    (void)lock;
#endif
}

ERTS_GLB_INLINE int
erts_smp_lc_rwlock_is_rlocked(erts_smp_rwlock_t *lock)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_rwlock_is_rlocked(lock);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE int
erts_smp_lc_rwlock_is_rwlocked(erts_smp_rwlock_t *lock)
{
#if defined(ERTS_SMP) && defined(ERTS_ENABLE_LOCK_CHECK)
    return erts_lc_rwlock_is_rwlocked(lock);
#else
    return 0;
#endif
}

ERTS_GLB_INLINE void
erts_smp_tsd_key_create(erts_smp_tsd_key_t *keyp)
{
#ifdef ERTS_SMP
    erts_tsd_key_create(keyp);
#endif
}

ERTS_GLB_INLINE void
erts_smp_tsd_key_delete(erts_smp_tsd_key_t key)
{
#ifdef ERTS_SMP
    erts_tsd_key_delete(key);
#endif
}

ERTS_GLB_INLINE void
erts_smp_tsd_set(erts_smp_tsd_key_t key, void *value)
{
#ifdef ERTS_SMP
    erts_tsd_set(key, value);
#endif
}

ERTS_GLB_INLINE void *
erts_smp_tsd_get(erts_smp_tsd_key_t key)
{
#ifdef ERTS_SMP
    return erts_tsd_get(key);
#else
    return NULL;
#endif
}

#ifdef ERTS_THR_HAVE_SIG_FUNCS
#define ERTS_SMP_THR_HAVE_SIG_FUNCS 1

ERTS_GLB_INLINE void
erts_smp_thr_sigmask(int how, const sigset_t *set, sigset_t *oset)
{
#ifdef ERTS_SMP
    erts_thr_sigmask(how, set, oset);
#endif
}

ERTS_GLB_INLINE void
erts_smp_thr_sigwait(const sigset_t *set, int *sig)
{
#ifdef ERTS_SMP
    erts_thr_sigwait(set, sig);
#endif
}

#endif /* #ifdef ERTS_THR_HAVE_SIG_FUNCS */

#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */

#endif /* ERL_SMP_H */

#ifdef ERTS_UNDEF_DEPRECATED_ATOMICS

/* Deprecated functions to replace */

#undef erts_smp_atomic_init
#undef erts_smp_atomic_set
#undef erts_smp_atomic_read
#undef erts_smp_atomic_inctest
#undef erts_smp_atomic_dectest
#undef erts_smp_atomic_inc
#undef erts_smp_atomic_dec
#undef erts_smp_atomic_addtest
#undef erts_smp_atomic_add
#undef erts_smp_atomic_xchg
#undef erts_smp_atomic_cmpxchg
#undef erts_smp_atomic_bor
#undef erts_smp_atomic_band

#undef erts_smp_atomic32_init
#undef erts_smp_atomic32_set
#undef erts_smp_atomic32_read
#undef erts_smp_atomic32_inctest
#undef erts_smp_atomic32_dectest
#undef erts_smp_atomic32_inc
#undef erts_smp_atomic32_dec
#undef erts_smp_atomic32_addtest
#undef erts_smp_atomic32_add
#undef erts_smp_atomic32_xchg
#undef erts_smp_atomic32_cmpxchg
#undef erts_smp_atomic32_bor
#undef erts_smp_atomic32_band

#endif