]> Zhao Yanbai Git Server - kernel.git/commitdiff
添加completion_t
authoracevest <zhaoyanbai@126.com>
Sat, 27 Nov 2021 03:53:27 +0000 (11:53 +0800)
committeracevest <zhaoyanbai@126.com>
Sat, 27 Nov 2021 03:53:27 +0000 (11:53 +0800)
include/completion.h [new file with mode: 0644]
kernel/completion.c [new file with mode: 0644]

diff --git a/include/completion.h b/include/completion.h
new file mode 100644 (file)
index 0000000..db085be
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: completion.h
+ *      Author: Zhao Yanbai
+ *              2021-11-27 10:58:33 Saturday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#pragma once
+
+#include <wait.h>
+
+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 (file)
index 0000000..f127fb5
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: completion.c
+ *      Author: Zhao Yanbai
+ *              2021-11-27 10:58:46 Saturday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#include <completion.h>
+#include <sched.h>
+
+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