kernel: implement globally-unique object ids
This commit is contained in:
@@ -7,6 +7,20 @@
|
||||
static struct queue object_types;
|
||||
static spin_lock_t object_types_lock = SPIN_LOCK_INIT;
|
||||
|
||||
static koid_t koid_alloc(void)
|
||||
{
|
||||
static koid_t counter = 0;
|
||||
static spin_lock_t lock = SPIN_LOCK_INIT;
|
||||
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&lock, &flags);
|
||||
koid_t result = counter;
|
||||
counter++;
|
||||
spin_unlock_irqrestore(&lock, flags);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
kern_status_t object_bootstrap(void)
|
||||
{
|
||||
return KERN_OK;
|
||||
@@ -53,6 +67,7 @@ struct object *object_create(struct object_type *type)
|
||||
struct object *obj = (struct object *)((unsigned char *)obj_buf
|
||||
+ type->ob_header_offset);
|
||||
|
||||
obj->ob_id = koid_alloc();
|
||||
obj->ob_type = type;
|
||||
obj->ob_lock = SPIN_LOCK_INIT;
|
||||
obj->ob_magic = OBJECT_MAGIC;
|
||||
|
||||
Reference in New Issue
Block a user