ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ns3::TaskManager Class Reference

#include <task-manager.h>

+ Collaboration diagram for ns3::TaskManager:

Classes

struct  StartTaskContext

Public Member Functions

 TaskManager ()
virtual ~TaskManager ()
TaskClone (Task *task)
TaskCurrentTask (void)
void EnterHiTask (Task *task)
void ExecOnMain (EventImpl *e)
void Exit (void)
bool GetNoSignal ()
uint32_t GetStackSize (Task *task) const
void LeaveHiTask (Task *task)
EventId ScheduleMain (Time const &time, EventImpl *e)
void SetDelayModel (Ptr< ProcessDelayModel > model)
void SetScheduler (Ptr< TaskScheduler > scheduler)
void SetSwitchNotify (void(*fn)(void))
void Sleep (void)
Time Sleep (Time timeout)
TaskStart (void(*fn)(void *), void *context)
TaskStart (void(*fn)(void *), void *context, uint32_t stackSize)
void Stop (Task *task)
void Wakeup (Task *task)
void Yield (void)

Static Public Member Functions

static TaskManagerCurrent (void)
static TypeId GetTypeId (void)

Private Types

enum  FiberManagerType { UCONTEXT_FIBER_MANAGER, PTHREAD_FIBER_MANAGER }

Private Member Functions

virtual void DoDispose (void)
void EndWait (Task *task)
void GarbageCollectDeadTasks (void)
void Schedule (void)
void SetFiberManagerType (enum FiberManagerType type)

Static Private Member Functions

static void MainSchedule (EventId *res, Time const &time, EventImpl *e)
static void Trampoline (void *context)

Private Attributes

Taskm_current
std::list< Task * > m_deadTasks
uint32_t m_defaultStackSize
Ptr< ProcessDelayModelm_delayModel
bool m_disposing
FiberManagerm_fiberManager
Taskm_hightask
Fiberm_mainFiber
EventId m_nextSchedule
bool m_noSignal
bool m_reSchedule
Time m_reScheduleTime
Ptr< TaskSchedulerm_scheduler
EventImpl * m_todoOnMain
std::list< Sleeperm_waitQueue

Detailed Description

Definition at line 68 of file task-manager.h.

Member Enumeration Documentation

Enumerator:
UCONTEXT_FIBER_MANAGER 
PTHREAD_FIBER_MANAGER 

Definition at line 162 of file task-manager.h.

Constructor & Destructor Documentation

ns3::TaskManager::TaskManager ( )

Definition at line 102 of file task-manager.cc.

ns3::TaskManager::~TaskManager ( )
virtual

Definition at line 114 of file task-manager.cc.

References ns3::FiberManager::Delete(), GarbageCollectDeadTasks(), m_fiberManager, m_mainFiber, and m_scheduler.

+ Here is the call graph for this function:

Member Function Documentation

TaskManager * ns3::TaskManager::Current ( void  )
static

Returns the 'current' task manager. Note that this function does not return a reference (i.e., the caller does not need to call Unref on the object returned). This is done on purpose to avoid problems due to a task calling Current, storing the reference on the stack, calling Exit, and the destructor of the caller stack frame never being called during process unloading, hence resulting in a lost reference and a leak. This is also why we don't return a Ptr<TaskManager> because it would increase the reference count and thus lose references when the caller's stack is ripped out.

Definition at line 400 of file task-manager.cc.

Referenced by ns3::Current(), dce_debug_monitor(), dce_debug_unmonitor(), dce_exit(), dce_pthread_create(), dce_pthread_exit(), dce_setitimer(), ns3::DceManager::Execve(), ns3::DceManager::ResumeTemporaryTask(), ns3::DceManager::StartTemporaryTask(), ns3::DceManager::StopTemporaryTask(), ns3::DceManager::SuspendTemporaryTask(), and ns3::SwitchNotifEatSignal().

+ Here is the caller graph for this function:

Task * ns3::TaskManager::CurrentTask ( void  )

Returns currently-executing task or 0 if no tasks are currently running.

Definition at line 391 of file task-manager.cc.

References m_current, and m_hightask.

Referenced by ns3::Current(), ns3::DceManager::ResumeTemporaryTask(), ns3::DceManager::StartTemporaryTask(), ns3::DceManager::StopTemporaryTask(), ns3::DceManager::SuspendTemporaryTask(), ns3::SwitchNotifEatSignal(), and ns3::LinuxSocketFdFactory::TaskCurrent().

+ Here is the caller graph for this function:

void ns3::TaskManager::DoDispose ( void  )
privatevirtual

Definition at line 126 of file task-manager.cc.

References dce___cxa_finalize(), ns3::gDisposingThreadContext, m_disposing, and ns3::Process::openStreams.

