145
|
1 /**
|
|
2 *
|
|
3 * Copyright: Copyright Digital Mars 2011 - 2012.
|
|
4 * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
|
|
5 * Authors: Martin Nowak
|
|
6 */
|
|
7
|
|
8 /* Copyright Digital Mars 2011.
|
|
9 * Distributed under the Boost Software License, Version 1.0.
|
|
10 * (See accompanying file LICENSE or copy at
|
|
11 * http://www.boost.org/LICENSE_1_0.txt)
|
|
12 */
|
|
13 module rt.tlsgc;
|
|
14
|
|
15 import core.stdc.stdlib;
|
|
16
|
|
17 static import rt.lifetime, rt.sections;
|
|
18
|
|
19 /**
|
|
20 * Per thread record to store thread associated data for garbage collection.
|
|
21 */
|
|
22 struct Data
|
|
23 {
|
|
24 typeof(rt.sections.initTLSRanges()) tlsRanges;
|
|
25 rt.lifetime.BlkInfo** blockInfoCache;
|
|
26 }
|
|
27
|
|
28 /**
|
|
29 * Initialization hook, called FROM each thread. No assumptions about
|
|
30 * module initialization state should be made.
|
|
31 */
|
|
32 void* init() nothrow @nogc
|
|
33 {
|
|
34 auto data = cast(Data*).malloc(Data.sizeof);
|
|
35 import core.exception;
|
|
36 if ( data is null ) core.exception.onOutOfMemoryError();
|
|
37 *data = Data.init;
|
|
38
|
|
39 // do module specific initialization
|
|
40 data.tlsRanges = rt.sections.initTLSRanges();
|
|
41 data.blockInfoCache = &rt.lifetime.__blkcache_storage;
|
|
42
|
|
43 return data;
|
|
44 }
|
|
45
|
|
46 /**
|
|
47 * Finalization hook, called FOR each thread. No assumptions about
|
|
48 * module initialization state should be made.
|
|
49 */
|
|
50 void destroy(void* data) nothrow @nogc
|
|
51 {
|
|
52 // do module specific finalization
|
|
53 rt.sections.finiTLSRanges((cast(Data*)data).tlsRanges);
|
|
54
|
|
55 .free(data);
|
|
56 }
|
|
57
|
|
58 alias void delegate(void* pstart, void* pend) nothrow ScanDg;
|
|
59
|
|
60 /**
|
|
61 * GC scan hook, called FOR each thread. Can be used to scan
|
|
62 * additional thread local memory.
|
|
63 */
|
|
64 void scan(void* data, scope ScanDg dg) nothrow
|
|
65 {
|
|
66 // do module specific marking
|
|
67 rt.sections.scanTLSRanges((cast(Data*)data).tlsRanges, dg);
|
|
68 }
|
|
69
|
|
70 alias int delegate(void* addr) nothrow IsMarkedDg;
|
|
71
|
|
72 /**
|
|
73 * GC sweep hook, called FOR each thread. Can be used to free
|
|
74 * additional thread local memory or associated data structures. Note
|
|
75 * that only memory allocated from the GC can have marks.
|
|
76 */
|
|
77 void processGCMarks(void* data, scope IsMarkedDg dg) nothrow
|
|
78 {
|
|
79 // do module specific sweeping
|
|
80 rt.lifetime.processGCMarks(*(cast(Data*)data).blockInfoCache, dg);
|
|
81 }
|