mirror of
				https://sourceware.org/git/glibc.git
				synced 2025-11-02 09:33:31 +03:00 
			
		
		
		
	_IO_MTSAFE_IO controls whether stdio is *built* with support for
multithreading.  In the distant past it might also have worked as a
feature selection macro, allowing library *users* to select
thread-safe or lock-free stdio at application build time, I haven't
done the archaeology.  Nowadays, defining _IO_MTSAFE_IO while using
the installed headers, or in _ISOMAC mode, will cause libio.h to throw
syntax errors.
This patch removes _IO_MTSAFE_IO from the public headers
(specifically, from libio/libio.h).  The most important thing it
controlled in there was whether libio.h defines _IO_lock_t itself or
expects stdio-lock.h to have done it, and we do still need a
inter-header communication macro for that, because stdio-lock.h can
only define _IO_lock_t as a typedef.  I've invented
_IO_lock_t_defined, which is defined by both versions of stdio-lock.h.
_IO_MTSAFE_IO also controlled the definitions of a handful of macros
that _might_ count as part of the public libio.h interface.  They are
now unconditionally given their non-_IO_MTSAFE_IO definition in
libio/libio.h, and include/libio.h redefines them with the
_IO_MTSAFE_IO definition.  This should minimize the odds of breaking
old software that actually uses those macros.
I suspect that this entire mechanism is vestigial, and that glibc
won't build anymore if you *don't* define _IO_MTSAFE_IO, but that's
another patchset.  The bulk of libio.h is internal-use-only stuff that
no longer makes sense to expose (libstdc++ gave up on making a FILE
the same object as a C++ filebuf *decades* ago) but that, too, is
another patchset.
	* libio/libio.h: Condition dummy definition of _IO_lock_t on
	_IO_lock_t_defined, not _IO_MTSAFE_IO. Unconditionally use the
	non-_IO_MTSAFE_IO definitions for _IO_peekc, _IO_flockfile,
	_IO_funlockfile, and _IO_ftrylockfile.  Only define
	_IO_cleanup_region_start and _IO_cleanup_region_end if not
	already defined.
	* include/libio.h: If _IO_MTSAFE_IO is defined, redefine
        _IO_peekc, _IO_flockfile, _IO_funlockfile, and _IO_ftrylockfile
        appropriately.
	* sysdeps/generic/stdio-lock.h, sysdeps/nptl/stdio-lock.h:
	Define _IO_lock_t_defined after defining _IO_lock_t.
		
	
		
			
				
	
	
		
			112 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* Thread package specific definitions of stream lock type.  NPTL version.
 | 
						|
   Copyright (C) 2000-2017 Free Software Foundation, Inc.
 | 
						|
   This file is part of the GNU C Library.
 | 
						|
 | 
						|
   The GNU C Library is free software; you can redistribute it and/or
 | 
						|
   modify it under the terms of the GNU Lesser General Public
 | 
						|
   License as published by the Free Software Foundation; either
 | 
						|
   version 2.1 of the License, or (at your option) any later version.
 | 
						|
 | 
						|
   The GNU C Library is distributed in the hope that it will be useful,
 | 
						|
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
						|
   Lesser General Public License for more details.
 | 
						|
 | 
						|
   You should have received a copy of the GNU Lesser General Public
 | 
						|
   License along with the GNU C Library; if not, see
 | 
						|
   <http://www.gnu.org/licenses/>.  */
 | 
						|
 | 
						|
#ifndef _STDIO_LOCK_H
 | 
						|
#define _STDIO_LOCK_H 1
 | 
						|
 | 
						|
#include <libc-lock.h>
 | 
						|
#include <lowlevellock.h>
 | 
						|
 | 
						|
 | 
						|
/* The locking here is very inexpensive, even for inlining.  */
 | 
						|
#define _IO_lock_inexpensive	1
 | 
						|
 | 
						|
typedef struct { int lock; int cnt; void *owner; } _IO_lock_t;
 | 
						|
#define _IO_lock_t_defined 1
 | 
						|
 | 
						|
