RTAB-Map
0.25.2
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UThread.h
1
/*
2
Copyright (c) 2010, Mathieu Labbe
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright
8
notice, this list of conditions and the following disclaimer.
9
* Redistributions in binary form must reproduce the above copyright
10
notice, this list of conditions and the following disclaimer in the
11
documentation and/or other materials provided with the distribution.
12
* Neither the name of the copyright holders nor the
13
names of its contributors may be used to endorse or promote products
14
derived from this software without specific prior written permission.
15
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#ifndef UTHREADNODE_H
29
#define UTHREADNODE_H
30
31
#include "rtabmap/utilite/utilite_export.h"
// DLL export/import defines
32
33
#include "rtabmap/utilite/UThreadC.h"
34
94
class
UTILITE_EXPORT
UThread
:
public
UThreadC
<void>
95
{
96
public
:
100
enum
Priority
{kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime};
101
102
public
:
103
//return caller thread id
104
static
unsigned
long
currentThreadId() {
return
(
unsigned
long
)
UThreadC<void>::Self
();}
105
106
public
:
112
UThread
(
Priority
priority = kPNormal);
113
120
virtual
~UThread
();
121
127
void
start
();
128
135
void
kill
();
136
143
void
join
(
bool
killFirst =
false
);
144
149
void
setPriority
(
Priority
priority);
150
157
void
setAffinity
(
int
cpu = 0);
158
162
bool
isCreating
()
const
;
163
167
bool
isRunning
()
const
;
168
172
bool
isIdle
()
const
;
173
177
bool
isKilled
()
const
;
178
179
Handle getThreadHandle()
const
{
return
handle_;}
180
unsigned
long
getThreadId()
const
{
return
threadId_;}
181
182
protected
:
183
184
private
:
191
virtual
void
mainLoopBegin() {}
192
202
virtual
void
mainLoop() = 0;
203
211
virtual
void
mainLoopKill() {}
212
219
virtual
void
mainLoopEnd() {}
220
221
/*
222
* Inherited method ThreadMain() from Thread.
223
* @see Thread<void>
224
*/
225
void
ThreadMain();
226
227
/*
228
* Apply thread priority. This is called when starting the thread.
229
* *@todo : Support pthread
230
*/
231
void
applyPriority();
232
233
/*
234
* Apply cpu affinity. This is called when starting the thread.
235
* *@todo : Support Windows
236
*/
237
void
applyAffinity();
238
239
/*
240
* Inherited method Create() from Thread.
241
* Here we force this function to be private so the
242
* inherited class can't have access to it.
243
* @see Thread<void>
244
*/
245
int
Create(
246
Handle *
const
& H = 0,
247
const
bool
& CreateDetached =
false
,
248
const
unsigned
int
& StackSize = 0,
249
const
bool
& CancelEnable =
false
,
// UNUSED
250
const
bool
& CancelAsync =
false
// UNUSED
251
)
const
;
252
253
//Methods from UThread<void> class hided
254
static
int
Join( Handle H )
255
{
return
UThreadC<void>::Join
(H); }
256
#ifndef ANDROID
257
static
int
Kill( Handle H )
258
{
return
UThreadC<void>::Kill
(H); }
259
#endif
260
static
int
Detach( Handle H )
261
{
return
UThreadC<void>::Detach
(H); }
262
263
private
:
264
void
operator=(
UThread
&) {}
265
UThread
(
const
UThread
&) : state_(kSIdle) {}
266
267
private
:
268
enum
State{kSIdle, kSCreating, kSRunning, kSKilled};
/* Enum of states. */
269
State state_;
/* The thread state. */
270
Priority priority_;
/* The thread priority. */
271
Handle handle_;
/* The thread handle. */
272
unsigned
long
threadId_;
/* The thread id. */
273
int
cpuAffinity_;
/* The cpu affinity. */
274
UMutex
killSafelyMutex_;
/* Mutex used to protect the kill() method. */
275
UMutex
runningMutex_;
/* Mutex used to notify the join method when the thread has finished. */
276
};
277
278
#endif
// UTHREADNODE_H
UMutex
Definition
UMutex.h:63
UThreadC
Definition
UThreadC.h:67
UThread
Definition
UThread.h:95
UThread::start
void start()
UThread::UThread
UThread(Priority priority=kPNormal)
UThread::isIdle
bool isIdle() const
UThread::isRunning
bool isRunning() const
UThread::isKilled
bool isKilled() const
UThread::~UThread
virtual ~UThread()
UThread::Priority
Priority
Definition
UThread.h:100
UThread::setPriority
void setPriority(Priority priority)
UThread::kill
void kill()
UThread::setAffinity
void setAffinity(int cpu=0)
UThread::isCreating
bool isCreating() const
UThread::join
void join(bool killFirst=false)
utilite
include
rtabmap
utilite
UThread.h
Generated by
1.9.8