@@ -322,25 +322,16 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
322322
323323 inline CURLM *GetMultiHandle () noexcept { return multi_handle_; }
324324
325- void MaybeSpawnBackgroundThread ();
325+ // return true if create background thread, false is already exist background thread
326+ bool MaybeSpawnBackgroundThread ();
326327
327328 void ScheduleAddSession (uint64_t session_id);
328329 void ScheduleAbortSession (uint64_t session_id);
329330 void ScheduleRemoveSession (uint64_t session_id, HttpCurlEasyResource &&resource);
330331
331- void WaitBackgroundThreadExit ()
332- {
333- std::unique_ptr<std::thread> background_thread;
334- {
335- std::lock_guard<std::mutex> lock_guard{background_thread_m_};
336- background_thread.swap (background_thread_);
337- }
332+ void SetBackgroundWaitFor (std::chrono::milliseconds ms);
338333
339- if (background_thread && background_thread->joinable ())
340- {
341- background_thread->join ();
342- }
343- }
334+ void WaitBackgroundThreadExit ();
344335
345336private:
346337 void wakeupBackgroundThread ();
@@ -366,6 +357,9 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
366357 std::unique_ptr<std::thread> background_thread_;
367358 std::chrono::milliseconds scheduled_delay_milliseconds_;
368359
360+ std::chrono::milliseconds background_thread_wait_for_;
361+ std::atomic<bool > is_shutdown_{false };
362+
369363 nostd::shared_ptr<HttpCurlGlobalInitializer> curl_global_initializer_;
370364};
371365
0 commit comments