Browse Source

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>
pull/7396/merge
Andrew Boie 7 years ago committed by Andrew Boie
parent
commit
337e74334c
  1. 26
      kernel/userspace.c

26
kernel/userspace.c

@ -239,6 +239,25 @@ static int thread_index_get(struct k_thread *t) @@ -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) @@ -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…
Cancel
Save