root/Whitix/trunk/kernel/wait.c
| Revision 1766, 2.2 KB (checked in by mwhitworth, 3 years ago) |
|---|
| Line | |
|---|---|
| 1 | /* This file is part of Whitix. |
| 2 | * |
| 3 | * Whitix is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * Whitix is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with Whitix; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <module.h> |
| 20 | #include <sched.h> |
| 21 | #include <task.h> |
| 22 | #include <wait.h> |
| 23 | |
| 24 | /*********************************************************************** |
| 25 | * |
| 26 | * FUNCTION: WakeUpCommon |
| 27 | * |
| 28 | * DESCRIPTION: Wake up all threads waiting on a waitqueue. |
| 29 | * |
| 30 | * PARAMETERS: waitQueue - wait queue in question. |
| 31 | * |
| 32 | * RETURNS: Nothing. |
| 33 | * |
| 34 | ***********************************************************************/ |
| 35 | |
| 36 | void WakeUpCommon(WaitQueue* waitQueue, int number) |
| 37 | { |
| 38 | struct WaitQueueEntry* curr, *curr2; |
| 39 | |
| 40 | /* No point if it's empty */ |
| 41 | if (ListEmpty(&waitQueue->list)) |
| 42 | return; |
| 43 | |
| 44 | ListForEachEntrySafe(curr, curr2, &waitQueue->list, next) |
| 45 | { |
| 46 | ListRemoveInit(&curr->next); |
| 47 | ThrResumeThread(curr->thread); |
| 48 | |
| 49 | if (!--number) |
| 50 | return; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | SYMBOL_EXPORT(WakeUpCommon); |
| 55 | |
| 56 | void _WakeUp(WaitQueue* waitQueue, int number) |
| 57 | { |
| 58 | DWORD flags; |
| 59 | IrqSaveFlags(flags); |
| 60 | WakeUpCommon(waitQueue, number); |
| 61 | IrqRestoreFlags(flags); |
| 62 | } |
| 63 | |
| 64 | SYMBOL_EXPORT(_WakeUp); |
| 65 | |
| 66 | void WaitPrepareWait(WaitQueue* waitQueue, struct WaitQueueEntry* waitEntry) |
| 67 | { |
| 68 | SpinLockIrq(&waitQueue->spinLock); |
| 69 | |
| 70 | if (ListEmpty(&waitEntry->next)) |
| 71 | WaitAddToQueue(waitQueue, waitEntry); |
| 72 | |
| 73 | SpinUnlockIrq(&waitQueue->spinLock); |
| 74 | } |
| 75 | |
| 76 | SYMBOL_EXPORT(WaitPrepareWait); |
| 77 | |
| 78 | void ThrEndWait(struct Thread* thread); |
| 79 | |
| 80 | void WaitFinishWait(WaitQueue* waitQueue, struct WaitQueueEntry* waitEntry) |
| 81 | { |
| 82 | if (!ListEmpty(&waitEntry->next)) |
| 83 | { |
| 84 | SpinLockIrq(&waitQueue->spinLock); |
| 85 | ListRemoveInit(&waitEntry->next); |
| 86 | SpinUnlockIrq(&waitQueue->spinLock); |
| 87 | } |
| 88 | |
| 89 | ThrEndWait(currThread); |
| 90 | } |
| 91 | |
| 92 | SYMBOL_EXPORT(WaitFinishWait); |
Note: See TracBrowser
for help on using the browser.
