#ifndef __THREAD_SYNC_H #define __THREAD_SYNC_H #include "../lib/kernel/list.h" #include "../lib/stdint.h" #include "thread.h" #include "../kernel/interrupt.h" #include "../kernel/debug.h" // 信号量结构 struct semaphore { uint8_t value; struct list waiters; // 等待该信号量的线程列表 }; struct lock { struct task_struct *holder; // 持有该锁的线程 struct semaphore sem; // 用二元信号量实现锁 uint32_t holder_repeat_count; // 持有该锁的线程重入的次数 }; // 初始化信号量 void semaphore_init(struct semaphore *sem, uint8_t value); // 初始化锁 void lock_init(struct lock *lock); // 信号量 down 操作 P void semaphore_down(struct semaphore *sem); // 信号量 up 操作 V void semaphore_up(struct semaphore *sem); // 获取锁 void lock_acquire(struct lock *plock); // 释放锁 void lock_release(struct lock *plock); #endif // __THREAD_SYNC_H