diff --git a/src/utils/pathut.h b/src/utils/pathut.h index f969d0d6..195c2989 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -123,6 +123,7 @@ extern int path_fileprops(const std::string path, struct PathStat *stp, extern std::string path_PATHsep(); #ifdef _WIN32 +#include bool wchartoutf8(const wchar_t *in, std::string& out, size_t len = 0); std::string wchartoutf8(const wchar_t *in, size_t len = 0); bool utf8towchar(const std::string& in, wchar_t *out, size_t obytescap); diff --git a/src/utils/workqueue.h b/src/utils/workqueue.h index 8b2dd610..026ab1f9 100644 --- a/src/utils/workqueue.h +++ b/src/utils/workqueue.h @@ -72,6 +72,16 @@ public: } } + /** Task deleter + * If put() is called with the flush option, and the tasks allocate memory, + * you need to set this function, which will be called on each task popped + * from the queue. Tasks which go through normally must be freed by the + * worker function. + */ + void setTaskFreeFunc(void (*func)(T&)) { + m_taskfreefunc = func; + } + /** Start the worker threads. * * @param nworkers number of threads copies to start. @@ -120,6 +130,10 @@ public: } if (flushprevious) { while (!m_queue.empty()) { + if (m_taskfreefunc) { + T& d = m_queue.front(); + m_taskfreefunc(d); + } m_queue.pop(); } } @@ -325,6 +339,7 @@ private: #endif }; + void (*m_taskfreefunc)(T&){nullptr}; // Configuration std::string m_name; size_t m_high;