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