mirror of
https://github.com/fmtlib/fmt.git
synced 2026-04-30 19:09:22 +08:00
Fix false positive in tsan (fixes #4755)
This commit is contained in:
parent
eeff8680ed
commit
432fda7bfa
@ -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 <stddef.h> // ptrdiff_t
|
||||
|
||||
@ -1696,6 +1701,9 @@ class file_print_buffer<F, enable_if_t<has_flockfile<F>::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<F, enable_if_t<has_flockfile<F>::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_);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user