+ Here is the call graph for this function:

void ns3::TaskManager::EndWait ( Task task)
private

Definition at line 521 of file task-manager.cc.

References ns3::Task::BLOCKED, ns3::Task::m_state, and Wakeup().

Referenced by Schedule().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::EnterHiTask ( Task task)

Preempt the task to schedule.

Definition at line 376 of file task-manager.cc.

References m_hightask.

void ns3::TaskManager::ExecOnMain ( EventImpl *  e)

NS-3 prohibits to post event from a thread which is not the main thread, ExecOnMain call a callback using the main thread ScheduleMain use the Main thread to Schedule an event.

Definition at line 540 of file task-manager.cc.

References m_current, ns3::Task::m_fiber, m_fiberManager, m_mainFiber, m_noSignal, m_todoOnMain, and ns3::FiberManager::SwitchTo().

Referenced by ns3::UnixSocketFd::Close(), ns3::UnixSocketFd::Connect(), ns3::LinuxSocketFdFactory::DevXmit(), ns3::UnixDatagramSocketFd::DoSendmsg(), and ScheduleMain().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::Exit ( void  )

This method blocks and never returns. The current task is asynchronously deleted at the next available opportunity.

Definition at line 363 of file task-manager.cc.

References ns3::Task::DEAD, m_current, m_deadTasks, ns3::Task::m_state, ns3::Task::m_waitTimer, ns3::Task::RUNNING, and Schedule().

Referenced by dce_exit(), and dce_pthread_exit().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::GarbageCollectDeadTasks ( void  )
private

Definition at line 167 of file task-manager.cc.

References ns3::FiberManager::Delete(), m_deadTasks, ns3::Task::m_fiber, m_fiberManager, and ns3::Task::m_waitTimer.

Referenced by Schedule(), and ~TaskManager().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::TaskManager::GetNoSignal ( )

Definition at line 571 of file task-manager.cc.

References m_noSignal.

Referenced by ns3::SwitchNotifEatSignal().

+ Here is the caller graph for this function:

uint32_t ns3::TaskManager::GetStackSize ( Task task) const

Definition at line 535 of file task-manager.cc.

References ns3::FiberManager::GetStackSize(), ns3::Task::m_fiber, and m_fiberManager.

Referenced by dce_pthread_create().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TypeId ns3::TaskManager::GetTypeId ( void  )
static

Definition at line 80 of file task-manager.cc.

References m_defaultStackSize, PTHREAD_FIBER_MANAGER, SetFiberManagerType(), and UCONTEXT_FIBER_MANAGER.

+ Here is the call graph for this function:

void ns3::TaskManager::LeaveHiTask ( Task task)

Definition at line 383 of file task-manager.cc.

References m_hightask.

void ns3::TaskManager::MainSchedule ( EventId *  res,
Time const &  time,
EventImpl *  e 
)
staticprivate

Definition at line 566 of file task-manager.cc.

References Schedule().

Referenced by ScheduleMain().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

EventId ns3::TaskManager::ScheduleMain ( Time const &  time,
EventImpl *  e 
)

Definition at line 557 of file task-manager.cc.

References ExecOnMain(), and MainSchedule().

Referenced by dce_setitimer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::SetDelayModel ( Ptr< ProcessDelayModel model)

Definition at line 194 of file task-manager.cc.

References m_delayModel.

void ns3::TaskManager::SetFiberManagerType ( enum FiberManagerType  type)
private

Definition at line 500 of file task-manager.cc.

References ns3::FiberManager::CreateFromCaller(), m_fiberManager, m_mainFiber, PTHREAD_FIBER_MANAGER, ns3::FiberManager::SetSwitchNotification(), ns3::SwitchNotifEatSignal(), and UCONTEXT_FIBER_MANAGER.

Referenced by GetTypeId().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::SetScheduler ( Ptr< TaskScheduler scheduler)

Definition at line 188 of file task-manager.cc.

References m_scheduler.

void ns3::TaskManager::SetSwitchNotify ( void(*)(void)  fn)

Definition at line 530 of file task-manager.cc.

References m_fiberManager, and ns3::FiberManager::SetSwitchNotification().

Referenced by dce_debug_monitor(), and dce_debug_unmonitor().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::Sleep ( void  )

This method blocks and returns only when someone calls Wakeup on this task.

Definition at line 319 of file task-manager.cc.

References ns3::Task::BLOCKED, m_current, ns3::Task::m_state, ns3::Task::RUNNING, and Schedule().

+ Here is the call graph for this function:

Time ns3::TaskManager::Sleep ( Time  timeout)

This method blocks and returns when someone calls Wakeup on this task or timeout elapsed. Returns the amount of time left until the timeout elapses.

