GadgetSeed  0.9.6
sleepqueue.c
[詳解]
1 /** @file
2  @brief タイムアウト待ちタスクキューの操作
3 
4  GadgetSeed のタスク時間制御
5 
6  これらの関数は非タスク状態からコールされる
7 
8  @date 2011.03.17
9  @author Takashi SHUDO
10 */
11 
12 #include "sleepqueue.h"
13 #include "calltrace.h"
14 #include "timer.h"
15 #include "tkprintf.h"
16 
17 #include "task_opration.h"
18 #include "queue_opration.h"
19 
20 //#define DEBUGKBITS 0x01
21 #include "dkprintf.h"
22 
23 
24 struct tcb_queue timeout_wait_queue_head; ///< タイムアウト待ちタスクキュー
25 
26 /* NOT API
27  @brief スリープ中タスクキューにTCBを追加する
28 
29  タイムアウト時間が早い順(tcb->wup_time が小さい)に追加
30 */
31 void sleepqueue_add(struct st_tcb *tcb, unsigned int sleep_time,
32  unsigned int now_time)
33 {
34  tcb->wup_time = now_time + sleep_time; // 起床予定時間
35 
36  DKFPRINTF(0x01, "Sleep PID=%d \"%s\" %ld\n", tcb->id, tcb->name, sleep_time);
37  DKPRINTF(0x01, " now = %ld, wup = %ld\n", now_time, tcb->wup_time);
38  //tkprintf("IN :");
39  //print_tcb_queue(&timeout_wait_queue_head);
40 
41  /*
42  タイムアウト時間の早いタスクの順に追加する
43  */
44  if(check_queue(&timeout_wait_queue_head.queue) == 0) {
45  DKPRINTF(0x02, "TQ 0 top\n");
46  insert_queue(&timeout_wait_queue_head.queue,
47  &(tcb->timer_list.queue));
48  } else {
49  struct st_queue *tmp = timeout_wait_queue_head.queue.next;
50  while(tmp->next != timeout_wait_queue_head.queue.next) {
51  DKPRINTF(0x02, "T=%ld\n", ((struct tcb_queue *)tmp)->tcb->wup_time);
52  if(tcb->wup_time <
53  ((struct tcb_queue *)tmp)->tcb->wup_time) {
54  // キューに追加
55  DKPRINTF(0x02, "TQ add\n");
56  add_queue(tmp, &(tcb->timer_list.queue));
57  goto end;
58  }
59 
60  if(tmp == tmp->next) {
61  SYSERR_PRINT("timeout_wait_queue broken? (%p)\n", tmp);
62  disp_regs(run_task->sp);
63  print_task();
64  print_stack();
65  //print_queues();
66  print_calltrace();
67  while(1);
68  }
69  tmp = tmp->next;
70  }
71 
72  if(tcb->wup_time <
73  ((struct tcb_queue *)timeout_wait_queue_head.queue.next)
74  ->tcb->wup_time) {
75  DKPRINTF(0x02, "TQ ? add\n");
76  insert_queue(&timeout_wait_queue_head.queue,
77  &(tcb->timer_list.queue));
78  } else {
79  DKPRINTF(0x02, "TQ tail\n");
80  add_queue(&timeout_wait_queue_head.queue,
81  &(tcb->timer_list.queue));
82  }
83  }
84 
85  //tkprintf("OUT :");
86  //print_struct tcb_queue(&timeout_wait_queue_head);
87 end:
88  return;
89 }
90 
91 /* NOT API
92  @brief スリープ時間がタイムアウトしたTCBを返す
93 */
94 struct st_tcb *sleepqueue_schedule(unsigned long long now_time)
95 {
96  struct st_tcb *wup_tcb = 0;
97 
98  DKFPRINTF(0x01, "now_time = %ld\n", now_time);
99 
100  if(check_queue(&timeout_wait_queue_head.queue) == 0) {
101  return (struct st_tcb *)0;
102  } else {
103  if(now_time >= ((struct tcb_queue *)(timeout_wait_queue_head.queue.next))->tcb->wup_time) {
104  wup_tcb = ((struct tcb_queue *)del_next_queue(&timeout_wait_queue_head.queue))->tcb;
105  } else {
106  return (struct st_tcb *)0;
107  }
108  }
109 
110 #ifdef DEBUGKBITS
111  if(wup_tcb != 0) {
112  DKPRINTF(0x01, "Sleep Timeout wakeup PID=%d \"%s\"\n", wup_tcb->id,
113  wup_tcb->name);
114  DKPRINTF(0x02, " now = %ld, wup = %ld\n", now_time, wup_tcb->wup_time);
115  }
116 #endif
117 
118  return wup_tcb;
119 }
タスクキュー
Definition: tcb.h:27
struct tcb_queue timer_list
タイムアウト待ちキュー
Definition: tcb.h:35
struct st_queue queue
キュー
Definition: tcb.h:28
スリープタスク制御
カーネルタイマ
キュー構造
Definition: queue.h:13
カーネル用機能限定printf
char name[TASK_NAME_LEN+1]
タスク名
Definition: tcb.h:39
void * sp
スタックポインタ
Definition: tcb.h:40
unsigned int wup_time
スリープタイムアウト時間
Definition: tcb.h:49
キュー操作
デバッグ用システムコールトレース
struct tcb_queue timeout_wait_queue_head
タイムアウト待ちタスクキュー
Definition: sleepqueue.c:24
タスク操作
カーネル、ドライバ(非タスク)デバッグ用マクロ
int id
タスクID
Definition: tcb.h:38
タスクコンテキスト
Definition: tcb.h:32