This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bits/stdio-lock.h cleanup


How about this cleanup that lets us define bits/stdio-lock.h entirely in
terms of bits/libc-lock.h?  Ok to check in?


2001-08-23  Roland McGrath  <roland@frob.com>

	* sysdeps/generic/bits/stdio-lock.h (_IO_lock_initializer): Define to
	_LIBC_LOCK_RECURSIVE_INITIALIZER if defined, else do an #error.
	(__libc_cleanup_region_start, __libc_cleanup_region_end,
	__libc_clean_end): Define these to call the cleanup function after
	normal exit when they're supposed to.

	* sysdeps/mach/bits/libc-lock.h (__libc_cleanup_region_start):
	Take new first arg DOIT, a boolean saying whether to really install
	any cleanup handler.
	(__libc_cleanup_region_end): Do nothing if start's DOIT arg was zero.
	(__libc_cleanup_end): Likewise.
	* stdio-common/vfscanf.c (LOCK_STREAM): Pass new arg.
	* stdio-common/vfprintf.c (buffered_vfprintf, vfprintf): Likewise.
	* sysdeps/mach/hurd/bits/stdio-lock.h (_IO_cleanup_region_start):
	Likewise.
	* misc/syslog.c (vsyslog, openlog, closelog): Likewise.
	* sysdeps/generic/bits/stdio-lock.h
	(_IO_cleanup_region_start, _IO_cleanup_region_start_noarg): Likewise.

linuxthreads:

2001-08-23  Roland McGrath  <roland@frob.com>

	* sysdeps/pthread/bits/libc-lock.h (__libc_cleanup_region_start): Take
	new first argument, skip the cleanup handler if it's zero.
	(_LIBC_LOCK_RECURSIVE_INITIALIZER): New macro.
	(__libc_lock_define_initialized_recursive): Use it.
	* sysdeps/pthread/bits/stdio-lock.h: File removed.
	The sysdeps/generic file from the main tree now suffices.



Index: sysdeps/mach/bits/libc-lock.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/bits/libc-lock.h,v
retrieving revision 1.8
diff -u -r1.8 libc-lock.h
--- libc-lock.h	2001/08/04 01:17:57	1.8
+++ libc-lock.h	2001/08/23 08:15:16
@@ -76,21 +76,21 @@
 
 
 /* Start a critical region with a cleanup function */
-#define __libc_cleanup_region_start(FCT, ARG)				    \
+#define __libc_cleanup_region_start(DOIT, FCT, ARG)			    \
 {									    \
-  typeof (***(FCT)) *__save_FCT = FCT;					    \
+  typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0;			    \
   typeof (ARG) __save_ARG = ARG;					    \
   /* close brace is in __libc_cleanup_region_end below. */
 
 /* End a critical region started with __libc_cleanup_region_start. */
 #define __libc_cleanup_region_end(DOIT)					    \
-  if (DOIT)								    \
+  if ((DOIT) && __save_FCT != 0)					    \
     (*__save_FCT)(__save_ARG);						    \
 }
 
 /* Sometimes we have to exit the block in the middle.  */
 #define __libc_cleanup_end(DOIT)					    \
-  if (DOIT)								    \
+  if ((DOIT) && __save_FCT != 0)					    \
     (*__save_FCT)(__save_ARG);						    \
 
 
Index: linuxthreads/sysdeps/pthread/bits/libc-lock.h
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/sysdeps/pthread/bits/libc-lock.h,v
retrieving revision 1.18
diff -u -r1.18 libc-lock.h
--- libc-lock.h	2001/08/23 06:03:10	1.18
+++ libc-lock.h	2001/08/23 08:15:16
@@ -72,8 +72,10 @@
 
 /* Define an initialized recursive lock variable NAME with storage
    class CLASS.  */
-#define __libc_lock_define_initialized_recursive(CLS,NAME) \
-  CLS __libc_lock_recursive_t NAME = {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP};
+#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
+  CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
+#define _LIBC_LOCK_RECURSIVE_INITIALIZER \
+  {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
 
 /* Initialize the named lock variable, leaving it in a consistent, unlocked
    state.  */
@@ -164,9 +166,9 @@
 
 
 /* Start critical region with cleanup.  */
-#define __libc_cleanup_region_start(FCT, ARG) \
+#define __libc_cleanup_region_start(DOIT, FCT, ARG) \
   { struct _pthread_cleanup_buffer _buffer;				      \
-    int _avail = _pthread_cleanup_push_defer != NULL;			      \
+    int _avail = (DOIT) && _pthread_cleanup_push_defer != NULL;		      \
     if (_avail) {							      \
       _pthread_cleanup_push_defer (&_buffer, (FCT), (ARG));		      \
     }
cvs server: linuxthreads/sysdeps/pthread/bits/stdio-lock.h was removed, no comparison available
Index: stdio-common/vfprintf.c
===================================================================
RCS file: /cvs/glibc/libc/stdio-common/vfprintf.c,v
retrieving revision 1.102
diff -u -r1.102 vfprintf.c
--- vfprintf.c	2001/08/17 04:45:43	1.102
+++ vfprintf.c	2001/08/23 08:15:17
@@ -1296,10 +1296,10 @@
 
   /* Lock stream.  */
 #ifdef USE_IN_LIBIO
-  __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, s);
+  __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, s);
   _IO_flockfile (s);
 #else
