BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / e8e484f3952a9a3b7df1c3f5763a794a51ea6966 / include / nucleus

// Related

Nucleus

Barry Object locking e8e484f (3 years, 3 months ago)
diff --git a/include/nucleus/cpu.h b/include/nucleus/cpu.h
index c379cb0..8ed1f43 100644
--- a/include/nucleus/cpu.h
+++ b/include/nucleus/cpu.h
@@ -3,6 +3,8 @@
 
 #include <stdint.h>
 
+typedef unsigned int cpu_t;
+
 /* Structure for an Interrupt Frame */
 struct InterruptFrame {
 	uint32_t eip, cs, eflags;
@@ -15,8 +17,8 @@ extern uintptr_t lapicPtr, ioapicPtr;
 #define LAPIC(off)  (*((uint32_t *) ((uint32_t)  lapicPtr + (off))))
 #define IOAPIC(off) (*((uint32_t *) ((uint32_t) ioapicPtr + (off))))
 
-extern uint8_t lapicNums[];
-#define CPUID lapicNums[(uint8_t) (LAPIC(0x20) >> 24)]
+extern cpu_t lapicNums[];
+#define CPUID lapicNums[(cpu_t) (LAPIC(0x20) >> 24)]
 #define MAX_CPUS 2
 
 /* Push/pop interrupts */
diff --git a/include/nucleus/object.h b/include/nucleus/object.h
index bcd7c9a..3103736 100644
--- a/include/nucleus/object.h
+++ b/include/nucleus/object.h
@@ -1,13 +1,30 @@
 #ifndef _NUCLEUS_OBJECT_H
 #define _NUCLEUS_OBJECT_H
 
+#include <sys/types.h>
+#include <nucleus/cpu.h>
+
 typedef struct ObjectType ObjectType;
+struct Object;
 typedef struct Object Object;
+typedef struct Spinlock Spinlock;
+
+typedef struct Task Task; /* Just a pointer, no need for full definition */
+
+/* Spinlock */
+struct Spinlock {
+	char locked;
+	refcount_t usage;
+	union {
+		Task *owner;
+		cpu_t cpu;
+	};
+};
 
 /* Object Type */
 struct ObjectType {
 	unsigned int count;
-	unsigned int usage;
+	refcount_t usage;
 	void *(*new)(void);
 	void (*delete)(Object *);
 };
@@ -15,11 +32,14 @@ struct ObjectType {
 /* Object */
 struct Object {
 	ObjectType *type;
-	unsigned int usage;
+	refcount_t usage;
+	Spinlock lock;
 };
 
 void *get(void *addr);
 void put(void *addr);
 void *new(ObjectType *type);
+void lock(void *addr);
+void unlock(void *addr);
 
 #endif