XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
u32.c
浏览该文件的文档.
1
13#include <xwos/standard.h>
14
15#if __STDC_VERSION__ >= 201112L
16
17#include <stdatomic.h>
18#include <xwos/lib/xwaop.h>
19
21xwu32_t xwaop__xwu32_t__load(atomic_xwu32_t * a,
22 const enum xwaop_memory_order_em mo)
23{
24 xwu32_t v;
25
26 v = atomic_load_explicit(a, (int)mo);
27 return v;
28}
29
31xwu32_t xwaop__xwu32_t__store(atomic_xwu32_t * a,
32 const enum xwaop_memory_order_em mo,
33 xwu32_t v)
34{
35 atomic_store_explicit(a, v, (int)mo);
36 return v;
37}
38
40void xwaop__xwu32_t__read(atomic_xwu32_t * a,
41 xwu32_t * ov)
42{
43 xwu32_t o;
44
45 o = atomic_load_explicit(a, memory_order_acquire);
46 if (ov) {
47 *ov = o;
48 }
49}
50
52void xwaop__xwu32_t__write(atomic_xwu32_t * a,
53 xwu32_t v,
54 xwu32_t * ov)
55{
56 xwu32_t o;
57
58 o = atomic_exchange_explicit(a, v, memory_order_acq_rel);
59 if (ov) {
60 *ov = o;
61 }
62}
63
65xwer_t xwaop__xwu32_t__teq_then_write(atomic_xwu32_t * a,
66 xwu32_t t,
67 xwu32_t v,
68 xwu32_t * ov)
69{
70 xwu32_t o;
71 xwer_t rc;
72
73 o = t;
74 rc = (xwer_t)atomic_compare_exchange_strong_explicit(a, &o, v,
75 memory_order_acq_rel,
76 memory_order_consume);
77 if ((bool)rc) {
78 rc = XWOK;
79 } else {
80 rc = -EACCES;
81 }
82 if (ov) {
83 *ov = o;
84 }
85 return rc;
86}
87
89xwer_t xwaop__xwu32_t__tne_then_write(atomic_xwu32_t * a,
90 xwu32_t t,
91 xwu32_t v,
92 xwu32_t * ov)
93{
94 xwu32_t o;
95 xwer_t rc;
96
97 do {
98 o = atomic_load_explicit(a, memory_order_consume);
99 if (o != t) {
100 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
101 a, &o, v,
102 memory_order_acq_rel,
103 memory_order_consume);
104 if ((bool)rc) {
105 rc = XWOK;
106 }
107 } else {
108 rc = -EACCES;
109 break;
110 }
111 } while (rc != XWOK);
112 if (ov) {
113 *ov = o;
114 }
115 return rc;
116}
117
119xwer_t xwaop__xwu32_t__tgt_then_write(atomic_xwu32_t * a,
120 xwu32_t t,
121 xwu32_t v,
122 xwu32_t * ov)
123{
124 xwu32_t o;
125 xwer_t rc;
126
127 do {
128 o = atomic_load_explicit(a, memory_order_consume);
129 if (o > t) {
130 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
131 a, &o, v,
132 memory_order_acq_rel,
133 memory_order_consume);
134 if ((bool)rc) {
135 rc = XWOK;
136 }
137 } else {
138 rc = -EACCES;
139 break;
140 }
141 } while (rc != XWOK);
142 if (ov) {
143 *ov = o;
144 }
145 return rc;
146}
147
149xwer_t xwaop__xwu32_t__tge_then_write(atomic_xwu32_t * a,
150 xwu32_t t,
151 xwu32_t v,
152 xwu32_t * ov)
153{
154 xwu32_t o;
155 xwer_t rc;
156
157 do {
158 o = atomic_load_explicit(a, memory_order_consume);
159 if (o >= t) {
160 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
161 a, &o, v,
162 memory_order_acq_rel,
163 memory_order_consume);
164 if ((bool)rc) {
165 rc = XWOK;
166 }
167 } else {
168 rc = -EACCES;
169 break;
170 }
171 } while (rc != XWOK);
172 if (ov) {
173 *ov = o;
174 }
175 return rc;
176}
177
179xwer_t xwaop__xwu32_t__tlt_then_write(atomic_xwu32_t * a,
180 xwu32_t t,
181 xwu32_t v,
182 xwu32_t * ov)
183{
184 xwu32_t o;
185 xwer_t rc;
186
187 do {
188 o = atomic_load_explicit(a, memory_order_consume);
189 if (o < t) {
190 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
191 a, &o, v,
192 memory_order_acq_rel,
193 memory_order_consume);
194 if ((bool)rc) {
195 rc = XWOK;
196 }
197 } else {
198 rc = -EACCES;
199 break;
200 }
201 } while (rc != XWOK);
202 if (ov) {
203 *ov = o;
204 }
205 return rc;
206}
207
209xwer_t xwaop__xwu32_t__tle_then_write(atomic_xwu32_t * a,
210 xwu32_t t,
211 xwu32_t v,
212 xwu32_t * ov)
213{
214 xwu32_t o;
215 xwer_t rc;
216
217 do {
218 o = atomic_load_explicit(a, memory_order_consume);
219 if (o <= t) {
220 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
221 a, &o, v,
222 memory_order_acq_rel,
223 memory_order_consume);
224 if ((bool)rc) {
225 rc = XWOK;
226 }
227 } else {
228 rc = -EACCES;
229 break;
230 }
231 } while (rc != XWOK);
232 if (ov) {
233 *ov = o;
234 }
235 return rc;
236}
237
239xwer_t xwaop__xwu32_t__tgtlt_then_write(atomic_xwu32_t * a,
240 xwu32_t l, xwu32_t r,
241 xwu32_t v,
242 xwu32_t * ov)
243{
244 xwu32_t o;
245 xwer_t rc;
246
247 do {
248 o = atomic_load_explicit(a, memory_order_consume);
249 if ((o > l) && (o < r)) {
250 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
251 a, &o, v,
252 memory_order_acq_rel,
253 memory_order_consume);
254 if ((bool)rc) {
255 rc = XWOK;
256 }
257 } else {
258 rc = -EACCES;
259 break;
260 }
261 } while (rc != XWOK);
262 if (ov) {
263 *ov = o;
264 }
265 return rc;
266}
267
269xwer_t xwaop__xwu32_t__tgelt_then_write(atomic_xwu32_t * a,
270 xwu32_t l, xwu32_t r,
271 xwu32_t v,
272 xwu32_t * ov)
273{
274 xwu32_t o;
275 xwer_t rc;
276
277 do {
278 o = atomic_load_explicit(a, memory_order_consume);
279 if ((o >= l) && (o < r)) {
280 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
281 a, &o, v,
282 memory_order_acq_rel,
283 memory_order_consume);
284 if ((bool)rc) {
285 rc = XWOK;
286 }
287 } else {
288 rc = -EACCES;
289 break;
290 }
291 } while (rc != XWOK);
292 if (ov) {
293 *ov = o;
294 }
295 return rc;
296}
297
299xwer_t xwaop__xwu32_t__tgtle_then_write(atomic_xwu32_t * a,
300 xwu32_t l, xwu32_t r,
301 xwu32_t v,
302 xwu32_t * ov)
303{
304 xwu32_t o;
305 xwer_t rc;
306
307 do {
308 o = atomic_load_explicit(a, memory_order_consume);
309 if ((o > l) && (o <= r)) {
310 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
311 a, &o, v,
312 memory_order_acq_rel,
313 memory_order_consume);
314 if ((bool)rc) {
315 rc = XWOK;
316 }
317 } else {
318 rc = -EACCES;
319 break;
320 }
321 } while (rc != XWOK);
322 if (ov) {
323 *ov = o;
324 }
325 return rc;
326}
327
329xwer_t xwaop__xwu32_t__tgele_then_write(atomic_xwu32_t * a,
330 xwu32_t l, xwu32_t r,
331 xwu32_t v,
332 xwu32_t * ov)
333{
334 xwu32_t o;
335 xwer_t rc;
336
337 do {
338 o = atomic_load_explicit(a, memory_order_consume);
339 if ((o >= l) && (o <= r)) {
340 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
341 a, &o, v,
342 memory_order_acq_rel,
343 memory_order_consume);
344 if ((bool)rc) {
345 rc = XWOK;
346 }
347 } else {
348 rc = -EACCES;
349 break;
350 }
351 } while (rc != XWOK);
352 if (ov) {
353 *ov = o;
354 }
355 return rc;
356}
357
358/******** ******** add ******** ********/
360void xwaop__xwu32_t__add(atomic_xwu32_t * a,
361 xwu32_t v,
362 xwu32_t * nv, xwu32_t * ov)
363{
364 xwu32_t o;
365
366 o = atomic_fetch_add_explicit(a, v, memory_order_acq_rel);
367 if (nv) {
368 *nv = o + v;
369 }
370 if (ov) {
371 *ov = o;
372 }
373}
374
376xwer_t xwaop__xwu32_t__teq_then_add(atomic_xwu32_t * a,
377 xwu32_t t,
378 xwu32_t v,
379 xwu32_t * nv, xwu32_t * ov)
380{
381 xwu32_t o;
382 xwu32_t n;
383 xwer_t rc;
384
385 o = t;
386 n = o + v;
387 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
388 a, &o, n,
389 memory_order_acq_rel,
390 memory_order_consume);
391 if ((bool)rc) {
392 rc = XWOK;
393 } else {
394 rc = -EACCES;
395 n = o;
396 }
397 if (nv) {
398 *nv = n;
399 }
400 if (ov) {
401 *ov = o;
402 }
403 return rc;
404}
405
407xwer_t xwaop__xwu32_t__tne_then_add(atomic_xwu32_t * a,
408 xwu32_t t,
409 xwu32_t v,
410 xwu32_t * nv, xwu32_t * ov)
411{
412 xwu32_t o;
413 xwu32_t n;
414 xwer_t rc;
415
416 do {
417 o = atomic_load_explicit(a, memory_order_consume);
418 if (o != t) {
419 n = o + v;
420 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
421 a, &o, n,
422 memory_order_acq_rel,
423 memory_order_consume);
424 if ((bool)rc) {
425 rc = XWOK;
426 }
427 } else {
428 rc = -EACCES;
429 n = o;
430 break;
431 }
432 } while (rc != XWOK);
433 if (nv) {
434 *nv = n;
435 }
436 if (ov) {
437 *ov = o;
438 }
439 return rc;
440}
441
443xwer_t xwaop__xwu32_t__tgt_then_add(atomic_xwu32_t * a,
444 xwu32_t t,
445 xwu32_t v,
446 xwu32_t * nv, xwu32_t * ov)
447{
448 xwu32_t o;
449 xwu32_t n;
450 xwer_t rc;
451
452 do {
453 o = atomic_load_explicit(a, memory_order_consume);
454 if (o > t) {
455 n = o + v;
456 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
457 a, &o, n,
458 memory_order_acq_rel,
459 memory_order_consume);
460 if ((bool)rc) {
461 rc = XWOK;
462 }
463 } else {
464 rc = -EACCES;
465 n = o;
466 break;
467 }
468 } while (rc != XWOK);
469 if (nv) {
470 *nv = n;
471 }
472 if (ov) {
473 *ov = o;
474 }
475 return rc;
476}
477
479xwer_t xwaop__xwu32_t__tge_then_add(atomic_xwu32_t * a,
480 xwu32_t t,
481 xwu32_t v,
482 xwu32_t * nv, xwu32_t * ov)
483{
484 xwu32_t o;
485 xwu32_t n;
486 xwer_t rc;
487
488 do {
489 o = atomic_load_explicit(a, memory_order_consume);
490 if (o >= t) {
491 n = o + v;
492 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
493 a, &o, n,
494 memory_order_acq_rel,
495 memory_order_consume);
496 if ((bool)rc) {
497 rc = XWOK;
498 }
499 } else {
500 rc = -EACCES;
501 n = o;
502 break;
503 }
504 } while (rc != XWOK);
505 if (nv) {
506 *nv = n;
507 }
508 if (ov) {
509 *ov = o;
510 }
511 return rc;
512}
513
515xwer_t xwaop__xwu32_t__tlt_then_add(atomic_xwu32_t * a,
516 xwu32_t t,
517 xwu32_t v,
518 xwu32_t * nv, xwu32_t * ov)
519{
520 xwu32_t o;
521 xwu32_t n;
522 xwer_t rc;
523
524 do {
525 o = atomic_load_explicit(a, memory_order_consume);
526 if (o < t) {
527 n = o + v;
528 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
529 a, &o, n,
530 memory_order_acq_rel,
531 memory_order_consume);
532 if ((bool)rc) {
533 rc = XWOK;
534 }
535 } else {
536 rc = -EACCES;
537 n = o;
538 break;
539 }
540 } while (rc != XWOK);
541 if (nv) {
542 *nv = n;
543 }
544 if (ov) {
545 *ov = o;
546 }
547 return rc;
548}
549
551xwer_t xwaop__xwu32_t__tle_then_add(atomic_xwu32_t * a,
552 xwu32_t t,
553 xwu32_t v,
554 xwu32_t * nv, xwu32_t * ov)
555{
556 xwu32_t o;
557 xwu32_t n;
558 xwer_t rc;
559
560 do {
561 o = atomic_load_explicit(a, memory_order_consume);
562 if (o <= t) {
563 n = o + v;
564 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
565 a, &o, n,
566 memory_order_acq_rel,
567 memory_order_consume);
568 if ((bool)rc) {
569 rc = XWOK;
570 }
571 } else {
572 rc = -EACCES;
573 n = o;
574 break;
575 }
576 } while (rc != XWOK);
577 if (nv) {
578 *nv = n;
579 }
580 if (ov) {
581 *ov = o;
582 }
583 return rc;
584}
585
587xwer_t xwaop__xwu32_t__tgtlt_then_add(atomic_xwu32_t * a,
588 xwu32_t l, xwu32_t r,
589 xwu32_t v,
590 xwu32_t * nv, xwu32_t * ov)
591{
592 xwu32_t o;
593 xwu32_t n;
594 xwer_t rc;
595
596 do {
597 o = atomic_load_explicit(a, memory_order_consume);
598 if ((o > l) && (o < r)) {
599 n = o + v;
600 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
601 a, &o, n,
602 memory_order_acq_rel,
603 memory_order_consume);
604 if ((bool)rc) {
605 rc = XWOK;
606 }
607 } else {
608 rc = -EACCES;
609 n = o;
610 break;
611 }
612 } while (rc != XWOK);
613 if (nv) {
614 *nv = n;
615 }
616 if (ov) {
617 *ov = o;
618 }
619 return rc;
620}
621
623xwer_t xwaop__xwu32_t__tgelt_then_add(atomic_xwu32_t * a,
624 xwu32_t l, xwu32_t r,
625 xwu32_t v,
626 xwu32_t * nv, xwu32_t * ov)
627{
628 xwu32_t o;
629 xwu32_t n;
630 xwer_t rc;
631
632 do {
633 o = atomic_load_explicit(a, memory_order_consume);
634 if ((o >= l) && (o < r)) {
635 n = o + v;
636 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
637 a, &o, n,
638 memory_order_acq_rel,
639 memory_order_consume);
640 if ((bool)rc) {
641 rc = XWOK;
642 }
643 } else {
644 rc = -EACCES;
645 n = o;
646 break;
647 }
648 } while (rc != XWOK);
649 if (nv) {
650 *nv = n;
651 }
652 if (ov) {
653 *ov = o;
654 }
655 return rc;
656}
657
659xwer_t xwaop__xwu32_t__tgtle_then_add(atomic_xwu32_t * a,
660 xwu32_t l, xwu32_t r,
661 xwu32_t v,
662 xwu32_t * nv, xwu32_t * ov)
663{
664 xwu32_t o;
665 xwu32_t n;
666 xwer_t rc;
667
668 do {
669 o = atomic_load_explicit(a, memory_order_consume);
670 if ((o > l) && (o <= r)) {
671 n = o + v;
672 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
673 a, &o, n,
674 memory_order_acq_rel,
675 memory_order_consume);
676 if ((bool)rc) {
677 rc = XWOK;
678 }
679 } else {
680 rc = -EACCES;
681 n = o;
682 break;
683 }
684 } while (rc != XWOK);
685 if (nv) {
686 *nv = n;
687 }
688 if (ov) {
689 *ov = o;
690 }
691 return rc;
692}
693
695xwer_t xwaop__xwu32_t__tgele_then_add(atomic_xwu32_t * a,
696 xwu32_t l, xwu32_t r,
697 xwu32_t v,
698 xwu32_t * nv, xwu32_t * ov)
699{
700 xwu32_t o;
701 xwu32_t n;
702 xwer_t rc;
703
704 do {
705 o = atomic_load_explicit(a, memory_order_consume);
706 if ((o >= l) && (o <= r)) {
707 n = o + v;
708 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
709 a, &o, n,
710 memory_order_acq_rel,
711 memory_order_consume);
712 if ((bool)rc) {
713 rc = XWOK;
714 }
715 } else {
716 rc = -EACCES;
717 n = o;
718 break;
719 }
720 } while (rc != XWOK);
721 if (nv) {
722 *nv = n;
723 }
724 if (ov) {
725 *ov = o;
726 }
727 return rc;
728}
729
730/******** ******** subtract ******** ********/
732void xwaop__xwu32_t__sub(atomic_xwu32_t * a,
733 xwu32_t v,
734 xwu32_t * nv, xwu32_t * ov)
735{
736 xwu32_t o;
737
738 o = atomic_fetch_sub_explicit(a, v, memory_order_acq_rel);
739 if (nv) {
740 *nv = o - v;
741 }
742 if (ov) {
743 *ov = o;
744 }
745}
746
748xwer_t xwaop__xwu32_t__teq_then_sub(atomic_xwu32_t * a,
749 xwu32_t t,
750 xwu32_t v,
751 xwu32_t * nv, xwu32_t * ov)
752{
753 xwu32_t o;
754 xwu32_t n;
755 xwer_t rc;
756
757 o = t;
758 n = o - v;
759 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
760 a, &o, n,
761 memory_order_acq_rel,
762 memory_order_consume);
763 if ((bool)rc) {
764 rc = XWOK;
765 } else {
766 rc = -EACCES;
767 n = o;
768 }
769 if (nv) {
770 *nv = n;
771 }
772 if (ov) {
773 *ov = o;
774 }
775 return rc;
776}
777
779xwer_t xwaop__xwu32_t__tne_then_sub(atomic_xwu32_t * a,
780 xwu32_t t,
781 xwu32_t v,
782 xwu32_t * nv, xwu32_t * ov)
783{
784 xwu32_t o;
785 xwu32_t n;
786 xwer_t rc;
787
788 do {
789 o = atomic_load_explicit(a, memory_order_consume);
790 if (o != t) {
791 n = o - v;
792 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
793 a, &o, n,
794 memory_order_acq_rel,
795 memory_order_consume);
796 if ((bool)rc) {
797 rc = XWOK;
798 }
799 } else {
800 rc = -EACCES;
801 n = o;
802 break;
803 }
804 } while (rc != XWOK);
805 if (nv) {
806 *nv = n;
807 }
808 if (ov) {
809 *ov = o;
810 }
811 return rc;
812}
813
815xwer_t xwaop__xwu32_t__tgt_then_sub(atomic_xwu32_t * a,
816 xwu32_t t,
817 xwu32_t v,
818 xwu32_t * nv, xwu32_t * ov)
819{
820 xwu32_t o;
821 xwu32_t n;
822 xwer_t rc;
823
824 do {
825 o = atomic_load_explicit(a, memory_order_consume);
826 if (o > t) {
827 n = o - v;
828 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
829 a, &o, n,
830 memory_order_acq_rel,
831 memory_order_consume);
832 if ((bool)rc) {
833 rc = XWOK;
834 }
835 } else {
836 rc = -EACCES;
837 n = o;
838 break;
839 }
840 } while (rc != XWOK);
841 if (nv) {
842 *nv = n;
843 }
844 if (ov) {
845 *ov = o;
846 }
847 return rc;
848}
849
851xwer_t xwaop__xwu32_t__tge_then_sub(atomic_xwu32_t * a,
852 xwu32_t t,
853 xwu32_t v,
854 xwu32_t * nv, xwu32_t * ov)
855{
856 xwu32_t o;
857 xwu32_t n;
858 xwer_t rc;
859
860 do {
861 o = atomic_load_explicit(a, memory_order_consume);
862 if (o >= t) {
863 n = o - v;
864 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
865 a, &o, n,
866 memory_order_acq_rel,
867 memory_order_consume);
868 if ((bool)rc) {
869 rc = XWOK;
870 }
871 } else {
872 rc = -EACCES;
873 n = o;
874 break;
875 }
876 } while (rc != XWOK);
877 if (nv) {
878 *nv = n;
879 }
880 if (ov) {
881 *ov = o;
882 }
883 return rc;
884}
885
887xwer_t xwaop__xwu32_t__tlt_then_sub(atomic_xwu32_t * a,
888 xwu32_t t,
889 xwu32_t v,
890 xwu32_t * nv, xwu32_t * ov)
891{
892 xwu32_t o;
893 xwu32_t n;
894 xwer_t rc;
895
896 do {
897 o = atomic_load_explicit(a, memory_order_consume);
898 if (o < t) {
899 n = o - v;
900 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
901 a, &o, n,
902 memory_order_acq_rel,
903 memory_order_consume);
904 if ((bool)rc) {
905 rc = XWOK;
906 }
907 } else {
908 rc = -EACCES;
909 n = o;
910 break;
911 }
912 } while (rc != XWOK);
913 if (nv) {
914 *nv = n;
915 }
916 if (ov) {
917 *ov = o;
918 }
919 return rc;
920}
921
923xwer_t xwaop__xwu32_t__tle_then_sub(atomic_xwu32_t * a,
924 xwu32_t t,
925 xwu32_t v,
926 xwu32_t * nv, xwu32_t * ov)
927{
928 xwu32_t o;
929 xwu32_t n;
930 xwer_t rc;
931
932 do {
933 o = atomic_load_explicit(a, memory_order_consume);
934 if (o <= t) {
935 n = o - v;
936 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
937 a, &o, n,
938 memory_order_acq_rel,
939 memory_order_consume);
940 if ((bool)rc) {
941 rc = XWOK;
942 }
943 } else {
944 rc = -EACCES;
945 n = o;
946 break;
947 }
948 } while (rc != XWOK);
949 if (nv) {
950 *nv = n;
951 }
952 if (ov) {
953 *ov = o;
954 }
955 return rc;
956}
957
959xwer_t xwaop__xwu32_t__tgtlt_then_sub(atomic_xwu32_t * a,
960 xwu32_t l, xwu32_t r,
961 xwu32_t v,
962 xwu32_t * nv, xwu32_t * ov)
963{
964 xwu32_t o;
965 xwu32_t n;
966 xwer_t rc;
967
968 do {
969 o = atomic_load_explicit(a, memory_order_consume);
970 if ((o > l) && (o < r)) {
971 n = o - v;
972 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
973 a, &o, n,
974 memory_order_acq_rel,
975 memory_order_consume);
976 if ((bool)rc) {
977 rc = XWOK;
978 }
979 } else {
980 rc = -EACCES;
981 n = o;
982 break;
983 }
984 } while (rc != XWOK);
985 if (nv) {
986 *nv = n;
987 }
988 if (ov) {
989 *ov = o;
990 }
991 return rc;
992}
993
995xwer_t xwaop__xwu32_t__tgelt_then_sub(atomic_xwu32_t * a,
996 xwu32_t l, xwu32_t r,
997 xwu32_t v,
998 xwu32_t * nv, xwu32_t * ov)
999{
1000 xwu32_t o;
1001 xwu32_t n;
1002 xwer_t rc;
1003
1004 do {
1005 o = atomic_load_explicit(a, memory_order_consume);
1006 if ((o >= l) && (o < r)) {
1007 n = o - v;
1008 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1009 a, &o, n,
1010 memory_order_acq_rel,
1011 memory_order_consume);
1012 if ((bool)rc) {
1013 rc = XWOK;
1014 }
1015 } else {
1016 rc = -EACCES;
1017 n = o;
1018 break;
1019 }
1020 } while (rc != XWOK);
1021 if (nv) {
1022 *nv = n;
1023 }
1024 if (ov) {
1025 *ov = o;
1026 }
1027 return rc;
1028}
1029
1031xwer_t xwaop__xwu32_t__tgtle_then_sub(atomic_xwu32_t * a,
1032 xwu32_t l, xwu32_t r,
1033 xwu32_t v,
1034 xwu32_t * nv, xwu32_t * ov)
1035{
1036 xwu32_t o;
1037 xwu32_t n;
1038 xwer_t rc;
1039
1040 do {
1041 o = atomic_load_explicit(a, memory_order_consume);
1042 if ((o > l) && (o <= r)) {
1043 n = o - v;
1044 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1045 a, &o, n,
1046 memory_order_acq_rel,
1047 memory_order_consume);
1048 if ((bool)rc) {
1049 rc = XWOK;
1050 }
1051 } else {
1052 rc = -EACCES;
1053 n = o;
1054 break;
1055 }
1056 } while (rc != XWOK);
1057 if (nv) {
1058 *nv = n;
1059 }
1060 if (ov) {
1061 *ov = o;
1062 }
1063 return rc;
1064}
1065
1067xwer_t xwaop__xwu32_t__tgele_then_sub(atomic_xwu32_t * a,
1068 xwu32_t l, xwu32_t r,
1069 xwu32_t v,
1070 xwu32_t * nv, xwu32_t * ov)
1071{
1072 xwu32_t o;
1073 xwu32_t n;
1074 xwer_t rc;
1075
1076 do {
1077 o = atomic_load_explicit(a, memory_order_consume);
1078 if ((o >= l) && (o <= r)) {
1079 n = o - v;
1080 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1081 a, &o, n,
1082 memory_order_acq_rel,
1083 memory_order_consume);
1084 if ((bool)rc) {
1085 rc = XWOK;
1086 }
1087 } else {
1088 rc = -EACCES;
1089 n = o;
1090 break;
1091 }
1092 } while (rc != XWOK);
1093 if (nv) {
1094 *nv = n;
1095 }
1096 if (ov) {
1097 *ov = o;
1098 }
1099 return rc;
1100}
1101
1102/******** ******** reverse subtract ******** ********/
1104void xwaop__xwu32_t__rsb(atomic_xwu32_t * a,
1105 xwu32_t v,
1106 xwu32_t * nv, xwu32_t * ov)
1107{
1108 xwu32_t o;
1109 xwu32_t n;
1110 bool r;
1111
1112 do {
1113 o = atomic_load_explicit(a, memory_order_relaxed);
1114 n = v - o;
1115 r = atomic_compare_exchange_strong_explicit(
1116 a, &o, n,
1117 memory_order_acq_rel,
1118 memory_order_relaxed);
1119 } while (!r);
1120 if (nv) {
1121 *nv = n;
1122 }
1123 if (ov) {
1124 *ov = o;
1125 }
1126}
1127
1129xwer_t xwaop__xwu32_t__teq_then_rsb(atomic_xwu32_t * a,
1130 xwu32_t t,
1131 xwu32_t v,
1132 xwu32_t * nv, xwu32_t * ov)
1133{
1134 xwu32_t o;
1135 xwu32_t n;
1136 xwer_t rc;
1137
1138 do {
1139 o = atomic_load_explicit(a, memory_order_consume);
1140 if (o == t) {
1141 n = v - o;
1142 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1143 a, &o, n,
1144 memory_order_acq_rel,
1145 memory_order_consume);
1146 if ((bool)rc) {
1147 rc = XWOK;
1148 }
1149 } else {
1150 rc = -EACCES;
1151 n = o;
1152 break;
1153 }
1154 } while (rc != XWOK);
1155 if (nv) {
1156 *nv = n;
1157 }
1158 if (ov) {
1159 *ov = o;
1160 }
1161 return rc;
1162}
1163
1165xwer_t xwaop__xwu32_t__tne_then_rsb(atomic_xwu32_t * a,
1166 xwu32_t t,
1167 xwu32_t v,
1168 xwu32_t * nv, xwu32_t * ov)
1169{
1170 xwu32_t o;
1171 xwu32_t n;
1172 xwer_t rc;
1173
1174 do {
1175 o = atomic_load_explicit(a, memory_order_consume);
1176 if (o != t) {
1177 n = v - o;
1178 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1179 a, &o, n,
1180 memory_order_acq_rel,
1181 memory_order_consume);
1182 if ((bool)rc) {
1183 rc = XWOK;
1184 }
1185 } else {
1186 rc = -EACCES;
1187 n = o;
1188 break;
1189 }
1190 } while (rc != XWOK);
1191 if (nv) {
1192 *nv = n;
1193 }
1194 if (ov) {
1195 *ov = o;
1196 }
1197 return rc;
1198}
1199
1201xwer_t xwaop__xwu32_t__tgt_then_rsb(atomic_xwu32_t * a,
1202 xwu32_t t,
1203 xwu32_t v,
1204 xwu32_t * nv, xwu32_t * ov)
1205{
1206 xwu32_t o;
1207 xwu32_t n;
1208 xwer_t rc;
1209
1210 do {
1211 o = atomic_load_explicit(a, memory_order_consume);
1212 if (o > t) {
1213 n = v - o;
1214 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1215 a, &o, n,
1216 memory_order_acq_rel,
1217 memory_order_consume);
1218 if ((bool)rc) {
1219 rc = XWOK;
1220 }
1221 } else {
1222 rc = -EACCES;
1223 n = o;
1224 break;
1225 }
1226 } while (rc != XWOK);
1227 if (nv) {
1228 *nv = n;
1229 }
1230 if (ov) {
1231 *ov = o;
1232 }
1233 return rc;
1234}
1235
1237xwer_t xwaop__xwu32_t__tge_then_rsb(atomic_xwu32_t * a,
1238 xwu32_t t,
1239 xwu32_t v,
1240 xwu32_t * nv, xwu32_t * ov)
1241{
1242 xwu32_t o;
1243 xwu32_t n;
1244 xwer_t rc;
1245
1246 do {
1247 o = atomic_load_explicit(a, memory_order_consume);
1248 if (o >= t) {
1249 n = v - o;
1250 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1251 a, &o, n,
1252 memory_order_acq_rel,
1253 memory_order_consume);
1254 if ((bool)rc) {
1255 rc = XWOK;
1256 }
1257 } else {
1258 rc = -EACCES;
1259 n = o;
1260 break;
1261 }
1262 } while (rc != XWOK);
1263 if (nv) {
1264 *nv = n;
1265 }
1266 if (ov) {
1267 *ov = o;
1268 }
1269 return rc;
1270}
1271
1273xwer_t xwaop__xwu32_t__tlt_then_rsb(atomic_xwu32_t * a,
1274 xwu32_t t,
1275 xwu32_t v,
1276 xwu32_t * nv, xwu32_t * ov)
1277{
1278 xwu32_t o;
1279 xwu32_t n;
1280 xwer_t rc;
1281
1282 do {
1283 o = atomic_load_explicit(a, memory_order_consume);
1284 if (o < t) {
1285 n = v - o;
1286 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1287 a, &o, n,
1288 memory_order_acq_rel,
1289 memory_order_consume);
1290 if ((bool)rc) {
1291 rc = XWOK;
1292 }
1293 } else {
1294 rc = -EACCES;
1295 n = o;
1296 break;
1297 }
1298 } while (rc != XWOK);
1299 if (nv) {
1300 *nv = n;
1301 }
1302 if (ov) {
1303 *ov = o;
1304 }
1305 return rc;
1306}
1307
1309xwer_t xwaop__xwu32_t__tle_then_rsb(atomic_xwu32_t * a,
1310 xwu32_t t,
1311 xwu32_t v,
1312 xwu32_t * nv, xwu32_t * ov)
1313{
1314 xwu32_t o;
1315 xwu32_t n;
1316 xwer_t rc;
1317
1318 do {
1319 o = atomic_load_explicit(a, memory_order_consume);
1320 if (o <= t) {
1321 n = v - o;
1322 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1323 a, &o, n,
1324 memory_order_acq_rel,
1325 memory_order_consume);
1326 if ((bool)rc) {
1327 rc = XWOK;
1328 }
1329 } else {
1330 rc = -EACCES;
1331 n = o;
1332 break;
1333 }
1334 } while (rc != XWOK);
1335 if (nv) {
1336 *nv = n;
1337 }
1338 if (ov) {
1339 *ov = o;
1340 }
1341 return rc;
1342}
1343
1345xwer_t xwaop__xwu32_t__tgtlt_then_rsb(atomic_xwu32_t * a,
1346 xwu32_t l, xwu32_t r,
1347 xwu32_t v,
1348 xwu32_t * nv, xwu32_t * ov)
1349{
1350 xwu32_t o;
1351 xwu32_t n;
1352 xwer_t rc;
1353
1354 do {
1355 o = atomic_load_explicit(a, memory_order_consume);
1356 if ((o > l) && (o < r)) {
1357 n = v - o;
1358 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1359 a, &o, n,
1360 memory_order_acq_rel,
1361 memory_order_consume);
1362 if ((bool)rc) {
1363 rc = XWOK;
1364 }
1365 } else {
1366 rc = -EACCES;
1367 n = o;
1368 break;
1369 }
1370 } while (rc != XWOK);
1371 if (nv) {
1372 *nv = n;
1373 }
1374 if (ov) {
1375 *ov = o;
1376 }
1377 return rc;
1378}
1379
1381xwer_t xwaop__xwu32_t__tgelt_then_rsb(atomic_xwu32_t * a,
1382 xwu32_t l, xwu32_t r,
1383 xwu32_t v,
1384 xwu32_t * nv, xwu32_t * ov)
1385{
1386 xwu32_t o;
1387 xwu32_t n;
1388 xwer_t rc;
1389
1390 do {
1391 o = atomic_load_explicit(a, memory_order_consume);
1392 if ((o >= l) && (o < r)) {
1393 n = v - o;
1394 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1395 a, &o, n,
1396 memory_order_acq_rel,
1397 memory_order_consume);
1398 if ((bool)rc) {
1399 rc = XWOK;
1400 }
1401 } else {
1402 rc = -EACCES;
1403 n = o;
1404 break;
1405 }
1406 } while (rc != XWOK);
1407 if (nv) {
1408 *nv = n;
1409 }
1410 if (ov) {
1411 *ov = o;
1412 }
1413 return rc;
1414}
1415
1417xwer_t xwaop__xwu32_t__tgtle_then_rsb(atomic_xwu32_t * a,
1418 xwu32_t l, xwu32_t r,
1419 xwu32_t v,
1420 xwu32_t * nv, xwu32_t * ov)
1421{
1422 xwu32_t o;
1423 xwu32_t n;
1424 xwer_t rc;
1425
1426 do {
1427 o = atomic_load_explicit(a, memory_order_consume);
1428 if ((o > l) && (o <= r)) {
1429 n = v - o;
1430 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1431 a, &o, n,
1432 memory_order_acq_rel,
1433 memory_order_consume);
1434 if ((bool)rc) {
1435 rc = XWOK;
1436 }
1437 } else {
1438 rc = -EACCES;
1439 n = o;
1440 break;
1441 }
1442 } while (rc != XWOK);
1443 if (nv) {
1444 *nv = n;
1445 }
1446 if (ov) {
1447 *ov = o;
1448 }
1449 return rc;
1450}
1451
1453xwer_t xwaop__xwu32_t__tgele_then_rsb(atomic_xwu32_t * a,
1454 xwu32_t l, xwu32_t r,
1455 xwu32_t v,
1456 xwu32_t * nv, xwu32_t * ov)
1457{
1458 xwu32_t o;
1459 xwu32_t n;
1460 xwer_t rc;
1461
1462 do {
1463 o = atomic_load_explicit(a, memory_order_consume);
1464 if ((o >= l) && (o <= r)) {
1465 n = v - o;
1466 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1467 a, &o, n,
1468 memory_order_acq_rel,
1469 memory_order_consume);
1470 if ((bool)rc) {
1471 rc = XWOK;
1472 }
1473 } else {
1474 rc = -EACCES;
1475 n = o;
1476 break;
1477 }
1478 } while (rc != XWOK);
1479 if (nv) {
1480 *nv = n;
1481 }
1482 if (ov) {
1483 *ov = o;
1484 }
1485 return rc;
1486}
1487
1488/******** ******** bit operations ******** ********/
1490void xwaop__xwu32_t__or(atomic_xwu32_t * a,
1491 xwu32_t v,
1492 xwu32_t * nv, xwu32_t * ov)
1493{
1494 xwu32_t o;
1495
1496 o = atomic_fetch_or_explicit(a, v, memory_order_acq_rel);
1497 if (nv) {
1498 *nv = o | v;
1499 }
1500 if (ov) {
1501 *ov = o;
1502 }
1503}
1504
1506void xwaop__xwu32_t__and(atomic_xwu32_t * a,
1507 xwu32_t v,
1508 xwu32_t * nv, xwu32_t * ov)
1509{
1510 xwu32_t o;
1511
1512 o = atomic_fetch_and_explicit(a, v, memory_order_acq_rel);
1513 if (nv) {
1514 *nv = o & v;
1515 }
1516 if (ov) {
1517 *ov = o;
1518 }
1519}
1520
1522void xwaop__xwu32_t__xor(atomic_xwu32_t * a,
1523 xwu32_t v,
1524 xwu32_t * nv, xwu32_t * ov)
1525{
1526 xwu32_t o;
1527
1528 o = atomic_fetch_xor_explicit(a, v, memory_order_acq_rel);
1529 if (nv) {
1530 *nv = o ^ v;
1531 }
1532 if (ov) {
1533 *ov = o;
1534 }
1535}
1536
1538void xwaop__xwu32_t__c0m(atomic_xwu32_t * a,
1539 xwu32_t m,
1540 xwu32_t * nv, xwu32_t * ov)
1541{
1542 xwu32_t o;
1543
1544 o = atomic_fetch_and_explicit(a, ~m, memory_order_acq_rel);
1545 if (nv) {
1546 *nv = o & (~m);
1547 }
1548 if (ov) {
1549 *ov = o;
1550 }
1551}
1552
1554xwer_t xwaop__xwu32_t__t1ma_then_c0m(atomic_xwu32_t * a,
1555 xwu32_t m,
1556 xwu32_t * nv, xwu32_t * ov)
1557{
1558 xwu32_t o;
1559 xwu32_t n;
1560 xwer_t rc;
1561
1562 do {
1563 o = atomic_load_explicit(a, memory_order_consume);
1564 if ((o & m) == m) {
1565 n = o & (~m);
1566 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1567 a, &o, n,
1568 memory_order_acq_rel,
1569 memory_order_consume);
1570 if ((bool)rc) {
1571 rc = XWOK;
1572 }
1573 } else {
1574 rc = -EACCES;
1575 n = o;
1576 break;
1577 }
1578 } while (rc != XWOK);
1579 if (nv) {
1580 *nv = n;
1581 }
1582 if (ov) {
1583 *ov = o;
1584 }
1585 return rc;
1586}
1587
1589xwer_t xwaop__xwu32_t__t1mo_then_c0m(atomic_xwu32_t * a,
1590 xwu32_t m,
1591 xwu32_t * nv, xwu32_t * ov)
1592{
1593 xwu32_t o;
1594 xwu32_t n;
1595 xwer_t rc;
1596
1597 do {
1598 o = atomic_load_explicit(a, memory_order_consume);
1599 if (o & m) {
1600 n = o & (~m);
1601 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1602 a, &o, n,
1603 memory_order_acq_rel,
1604 memory_order_consume);
1605 if ((bool)rc) {
1606 rc = XWOK;
1607 }
1608 } else {
1609 rc = -EACCES;
1610 n = o;
1611 break;
1612 }
1613 } while (rc != XWOK);
1614 if (nv) {
1615 *nv = n;
1616 }
1617 if (ov) {
1618 *ov = o;
1619 }
1620 return rc;
1621}
1622
1624xwer_t xwaop__xwu32_t__t0ma_then_s1m(atomic_xwu32_t * a,
1625 xwu32_t m,
1626 xwu32_t * nv, xwu32_t * ov)
1627{
1628 xwu32_t o;
1629 xwu32_t n;
1630 xwer_t rc;
1631
1632 do {
1633 o = atomic_load_explicit(a, memory_order_consume);
1634 if (!(o & m)) {
1635 n = o | m;
1636 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1637 a, &o, n,
1638 memory_order_acq_rel,
1639 memory_order_consume);
1640 if ((bool)rc) {
1641 rc = XWOK;
1642 }
1643 } else {
1644 rc = -EACCES;
1645 n = o;
1646 break;
1647 }
1648 } while (rc != XWOK);
1649 if (nv) {
1650 *nv = n;
1651 }
1652 if (ov) {
1653 *ov = o;
1654 }
1655 return rc;
1656}
1657
1659xwer_t xwaop__xwu32_t__t0mo_then_s1m(atomic_xwu32_t * a,
1660 xwu32_t m,
1661 xwu32_t * nv, xwu32_t * ov)
1662{
1663 xwu32_t o;
1664 xwu32_t n;
1665 xwer_t rc;
1666
1667 do {
1668 o = atomic_load_explicit(a, memory_order_consume);
1669 if ((o & m) != m) {
1670 n = o | m;
1671 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1672 a, &o, n,
1673 memory_order_acq_rel,
1674 memory_order_consume);
1675 if ((bool)rc) {
1676 rc = XWOK;
1677 }
1678 } else {
1679 rc = -EACCES;
1680 n = o;
1681 break;
1682 }
1683 } while (rc != XWOK);
1684 if (nv) {
1685 *nv = n;
1686 }
1687 if (ov) {
1688 *ov = o;
1689 }
1690 return rc;
1691}
1692
1693/******** ******** test and operation ******** ********/
1695xwer_t xwaop__xwu32_t__tst_then_op(atomic_xwu32_t * a,
1696 xwaop_tst_f tst, void * tst_args,
1697 xwaop_op_f op, void * op_args,
1698 xwu32_t * nv, xwu32_t * ov)
1699{
1700 xwu32_t o;
1701 xwu32_t n;
1702 xwer_t rc;
1703
1704 do {
1705 o = atomic_load_explicit(a, memory_order_consume);
1706 if (tst) {
1707 rc = tst((const void *)&o, tst_args);
1708 if (XWOK == rc) {
1709 if (op) {
1710 op(&n, (const void *)&o, op_args);
1711 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1712 a, &o, n,
1713 memory_order_acq_rel,
1714 memory_order_consume);
1715 } else {
1716 n = o;
1717 break;
1718 }
1719 } else {
1720 n = o;
1721 break;
1722 }
1723 } else {
1724 if (op) {
1725 op(&n, (const void *)&o, op_args);
1726 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1727 a, &o, n,
1728 memory_order_acq_rel,
1729 memory_order_consume);
1730 } else {
1731 rc = XWOK;
1732 n = o;
1733 break;
1734 }
1735 }
1736 } while (rc);
1737 if (nv) {
1738 *nv = n;
1739 }
1740 if (ov) {
1741 *ov = o;
1742 }
1743 return rc;
1744}
1745
1746#endif
#define __xwlib_code
Definition compiler.h:199
#define XWOK
No error
Definition errno.h:182
#define EACCES
Permission denied
Definition errno.h:43
signed long xwer_t
Definition type.h:554
xwaop_memory_order_em
原子操作内存模型
Definition type.h:627
xwer_t(* xwaop_tst_f)(const void *, void *)
原子变量测试函数指针类型
Definition type.h:612
__xwcc_atomic xwu32_t atomic_xwu32_t
Definition type.h:269
void(* xwaop_op_f)(void *, const void *, void *)
原子变量操作函数指针类型
Definition type.h:618
uint32_t xwu32_t
Definition type.h:266
XWOS通用库:原子操作
XWOS的标准头文件