-  __libc_cleanup_region_start ((void (*) (void *)) &__funlockfile, s);
+  __libc_cleanup_region_start (1, (void (*) (void *)) &__funlockfile, s);
   __flockfile (s);
 #endif
 
@@ -2086,7 +2086,7 @@
   result = vfprintf (hp, format, args);
 
   /* Lock stream.  */
-  __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, s);
+  __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, s);
   _IO_flockfile (s);
 
   /* Now flush anything from the helper to the S. */
Index: stdio-common/vfscanf.c
===================================================================
RCS file: /cvs/glibc/libc/stdio-common/vfscanf.c,v
retrieving revision 1.95
diff -u -r1.95 vfscanf.c
--- vfscanf.c	2001/08/22 18:29:02	1.95
+++ vfscanf.c	2001/08/23 08:15:19
@@ -168,7 +168,7 @@
 	}								      \
     } while (0)
 # define LOCK_STREAM(S)							      \
-  __libc_cleanup_region_start ((void (*) (void *)) &_IO_funlockfile, (S));    \
+  __libc_cleanup_region_start (1, (void (*) (void *)) &_IO_funlockfile, (S)); \
   _IO_flockfile (S)
 # define UNLOCK_STREAM(S)						      \
   _IO_funlockfile (S);							      \
Index: sysdeps/generic/bits/libc-lock.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/bits/libc-lock.h,v
retrieving revision 1.5
diff -u -r1.5 libc-lock.h
--- libc-lock.h	2001/08/23 06:02:40	1.5
+++ libc-lock.h	2001/08/23 08:15:19
@@ -94,14 +94,23 @@
   } while (0)
 
 
-/* Start critical region with cleanup.  */
-#define __libc_cleanup_region_start(FCT, ARG)
+/* Start a critical region with a cleanup function */
+#define __libc_cleanup_region_start(DOIT, FCT, ARG)			    \
+{									    \
+  typeof (***(FCT)) *__save_FCT = (DOIT) ? (FCT) : 0;			    \
+  typeof (ARG) __save_ARG = ARG;					    \
+  /* close brace is in __libc_cleanup_region_end below. */
 
-/* End critical region with cleanup.  */
-#define __libc_cleanup_region_end(DOIT)
+/* End a critical region started with __libc_cleanup_region_start. */
+#define __libc_cleanup_region_end(DOIT)					    \
+  if ((DOIT) && __save_FCT != 0)					    \
+    (*__save_FCT)(__save_ARG);						    \
+}
 
 /* Sometimes we have to exit the block in the middle.  */
-#define __libc_cleanup_end(DOIT)
+#define __libc_cleanup_end(DOIT)					    \
+  if ((DOIT) && __save_FCT != 0)					    \
+    (*__save_FCT)(__save_ARG);						    \
 
 
 /* We need portable names for some of the functions.  */
Index: sysdeps/generic/bits/stdio-lock.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/bits/stdio-lock.h,v
retrieving revision 1.5
diff -u -r1.5 stdio-lock.h
--- stdio-lock.h	2001/08/23 06:02:40	1.5
+++ stdio-lock.h	2001/08/23 08:15:19
@@ -1,4 +1,4 @@
-/* Thread package specific definitions of stream lock type.  Stub version.
+/* Thread package specific definitions of stream lock type.  Generic version.
    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -25,8 +25,11 @@
 __libc_lock_define_recursive (typedef, _IO_lock_t)
 
 /* We need recursive (counting) mutexes.  */
-#define _IO_lock_initializer ...
-#error libio needs recursive mutexes for _IO_MTSAFE_IO
+#ifdef _LIBC_LOCK_RECURSIVE_INITIALIZER
+# define _IO_lock_initializer _LIBC_LOCK_RECURSIVE_INITIALIZER
+#elif _IO_MTSAFE_IO
+ #error libio needs recursive mutexes for _IO_MTSAFE_IO
+#endif
 
 #define _IO_lock_init(_name)	__libc_lock_init_recursive (_name)
 #define _IO_lock_fini(_name)	__libc_lock_fini_recursive (_name)
@@ -35,11 +38,11 @@
 
 
 #define _IO_cleanup_region_start(_fct, _fp) \
-     __libc_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 (_fct, NULL)
+  __libc_cleanup_region_start (1, _fct, NULL)
 #define _IO_cleanup_region_end(_doit) \
-     __libc_cleanup_region_end (_doit)
+  __libc_cleanup_region_end (_doit)
 
 
 #endif /* bits/stdio-lock.h */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]