BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / e8e484f3952a9a3b7df1c3f5763a794a51ea6966 / include / nucleus / object.h

// Related

Nucleus

Barry Object locking e8e484f (3 years, 3 months ago)
#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;
	refcount_t usage;
	void *(*new)(void);
	void (*delete)(Object *);
};

/* Object */
struct Object {
	ObjectType *type;
	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