3 * Copyright: Copyright Digital Mars 2011 - 2012.
4 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
5 * Authors: Martin Nowak
6 * Source: $(DRUNTIMESRC rt/tlsgc.d)
9 /* Copyright Digital Mars 2011.
10 * Distributed under the Boost Software License, Version 1.0.
11 * (See accompanying file LICENSE or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
16 import core
.stdc
.stdlib
;
18 static import rt
.lifetime
, rt
.sections
;
21 * Per thread record to store thread associated data for garbage collection.
25 typeof(rt
.sections
.initTLSRanges()) tlsRanges
;
26 rt
.lifetime
.BlkInfo
** blockInfoCache
;
30 * Initialization hook, called FROM each thread. No assumptions about
31 * module initialization state should be made.
33 void* init() nothrow @nogc
35 auto data
= cast(Data
*).malloc(Data
.sizeof
);
36 import core
.exception
;
37 if ( data
is null ) core
.exception
.onOutOfMemoryError();
40 // do module specific initialization
41 data
.tlsRanges
= rt
.sections
.initTLSRanges();
42 data
.blockInfoCache
= &rt
.lifetime
.__blkcache_storage
;
48 * Finalization hook, called FOR each thread. No assumptions about
49 * module initialization state should be made.
51 void destroy(void* data
) nothrow @nogc
53 // do module specific finalization
54 rt
.sections
.finiTLSRanges((cast(Data
*)data
).tlsRanges
);
59 alias void delegate(void* pstart
, void* pend
) nothrow ScanDg
;
62 * GC scan hook, called FOR each thread. Can be used to scan
63 * additional thread local memory.
65 void scan(void* data
, scope ScanDg dg
) nothrow
67 // do module specific marking
68 rt
.sections
.scanTLSRanges((cast(Data
*)data
).tlsRanges
, dg
);
71 alias int delegate(void* addr
) nothrow IsMarkedDg
;
74 * GC sweep hook, called FOR each thread. Can be used to free
75 * additional thread local memory or associated data structures. Note
76 * that only memory allocated from the GC can have marks.
78 void processGCMarks(void* data
, scope IsMarkedDg dg
) nothrow
80 // do module specific sweeping
81 rt
.lifetime
.processGCMarks(*(cast(Data
*)data
).blockInfoCache
, dg
);