XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
Spinlock.cxx
浏览该文件的文档.
1
14
15namespace xwos {
16namespace lock {
17
18/* Spinlock::LkGrd Non-static Member */
20 : mSpinlock(spinlock)
21 , mStatus(Spinlock::LockStatus::SpinlockUnlocked)
22{
23 if (nullptr != mSpinlock) {
26 }
27}
28
30 : mSpinlock(&spinlock)
32{
33 if (nullptr != mSpinlock) {
36 }
37}
38
40{
41 if (nullptr != mSpinlock) {
44 xwos_splk_unlock(&mSpinlock->mLock);
45 }
46 }
47}
48
50{
51 xwer_t rc;
52 if (nullptr != mSpinlock) {
54 union xwos_ulock lock;
55 xwsq_t lkst;
56 lock.osal.splk = &mSpinlock->mLock;
57 rc = xwos_cond_wait(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr, &lkst);
58 if (rc < 0) {
59 if (XWOS_LKST_UNLOCKED == lkst) {
60 xwos_splk_lock(&mSpinlock->mLock);
61 }
62 }
63 } else {
64 rc = -ENOLCK;
65 }
66 } else {
67 rc = -EFAULT;
68 }
69 return rc;
70}
71
73{
74 xwer_t rc;
75 if (nullptr != mSpinlock) {
77 union xwos_ulock lock;
78 xwsq_t lkst;
79 lock.osal.splk = &mSpinlock->mLock;
80 rc = xwos_cond_wait_to(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr,
81 to, &lkst);
82 if (rc < 0) {
83 if (XWOS_LKST_UNLOCKED == lkst) {
84 xwos_splk_lock(&mSpinlock->mLock);
85 }
86 }
87 } else {
88 rc = -ENOLCK;
89 }
90 } else {
91 rc = -EFAULT;
92 }
93 return rc;
94}
95
96/* Spinlock::TryLkGrd Non-static Member */
98 : LkGrd()
99{
100 mSpinlock = spinlock;
101 if (nullptr != mSpinlock) {
103 if (XWOK != mRc) {
104 mSpinlock = nullptr;
105 } else {
107 }
108 }
109}
110
112 : LkGrd()
113{
114 mSpinlock = &spinlock;
115 if (nullptr != mSpinlock) {
117 if (XWOK != mRc) {
118 mSpinlock = nullptr;
119 } else {
121 }
122 }
123}
124
125/* Spinlock::LkThGrd Non-static Member */
127 : mSpinlock(spinlock)
129{
130 if (nullptr != mSpinlock) {
133 }
134}
135
137 : mSpinlock(&spinlock)
139{
140 if (nullptr != mSpinlock) {
143 }
144}
145
147{
148 if (nullptr != mSpinlock) {
151 xwos_splk_unlock_cpuirqrs(&mSpinlock->mLock, mCpuirq);
152 }
153 }
154}
155
157{
158 xwer_t rc;
159 if (nullptr != mSpinlock) {
161 union xwos_ulock lock;
162 xwsq_t lkst;
163 lock.osal.splk = &mSpinlock->mLock;
164 rc = xwos_cond_wait(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr, &lkst);
165 if (rc < 0) {
166 if (XWOS_LKST_UNLOCKED == lkst) {
167 xwos_splk_lock(&mSpinlock->mLock);
168 }
169 }
170 } else {
171 rc = -ENOLCK;
172 }
173 } else {
174 rc = -EFAULT;
175 }
176 return rc;
177}
178
180{
181 xwer_t rc;
182 if (nullptr != mSpinlock) {
184 union xwos_ulock lock;
185 xwsq_t lkst;
186 lock.osal.splk = &mSpinlock->mLock;
187 rc = xwos_cond_wait_to(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr,
188 to, &lkst);
189 if (rc < 0) {
190 if (XWOS_LKST_UNLOCKED == lkst) {
191 xwos_splk_lock(&mSpinlock->mLock);
192 }
193 }
194 } else {
195 rc = -ENOLCK;
196 }
197 } else {
198 rc = -EFAULT;
199 }
200 return rc;
201}
202
203/* Spinlock::TryLkThGrd Non-static Member */
205 : LkThGrd()
206{
207 mSpinlock = spinlock;
208 if (nullptr != mSpinlock) {
210 if (XWOK != mRc) {
211 mSpinlock = nullptr;
212 } else {
214 }
215 }
216}
217
219 : LkThGrd()
220{
221 mSpinlock = &spinlock;
222 if (nullptr != mSpinlock) {
224 if (XWOK != mRc) {
225 mSpinlock = nullptr;
226 } else {
228 }
229 }
230}
231
232/* Spinlock::LkBhGrd Non-static Member */
234 : mSpinlock(spinlock)
236{
237 if (nullptr != mSpinlock) {
240 }
241}
242
244 : mSpinlock(&spinlock)
246{
247 if (nullptr != mSpinlock) {
250 }
251}
252
254{
255 if (nullptr != mSpinlock) {
258 xwos_splk_unlock_bh(&mSpinlock->mLock);
259 }
260 }
261}
262
264{
265 xwer_t rc;
266 if (nullptr != mSpinlock) {
268 union xwos_ulock lock;
269 xwsq_t lkst;
270 lock.osal.splk = &mSpinlock->mLock;
271 rc = xwos_cond_wait(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr, &lkst);
272 if (rc < 0) {
273 if (XWOS_LKST_UNLOCKED == lkst) {
274 xwos_splk_lock(&mSpinlock->mLock);
275 }
276 }
277 } else {
278 rc = -ENOLCK;
279 }
280 } else {
281 rc = -EFAULT;
282 }
283 return rc;
284}
285
287{
288 xwer_t rc;
289 if (nullptr != mSpinlock) {
291 union xwos_ulock lock;
292 xwsq_t lkst;
293 lock.osal.splk = &mSpinlock->mLock;
294 rc = xwos_cond_wait_to(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr,
295 to, &lkst);
296 if (rc < 0) {
297 if (XWOS_LKST_UNLOCKED == lkst) {
298 xwos_splk_lock(&mSpinlock->mLock);
299 }
300 }
301 } else {
302 rc = -ENOLCK;
303 }
304 } else {
305 rc = -EFAULT;
306 }
307 return rc;
308}
309
310/* Spinlock::TryLkBhGrd Non-static Member */
312 : LkBhGrd()
313{
314 mSpinlock = spinlock;
315 if (nullptr != mSpinlock) {
317 if (XWOK != mRc) {
318 mSpinlock = nullptr;
319 } else {
321 }
322 }
323}
324
326 : LkBhGrd()
327{
328 mSpinlock = &spinlock;
329 if (nullptr != mSpinlock) {
331 if (XWOK != mRc) {
332 mSpinlock = nullptr;
333 } else {
335 }
336 }
337}
338
339/* Spinlock::LkIrqsGrd Non-static Member */
340template<xwirq_t ... TIrqList>
342 : mSpinlock(spinlock)
344 , mIrqs{TIrqList ...}
345{
346 if (nullptr != mSpinlock) {
347 xwos_splk_lock_irqssv(&mSpinlock->mLock, mIrqs, mIrqFlags, sizeof...(TIrqList));
349 }
350}
351
352template<xwirq_t ... TIrqList>
354 : mSpinlock(&spinlock)
356 , mIrqs{TIrqList ...}
357{
358 if (nullptr != mSpinlock) {
359 xwos_splk_lock_irqssv(&mSpinlock->mLock, mIrqs, mIrqFlags, sizeof...(TIrqList));
361 }
362}
363
364template<xwirq_t ... TIrqList>
366{
367 if (nullptr != mSpinlock) {
370 xwos_splk_unlock_irqsrs(&mSpinlock->mLock, mIrqs, mIrqFlags,
371 sizeof...(TIrqList));
372 }
373 }
374}
375
376template <xwirq_t ... TIrqList>
378{
379 xwer_t rc;
380 if (nullptr != mSpinlock) {
382 union xwos_ulock lock;
383 xwsq_t lkst;
384 lock.osal.splk = &mSpinlock->mLock;
385 rc = xwos_cond_wait(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr, &lkst);
386 if (rc < 0) {
387 if (XWOS_LKST_UNLOCKED == lkst) {
388 xwos_splk_lock(&mSpinlock->mLock);
389 }
390 }
391 } else {
392 rc = -ENOLCK;
393 }
394 } else {
395 rc = -EFAULT;
396 }
397 return rc;
398}
399
400template <xwirq_t ... TIrqList>
402{
403 xwer_t rc;
404 if (nullptr != mSpinlock) {
406 union xwos_ulock lock;
407 xwsq_t lkst;
408 lock.osal.splk = &mSpinlock->mLock;
409 rc = xwos_cond_wait_to(cond->getXwosObj(), lock, XWOS_LK_SPLK, nullptr,
410 to, &lkst);
411 if (rc < 0) {
412 if (XWOS_LKST_UNLOCKED == lkst) {
413 xwos_splk_lock(&mSpinlock->mLock);
414 }
415 }
416 } else {
417 rc = -ENOLCK;
418 }
419 } else {
420 rc = -EFAULT;
421 }
422 return rc;
423}
424
425/* Spinlock::LkIrqsGrd Non-static Member */
426template<xwirq_t ... TIrqList>
428 : LkIrqsGrd<TIrqList ...>()
429{
430 LkIrqsGrd<TIrqList ...>::mSpinlock = spinlock;
431 if (nullptr != LkIrqsGrd<TIrqList ...>::mSpinlock) {
435 sizeof...(TIrqList));
436 if (XWOK != mRc) {
437 LkIrqsGrd<TIrqList ...>::mSpinlock = nullptr;
438 } else {
440 }
441 }
442}
443
444template<xwirq_t ... TIrqList>
446 : LkIrqsGrd<TIrqList ...>()
447{
448 LkIrqsGrd<TIrqList ...>::mSpinlock = spinlock;
449 if (nullptr != LkIrqsGrd<TIrqList ...>::mSpinlock) {
453 sizeof...(TIrqList));
454 if (XWOK != mRc) {
455 LkIrqsGrd<TIrqList ...>::mSpinlock = nullptr;
456 } else {
458 }
459 }
460}
461
462/* Spinlock Non-static Member */
464{
466}
467
469{
470}
471
472} // namespace xwos
473} // namespace lock
xwos::lock::Spinlock
中断底半部上锁模式下的自旋锁RAII机制守卫
Definition Spinlock.hxx:582
xwer_t wait(sync::Cond *cond)
等待条件量
Definition Spinlock.cxx:263
~LkBhGrd()
析构自旋锁的RAII机制守卫
Definition Spinlock.cxx:253
普通上锁模式下的自旋锁RAII机制守卫
Definition Spinlock.hxx:265
xwer_t wait(sync::Cond *cond)
等待条件量
Definition Spinlock.cxx:49
~LkGrd()
析构自旋锁的RAII机制守卫
Definition Spinlock.cxx:39
部分中断上锁模式的自旋锁RAII机制守卫
Definition Spinlock.hxx:743
~LkIrqsGrd()
析构自旋锁的RAII机制守卫
Definition Spinlock.cxx:365
xwer_t wait(sync::Cond *cond)
等待条件量
Definition Spinlock.cxx:377
xwreg_t mIrqFlags[sizeof...(TIrqList)]
Definition Spinlock.hxx:748
xwirq_t mIrqs[sizeof...(TIrqList)]
Definition Spinlock.hxx:747
CPU中断上锁模式下的自旋锁RAII机制守卫
Definition Spinlock.hxx:423
~LkThGrd()
析构自旋锁的RAII机制守卫
Definition Spinlock.cxx:146
xwer_t wait(sync::Cond *cond)
等待条件量
Definition Spinlock.cxx:156
TryLkBhGrd(Spinlock *spinlock)
构造自旋锁的RAII机制守卫
Definition Spinlock.cxx:311
TryLkGrd(Spinlock *spinlock)
构造自旋锁的RAII机制守卫
Definition Spinlock.cxx:97
TryLkIrqsGrd(Spinlock *spinlock)
构造自旋锁的RAII机制守卫
Definition Spinlock.cxx:427
TryLkThGrd(Spinlock *spinlock)
构造自旋锁的RAII机制守卫
Definition Spinlock.cxx:204
struct xwos_splk mLock
Definition Spinlock.hxx:897
条件量基类
Definition Cond.hxx:31
struct xwos_cond * getXwosObj()
Definition Cond.hxx:45
#define EFAULT
Bad address
Definition errno.h:44
#define ENOLCK
No lock
Definition errno.h:76
#define XWOK
No error
Definition errno.h:182
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
signed long xwer_t
Definition type.h:554
signed int xwirq_t
Definition type.h:517
unsigned long xwsq_t
Definition type.h:445
@ XWOS_LKST_UNLOCKED
Definition type.h:661
@ XWOS_LK_SPLK
Definition type.h:642
static void xwos_splk_unlock_irqsrs(struct xwos_splk *spl, const xwirq_t irqs[], xwreg_t flags[], xwsz_t num)
XWOS API:解锁自旋锁,并恢复部分中断的中断标志
Definition spinlock.h:341
static void xwos_splk_lock_bh(struct xwos_splk *spl)
XWOS API:上锁自旋锁,关闭本地CPU的中断底半部
Definition spinlock.h:358
static xwer_t xwos_splk_trylock_bh(struct xwos_splk *spl)
XWOS API:尝试上锁自旋锁,关闭本地CPU的中断底半部
Definition spinlock.h:377
static xwer_t xwos_splk_trylock_cpuirqsv(struct xwos_splk *spl, xwreg_t *cpuirq)
XWOS API:尝试上锁自旋锁,保存本地CPU的中断标志并关闭
Definition spinlock.h:211
static void xwos_splk_unlock(struct xwos_splk *spl)
XWOS API:解锁自旋锁
Definition spinlock.h:133
static void xwos_splk_lock(struct xwos_splk *spl)
XWOS API:上锁自旋锁,若自旋锁已开启临界区,就自旋等待
Definition spinlock.h:103
static void xwos_splk_unlock_cpuirqrs(struct xwos_splk *spl, xwreg_t cpuirq)
XWOS API:解锁自旋锁,并恢复本地CPU的中断标志
Definition spinlock.h:224
static void xwos_splk_init(struct xwos_splk *spl)
XWOS API:初始化自旋锁
Definition spinlock.h:89
static xwer_t xwos_splk_trylock_irqssv(struct xwos_splk *spl, const xwirq_t irqs[], xwreg_t flags[], xwsz_t num)
XWOS API:尝试上锁自旋锁,保存部分中断的中断标志并关闭
Definition spinlock.h:324
static void xwos_splk_lock_cpuirqsv(struct xwos_splk *spl, xwreg_t *cpuirq)
XWOS API:上锁自旋锁,保存本地CPU的中断标志并关闭
Definition spinlock.h:192
static xwer_t xwos_splk_trylock(struct xwos_splk *spl)
XWOS API:尝试上锁自旋锁
Definition spinlock.h:121
static void xwos_splk_lock_irqssv(struct xwos_splk *spl, const xwirq_t irqs[], xwreg_t flags[], xwsz_t num)
XWOS API:上锁自旋锁,保存部分中断的中断标志并关闭
Definition spinlock.h:300
static void xwos_splk_unlock_bh(struct xwos_splk *spl)
XWOS API:解锁自旋锁,开启本地CPU的中断底半部
Definition spinlock.h:389
static xwer_t xwos_cond_wait(struct xwos_cond *cond, union xwos_ulock lock, xwsq_t lktype, void *lkdata, xwsq_t *lkst)
XWOS API:等待条件量
Definition cond.h:432
static xwer_t xwos_cond_wait_to(struct xwos_cond *cond, union xwos_ulock lock, xwsq_t lktype, void *lkdata, xwtm_t to, xwsq_t *lkst)
XWOS API:限时等待条件量
Definition cond.h:492
Definition Cpu.hxx:19
所有锁的联合
Definition type.h:680
struct xwmp_splk * splk
Definition type.h:683
union xwos_ulock::@8 osal