5
#ifndef OPENCV_UTILS_TLS_HPP
6
#define OPENCV_UTILS_TLS_HPP
8
#ifndef OPENCV_CORE_UTILITY_H
9
#error "tls.hpp must be included after opencv2/core/utility.hpp or opencv2/core.hpp"
17
namespace
details {
class
TlsStorage; }
36
void* getData()
const;
40
virtual
void* createDataInstance()
const
= 0;
41
virtual
void
deleteDataInstance(
void* pData)
const
= 0;
46
friend
class
cv::details::TlsStorage;
69
inline
T*
get()
const
{
return
(T*)getData(); }
90
mutable
cv::Mutex mutex;
91
mutable
std::vector<T*> dataFromTerminatedThreads;
92
std::vector<T*> detachedData;
113
std::vector<void*> &dataVoid =
reinterpret_cast<std::vector<void*>&
>(data);
117
AutoLock lock(mutex);
118
data.reserve(data.size() + dataFromTerminatedThreads.size());
119
for
(
typename
std::vector<T*>::const_iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i)
121
data.push_back((T*)*i);
135
std::vector<void*> dataVoid;
140
AutoLock lock(mutex);
141
detachedData.reserve(dataVoid.size() + dataFromTerminatedThreads.size());
142
for
(
typename
std::vector<T*>::const_iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i)
144
detachedData.push_back((T*)*i);
146
dataFromTerminatedThreads.clear();
147
for
(
typename
std::vector<void*>::const_iterator i = dataVoid.begin(); i != dataVoid.end(); ++i)
149
detachedData.push_back((T*)(
void*)*i);
159
AutoLock lock(mutex);
161
_cleanupDetachedData();
171
AutoLock lock(mutex);
172
_cleanupDetachedData();
173
_cleanupTerminatedData();
181
TLSDataContainer::release();
183
AutoLock lock(mutex);
184
_cleanupDetachedData();
185
_cleanupTerminatedData();
191
void
_cleanupDetachedData()
193
for
(
typename
std::vector<T*>::iterator i = detachedData.begin(); i != detachedData.end(); ++i)
197
detachedData.clear();
201
void
_cleanupTerminatedData()
203
for
(
typename
std::vector<T*>::iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i)
207
dataFromTerminatedThreads.clear();
224
AutoLock lock(mutex);
225
dataFromTerminatedThreads.push_back((T*)pData);
TLS data accumulator with gathering methods
Definition:
tls.hpp:89
void cleanup()
Release associated thread data
Definition:
tls.hpp:166
std::vector< T * > & detachData()
Get and detach data from all threads
Definition:
tls.hpp:132
void cleanupDetachedData()
Release associated thread data returned by detachData() call
Definition:
tls.hpp:157
void release()
Release associated thread data and free TLS key
Definition:
tls.hpp:178
void gather(std::vector< T * > &data) const
Get data from all threads
Definition:
tls.hpp:108
virtual void * createDataInstance() const CV_OVERRIDE
Wrapper to allocate data by template
Definition:
tls.hpp:211
virtual void deleteDataInstance(void *pData) const CV_OVERRIDE
Wrapper to release data by template
Definition:
tls.hpp:216
void detachData(std::vector< void * > &data)
get TLS data and detach all data from threads (similar to cleanup() call)
void gatherData(std::vector< void * > &data) const
void cleanup()
Release created TLS data container objects. It is similar to release() call, but it keeps TLS contain...
Simple TLS data class
Definition:
tls.hpp:64
void cleanup()
Release associated thread data
Definition:
tls.hpp:73
virtual void deleteDataInstance(void *pData) const CV_OVERRIDE
Wrapper to release data by template
Definition:
tls.hpp:82
virtual void * createDataInstance() const CV_OVERRIDE
Wrapper to allocate data by template
Definition:
tls.hpp:80
T & getRef() const
Get data associated with key
Definition:
tls.hpp:70
T * get() const
Get data associated with key
Definition:
tls.hpp:69
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails
Definition:
base.hpp:342
#define CV_DbgAssert(expr)
Definition:
base.hpp:375
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75