summaryrefslogtreecommitdiffstats
path: root/include/linux/completion.h
blob: e897e4f65b8b1cfb44c2d718d677e9566de6cc58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * (C) Copyright 2021 Ahmad Fatoum
 *
 * Async wait-for-completion handler data structures.
 * This allows one bthread to wait for another
 */

#ifndef __LINUX_COMPLETION_H
#define __LINUX_COMPLETION_H

#include <stdio.h>
#include <errno.h>
#include <bthread.h>

struct completion {
	unsigned int done;
};

static inline void init_completion(struct completion *x)
{
	x->done = 0;
}

static inline void reinit_completion(struct completion *x)
{
	x->done = 0;
}

static inline int wait_for_completion_interruptible(struct completion *x)
{
	while (!x->done) {
		switch (bthread_should_stop()) {
		case -EINTR:
			if (!ctrlc())
				continue;
		case 1:
			return -ERESTARTSYS;
		}
	}

	return 0;
}

static inline bool completion_done(struct completion *x)
{
	return x->done;
}

static inline void complete(struct completion *x)
{
	x->done = 1;
}

#endif