From: Ahmad Fatoum <a.fatoum@pengutronix.de> To: barebox@lists.infradead.org Cc: Ahmad Fatoum <a.fatoum@pengutronix.de> Subject: [PATCH v4 5/8] bthread: implement basic Linux-like completion API Date: Tue, 22 Jun 2021 10:26:14 +0200 [thread overview] Message-ID: <20210622082617.18011-6-a.fatoum@pengutronix.de> (raw) In-Reply-To: <20210622082617.18011-1-a.fatoum@pengutronix.de> So far, completions made sense only in one direction: The main thread can wait for pollers, but the other way around didn't work. With the new bthread support, any bthread can wait for another to complete(). Wrap this up using the Linux completion API to make porting threaded code easier. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- include/linux/completion.h | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 include/linux/completion.h diff --git a/include/linux/completion.h b/include/linux/completion.h new file mode 100644 index 000000000000..e897e4f65b8b --- /dev/null +++ b/include/linux/completion.h @@ -0,0 +1,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 -- 2.29.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-22 8:27 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-22 8:26 [PATCH v4 0/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 1/8] input: virtio: poll from poller, not bthread Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 2/8] bthread: add debug print for scheduler context switches Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 3/8] common: move workqueue handling from poller_call() to sched() Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 4/8] common: bthread: schedule only in command context Ahmad Fatoum 2021-06-22 9:08 ` Ahmad Fatoum 2021-06-22 8:26 ` Ahmad Fatoum [this message] 2021-06-22 8:26 ` [PATCH v4 6/8] Documentation: devel: background-execution: update bthread docs Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 7/8] usbgadget: refactor usbgadget_register to accept array Ahmad Fatoum 2021-06-22 8:26 ` [PATCH v4 8/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum 2021-06-25 7:34 ` [PATCH v4 0/8] " Sascha Hauer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210622082617.18011-6-a.fatoum@pengutronix.de \ --to=a.fatoum@pengutronix.de \ --cc=barebox@lists.infradead.org \ --subject='Re: [PATCH v4 5/8] bthread: implement basic Linux-like completion API' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox