XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
object.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <xwos/lib/object.h>
23#include <xwos/lib/xwlog.h>
24#include <xwos/lib/bclst.h>
26#include <xwcd/ds/xwds.h>
27#include <xwcd/ds/object.h>
28
31{
34 obj->ds = NULL;
35}
36
39{
40 obj->ds = NULL;
42}
43
46{
47 xwsq_t tik;
48
49 if (obj) {
50 tik = obj->xwobj.tik;
51 } else {
52 tik = 0;
53 }
54 return tik;
55}
56
59{
60 return xwos_object_activate(&obj->xwobj, gcfunc);
61}
62
65{
66 xwer_t rc;
67
70 NULL, NULL);
71 if (XWOK == rc) {
72 if (obj->xwobj.gcfunc) {
73 rc = obj->xwobj.gcfunc(&obj->xwobj);
74 }
75 } else {
76 rc = -EPERM;
77 }
78 return rc;
79}
80
83{
84 xwer_t rc;
85
88 NULL, NULL);
89 if (rc < 0) {
90 rc = -EPERM;
91 }
92 return rc;
93}
94
97{
98 xwer_t rc;
99
102 NULL, NULL);
103 if (rc < 0) {
104 rc = -EPERM;
105 }
106 return rc;
107}
108
111{
112 xwer_t rc;
113
116 NULL, NULL);
117 if (rc < 0) {
118 rc = -EPERM;
119 }
120 return rc;
121}
122
125{
126 xwer_t rc;
127
130 NULL, NULL);
131 if (rc < 0) {
132 rc = -EPERM;
133 }
134 return rc;
135}
136
139{
140 xwer_t rc;
141
144 NULL, NULL);
145 if (rc < 0) {
146 rc = -EPERM;
147 }
148 return rc;
149}
150
153{
154 xwer_t rc;
155
158 NULL, NULL);
159 if (rc < 0) {
160 rc = -EPERM;
161 }
162 return rc;
163}
164
167{
168 return xwos_object_get_refcnt(&obj->xwobj);
169}
170
172xwer_t xwds_obj_add(struct xwds * ds, struct xwds_object * obj)
173{
174 xwreg_t cpuirq;
175 xwer_t rc;
176
178 if (obj->ds) {
179 rc = -EPERM;
180 } else {
181 xwlib_bclst_add_tail(&ds->devhead, &obj->node); /* LIFO */
182 obj->ds = ds;
183 rc = XWOK;
184 }
186 return rc;
187}
188
190xwer_t xwds_obj_del(struct xwds * ds, struct xwds_object * obj)
191{
192 xwreg_t cpuirq;
193 xwer_t rc;
194
196 if (obj->ds != ds) {
197 rc = -EOWNER;
198 } else {
199 xwlib_bclst_del_init(&obj->node); /* LIFO */
200 obj->ds = NULL;
201 rc = XWOK;
202 }
204 return rc;
205}
XWOS通用库:双循环链表
xwer_t xwds_obj_add(struct xwds *ds, struct xwds_object *obj)
Definition object.c:172
xwer_t xwds_obj_probe(struct xwds_object *obj, xwobj_gc_f gcfunc)
Definition object.c:58
xwer_t xwds_obj_put(struct xwds_object *obj)
Definition object.c:152
xwer_t xwds_obj_remove(struct xwds_object *obj)
Definition object.c:64
void xwds_obj_destruct(struct xwds_object *obj)
Definition object.c:38
void xwds_obj_construct(struct xwds_object *obj)
Definition object.c:30
xwer_t xwds_obj_del(struct xwds *ds, struct xwds_object *obj)
Definition object.c:190
xwer_t xwds_obj_start(struct xwds_object *obj)
Definition object.c:82
xwsq_t xwds_obj_get_tik(struct xwds_object *obj)
Definition object.c:45
xwsq_t xwds_obj_get_refcnt(struct xwds_object *obj)
Definition object.c:166
xwer_t xwds_obj_resume(struct xwds_object *obj)
Definition object.c:124
xwer_t xwds_obj_suspend(struct xwds_object *obj)
Definition object.c:110
xwer_t xwds_obj_grab(struct xwds_object *obj)
Definition object.c:138
xwer_t xwds_obj_stop(struct xwds_object *obj)
Definition object.c:96
@ XWDS_OBJ_REF_SHUTDOWN
Definition object.h:41
@ XWDS_OBJ_REF_RUNNING
Definition object.h:43
@ XWDS_OBJ_REF_SUSPEND
Definition object.h:42
#define __xwds_code
Definition standard.h:31
static void xwlib_bclst_add_tail(struct xwlib_bclst_node *head, struct xwlib_bclst_node *newn)
将一个节点加入链表尾部(链表头的前面)
Definition bclst.h:357
static void xwlib_bclst_init_node(struct xwlib_bclst_node *n)
初始化一个链表节点。
Definition bclst.h:240
static void xwlib_bclst_del_init(struct xwlib_bclst_node *node)
删除一个节点,并重新初始化它
Definition bclst.h:391
#define XWOK
No error
Definition errno.h:182
#define EOWNER
Owner error
Definition errno.h:202
#define EPERM
Operation not permitted
Definition errno.h:31
signed long xwer_t
Definition type.h:554
#define NULL
Definition type.h:28
unsigned long xwsq_t
Definition type.h:445
xwptr_t xwreg_t
Definition type.h:409
#define xwaop_teq_then_sub(type, a, t, v, nv, ov)
对原子变量进行原子操作:读取-测试“相等”-相减-回写
Definition xwaop.h:623
#define xwaop_tge_then_add(type, a, t, v, nv, ov)
对原子变量进行原子操作:读取-测试“大于等于”-相加-回写
Definition xwaop.h:430
#define xwaop_tgt_then_sub(type, a, t, v, nv, ov)
对原子变量进行原子操作:读取-测试“大于”-相减-回写
Definition xwaop.h:673
#define xwaop_teq_then_add(type, a, t, v, nv, ov)
对原子变量进行原子操作:读取-测试“相等”-相加-回写
Definition xwaop.h:355
xwer_t(* xwobj_gc_f)(struct xwos_object *)
垃圾回收函数指针类型
Definition object.h:42
xwer_t xwos_object_activate(struct xwos_object *obj, xwobj_gc_f gcfunc)
激活一个XWOS对象(将其引用计数初始化位1)
Definition object.c:135
void xwos_object_construct(struct xwos_object *obj)
XWOS对象的构造函数
Definition object.c:107
xwsq_t xwos_object_get_refcnt(struct xwos_object *obj)
获取XWOS对象的引用计数
Definition object.c:363
void xwos_object_destruct(struct xwos_object *obj)
XWOS对象的析构函数
Definition object.c:119
static void xwos_sqlk_wr_lock_cpuirqsv(struct xwos_sqlk *sql, xwreg_t *cpuirq)
XWOS API:开启写临界区,保存本地CPU的中断标志并关闭
Definition seqlock.h:580
static void xwos_sqlk_wr_unlock_cpuirqrs(struct xwos_sqlk *sql, xwreg_t cpuirq)
XWOS API:关闭写临界区,恢复本地CPU的中断标志
Definition seqlock.h:613
操作系统抽象层:顺序锁
设备栈对象
Definition object.h:49
struct xwds * ds
Definition object.h:54
struct xwos_object xwobj
Definition object.h:50
struct xwlib_bclst_node node
Definition object.h:53
设备栈
Definition xwds.h:37
struct xwos_sqlk devlistlock
Definition xwds.h:39
struct xwlib_bclst_node devhead
Definition xwds.h:38
atomic_xwsq_t refcnt
Definition object.h:56
xwsq_t tik
Definition object.h:54
xwobj_gc_f gcfunc
Definition object.h:57
玄武设备栈:对象
玄武设备栈:顶级头文件
玄武设备栈:电源管理框架
XWOS通用库:日志
XWOS通用库:XWOS的对象