public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Unify names of all lock objects
@ 2017-01-30 18:56 Freddie Chopin
  2017-01-30 18:57 ` Freddie Chopin
  0 siblings, 1 reply; 6+ messages in thread
From: Freddie Chopin @ 2017-01-30 18:56 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

Hello!

Second version of the patch to unify names of all lock objects, which
includes Sebastian's suggestion to use better name.

All locks used by newlib (with exception of any code from sys/ folder)
follow this naming pattern: "__<name>_[recursive_]mutex".

As previously - newlib with this patch (and with fixed Thomas' patch,
which I'll send in a moment) can be compiled without issues and works
fine.

Regards,
FCh

[-- Attachment #2: 0001-Unify-names-of-all-lock-objects.patch --]
[-- Type: text/x-patch, Size: 10993 bytes --]

From 3fba105898df4f00b8cbdabf8a46182a55bc3704 Mon Sep 17 00:00:00 2001
From: Freddie Chopin <freddie.chopin@gmail.com>
Date: Sun, 29 Jan 2017 10:27:17 +0100
Subject: [PATCH] Unify names of all lock objects

In preparation for the patch that would allow retargeting of locking
routines, rename all lock objects to follow this pattern:

"__<name>_[recursive_]mutex".

Following locks were renamed:
__dd_hash_lock -> __dd_hash_mutex
__sfp_lock -> __sfp_recursive_mutex
__sinit_lock -> __sinit_recursive_mutex
__atexit_lock -> __atexit_recursive_mutex
_arc4random_mutex -> __arc4random_mutex
__env_lock_object -> __env_recursive_mutex
__malloc_lock_object -> __malloc_recursive_mutex
__atexit_mutex -> __at_quick_exit_mutex
__tz_lock_object -> __tz_mutex
---
 newlib/libc/posix/telldir.c        | 16 ++++++++--------
 newlib/libc/stdio/findfp.c         | 12 ++++++------
 newlib/libc/stdlib/__atexit.c      | 16 ++++++++--------
 newlib/libc/stdlib/__call_atexit.c |  6 +++---
 newlib/libc/stdlib/arc4random.h    |  6 +++---
 newlib/libc/stdlib/envlock.c       |  6 +++---
 newlib/libc/stdlib/mlock.c         |  6 +++---
 newlib/libc/stdlib/quick_exit.c    |  6 +++---
 newlib/libc/time/tzlock.c          |  6 +++---
 9 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/newlib/libc/posix/telldir.c b/newlib/libc/posix/telldir.c
index d4cf4a8c1..0a8eac024 100644
--- a/newlib/libc/posix/telldir.c
+++ b/newlib/libc/posix/telldir.c
@@ -71,7 +71,7 @@ static long	dd_loccnt = 1;	/* Index of entry for sequential readdir's */
 static struct	ddloc *dd_hash[NDIRHASH];   /* Hash list heads for ddlocs */
 
 #ifdef HAVE_DD_LOCK
-__LOCK_INIT(static, __dd_hash_lock);
+__LOCK_INIT(static, __dd_hash_mutex);
 #endif
 
 /*
@@ -92,7 +92,7 @@ _DEFUN(telldir, (dirp),
 
 #ifdef HAVE_DD_LOCK
 	__lock_acquire_recursive(dirp->dd_lock);
-	__lock_acquire(__dd_hash_lock);
+	__lock_acquire(__dd_hash_mutex);
 #endif
 	index = dd_loccnt++;
 	lp->loc_index = index;
@@ -102,7 +102,7 @@ _DEFUN(telldir, (dirp),
 	lp->loc_next = dd_hash[LOCHASH(index)];
 	dd_hash[LOCHASH(index)] = lp;
 #ifdef HAVE_DD_LOCK
-	__lock_release(__dd_hash_lock);
+	__lock_release(__dd_hash_mutex);
 	__lock_release_recursive(dirp->dd_lock);
 #endif
 	return (index);
@@ -124,7 +124,7 @@ _DEFUN(_seekdir, (dirp, loc),
 	struct dirent *dp;
 
 #ifdef HAVE_DD_LOCK
-	__lock_acquire(__dd_hash_lock);
+	__lock_acquire(__dd_hash_mutex);
 #endif
 	if (loc != 0) {
 		prevlp = &dd_hash[LOCHASH(loc)];
@@ -137,7 +137,7 @@ _DEFUN(_seekdir, (dirp, loc),
 		}
 		if (lp == NULL) {
 #ifdef HAVE_DD_LOCK
-			__lock_release(__dd_hash_lock);
+			__lock_release(__dd_hash_mutex);
 #endif
 			return;
 		}
@@ -163,7 +163,7 @@ found:
 		dirp->dd_loc = 0;
 	}
 #ifdef HAVE_DD_LOCK
-	__lock_release(__dd_hash_lock);
+	__lock_release(__dd_hash_mutex);
 #endif
 }
 
@@ -175,7 +175,7 @@ _DEFUN(_cleanupdir, (dirp),
 	int i;
 
 #ifdef HAVE_DD_LOCK
-	__lock_acquire(__dd_hash_lock);
+	__lock_acquire(__dd_hash_mutex);
 #endif
 	for (i = 0; i < NDIRHASH; ++i) {
 		struct ddloc head;
@@ -200,7 +200,7 @@ _DEFUN(_cleanupdir, (dirp),
 		dd_hash[i] = head.loc_next;
 	}
 #ifdef HAVE_DD_LOCK
-	__lock_release(__dd_hash_lock);
+	__lock_release(__dd_hash_mutex);
 #endif
 
 }
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 975a855c2..83d3dc558 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -261,31 +261,31 @@ _DEFUN(__sinit, (s),
 
 #ifndef __SINGLE_THREAD__
 
-__LOCK_INIT_RECURSIVE(static, __sfp_lock);
-__LOCK_INIT_RECURSIVE(static, __sinit_lock);
+__LOCK_INIT_RECURSIVE(static, __sfp_recursive_mutex);
+__LOCK_INIT_RECURSIVE(static, __sinit_recursive_mutex);
 
 _VOID
 _DEFUN_VOID(__sfp_lock_acquire)
 {
-  __lock_acquire_recursive (__sfp_lock);
+  __lock_acquire_recursive (__sfp_recursive_mutex);
 }
 
 _VOID
 _DEFUN_VOID(__sfp_lock_release)
 {
-  __lock_release_recursive (__sfp_lock);
+  __lock_release_recursive (__sfp_recursive_mutex);
 }
 
 _VOID
 _DEFUN_VOID(__sinit_lock_acquire)
 {
-  __lock_acquire_recursive (__sinit_lock);
+  __lock_acquire_recursive (__sinit_recursive_mutex);
 }
 
 _VOID
 _DEFUN_VOID(__sinit_lock_release)
 {
-  __lock_release_recursive (__sinit_lock);
+  __lock_release_recursive (__sinit_recursive_mutex);
 }
 
 /* Walkable file locking routine.  */
diff --git a/newlib/libc/stdlib/__atexit.c b/newlib/libc/stdlib/__atexit.c
index d07f6c122..0f4aeb8a9 100644
--- a/newlib/libc/stdlib/__atexit.c
+++ b/newlib/libc/stdlib/__atexit.c
@@ -48,7 +48,7 @@ const void * __atexit_dummy = &__call_exitprocs;
 #endif
 
 #ifndef __SINGLE_THREAD__
-extern _LOCK_RECURSIVE_T __atexit_lock;
+extern _LOCK_RECURSIVE_T __atexit_recursive_mutex;
 #endif
 
 #ifdef _REENT_GLOBAL_ATEXIT
@@ -74,7 +74,7 @@ _DEFUN (__register_exitproc,
   register struct _atexit *p;
 
 #ifndef __SINGLE_THREAD__
-  __lock_acquire_recursive(__atexit_lock);
+  __lock_acquire_recursive(__atexit_recursive_mutex);
 #endif
 
   p = _GLOBAL_ATEXIT;
@@ -91,7 +91,7 @@ _DEFUN (__register_exitproc,
     {
 #ifndef _ATEXIT_DYNAMIC_ALLOC
 #ifndef __SINGLE_THREAD__
-      __lock_release_recursive(__atexit_lock);
+      __lock_release_recursive(__atexit_recursive_mutex);
 #endif
       return -1;
 #else
@@ -100,7 +100,7 @@ _DEFUN (__register_exitproc,
       if (!malloc)
 	{
 #ifndef __SINGLE_THREAD__
-	  __lock_release_recursive(__atexit_lock);
+	  __lock_release_recursive(__atexit_recursive_mutex);
 #endif
 	  return -1;
 	}
@@ -109,7 +109,7 @@ _DEFUN (__register_exitproc,
       if (p == NULL)
 	{
 #ifndef __SINGLE_THREAD__
-	  __lock_release_recursive(__atexit_lock);
+	  __lock_release_recursive(__atexit_recursive_mutex);
 #endif
 	  return -1;
 	}
@@ -133,7 +133,7 @@ _DEFUN (__register_exitproc,
 	{
 #ifndef _ATEXIT_DYNAMIC_ALLOC
 #ifndef __SINGLE_THREAD__
-	  __lock_release_recursive(__atexit_lock);
+	  __lock_release_recursive(__atexit_recursive_mutex);
 #endif
 	  return -1;
 #else
@@ -143,7 +143,7 @@ _DEFUN (__register_exitproc,
 	  if (args == NULL)
 	    {
 #ifndef __SINGLE_THREAD__
-	      __lock_release(__atexit_lock);
+	      __lock_release(__atexit_recursive_mutex);
 #endif
 	      return -1;
 	    }
@@ -163,7 +163,7 @@ _DEFUN (__register_exitproc,
     }
   p->_fns[p->_ind++] = fn;
 #ifndef __SINGLE_THREAD__
-  __lock_release_recursive(__atexit_lock);
+  __lock_release_recursive(__atexit_recursive_mutex);
 #endif
   return 0;
 }
diff --git a/newlib/libc/stdlib/__call_atexit.c b/newlib/libc/stdlib/__call_atexit.c
index 1e6e71044..7d5e0d046 100644
--- a/newlib/libc/stdlib/__call_atexit.c
+++ b/newlib/libc/stdlib/__call_atexit.c
@@ -11,7 +11,7 @@
 /* Make this a weak reference to avoid pulling in free.  */
 void free(void *) _ATTRIBUTE((__weak__));
 
-__LOCK_INIT_RECURSIVE(, __atexit_lock);
+__LOCK_INIT_RECURSIVE(, __atexit_recursive_mutex);
 
 #ifdef _REENT_GLOBAL_ATEXIT
 struct _atexit *_global_atexit = _NULL;
@@ -75,7 +75,7 @@ _DEFUN (__call_exitprocs, (code, d),
 
 
 #ifndef __SINGLE_THREAD__
-  __lock_acquire_recursive(__atexit_lock);
+  __lock_acquire_recursive(__atexit_recursive_mutex);
 #endif
 
  restart:
@@ -157,7 +157,7 @@ _DEFUN (__call_exitprocs, (code, d),
 #endif
     }
 #ifndef __SINGLE_THREAD__
-  __lock_release_recursive(__atexit_lock);
+  __lock_release_recursive(__atexit_recursive_mutex);
 #endif
 
 }
diff --git a/newlib/libc/stdlib/arc4random.h b/newlib/libc/stdlib/arc4random.h
index 54bcbe8ae..3c5fe2353 100644
--- a/newlib/libc/stdlib/arc4random.h
+++ b/newlib/libc/stdlib/arc4random.h
@@ -39,11 +39,11 @@
 
 #ifndef _ARC4_LOCK_INIT
 
-#define _ARC4_LOCK_INIT __LOCK_INIT(static, _arc4random_mutex);
+#define _ARC4_LOCK_INIT __LOCK_INIT(static, __arc4random_mutex);
 
-#define _ARC4_LOCK() __lock_acquire(_arc4random_mutex)
+#define _ARC4_LOCK() __lock_acquire(__arc4random_mutex)
 
-#define _ARC4_UNLOCK() __lock_release(_arc4random_mutex)
+#define _ARC4_UNLOCK() __lock_release(__arc4random_mutex)
 
 #endif /* _ARC4_LOCK_INIT */
 
diff --git a/newlib/libc/stdlib/envlock.c b/newlib/libc/stdlib/envlock.c
index ce7ae2e26..410a28a9c 100644
--- a/newlib/libc/stdlib/envlock.c
+++ b/newlib/libc/stdlib/envlock.c
@@ -39,7 +39,7 @@ that it already holds.
 #include <sys/lock.h>
 
 #ifndef __SINGLE_THREAD__
-__LOCK_INIT_RECURSIVE(static, __env_lock_object);
+__LOCK_INIT_RECURSIVE(static, __env_recursive_mutex);
 #endif
 
 void
@@ -47,7 +47,7 @@ __env_lock (ptr)
      struct _reent *ptr;
 {
 #ifndef __SINGLE_THREAD__
-  __lock_acquire_recursive (__env_lock_object);
+  __lock_acquire_recursive (__env_recursive_mutex);
 #endif
 }
 
@@ -56,6 +56,6 @@ __env_unlock (ptr)
      struct _reent *ptr;
 {
 #ifndef __SINGLE_THREAD__
-  __lock_release_recursive (__env_lock_object);
+  __lock_release_recursive (__env_recursive_mutex);
 #endif
 }
diff --git a/newlib/libc/stdlib/mlock.c b/newlib/libc/stdlib/mlock.c
index 888c986a9..4c392947d 100644
--- a/newlib/libc/stdlib/mlock.c
+++ b/newlib/libc/stdlib/mlock.c
@@ -40,7 +40,7 @@ that it already holds.
 #include <sys/lock.h>
 
 #ifndef __SINGLE_THREAD__
-__LOCK_INIT_RECURSIVE(static, __malloc_lock_object);
+__LOCK_INIT_RECURSIVE(static, __malloc_recursive_mutex);
 #endif
 
 void
@@ -48,7 +48,7 @@ __malloc_lock (ptr)
      struct _reent *ptr;
 {
 #ifndef __SINGLE_THREAD__
-  __lock_acquire_recursive (__malloc_lock_object);
+  __lock_acquire_recursive (__malloc_recursive_mutex);
 #endif
 }
 
@@ -57,7 +57,7 @@ __malloc_unlock (ptr)
      struct _reent *ptr;
 {
 #ifndef __SINGLE_THREAD__
-  __lock_release_recursive (__malloc_lock_object);
+  __lock_release_recursive (__malloc_recursive_mutex);
 #endif
 }
 
diff --git a/newlib/libc/stdlib/quick_exit.c b/newlib/libc/stdlib/quick_exit.c
index 34f41b737..aaa5f9f7f 100644
--- a/newlib/libc/stdlib/quick_exit.c
+++ b/newlib/libc/stdlib/quick_exit.c
@@ -44,7 +44,7 @@ struct quick_exit_handler {
 /**
  * Lock protecting the handlers list.
  */
-__LOCK_INIT(static, __atexit_mutex);
+__LOCK_INIT(static, __at_quick_exit_mutex);
 /**
  * Stack of cleanup handlers.  These will be invoked in reverse order when
  */
@@ -60,10 +60,10 @@ at_quick_exit(void (*func)(void))
 	if (NULL == h)
 		return (1);
 	h->cleanup = func;
-	__lock_acquire(__atexit_mutex);
+	__lock_acquire(__at_quick_exit_mutex);
 	h->next = handlers;
 	handlers = h;
-	__lock_release(__atexit_mutex);
+	__lock_release(__at_quick_exit_mutex);
 	return (0);
 }
 
diff --git a/newlib/libc/time/tzlock.c b/newlib/libc/time/tzlock.c
index ccfef7891..5ac42d7f4 100644
--- a/newlib/libc/time/tzlock.c
+++ b/newlib/libc/time/tzlock.c
@@ -36,14 +36,14 @@ until the corresponding <<__tz_unlock>> call on the same thread is made.
 #include <sys/lock.h>
 
 #ifndef __SINGLE_THREAD__
-__LOCK_INIT(static, __tz_lock_object);
+__LOCK_INIT(static, __tz_mutex);
 #endif
 
 _VOID
 _DEFUN_VOID (__tz_lock)
 {
 #ifndef __SINGLE_THREAD__
-  __lock_acquire(__tz_lock_object);
+  __lock_acquire(__tz_mutex);
 #endif
 }
 
@@ -51,6 +51,6 @@ _VOID
 _DEFUN_VOID (__tz_unlock)
 {
 #ifndef __SINGLE_THREAD__
-  __lock_release(__tz_lock_object);
+  __lock_release(__tz_mutex);
 #endif
 }
-- 
2.11.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Unify names of all lock objects
  2017-01-30 18:56 [PATCH v2] Unify names of all lock objects Freddie Chopin
@ 2017-01-30 18:57 ` Freddie Chopin
  2017-01-31 10:30   ` Thomas Preudhomme
  2017-02-06 10:49   ` Freddie Chopin
  0 siblings, 2 replies; 6+ messages in thread
From: Freddie Chopin @ 2017-01-30 18:57 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 130 bytes --]

Most recent patch from Thomas' that adds lock retargeting, with changed
names of objects to work on top of my patch.

Regards,
FCh

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 19485 bytes --]

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe06bfc795d94ba36d0061e4f8135146125..de28c25b3c4aaeed14b6d0ee8354fdd5c5c3115a 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038c7f495d32d05ae8caff0172f464895ffe..354c07ca580edf75da59fb858ca2c434e0b1a4e9 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1bf703f388ecd3b4e0d8bef6786f7995021..dabe44fd98d74a2e029a22a217953dd52575736f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb8815be44fb1e92f753fa2c8df2a31b95f94..ac25a3933c4a4794f3cfe291e0275d0ed001b96a 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index 9075e35c9179968031010432515e3a845ff6ca8d..9a8e2528c79a89d5807da8c4bb0e65151870bf42 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#ifndef _RETARGETABLE_LOCKING
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #define __LOCK_INIT(class,lock) static int lock = 0;
 #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
@@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _lock;
+typedef struct _lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct _lock _lock_ ## lock; \
+	class _LOCK_T lock = &_lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RETARGETABLE_LOCKING */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55f53ca87ba55f3a676b213e55fa66e77aa..7571ef26335c053315ad3f3df428a4742a9cf368 100644
--- a/newlib/libc/misc/Makefile.am
+++ b/newlib/libc/misc/Makefile.am
@@ -6,6 +6,11 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
 
 LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c
 
