File indexing completed on 2025-05-11 08:24:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifndef _RTEMS_SCORE_WKSPACEINITMULTI_H
0038 #define _RTEMS_SCORE_WKSPACEINITMULTI_H
0039
0040 #include <rtems/score/wkspace.h>
0041 #include <rtems/score/heapimpl.h>
0042 #include <rtems/score/interr.h>
0043 #include <rtems/score/memory.h>
0044 #include <rtems/config.h>
0045
0046 #ifdef __cplusplus
0047 extern "C" {
0048 #endif
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 static inline void _Workspace_Initialize_for_multiple_areas( void )
0061 {
0062 const Memory_Information *mem;
0063 Heap_Initialization_or_extend_handler init_or_extend;
0064 uintptr_t remaining;
0065 bool unified;
0066 uintptr_t page_size;
0067 uintptr_t overhead;
0068 size_t i;
0069
0070 mem = _Memory_Get();
0071 page_size = CPU_HEAP_ALIGNMENT;
0072 remaining = rtems_configuration_get_work_space_size();
0073 init_or_extend = _Heap_Initialize;
0074 unified = rtems_configuration_get_unified_work_area();
0075 overhead = _Heap_Area_overhead( page_size );
0076
0077 for ( i = 0; i < _Memory_Get_count( mem ); ++i ) {
0078 Memory_Area *area;
0079 uintptr_t free_size;
0080
0081 area = _Memory_Get_area( mem, i );
0082 free_size = _Memory_Get_free_size( area );
0083
0084 if ( free_size > overhead ) {
0085 uintptr_t space_available;
0086 uintptr_t size;
0087
0088 if ( unified ) {
0089 size = free_size;
0090 } else {
0091 if ( remaining > 0 ) {
0092 size = remaining < free_size - overhead ?
0093 remaining + overhead : free_size;
0094 } else {
0095 size = 0;
0096 }
0097 }
0098
0099 space_available = ( *init_or_extend )(
0100 &_Workspace_Area,
0101 _Memory_Get_free_begin( area ),
0102 size,
0103 page_size
0104 );
0105
0106 _Memory_Consume( area, size );
0107
0108 if ( space_available < remaining ) {
0109 remaining -= space_available;
0110 } else {
0111 remaining = 0;
0112 }
0113
0114 init_or_extend = _Heap_Extend;
0115 }
0116 }
0117
0118 if ( remaining > 0 ) {
0119 _Internal_error( INTERNAL_ERROR_TOO_LITTLE_WORKSPACE );
0120 }
0121
0122 _Heap_Protection_set_delayed_free_fraction( &_Workspace_Area, 1 );
0123 }
0124
0125 #ifdef __cplusplus
0126 }
0127 #endif
0128
0129 #endif