X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=task.c;h=d704d60bd850d6042c95641b5eaeb897af8d8dab;hb=b3ddf1998eea5cda9f775b84d14fba96090b8c2f;hp=d88d9076fe1e568deeeb180a31de7f682cb62a7e;hpb=b2527c29d63421702a2a2b132f174074cd950e31;p=rgblamp.git diff --git a/task.c b/task.c index d88d907..d704d60 100644 --- a/task.c +++ b/task.c @@ -36,21 +36,24 @@ task_id_t task_get(unsigned char block) nei(); if (ids) { for (unsigned char i = 0; t == -1 && i < TASK_COUNT; i++) { - if (bit_get(ids, _task_bitno)) + if (bit_get(ids, _task_bitno)) { t = _task_bitno; - _task_bitno = (_task_bitno + 1) % TASK_COUNT; + ndi(); + bit_clr(_task_ids, t); + nei(); + } + if (++_task_bitno == TASK_COUNT) + _task_bitno = 0; } } -#if 0 /* Not until we have a crystal and can wake from sleep via tmr module */ +#if 0 + /* Something like this when we have a crystal. But watch for the race of + * going to sleep when a task is posted by an ISR. + */ else SLEEP(); #endif } while (t == -1 && block == 1); - if (t >= 0) { - ndi(); - bit_clr(_task_ids, t); - nei(); - } return t; }