Skip to content

Commit 887d8d0

Browse files
committed
Merge pull request opencv#5177 from lupustr3:pvlasov/tls_fixes
2 parents 76da19d + a33d98c commit 887d8d0

File tree

3 files changed

+230
-177
lines changed

3 files changed

+230
-177
lines changed

modules/core/include/opencv2/core/cvdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858

5959
#include "opencv2/hal/defs.h"
6060

61+
#define OPENCV_ABI_COMPATIBILITY 300
62+
6163
#ifdef __OPENCV_BUILD
6264
# define DISABLE_OPENCV_24_COMPATIBILITY
6365
#endif

modules/core/include/opencv2/core/utility.hpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,30 +513,42 @@ class CV_EXPORTS AutoLock
513513
AutoLock& operator = (const AutoLock&);
514514
};
515515

516+
// TLS interface
516517
class CV_EXPORTS TLSDataContainer
517518
{
518-
private:
519-
int key_;
520519
protected:
521520
TLSDataContainer();
522521
virtual ~TLSDataContainer();
522+
523+
#if OPENCV_ABI_COMPATIBILITY > 300
524+
void* getData() const;
525+
void release();
526+
527+
private:
528+
#else
529+
void release();
530+
523531
public:
532+
void* getData() const;
533+
#endif
524534
virtual void* createDataInstance() const = 0;
525-
virtual void deleteDataInstance(void* data) const = 0;
535+
virtual void deleteDataInstance(void* pData) const = 0;
526536

527-
void* getData() const;
537+
int key_;
528538
};
529539

540+
// Main TLS data class
530541
template <typename T>
531542
class TLSData : protected TLSDataContainer
532543
{
533544
public:
534-
inline TLSData() {}
535-
inline ~TLSData() {}
536-
inline T* get() const { return (T*)getData(); }
545+
inline TLSData() {}
546+
inline ~TLSData() { release(); } // Release key and delete associated data
547+
inline T* get() const { return (T*)getData(); } // Get data assosiated with key
548+
537549
private:
538-
virtual void* createDataInstance() const { return new T; }
539-
virtual void deleteDataInstance(void* data) const { delete (T*)data; }
550+
virtual void* createDataInstance() const {return new T;} // Wrapper to allocate data by template
551+
virtual void deleteDataInstance(void* pData) const {delete (T*)pData;} // Wrapper to release data by template
540552
};
541553

542554
/** @brief Designed for command line parsing

0 commit comments

Comments
 (0)