aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-08-08 15:21:33 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-08-09 12:55:44 -0400
commita38082016d5487a9003c4618f8bdde8c3b32a204 (patch)
tree19ad888c8451ccd19bb615dbdabbf164ae13e84a /src
parent156e9b7556190b2c22fa7013f47756e6141cdc81 (diff)
downloadkutter-a38082016d5487a9003c4618f8bdde8c3b32a204.tar.gz
kutter-a38082016d5487a9003c4618f8bdde8c3b32a204.tar.xz
kutter-a38082016d5487a9003c4618f8bdde8c3b32a204.zip
sched: Reduce the amount of time irqs are disabled in sleep check
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/sched.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/sched.c b/src/sched.c
index 6cafa999..9aa5aea2 100644
--- a/src/sched.c
+++ b/src/sched.c
@@ -181,20 +181,24 @@ sched_timer_reset(void)
* Tasks
****************************************************************/
-static int_fast8_t tasks_pending;
+static int_fast8_t tasks_status;
+
+#define TS_IDLE -1
+#define TS_REQUESTED 0
+#define TS_RUNNING 1
// Note that at least one task is ready to run
void
sched_wake_tasks(void)
{
- tasks_pending = 0;
+ tasks_status = TS_REQUESTED;
}
// Check if tasks need to be run
uint8_t
sched_tasks_busy(void)
{
- return tasks_pending >= 0;
+ return tasks_status >= TS_REQUESTED;
}
// Note that a task is ready to run
@@ -222,21 +226,20 @@ run_tasks(void)
uint32_t start = timer_read_time();
for (;;) {
// Check if can sleep
- irq_disable();
- if (!tasks_pending) {
- // Tasks are busy - don't sleep
- irq_enable();
- } else {
- // Sleep processor (only run timers) until tasks pending
- tasks_pending = -1;
- uint32_t sleep_start = timer_read_time();
- do {
- irq_wait();
- } while (!sched_tasks_busy());
+ if (tasks_status != TS_REQUESTED) {
+ start -= timer_read_time();
+ irq_disable();
+ if (tasks_status != TS_REQUESTED) {
+ // Sleep processor (only run timers) until tasks woken
+ tasks_status = TS_IDLE;
+ do {
+ irq_wait();
+ } while (tasks_status != TS_REQUESTED);
+ }
irq_enable();
- start += timer_read_time() - sleep_start;
+ start += timer_read_time();
}
- tasks_pending = 1;
+ tasks_status = TS_RUNNING;
// Run all tasks
extern void ctr_run_taskfuncs(void);