|
Revision 2025, 0.6 KB
(checked in by mwhitworth, 3 years ago)
|
|
Add beginning of completion API.
|
| Line | |
|---|
| 1 | #include <completion.h> |
|---|
| 2 | #include <module.h> |
|---|
| 3 | #include <task.h> |
|---|
| 4 | #include <wait.h> |
|---|
| 5 | |
|---|
| 6 | inline int CompletionIsDone(struct Completion* comp) |
|---|
| 7 | { |
|---|
| 8 | return comp->done; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | SYMBOL_EXPORT(CompletionIsDone); |
|---|
| 12 | |
|---|
| 13 | int CompletionWaitEx(struct Completion* comp, int timeout) |
|---|
| 14 | { |
|---|
| 15 | if (!comp->done) |
|---|
| 16 | { |
|---|
| 17 | |
|---|
| 18 | WAIT_ON(&comp->waitQueue, CompletionIsDone(comp)); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | comp->done--; |
|---|
| 22 | |
|---|
| 23 | return 0; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | SYMBOL_EXPORT(CompletionWaitEx); |
|---|
| 27 | |
|---|
| 28 | void CompletionDone(struct Completion* comp) |
|---|
| 29 | { |
|---|
| 30 | DWORD flags; |
|---|
| 31 | |
|---|
| 32 | IrqSaveFlags(flags); |
|---|
| 33 | |
|---|
| 34 | comp->done++; |
|---|
| 35 | WakeUpAll(&comp->waitQueue); |
|---|
| 36 | |
|---|
| 37 | IrqRestoreFlags(flags); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | SYMBOL_EXPORT(CompletionDone); |
|---|