diff options
author | UbitUmarov | 2018-02-23 14:52:34 +0000 |
---|---|---|
committer | UbitUmarov | 2018-02-23 14:52:34 +0000 |
commit | 2129d941acbc5f83aca4dc4c30a62d3226888136 (patch) | |
tree | e12f2391978c923ef780f558ee5a32d857ee9124 /OpenSim/Region/ScriptEngine/XMREngine/XMRScriptUThread.cs | |
parent | Merge branch 'master' into httptests (diff) | |
download | opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.zip opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.gz opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.bz2 opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.xz |
rename XMREngine as Yengine (still not all done), big mess source formating changes, move state files to proper folder, fix a source file locking on errors, more changes for cross platform including from Mike,... yes yes i know a messy commit
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XMREngine/XMRScriptUThread.cs | 196 |
1 files changed, 0 insertions, 196 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptUThread.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptUThread.cs deleted file mode 100644 index ca2806e..0000000 --- a/OpenSim/Region/ScriptEngine/XMREngine/XMRScriptUThread.cs +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | /***************************\ | ||
31 | * Use standard C# code * | ||
32 | * - uses stack smashing * | ||
33 | \***************************/ | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.XMREngine | ||
36 | { | ||
37 | |||
38 | public class ScriptUThread_Nul : IScriptUThread, IDisposable | ||
39 | { | ||
40 | private int active; // -1: hibernating | ||
41 | // 0: exited | ||
42 | // 1: running | ||
43 | private XMRInstance instance; | ||
44 | |||
45 | public ScriptUThread_Nul (XMRInstance instance) | ||
46 | { | ||
47 | this.instance = instance; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * @brief Start script event handler from the beginning. | ||
52 | * Return when either the script event handler completes | ||
53 | * or the script calls Hiber(). | ||
54 | * @returns null: script did not throw any exception so far | ||
55 | * else: script threw an exception | ||
56 | */ | ||
57 | public Exception StartEx () | ||
58 | { | ||
59 | // We should only be called when no event handler running. | ||
60 | if (active != 0) | ||
61 | throw new Exception ("active=" + active); | ||
62 | |||
63 | // Start script event handler from very beginning. | ||
64 | active = 1; | ||
65 | Exception except = null; | ||
66 | instance.callMode = XMRInstance.CallMode_NORMAL; | ||
67 | try | ||
68 | { | ||
69 | instance.CallSEH (); // run script event handler | ||
70 | active = 0; | ||
71 | } | ||
72 | catch (StackHibernateException) | ||
73 | { | ||
74 | if (instance.callMode != XMRInstance.CallMode_SAVE) | ||
75 | { | ||
76 | throw new Exception ("callMode=" + instance.callMode); | ||
77 | } | ||
78 | active = -1; // it is hibernating, can be resumed | ||
79 | } | ||
80 | catch (Exception e) | ||
81 | { | ||
82 | active = 0; | ||
83 | except = e; // threw exception, save for Start()/Resume() | ||
84 | } | ||
85 | |||
86 | // Return whether or not script threw an exception. | ||
87 | return except; | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * @brief We now want to run some more script code from where it last hibernated | ||
92 | * until it either finishes the script event handler or until the script | ||
93 | * calls Hiber() again. | ||
94 | */ | ||
95 | public Exception ResumeEx () | ||
96 | { | ||
97 | // We should only be called when script is hibernating. | ||
98 | if (active >= 0) | ||
99 | throw new Exception ("active=" + active); | ||
100 | |||
101 | // Resume script from captured stack. | ||
102 | instance.callMode = XMRInstance.CallMode_RESTORE; | ||
103 | instance.suspendOnCheckRunTemp = true; | ||
104 | Exception except = null; | ||
105 | try | ||
106 | { | ||
107 | instance.CallSEH (); // run script event handler | ||
108 | active = 0; | ||
109 | } | ||
110 | catch (StackHibernateException) | ||
111 | { | ||
112 | if (instance.callMode != XMRInstance.CallMode_SAVE) | ||
113 | { | ||
114 | throw new Exception ("callMode=" + instance.callMode); | ||
115 | } | ||
116 | active = -1; | ||
117 | } | ||
118 | catch (Exception e) | ||
119 | { | ||
120 | active = 0; | ||
121 | except = e; // threw exception, save for Start()/Resume() | ||
122 | } | ||
123 | |||
124 | // Return whether or not script threw an exception. | ||
125 | return except; | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * @brief Script is being closed out. | ||
130 | * Terminate thread asap. | ||
131 | */ | ||
132 | public void Dispose () | ||
133 | { } | ||
134 | |||
135 | /** | ||
136 | * @brief Determine if script is active. | ||
137 | * Returns: 0: nothing started or has returned | ||
138 | * Resume() must not be called | ||
139 | * Start() may be called | ||
140 | * Hiber() must not be called | ||
141 | * -1: thread has called Hiber() | ||
142 | * Resume() may be called | ||
143 | * Start() may be called | ||
144 | * Hiber() must not be called | ||
145 | * 1: thread is running | ||
146 | * Resume() must not be called | ||
147 | * Start() must not be called | ||
148 | * Hiber() may be called | ||
149 | */ | ||
150 | public int Active () | ||
151 | { | ||
152 | return active; | ||
153 | } | ||
154 | |||
155 | /** | ||
156 | * @brief Called by the script event handler whenever it wants to hibernate. | ||
157 | */ | ||
158 | public void Hiber () | ||
159 | { | ||
160 | if (instance.callMode != XMRInstance.CallMode_NORMAL) { | ||
161 | throw new Exception ("callMode=" + instance.callMode); | ||
162 | } | ||
163 | |||
164 | switch (active) { | ||
165 | |||
166 | // the stack has been restored as a result of calling ResumeEx() | ||
167 | // say the microthread is now active and resume processing | ||
168 | case -1: { | ||
169 | active = 1; | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | // the script event handler wants to hibernate | ||
174 | // capture stack frames and unwind to Start() or Resume() | ||
175 | case 1: { | ||
176 | instance.callMode = XMRInstance.CallMode_SAVE; | ||
177 | instance.stackFrames = null; | ||
178 | throw new StackHibernateException (); | ||
179 | } | ||
180 | |||
181 | default: throw new Exception ("active=" + active); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * @brief Number of remaining stack bytes. | ||
187 | */ | ||
188 | public int StackLeft () | ||
189 | { | ||
190 | return 0x7FFFFFFF; | ||
191 | } | ||
192 | |||
193 | public class StackHibernateException : Exception, IXMRUncatchable { } | ||
194 | } | ||
195 | } | ||
196 | |||