From: acevest Date: Sat, 27 Nov 2021 03:53:27 +0000 (+0800) Subject: 添加completion_t X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/static/gitweb.js?a=commitdiff_plain;h=36a29d5fe4e7b86306699cd2ed1337495dc99474;p=kernel.git 添加completion_t --- 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