diff options
author | Adam Frisby | 2009-04-24 05:33:23 +0000 |
---|---|---|
committer | Adam Frisby | 2009-04-24 05:33:23 +0000 |
commit | 883f7dde3884bca10f324f6a31e0882cf23c04d8 (patch) | |
tree | 53cdc16d97034bc125c148086c689badcc7f2906 /OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs | |
parent | Update svn properties. (diff) | |
download | opensim-SC_OLD-883f7dde3884bca10f324f6a31e0882cf23c04d8.zip opensim-SC_OLD-883f7dde3884bca10f324f6a31e0882cf23c04d8.tar.gz opensim-SC_OLD-883f7dde3884bca10f324f6a31e0882cf23c04d8.tar.bz2 opensim-SC_OLD-883f7dde3884bca10f324f6a31e0882cf23c04d8.tar.xz |
* Implements Microthreading for MRM scripting.
* This is achieved through two new keywords "microthreaded" and "relax". example:
public microthreaded void MyFunc(...) {
...
relax;
...
}
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs new file mode 100644 index 0000000..a5da87b --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs | |||
@@ -0,0 +1,38 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; | ||
6 | |||
7 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | ||
8 | { | ||
9 | public class MicroScheduler : IMicrothreader | ||
10 | { | ||
11 | private readonly List<IEnumerator> m_threads = new List<IEnumerator>(); | ||
12 | |||
13 | public void Run(IEnumerable microthread) | ||
14 | { | ||
15 | lock (m_threads) | ||
16 | m_threads.Add(microthread.GetEnumerator()); | ||
17 | } | ||
18 | |||
19 | public void Tick(int count) | ||
20 | { | ||
21 | lock (m_threads) | ||
22 | { | ||
23 | if(m_threads.Count == 0) | ||
24 | return; | ||
25 | |||
26 | int i = 0; | ||
27 | while (m_threads.Count > 0 && i < count) | ||
28 | { | ||
29 | i++; | ||
30 | bool running = m_threads[i%m_threads.Count].MoveNext(); | ||
31 | |||
32 | if (!running) | ||
33 | m_threads.Remove(m_threads[i%m_threads.Count]); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | } | ||