From 46ffdf3bbd65941a229f48a1c441b7ee3f348435 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 24 Apr 2012 17:51:36 +0000 Subject: Take the spinlock around clearing of the fp->_flags in fclose(3), which indicates the avaliability of FILE, to prevent possible reordering of the writes as seen by other CPUs. Reported by: Fengwei yin Reviewed by: jhb MFC after: 1 week --- lib/libc/include/libc_private.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/libc/include') diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index d4b24a7c962eb..2182f4689719e 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -81,6 +81,19 @@ void _rtld_error(const char *fmt, ...); #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) #define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) +struct _spinlock; +extern struct _spinlock __stdio_thread_lock; +#define STDIO_THREAD_LOCK() \ +do { \ + if (__isthreaded) \ + _SPINLOCK(&__stdio_thread_lock); \ +} while (0) +#define STDIO_THREAD_UNLOCK() \ +do { \ + if (__isthreaded) \ + _SPINUNLOCK(&__stdio_thread_lock); \ +} while (0) + /* * Indexes into the pthread jump table. * -- cgit v1.3