tkernel_2/kernel/tkernel/src/wait.h | bare source | permlink (0.05 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T-Kernel 2.0 Software Package 4: * 5: * Copyright 2011 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17. 10: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * wait.h (T-Kernel/OS) 17: * Definition of Common Routine for Synchronization 18: */ 19: 20: #ifndef _WAIT_ 21: #define _WAIT_ 22: 23: #include <sys/queue.h> 24: #include "timer.h" 25: #include "task.h" 26: 27: /* 28: * Release wait state of the task. 29: * Remove the task from the timer queue and the wait queue, then 30: * update the task state. 'wait_release_ok' sends E_OK to the 31: * wait released task. 32: * 'wait_release_ok_recd' is normal wait release as well as 33: * 'wait_release_ok', but it sends 'ercd' to the wait released task. 34: * It needs to be ercd >= 0. 35: * 'wait_release_ng' sends 'ercd' to the wait released task. Use for 36: * releasing the forced wait task. It needs to be ercd < 0. 37: * 'wait_release_tmout' don't remove from the timer queue. Use for 38: * time out processing. 39: */ 40: IMPORT void wait_release_ok( TCB *tcb ); 41: IMPORT void wait_release_ok_ercd( TCB *tcb, ER ercd ); 42: IMPORT void wait_release_ng( TCB *tcb, ER ercd ); 43: IMPORT void wait_release_tmout( TCB *tcb ); 44: 45: /* 46: * Cancel task wait state. 47: * Remove the task from the timer queue and the wait queue. 48: * Do not update the task state. 49: */ 50: Inline void wait_cancel( TCB *tcb ) 51: { 52: timer_delete(&tcb->wtmeb); 53: QueRemove(&tcb->tskque); 54: } 55: 56: /* 57: * Change the active task to wait state and connect to the 58: * timer event queue. 59: */ 60: IMPORT void make_wait( TMO_U tmout, ATR atr ); 61: IMPORT void make_wait_reltim( RELTIM_U tmout, ATR atr ); 62: 63: /* 64: * Release wait state of all tasks connected to the wait queue, 65: * and set it as E_DLT error. 66: * Use when synchronization between tasks or communication 67: * object is deleted. 68: */ 69: IMPORT void wait_delete( QUEUE *wait_queue ); 70: 71: /* 72: * Get ID of the head task in the wait queue. 73: */ 74: IMPORT ID wait_tskid( QUEUE *wait_queue ); 75: 76: /* 77: * Connect the task to the prioritized wait queue. 78: */ 79: Inline void queue_insert_tpri( TCB *tcb, QUEUE *queue ) 80: { 81: QUEUE *q; 82: QUEUE *start, *end; 83: UB val; 84: W offset; 85: 86: start = end = queue; 87: val = tcb->priority; 88: offset = offsetof(TCB,priority); 89: 90: for ( q = start->next; q != end; q = q->next ) { 91: if ( *(UB*)((VB*)q + offset) > val ) { 92: break; 93: } 94: } 95: 96: QueInsert(&tcb->tskque, q); 97: } 98: 99: /* 100: * Common part of control block 101: * For synchronization between tasks and communication object, 102: * the head part of control block is common. The followings are 103: * common routines. 104: * Define common part as GCB (generic control block) type. 105: * Cannot use these routines if an object has multiple wait queues 106: * and when it operates a wait queue after the first one. 107: * Cannot use these routines if TA_TPRI, TA_NODISWAI object attribute 108: * bits are used for other purposes since these bits are checked. 109: */ 110: typedef struct generic_control_block { 111: QUEUE wait_queue; /* Wait queue */ 112: ID objid; /* Object ID */ 113: void *exinf; /* Extended information */ 114: ATR objatr; /* Object attribute */ 115: /* It is OK to have another field after this point, */ 116: /* but it is not used for generic operation routines. */ 117: } GCB ; 118: 119: /* 120: * Change the active task to wait state and connect to the timer event 121: * queue and the object wait queue. Also, set 'wid' in 'ctxtsk'. 122: */ 123: IMPORT void gcb_make_wait( GCB *gcb, TMO_U tmout ); 124: 125: /* 126: * Check wait disable 127: */ 128: Inline BOOL is_diswai( GCB *gcb, TCB *tcb, UINT tskwait ) 129: { 130: return ( (tcb->waitmask & tskwait) != 0 131: && (gcb->objatr & TA_NODISWAI) == 0 ); 132: } 133: 134: /* 135: * gcb_make_wait with wait disable check function. 136: */ 137: IMPORT void gcb_make_wait_with_diswai( GCB *gcb, TMO_U tmout ); 138: 139: /* 140: * When the task priority changes, adjust the task position in the 141: * wait queue. 142: * Do nothing if TA_TPRI is not specified in the object attribute. 143: */ 144: IMPORT void gcb_change_priority( GCB *gcb, TCB *tcb ); 145: 146: /* 147: * Search the first task of wait queue include "tcb" with target. 148: * (Not insert "tcb" into wait queue.) 149: * 150: */ 151: IMPORT TCB* gcb_top_of_wait_queue( GCB *gcb, TCB *tcb ); 152: 153: #endif /* _WAIT_ */