assert(NULL != t);
assert(t->block_size == size);
- if (t->ref_count == 0 && t->locked == 0) {
+ if (t->ref_count == 0) {
b = t;
break;
}
goto again;
}
- // 此时b->locked不一定为0
+ // 把它从free_list上删掉
+ list_del_init(&b->node);
+
+ // 虽然此时该bbuffer_t上的ref_count为0但其可能还有I/O操作没有完成
// 因为可能有的进程调用了write、read后再直接调用brelse
- // 虽然此时ref_count为0,但io操作标记的b->locked并未结束
// 所以需要在此等待其结束
- while (b->locked == 1) {
- // 此时是不用担心wake_up在这个sleep_on之前调用
- }
+ wait_completion(&b->io_done);
// 找到了
b->block = block;
b->dev = 0;
b->page = page;
b->uptodate = 0;
- b->locked = 0;
+ init_completion(&b->io_done);
list_init(&b->node);
assert(NULL != b->data);
#pragma once
#include <atomic.h>
+#include <completion.h>
#include <fs.h>
#include <mm.h>
#include <page.h>
#include <system.h>
-
typedef struct bbuffer {
uint32_t block; // block number
void *data; //
dev_t dev;
page_t *page;
list_head_t node;
+ completion_t io_done;
uint16_t block_size; // block size
uint16_t uptodate : 1;
- uint16_t locked : 1;
- uint16_t dirt : 1; // 还不支持
} bbuffer_t;
#pragma once
-#if 0
#include <wait.h>
typedef struct completion {
void init_completion(completion_t *x);
void complete(completion_t *x);
-#endif
void schedule();
-void wake_up(wait_queue_head_t *wqh);
-
extern task_union root_task;
extern void load_cr3(task_union *tsk);
// 如果s->cnt == 0 会重新调度进程
volatile void down(semaphore_t *s);
-// volatile bool try_down(semaphore_t *s);
-
// up
// 只会唤醒进程,但不会立即重新调度进程
volatile void up(semaphore_t *s);
#include <processor.h>
#include <system.h>
#include <types.h>
-#include <wait.h>
+// #include <wait.h>
enum {
TASK_UNUSED,
#include <irq.h>
#include <list.h>
-
+#include <sched.h>
union task_union;
typedef struct wait_queue_head {
* ------------------------------------------------------------------------
*/
-#if 0
#include <completion.h>
#include <sched.h>
x->done = 0;
init_wait_queue_head(&x->wait);
}
-#endif
#endif
void irq_bh_handler();
+void schedule();
__attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) {
unsigned int irq = regs->irq;