ns-3 Direct Code Execution
Home
Tutorials ▼
Docs ▼
Wiki
Manual
Develop ▼
API
Bugs
API
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
task-manager.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
#ifndef TASK_MANAGER_H
3
#define TASK_MANAGER_H
4
5
#include "ns3/object.h"
6
#include "ns3/event-id.h"
7
#include "ns3/nstime.h"
8
#include "
task-scheduler.h
"
9
#include <list>
10
#include "
process-delay-model.h
"
11
12
namespace
ns3 {
13
14
class
TaskScheduler;
15
class
Fiber;
16
class
FiberManager;
17
18
class
Task
19
{
20
public
:
21
enum
SwitchType
22
{
23
TO
,
24
FROM
25
};
26
bool
IsActive
(
void
)
const
;
27
bool
IsRunning
(
void
)
const
;
28
bool
IsBlocked
(
void
)
const
;
29
bool
IsDead
(
void
)
const
;
30
31
void
SetExtraContext
(
void
*ctx);
32
void
SetContext
(
void
*ctx);
33
34
void
*
GetExtraContext
(
void
)
const
;
35
void
*
GetContext
(
void
)
const
;
36
37
void
SetSwitchNotifier
(
void
(*fn)(
enum
SwitchType
,
void
*),
void
*context);
38
private
:
39
friend
class
TaskManager
;
40
~Task
();
41
enum
State
42
{
43
RUNNING
,
44
ACTIVE
,
45
BLOCKED
,
46
DEAD
47
};
48
enum
State
m_state
;
49
Fiber
*
m_fiber
;
50
EventId
m_waitTimer
;
51
void
*
m_context
;
52
void
*
m_extraContext
;
53
void (*
m_switchNotifier
)(
enum
SwitchType
,
void
*);
54
void
*
m_switchNotifierContext
;
55
};
56
57
class
Sleeper
58
{
59
public
:
60
Sleeper
(
Task
*t, Time to) :
m_task
(t),
61
m_timeout
(to)
62
{
63
}
64
Task
*
const
m_task
;
65
const
Time
m_timeout
;
66
};
67
68
class
TaskManager
:
public
Object
69
{
70
public
:
71
static
TypeId
GetTypeId
(
void
);
72
73
TaskManager
();
74
virtual
~TaskManager
();
75
76
void
SetScheduler
(Ptr<TaskScheduler> scheduler);
77
void
SetDelayModel
(Ptr<ProcessDelayModel> model);
78
84
Task
*
Start
(
void
(*fn)(
void
*),
void
*context);
85
Task
*
Start
(
void
(*fn)(
void
*),
void
*context, uint32_t stackSize);
86
87
Task
*
Clone
(
Task
*task);
88
93
void
Stop
(
Task
*task);
94
99
void
Wakeup
(
Task
*task);
100
105
void
Sleep
(
void
);
111
Time
Sleep
(Time timeout);
117
void
Yield
(
void
);
122
void
Exit
(
void
);
123
128
Task
*
CurrentTask
(
void
);
140
static
TaskManager
*
Current
(
void
);
141
145
void
EnterHiTask
(
Task
*task);
146
void
LeaveHiTask
(
Task
*task);
147
148
void
SetSwitchNotify
(
void
(*fn)(
void
));
149
uint32_t
GetStackSize
(
Task
*task)
const
;
150
156
void
ExecOnMain
(EventImpl *e);
157
EventId
ScheduleMain
(Time
const
&time, EventImpl *e);
158
159
bool
GetNoSignal
();
160
161
private
:
162
enum
FiberManagerType
163
{
164
UCONTEXT_FIBER_MANAGER
,
165
PTHREAD_FIBER_MANAGER
,
166
};
167
struct
StartTaskContext
168
{
169
void (*
function
)(
void
*);
170
void
*
context
;
171
};
172
173
virtual
void
DoDispose
(
void
);
174
void
Schedule
(
void
);
175
void
SetFiberManagerType
(
enum
FiberManagerType
type);
176
void
GarbageCollectDeadTasks
(
void
);
177
void
EndWait
(
Task
*task);
178
static
void
Trampoline
(
void
*context);
179
static
void
MainSchedule
(EventId *res,Time
const
&time, EventImpl *e);
180
181
182
Task
*
m_current
;
183
Task
*
m_hightask
;
184
Ptr<TaskScheduler>
m_scheduler
;
185
Ptr<ProcessDelayModel>
m_delayModel
;
186
FiberManager
*
m_fiberManager
;
187
Fiber
*
m_mainFiber
;
188
uint32_t
m_defaultStackSize
;
189
EventId
m_nextSchedule
;
190
bool
m_reSchedule
;
191
Time
m_reScheduleTime
;
192
std::list<Sleeper>
m_waitQueue
;
193
std::list<Task *>
m_deadTasks
;
194
EventImpl *
m_todoOnMain
;
195
bool
m_noSignal
;
// I am not come back from a real thread interruption do not run signal ....
196
bool
m_disposing
;
// In order to never loop while disposing me.
197
};
198
199
}
// namespace
200
201
#endif
/* TASK_MANAGER_H */
model
task-manager.h
Generated on Fri Aug 30 2013 13:57:56 for ns-3-dce by
1.8.1.2