mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-22 14:25:56 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@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();
|
||||
}
|
||||
Reference in New Issue
Block a user