1f1e2e235SFrançois Tigeot /*
2*3f2dd94aSFrançois Tigeot * Copyright (c) 2019-2020 François Tigeot <ftigeot@wolfpond.org>
3f1e2e235SFrançois Tigeot * All rights reserved.
4f1e2e235SFrançois Tigeot *
5f1e2e235SFrançois Tigeot * Redistribution and use in source and binary forms, with or without
6f1e2e235SFrançois Tigeot * modification, are permitted provided that the following conditions
7f1e2e235SFrançois Tigeot * are met:
8f1e2e235SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
9f1e2e235SFrançois Tigeot * notice unmodified, this list of conditions, and the following
10f1e2e235SFrançois Tigeot * disclaimer.
11f1e2e235SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
12f1e2e235SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
13f1e2e235SFrançois Tigeot * documentation and/or other materials provided with the distribution.
14f1e2e235SFrançois Tigeot *
15f1e2e235SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16f1e2e235SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17f1e2e235SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18f1e2e235SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19f1e2e235SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20f1e2e235SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21f1e2e235SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22f1e2e235SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23f1e2e235SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24f1e2e235SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25f1e2e235SFrançois Tigeot */
26f1e2e235SFrançois Tigeot
27f1e2e235SFrançois Tigeot #include <linux/sched.h>
28f1e2e235SFrançois Tigeot #include <linux/completion.h>
29f1e2e235SFrançois Tigeot
30f1e2e235SFrançois Tigeot void
wait_for_completion(struct completion * c)31f1e2e235SFrançois Tigeot wait_for_completion(struct completion *c)
32f1e2e235SFrançois Tigeot {
33f1e2e235SFrançois Tigeot __wait_for_completion_generic(c, MAX_SCHEDULE_TIMEOUT, 0);
34f1e2e235SFrançois Tigeot }
35*3f2dd94aSFrançois Tigeot
36*3f2dd94aSFrançois Tigeot /* This function can only return 0 or -ERESTARTSYS */
37*3f2dd94aSFrançois Tigeot int
wait_for_completion_interruptible(struct completion * c)38*3f2dd94aSFrançois Tigeot wait_for_completion_interruptible(struct completion *c)
39*3f2dd94aSFrançois Tigeot {
40*3f2dd94aSFrançois Tigeot long rv = __wait_for_completion_generic(c, MAX_SCHEDULE_TIMEOUT, PCATCH);
41*3f2dd94aSFrançois Tigeot
42*3f2dd94aSFrançois Tigeot if (rv == -ERESTARTSYS)
43*3f2dd94aSFrançois Tigeot return -ERESTARTSYS;
44*3f2dd94aSFrançois Tigeot
45*3f2dd94aSFrançois Tigeot return 0;
46*3f2dd94aSFrançois Tigeot }
47