This commit is contained in:
Jean-Francois Dockes 2021-01-17 10:51:16 +01:00
parent f9f524fed1
commit 6567d7d912
2 changed files with 16 additions and 0 deletions

View File

@ -123,6 +123,7 @@ extern int path_fileprops(const std::string path, struct PathStat *stp,
extern std::string path_PATHsep();
#ifdef _WIN32
#include <memory>
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);

View File

@ -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;