1 module lwdr; 2 3 public import lwdr.tracking; 4 5 /// A static class by which to interface with core features of LWDR. 6 static final class LWDR 7 { 8 /// Finalise and deallocate object `obj` 9 static void free(ref Object obj) nothrow @nogc 10 { 11 import lifetime.class_; 12 _d_delclass(&obj); 13 obj = null; 14 } 15 16 version(LWDR_DynamicArray) 17 /// Finalise (if possible) and deallocate dynamic array `arr` 18 static void free(TArr : T[], T)(ref TArr arr) 19 { 20 import lifetime.array_; 21 _d_delarray_t(cast(void[]*)&arr, typeid(T)); 22 arr = null; 23 } 24 25 /// Deallocate `ptr` 26 static void free(TPtr : T*, T)(ref TPtr ptr) 27 if(!is(T == struct)) 28 { 29 import lifetime.common; 30 _d_delmemory(cast(void**)&ptr); 31 ptr = null; 32 } 33 34 /// Finalise (if possible) and deallocate struct pointed to by `ptr`. 35 static void free(TPtr : T*, T)(ref TPtr ptr) 36 if(is(T == struct)) 37 { 38 import lifetime.common; 39 TypeInfo_Struct s = cast(TypeInfo_Struct)typeid(T); 40 s.dtor(ptr); 41 _d_delmemory(cast(void**)&ptr); 42 ptr = null; 43 } 44 45 version(LWDR_TLS) 46 { 47 /++ Register the current thread with LWDR. 48 + This will perform the necessary TLS allocations for this thread. ++/ 49 static void registerCurrentThread() nothrow @nogc 50 { 51 import rt.sections; 52 initTLSRanges(); 53 } 54 55 /++ Deregister the current thread from LWDR. 56 + If this thread was not registered, it will cause unknown behaviour. 57 + This will deallocate TLS memory for this thread. ++/ 58 static void deregisterCurrentThread() nothrow @nogc 59 { 60 import rt.sections; 61 freeTLSRanges(); 62 } 63 } 64 }