5 #include <lwp_threads.h>
6 #include <lwp_wkspace.h>
7 #include <lwp_config.h>
9 #include "lwp_objmgr.h"
11 static u32 _lwp_objmgr_memsize
= 0;
12 static lwp_obj
*null_local_table
= NULL
;
14 u32
__lwp_objmgr_memsize()
16 return _lwp_objmgr_memsize
;
19 void __lwp_objmgr_initinfo(lwp_objinfo
*info
,u32 max_nodes
,u32 node_size
)
28 info
->inactives_cnt
= 0;
29 info
->node_size
= node_size
;
30 info
->max_nodes
= max_nodes
;
31 info
->obj_blocks
= NULL
;
32 info
->local_table
= &null_local_table
;
34 __lwp_queue_init_empty(&info
->inactives
);
36 size
= ((info
->max_nodes
*sizeof(lwp_obj
*))+(info
->max_nodes
*info
->node_size
));
37 local_table
= (void**)__lwp_wkspace_allocate(info
->max_nodes
*sizeof(lwp_obj
*));
38 if(!local_table
) return;
40 info
->local_table
= (lwp_obj
**)local_table
;
41 for(i
=0;i
<info
->max_nodes
;i
++) {
42 local_table
[i
] = NULL
;
45 info
->obj_blocks
= __lwp_wkspace_allocate(info
->max_nodes
*info
->node_size
);
46 if(!info
->obj_blocks
) {
47 __lwp_wkspace_free(local_table
);
51 __lwp_queue_initialize(&inactives
,info
->obj_blocks
,info
->max_nodes
,info
->node_size
);
54 while((object
=(lwp_obj
*)__lwp_queue_get(&inactives
))!=NULL
) {
56 object
->information
= NULL
;
57 __lwp_queue_append(&info
->inactives
,&object
->node
);
61 info
->max_id
+= info
->max_nodes
;
62 info
->inactives_cnt
+= info
->max_nodes
;
63 _lwp_objmgr_memsize
+= size
;
66 lwp_obj
* __lwp_objmgr_getisrdisable(lwp_objinfo
*info
,u32 id
,u32
*p_level
)
69 lwp_obj
*object
= NULL
;
71 _CPU_ISR_Disable(level
);
72 if(info
->max_id
>=id
) {
73 if((object
=info
->local_table
[id
])!=NULL
) {
78 _CPU_ISR_Restore(level
);
82 lwp_obj
* __lwp_objmgr_getnoprotection(lwp_objinfo
*info
,u32 id
)
84 lwp_obj
*object
= NULL
;
86 if(info
->max_id
>=id
) {
87 if((object
=info
->local_table
[id
])!=NULL
) return object
;
92 lwp_obj
* __lwp_objmgr_get(lwp_objinfo
*info
,u32 id
)
94 lwp_obj
*object
= NULL
;
96 if(info
->max_id
>=id
) {
97 __lwp_thread_dispatchdisable();
98 if((object
=info
->local_table
[id
])!=NULL
) return object
;
99 __lwp_thread_dispatchenable();
104 lwp_obj
* __lwp_objmgr_allocate(lwp_objinfo
*info
)
109 _CPU_ISR_Disable(level
);
110 object
= (lwp_obj
*)__lwp_queue_getI(&info
->inactives
);
112 object
->information
= info
;
113 info
->inactives_cnt
--;
115 _CPU_ISR_Restore(level
);
120 void __lwp_objmgr_free(lwp_objinfo
*info
,lwp_obj
*object
)
124 _CPU_ISR_Disable(level
);
125 __lwp_queue_appendI(&info
->inactives
,&object
->node
);
126 object
->information
= NULL
;
127 info
->inactives_cnt
++;
128 _CPU_ISR_Restore(level
);