diff options
3 files changed, 90 insertions, 90 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IMicrothreader.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IMicrothreader.cs index 22d3a99..5e187a5 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IMicrothreader.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IMicrothreader.cs | |||
@@ -1,12 +1,12 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections; | 2 | using System.Collections; |
3 | using System.Collections.Generic; | 3 | using System.Collections.Generic; |
4 | using System.Text; | 4 | using System.Text; |
5 | 5 | ||
6 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces | 6 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces |
7 | { | 7 | { |
8 | public interface IMicrothreader | 8 | public interface IMicrothreader |
9 | { | 9 | { |
10 | void Run(IEnumerable microthread); | 10 | void Run(IEnumerable microthread); |
11 | } | 11 | } |
12 | } | 12 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs index a5da87b..500c5bf 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MicroScheduler.cs | |||
@@ -1,38 +1,38 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections; | 2 | using System.Collections; |
3 | using System.Collections.Generic; | 3 | using System.Collections.Generic; |
4 | using System.Text; | 4 | using System.Text; |
5 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; | 5 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; |
6 | 6 | ||
7 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | 7 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule |
8 | { | 8 | { |
9 | public class MicroScheduler : IMicrothreader | 9 | public class MicroScheduler : IMicrothreader |
10 | { | 10 | { |
11 | private readonly List<IEnumerator> m_threads = new List<IEnumerator>(); | 11 | private readonly List<IEnumerator> m_threads = new List<IEnumerator>(); |
12 | 12 | ||
13 | public void Run(IEnumerable microthread) | 13 | public void Run(IEnumerable microthread) |
14 | { | 14 | { |
15 | lock (m_threads) | 15 | lock (m_threads) |
16 | m_threads.Add(microthread.GetEnumerator()); | 16 | m_threads.Add(microthread.GetEnumerator()); |
17 | } | 17 | } |
18 | 18 | ||
19 | public void Tick(int count) | 19 | public void Tick(int count) |
20 | { | 20 | { |
21 | lock (m_threads) | 21 | lock (m_threads) |
22 | { | 22 | { |
23 | if(m_threads.Count == 0) | 23 | if(m_threads.Count == 0) |
24 | return; | 24 | return; |
25 | 25 | ||
26 | int i = 0; | 26 | int i = 0; |
27 | while (m_threads.Count > 0 && i < count) | 27 | while (m_threads.Count > 0 && i < count) |
28 | { | 28 | { |
29 | i++; | 29 | i++; |
30 | bool running = m_threads[i%m_threads.Count].MoveNext(); | 30 | bool running = m_threads[i%m_threads.Count].MoveNext(); |
31 | 31 | ||
32 | if (!running) | 32 | if (!running) |
33 | m_threads.Remove(m_threads[i%m_threads.Count]); | 33 | m_threads.Remove(m_threads[i%m_threads.Count]); |
34 | } | 34 | } |
35 | } | 35 | } |
36 | } | 36 | } |
37 | } | 37 | } |
38 | } | 38 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/Microthreads/MicrothreadSample.txt b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/Microthreads/MicrothreadSample.txt index dc15c47..d2c204a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/Microthreads/MicrothreadSample.txt +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/Microthreads/MicrothreadSample.txt | |||
@@ -1,40 +1,40 @@ | |||
1 | //MRM:C# | 1 | //MRM:C# |
2 | using System.Collections; | 2 | using System.Collections; |
3 | using System.Collections.Generic; | 3 | using System.Collections.Generic; |
4 | using OpenSim.Region.OptionalModules.Scripting.Minimodule; | 4 | using OpenSim.Region.OptionalModules.Scripting.Minimodule; |
5 | 5 | ||
6 | namespace OpenSim | 6 | namespace OpenSim |
7 | { | 7 | { |
8 | class MiniModule : MRMBase | 8 | class MiniModule : MRMBase |
9 | { | 9 | { |
10 | public microthreaded void MicroThreadFunction(string testparam) | 10 | public microthreaded void MicroThreadFunction(string testparam) |
11 | { | 11 | { |
12 | Host.Object.Say("Hello " + testparam); | 12 | Host.Object.Say("Hello " + testparam); |
13 | 13 | ||
14 | relax; // the 'relax' keyword gives up processing time. | 14 | relax; // the 'relax' keyword gives up processing time. |
15 | // and should be inserted before, after or in | 15 | // and should be inserted before, after or in |
16 | // any computationally "heavy" zones. | 16 | // any computationally "heavy" zones. |
17 | 17 | ||
18 | int c = 500; | 18 | int c = 500; |
19 | while(c-- < 0) { | 19 | while(c-- < 0) { |
20 | Host.Object.Say("C=" + c); | 20 | Host.Object.Say("C=" + c); |
21 | relax; // Putting 'relax' in microthreaded loops | 21 | relax; // Putting 'relax' in microthreaded loops |
22 | // is an easy way to lower the CPU tax | 22 | // is an easy way to lower the CPU tax |
23 | // on your script. | 23 | // on your script. |
24 | } | 24 | } |
25 | 25 | ||
26 | } | 26 | } |
27 | 27 | ||
28 | public override void Start() | 28 | public override void Start() |
29 | { | 29 | { |
30 | Host.Microthreads.Run( | 30 | Host.Microthreads.Run( |
31 | MicroThreadFunction("World!") | 31 | MicroThreadFunction("World!") |
32 | ); | 32 | ); |
33 | } | 33 | } |
34 | 34 | ||
35 | public override void Stop() | 35 | public override void Stop() |
36 | { | 36 | { |
37 | 37 | ||
38 | } | 38 | } |
39 | } | 39 | } |
40 | } | 40 | } |