diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 539b1fd7..3e04ddf5 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -8,6 +8,11 @@ #ifndef FMT_FORMAT_INL_H_ #define FMT_FORMAT_INL_H_ +#ifdef __SANITIZE_THREAD__ +extern "C" void __tsan_acquire(void*); +extern "C" void __tsan_release(void*); +#endif + #ifndef FMT_MODULE # include // ptrdiff_t @@ -1696,6 +1701,9 @@ class file_print_buffer::value>> public: explicit file_print_buffer(F* f) : buffer(grow, size_t()), file_(f) { flockfile(f); +#ifdef __SANITIZE_THREAD__ + __tsan_acquire(f); +#endif file_.init_buffer(); auto buf = file_.get_write_buffer(); set(buf.data, buf.size); @@ -1703,7 +1711,10 @@ class file_print_buffer::value>> ~file_print_buffer() { file_.advance_write_buffer(size()); bool flush = file_.needs_flush(); - F* f = file_; // Make funlockfile depend on the template parameter F + F* f = file_; // Make funlockfile depend on the template parameter F. +#ifdef __SANITIZE_THREAD__ + __tsan_release(f); +#endif funlockfile(f); // for the system API detection to work. if (flush) fflush(file_); }