#define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL }
 | 
						|
 | 
						|
#define _IO_lock_init(_name) \
 | 
						|
  ((void) ((_name) = (_IO_lock_t) _IO_lock_initializer))
 | 
						|
 | 
						|
#define _IO_lock_fini(_name) \
 | 
						|
  ((void) 0)
 | 
						|
 | 
						|
#define _IO_lock_lock(_name) \
 | 
						|
  do {									      \
 | 
						|
    void *__self = THREAD_SELF;						      \
 | 
						|
    if ((_name).owner != __self)					      \
 | 
						|
      {									      \
 | 
						|
	lll_lock ((_name).lock, LLL_PRIVATE);				      \
 | 
						|
        (_name).owner = __self;						      \
 | 
						|
      }									      \
 | 
						|
    ++(_name).cnt;							      \
 | 
						|
  } while (0)
 | 
						|
 | 
						|
#define _IO_lock_trylock(_name) \
 | 
						|
  ({									      \
 | 
						|
    int __result = 0;							      \
 | 
						|
    void *__self = THREAD_SELF;						      \
 | 
						|
    if ((_name).owner != __self)					      \
 | 
						|
      {									      \
 | 
						|
        if (lll_trylock ((_name).lock) == 0)				      \
 | 
						|
          {								      \
 | 
						|
            (_name).owner = __self;					      \
 | 
						|
            (_name).cnt = 1;						      \
 | 
						|
          }								      \
 | 
						|
        else								      \
 | 
						|
          __result = EBUSY;						      \
 | 
						|
      }									      \
 | 
						|
    else								      \
 | 
						|
      ++(_name).cnt;							      \
 | 
						|
    __result;								      \
 | 
						|
  })
 | 
						|
 | 
						|
#define _IO_lock_unlock(_name) \
 | 
						|
  do {									      \
 | 
						|
    if (--(_name).cnt == 0)						      \
 | 
						|
      {									      \
 | 
						|
        (_name).owner = NULL;						      \
 | 
						|
	lll_unlock ((_name).lock, LLL_PRIVATE);				      \
 | 
						|
      }									      \
 | 
						|
  } while (0)
 | 
						|
 | 
						|
 | 
						|
 | 
						|
#define _IO_cleanup_region_start(_fct, _fp) \
 | 
						|
  __libc_cleanup_region_start (((_fp)->_flags & _IO_USER_LOCK) == 0, _fct, _fp)
 | 
						|
#define _IO_cleanup_region_start_noarg(_fct) \
 | 
						|
  __libc_cleanup_region_start (1, _fct, NULL)
 | 
						|
#define _IO_cleanup_region_end(_doit) \
 | 
						|
  __libc_cleanup_region_end (_doit)
 | 
						|
 | 
						|
#if defined _LIBC && IS_IN (libc)
 | 
						|
 | 
						|
# ifdef __EXCEPTIONS
 | 
						|
#  define _IO_acquire_lock(_fp) \
 | 
						|
  do {									      \
 | 
						|
    _IO_FILE *_IO_acquire_lock_file					      \
 | 
						|
	__attribute__((cleanup (_IO_acquire_lock_fct)))			      \
 | 
						|
	= (_fp);							      \
 | 
						|
    _IO_flockfile (_IO_acquire_lock_file);
 | 
						|
#  define _IO_acquire_lock_clear_flags2(_fp) \
 | 
						|
  do {									      \
 | 
						|
    _IO_FILE *_IO_acquire_lock_file					      \
 | 
						|
	__attribute__((cleanup (_IO_acquire_lock_clear_flags2_fct)))	      \
 | 
						|
	= (_fp);							      \
 | 
						|
    _IO_flockfile (_IO_acquire_lock_file);
 | 
						|
# else
 | 
						|
#  define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled
 | 
						|
#  define _IO_acquire_lock_clear_flags2(_fp) _IO_acquire_lock (_fp)
 | 
						|
# endif
 | 
						|
# define _IO_release_lock(_fp) ; } while (0)
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* stdio-lock.h */
 |