RTAB-Map 0.25.2
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UObjDeletionThread.h
1/*
2Copyright (c) 2010, Mathieu Labbe
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON 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
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef UOBJDELETIONTHREAD_H
29#define UOBJDELETIONTHREAD_H
30
32#include "rtabmap/utilite/UEvent.h"
33#include "rtabmap/utilite/UEventsManager.h"
34
40{
41public:
42 UObjDeletedEvent(int objDeletionThreadId) : UEvent(objDeletionThreadId) {}
43 virtual ~UObjDeletedEvent() {}
47 virtual std::string getClassName() const {return std::string("UObjDeletedEvent");}
48};
49
55template<class T>
57{
58public:
64 UObjDeletionThread(T * obj, int id=0) :
65 obj_(obj),
66 id_(id),
67 waitMs_(0) {}
68
77 {
78 join(true);
79 if(obj_)
80 {
81 delete obj_;
82 }
83 }
84
89 void startDeletion(int waitMs = 0) {waitMs_ = waitMs; this->start();}
90
95 int id() const {return id_;}
96
101 void setObj(T * obj)
102 {
103 join();
104 if(obj_)
105 {
106 delete obj_;
107 obj_ = 0;
108 }
109 obj_ = obj;
110 }
111
112private:
116 virtual void mainLoop()
117 {
118 if(waitMs_)
119 {
120 uSleep(waitMs_);
121 }
122 if(obj_)
123 {
124 delete obj_;
125 obj_ = 0;
126 }
127 this->kill();
128 UEventsManager::post(new UObjDeletedEvent(id_), false);
129 }
130
131private:
132 T * obj_;
133 int id_;
134 int waitMs_;
135};
136
137#endif /* UOBJDELETIONTHREAD_H */
Backward-compatible alias header for UThread.
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
virtual std::string getClassName() const
void startDeletion(int waitMs=0)
UObjDeletionThread(T *obj, int id=0)
void start()
void kill()
void join(bool killFirst=false)