XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
s16.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
21xws16_t xwaop__xws16_t__load(atomic_xws16_t * a,
22 const enum xwaop_memory_order_em mo)
23{
24 xws16_t v;
25
26 v = atomic_load_explicit(a, (int)mo);
27 return v;
28}
29
31xws16_t xwaop__xws16_t__store(atomic_xws16_t * a,
32 const enum xwaop_memory_order_em mo,
33 xws16_t v)
34{
35 atomic_store_explicit(a, v, (int)mo);
36 return v;
37}
38
40void xwaop__xws16_t__read(atomic_xws16_t * a,
41 xws16_t * ov)
42{
43 xws16_t o;
44
45 o = atomic_load_explicit(a, memory_order_acquire);
46 if (ov) {
47 *ov = o;
48 }
49}
50
52void xwaop__xws16_t__write(atomic_xws16_t * a,
53 xws16_t v,
54 xws16_t * ov)
55{
56 xws16_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__xws16_t__teq_then_write(atomic_xws16_t * a,
66 xws16_t t,
67 xws16_t v,
68 xws16_t * ov)
69{
70 xws16_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__xws16_t__tne_then_write(atomic_xws16_t * a,
90 xws16_t t,
91 xws16_t v,
92 xws16_t * ov)
93{
94 xws16_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__xws16_t__tgt_then_write(atomic_xws16_t * a,
120 xws16_t t,
121 xws16_t v,
122 xws16_t * ov)
123{
124 xws16_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__xws16_t__tge_then_write(atomic_xws16_t * a,
150 xws16_t t,
151 xws16_t v,
152 xws16_t * ov)
153{
154 xws16_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__xws16_t__tlt_then_write(atomic_xws16_t * a,
180 xws16_t t,
181 xws16_t v,
182 xws16_t * ov)
183{
184 xws16_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__xws16_t__tle_then_write(atomic_xws16_t * a,
210 xws16_t t,
211 xws16_t v,
212 xws16_t * ov)
213{
214 xws16_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__xws16_t__tgtlt_then_write(atomic_xws16_t * a,
240 xws16_t l, xws16_t r,
241 xws16_t v,
242 xws16_t * ov)
243{
244 xws16_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__xws16_t__tgelt_then_write(atomic_xws16_t * a,
270 xws16_t l, xws16_t r,
271 xws16_t v,
272 xws16_t * ov)
273{
274 xws16_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__xws16_t__tgtle_then_write(atomic_xws16_t * a,
300 xws16_t l, xws16_t r,
301 xws16_t v,
302 xws16_t * ov)
303{
304 xws16_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__xws16_t__tgele_then_write(atomic_xws16_t * a,
330 xws16_t l, xws16_t r,
331 xws16_t v,
332 xws16_t * ov)
333{
334 xws16_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__xws16_t__add(atomic_xws16_t * a,
361 xws16_t v,
362 xws16_t * nv, xws16_t * ov)
363{
364 xws16_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__xws16_t__teq_then_add(atomic_xws16_t * a,
377 xws16_t t,
378 xws16_t v,
379 xws16_t * nv, xws16_t * ov)
380{
381 xws16_t o;
382 xws16_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__xws16_t__tne_then_add(atomic_xws16_t * a,
408 xws16_t t,
409 xws16_t v,
410 xws16_t * nv, xws16_t * ov)
411{
412 xws16_t o;
413 xws16_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__xws16_t__tgt_then_add(atomic_xws16_t * a,
444 xws16_t t,
445 xws16_t v,
446 xws16_t * nv, xws16_t * ov)
447{
448 xws16_t o;
449 xws16_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__xws16_t__tge_then_add(atomic_xws16_t * a,
480 xws16_t t,
481 xws16_t v,
482 xws16_t * nv, xws16_t * ov)
483{
484 xws16_t o;
485 xws16_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__xws16_t__tlt_then_add(atomic_xws16_t * a,
516 xws16_t t,
517 xws16_t v,
518 xws16_t * nv, xws16_t * ov)
519{
520 xws16_t o;
521 xws16_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__xws16_t__tle_then_add(atomic_xws16_t * a,
552 xws16_t t,
553 xws16_t v,
554 xws16_t * nv, xws16_t * ov)
555{
556 xws16_t o;
557 xws16_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__xws16_t__tgtlt_then_add(atomic_xws16_t * a,
588 xws16_t l, xws16_t r,
589 xws16_t v,
590 xws16_t * nv, xws16_t * ov)
591{
592 xws16_t o;
593 xws16_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__xws16_t__tgelt_then_add(atomic_xws16_t * a,
624 xws16_t l, xws16_t r,
625 xws16_t v,
626 xws16_t * nv, xws16_t * ov)
627{
628 xws16_t o;
629 xws16_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__xws16_t__tgtle_then_add(atomic_xws16_t * a,
660 xws16_t l, xws16_t r,
661 xws16_t v,
662 xws16_t * nv, xws16_t * ov)
663{
664 xws16_t o;
665 xws16_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__xws16_t__tgele_then_add(atomic_xws16_t * a,
696 xws16_t l, xws16_t r,
697 xws16_t v,
698 xws16_t * nv, xws16_t * ov)
699{
700 xws16_t o;
701 xws16_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__xws16_t__sub(atomic_xws16_t * a,
733 xws16_t v,
734 xws16_t * nv, xws16_t * ov)
735{
736 xws16_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__xws16_t__teq_then_sub(atomic_xws16_t * a,
749 xws16_t t,
750 xws16_t v,
751 xws16_t * nv, xws16_t * ov)
752{
753 xws16_t o;
754 xws16_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__xws16_t__tne_then_sub(atomic_xws16_t * a,
780 xws16_t t,
781 xws16_t v,
782 xws16_t * nv, xws16_t * ov)
783{
784 xws16_t o;
785 xws16_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__xws16_t__tgt_then_sub(atomic_xws16_t * a,
816 xws16_t t,
817 xws16_t v,
818 xws16_t * nv, xws16_t * ov)
819{
820 xws16_t o;
821 xws16_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__xws16_t__tge_then_sub(atomic_xws16_t * a,
852 xws16_t t,
853 xws16_t v,
854 xws16_t * nv, xws16_t * ov)
855{
856 xws16_t o;
857 xws16_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__xws16_t__tlt_then_sub(atomic_xws16_t * a,
888 xws16_t t,
889 xws16_t v,
890 xws16_t * nv, xws16_t * ov)
891{
892 xws16_t o;
893 xws16_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__xws16_t__tle_then_sub(atomic_xws16_t * a,
924 xws16_t t,
925 xws16_t v,
926 xws16_t * nv, xws16_t * ov)
927{
928 xws16_t o;
929 xws16_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__xws16_t__tgtlt_then_sub(atomic_xws16_t * a,
960 xws16_t l, xws16_t r,
961 xws16_t v,
962 xws16_t * nv, xws16_t * ov)
963{
964 xws16_t o;
965 xws16_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__xws16_t__tgelt_then_sub(atomic_xws16_t * a,
996 xws16_t l, xws16_t r,
997 xws16_t v,
998 xws16_t * nv, xws16_t * ov)
999{
1000 xws16_t o;
1001 xws16_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__xws16_t__tgtle_then_sub(atomic_xws16_t * a,
1032 xws16_t l, xws16_t r,
1033 xws16_t v,
1034 xws16_t * nv, xws16_t * ov)
1035{
1036 xws16_t o;
1037 xws16_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__xws16_t__tgele_then_sub(atomic_xws16_t * a,
1068 xws16_t l, xws16_t r,
1069 xws16_t v,
1070 xws16_t * nv, xws16_t * ov)
1071{
1072 xws16_t o;
1073 xws16_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__xws16_t__rsb(atomic_xws16_t * a,
1105 xws16_t v,
1106 xws16_t * nv, xws16_t * ov)
1107{
1108 xws16_t o;
1109 xws16_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__xws16_t__teq_then_rsb(atomic_xws16_t * a,
1130 xws16_t t,
1131 xws16_t v,
1132 xws16_t * nv, xws16_t * ov)
1133{
1134 xws16_t o;
1135 xws16_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__xws16_t__tne_then_rsb(atomic_xws16_t * a,
1166 xws16_t t,
1167 xws16_t v,
1168 xws16_t * nv, xws16_t * ov)
1169{
1170 xws16_t o;
1171 xws16_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__xws16_t__tgt_then_rsb(atomic_xws16_t * a,
1202 xws16_t t,
1203 xws16_t v,
1204 xws16_t * nv, xws16_t * ov)
1205{
1206 xws16_t o;
1207 xws16_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__xws16_t__tge_then_rsb(atomic_xws16_t * a,
1238 xws16_t t,
1239 xws16_t v,
1240 xws16_t * nv, xws16_t * ov)
1241{
1242 xws16_t o;
1243 xws16_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__xws16_t__tlt_then_rsb(atomic_xws16_t * a,
1274 xws16_t t,
1275 xws16_t v,
1276 xws16_t * nv, xws16_t * ov)
1277{
1278 xws16_t o;
1279 xws16_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__xws16_t__tle_then_rsb(atomic_xws16_t * a,
1310 xws16_t t,
1311 xws16_t v,
1312 xws16_t * nv, xws16_t * ov)
1313{
1314 xws16_t o;
1315 xws16_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__xws16_t__tgtlt_then_rsb(atomic_xws16_t * a,
1346 xws16_t l, xws16_t r,
1347 xws16_t v,
1348 xws16_t * nv, xws16_t * ov)
1349{
1350 xws16_t o;
1351 xws16_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__xws16_t__tgelt_then_rsb(atomic_xws16_t * a,
1382 xws16_t l, xws16_t r,
1383 xws16_t v,
1384 xws16_t * nv, xws16_t * ov)
1385{
1386 xws16_t o;
1387 xws16_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__xws16_t__tgtle_then_rsb(atomic_xws16_t * a,
1418 xws16_t l, xws16_t r,
1419 xws16_t v,
1420 xws16_t * nv, xws16_t * ov)
1421{
1422 xws16_t o;
1423 xws16_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__xws16_t__tgele_then_rsb(atomic_xws16_t * a,
1454 xws16_t l, xws16_t r,
1455 xws16_t v,
1456 xws16_t * nv, xws16_t * ov)
1457{
1458 xws16_t o;
1459 xws16_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__xws16_t__or(atomic_xws16_t * a,
1491 xws16_t v,
1492 xws16_t * nv, xws16_t * ov)
1493{
1494 xws16_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__xws16_t__and(atomic_xws16_t * a,
1507 xws16_t v,
1508 xws16_t * nv, xws16_t * ov)
1509{
1510 xws16_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__xws16_t__xor(atomic_xws16_t * a,
1523 xws16_t v,
1524 xws16_t * nv, xws16_t * ov)
1525{
1526 xws16_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
1537/******** ******** test and operation ******** ********/
1539xwer_t xwaop__xws16_t__tst_then_op(atomic_xws16_t * a,
1540 xwaop_tst_f tst, void * tst_args,
1541 xwaop_op_f op, void * op_args,
1542 xws16_t * nv, xws16_t * ov)
1543{
1544 xws16_t o;
1545 xws16_t n;
1546 xwer_t rc;
1547
1548 do {
1549 o = atomic_load_explicit(a, memory_order_consume);
1550 if (tst) {
1551 rc = tst((const void *)&o, tst_args);
1552 if (XWOK == rc) {
1553 if (op) {
1554 op(&n, (const void *)&o, op_args);
1555 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1556 a, &o, n,
1557 memory_order_acq_rel,
1558 memory_order_consume);
1559 } else {
1560 n = o;
1561 break;
1562 }
1563 } else {
1564 n = o;
1565 break;
1566 }
1567 } else {
1568 if (op) {
1569 op(&n, (const void *)&o, op_args);
1570 rc = (xwer_t)atomic_compare_exchange_strong_explicit(
1571 a, &o, n,
1572 memory_order_acq_rel,
1573 memory_order_consume);
1574 } else {
1575 rc = XWOK;
1576 n = o;
1577 break;
1578 }
1579 }
1580 } while (rc);
1581 if (nv) {
1582 *nv = n;
1583 }
1584 if (ov) {
1585 *ov = o;
1586 }
1587 return rc;
1588}
1589
1590#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
void(* xwaop_op_f)(void *, const void *, void *)
原子变量操作函数指针类型
Definition type.h:618
int16_t xws16_t
Definition type.h:246
__xwcc_atomic xws16_t atomic_xws16_t
Definition type.h:249
XWOS通用库:原子操作
XWOS的标准头文件