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