Definition at line 330 of file task-manager.cc.

References ns3::Task::BLOCKED, m_current, ns3::Task::m_state, m_waitQueue, ns3::Task::m_waitTimer, ns3::Task::RUNNING, and Schedule().

+ Here is the call graph for this function:

Task * ns3::TaskManager::Start ( void(*)(void *)  fn,
void *  context 
)

Create a task and schedule it to run later. The input context is forever associated to this task and can be retrieved by a call to CurrentTaskContext.

Definition at line 200 of file task-manager.cc.

References m_defaultStackSize.

Referenced by dce_pthread_create().

+ Here is the caller graph for this function:

void ns3::TaskManager::Stop ( Task task)

Stop and delete a task. This task will never run again. This method returns immediately.

Definition at line 279 of file task-manager.cc.

References ns3::Task::DEAD, ns3::FiberManager::Delete(), m_current, ns3::Task::m_fiber, m_fiberManager, m_scheduler, ns3::Task::m_state, and ns3::Task::m_waitTimer.

+ Here is the call graph for this function:

void ns3::TaskManager::Trampoline ( void *  context)
staticprivate

Definition at line 268 of file task-manager.cc.

References ns3::TaskManager::StartTaskContext::context, and ns3::TaskManager::StartTaskContext::function.

Referenced by Start().

+ Here is the caller graph for this function:

void ns3::TaskManager::Wakeup ( Task task)

Schedule the input task to run later. This method returns immediately.

Definition at line 302 of file task-manager.cc.

References ns3::Task::ACTIVE, m_current, m_nextSchedule, m_scheduler, ns3::Task::m_state, ns3::Task::RUNNING, and Schedule().

Referenced by Clone(), EndWait(), Start(), and ns3::LinuxSocketFdFactory::TaskWakeup().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::TaskManager::Yield ( void  )

This method blocks if other tasks can be scheduled but it will return immediately if the current task is the only active task.

Definition at line 352 of file task-manager.cc.

References ns3::Task::ACTIVE, m_current, m_scheduler, ns3::Task::m_state, ns3::Task::RUNNING, and Schedule().

Referenced by dce_pthread_create().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Task* ns3::TaskManager::m_current
private

Definition at line 182 of file task-manager.h.

Referenced by CurrentTask(), ExecOnMain(), Exit(), Schedule(), Sleep(), Stop(), Wakeup(), and Yield().

std::list<Task *> ns3::TaskManager::m_deadTasks
private

Definition at line 193 of file task-manager.h.

Referenced by Exit(), and GarbageCollectDeadTasks().

uint32_t ns3::TaskManager::m_defaultStackSize
private

Definition at line 188 of file task-manager.h.

Referenced by GetTypeId(), and Start().

Ptr<ProcessDelayModel> ns3::TaskManager::m_delayModel
private

Definition at line 185 of file task-manager.h.

Referenced by Schedule(), and SetDelayModel().

bool ns3::TaskManager::m_disposing
private

Definition at line 196 of file task-manager.h.

Referenced by DoDispose().

FiberManager* ns3::TaskManager::m_fiberManager
private
Task* ns3::TaskManager::m_hightask
private

Definition at line 183 of file task-manager.h.

Referenced by CurrentTask(), EnterHiTask(), and LeaveHiTask().

Fiber* ns3::TaskManager::m_mainFiber
private

Definition at line 187 of file task-manager.h.

Referenced by ExecOnMain(), Schedule(), SetFiberManagerType(), and ~TaskManager().

EventId ns3::TaskManager::m_nextSchedule
private

Definition at line 189 of file task-manager.h.

Referenced by Wakeup().

bool ns3::TaskManager::m_noSignal
private

Definition at line 195 of file task-manager.h.

Referenced by ExecOnMain(), and GetNoSignal().

bool ns3::TaskManager::m_reSchedule
private

Definition at line 190 of file task-manager.h.

Referenced by Schedule().

Time ns3::TaskManager::m_reScheduleTime
private

Definition at line 191 of file task-manager.h.

Referenced by Schedule().

Ptr<TaskScheduler> ns3::TaskManager::m_scheduler
private

Definition at line 184 of file task-manager.h.

Referenced by Schedule(), SetScheduler(), Stop(), Wakeup(), Yield(), and ~TaskManager().

EventImpl* ns3::TaskManager::m_todoOnMain
private

Definition at line 194 of file task-manager.h.

Referenced by ExecOnMain(), and Schedule().

std::list<Sleeper> ns3::TaskManager::m_waitQueue
private

Definition at line 192 of file task-manager.h.

Referenced by Schedule(), and Sleep().


The documentation for this class was generated from the following files: