changed to semi single header

This commit is contained in:
2026-06-08 09:47:44 +02:00
parent 6d864b3abd
commit 546ad3843c
5 changed files with 35 additions and 13 deletions

View File

@@ -1,23 +1,35 @@
#pragma once
/* Version 1.0 */
/* Version 1.1 */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef MIHP_IMPLEMENTATION
#define MIHP_IMPLEMENTATION 0
#endif
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_NONE 0
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_MAGIC_NUMBER 1
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM 2
#ifndef __MINIMAL_HEAP_H__
#define __MINIMAL_HEAP_H__
/* Defines to be configured by the library user */
#ifndef MIHP_HEAP_STRUCTURE_VALIDATION_TYPE
#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM
#endif
#ifndef MIHP_ASSERT
#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; }
#endif
#define MIHP_HEAP_LOCK_TYPE uint8_t // Does NOT have to be reentred safe
#ifndef MIHP_HEAP_LOCK_TYPE
#define MIHP_HEAP_LOCK_TYPE bool // Does NOT have to be reentred safe
#define MIHP_LOCK_HEAP(LockVarPtr) { while (*(LockVarPtr)) {}; *(LockVarPtr) = true; }
#define MIHP_UNLOCK_HEAP(LockVarPtr) { *(LockVarPtr) = false; }
#endif
/* */
/* Hooks to be implemented by the library user */
@@ -133,3 +145,9 @@ uint32_t MIHP_GenerateHeapSegmentChecksum(const MIHP_HeapSegmentHeader* segment)
void MIHP_ValidateHeapMemoryAreaHeader(const MIHP_HeapInfo* heap, const MIHP_HeapMemoryAreaHeader* area);
void MIHP_ValidateHeapSegmentHeader(const MIHP_HeapInfo* heap, const MIHP_HeapSegmentHeader* segment);
/* */
#endif
#if MIHP_IMPLEMENTATION
#include "minimal_heap_implementation.inl"
#endif

View File

@@ -1,5 +1,3 @@
#include "minimal_heap.h"
#define MIHP_MIN(A, B) (A) < (B) ? (A) : (B)
#define MIHP_MAX(A, B) (A) > (B) ? (A) : (B)

View File

@@ -1,4 +1,6 @@
#define MIHP_IMPLEMENTATION 1
#include "minimal_heap.h"
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

View File

@@ -124,12 +124,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="minimal_heap.c" />
<ClCompile Include="minimal_heap_test.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="minimal_heap.h" />
</ItemGroup>
<ItemGroup>
<None Include="minimal_heap_implementation.inl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@@ -18,13 +18,15 @@
<ClCompile Include="minimal_heap_test.c">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="minimal_heap.c">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="minimal_heap.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="minimal_heap_implementation.inl">
<Filter>Headerdateien</Filter>
</None>
</ItemGroup>
</Project>