Rev 2089 | Rev 2183 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2089 | Rev 2109 | ||
|---|---|---|---|
| Line 114... | Line 114... | ||
| 114 | 114 | ||
| 115 | out: |
115 | out: |
| 116 | spinlock_unlock(&threads_lock); |
116 | spinlock_unlock(&threads_lock); |
| 117 | } |
117 | } |
| 118 | 118 | ||
| - | 119 | /** Interrupt sleeping thread. |
|
| - | 120 | * |
|
| - | 121 | * This routine attempts to interrupt a thread from its sleep in a waitqueue. |
|
| - | 122 | * If the thread is not found sleeping, no action is taken. |
|
| - | 123 | * |
|
| - | 124 | * @param t Thread to be interrupted. |
|
| - | 125 | */ |
|
| - | 126 | void waitq_interrupt_sleep(thread_t *t) |
|
| - | 127 | { |
|
| - | 128 | waitq_t *wq; |
|
| - | 129 | bool do_wakeup = false; |
|
| - | 130 | ipl_t ipl; |
|
| - | 131 | ||
| - | 132 | ipl = interrupts_disable(); |
|
| - | 133 | spinlock_lock(&threads_lock); |
|
| - | 134 | if (!thread_exists(t)) |
|
| - | 135 | goto out; |
|
| - | 136 | ||
| - | 137 | grab_locks: |
|
| - | 138 | spinlock_lock(&t->lock); |
|
| - | 139 | if ((wq = t->sleep_queue)) { /* assignment */ |
|
| - | 140 | if (!(t->sleep_interruptible)) { |
|
| - | 141 | /* |
|
| - | 142 | * The sleep cannot be interrupted. |
|
| - | 143 | */ |
|
| - | 144 | spinlock_unlock(&t->lock); |
|
| - | 145 | goto out; |
|
| - | 146 | } |
|
| - | 147 | ||
| - | 148 | if (!spinlock_trylock(&wq->lock)) { |
|
| - | 149 | spinlock_unlock(&t->lock); |
|
| - | 150 | goto grab_locks; /* avoid deadlock */ |
|
| - | 151 | } |
|
| - | 152 | ||
| - | 153 | if (t->timeout_pending && timeout_unregister(&t->sleep_timeout)) |
|
| - | 154 | t->timeout_pending = false; |
|
| - | 155 | ||
| - | 156 | list_remove(&t->wq_link); |
|
| - | 157 | t->saved_context = t->sleep_interruption_context; |
|
| - | 158 | do_wakeup = true; |
|
| - | 159 | t->sleep_queue = NULL; |
|
| - | 160 | spinlock_unlock(&wq->lock); |
|
| - | 161 | } |
|
| - | 162 | spinlock_unlock(&t->lock); |
|
| - | 163 | ||
| - | 164 | if (do_wakeup) |
|
| - | 165 | thread_ready(t); |
|
| - | 166 | ||
| - | 167 | out: |
|
| - | 168 | spinlock_unlock(&threads_lock); |
|
| - | 169 | interrupts_restore(ipl); |
|
| - | 170 | } |
|
| 119 | 171 | ||
| 120 | /** Sleep until either wakeup, timeout or interruption occurs |
172 | /** Sleep until either wakeup, timeout or interruption occurs |
| 121 | * |
173 | * |
| 122 | * This is a sleep implementation which allows itself to time out or to be |
174 | * This is a sleep implementation which allows itself to time out or to be |
| 123 | * interrupted from the sleep, restoring a failover context. |
175 | * interrupted from the sleep, restoring a failover context. |