Commit 887d8d09 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #5177 from lupustr3:pvlasov/tls_fixes

parents 76da19d5 a33d98c1
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
#include "opencv2/hal/defs.h" #include "opencv2/hal/defs.h"
#define OPENCV_ABI_COMPATIBILITY 300
#ifdef __OPENCV_BUILD #ifdef __OPENCV_BUILD
# define DISABLE_OPENCV_24_COMPATIBILITY # define DISABLE_OPENCV_24_COMPATIBILITY
#endif #endif
......
...@@ -513,30 +513,42 @@ private: ...@@ -513,30 +513,42 @@ private:
AutoLock& operator = (const AutoLock&); AutoLock& operator = (const AutoLock&);
}; };
// TLS interface
class CV_EXPORTS TLSDataContainer class CV_EXPORTS TLSDataContainer
{ {
private:
int key_;
protected: protected:
TLSDataContainer(); TLSDataContainer();
virtual ~TLSDataContainer(); virtual ~TLSDataContainer();
#if OPENCV_ABI_COMPATIBILITY > 300
void* getData() const;
void release();
private:
#else
void release();
public: public:
void* getData() const;
#endif
virtual void* createDataInstance() const = 0; virtual void* createDataInstance() const = 0;
virtual void deleteDataInstance(void* data) const = 0; virtual void deleteDataInstance(void* pData) const = 0;
void* getData() const; int key_;
}; };
// Main TLS data class
template <typename T> template <typename T>
class TLSData : protected TLSDataContainer class TLSData : protected TLSDataContainer
{ {
public: public:
inline TLSData() {} inline TLSData() {}
inline ~TLSData() {} inline ~TLSData() { release(); } // Release key and delete associated data
inline T* get() const { return (T*)getData(); } inline T* get() const { return (T*)getData(); } // Get data assosiated with key
private: private:
virtual void* createDataInstance() const { return new T; } virtual void* createDataInstance() const {return new T;} // Wrapper to allocate data by template
virtual void deleteDataInstance(void* data) const { delete (T*)data; } virtual void deleteDataInstance(void* pData) const {delete (T*)pData;} // Wrapper to release data by template
}; };
/** @brief Designed for command line parsing /** @brief Designed for command line parsing
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment