[rtems commit] Add functions for greedy workspace allocation

Sebastian Huber sebh at rtems.org
Fri Feb 17 15:11:59 UTC 2012


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Feb 17 13:42:51 2012 +0100

Add functions for greedy workspace allocation

Various tests must check program paths that result due to failed memory
allocations from the workspace.  To avoid tinkering with internal
workspace structures throughout the test code these functions should be
used.

---

 cpukit/rtems/Makefile.am                   |    1 +
 cpukit/rtems/include/rtems/rtems/support.h |   18 +++++++++++++
 cpukit/rtems/src/workspacegreedy.c         |   38 ++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index e9f9906..8d593a4 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -254,6 +254,7 @@ librtems_a_SOURCES += src/dpmemdata.c
 
 ## WORKSPACE_FILES
 librtems_a_SOURCES += src/workspace.c
+librtems_a_SOURCES += src/workspacegreedy.c
 
 librtems_a_SOURCES += src/modes.c
 
diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h
index 220411d..08c911d 100644
--- a/cpukit/rtems/include/rtems/rtems/support.h
+++ b/cpukit/rtems/include/rtems/rtems/support.h
@@ -101,6 +101,24 @@ bool rtems_workspace_free(
   void *pointer
 );
 
+/**
+ * @brief Greedy allocate that empties the workspace.
+ *
+ * Afterward the workspace has at most @a remaining_free_space free space left
+ * in one free block.  All other blocks are used.
+ *
+ * @see rtems_workspace_greedy_free().
+ */
+void *rtems_workspace_greedy_allocate( size_t remaining_free_space );
+
+/**
+ * @brief Frees space of a greedy allocation.
+ *
+ * The @a opaque argument must be the return value of
+ * rtems_workspace_greedy_allocate().
+ */
+void rtems_workspace_greedy_free( void *opaque );
+
 /** @} */
 
 #ifndef __RTEMS_APPLICATION__
diff --git a/cpukit/rtems/src/workspacegreedy.c b/cpukit/rtems/src/workspacegreedy.c
new file mode 100644
index 0000000..6d8fd9b
--- /dev/null
+++ b/cpukit/rtems/src/workspacegreedy.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/rtems/support.h>
+#include <rtems/score/wkspace.h>
+
+void *rtems_workspace_greedy_allocate( size_t remaining_free_space )
+{
+  void *opaque;
+
+  _Thread_Disable_dispatch();
+  opaque = _Heap_Greedy_allocate( &_Workspace_Area, remaining_free_space );
+  _Thread_Enable_dispatch();
+
+  return opaque;
+}
+
+void rtems_workspace_greedy_free( void *opaque )
+{
+  _Thread_Disable_dispatch();
+  _Heap_Greedy_free( &_Workspace_Area, opaque );
+  _Thread_Enable_dispatch();
+}




More information about the vc mailing list