fix CurlThreadPool destroy logic
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
|
||||
CurlThreadPool::CurlThreadPool() {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
piForTimes(10) {
|
||||
const int count = 10;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
auto * t = new PIThread([this]() { threadFunc(); }, true);
|
||||
threads << t;
|
||||
}
|
||||
@@ -43,7 +44,9 @@ void CurlThreadPool::threadFunc() {
|
||||
|
||||
|
||||
void CurlThreadPool::procClient(PIHTTPClient * c) {
|
||||
{ clients_in_proc.getRef()->append(c); }
|
||||
if (c->init()) c->perform();
|
||||
{ clients_in_proc.getRef()->removeOne(c); }
|
||||
delete c;
|
||||
}
|
||||
|
||||
@@ -70,6 +73,11 @@ void CurlThreadPool::destroy() {
|
||||
for (auto c: *cr)
|
||||
c->abort();
|
||||
}
|
||||
{
|
||||
auto cr = clients_in_proc.getRef();
|
||||
for (auto c: *cr)
|
||||
c->abort();
|
||||
}
|
||||
// piCout << "~CurlThreadPool release ...";
|
||||
sem.release(threads.size());
|
||||
for (auto * t: threads) {
|
||||
|
||||
@@ -24,6 +24,7 @@ private:
|
||||
void procClient(PIHTTPClient * c);
|
||||
|
||||
PIProtectedVariable<PIQueue<PIHTTPClient *>> clients;
|
||||
PIProtectedVariable<PIVector<PIHTTPClient *>> clients_in_proc;
|
||||
PISemaphore sem;
|
||||
PIVector<PIThread *> threads;
|
||||
std::atomic_bool exiting = {false};
|
||||
|
||||
Reference in New Issue
Block a user