--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * 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
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * 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