mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 17:37:46 +00:00
[tasklet] declare Scheduler as nested type of Tasklet (#6815)
This commit also inlines simple constructors.
This commit is contained in:
@@ -47,7 +47,7 @@ void otTaskletsProcess(otInstance *aInstance)
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(otInstanceIsInitialized(aInstance));
|
||||
instance.Get<TaskletScheduler>().ProcessQueuedTasklets();
|
||||
instance.Get<Tasklet::Scheduler>().ProcessQueuedTasklets();
|
||||
|
||||
exit:
|
||||
return;
|
||||
@@ -59,7 +59,7 @@ bool otTaskletsArePending(otInstance *aInstance)
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(otInstanceIsInitialized(aInstance));
|
||||
retval = instance.Get<TaskletScheduler>().AreTaskletsPending();
|
||||
retval = instance.Get<Tasklet::Scheduler>().AreTaskletsPending();
|
||||
|
||||
exit:
|
||||
return retval;
|
||||
|
||||
@@ -333,7 +333,7 @@ private:
|
||||
// Tasklet and Timer Schedulers are first to ensure other
|
||||
// objects/classes can use them from their constructors.
|
||||
|
||||
TaskletScheduler mTaskletScheduler;
|
||||
Tasklet::Scheduler mTaskletScheduler;
|
||||
TimerMilliScheduler mTimerMilliScheduler;
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
TimerMicroScheduler mTimerMicroScheduler;
|
||||
@@ -945,7 +945,7 @@ template <> inline Mac::SubMac &Instance::Get(void)
|
||||
|
||||
#endif // OPENTHREAD_RADIO || OPENTHREAD_CONFIG_LINK_RAW_ENABLE
|
||||
|
||||
template <> inline TaskletScheduler &Instance::Get(void)
|
||||
template <> inline Tasklet::Scheduler &Instance::Get(void)
|
||||
{
|
||||
return mTaskletScheduler;
|
||||
}
|
||||
|
||||
@@ -34,34 +34,19 @@
|
||||
#include "tasklet.hpp"
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/locator_getters.hpp"
|
||||
#include "net/ip6.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
Tasklet::Tasklet(Instance &aInstance, Handler aHandler)
|
||||
: InstanceLocator(aInstance)
|
||||
, mHandler(aHandler)
|
||||
, mNext(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void Tasklet::Post(void)
|
||||
{
|
||||
if (!IsPosted())
|
||||
{
|
||||
Get<TaskletScheduler>().PostTasklet(*this);
|
||||
Get<Scheduler>().PostTasklet(*this);
|
||||
}
|
||||
}
|
||||
|
||||
TaskletScheduler::TaskletScheduler(void)
|
||||
: mTail(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskletScheduler::PostTasklet(Tasklet &aTasklet)
|
||||
void Tasklet::Scheduler::PostTasklet(Tasklet &aTasklet)
|
||||
{
|
||||
// Tasklets are saved in a circular singly linked list.
|
||||
|
||||
@@ -79,7 +64,7 @@ void TaskletScheduler::PostTasklet(Tasklet &aTasklet)
|
||||
}
|
||||
}
|
||||
|
||||
void TaskletScheduler::ProcessQueuedTasklets(void)
|
||||
void Tasklet::Scheduler::ProcessQueuedTasklets(void)
|
||||
{
|
||||
Tasklet *tail = mTail;
|
||||
|
||||
|
||||
+45
-39
@@ -63,9 +63,46 @@ class TaskletScheduler;
|
||||
*/
|
||||
class Tasklet : public InstanceLocator
|
||||
{
|
||||
friend class TaskletScheduler;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This class implements the tasklet scheduler.
|
||||
*
|
||||
*/
|
||||
class Scheduler : private NonCopyable
|
||||
{
|
||||
friend class Tasklet;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
*/
|
||||
Scheduler(void)
|
||||
: mTail(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates whether or not there are tasklets pending.
|
||||
*
|
||||
* @retval TRUE If there are tasklets pending.
|
||||
* @retval FALSE If there are no tasklets pending.
|
||||
*
|
||||
*/
|
||||
bool AreTaskletsPending(void) const { return mTail != nullptr; }
|
||||
|
||||
/**
|
||||
* This method processes all tasklets queued when this is called.
|
||||
*
|
||||
*/
|
||||
void ProcessQueuedTasklets(void);
|
||||
|
||||
private:
|
||||
void PostTasklet(Tasklet &aTasklet);
|
||||
|
||||
Tasklet *mTail; // A circular singly linked-list
|
||||
};
|
||||
|
||||
/**
|
||||
* This function reference is called when the tasklet is run.
|
||||
*
|
||||
@@ -81,7 +118,12 @@ public:
|
||||
* @param[in] aHandler A pointer to a function that is called when the tasklet is run.
|
||||
*
|
||||
*/
|
||||
Tasklet(Instance &aInstance, Handler aHandler);
|
||||
Tasklet(Instance &aInstance, Handler aHandler)
|
||||
: InstanceLocator(aInstance)
|
||||
, mHandler(aHandler)
|
||||
, mNext(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method puts the tasklet on the tasklet scheduler run queue.
|
||||
@@ -145,42 +187,6 @@ private:
|
||||
void *mContext;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements the tasklet scheduler.
|
||||
*
|
||||
*/
|
||||
class TaskletScheduler : private NonCopyable
|
||||
{
|
||||
friend class Tasklet;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
*/
|
||||
TaskletScheduler(void);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not there are tasklets pending.
|
||||
*
|
||||
* @retval TRUE If there are tasklets pending.
|
||||
* @retval FALSE If there are no tasklets pending.
|
||||
*
|
||||
*/
|
||||
bool AreTaskletsPending(void) const { return mTail != nullptr; }
|
||||
|
||||
/**
|
||||
* This method processes all tasklets queued when this is called.
|
||||
*
|
||||
*/
|
||||
void ProcessQueuedTasklets(void);
|
||||
|
||||
private:
|
||||
void PostTasklet(Tasklet &aTasklet);
|
||||
|
||||
Tasklet *mTail; // A circular singly linked-list
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user