1 #ifndef __LUNAIX_SPIN_H
2 #define __LUNAIX_SPIN_H
4 #include <lunaix/types.h>
11 #define DEFINE_SPINLOCK(name) \
12 struct spinlock name = { .flag = false }
14 typedef struct spinlock spinlock_t;
17 TODO we might use our own construct for atomic ops
18 But we will do itlater, currently this whole
19 kernel is on a single long thread of fate,
20 there won't be any hardware concurrent access
25 spinlock_init(spinlock_t* lock)
30 static inline bool spinlock_try_acquire(spinlock_t* lock)
36 return (lock->flag = true);
39 static inline void spinlock_acquire(spinlock_t* lock)
45 static inline void spinlock_release(spinlock_t* lock)
50 #define DEFINE_SPINLOCK_OPS(type, lock_accessor) \
51 static inline void lock(type obj) { spinlock_acquire(&obj->lock_accessor); } \
52 static inline void unlock(type obj) { spinlock_release(&obj->lock_accessor); }
54 #endif /* __LUNAIX_SPIN_H */