RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UObjDeletionThread.h
1/*
2* utilite is a cross-platform library with
3* useful utilities for fast and small developing.
4* Copyright (C) 2010 Mathieu Labbe
5*
6* utilite is free library: you can redistribute it and/or modify
7* it under the terms of the GNU Lesser General Public License as published by
8* the Free Software Foundation, either version 3 of the License, or
9* (at your option) any later version.
10*
11* utilite is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU Lesser General Public License for more details.
15*
16* You should have received a copy of the GNU Lesser General Public License
17* along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef UOBJDELETIONTHREAD_H
21#define UOBJDELETIONTHREAD_H
22
24#include "rtabmap/utilite/UEvent.h"
25#include "rtabmap/utilite/UEventsManager.h"
26
32{
33public:
34 UObjDeletedEvent(int objDeletionThreadId) : UEvent(objDeletionThreadId) {}
35 virtual ~UObjDeletedEvent() {}
39 virtual std::string getClassName() const {return std::string("UObjDeletedEvent");}
40};
41
47template<class T>
49{
50public:
56 UObjDeletionThread(T * obj, int id=0) :
57 obj_(obj),
58 id_(id),
59 waitMs_(0) {}
60
69 {
70 join(true);
71 if(obj_)
72 {
73 delete obj_;
74 }
75 }
76
81 void startDeletion(int waitMs = 0) {waitMs_ = waitMs; this->start();}
82
87 int id() const {return id_;}
88
93 void setObj(T * obj)
94 {
95 join();
96 if(obj_)
97 {
98 delete obj_;
99 obj_ = 0;
100 }
101 obj_ = obj;
102 }
103
104private:
108 virtual void mainLoop()
109 {
110 if(waitMs_)
111 {
112 uSleep(waitMs_);
113 }
114 if(obj_)
115 {
116 delete obj_;
117 obj_ = 0;
118 }
119 this->kill();
120 UEventsManager::post(new UObjDeletedEvent(id_), false);
121 }
122
123private:
124 T * obj_;
125 int id_;
126 int waitMs_;
127};
128
129#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)