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; };