Skip to content

Commit

Permalink
[Thread] move off joiner start from timer task (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukepo authored Aug 17, 2020
1 parent 807c052 commit 1740117
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class GenericThreadStackManagerImpl_FreeRTOS
static void OnJoinerTimer(TimerHandle_t xTimer);

portTickType mJoinerExpire;
bool mJoinerStartPending = false;
};

// Instruct the compiler to instantiate the template only when explicitly told to do so.
Expand Down
22 changes: 12 additions & 10 deletions src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,20 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::OnJoinerTimer(TimerHandl
GenericThreadStackManagerImpl_FreeRTOS<ImplClass> * self =
static_cast<GenericThreadStackManagerImpl_FreeRTOS<ImplClass> *>(pvTimerGetTimerID(xTimer));

ChipLogDetail(DeviceLayer, "Thread joiner timer running");

if (xTaskGetTickCount() > self->mJoinerExpire || self->Impl()->IsThreadProvisioned())
{
ChipLogDetail(DeviceLayer, "Thread joiner timer stopped");

VerifyOrDie(pdPASS == xTimerStop(xTimer, portMAX_DELAY) && pdPASS == xTimerDelete(xTimer, portMAX_DELAY));
}
else
else if (!self->mJoinerStartPending)
{
CHIP_ERROR error = self->Impl()->JoinerStart();
ChipLogDetail(DeviceLayer, "Request Thread joiner start");

ChipLogDetail(DeviceLayer, "Thread joiner timer triggered: %s", chip::ErrorStr(error));
self->mJoinerStartPending = true;
self->Impl()->SignalThreadActivityPending();
}
}

Expand All @@ -145,7 +148,6 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::ThreadTaskMain(void * ar

ChipLogDetail(DeviceLayer, "Thread task running");

// Capture the Thread task handle.
self->mThreadTask = xTaskGetCurrentTaskHandle();

// Try starting joiner within 15m.
Expand All @@ -157,17 +159,17 @@ void GenericThreadStackManagerImpl_FreeRTOS<ImplClass>::ThreadTaskMain(void * ar

while (true)
{
// Lock the Thread stack.
self->Impl()->LockThreadStack();

// Process any pending Thread activity.
self->Impl()->ProcessThreadActivity();

// Unlock the Thread stack.
self->Impl()->UnlockThreadStack();

// Wait for a signal that more activity is pending.
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (self->mJoinerStartPending)
{
self->mJoinerStartPending = false;
self->Impl()->JoinerStart();
}
}
}

Expand Down

0 comments on commit 1740117

Please sign in to comment.