@@ -47,6 +47,28 @@ namespace client
47
47
namespace curl
48
48
{
49
49
50
+ class HttpOperationAccessor
51
+ {
52
+ public:
53
+ OPENTELEMETRY_SANITIZER_NO_THREAD static std::thread::id GetThreadId (
54
+ const HttpOperation::AsyncData &async_data)
55
+ {
56
+ #if !(defined(OPENTELEMETRY_HAVE_THREAD_SANITIZER) && OPENTELEMETRY_HAVE_THREAD_SANITIZER)
57
+ std::atomic_thread_fence (std::memory_order_acquire);
58
+ #endif
59
+ return async_data.callback_thread ;
60
+ }
61
+
62
+ OPENTELEMETRY_SANITIZER_NO_THREAD static void SetThreadId (HttpOperation::AsyncData &async_data,
63
+ std::thread::id thread_id)
64
+ {
65
+ async_data.callback_thread = thread_id;
66
+ #if !(defined(OPENTELEMETRY_HAVE_THREAD_SANITIZER) && OPENTELEMETRY_HAVE_THREAD_SANITIZER)
67
+ std::atomic_thread_fence (std::memory_order_release);
68
+ #endif
69
+ }
70
+ };
71
+
50
72
size_t HttpOperation::WriteMemoryCallback (void *contents, size_t size, size_t nmemb, void *userp)
51
73
{
52
74
HttpOperation *self = reinterpret_cast <HttpOperation *>(userp);
@@ -335,7 +357,7 @@ HttpOperation::~HttpOperation()
335
357
case opentelemetry::ext::http::client::SessionState::Sending: {
336
358
if (async_data_ && async_data_->result_future .valid ())
337
359
{
338
- if (async_data_-> callback_thread != std::this_thread::get_id ())
360
+ if (HttpOperationAccessor::GetThreadId (* async_data_) != std::this_thread::get_id ())
339
361
{
340
362
async_data_->result_future .wait ();
341
363
last_curl_result_ = async_data_->result_future .get ();
@@ -360,7 +382,7 @@ void HttpOperation::Finish()
360
382
if (async_data_ && async_data_->result_future .valid ())
361
383
{
362
384
// We should not wait in callback from Cleanup()
363
- if (async_data_-> callback_thread != std::this_thread::get_id ())
385
+ if (HttpOperationAccessor::GetThreadId (* async_data_) != std::this_thread::get_id ())
364
386
{
365
387
async_data_->result_future .wait ();
366
388
last_curl_result_ = async_data_->result_future .get ();
@@ -412,9 +434,9 @@ void HttpOperation::Cleanup()
412
434
callback.swap (async_data_->callback );
413
435
if (callback)
414
436
{
415
- async_data_-> callback_thread = std::this_thread::get_id ();
437
+ HttpOperationAccessor::SetThreadId (* async_data_, std::this_thread::get_id () );
416
438
callback (*this );
417
- async_data_-> callback_thread = std::thread::id ();
439
+ HttpOperationAccessor::SetThreadId (* async_data_, std::thread::id () );
418
440
}
419
441
420
442
// Set value to promise to continue Finish()
0 commit comments