From 77bc491c5696fd1f3f46cf4d4c80eacbc4988c1e Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 11 Jan 2017 13:43:35 -0800 Subject: [PATCH] Tasklet API cleanup. --- etc/visual-studio/libopenthread.vcxproj | 1 + .../libopenthread.vcxproj.filters | 3 + etc/visual-studio/libopenthread_k.vcxproj | 1 + .../libopenthread_k.vcxproj.filters | 3 + examples/apps/cli/main.c | 6 +- examples/apps/ncp/main.c | 6 +- .../drivers/windows/otLwf/eventprocessing.c | 2 +- examples/drivers/windows/otLwf/precomp.h | 2 +- examples/drivers/windows/otLwf/thread.c | 4 +- examples/platforms/posix/platform.c | 4 +- include/Makefile.am | 1 - include/openthread.h | 2 + include/openthread/Makefile.am | 1 + .../tasklet.h} | 10 +-- src/core/Makefile.am | 1 + src/core/api/tasklet_api.cpp | 61 +++++++++++++++++++ src/core/common/tasklet.cpp | 4 +- src/core/common/tasklet.hpp | 3 +- src/core/openthread.cpp | 13 ---- tests/unit/test_diag.cpp | 4 +- tests/unit/test_fuzz.cpp | 2 +- tests/unit/test_platform.cpp | 2 +- tests/unit/test_platform.h | 2 +- 23 files changed, 98 insertions(+), 40 deletions(-) rename include/{openthread-tasklet.h => openthread/tasklet.h} (90%) create mode 100644 src/core/api/tasklet_api.cpp diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index 38f7f4c01..fb25856c4 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -56,6 +56,7 @@ + diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index a73a75dff..7830899bc 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -63,6 +63,9 @@ Source Files\api + + Source Files\api + Source Files\coap diff --git a/etc/visual-studio/libopenthread_k.vcxproj b/etc/visual-studio/libopenthread_k.vcxproj index d20fca6c0..13fe8e6b9 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj +++ b/etc/visual-studio/libopenthread_k.vcxproj @@ -64,6 +64,7 @@ + diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index 89e658f76..563d77688 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -63,6 +63,9 @@ Source Files\api + + Source Files\api + Source Files\coap diff --git a/examples/apps/cli/main.c b/examples/apps/cli/main.c index 78c3d51ce..b55e66b65 100644 --- a/examples/apps/cli/main.c +++ b/examples/apps/cli/main.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ void otPlatFree(void *aPtr) } #endif -void otSignalTaskletPending(otInstance *aInstance) +void otTaskletsSignalPending(otInstance *aInstance) { (void)aInstance; } @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) while (1) { - otProcessQueuedTasklets(sInstance); + otTaskletsProcess(sInstance); PlatformProcessDrivers(sInstance); } diff --git a/examples/apps/ncp/main.c b/examples/apps/ncp/main.c index d33ed009b..0ca56eff5 100644 --- a/examples/apps/ncp/main.c +++ b/examples/apps/ncp/main.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ void otPlatFree(void *aPtr) } #endif -void otSignalTaskletPending(otInstance *aInstance) +void otTaskletsSignalPending(otInstance *aInstance) { (void)aInstance; } @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) while (1) { - otProcessQueuedTasklets(sInstance); + otTaskletsProcess(sInstance); PlatformProcessDrivers(sInstance); } diff --git a/examples/drivers/windows/otLwf/eventprocessing.c b/examples/drivers/windows/otLwf/eventprocessing.c index 917fc6b45..b46ff4ef1 100644 --- a/examples/drivers/windows/otLwf/eventprocessing.c +++ b/examples/drivers/windows/otLwf/eventprocessing.c @@ -1032,7 +1032,7 @@ otLwfEventWorkerThread( else if (status == STATUS_WAIT_0 + 4) // EventWorkerThreadProcessTasklets fired { // Process all tasklets that were indicated to us from OpenThread - otProcessQueuedTasklets(pFilter->otCtx); + otTaskletsProcess(pFilter->otCtx); } else if (status == STATUS_WAIT_0 + 5) // SendNetBufferListComplete fired { diff --git a/examples/drivers/windows/otLwf/precomp.h b/examples/drivers/windows/otLwf/precomp.h index d1ba9c86f..8b774f698 100644 --- a/examples/drivers/windows/otLwf/precomp.h +++ b/examples/drivers/windows/otLwf/precomp.h @@ -64,7 +64,7 @@ RtlCopyBufferToMdl( #include #include #include -#include +#include #include #include #include diff --git a/examples/drivers/windows/otLwf/thread.c b/examples/drivers/windows/otLwf/thread.c index 48d37f120..337cd4ee6 100644 --- a/examples/drivers/windows/otLwf/thread.c +++ b/examples/drivers/windows/otLwf/thread.c @@ -284,9 +284,9 @@ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint1 return kThreadError_None; } -void otSignalTaskletPending(_In_ otInstance *otCtx) +void otTaskletsSignalPending(_In_ otInstance *otCtx) { - LogVerbose(DRIVER_DEFAULT, "otSignalTaskletPending"); + LogVerbose(DRIVER_DEFAULT, "otTaskletsSignalPending"); PMS_FILTER pFilter = otCtxToFilter(otCtx); otLwfEventProcessingIndicateNewTasklet(pFilter); } diff --git a/examples/platforms/posix/platform.c b/examples/platforms/posix/platform.c index c5fccc3e5..308e9ab59 100644 --- a/examples/platforms/posix/platform.c +++ b/examples/platforms/posix/platform.c @@ -47,7 +47,7 @@ #endif #include -#include +#include #include uint32_t NODE_ID = 1; @@ -97,7 +97,7 @@ void PlatformProcessDrivers(otInstance *aInstance) platformRadioUpdateFdSet(&read_fds, &write_fds, &max_fd); platformAlarmUpdateTimeout(&timeout); - if (!otAreTaskletsPending(aInstance)) + if (!otTaskletsArePending(aInstance)) { rval = select(max_fd + 1, &read_fds, &write_fds, &error_fds, &timeout); diff --git a/include/Makefile.am b/include/Makefile.am index f8631fdd8..4350aa4e1 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -70,7 +70,6 @@ include_HEADERS = \ openthread-ip6.h \ openthread-jam-detection.h \ openthread-message.h \ - openthread-tasklet.h \ openthread-types.h \ $(NULL) diff --git a/include/openthread.h b/include/openthread.h index fa511a9ec..aebb6810a 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -37,6 +37,8 @@ #include +#include "openthread/tasklet.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am index f404dff13..6d9d29ef1 100644 --- a/include/openthread/Makefile.am +++ b/include/openthread/Makefile.am @@ -30,6 +30,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am openthread_headers = \ coap.h \ + tasklet.h \ udp.h \ $(NULL) diff --git a/include/openthread-tasklet.h b/include/openthread/tasklet.h similarity index 90% rename from include/openthread-tasklet.h rename to include/openthread/tasklet.h index eed8ee167..51fd783aa 100644 --- a/include/openthread-tasklet.h +++ b/include/openthread/tasklet.h @@ -29,13 +29,13 @@ /** * @file * @brief - * This file includes the platform abstraction for the tasklet service. + * This file defines the OpenThread API for Tasklets. */ #ifndef OPENTHREAD_TASKLET_H_ #define OPENTHREAD_TASKLET_H_ -#include +#include "openthread-types.h" #ifdef __cplusplus extern "C" { @@ -56,7 +56,7 @@ extern "C" { * * @param[in] aInstance A pointer to an OpenThread instance. */ -void otProcessQueuedTasklets(otInstance *aInstance); +void otTaskletsProcess(otInstance *aInstance); /** * Indicates whether or not OpenThread has tasklets pending. @@ -66,7 +66,7 @@ void otProcessQueuedTasklets(otInstance *aInstance); * @retval TRUE If there are tasklets pending. * @retval FALSE If there are no tasklets pending. */ -bool otAreTaskletsPending(otInstance *aInstance); +bool otTaskletsArePending(otInstance *aInstance); /** * OpenThread calls this function when the tasklet queue transitions from empty to non-empty. @@ -74,7 +74,7 @@ bool otAreTaskletsPending(otInstance *aInstance); * @param[in] aInstance A pointer to an OpenThread instance. * */ -extern void otSignalTaskletPending(otInstance *aInstance); +extern void otTaskletsSignalPending(otInstance *aInstance); /** * @} diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 829f8d89f..02fcd4840 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -40,6 +40,7 @@ CPPFLAGS_COMMON = \ SOURCES_COMMON = \ openthread.cpp \ + api/tasklet_api.cpp \ api/udp_api.cpp \ coap/coap_base.cpp \ coap/coap_client.cpp \ diff --git a/src/core/api/tasklet_api.cpp b/src/core/api/tasklet_api.cpp new file mode 100644 index 000000000..92b31f010 --- /dev/null +++ b/src/core/api/tasklet_api.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the OpenThread Tasklet API. + */ + +#define WPP_NAME "tasklet_api.tmh" + +#include "openthread/tasklet.h" + +#include "openthread-instance.h" +#include "common/logging.hpp" + +using namespace Thread; + +#ifdef __cplusplus +extern "C" { +#endif + +void otTaskletsProcess(otInstance *aInstance) +{ + otLogFuncEntry(); + aInstance->mIp6.mTaskletScheduler.ProcessQueuedTasklets(); + otLogFuncExit(); +} + +bool otTaskletsArePending(otInstance *aInstance) +{ + return aInstance->mIp6.mTaskletScheduler.AreTaskletsPending(); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/core/common/tasklet.cpp b/src/core/common/tasklet.cpp index 5ed7d6563..456659554 100644 --- a/src/core/common/tasklet.cpp +++ b/src/core/common/tasklet.cpp @@ -68,7 +68,7 @@ ThreadError TaskletScheduler::Post(Tasklet &aTasklet) { mHead = &aTasklet; mTail = &aTasklet; - otSignalTaskletPending(aTasklet.mScheduler.GetIp6()->GetInstance()); + otTaskletsSignalPending(aTasklet.mScheduler.GetIp6()->GetInstance()); } else { @@ -118,7 +118,7 @@ void TaskletScheduler::ProcessQueuedTasklets(void) { if (mHead != NULL) { - otSignalTaskletPending(cur->mScheduler.GetIp6()->GetInstance()); + otTaskletsSignalPending(cur->mScheduler.GetIp6()->GetInstance()); } break; diff --git a/src/core/common/tasklet.hpp b/src/core/common/tasklet.hpp index 497bdb489..de58de123 100644 --- a/src/core/common/tasklet.hpp +++ b/src/core/common/tasklet.hpp @@ -34,8 +34,7 @@ #ifndef TASKLET_HPP_ #define TASKLET_HPP_ -#include -#include +#include "openthread/tasklet.h" namespace Thread { diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index bcbd87f74..aab4efe77 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -97,18 +96,6 @@ extern "C" { static void HandleActiveScanResult(void *aContext, Mac::Frame *aFrame); static void HandleEnergyScanResult(void *aContext, otEnergyScanResult *aResult); -void otProcessQueuedTasklets(otInstance *aInstance) -{ - otLogFuncEntry(); - aInstance->mIp6.mTaskletScheduler.ProcessQueuedTasklets(); - otLogFuncExit(); -} - -bool otAreTaskletsPending(otInstance *aInstance) -{ - return aInstance->mIp6.mTaskletScheduler.AreTaskletsPending(); -} - uint8_t otGetChannel(otInstance *aInstance) { return aInstance->mThreadNetif.GetMac().GetChannel(); diff --git a/tests/unit/test_diag.cpp b/tests/unit/test_diag.cpp index fcb0123ea..e9dc9d8a6 100644 --- a/tests/unit/test_diag.cpp +++ b/tests/unit/test_diag.cpp @@ -32,11 +32,11 @@ #include #include -extern "C" void otSignalTaskletPending(otInstance *) +extern "C" void otTaskletsSignalPending(otInstance *) { } -extern "C" bool otAreTaskletsPending(otInstance *) +extern "C" bool otTaskletsArePending(otInstance *) { return false; } diff --git a/tests/unit/test_fuzz.cpp b/tests/unit/test_fuzz.cpp index 3e10a368f..27148f8e5 100644 --- a/tests/unit/test_fuzz.cpp +++ b/tests/unit/test_fuzz.cpp @@ -138,7 +138,7 @@ void TestFuzz(uint32_t aSeconds) while (otPlatAlarmGetNow() < tEnd) { - otProcessQueuedTasklets(aInstance); + otTaskletsProcess(aInstance); if (g_testPlatAlarmSet && otPlatAlarmGetNow() >= g_testPlatAlarmNext) { diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index ea2b03076..282efe519 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -93,7 +93,7 @@ extern "C" { } #endif - void otSignalTaskletPending(otInstance *) + void otTaskletsSignalPending(otInstance *) { } diff --git a/tests/unit/test_platform.h b/tests/unit/test_platform.h index 1483c8ac7..139570e53 100644 --- a/tests/unit/test_platform.h +++ b/tests/unit/test_platform.h @@ -36,7 +36,7 @@ #endif #include -#include +#include "openthread/tasklet.h" #include #include