d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.
[official-gcc.git] / libphobos / libdruntime / rt / tlsgc.d
blobb13a1b319cf0678181333a24b9e329b033acc68c
1 /**
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)
7 */
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)
14 module rt.tlsgc;
16 import core.stdc.stdlib;
18 static import rt.lifetime, rt.sections;
20 /**
21 * Per thread record to store thread associated data for garbage collection.
23 struct Data
25 typeof(rt.sections.initTLSRanges()) tlsRanges;
26 rt.lifetime.BlkInfo** blockInfoCache;
29 /**
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();
38 *data = Data.init;
40 // do module specific initialization
41 data.tlsRanges = rt.sections.initTLSRanges();
42 data.blockInfoCache = &rt.lifetime.__blkcache_storage;
44 return data;
47 /**
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);
56 .free(data);
59 alias void delegate(void* pstart, void* pend) nothrow ScanDg;
61 /**
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;
73 /**
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);