0
|
1
|
|
2 /* Digital Mars DMDScript source code.
|
|
3 * Copyright (c) 2000-2002 by Chromium Communications
|
|
4 * D version Copyright (c) 2004-2005 by Digital Mars
|
|
5 * All Rights Reserved
|
|
6 * written by Walter Bright
|
|
7 * www.digitalmars.com
|
|
8 * Use at your own risk. There is no warranty, express or implied.
|
|
9 * License for redistribution is by the GNU General Public License in gpl.txt.
|
|
10 *
|
|
11 * A binary, non-exclusive license for commercial use can be
|
|
12 * purchased from www.digitalmars.com/dscript/buy.html.
|
|
13 *
|
|
14 * DMDScript is implemented in the D Programming Language,
|
|
15 * www.digitalmars.com/d/
|
|
16 *
|
|
17 * For a C++ implementation of DMDScript, including COM support,
|
|
18 * see www.digitalmars.com/dscript/cppscript.html.
|
|
19 */
|
|
20
|
|
21
|
3
|
22 module dmdscript_tango.threadcontext;
|
0
|
23
|
4
|
24 //import std.thread;
|
0
|
25
|
4
|
26 //alias std.thread.Thread Thread;
|
|
27 import tango.core.Thread;
|
0
|
28
|
3
|
29 import dmdscript_tango.script;
|
|
30 import dmdscript_tango.program;
|
|
31 import dmdscript_tango.dmath;
|
|
32 import dmdscript_tango.dobject;
|
|
33 import dmdscript_tango.dfunction;
|
0
|
34
|
|
35 // These are our per-thread global variables
|
|
36
|
|
37 struct ThreadContext
|
|
38 {
|
|
39 Thread threadid; // identifier of current thread
|
|
40
|
|
41 // Tables where the prototype and constructor object are stored.
|
|
42 Dobject[d_string] protoTable;
|
|
43 Dfunction[d_string] ctorTable;
|
|
44
|
|
45 // Table where object initializers go
|
|
46 static void function(ThreadContext*)[] initTable;
|
|
47
|
|
48 // Values from here to the end of the struct are 0'd by dobject_term()
|
|
49 Program program; // associated data
|
|
50
|
|
51 Dfunction Dobject_constructor;
|
|
52 Dobject Dobject_prototype;
|
|
53
|
|
54 Dfunction Dfunction_constructor;
|
|
55 Dobject Dfunction_prototype;
|
|
56
|
|
57 Dfunction Darray_constructor;
|
|
58 Dobject Darray_prototype;
|
|
59
|
|
60 Dfunction Dstring_constructor;
|
|
61 Dobject Dstring_prototype;
|
|
62
|
|
63 Dfunction Dboolean_constructor;
|
|
64 Dobject Dboolean_prototype;
|
|
65
|
|
66 Dfunction Dnumber_constructor;
|
|
67 Dobject Dnumber_prototype;
|
|
68
|
|
69 Dfunction Derror_constructor;
|
|
70 Dobject Derror_prototype;
|
|
71
|
|
72 Dfunction Ddate_constructor;
|
|
73 Dobject Ddate_prototype;
|
|
74
|
|
75 Dfunction Dregexp_constructor;
|
|
76 Dobject Dregexp_prototype;
|
|
77
|
|
78 Dfunction Denumerator_constructor;
|
|
79 Dobject Denumerator_prototype;
|
|
80
|
|
81 Dmath Dmath_object;
|
|
82
|
|
83 /***********************************************
|
|
84 * Get ThreadContext associated with this thread.
|
|
85 */
|
|
86
|
|
87 static ThreadContext[Thread] threadtable;
|
|
88
|
|
89 static Thread cache_ti;
|
|
90 static ThreadContext* cache_cc;
|
|
91
|
|
92 static ThreadContext* getThreadContext()
|
|
93 {
|
|
94 /* This works by creating an array of ThreadContext's, one
|
|
95 * for each thread. We match up by thread id.
|
|
96 */
|
|
97
|
|
98 Thread ti;
|
|
99 ThreadContext *cc;
|
|
100
|
|
101 //writef("ThreadContext.getThreadContext()\n");
|
|
102
|
|
103 ti = Thread.getThis();
|
|
104
|
|
105 synchronized
|
|
106 {
|
|
107 // Used cached version if we can
|
|
108 if (ti == cache_ti)
|
|
109 {
|
|
110 cc = cache_cc;
|
|
111 //exception(L"getThreadContext(): cache x%x", ti);
|
|
112 }
|
|
113 else
|
|
114 {
|
|
115 cc = ti in threadtable;
|
|
116 if (!cc)
|
|
117 {
|
|
118 threadtable[ti] = ThreadContext.init;
|
|
119 cc = &threadtable[ti];
|
|
120 }
|
|
121
|
|
122 cc.threadid = ti;
|
|
123
|
|
124 // Cache for next time
|
|
125 cache_ti = ti;
|
|
126 cache_cc = cc;
|
|
127 }
|
|
128 }
|
|
129 return cc;
|
|
130 }
|
|
131 }
|
|
132
|
|
133
|