From 546ad3843c447842b92b3589dbfb593dd1df2bbf Mon Sep 17 00:00:00 2001 From: ToyB-Chan Date: Mon, 8 Jun 2026 09:47:44 +0200 Subject: [PATCH] changed to semi single header --- minimal_heap.h | 32 +++++++++++++++---- ..._heap.c => minimal_heap_implementation.inl | 2 -- minimal_heap_test.c | 2 ++ minimal_heap_test.vcxproj | 4 ++- minimal_heap_test.vcxproj.filters | 8 +++-- 5 files changed, 35 insertions(+), 13 deletions(-) rename minimal_heap.c => minimal_heap_implementation.inl (99%) diff --git a/minimal_heap.h b/minimal_heap.h index 0883dc5..967087e 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -1,23 +1,35 @@ -#pragma once -/* Version 1.0 */ +/* Version 1.1 */ #include #include #include +#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 */ -#define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM +#ifndef MIHP_HEAP_STRUCTURE_VALIDATION_TYPE + #define MIHP_HEAP_STRUCTURE_VALIDATION_TYPE MIHP_HEAP_STRUCTURE_VALIDATION_TYPE_CHECKSUM +#endif -#define MIHP_ASSERT(Condition) while(1) { if (Condition) break; *(volatile char*)(0x0) = 0; } +#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 -#define MIHP_LOCK_HEAP(LockVarPtr) { while (*(LockVarPtr)) {}; *(LockVarPtr) = true; } -#define MIHP_UNLOCK_HEAP(LockVarPtr) { *(LockVarPtr) = false; } +#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 diff --git a/minimal_heap.c b/minimal_heap_implementation.inl similarity index 99% rename from minimal_heap.c rename to minimal_heap_implementation.inl index ca5deec..3e4f5bc 100644 --- a/minimal_heap.c +++ b/minimal_heap_implementation.inl @@ -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) diff --git a/minimal_heap_test.c b/minimal_heap_test.c index 371329b..a0098c4 100644 --- a/minimal_heap_test.c +++ b/minimal_heap_test.c @@ -1,4 +1,6 @@ +#define MIHP_IMPLEMENTATION 1 #include "minimal_heap.h" + #include #include #include diff --git a/minimal_heap_test.vcxproj b/minimal_heap_test.vcxproj index 9688f30..06693a7 100644 --- a/minimal_heap_test.vcxproj +++ b/minimal_heap_test.vcxproj @@ -124,12 +124,14 @@ - + + + diff --git a/minimal_heap_test.vcxproj.filters b/minimal_heap_test.vcxproj.filters index e9330a5..aad3cae 100644 --- a/minimal_heap_test.vcxproj.filters +++ b/minimal_heap_test.vcxproj.filters @@ -18,13 +18,15 @@ Quelldateien - - Quelldateien - Headerdateien + + + Headerdateien + + \ No newline at end of file