summaryrefslogtreecommitdiffstats
path: root/common/sched.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-06-22 10:26:12 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-25 09:30:33 +0200
commit6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69 (patch)
tree248965d7519753bb0e23105a277166416e569398 /common/sched.c
parentf866f471337e3249e0946764f09841baf73d6c9d (diff)
downloadbarebox-6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69.tar.gz
barebox-6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69.tar.xz
common: move workqueue handling from poller_call() to sched()
Workqueues are run out of poller_call, not because of a dependency, but because when they were added, poller_call was directly called from is_timeout. With the addition of bthreads, there is now a general resched() function that runs pollers and switches between bthreads. It makes sense to move workqueue handling there as well to keep scheduling matter contained in a single function. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/sched.c')
-rw-r--r--common/sched.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/common/sched.c b/common/sched.c
new file mode 100644
index 0000000000..dcf6522ac0
--- /dev/null
+++ b/common/sched.c
@@ -0,0 +1,26 @@
+/* SPDX License Identifier: GPL-2.0 */
+
+#include <bthread.h>
+#include <poller.h>
+#include <work.h>
+#include <slice.h>
+#include <sched.h>
+
+void resched(void)
+{
+ bool run_workqueues = !slice_acquired(&command_slice);
+
+ if (poller_active())
+ return;
+
+ command_slice_acquire();
+
+ if (run_workqueues)
+ wq_do_all_works();
+
+ poller_call();
+
+ command_slice_release();
+
+ bthread_reschedule();
+}