aboutsummaryrefslogtreecommitdiff
path: root/kernel/task/include/task/lock.h
blob: eaa661cb1b067b547bf145b6aac274884376a2c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef LOCK_H
#define LOCK_H

#include "task/shed.h"

typedef char spin_lock_t;

#define SPIN_LOCK_UNLOCKED 0

static inline void spin_lock(struct spin_lock_t* lock) {
  while(*lock != SPIN_LOCK_UNLOCKED) {yield();};
  cli();
  *lock = 1;
  sei();
}

static inline void spin_unlock(struct spin_lock_t* lock) {
  cli();
  *lock = SPIN_LOCK_UNLOCKED;
  sei();
}

#endif