+if NEWLIB_RETARGETABLE_LOCKING
+LIB_SOURCES += \
+	lock.c
+endif
+
 libmisc_la_LDFLAGS = -Xcompiler -nostdlib
 
 if USE_LIBTOOL
@@ -21,5 +26,5 @@ endif # USE_LIBTOOL
 
 include $(srcdir)/../../Makefile.shared
 
-CHEWOUT_FILES = unctrl.def ffs.def
+CHEWOUT_FILES = unctrl.def lock.def ffs.def
 CHAPTERS = misc.tex
diff --git a/newlib/libc/misc/Makefile.in b/newlib/libc/misc/Makefile.in
index 0ada8de34e7a3a6084dbab4bfa7caf8cb7f8d8f3..e7925231c203897d917f41accf6560e3336895bc 100644
--- a/newlib/libc/misc/Makefile.in
+++ b/newlib/libc/misc/Makefile.in
@@ -53,6 +53,9 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
+@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__append_1 = \
+@NEWLIB_RETARGETABLE_LOCKING_TRUE@	lock.c
+
 DIST_COMMON = $(srcdir)/../../Makefile.shared $(srcdir)/Makefile.in \
 	$(srcdir)/Makefile.am
 subdir = misc
@@ -72,14 +75,19 @@ LIBRARIES = $(noinst_LIBRARIES)
 ARFLAGS = cru
 lib_a_AR = $(AR) $(ARFLAGS)
 lib_a_LIBADD =
-am__objects_1 = lib_a-__dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \
-	lib_a-ffs.$(OBJEXT) lib_a-init.$(OBJEXT) lib_a-fini.$(OBJEXT)
-@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1)
+@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__objects_1 =  \
+@NEWLIB_RETARGETABLE_LOCKING_TRUE@	lib_a-lock.$(OBJEXT)
+am__objects_2 = lib_a-__dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \
+	lib_a-ffs.$(OBJEXT) lib_a-init.$(OBJEXT) lib_a-fini.$(OBJEXT) \
+	$(am__objects_1)
+@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_2)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libmisc_la_LIBADD =
-am__objects_2 = __dprintf.lo unctrl.lo ffs.lo init.lo fini.lo
-@USE_LIBTOOL_TRUE@am_libmisc_la_OBJECTS = $(am__objects_2)
+@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__objects_3 = lock.lo
+am__objects_4 = __dprintf.lo unctrl.lo ffs.lo init.lo fini.lo \
+	$(am__objects_3)
+@USE_LIBTOOL_TRUE@am_libmisc_la_OBJECTS = $(am__objects_4)
 libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS)
 libmisc_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@@ -252,7 +260,7 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 AUTOMAKE_OPTIONS = cygnus
 INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c
+LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c $(am__append_1)
 libmisc_la_LDFLAGS = -Xcompiler -nostdlib
 @USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libmisc.la
 @USE_LIBTOOL_TRUE@libmisc_la_SOURCES = $(LIB_SOURCES)
@@ -271,7 +279,7 @@ DOCBOOK_CHEW = ${top_srcdir}/../doc/makedocbook.py
 DOCBOOK_OUT_FILES = $(CHEWOUT_FILES:.def=.xml)
 DOCBOOK_CHAPTERS = $(CHAPTERS:.tex=.xml)
 CLEANFILES = $(CHEWOUT_FILES) $(CHEWOUT_FILES:.def=.ref) $(DOCBOOK_OUT_FILES)
-CHEWOUT_FILES = unctrl.def ffs.def
+CHEWOUT_FILES = unctrl.def lock.def ffs.def
 CHAPTERS = misc.tex
 all: all-am
 
@@ -372,6 +380,12 @@ lib_a-fini.o: fini.c
 lib_a-fini.obj: fini.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fini.obj `if test -f 'fini.c'; then $(CYGPATH_W) 'fini.c'; else $(CYGPATH_W) '$(srcdir)/fini.c'; fi`
 
+lib_a-lock.o: lock.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lock.o `test -f 'lock.c' || echo '$(srcdir)/'`lock.c
+
+lib_a-lock.obj: lock.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lock.obj `if test -f 'lock.c'; then $(CYGPATH_W) 'lock.c'; else $(CYGPATH_W) '$(srcdir)/lock.c'; fi`
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
diff --git a/newlib/libc/misc/lock.c b/newlib/libc/misc/lock.c
new file mode 100644
index 0000000000000000000000000000000000000000..1c69575b33f666c8170c2fe8473ad428f2741137
--- /dev/null
+++ b/newlib/libc/misc/lock.c
@@ -0,0 +1,149 @@
+/*
+FUNCTION
+<<__retarget_lock_init>>, <<__retarget_lock_init_recursive>>, <<__retarget_lock_close>>, <<__retarget_lock_close_recursive>>, <<__retarget_lock_acquire>>, <<__retarget_lock_acquire_recursive>>, <<__retarget_lock_try_acquire>>, <<__retarget_lock_try_acquire_recursive>>, <<__retarget_lock_release>>, <<__retarget_lock_release_recursive>>---locking routines
+
+INDEX
+	_lock___sinit_recursive_mutex
+INDEX
+	_lock___sfp_recursive_mutex
+INDEX
+	_lock___atexit_recursive_mutex
+INDEX
+	_lock___at_quick_exit_mutex
+INDEX
+	_lock___malloc_recursive_mutex
+INDEX
+	_lock___env_recursive_mutex
+INDEX
+	_lock___tz_mutex
+INDEX
+	_lock___dd_hash_mutex
+
+INDEX
+	__retarget_lock_init
+INDEX
+	__retarget_lock_init_recursive
+INDEX
+	__retarget_lock_close
+INDEX
+	__retarget_lock_close_recursive
+INDEX
+	__retarget_lock_acquire
+INDEX
+	__retarget_lock_acquire_recursive
+INDEX
+	__retarget_lock_try_acquire
+INDEX
+	__retarget_lock_try_acquire_recursive
+INDEX
+	__retarget_lock_release
+INDEX
+	__retarget_lock_release_recursive
+
+ANSI_SYNOPSIS
+	#include <lock.h>
+	struct _lock _lock___sinit_recursive_mutex;
+	struct _lock _lock___sfp_recursive_mutex;
+	struct _lock _lock___atexit_recursive_mutex;
+	struct _lock _lock___at_quick_exit_mutex;
+	struct _lock _lock___malloc_recursive_mutex;
+	struct _lock _lock___env_recursive_mutex;
+	struct _lock _lock___tz_mutex;
+	struct _lock _lock___dd_hash_mutex;
+
+	void __retarget_lock_init (_LOCK_T * <[lock_ptr]>);
+	void __retarget_lock_init_recursive (_LOCK_T * <[lock_ptr]>);
+	void __retarget_lock_close (_LOCK_T <[lock]>);
+	void __retarget_lock_close_recursive (_LOCK_T <[lock]>);
+	void __retarget_lock_acquire (_LOCK_T <[lock]>);
+	void __retarget_lock_acquire_recursive (_LOCK_T <[lock]>);
+	int __retarget_lock_try_acquire (_LOCK_T <[lock]>);
+	int __retarget_lock_try_acquire_recursive (_LOCK_T <[lock]>);
+	void __retarget_lock_release (_LOCK_T <[lock]>);
+	void __retarget_lock_release_recursive (_LOCK_T <[lock]>);
+
+DESCRIPTION
+Newlib was configured to allow the target platform to provide the locking
+routines and static locks at link time.  As such, a dummy default
+implementation of these routines and static locks is provided for
+single-threaded application to link successfully out of the box on bare-metal
+systems.
+
+For multi-threaded applications the target platform is required to provide
+an implementation for @strong{all} these routines and static locks.  If some
+routines or static locks are missing, the link will fail with doubly defined
+symbols.
+
+PORTABILITY
+These locking routines and static lock are newlib-specific.  Supporting OS
+subroutines are required for linking multi-threaded applications.
+*/
+
+/* dummy lock routines and static locks for single-threaded apps */
+
+#include <sys/lock.h>
+
+struct _lock {
+  char unused;
+};
+
+struct _lock _lock___sinit_recursive_mutex;
+struct _lock _lock___sfp_recursive_mutex;
+struct _lock _lock___atexit_recursive_mutex;
+struct _lock _lock___at_quick_exit_mutex;
+struct _lock _lock___malloc_recursive_mutex;
+struct _lock _lock___env_recursive_mutex;
+struct _lock _lock___tz_mutex;
+struct _lock _lock___dd_hash_mutex;
+
+void
+__retarget_lock_init (_LOCK_T *lock)
+{
+}
+
+void
+__retarget_lock_init_recursive(_LOCK_T *lock)
+{
+}
+
+void
+__retarget_lock_close(_LOCK_T lock)
+{
+}
+
+void
+__retarget_lock_close_recursive(_LOCK_T lock)
+{
+}
+
+void
+__retarget_lock_acquire (_LOCK_T lock)
+{
+}
+
+void
+__retarget_lock_acquire_recursive (_LOCK_T lock)
+{
+}
+
+int
+__retarget_lock_try_acquire(_LOCK_T lock)
+{
+  return 1;
+}
+
+int
+__retarget_lock_try_acquire_recursive(_LOCK_T lock)
+{
+  return 1;
+}
+
+void
+__retarget_lock_release (_LOCK_T lock)
+{
+}
+
+void
+__retarget_lock_release_recursive (_LOCK_T lock)
+{
+}
diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex
index 22c313eb15c7676443ff4c928c8c76cc038f3f0f..6afd1be5c4a1e90ffd64881c63c5132e144ad364 100644
--- a/newlib/libc/misc/misc.tex
+++ b/newlib/libc/misc/misc.tex
@@ -4,6 +4,7 @@ This chapter describes miscellaneous routines not covered elsewhere.
 
 @menu 
 * ffs::      Return first bit set in a word
