@@ -192,12 +192,12 @@ HttpClient::HttpClient()
192192 background_thread_wait_for_{std::chrono::minutes{1 }},
193193 curl_global_initializer_ (HttpCurlGlobalInitializer::GetInstance())
194194{
195- is_shutdown .store (false );
195+ is_shutdown_ .store (false );
196196}
197197
198198HttpClient::~HttpClient ()
199199{
200- is_shutdown .store (true , std::memory_order_release);
200+ is_shutdown_ .store (true , std::memory_order_release);
201201 while (true )
202202 {
203203 std::unique_ptr<std::thread> background_thread;
@@ -432,14 +432,16 @@ void HttpClient::MaybeSpawnBackgroundThread()
432432 continue ;
433433 }
434434
435- std::chrono::milliseconds wait_for;
435+ std::chrono::milliseconds wait_for = std::chrono::milliseconds::zero ();
436+ ;
436437#if LIBCURL_VERSION_NUM >= 0x074200
437- // only avaliable with curl_multi_poll
438+ // only avaliable with curl_multi_poll, because curl_multi_wait would cause CPU busy,
439+ // curl_multi_wait+sleep could not wakeup quickly
438440 wait_for = self->background_thread_wait_for_ ;
439441#endif
440- if (self->is_shutdown .load (std::memory_order_acquire))
442+ if (self->is_shutdown_ .load (std::memory_order_acquire))
441443 {
442- wait_for = std::chrono::milliseconds{ 0 } ;
444+ wait_for = std::chrono::milliseconds::zero () ;
443445 }
444446
445447 if (now - last_free_job_timepoint < wait_for)
@@ -541,7 +543,7 @@ void HttpClient::SetBackgroundWaitFor(std::chrono::milliseconds ms)
541543
542544void HttpClient::WaitBackgroundThreadExit ()
543545{
544- is_shutdown .store (true , std::memory_order_release);
546+ is_shutdown_ .store (true , std::memory_order_release);
545547 std::unique_ptr<std::thread> background_thread;
546548 {
547549 std::lock_guard<std::mutex> lock_guard{background_thread_m_};
@@ -552,7 +554,7 @@ void HttpClient::WaitBackgroundThreadExit()
552554 {
553555 background_thread->join ();
554556 }
555- is_shutdown .store (false , std::memory_order_release);
557+ is_shutdown_ .store (false , std::memory_order_release);
556558}
557559
558560void HttpClient::wakeupBackgroundThread ()
0 commit comments