[rtems commit] score: Lazy key value pair allocation

Sebastian Huber sebh at rtems.org
Mon Apr 7 14:42:12 UTC 2014


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Apr  7 14:50:32 2014 +0200

score: Lazy key value pair allocation

---

 cpukit/posix/src/key.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c
index b4f3e8a..10fc3e9 100644
--- a/cpukit/posix/src/key.c
+++ b/cpukit/posix/src/key.c
@@ -112,19 +112,23 @@ static bool _POSIX_Keys_Keypool_extend( Freechain_Control *keypool )
 
 static void _POSIX_Keys_Initialize_keypool( void )
 {
-  Freechain_Control *keypool = &_POSIX_Keys_Keypool;
   size_t initial_count = _POSIX_Keys_Get_initial_keypool_size();
   size_t size = initial_count * sizeof( POSIX_Keys_Key_value_pair );
-  POSIX_Keys_Key_value_pair *nodes = _Workspace_Allocate_or_fatal_error( size );
 
-  _Freechain_Initialize( keypool, _POSIX_Keys_Keypool_extend );
+  if ( size > 0 ) {
+    Freechain_Control *keypool = &_POSIX_Keys_Keypool;
+    POSIX_Keys_Key_value_pair *nodes =
+      _Workspace_Allocate_or_fatal_error( size );
 
-  _Chain_Initialize(
-    &keypool->Freechain,
-    nodes,
-    initial_count,
-    sizeof( *nodes )
-  );
+    _Freechain_Initialize( keypool, _POSIX_Keys_Keypool_extend );
+
+    _Chain_Initialize(
+      &keypool->Freechain,
+      nodes,
+      initial_count,
+      sizeof( *nodes )
+    );
+  }
 }
 
 /**




More information about the vc mailing list