From 883f7dde3884bca10f324f6a31e0882cf23c04d8 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Fri, 24 Apr 2009 05:33:23 +0000 Subject: * Implements Microthreading for MRM scripting. * This is achieved through two new keywords "microthreaded" and "relax". example: public microthreaded void MyFunc(...) { ... relax; ... } --- .../Scripting/Minimodule/MicroScheduler.cs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs (limited to 'OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs') 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 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public class MicroScheduler : IMicrothreader + { + private readonly List m_threads = new List(); + + public void Run(IEnumerable microthread) + { + lock (m_threads) + m_threads.Add(microthread.GetEnumerator()); + } + + public void Tick(int count) + { + lock (m_threads) + { + if(m_threads.Count == 0) + return; + + int i = 0; + while (m_threads.Count > 0 && i < count) + { + i++; + bool running = m_threads[i%m_threads.Count].MoveNext(); + + if (!running) + m_threads.Remove(m_threads[i%m_threads.Count]); + } + } + } + } +} -- cgit v1.1