TLS keys leak fix;

Disables TLS copy constructor and operator, as they can lead to errors and reservation of too much keys in TLS storage;

gather method was added to TLS to gather data from all threads;
This commit is contained in:
Pavel Vlasov
2015-09-16 14:00:36 +03:00
parent 9533982729
commit aa485ccd75
2 changed files with 57 additions and 11 deletions

View File

@@ -520,6 +520,7 @@ protected:
TLSDataContainer();
virtual ~TLSDataContainer();
void gatherData(std::vector<void*> &data) const;
#if OPENCV_ABI_COMPATIBILITY > 300
void* getData() const;
void release();
@@ -546,9 +547,20 @@ public:
inline ~TLSData() { release(); } // Release key and delete associated data
inline T* get() const { return (T*)getData(); } // Get data assosiated with key
// Get data from all threads
inline void gather(std::vector<T*> &data) const
{
std::vector<void*> &dataVoid = reinterpret_cast<std::vector<void*>&>(data);
gatherData(dataVoid);
}
private:
virtual void* createDataInstance() const {return new T;} // Wrapper to allocate data by template
virtual void deleteDataInstance(void* pData) const {delete (T*)pData;} // Wrapper to release data by template
// Disable TLS copy operations
TLSData(TLSData &) {};
TLSData& operator =(const TLSData &) {return *this;};
};
/** @brief Designed for command line parsing