XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
s8.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
21xws8_t xwaop__xws8_t__load(atomic_xws8_t * a,
22 const enum xwaop_memory_order_em mo)
23{
24 xws8_t v;
25
26 v = atomic_load_explicit(a, (int)mo);
27 return v;
28}
29
31xws8_t xwaop__xws8_t__store(atomic_xws8_t * a,
32 const enum xwaop_memory_order_em mo,
33 xws8_t v)
34{
35 atomic_store_explicit(a, v, (int)mo);
36 return v;
37}
38
40void xwaop__xws8_t__read(atomic_xws8_t * a,
41 xws8_t * ov)
42{
43 xws8_t o;
44
45 o = atomic_load_explicit(a, memory_order_acquire);
46 if (ov) {
47 *ov = o;
48 }
49}
50
52void xwaop__xws8_t__write(atomic_xws8_t * a,
53 xws8_t v,
54 xws8_t * ov)
55{
56 xws8_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__xws8_t__teq_then_write(atomic_xws8_t * a,
66 xws8_t t,
67 xws8_t v,
68 xws8_t * ov)
69{
70 xws8_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__xws8_t__tne_then_write(atomic_xws8_t * a,
90 xws8_t t,
91 xws8_t v,
92 xws8_t * ov)
93{
94 xws8_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__xws8_t__tgt_then_write(atomic_xws8_t * a,
120 xws8_t t,
121 xws8_t v,
122 xws8_t * ov)
123{
124 xws8_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__xws8_t__tge_then_write(atomic_xws8_t * a,
150 xws8_t t,
151 xws8_t v,
152 xws8_t * ov)
153{
154 xws8_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__xws8_t__tlt_then_write(atomic_xws8_t * a,
180 xws8_t t,
181 xws8_t v,
182 xws8_t * ov)
183{
184 xws8_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__xws8_t__tle_then_write(atomic_xws8_t * a,
210 xws8_t t,
211 xws8_t v,
212 xws8_t * ov)
213{
214 xws8_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__xws8_t__tgtlt_then_write(atomic_xws8_t * a,
240 xws8_t l, xws8_t r,
241 xws8_t v,
242 xws8_t * ov)
243{
244 xws8_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__xws8_t__tgelt_then_write(atomic_xws8_t * a,
270 xws8_t l, xws8_t r,
271 xws8_t v,
272 xws8_t * ov)
273{
274 xws8_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__xws8_t__tgtle_then_write(atomic_xws8_t * a,
300 xws8_t l, xws8_t r,
301 xws8_t v,
302 xws8_t * ov)
303{
304 xws8_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__xws8_t__tgele_then_write(atomic_xws8_t * a,
330 xws8_t l, xws8_t r,
331 xws8_t v,
332 xws8_t * ov)
333{
334 xws8_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__xws8_t__add(atomic_xws8_t * a,
361 xws8_t v,
362 xws8_t * nv, xws8_t * ov)
363{
364 xws8_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__xws8_t__teq_then_add(atomic_xws8_t * a,
377 xws8_t t,
378 xws8_t v,
379 xws8_t * nv, xws8_t * ov)
380{
381 xws8_t o;
382 xws8_t n;
383 xwer_t rc;
384
385 o = t;
386 n = o + v;
387 rc = (xwer_t)atomic_compare_exchange_strong_explicit(a, &o, n,
388 memory_order_acq_rel,
389 memory_order_consume);
390 if ((bool)rc) {
391 rc = XWOK;
392 } else {
393 rc = -EACCES;
394 n = o;
395 }
396 if (nv) {
397 *nv = n;
398 }
399 if (ov) {
400 *ov = o;
401 }
402 return rc;
403}
404
406xwer_t xwaop__xws8_t__tne_then_add(atomic_xws8_t * a,
407 xws8_t t,
408 xws8_t v,
409 xws8_t * nv, xws8_t * ov)
410{
411 xws8_t o;
412 xws8_t n;
413 xwer_t rc;
414
415 do {
416 o = atomic_load_explicit(a, memory_order_consume);
417 if (o != t) {
418 n = o + v;
419 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
420 a, &o, n,
421 memory_order_acq_rel,
422 memory_order_consume);
423 if ((bool)rc) {
424 rc = XWOK;
425 }
426 } else {
427 rc = -EACCES;
428 n = o;
429 break;
430 }
431 } while (rc != XWOK);
432 if (nv) {
433 *nv = n;
434 }
435 if (ov) {
436 *ov = o;
437 }
438 return rc;
439}
440
442xwer_t xwaop__xws8_t__tgt_then_add(atomic_xws8_t * a,
443 xws8_t t,
444 xws8_t v,
445 xws8_t * nv, xws8_t * ov)
446{
447 xws8_t o;
448 xws8_t n;
449 xwer_t rc;
450
451 do {
452 o = atomic_load_explicit(a, memory_order_consume);
453 if (o > t) {
454 n = o + v;
455 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
456 a, &o, n,
457 memory_order_acq_rel,
458 memory_order_consume);
459 if ((bool)rc) {
460 rc = XWOK;
461 }
462 } else {
463 rc = -EACCES;
464 n = o;
465 break;
466 }
467 } while (rc != XWOK);
468 if (nv) {
469 *nv = n;
470 }
471 if (ov) {
472 *ov = o;
473 }
474 return rc;
475}
476
478xwer_t xwaop__xws8_t__tge_then_add(atomic_xws8_t * a,
479 xws8_t t,
480 xws8_t v,
481 xws8_t * nv, xws8_t * ov)
482{
483 xws8_t o;
484 xws8_t n;
485 xwer_t rc;
486
487 do {
488 o = atomic_load_explicit(a, memory_order_consume);
489 if (o >= t) {
490 n = o + v;
491 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
492 a, &o, n,
493 memory_order_acq_rel,
494 memory_order_consume);
495 if ((bool)rc) {
496 rc = XWOK;
497 }
498 } else {
499 rc = -EACCES;
500 n = o;
501 break;
502 }
503 } while (rc != XWOK);
504 if (nv) {
505 *nv = n;
506 }
507 if (ov) {
508 *ov = o;
509 }
510 return rc;
511}
512
514xwer_t xwaop__xws8_t__tlt_then_add(atomic_xws8_t * a,
515 xws8_t t,
516 xws8_t v,
517 xws8_t * nv, xws8_t * ov)
518{
519 xws8_t o;
520 xws8_t n;
521 xwer_t rc;
522
523 do {
524 o = atomic_load_explicit(a, memory_order_consume);
525 if (o < t) {
526 n = o + v;
527 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
528 a, &o, n,
529 memory_order_acq_rel,
530 memory_order_consume);
531 if ((bool)rc) {
532 rc = XWOK;
533 }
534 } else {
535 rc = -EACCES;
536 n = o;
537 break;
538 }
539 } while (rc != XWOK);
540 if (nv) {
541 *nv = n;
542 }
543 if (ov) {
544 *ov = o;
545 }
546 return rc;
547}
548
550xwer_t xwaop__xws8_t__tle_then_add(atomic_xws8_t * a,
551 xws8_t t,
552 xws8_t v,
553 xws8_t * nv, xws8_t * ov)
554{
555 xws8_t o;
556 xws8_t n;
557 xwer_t rc;
558
559 do {
560 o = atomic_load_explicit(a, memory_order_consume);
561 if (o <= t) {
562 n = o + v;
563 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
564 a, &o, n,
565 memory_order_acq_rel,
566 memory_order_consume);
567 if ((bool)rc) {
568 rc = XWOK;
569 }
570 } else {
571 rc = -EACCES;
572 n = o;
573 break;
574 }
575 } while (rc != XWOK);
576 if (nv) {
577 *nv = n;
578 }
579 if (ov) {
580 *ov = o;
581 }
582 return rc;
583}
584
586xwer_t xwaop__xws8_t__tgtlt_then_add(atomic_xws8_t * a,
587 xws8_t l, xws8_t r,
588 xws8_t v,
589 xws8_t * nv, xws8_t * ov)
590{
591 xws8_t o;
592 xws8_t n;
593 xwer_t rc;
594
595 do {
596 o = atomic_load_explicit(a, memory_order_consume);
597 if ((o > l) && (o < r)) {
598 n = o + v;
599 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
600 a, &o, n,
601 memory_order_acq_rel,
602 memory_order_consume);
603 if ((bool)rc) {
604 rc = XWOK;
605 }
606 } else {
607 rc = -EACCES;
608 n = o;
609 break;
610 }
611 } while (rc != XWOK);
612 if (nv) {
613 *nv = n;
614 }
615 if (ov) {
616 *ov = o;
617 }
618 return rc;
619}
620
622xwer_t xwaop__xws8_t__tgelt_then_add(atomic_xws8_t * a,
623 xws8_t l, xws8_t r,
624 xws8_t v,
625 xws8_t * nv, xws8_t * ov)
626{
627 xws8_t o;
628 xws8_t n;
629 xwer_t rc;
630
631 do {
632 o = atomic_load_explicit(a, memory_order_consume);
633 if ((o >= l) && (o < r)) {
634 n = o + v;
635 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
636 a, &o, n,
637 memory_order_acq_rel,
638 memory_order_consume);
639 if ((bool)rc) {
640 rc = XWOK;
641 }
642 } else {
643 rc = -EACCES;
644 n = o;
645 break;
646 }
647 } while (rc != XWOK);
648 if (nv) {
649 *nv = n;
650 }
651 if (ov) {
652 *ov = o;
653 }
654 return rc;
655}
656
658xwer_t xwaop__xws8_t__tgtle_then_add(atomic_xws8_t * a,
659 xws8_t l, xws8_t r,
660 xws8_t v,
661 xws8_t * nv, xws8_t * ov)
662{
663 xws8_t o;
664 xws8_t n;
665 xwer_t rc;
666
667 do {
668 o = atomic_load_explicit(a, memory_order_consume);
669 if ((o > l) && (o <= r)) {
670 n = o + v;
671 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
672 a, &o, n,
673 memory_order_acq_rel,
674 memory_order_consume);
675 if ((bool)rc) {
676 rc = XWOK;
677 }
678 } else {
679 rc = -EACCES;
680 n = o;
681 break;
682 }
683 } while (rc != XWOK);
684 if (nv) {
685 *nv = n;
686 }
687 if (ov) {
688 *ov = o;
689 }
690 return rc;
691}
692
694xwer_t xwaop__xws8_t__tgele_then_add(atomic_xws8_t * a,
695 xws8_t l, xws8_t r,
696 xws8_t v,
697 xws8_t * nv, xws8_t * ov)
698{
699 xws8_t o;
700 xws8_t n;
701 xwer_t rc;
702
703 do {
704 o = atomic_load_explicit(a, memory_order_consume);
705 if ((o >= l) && (o <= r)) {
706 n = o + v;
707 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
708 a, &o, n,
709 memory_order_acq_rel,
710 memory_order_consume);
711 if ((bool)rc) {
712 rc = XWOK;
713 }
714 } else {
715 rc = -EACCES;
716 n = o;
717 break;
718 }
719 } while (rc != XWOK);
720 if (nv) {
721 *nv = n;
722 }
723 if (ov) {
724 *ov = o;
725 }
726 return rc;
727}
728
729/******** ******** subtract ******** ********/
731void xwaop__xws8_t__sub(atomic_xws8_t * a,
732 xws8_t v,
733 xws8_t * nv, xws8_t * ov)
734{
735 xws8_t o;
736
737 o = atomic_fetch_sub_explicit(a, v, memory_order_acq_rel);
738 if (nv) {
739 *nv = o - v;
740 }
741 if (ov) {
742 *ov = o;
743 }
744}
745
747xwer_t xwaop__xws8_t__teq_then_sub(atomic_xws8_t * a,
748 xws8_t t,
749 xws8_t v,
750 xws8_t * nv, xws8_t * ov)
751{
752 xws8_t o;
753 xws8_t n;
754 xwer_t rc;
755
756 o = t;
757 n = o - v;
758 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
759 a, &o, n,
760 memory_order_acq_rel,
761 memory_order_consume);
762 if ((bool)rc) {
763 rc = XWOK;
764 } else {
765 rc = -EACCES;
766 n = o;
767 }
768 if (nv) {
769 *nv = n;
770 }
771 if (ov) {
772 *ov = o;
773 }
774 return rc;
775}
776
778xwer_t xwaop__xws8_t__tne_then_sub(atomic_xws8_t * a,
779 xws8_t t,
780 xws8_t v,
781 xws8_t * nv, xws8_t * ov)
782{
783 xws8_t o;
784 xws8_t n;
785 xwer_t rc;
786
787 do {
788 o = atomic_load_explicit(a, memory_order_consume);
789 if (o != t) {
790 n = o - v;
791 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
792 a, &o, n,
793 memory_order_acq_rel,
794 memory_order_consume);
795 if ((bool)rc) {
796 rc = XWOK;
797 }
798 } else {
799 rc = -EACCES;
800 n = o;
801 break;
802 }
803 } while (rc != XWOK);
804 if (nv) {
805 *nv = n;
806 }
807 if (ov) {
808 *ov = o;
809 }
810 return rc;
811}
812
814xwer_t xwaop__xws8_t__tgt_then_sub(atomic_xws8_t * a,
815 xws8_t t,
816 xws8_t v,
817 xws8_t * nv, xws8_t * ov)
818{
819 xws8_t o;
820 xws8_t n;
821 xwer_t rc;
822
823 do {
824 o = atomic_load_explicit(a, memory_order_consume);
825 if (o > t) {
826 n = o - v;
827 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
828 a, &o, n,
829 memory_order_acq_rel,
830 memory_order_consume);
831 if ((bool)rc) {
832 rc = XWOK;
833 }
834 } else {
835 rc = -EACCES;
836 n = o;
837 break;
838 }
839 } while (rc != XWOK);
840 if (nv) {
841 *nv = n;
842 }
843 if (ov) {
844 *ov = o;
845 }
846 return rc;
847}
848
850xwer_t xwaop__xws8_t__tge_then_sub(atomic_xws8_t * a,
851 xws8_t t,
852 xws8_t v,
853 xws8_t * nv, xws8_t * ov)
854{
855 xws8_t o;
856 xws8_t n;
857 xwer_t rc;
858
859 do {
860 o = atomic_load_explicit(a, memory_order_consume);
861 if (o >= t) {
862 n = o - v;
863 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
864 a, &o, n,
865 memory_order_acq_rel,
866 memory_order_consume);
867 if ((bool)rc) {
868 rc = XWOK;
869 }
870 } else {
871 rc = -EACCES;
872 n = o;
873 break;
874 }
875 } while (rc != XWOK);
876 if (nv) {
877 *nv = n;
878 }
879 if (ov) {
880 *ov = o;
881 }
882 return rc;
883}
884
886xwer_t xwaop__xws8_t__tlt_then_sub(atomic_xws8_t * a,
887 xws8_t t,
888 xws8_t v,
889 xws8_t * nv, xws8_t * ov)
890{
891 xws8_t o;
892 xws8_t n;
893 xwer_t rc;
894
895 do {
896 o = atomic_load_explicit(a, memory_order_consume);
897 if (o < t) {
898 n = o - v;
899 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
900 a, &o, n,
901 memory_order_acq_rel,
902 memory_order_consume);
903 if ((bool)rc) {
904 rc = XWOK;
905 }
906 } else {
907 rc = -EACCES;
908 n = o;
909 break;
910 }
911 } while (rc != XWOK);
912 if (nv) {
913 *nv = n;
914 }
915 if (ov) {
916 *ov = o;
917 }
918 return rc;
919}
920
922xwer_t xwaop__xws8_t__tle_then_sub(atomic_xws8_t * a,
923 xws8_t t,
924 xws8_t v,
925 xws8_t * nv, xws8_t * ov)
926{
927 xws8_t o;
928 xws8_t n;
929 xwer_t rc;
930
931 do {
932 o = atomic_load_explicit(a, memory_order_consume);
933 if (o <= t) {
934 n = o - v;
935 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
936 a, &o, n,
937 memory_order_acq_rel,
938 memory_order_consume);
939 if ((bool)rc) {
940 rc = XWOK;
941 }
942 } else {
943 rc = -EACCES;
944 n = o;
945 break;
946 }
947 } while (rc != XWOK);
948 if (nv) {
949 *nv = n;
950 }
951 if (ov) {
952 *ov = o;
953 }
954 return rc;
955}
956
958xwer_t xwaop__xws8_t__tgtlt_then_sub(atomic_xws8_t * a,
959 xws8_t l, xws8_t r,
960 xws8_t v,
961 xws8_t * nv, xws8_t * ov)
962{
963 xws8_t o;
964 xws8_t n;
965 xwer_t rc;
966
967 do {
968 o = atomic_load_explicit(a, memory_order_consume);
969 if ((o > l) && (o < r)) {
970 n = o - v;
971 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
972 a, &o, n,
973 memory_order_acq_rel,
974 memory_order_consume);
975 if ((bool)rc) {
976 rc = XWOK;
977 }
978 } else {
979 rc = -EACCES;
980 n = o;
981 break;
982 }
983 } while (rc != XWOK);
984 if (nv) {
985 *nv = n;
986 }
987 if (ov) {
988 *ov = o;
989 }
990 return rc;
991}
992
994xwer_t xwaop__xws8_t__tgelt_then_sub(atomic_xws8_t * a,
995 xws8_t l, xws8_t r,
996 xws8_t v,
997 xws8_t * nv, xws8_t * ov)
998{
999 xws8_t o;
1000 xws8_t n;
1001 xwer_t rc;
1002
1003 do {
1004 o = atomic_load_explicit(a, memory_order_consume);
1005 if ((o >= l) && (o < r)) {
1006 n = o - v;
1007 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1008 a, &o, n,
1009 memory_order_acq_rel,
1010 memory_order_consume);
1011 if ((bool)rc) {
1012 rc = XWOK;
1013 }
1014 } else {
1015 rc = -EACCES;
1016 n = o;
1017 break;
1018 }
1019 } while (rc != XWOK);
1020 if (nv) {
1021 *nv = n;
1022 }
1023 if (ov) {
1024 *ov = o;
1025 }
1026 return rc;
1027}
1028
1030xwer_t xwaop__xws8_t__tgtle_then_sub(atomic_xws8_t * a,
1031 xws8_t l, xws8_t r,
1032 xws8_t v,
1033 xws8_t * nv, xws8_t * ov)
1034{
1035 xws8_t o;
1036 xws8_t n;
1037 xwer_t rc;
1038
1039 do {
1040 o = atomic_load_explicit(a, memory_order_consume);
1041 if ((o > l) && (o <= r)) {
1042 n = o - v;
1043 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1044 a, &o, n,
1045 memory_order_acq_rel,
1046 memory_order_consume);
1047 if ((bool)rc) {
1048 rc = XWOK;
1049 }
1050 } else {
1051 rc = -EACCES;
1052 n = o;
1053 break;
1054 }
1055 } while (rc != XWOK);
1056 if (nv) {
1057 *nv = n;
1058 }
1059 if (ov) {
1060 *ov = o;
1061 }
1062 return rc;
1063}
1064
1066xwer_t xwaop__xws8_t__tgele_then_sub(atomic_xws8_t * a,
1067 xws8_t l, xws8_t r,
1068 xws8_t v,
1069 xws8_t * nv, xws8_t * ov)
1070{
1071 xws8_t o;
1072 xws8_t n;
1073 xwer_t rc;
1074
1075 do {
1076 o = atomic_load_explicit(a, memory_order_consume);
1077 if ((o >= l) && (o <= r)) {
1078 n = o - v;
1079 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1080 a, &o, n,
1081 memory_order_acq_rel,
1082 memory_order_consume);
1083 if ((bool)rc) {
1084 rc = XWOK;
1085 }
1086 } else {
1087 rc = -EACCES;
1088 n = o;
1089 break;
1090 }
1091 } while (rc != XWOK);
1092 if (nv) {
1093 *nv = n;
1094 }
1095 if (ov) {
1096 *ov = o;
1097 }
1098 return rc;
1099}
1100
1101/******** ******** reverse subtract ******** ********/
1103void xwaop__xws8_t__rsb(atomic_xws8_t * a,
1104 xws8_t v,
1105 xws8_t * nv, xws8_t * ov)
1106{
1107 xws8_t o;
1108 xws8_t n;
1109 bool r;
1110
1111 do {
1112 o = atomic_load_explicit(a, memory_order_relaxed);
1113 n = v - o;
1114 r = atomic_compare_exchange_strong_explicit(
1115 a, &o, n,
1116 memory_order_acq_rel,
1117 memory_order_relaxed);
1118 } while (!r);
1119 if (nv) {
1120 *nv = n;
1121 }
1122 if (ov) {
1123 *ov = o;
1124 }
1125}
1126
1128xwer_t xwaop__xws8_t__teq_then_rsb(atomic_xws8_t * a,
1129 xws8_t t,
1130 xws8_t v,
1131 xws8_t * nv, xws8_t * ov)
1132{
1133 xws8_t o;
1134 xws8_t n;
1135 xwer_t rc;
1136
1137 do {
1138 o = atomic_load_explicit(a, memory_order_consume);
1139 if (o == t) {
1140 n = v - o;
1141 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1142 a, &o, n,
1143 memory_order_acq_rel,
1144 memory_order_consume);
1145 if ((bool)rc) {
1146 rc = XWOK;
1147 }
1148 } else {
1149 rc = -EACCES;
1150 n = o;
1151 break;
1152 }
1153 } while (rc != XWOK);
1154 if (nv) {
1155 *nv = n;
1156 }
1157 if (ov) {
1158 *ov = o;
1159 }
1160 return rc;
1161}
1162
1164xwer_t xwaop__xws8_t__tne_then_rsb(atomic_xws8_t * a,
1165 xws8_t t,
1166 xws8_t v,
1167 xws8_t * nv, xws8_t * ov)
1168{
1169 xws8_t o;
1170 xws8_t n;
1171 xwer_t rc;
1172
1173 do {
1174 o = atomic_load_explicit(a, memory_order_consume);
1175 if (o != t) {
1176 n = v - o;
1177 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1178 a, &o, n,
1179 memory_order_acq_rel,
1180 memory_order_consume);
1181 if ((bool)rc) {
1182 rc = XWOK;
1183 }
1184 } else {
1185 rc = -EACCES;
1186 n = o;
1187 break;
1188 }
1189 } while (rc != XWOK);
1190 if (nv) {
1191 *nv = n;
1192 }
1193 if (ov) {
1194 *ov = o;
1195 }
1196 return rc;
1197}
1198
1200xwer_t xwaop__xws8_t__tgt_then_rsb(atomic_xws8_t * a,
1201 xws8_t t,
1202 xws8_t v,
1203 xws8_t * nv, xws8_t * ov)
1204{
1205 xws8_t o;
1206 xws8_t n;
1207 xwer_t rc;
1208
1209 do {
1210 o = atomic_load_explicit(a, memory_order_consume);
1211 if (o > t) {
1212 n = v - o;
1213 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1214 a, &o, n,
1215 memory_order_acq_rel,
1216 memory_order_consume);
1217 if ((bool)rc) {
1218 rc = XWOK;
1219 }
1220 } else {
1221 rc = -EACCES;
1222 n = o;
1223 break;
1224 }
1225 } while (rc != XWOK);
1226 if (nv) {
1227 *nv = n;
1228 }
1229 if (ov) {
1230 *ov = o;
1231 }
1232 return rc;
1233}
1234
1236xwer_t xwaop__xws8_t__tge_then_rsb(atomic_xws8_t * a,
1237 xws8_t t,
1238 xws8_t v,
1239 xws8_t * nv, xws8_t * ov)
1240{
1241 xws8_t o;
1242 xws8_t n;
1243 xwer_t rc;
1244
1245 do {
1246 o = atomic_load_explicit(a, memory_order_consume);
1247 if (o >= t) {
1248 n = v - o;
1249 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1250 a, &o, n,
1251 memory_order_acq_rel,
1252 memory_order_consume);
1253 if ((bool)rc) {
1254 rc = XWOK;
1255 }
1256 } else {
1257 rc = -EACCES;
1258 n = o;
1259 break;
1260 }
1261 } while (rc != XWOK);
1262 if (nv) {
1263 *nv = n;
1264 }
1265 if (ov) {
1266 *ov = o;
1267 }
1268 return rc;
1269}
1270
1272xwer_t xwaop__xws8_t__tlt_then_rsb(atomic_xws8_t * a,
1273 xws8_t t,
1274 xws8_t v,
1275 xws8_t * nv, xws8_t * ov)
1276{
1277 xws8_t o;
1278 xws8_t n;
1279 xwer_t rc;
1280
1281 do {
1282 o = atomic_load_explicit(a, memory_order_consume);
1283 if (o < t) {
1284 n = v - o;
1285 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1286 a, &o, n,
1287 memory_order_acq_rel,
1288 memory_order_consume);
1289 if ((bool)rc) {
1290 rc = XWOK;
1291 }
1292 } else {
1293 rc = -EACCES;
1294 n = o;
1295 break;
1296 }
1297 } while (rc != XWOK);
1298 if (nv) {
1299 *nv = n;
1300 }
1301 if (ov) {
1302 *ov = o;
1303 }
1304 return rc;
1305}
1306
1308xwer_t xwaop__xws8_t__tle_then_rsb(atomic_xws8_t * a,
1309 xws8_t t,
1310 xws8_t v,
1311 xws8_t * nv, xws8_t * ov)
1312{
1313 xws8_t o;
1314 xws8_t n;
1315 xwer_t rc;
1316
1317 do {
1318 o = atomic_load_explicit(a, memory_order_consume);
1319 if (o <= t) {
1320 n = v - o;
1321 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1322 a, &o, n,
1323 memory_order_acq_rel,
1324 memory_order_consume);
1325 if ((bool)rc) {
1326 rc = XWOK;
1327 }
1328 } else {
1329 rc = -EACCES;
1330 n = o;
1331 break;
1332 }
1333 } while (rc != XWOK);
1334 if (nv) {
1335 *nv = n;
1336 }
1337 if (ov) {
1338 *ov = o;
1339 }
1340 return rc;
1341}
1342
1344xwer_t xwaop__xws8_t__tgtlt_then_rsb(atomic_xws8_t * a,
1345 xws8_t l, xws8_t r,
1346 xws8_t v,
1347 xws8_t * nv, xws8_t * ov)
1348{
1349 xws8_t o;
1350 xws8_t n;
1351 xwer_t rc;
1352
1353 do {
1354 o = atomic_load_explicit(a, memory_order_consume);
1355 if ((o > l) && (o < r)) {
1356 n = v - o;
1357 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1358 a, &o, n,
1359 memory_order_acq_rel,
1360 memory_order_consume);
1361 if ((bool)rc) {
1362 rc = XWOK;
1363 }
1364 } else {
1365 rc = -EACCES;
1366 n = o;
1367 break;
1368 }
1369 } while (rc != XWOK);
1370 if (nv) {
1371 *nv = n;
1372 }
1373 if (ov) {
1374 *ov = o;
1375 }
1376 return rc;
1377}
1378
1380xwer_t xwaop__xws8_t__tgelt_then_rsb(atomic_xws8_t * a,
1381 xws8_t l, xws8_t r,
1382 xws8_t v,
1383 xws8_t * nv, xws8_t * ov)
1384{
1385 xws8_t o;
1386 xws8_t n;
1387 xwer_t rc;
1388
1389 do {
1390 o = atomic_load_explicit(a, memory_order_consume);
1391 if ((o >= l) && (o < r)) {
1392 n = v - o;
1393 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1394 a, &o, n,
1395 memory_order_acq_rel,
1396 memory_order_consume);
1397 if ((bool)rc) {
1398 rc = XWOK;
1399 }
1400 } else {
1401 rc = -EACCES;
1402 n = o;
1403 break;
1404 }
1405 } while (rc != XWOK);
1406 if (nv) {
1407 *nv = n;
1408 }
1409 if (ov) {
1410 *ov = o;
1411 }
1412 return rc;
1413}
1414
1416xwer_t xwaop__xws8_t__tgtle_then_rsb(atomic_xws8_t * a,
1417 xws8_t l, xws8_t r,
1418 xws8_t v,
1419 xws8_t * nv, xws8_t * ov)
1420{
1421 xws8_t o;
1422 xws8_t n;
1423 xwer_t rc;
1424
1425 do {
1426 o = atomic_load_explicit(a, memory_order_consume);
1427 if ((o > l) && (o <= r)) {
1428 n = v - o;
1429 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1430 a, &o, n,
1431 memory_order_acq_rel,
1432 memory_order_consume);
1433 if ((bool)rc) {
1434 rc = XWOK;
1435 }
1436 } else {
1437 rc = -EACCES;
1438 n = o;
1439 break;
1440 }
1441 } while (rc != XWOK);
1442 if (nv) {
1443 *nv = n;
1444 }
1445 if (ov) {
1446 *ov = o;
1447 }
1448 return rc;
1449}
1450
1452xwer_t xwaop__xws8_t__tgele_then_rsb(atomic_xws8_t * a,
1453 xws8_t l, xws8_t r,
1454 xws8_t v,
1455 xws8_t * nv, xws8_t * ov)
1456{
1457 xws8_t o;
1458 xws8_t n;
1459 xwer_t rc;
1460
1461 do {
1462 o = atomic_load_explicit(a, memory_order_consume);
1463 if ((o >= l) && (o <= r)) {
1464 n = v - o;
1465 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1466 a, &o, n,
1467 memory_order_acq_rel,
1468 memory_order_consume);
1469 if ((bool)rc) {
1470 rc = XWOK;
1471 }
1472 } else {
1473 rc = -EACCES;
1474 n = o;
1475 break;
1476 }
1477 } while (rc != XWOK);
1478 if (nv) {
1479 *nv = n;
1480 }
1481 if (ov) {
1482 *ov = o;
1483 }
1484 return rc;
1485}
1486
1487/******** ******** bit operations ******** ********/
1489void xwaop__xws8_t__or(atomic_xws8_t * a,
1490 xws8_t v,
1491 xws8_t * nv, xws8_t * ov)
1492{
1493 xws8_t o;
1494
1495 o = atomic_fetch_or_explicit(a, v, memory_order_acq_rel);
1496 if (nv) {
1497 *nv = o | v;
1498 }
1499 if (ov) {
1500 *ov = o;
1501 }
1502}
1503
1505void xwaop__xws8_t__and(atomic_xws8_t * a,
1506 xws8_t v,
1507 xws8_t * nv, xws8_t * ov)
1508{
1509 xws8_t o;
1510
1511 o = atomic_fetch_and_explicit(a, v, memory_order_acq_rel);
1512 if (nv) {
1513 *nv = o & v;
1514 }
1515 if (ov) {
1516 *ov = o;
1517 }
1518}
1519
1521void xwaop__xws8_t__xor(atomic_xws8_t * a,
1522 xws8_t v,
1523 xws8_t * nv, xws8_t * ov)
1524{
1525 xws8_t o;
1526
1527 o = atomic_fetch_xor_explicit(a, v, memory_order_acq_rel);
1528 if (nv) {
1529 *nv = o ^ v;
1530 }
1531 if (ov) {
1532 *ov = o;
1533 }
1534}
1535
1536/******** ******** test and operation ******** ********/
1538xwer_t xwaop__xws8_t__tst_then_op(atomic_xws8_t * a,
1539 xwaop_tst_f tst, void * tst_args,
1540 xwaop_op_f op, void * op_args,
1541 xws8_t * nv, xws8_t * ov)
1542{
1543 xws8_t o;
1544 xws8_t n;
1545 xwer_t rc;
1546
1547 do {
1548 o = atomic_load_explicit(a, memory_order_consume);
1549 if (tst) {
1550 rc = tst((const void *)&o, tst_args);
1551 if (XWOK == rc) {
1552 if (op) {
1553 op(&n, (const void *)&o, op_args);
1554 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1555 a, &o, n,
1556 memory_order_acq_rel,
1557 memory_order_consume);
1558 } else {
1559 n = o;
1560 break;
1561 }
1562 } else {
1563 n = o;
1564 break;
1565 }
1566 } else {
1567 if (op) {
1568 op(&n, (const void *)&o, op_args);
1569 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1570 a, &o, n,
1571 memory_order_acq_rel,
1572 memory_order_consume);
1573 } else {
1574 rc = XWOK;
1575 n = o;
1576 break;
1577 }
1578 }
1579 } while (rc);
1580 if (nv) {
1581 *nv = n;
1582 }
1583 if (ov) {
1584 *ov = o;
1585 }
1586 return rc;
1587}
1588
1589#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 xws8_t atomic_xws8_t
Definition type.h:213
void(* xwaop_op_f)(void *, const void *, void *)
原子变量操作函数指针类型
Definition type.h:618
int8_t xws8_t
Definition type.h:210
XWOS通用库:原子操作
XWOS的标准头文件