From 36a29d5fe4e7b86306699cd2ed1337495dc99474 Mon Sep 17 00:00:00 2001 From: acevest Date: Sat, 27 Nov 2021 11:53:27 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0completion=5Ft?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/completion.h | 25 +++++++++++++++++++++++++ kernel/completion.c | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 include/completion.h create mode 100644 kernel/completion.c diff --git a/include/completion.h b/include/completion.h new file mode 100644 index 0000000..db085be --- /dev/null +++ b/include/completion.h @@ -0,0 +1,25 @@ +/* + * ------------------------------------------------------------------------ + * File Name: completion.h + * Author: Zhao Yanbai + * 2021-11-27 10:58:33 Saturday CST + * Description: none + * ------------------------------------------------------------------------ + */ + +#pragma once + +#include + +typedef struct completion { + int done; + wait_queue_head_t wait; +} completion_t; + +#define COMPLETION_INITIALIZER(x) \ + { 0, WAIT_QUEUE_HEAD_INITIALIZER(x).wait } + +void wait_completion(completion_t *x); +void init_completion(completion_t *x); + +void complete(completion_t *x); \ No newline at end of file diff --git a/kernel/completion.c b/kernel/completion.c new file mode 100644 index 0000000..f127fb5 --- /dev/null +++ b/kernel/completion.c @@ -0,0 +1,23 @@ +/* + * ------------------------------------------------------------------------ + * File Name: completion.c + * Author: Zhao Yanbai + * 2021-11-27 10:58:46 Saturday CST + * Description: none + * ------------------------------------------------------------------------ + */ + +#include +#include + +void wait_completion(completion_t *x) { wait_event(&x->wait, (x->done == 1)); } + +void complete(completion_t *x) { + x->done = 1; + wake_up(&x->wait); +} + +void init_completion(completion_t *x) { + x->done = 0; + init_wait_queue_head(&x->wait); +} \ No newline at end of file -- 2.44.0