summaryrefslogtreecommitdiff
path: root/include/slice.h
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-03-10 09:47:58 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-03-22 10:46:47 +0100
commit64242776de86d46d914aa8f3ab6cfee68420ca6a (patch)
tree33b339b551b65557d3f15c2af6e4beaae17da631 /include/slice.h
parent7ce21703892fac7084d417d296fc2723a85e7c10 (diff)
downloadbarebox-64242776de86d46d914aa8f3ab6cfee68420ca6a.tar.gz
common: introduce bthreads, co-operative barebox threads
With the new setjmp/longjmp/initjmp support, we have all the architecture support in place to have suspendable green threads in barebox. These are expected to replace pollers and workqueues. For now we still have a differentiation between the main and secondary threads. The main thread is allowed I/O access unconditionally. If it's in a delay loop, a secondary thread running needs to be wary of not entering the same driver and doing hardware manipulation. We already have slices as mechanism to guard against this, but they aren't used as widely as needed. Preferably, in the end, threads will automatically yield until they can claim a resource (i.e. lock a mutex). Until we are there, take the same care when using bthreads as with pollers. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/slice.h')
-rw-r--r--include/slice.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/include/slice.h b/include/slice.h
index b2d65b80cd..cf684300a8 100644
--- a/include/slice.h
+++ b/include/slice.h
@@ -1,6 +1,8 @@
#ifndef __SLICE_H
#define __SLICE_H
+#include <bthread.h>
+
enum slice_action {
SLICE_ACQUIRE = 1,
SLICE_RELEASE = -1,
@@ -35,12 +37,11 @@ void command_slice_release(void);
extern int poller_active;
-#ifdef CONFIG_POLLER
-#define assert_command_context() ({ \
- WARN_ONCE(poller_active, "%s called in poller\n", __func__); \
-})
-#else
-#define assert_command_context() do { } while (0)
-#endif
+#define assert_command_context() do { \
+ WARN_ONCE(IS_ENABLED(CONFIG_POLLER) && poller_active, \
+ "%s called in poller\n", __func__); \
+ WARN_ONCE(IS_ENABLED(CONFIG_BTHREAD) && !bthread_is_main(current), \
+ "%s called in secondary bthread\n", __func__); \
+} while (0)
-#endif /* __SLICE_H */
+#endif