aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs
diff options
context:
space:
mode:
authorAdam Frisby2009-04-24 05:33:23 +0000
committerAdam Frisby2009-04-24 05:33:23 +0000
commit883f7dde3884bca10f324f6a31e0882cf23c04d8 (patch)
tree53cdc16d97034bc125c148086c689badcc7f2906 /OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs
parentUpdate svn properties. (diff)
downloadopensim-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.cs38
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 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces;
6
7namespace 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}