void init_wait_queue_head(wait_queue_head_t *wqh);
void add_wait_queue(wait_queue_head_t *head, wait_queue_t *wq);
void del_wait_queue(wait_queue_head_t *head, wait_queue_t *wq);
-void __do_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state);
+
+// prepare_to_wait 不会调用schedule
+void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state);
+
void __end_wait(wait_queue_head_t *head, wait_queue_t *wq);
void sleep_on(wait_queue_head_t *head);
void wake_up(wait_queue_head_t *head);
unsigned long schedule();
-#define __wait_event(head, condition) \
- do { \
- DECLARE_WAIT_QUEUE(__wait, current); \
- while (1) { \
- __do_wait(head, &__wait, TASK_WAIT); \
- if ((condition)) { \
- break; \
- } \
- schedule(); \
- } \
- __end_wait(head, &__wait); \
+#define __wait_event(head, condition) \
+ do { \
+ DECLARE_WAIT_QUEUE(__wait, current); \
+ while (1) { \
+ prepare_to_wait(head, &__wait, TASK_WAIT); \
+ if ((condition)) { \
+ break; \
+ } \
+ schedule(); \
+ } \
+ __end_wait(head, &__wait); \
} while (0)
#define wait_event(head, condition) \
*/
#include <sched.h>
+#include <semaphore.h>
#include <wait.h>
-#if 0
+#if 0
typedef enum {
DISK_REQ_IDENTIFY,
DISK_REQ_READ,
}
#endif
+typedef struct {
+ semaphore_t sem;
+ list_head_t list;
+} disk_request_queue_t;
+
+disk_request_queue_t disk_request_queue = {.sem = SEMAPHORE_INITIALIZER(disk_request_queue.sem, 0),
+ .list = LIST_HEAD_INIT(disk_request_queue.list)};
+
+int cnt = 0;
void disk_task_entry() {
while (1) {
- // TODO
- asm("hlt;");
- // schedule();
+ printk("fuck you: %d\n", cnt);
+ down(&disk_request_queue.sem);
+ printk("fuck me: %d\n", cnt);
+ cnt++;
}
}
irq_restore(flags);
}
-void __do_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state) {
+void prepare_to_wait(wait_queue_head_t *head, wait_queue_t *wq, unsigned int state) {
unsigned long flags;
irq_save(flags);
if (list_empty(&wq->task_list)) {