XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
SMtx.cxx
浏览该文件的文档.
1
14
15namespace xwos {
16namespace lock {
17
18/* SMtx::Grd Non-static Member */
19SMtx::Grd::Grd(SMtx * mtx, enum LockMode mode, xwtm_t to)
20 : mMtx(mtx)
21 , mLockMode(mode)
22{
23 if (nullptr != mMtx) {
24 switch (mode) {
27 break;
30 break;
33 break;
36 break;
38 mRc = XWOK;
39 break;
40 default:
42 mRc = XWOK;
43 break;
44 }
45 }
46}
47
49{
50 if (nullptr != mMtx) {
51 if (SMtx::LockMode::SMtxUnlock != mLockMode) {
52 xwos_mtx_unlock(&mMtx->mLock);
53 }
54 }
55}
56
58{
59 xwer_t rc;
60 if (nullptr != mMtx) {
61 union xwos_ulock lock;
62 xwsq_t lkst;
63 lock.osal.mtx = &mMtx->mLock;
65 rc = xwos_cond_wait_unintr(cond->getXwosObj(), lock, XWOS_LK_MTX, nullptr, &lkst);
66 } else {
67 rc = xwos_cond_wait(cond->getXwosObj(), lock, XWOS_LK_MTX, nullptr, &lkst);
68 }
69 if (rc < 0) {
70 if (XWOS_LKST_UNLOCKED == lkst) {
72 }
73 }
74 } else {
75 rc = -EFAULT;
76 }
77 return rc;
78}
79
81{
82 xwer_t rc;
83 if (nullptr != mMtx) {
84 union xwos_ulock lock;
85 xwsq_t lkst;
86
87 lock.osal.mtx = &mMtx->mLock;
89 rc = xwos_cond_wait_unintr(cond->getXwosObj(), lock, XWOS_LK_MTX, nullptr, &lkst);
90 } else {
91 rc = xwos_cond_wait_to(cond->getXwosObj(), lock, XWOS_LK_MTX, nullptr, to, &lkst);
92 }
93 if (rc < 0) {
94 if (XWOS_LKST_UNLOCKED == lkst) {
96 }
97 }
98 } else {
99 rc = -EFAULT;
100 }
101 return rc;
102}
103
104/* SMtx Non-static Member */
106{
108}
109
111{
113}
114
115} // namespace xwos
116} // namespace lock
xwos::lock::SMtx
xwer_t wait(sync::Cond *cond)
等待条件量
Definition SMtx.cxx:57
~Grd()
析构静态互斥锁的RAII机制守卫并解锁互斥锁
Definition SMtx.cxx:48
enum LockMode mLockMode
Definition SMtx.hxx:98
静态互斥锁
Definition SMtx.hxx:74
xwer_t mCtorRc
Definition SMtx.hxx:264
struct xwos_mtx mLock
Definition SMtx.hxx:263
LockMode
静态互斥锁的锁模式
Definition SMtx.hxx:79
@ SMtxLockUninterruptable
Definition SMtx.hxx:84
SMtx(xwpr_t pr=XWOS_SKD_PRIORITY_RT_MAX)
构造函数
Definition SMtx.cxx:105
条件量基类
Definition Cond.hxx:31
struct xwos_cond * getXwosObj()
Definition Cond.hxx:45
#define EFAULT
Bad address
Definition errno.h:44
#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
xws32_t xwpr_t
Definition type.h:534
unsigned long xwsq_t
Definition type.h:445
@ XWOS_LKST_UNLOCKED
Definition type.h:661
@ XWOS_LK_MTX
Definition type.h:641
static xwer_t xwos_mtx_init(struct xwos_mtx *mtx, xwpr_t sprio)
XWOS API:静态方式初始化互斥锁
Definition mtx.h:111
static xwer_t xwos_mtx_lock_to(struct xwos_mtx *mtx, xwtm_t to)
XWOS API:限时等待上锁互斥锁
Definition mtx.h:329
static xwer_t xwos_mtx_trylock(struct xwos_mtx *mtx)
XWOS API:尝试上锁互斥锁,不会阻塞调用线程
Definition mtx.h:370
static xwer_t xwos_mtx_fini(struct xwos_mtx *mtx)
XWOS API:销毁静态方式初始化的互斥锁
Definition mtx.h:126
static xwer_t xwos_mtx_unlock(struct xwos_mtx *mtx)
XWOS API:解锁互斥锁
Definition mtx.h:279
static xwer_t xwos_mtx_lock(struct xwos_mtx *mtx)
XWOS API:等待并上锁互斥锁
Definition mtx.h:302
static xwer_t xwos_mtx_lock_unintr(struct xwos_mtx *mtx)
XWOS API:等待并上锁互斥锁,且等待不可被中断
Definition mtx.h:348
static xwer_t xwos_cond_wait_unintr(struct xwos_cond *cond, union xwos_ulock lock, xwsq_t lktype, void *lkdata, xwsq_t *lkst)
XWOS API:不可中断地等待条件量
Definition cond.h:543
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_mtx * mtx
Definition type.h:682
union xwos_ulock::@8 osal