XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
bmp.c
浏览该文件的文档.
1
13#include <xwos/standard.h>
14#include <xwos/lib/xwbop.h>
15#include <xwos/lib/xwaop.h>
16
19{
20 atomic_xwbmp_t * pos;
21 bool ret;
22 xwbmp_t value;
23
24 pos = &bmp[XWBOP_BMP(idx)];
25 value = xwaop_load(xwbmp_t, pos, xwaop_mo_consume);
26 ret = (bool)(!!(value & XWBOP_BMP_MASK(idx)));
27 return ret;
28}
29
32{
33 xwsq_t i = XWBOP_BMP(idx);
34 xwbmp_t m = XWBOP_BMP_MASK(idx);
35
36 xwaop_s1m(xwbmp_t, &bmp[i], m, NULL, NULL);
37}
38
41{
42 xwsq_t i = XWBOP_BMP(idx);
43 xwbmp_t m = XWBOP_BMP_MASK(idx);
44
45 xwaop_c0m(xwbmp_t, &bmp[i], m, NULL, NULL);
46}
47
50{
51 xwsq_t i = XWBOP_BMP(idx);
52 xwbmp_t m = XWBOP_BMP_MASK(idx);
53
54 xwaop_x1m(xwbmp_t, &bmp[i], m, NULL, NULL);
55}
56
59{
60 xwsq_t i = XWBOP_BMP(idx);
61 xwbmp_t m = XWBOP_BMP_MASK(idx);
62 xwbmp_t o;
63 xwbmp_t n;
64 xwer_t rc;
65
66 do {
67 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
68 if (!(o & m)) {
69 n = o | m;
70 rc = XWOK;
71 } else {
72 rc = -EACCES;
73 break;
74 }
75 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
76 return rc;
77}
78
81{
82 xwsq_t i = XWBOP_BMP(idx);
83 xwbmp_t m = XWBOP_BMP_MASK(idx);
84 xwbmp_t o;
85 xwbmp_t n;
86 xwer_t rc;
87
88 do {
89 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
90 if ((xwbmp_t)0 != (o & m)) {
91 n = o & (xwbmp_t)(~m);
92 rc = XWOK;
93 } else {
94 rc = -EACCES;
95 break;
96 }
97 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
98 return rc;
99}
100
103{
104 xwsz_t total = BITS_TO_XWBMP_T(num);
105 xwsq_t i;
106 xwbmp_t msk;
107 xwbmp_t o;
108 xwbmp_t n;
109 xwbmp_t m;
110 xwssq_t pos;
111
112 do {
113 i = total;
114 pos = -ENODATA;
115 msk = ((xwbmp_t)XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
116 if ((xwbmp_t)0 == msk) {
117 msk = (xwbmp_t)(~(xwbmp_t)0);
118 }
119 do {
120 i--;
121 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
122 o &= msk;
123 if ((xwbmp_t)0 != o) {
124 pos = xwbop_fls(xwbmp_t, o);
125 break;
126 }
127 msk = (xwbmp_t)(~(xwbmp_t)0);
128 } while (i > (xwsq_t)0);
129 if (pos < 0) {
130 pos = -ENODATA;
131 break;
132 } else {
133 m = ((xwbmp_t)1 << (xwbmp_t)pos);
134 n = o & (xwbmp_t)(~m);
135 pos += (xwssq_t)i * (xwssq_t)BITS_PER_XWBMP_T;
136 }
137 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
138 return pos;
139}
140
143{
144 xwsz_t total = BITS_TO_XWBMP_T(num);
145 xwsq_t i;
146 xwbmp_t msk;
147 xwbmp_t tmp;
148 xwbmp_t o;
149 xwbmp_t n;
150 xwbmp_t m;
151 xwssq_t pos;
152
153 do {
154 i = total;
155 pos = -ENODATA;
156 msk = ((xwbmp_t)XWBOP_BIT(num % BITS_PER_XWBMP_T) - (xwbmp_t)1);
157 if ((xwbmp_t)0 == msk) {
158 msk = (xwbmp_t)(~(xwbmp_t)0);
159 }
160 do {
161 i--;
162 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
163 tmp = (xwbmp_t)(~o) & msk;
164 if ((xwbmp_t)0 != tmp) {
165 pos = xwbop_fls(xwbmp_t, tmp);
166 break;
167 }
168 msk = (xwbmp_t)(~(xwbmp_t)0);
169 } while (i > (xwsq_t)0);
170 if (pos < 0) {
171 pos = -ENODATA;
172 break;
173 } else {
174 m = ((xwbmp_t)1 << (xwbmp_t)pos);
175 n = o | m;
176 pos += (xwssq_t)i * (xwssq_t)BITS_PER_XWBMP_T;
177 }
178 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
179 return pos;
180}
181
184{
185 xwsz_t total = BITS_TO_XWBMP_T(num);
186 xwsq_t i;
187 xwbmp_t msk;
188 xwbmp_t o;
189 xwbmp_t n;
190 xwbmp_t m;
191 xwssq_t pos;
192
193 do {
194 i = 0;
195 pos = -ENODATA;
196 do {
197 if (i == (total - (xwsz_t)1)) {
198 msk = ((xwbmp_t)XWBOP_BIT(num % BITS_PER_XWBMP_T) -
199 (xwbmp_t)1);
200 if ((xwbmp_t)0 == msk) {
201 msk = (xwbmp_t)(~(xwbmp_t)0);
202 }
203 } else {
204 msk = (xwbmp_t)(~(xwbmp_t)0);
205 }
206 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
207 o &= msk;
208 if ((xwbmp_t)0 != o) {
209 pos = xwbop_ffs(xwbmp_t, o);
210 break;
211 }
212 i++;
213 } while (i < total);
214 if (pos < 0) {
215 pos = -ENODATA;
216 break;
217 } else {
218 m = ((xwbmp_t)1 << (xwbmp_t)pos);
219 n = o & (xwbmp_t)(~m);
220 pos += (xwssq_t)i * (xwssq_t)BITS_PER_XWBMP_T;
221 }
222 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
223 return pos;
224}
225
228{
229 xwsz_t total = BITS_TO_XWBMP_T(num);
230 xwsq_t i;
231 xwbmp_t msk;
232 xwbmp_t tmp;
233 xwbmp_t o;
234 xwbmp_t n;
235 xwbmp_t m;
236 xwssq_t pos;
237
238 do {
239 i = 0;
240 pos = -ENODATA;
241 do {
242 if (i == (total - (xwsz_t)1)) {
243 msk = ((xwbmp_t)XWBOP_BIT(num % BITS_PER_XWBMP_T) -
244 (xwbmp_t)1);
245 if ((xwbmp_t)0 == msk) {
246 msk = (xwbmp_t)(~(xwbmp_t)0);
247 }
248 } else {
249 msk = (xwbmp_t)(~(xwbmp_t)0);
250 }
251 o = xwaop_load(xwbmp_t, &bmp[i], xwaop_mo_consume);
252 tmp = (xwbmp_t)(~o) & msk;
253 if ((xwbmp_t)0 != tmp) {
254 pos = xwbop_ffs(xwbmp_t, tmp);
255 break;
256 }
257 i++;
258 } while (i < total);
259 if (pos < 0) {
260 pos = -ENODATA;
261 break;
262 } else {
263 m = ((xwbmp_t)1 << (xwbmp_t)pos);
264 n = o | m;
265 pos += (xwssq_t)i * (xwssq_t)BITS_PER_XWBMP_T;
266 }
267 } while (XWOK != xwaop_teq_then_write(xwbmp_t, &bmp[i], o, n, NULL));
268 return pos;
269}
#define __xwlib_code
Definition compiler.h:199
#define ENODATA
No data (for no delay io)
Definition errno.h:86
#define XWOK
No error
Definition errno.h:182
#define EACCES
Permission denied
Definition errno.h:43
signed long xwer_t
Definition type.h:554
#define NULL
Definition type.h:28
unsigned long xwsz_t
Definition type.h:339
__xwcc_atomic xwbmp_t atomic_xwbmp_t
Definition type.h:577
unsigned long xwsq_t
Definition type.h:445
#define BITS_PER_XWBMP_T
Definition type.h:580
signed long xwssq_t
Definition type.h:461
xwu32_t xwbmp_t
Definition type.h:574
@ xwaop_mo_consume
Definition type.h:629
#define xwaop_teq_then_write(type, a, t, v, ov)
对原子变量进行原子操作:读取-测试“相等”-写
Definition xwaop.h:113
#define xwaop_c0m(type, a, m, nv, ov)
对原子变量进行原子操作:读取-位清0操作-回写
Definition xwaop.h:1190
#define xwaop_load(type, a, memorder)
对原子变量进行原子操作:加载
Definition xwaop.h:45
#define xwaop_s1m(type, a, m, nv, ov)
对原子变量进行原子操作:读取-位置1操作-回写
Definition xwaop.h:1176
#define xwaop_x1m(type, a, m, nv, ov)
对原子变量进行原子操作:读取-位翻转操作-回写
Definition xwaop.h:1204
void xwbmpaop_x1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:将位图中某位翻转
Definition bmp.c:49
xwssq_t xwbmpaop_ffz_then_s1i(atomic_xwbmp_t *bmp, xwsz_t num)
XWOS AOPLIB:从最低位起查找位图中第一个为0的位并将它置1
Definition bmp.c:227
xwssq_t xwbmpaop_fls_then_c0i(atomic_xwbmp_t *bmp, xwsz_t num)
XWOS AOPLIB:从最高位起查找位图中第一个为1的位并将它清0
Definition bmp.c:102
xwssq_t xwbmpaop_ffs_then_c0i(atomic_xwbmp_t *bmp, xwsz_t num)
XWOS AOPLIB:从最低位起查找位图中第一个为1的位并将它清0
Definition bmp.c:183
bool xwbmpaop_t1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:测试位图中的某位是否被置1
Definition bmp.c:18
xwer_t xwbmpaop_t1i_then_c0i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:测试位图中某位是否为1,如果是,就将它清0
Definition bmp.c:80
xwssq_t xwbmpaop_flz_then_s1i(atomic_xwbmp_t *bmp, xwsz_t num)
XWOS AOPLIB:从最高位起查找位图中第一个为0的位并将它置1
Definition bmp.c:142
void xwbmpaop_c0i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:将位图中某位清0
Definition bmp.c:40
xwer_t xwbmpaop_t0i_then_s1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:测试位图中某位是否为0,如果是,就将它置1
Definition bmp.c:58
void xwbmpaop_s1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:将位图中某位置1
Definition bmp.c:31
#define XWBOP_BMP(n)
Definition xwbop.h:29
#define xwbop_fls(type, data)
XWOS BOPLIB:在数据中从最高位起查找第一个被置1的位
Definition xwbop.h:169
#define BITS_TO_XWBMP_T(n)
Definition xwbop.h:35
#define XWBOP_BIT(n)
Definition xwbop.h:27
#define XWBOP_BMP_MASK(n)
Definition xwbop.h:28
#define xwbop_ffs(type, data)
XWOS BOPLIB:在数据中从最低位起查找第一个被置1的位
Definition xwbop.h:157
XWOS通用库:原子操作
XWOS通用库:位操作
XWOS的标准头文件