From ea611dc1f1a8c9f62d67a1515b9ada757e6fee10 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sun, 19 Jun 2022 09:10:10 -0700 Subject: [PATCH] [netdata] perform `SynchronizeServerData()` from a `Tasklet` (#7823) This commit adds a `Taskelt` in `NetworkData::Notifier` to perform `SynchronizeServerData()` and post this tasklet when there is a change and `HandleServerDataUpdated()` is called. This ensures that if there are multiple changes triggered within the same flow of execution, they are all synchronized together and included in the same message to register with leader. --- src/core/thread/network_data_notifier.cpp | 10 ++++++++-- src/core/thread/network_data_notifier.hpp | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/thread/network_data_notifier.cpp b/src/core/thread/network_data_notifier.cpp index d82df76b0..d8a53d4eb 100644 --- a/src/core/thread/network_data_notifier.cpp +++ b/src/core/thread/network_data_notifier.cpp @@ -46,7 +46,8 @@ namespace NetworkData { Notifier::Notifier(Instance &aInstance) : InstanceLocator(aInstance) - , mTimer(aInstance, Notifier::HandleTimer) + , mTimer(aInstance, HandleTimer) + , mSynchronizeDataTask(aInstance, HandleSynchronizeDataTask) , mNextDelay(0) , mWaitingForResponse(false) { @@ -55,7 +56,12 @@ Notifier::Notifier(Instance &aInstance) void Notifier::HandleServerDataUpdated(void) { mNextDelay = 0; - SynchronizeServerData(); + mSynchronizeDataTask.Post(); +} + +void Notifier::HandleSynchronizeDataTask(Tasklet &aTasklet) +{ + aTasklet.Get().SynchronizeServerData(); } void Notifier::SynchronizeServerData(void) diff --git a/src/core/thread/network_data_notifier.hpp b/src/core/thread/network_data_notifier.hpp index 7bd313415..b9d6d5efc 100644 --- a/src/core/thread/network_data_notifier.hpp +++ b/src/core/thread/network_data_notifier.hpp @@ -42,6 +42,7 @@ #include "common/message.hpp" #include "common/non_copyable.hpp" #include "common/notifier.hpp" +#include "common/tasklet.hpp" namespace ot { namespace NetworkData { @@ -66,6 +67,10 @@ public: /** * Call this method to inform the notifier that new server data is available. * + * This method posts a tasklet to sync new server data with leader so if there are multiple changes within the same + * flow of execution (multiple calls to this method) they are all synchronized together and included in the same + * message to the leader. + * */ void HandleServerDataUpdated(void); @@ -85,9 +90,12 @@ private: Error aResult); void HandleCoapResponse(Error aResult); + static void HandleSynchronizeDataTask(Tasklet &aTasklet); + void SynchronizeServerData(void); TimerMilli mTimer; + Tasklet mSynchronizeDataTask; uint32_t mNextDelay; bool mWaitingForResponse; };