Newer
Older
Scratch / lockwasher / src / sys / include / ubixos / spinlock.h
@Christopher W. Olsen Christopher W. Olsen on 25 Oct 2019 561 bytes Scratch
#ifndef _SPINLOCK_H
#define _SPINLOCK_H

enum spinlock_action 
{ 
	SPIN_RETURN, 
	SPIN_HLT, 
	SPIN_SCHED, 
	SPIN_LOOP 
};

typedef struct 
{
	int count; // for recursion.
	int owner;

	int ticket[16]; // allow up to 16 CPUs.
	int choiceInProgress[16];
	
	int deleteInProgress;
	
} spinlock_t;

enum spinlock_returns 
{ 
	SPINLOCK_SUCCESS, 
	SPINLOCK_FAIL_DELETING
};

spinlock_t * spinlockCreate();
void spinlockInit(spinlock_t *);
void spinlockDelete(spinlock_t *);

int spinlockLock(spinlock_t *, int , int);
int spinlockUnlock(spinlock_t *, int);

#endif