userspace: automatic resource release framework
An object's set of permissions is now also used as a form of reference counting. If an object's permission bitmap gets completely cleared, it is now possible to specify object type specific cleanup functions to be implicitly called. Currently no objects are enabled yet. Forthcoming patches will do this on a per object basis. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
e9cfc54d00
commit
337e74334c
1 changed files with 26 additions and 0 deletions
|
@ -239,6 +239,25 @@ static int thread_index_get(struct k_thread *t)
|
|||
return ko->data;
|
||||
}
|
||||
|
||||
static void unref_check(struct _k_object *ko)
|
||||
{
|
||||
for (int i = 0; i < CONFIG_MAX_THREAD_BYTES; i++) {
|
||||
if (ko->perms[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* This object has no more references. Some objects may have
|
||||
* dynamically allocated resources, require cleanup, or need to be
|
||||
* marked as uninitailized when all references are gone. What
|
||||
* specifically needs to happen depends on the object type.
|
||||
*/
|
||||
switch (ko->type) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void wordlist_cb(struct _k_object *ko, void *ctx_ptr)
|
||||
{
|
||||
struct perm_ctx *ctx = (struct perm_ctx *)ctx_ptr;
|
||||
|
@ -276,15 +295,22 @@ void _thread_perms_clear(struct _k_object *ko, struct k_thread *thread)
|
|||
int index = thread_index_get(thread);
|
||||
|
||||
if (index != -1) {
|
||||
int key = irq_lock();
|
||||
|
||||
sys_bitfield_clear_bit((mem_addr_t)&ko->perms, index);
|
||||
unref_check(ko);
|
||||
irq_unlock(key);
|
||||
}
|
||||
}
|
||||
|
||||
static void clear_perms_cb(struct _k_object *ko, void *ctx_ptr)
|
||||
{
|
||||
int id = (int)ctx_ptr;
|
||||
int key = irq_lock();
|
||||
|
||||
sys_bitfield_clear_bit((mem_addr_t)&ko->perms, id);
|
||||
unref_check(ko);
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
||||
void _thread_perms_all_clear(struct k_thread *thread)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue