[rtems commit] posix: Optimize pthread_once_t

Sebastian Huber sebh at rtems.org
Thu Oct 5 12:35:59 UTC 2017


Module:    rtems
Branch:    master
Commit:    47b1e31f119a5830976bc16d9495d6ccb27a909a
Changeset: http://git.rtems.org/rtems/commit/?id=47b1e31f119a5830976bc16d9495d6ccb27a909a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Sep 19 14:10:33 2017 +0200

posix: Optimize pthread_once_t

Reduce size of pthread_once_t and make it zero-initialized.

Update #3142.

---

 cpukit/libcsupport/src/gxx_wrappers.c       | 2 +-
 cpukit/posix/src/pthreadonce.c              | 5 +----
 cpukit/score/include/rtems/score/onceimpl.h | 2 +-
 cpukit/score/src/once.c                     | 2 +-
 4 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/cpukit/libcsupport/src/gxx_wrappers.c b/cpukit/libcsupport/src/gxx_wrappers.c
index d30b570..3a1b0f1 100644
--- a/cpukit/libcsupport/src/gxx_wrappers.c
+++ b/cpukit/libcsupport/src/gxx_wrappers.c
@@ -46,7 +46,7 @@ int rtems_gxx_once(__gthread_once_t *once, void (*func) (void))
     printk( "gxx_wrappers: once=%x, func=%x\n", *once, func );
   #endif
 
-  return _Once( once, func );
+  return _Once( (unsigned char *) once, func );
 }
 
 int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *))
diff --git a/cpukit/posix/src/pthreadonce.c b/cpukit/posix/src/pthreadonce.c
index dc8a449..c92acf8 100644
--- a/cpukit/posix/src/pthreadonce.c
+++ b/cpukit/posix/src/pthreadonce.c
@@ -33,8 +33,5 @@ int pthread_once(
   if ( !once_control || !init_routine )
     return EINVAL;
 
-  if ( once_control->is_initialized != 1 )
-    return EINVAL;
-
-  return _Once( &once_control->init_executed, init_routine );
+  return _Once( &once_control->_flags, init_routine );
 }
diff --git a/cpukit/score/include/rtems/score/onceimpl.h b/cpukit/score/include/rtems/score/onceimpl.h
index d81f1d0..21e9eda 100644
--- a/cpukit/score/include/rtems/score/onceimpl.h
+++ b/cpukit/score/include/rtems/score/onceimpl.h
@@ -37,7 +37,7 @@ extern "C" {
  * @{
  */
 
-int _Once( int *once_state, void (*init_routine)(void) );
+int _Once( unsigned char *once_state, void (*init_routine)(void) );
 
 /** @} */
 
diff --git a/cpukit/score/src/once.c b/cpukit/score/src/once.c
index 60ae7a7..427659e 100644
--- a/cpukit/score/src/once.c
+++ b/cpukit/score/src/once.c
@@ -20,7 +20,7 @@
 #define ONCE_STATE_RUNNING  1
 #define ONCE_STATE_COMPLETE 2
 
-int _Once( int *once_state, void ( *init_routine )( void ) )
+int _Once( unsigned char *once_state, void ( *init_routine )( void ) )
 {
   int eno = 0;
 




More information about the vc mailing list