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
wait-queue.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Frederic Urbani <frederic.urbani@inria.fr>
19
*
20
*/
21
#ifndef WAIT_QUEUE_H
22
#define WAIT_QUEUE_H
23
24
#include "ns3/callback.h"
25
#include "ns3/nstime.h"
26
#include <list>
27
28
namespace
ns3 {
29
30
struct
Thread;
31
class
UnixFd;
32
43
class
WaitQueueEntry
44
{
45
public
:
46
WaitQueueEntry
();
47
// virtual ~WaitQueueEntry ();
48
49
// Wake Up the waiter of some events
50
// \param key: generic parameter describing the event source
51
virtual
void
WakeUp
(
void
*key) = 0;
52
};
53
54
class
PollTableEntry
;
55
59
class
WaitQueueEntryPoll
:
public
WaitQueueEntry
60
{
61
public
:
65
WaitQueueEntryPoll
(Callback<void> cb);
66
// virtual ~WaitQueueEntryPoll ();
67
68
virtual
void
WakeUp
(
void
*key);
69
void
SetPollTableEntry
(
PollTableEntry
* p);
70
71
private
:
72
Callback<void>
const
m_func
;
73
PollTableEntry
*
m_pollTableEntry
;
74
};
75
81
class
PollTableEntry
82
{
83
public
:
84
PollTableEntry
();
90
PollTableEntry
(
UnixFd
*file,
WaitQueueEntryPoll
* wait,
short
eventMask);
91
virtual
~PollTableEntry
();
92
96
virtual
void
FreeWait
();
97
int
IsEventMatch
(
short
e)
const
;
98
99
private
:
100
UnixFd
*
const
m_file
;
101
WaitQueueEntryPoll
*
const
m_wait
;
102
short
const
m_eventMask
;
103
};
104
108
class
WaitPoint
109
{
110
public
:
111
typedef
enum
112
{
113
INTERRUPTED
,
114
TIMEOUT
,
115
OK
116
}
Result
;
117
118
WaitPoint
();
119
120
// Stop the thread until a wakeup or timeout reached .
121
// \param: time max to wait or 0 for no max
122
WaitPoint::Result
Wait
(Time to);
123
void
WakeUpCallback
();
124
125
private
:
126
Thread
*
m_waitTask
;
127
};
131
class
PollTable
:
public
WaitPoint
132
{
133
public
:
134
PollTable
();
135
~PollTable
();
136
137
// Remove from every wait queues
138
void
FreeWait
();
139
// Add new file to Poll table and add corresponding poll table entry to file's wait queue.
140
void
PollWait
(
UnixFd
* file);
141
void
PollWait
(
void
*ref, Callback<void, void*> cb);
142
void
SetEventMask
(
short
e);
143
short
GetEventMask
()
const
;
144
145
private
:
146
std::list <PollTableEntry*>
m_pollEntryList
;
147
short
m_eventMask
;
148
};
149
150
151
class
PollTableEntryLinux
:
public
PollTableEntry
152
{
153
public
:
159
PollTableEntryLinux
(
void
*kernelReference, Callback<void, void*> cb);
160
161
162
virtual
void
FreeWait
();
163
164
private
:
165
void
*
const
m_kernelRef
;
166
Callback<void, void*>
const
m_freeCb
;
167
};
168
169
173
class
WaitQueueEntryTimeout
:
public
WaitQueueEntry
,
174
public
WaitPoint
175
{
176
public
:
177
WaitQueueEntryTimeout
(
short
eventMask, Time timeout);
178
virtual
void
WakeUp
(
void
*key);
179
WaitPoint::Result
Wait
();
180
181
private
:
182
Thread
*
m_waitTask
;
183
short
m_eventMask
;
184
Time
m_lastTime
;
185
};
186
#define RETURNFREE(A) { if (wq) { delete wq; wq = 0; } return A; }
187
}
188
#endif
/* WAIT_QUEUE_H */
model
wait-queue.h
Generated on Fri Aug 30 2013 13:57:56 for ns-3-dce by
1.8.1.2