Thread wrapper. * * This wrapper is provided to ensure that every thread makes a call to * thread_exit() when its implementing function returns. * * interrupts_disable() is assumed. * */
| 117 | * |
| 118 | */ |
| 119 | static void cushion(void) |
| 120 | { |
| 121 | void (*f)(void *) = THREAD->thread_code; |
| 122 | void *arg = THREAD->thread_arg; |
| 123 | THREAD->last_cycle = get_cycle(); |
| 124 | |
| 125 | /* This is where each thread wakes up after its creation */ |
| 126 | irq_spinlock_unlock(&THREAD->lock, false); |
| 127 | interrupts_enable(); |
| 128 | |
| 129 | f(arg); |
| 130 | |
| 131 | /* Accumulate accounting to the task */ |
| 132 | irq_spinlock_lock(&THREAD->lock, true); |
| 133 | if (!THREAD->uncounted) { |
| 134 | thread_update_accounting(true); |
| 135 | uint64_t ucycles = THREAD->ucycles; |
| 136 | THREAD->ucycles = 0; |
| 137 | uint64_t kcycles = THREAD->kcycles; |
| 138 | THREAD->kcycles = 0; |
| 139 | |
| 140 | irq_spinlock_pass(&THREAD->lock, &TASK->lock); |
| 141 | TASK->ucycles += ucycles; |
| 142 | TASK->kcycles += kcycles; |
| 143 | irq_spinlock_unlock(&TASK->lock, true); |
| 144 | } else |
| 145 | irq_spinlock_unlock(&THREAD->lock, true); |
| 146 | |
| 147 | thread_exit(); |
| 148 | |
| 149 | /* Not reached */ |
| 150 | } |
| 151 | |
| 152 | /** Initialization and allocation for thread_t structure |
| 153 | * |
nothing calls this directly
no test coverage detected