diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-09-08 15:49:38 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-09-08 15:49:38 +0200 |
| commit | 4fdb0ed3a324adab8d752bdaa58b61ac445fea00 (patch) | |
| tree | d35e93c9971e903c6e3cac45acccb38c170abe9f /kernel/spinlock.c | |
| parent | 12b60a62e6d639f53d64f8a5823870070d8b467b (diff) | |
spinlocks
Diffstat (limited to 'kernel/spinlock.c')
| -rw-r--r-- | kernel/spinlock.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kernel/spinlock.c b/kernel/spinlock.c new file mode 100644 index 0000000..c7f5062 --- /dev/null +++ b/kernel/spinlock.c @@ -0,0 +1,34 @@ +#define FOOLOS_MODULE_NAME "spinlock" + +#include "lib/logger/log.h" +#include "lib/int/stdint.h" + +typedef uint8_t spinlock; + +volatile spinlock spinlocks[16]; + + +void init_spinlocks() +{ + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing spinlocks at 0x%08X ",spinlocks); + for(int i=0;i<16;i++)spinlocks[i]=0; +} + +volatile void lock_spin(int i) +{ + + spinlock *addr=spinlocks+i; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locking %d (0x%08X)",i,addr); + + while(x86_xchg(addr,1)); +} + +void lock_release(int i) +{ + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocking %d",i); + spinlock *addr=spinlocks+i; + + asm("movb $0,%0"::"m"(*addr)); + +} |