+* lock::     Retargetable locking routines
 * unctrl::   Return printable representation of a character
 @end menu
 
@@ -11,4 +12,7 @@ This chapter describes miscellaneous routines not covered elsewhere.
 @include misc/ffs.def
 
 @page
+@include misc/lock.def
+
+@page
 @include misc/unctrl.def
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac0eea6a8917a92b8f0f3584c2cd42b9388..397bc9b96eafddace3a75be509157040654b6fde 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Unify names of all lock objects
  2017-01-30 18:57 ` Freddie Chopin
@ 2017-01-31 10:30   ` Thomas Preudhomme
  2017-02-06 10:49   ` Freddie Chopin
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas Preudhomme @ 2017-01-31 10:30 UTC (permalink / raw)
  To: newlib

Hi,

On 30/01/17 18:57, Freddie Chopin wrote:
> Most recent patch from Thomas' that adds lock retargeting, with changed
> names of objects to work on top of my patch.

Thanks Freddie but please note that I've got an updated version addressing 
comments I've received. It's also based on yet another patch that make sure all 
static locks are guarded with !defined(__SINGLE_THREAD__). I've already rebased 
them and will send them shortly.

Best regards,

Thomas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Unify names of all lock objects
  2017-01-30 18:57 ` Freddie Chopin
  2017-01-31 10:30   ` Thomas Preudhomme
@ 2017-02-06 10:49   ` Freddie Chopin
  2017-02-06 22:03     ` Jeff Johnston
  1 sibling, 1 reply; 6+ messages in thread
From: Freddie Chopin @ 2017-02-06 10:49 UTC (permalink / raw)
  To: newlib

On Mon, 2017-01-30 at 19:57 +0100, Freddie Chopin wrote:
> Most recent patch from Thomas' that adds lock retargeting, with
> changed
> names of objects to work on top of my patch.

Hello group!

Any chance of merging this (and other 2 patches from Thomas)? (;

Thanks in advance!
FCh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Unify names of all lock objects
  2017-02-06 10:49   ` Freddie Chopin
