1 2 #ifndef __SPINLOCK_H__ 3 #define __SPINLOCK_H__ 4 5 #include <stdint.h> 6 7 #include <sys/cdefs.h> 8 #include <sys/queue.h> 9 10 #define SPINLOCK_NAMELEN 32 11 12 #define SPINLOCK_TYPE_NORMAL 1 13 #define SPINLOCK_TYPE_RECURSIVE 2 14 15 typedef struct Spinlock 16 { 17 volatile uint64_t lock; 18 uint64_t cpu; 19 uint64_t count; 20 uint64_t rCount; 21 uint64_t lockTime; 22 uint64_t waitTime; 23 uint64_t lockedTSC; 24 uint64_t type; 25 char name[SPINLOCK_NAMELEN]; 26 LIST_ENTRY(Spinlock) lockList; 27 TAILQ_ENTRY(Spinlock) lockStack; 28 } __LOCKABLE Spinlock; 29 30 void Critical_Init(); 31 void Critical_Enter(); 32 void Critical_Exit(); 33 uint32_t Critical_Level(); 34 35 void Spinlock_EarlyInit(); 36 void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type); 37 void Spinlock_Destroy(Spinlock *lock); 38 void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock); 39 void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock); 40 bool Spinlock_IsHeld(Spinlock *lock) __LOCK_EX_ASSERT(*lock); 41 42 #endif /* __SPINLOCK_H__ */ 43 44