Skip to content

Commit e467f40

Browse files
committed
设定任务优先级(1)
1 parent 70f8264 commit e467f40

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

16_day/bootpack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void HariMain(void)
7575
task_b[i]->tss.fs = 1 * 8;
7676
task_b[i]->tss.gs = 1 * 8;
7777
*((int *) (task_b[i]->tss.esp + 4)) = (int) sht_win_b[i];
78-
task_run(task_b[i]);
78+
task_run(task_b[i], i + 1);
7979
}
8080

8181
/* sht_win */

16_day/bootpack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ struct TSS32 {
196196
};
197197
struct TASK {
198198
int sel, flags; /* sel用来存放GDT的编号*/
199+
int priority; /* 优先级 */
199200
struct TSS32 tss;
200201
};
201202
struct TASKCTL {
@@ -207,6 +208,6 @@ struct TASKCTL {
207208
extern struct TIMER *task_timer;
208209
struct TASK *task_init(struct MEMMAN *memman);
209210
struct TASK *task_alloc(void);
210-
void task_run(struct TASK *task);
211+
void task_run(struct TASK *task, int priority);
211212
void task_switch(void);
212213
void task_sleep(struct TASK *task);

16_day/fifo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void fifo32_init(struct FIFO32 *fifo, int size, int *buf, struct TASK *task)
1818
}
1919

2020
int fifo32_put(struct FIFO32 *fifo, int data)
21-
/*给FIFO发送数据并储存在FIFO中*/
21+
/*向FIFO写入数据并累积起来*/
2222
{
2323
if (fifo->free == 0) {
2424
/*没有空余空间,溢出*/
@@ -33,7 +33,7 @@ int fifo32_put(struct FIFO32 *fifo, int data)
3333
fifo->free--;
3434
if (fifo->task != 0) {
3535
if (fifo->task->flags != 2) { /*如果任务处于休眠状态*/
36-
task_run(fifo->task); /*将任务唤醒*/
36+
task_run(fifo->task, 0); /*将任务唤醒*/
3737
}
3838
}
3939
return 0;

16_day/mtask.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ struct TASK *task_init(struct MEMMAN *memman)
2020

2121
task = task_alloc();
2222
task->flags = 2; /*活动中标志*/
23+
task->priority = 2; /* 0.02秒 */
2324
taskctl->running = 1;
2425
taskctl->now = 0;
2526
taskctl->tasks[0] = task;
2627
load_tr(task->sel);
2728
task_timer = timer_alloc();
28-
timer_settime(task_timer, 2);
29+
timer_settime(task_timer, task->priority);
2930
return task;
3031
}
3132

@@ -57,23 +58,29 @@ struct TASK *task_alloc(void)
5758
return 0; /*全部正在使用*/
5859
}
5960

60-
void task_run(struct TASK *task)
61+
void task_run(struct TASK *task, int priority)
6162
{
62-
task->flags = 2; /*活动中标志*/
63-
taskctl->tasks[taskctl->running] = task;
64-
taskctl->running++;
63+
if (priority > 0) {
64+
task->priority = priority;
65+
}
66+
if (task->flags != 2) {
67+
task->flags = 2; /*活动中标志*/
68+
taskctl->tasks[taskctl->running] = task;
69+
taskctl->running++;
70+
}
6571
return;
6672
}
6773

68-
void task_switch(void)
69-
{
70-
timer_settime(task_timer, 2);
74+
void task_switch(void){
75+
struct TASK *task;
76+
taskctl->now++;
77+
if (taskctl->now == taskctl->running) {
78+
taskctl->now = 0;
79+
}
80+
task = taskctl->tasks[taskctl->now];
81+
timer_settime(task_timer, task->priority);
7182
if (taskctl->running >= 2) {
72-
taskctl->now++;
73-
if (taskctl->now == taskctl->running) {
74-
taskctl->now = 0;
75-
}
76-
farjmp(0, taskctl->tasks[taskctl->now]->sel);
83+
farjmp(0, task->sel);
7784
}
7885
return;
7986
}

0 commit comments

Comments
 (0)