Explorar el Código

rtl/morphos: add optional support for the OSHeap allocator

Karoly Balogh hace 1 semana
padre
commit
53eeb1cf0f
Se han modificado 1 ficheros con 20 adiciones y 0 borrados
  1. 20 0
      rtl/morphos/system.pp

+ 20 - 0
rtl/morphos/system.pp

@@ -24,6 +24,11 @@ unit System;
 interface
 
 {$define FPC_IS_SYSTEM}
+{.$define FPC_MORPHOS_USE_OSHEAP}
+
+{$ifdef FPC_MORPHOS_USE_OSHEAP}
+{$define HAS_MEMORYMANAGER}
+{$endif FPC_MORPHOS_USE_OSHEAP}
 
 {$I systemh.inc}
 {$I osdebugh.inc}
@@ -81,6 +86,9 @@ implementation
 {$define FPC_SYSTEM_HAS_STACKTOP}
 
 {$I system.inc}
+{$ifdef FPC_MORPHOS_USE_OSHEAP}
+{$i osheap.inc}
+{$endif FPC_MORPHOS_USE_OSHEAP}
 {$I osdebug.inc}
 
 function StackTop: pointer;
@@ -186,6 +194,11 @@ begin
   randseed:=tmpTime.ds_tick;
 end;
 
+{$IFDEF FPC_MORPHOS_USE_OSHEAP}
+var
+  { generated by the compiler based on the $MEMORY directive }
+  heapsize : PtrInt; external name '__heapsize';
+{$ENDIF FPC_MORPHOS_USE_OSHEAP}
 
 { MorphOS specific startup }
 procedure SysInitMorphOS;
@@ -204,7 +217,11 @@ begin
  if MOS_UtilityBase=nil then Halt(1);
 
  { Creating the memory pool for growing heap }
+{$IFNDEF FPC_MORPHOS_USE_OSHEAP}
  ASYS_heapPool:=CreatePool(MEMF_FAST or MEMF_SEM_PROTECTED,growheapsize2,growheapsize2 div 4);
+{$ELSE FPC_MORPHOS_USE_OSHEAP}
+  ASYS_heapPool:=CreatePool(MEMF_FAST or MEMF_SEM_PROTECTED,min(heapsize,1024),min(heapsize div 2,1024));
+{$ENDIF FPC_MORPHOS_USE_OSHEAP}
  if ASYS_heapPool=nil then Halt(1);
 
  { Initialize semaphore for filelist access arbitration }
@@ -262,8 +279,11 @@ begin
   SysInitMorphOS;
 { Set up signals handlers }
 //  InstallSignals;
+{ Setup heap }
+{$ifndef FPC_MORPHOS_USE_OSHEAP}
 { Setup heap }
   InitHeap;
+{$endif FPC_MORPHOS_USE_OSHEAP}
   SysInitExceptions;
   initunicodestringmanager;
 { Setup stdin, stdout and stderr }