diff --git a/compiler-rt/lib/xray/xray_fdr_logging.cpp b/compiler-rt/lib/xray/xray_fdr_logging.cpp --- a/compiler-rt/lib/xray/xray_fdr_logging.cpp +++ b/compiler-rt/lib/xray/xray_fdr_logging.cpp @@ -284,13 +284,12 @@ return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING; } - s32 Result = XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING; - if (!atomic_compare_exchange_strong(&LogFlushStatus, &Result, - XRayLogFlushStatus::XRAY_LOG_FLUSHING, - memory_order_release)) { + if (atomic_exchange(&LogFlushStatus, XRayLogFlushStatus::XRAY_LOG_FLUSHING, + memory_order_release) == + XRayLogFlushStatus::XRAY_LOG_FLUSHING) { if (Verbosity()) - Report("Not flushing log, implementation is still finalizing.\n"); - return static_cast(Result); + Report("Not flushing log, implementation is still flushing.\n"); + return XRayLogFlushStatus::XRAY_LOG_NOT_FLUSHING; } if (BQ == nullptr) { diff --git a/compiler-rt/test/xray/TestCases/Posix/fdr-reinit.cpp b/compiler-rt/test/xray/TestCases/Posix/fdr-reinit.cpp --- a/compiler-rt/test/xray/TestCases/Posix/fdr-reinit.cpp +++ b/compiler-rt/test/xray/TestCases/Posix/fdr-reinit.cpp @@ -49,21 +49,23 @@ auto flush_status = __xray_log_flushLog(); assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED); - // Without doing anything else, we should re-initialize. - init_status = __xray_log_init_mode("xray-fdr", kConfig); - assert(init_status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); + for (auto trial = 0; trial < 3; trial++) { + // Without doing anything else, we should re-initialize. + init_status = __xray_log_init_mode("xray-fdr", kConfig); + assert(init_status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); - // Then we spin for a bit again calling func() enough times. - for (auto i = 0; i < 1 << 20; ++i) - func(); + // Then we spin for a bit again calling func() enough times. + for (auto i = 0; i < 1 << 20; ++i) + func(); - // Then immediately finalize the implementation. - finalize_status = __xray_log_finalize(); - assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED); + // Then immediately finalize the implementation. + finalize_status = __xray_log_finalize(); + assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED); - // Once we're here, we should then flush. - flush_status = __xray_log_flushLog(); - assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED); + // Once we're here, we should then flush. + flush_status = __xray_log_flushLog(); + assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED); + } // Finally, we should signal the sibling thread to stop. keep_going.clear(std::memory_order_release);