VR-Forces 4.3 Class Documentation
Home
Modules
Namespaces
Classes
Files
Examples
Behavior Models
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
vrfutil
callbackQueue.h
Go to the documentation of this file.
1
/*******************************************************************************
2
** Copyright (c) 2013 MAK Technologies, Inc.
3
** All rights reserved.
4
*******************************************************************************/
5
9
10
#pragma once
11
12
#include "
vrfutil/vrfutilDefines.h
"
13
#include "
vrfutil/objectCounter.h
"
14
15
#include <boost/function.hpp>
16
#include <boost/shared_ptr.hpp>
17
#include <boost/noncopyable.hpp>
18
19
#include <tbb/mutex.h>
20
#include <tbb/tbb_thread.h>
21
#include <tbb/compat/condition_variable>
22
#include <tbb/spin_mutex.h>
23
#include <tbb/atomic.h>
24
25
#include <list>
26
27
class
DtConsoleCommandManager
;
28
30
class
DT_DLL_vrfutil
DtCallbackQueue
: boost::noncopyable
31
{
32
struct
ThreadInfo
:
public
DtObjectDebugger
<ThreadInfo>
33
{
34
typedef
boost::shared_ptr<ThreadInfo>
Ptr
;
35
typedef
std::list<Ptr>
List
;
36
37
static
Ptr
Make(
DtCallbackQueue
&);
38
39
bool
quitFlag
;
40
tbb::tbb_thread
thread
;
41
42
protected
:
43
explicit
ThreadInfo
(
DtCallbackQueue
&);
44
};
45
46
friend
struct
ThreadInfo
;
47
48
public
:
49
typedef
boost::function<void ()>
Callback
;
50
52
class
DT_DLL_vrfutil
CallbackInterface
53
:
public
DtObjectDebugger
<CallbackInterface>
54
{
55
public
:
56
typedef
boost::shared_ptr<CallbackInterface>
Ptr
;
57
58
class
Wrapper
;
59
class
RefWrapper
;
60
62
virtual
~
CallbackInterface
();
63
65
virtual
std::string label()
const
;
66
68
virtual
void
run() = 0;
69
71
virtual
void
cancel();
72
};
73
76
explicit
DtCallbackQueue
(
77
const
std::string& label,
78
unsigned
maxTasks);
79
81
virtual
~
DtCallbackQueue
();
82
84
virtual
std::string label()
const
;
85
87
static
void
cleanup();
88
90
virtual
void
setWarnTime(
double
seconds);
91
93
virtual
void
printInfo(std::ostream&,
size_t
width=0)
const
;
94
96
virtual
size_t
totalNumberOfCallbacks()
const
;
97
99
virtual
unsigned
size()
const
;
100
102
virtual
size_t
numExecuting()
const
;
103
105
virtual
unsigned
maxTasks()
const
;
106
109
virtual
void
setMaxTasks(
unsigned
tasks,
bool
wait=
true
);
110
113
virtual
void
shutdown(
bool
wait =
true
);
114
116
virtual
void
clear(
bool
wait =
true
);
117
119
virtual
void
add_back(
const
Callback
&,
const
std::string& label =
""
);
120
122
virtual
void
add_front(
const
Callback
&,
const
std::string& label =
""
);
123
125
virtual
void
add_back(
CallbackInterface
*);
126
128
virtual
void
add_front(
CallbackInterface
*);
129
131
virtual
void
add_back(
const
CallbackInterface::Ptr
&);
132
134
virtual
void
add_front(
const
CallbackInterface::Ptr
&);
135
138
virtual
void
add_back(
CallbackInterface
&);
139
142
virtual
void
add_front(
CallbackInterface
&);
143
148
virtual
bool
runOne(
bool
block=
false
,
ThreadInfo
* info=0);
149
153
virtual
void
runAll(
bool
useThisThread=
false
);
154
155
private
:
160
virtual
bool
pop(
161
CallbackInterface::Ptr
&,
bool
block=
true
,
ThreadInfo
* info=0);
162
164
void
execute(
ThreadInfo
*);
165
167
struct
Record
:
public
DtObjectDebugger
<Record>
168
{
169
typedef
std::list<Record>
List
;
170
171
const
CallbackInterface::Ptr
callback
;
172
const
tbb::tick_count
timeAdded
;
173
174
explicit
Record
(
CallbackInterface
*);
175
explicit
Record
(
const
CallbackInterface::Ptr
&);
176
};
177
178
typedef
tbb::mutex
Mutex
;
179
typedef
tbb::interface5::condition_variable
Condition
;
180
typedef
tbb::interface5::unique_lock<Mutex>
Lock
;
181
182
mutable
Mutex
myMutex
;
183
mutable
Condition
myCondition
;
184
mutable
Condition
myDoneCondition
;
185
186
ThreadInfo::List
myThreads
;
187
Record::List
myCallbacks
;
188
189
bool
myShutdownFlag
;
190
size_t
myTotalNumCallbacks
;
191
192
tbb::atomic<size_t>
myNumExecuting
;
193
194
DtConsoleCommandManager
*
myConsoleManager
;
195
196
const
std::string
myLabel
;
197
198
double
myWarnTime
;
201
};
202
203
class
DtCallbackQueue::CallbackInterface::Wrapper
204
:
public
DtCallbackQueue::CallbackInterface
205
{
206
public
:
207
explicit
Wrapper
(
DtCallbackQueue::CallbackInterface
* i) :
myCallback
(i) { }
208
~Wrapper
() {
delete
myCallback
; }
209
std::string
label
()
const
{
return
myCallback
->
label
(); }
210
void
run
() {
myCallback
->
run
(); }
211
void
cancel
() {
myCallback
->
cancel
(); }
212
213
protected
:
214
DtCallbackQueue::CallbackInterface
*
myCallback
;
215
};
216
217
class
DtCallbackQueue::CallbackInterface::RefWrapper
218
:
public
DtCallbackQueue::CallbackInterface
219
{
220
public
:
221
explicit
RefWrapper
(
DtCallbackQueue::CallbackInterface
& i) :
myCallback
(i) { }
222
std::string
label
()
const
{
return
myCallback
.
label
(); }
223
void
run
() {
myCallback
.
run
(); }
224
void
cancel
() {
myCallback
.
cancel
(); }
225
226
protected
:
227
DtCallbackQueue::CallbackInterface
&
myCallback
;
228
};
229
230
DT_DEFINE_OBJECT_DEBUGGER_NAME
(
DtCallbackQueue::ThreadInfo
);
231
DT_DEFINE_OBJECT_DEBUGGER_NAME
(
DtCallbackQueue::CallbackInterface
);
232
DT_DEFINE_OBJECT_DEBUGGER_NAME
(
DtCallbackQueue::Record
);
Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (
www.mak.com
)