diff --git a/examples/apps/cli/main.c b/examples/apps/cli/main.c index 6a5428e03..6400f03a7 100644 --- a/examples/apps/cli/main.c +++ b/examples/apps/cli/main.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) while (1) { - otProcessNextTasklet(sInstance); + otProcessQueuedTasklets(sInstance); PlatformProcessDrivers(sInstance); } diff --git a/examples/apps/ncp/main.c b/examples/apps/ncp/main.c index 6f4169b07..a5496e0e0 100644 --- a/examples/apps/ncp/main.c +++ b/examples/apps/ncp/main.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) while (1) { - otProcessNextTasklet(sInstance); + otProcessQueuedTasklets(sInstance); PlatformProcessDrivers(sInstance); } diff --git a/include/openthread.h b/include/openthread.h index 6450736c1..8261d51ed 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -114,11 +114,11 @@ extern "C" { */ /** - * Run the next queued tasklet in OpenThread. + * Run all queued OpenThread tasklets at the time this is called. * * @param[in] aInstance A pointer to an OpenThread instance. */ -void otProcessNextTasklet(otInstance *aInstance); +void otProcessQueuedTasklets(otInstance *aInstance); /** * Indicates whether or not OpenThread has tasklets pending. diff --git a/src/core/common/tasklet.cpp b/src/core/common/tasklet.cpp index aa4e1f8b3..dbcdf6314 100644 --- a/src/core/common/tasklet.cpp +++ b/src/core/common/tasklet.cpp @@ -103,15 +103,20 @@ bool TaskletScheduler::AreTaskletsPending(void) return mHead != NULL; } -void TaskletScheduler::RunNextTasklet(void) +void TaskletScheduler::ProcessQueuedTasklets(void) { - Tasklet *task; + Tasklet *tail = mTail; + Tasklet *cur; - task = PopTasklet(); - - if (task != NULL) + while ((cur = PopTasklet()) != NULL) { - task->RunTask(); + cur->RunTask(); + + // only process tasklets that were queued at the time this method was called + if (cur == tail) + { + break; + } } } diff --git a/src/core/common/tasklet.hpp b/src/core/common/tasklet.hpp index 3e283b574..c5cd44412 100644 --- a/src/core/common/tasklet.hpp +++ b/src/core/common/tasklet.hpp @@ -125,10 +125,10 @@ public: bool AreTaskletsPending(void); /** - * This method runs the next tasklet. + * This method processes all tasklets queued when this is called. * */ - void RunNextTasklet(void); + void ProcessQueuedTasklets(void); private: Tasklet *PopTasklet(void); diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 799998dbf..c940b824c 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -98,9 +98,9 @@ static void *sEnergyScanCallbackContext = NULL; static otHandleActiveScanResult sDiscoverCallback = NULL; static void *sDiscoverCallbackContext = NULL; -void otProcessNextTasklet(otInstance *) +void otProcessQueuedTasklets(otInstance *) { - sIp6->mTaskletScheduler.RunNextTasklet(); + sIp6->mTaskletScheduler.ProcessQueuedTasklets(); } bool otAreTaskletsPending(otInstance *)