@ 2017-02-06 22:03     ` Jeff Johnston
  2017-02-06 22:18       ` Freddie Chopin
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Johnston @ 2017-02-06 22:03 UTC (permalink / raw)
  To: Freddie Chopin; +Cc: newlib

I have applied the lock renaming patch.  I still see _lock vs __lock
being used for external names.  I assume there is another patch forth-coming.

-- Jeff J.

----- Original Message -----
> On Mon, 2017-01-30 at 19:57 +0100, Freddie Chopin wrote:
> > Most recent patch from Thomas' that adds lock retargeting, with
> > changed
> > names of objects to work on top of my patch.
> 
> Hello group!
> 
> Any chance of merging this (and other 2 patches from Thomas)? (;
> 
> Thanks in advance!
> FCh
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] Unify names of all lock objects
  2017-02-06 22:03     ` Jeff Johnston
@ 2017-02-06 22:18       ` Freddie Chopin
  0 siblings, 0 replies; 6+ messages in thread
From: Freddie Chopin @ 2017-02-06 22:18 UTC (permalink / raw)
  To: newlib

On Mon, 2017-02-06 at 17:03 -0500, Jeff Johnston wrote:
> I have applied the lock renaming patch.

Thanks!

> I still see _lock vs __lock
> being used for external names.  I assume there is another patch
> forth-coming.

The patches with "_lock" changed to "__lock" are here:
https://sourceware.org/ml/newlib/2017/msg00112.html
https://sourceware.org/ml/newlib/2017/msg00117.html

Regards,
FCh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-06 22:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-30 18:56 [PATCH v2] Unify names of all lock objects Freddie Chopin
2017-01-30 18:57 ` Freddie Chopin
2017-01-31 10:30   ` Thomas Preudhomme
2017-02-06 10:49   ` Freddie Chopin
2017-02-06 22:03     ` Jeff Johnston
2017-02-06 22:18       ` Freddie Chopin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).