kernel: implement globally-unique object ids
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <kernel/flags.h>
|
#include <kernel/flags.h>
|
||||||
#include <kernel/locks.h>
|
#include <kernel/locks.h>
|
||||||
#include <mango/status.h>
|
|
||||||
#include <kernel/vm.h>
|
#include <kernel/vm.h>
|
||||||
|
#include <mango/status.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -67,6 +67,7 @@ struct object_type {
|
|||||||
|
|
||||||
struct object {
|
struct object {
|
||||||
uint32_t ob_magic;
|
uint32_t ob_magic;
|
||||||
|
koid_t ob_id;
|
||||||
struct object_type *ob_type;
|
struct object_type *ob_type;
|
||||||
spin_lock_t ob_lock;
|
spin_lock_t ob_lock;
|
||||||
unsigned int ob_refcount;
|
unsigned int ob_refcount;
|
||||||
|
|||||||
@@ -7,6 +7,20 @@
|
|||||||
static struct queue object_types;
|
static struct queue object_types;
|
||||||
static spin_lock_t object_types_lock = SPIN_LOCK_INIT;
|
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)
|
kern_status_t object_bootstrap(void)
|
||||||
{
|
{
|
||||||
return KERN_OK;
|
return KERN_OK;
|
||||||
@@ -53,6 +67,7 @@ struct object *object_create(struct object_type *type)
|
|||||||
struct object *obj = (struct object *)((unsigned char *)obj_buf
|
struct object *obj = (struct object *)((unsigned char *)obj_buf
|
||||||
+ type->ob_header_offset);
|
+ type->ob_header_offset);
|
||||||
|
|
||||||
|
obj->ob_id = koid_alloc();
|
||||||
obj->ob_type = type;
|
obj->ob_type = type;
|
||||||
obj->ob_lock = SPIN_LOCK_INIT;
|
obj->ob_lock = SPIN_LOCK_INIT;
|
||||||
obj->ob_magic = OBJECT_MAGIC;
|
obj->ob_magic = OBJECT_MAGIC;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ typedef uintptr_t phys_addr_t;
|
|||||||
typedef uintptr_t virt_addr_t;
|
typedef uintptr_t virt_addr_t;
|
||||||
typedef uint64_t msgid_t;
|
typedef uint64_t msgid_t;
|
||||||
typedef uint64_t off_t;
|
typedef uint64_t off_t;
|
||||||
|
typedef uint64_t koid_t;
|
||||||
typedef unsigned int tid_t;
|
typedef unsigned int tid_t;
|
||||||
typedef uint32_t kern_handle_t;
|
typedef uint32_t kern_handle_t;
|
||||||
typedef uint32_t kern_config_key_t;
|
typedef uint32_t kern_config_key_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user