aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-03-18 20:24:53 +0000
committerJustin Clarke Casey2009-03-18 20:24:53 +0000
commitc0c929665f652900b36f31f2446c8ae39ffd1291 (patch)
treec02fcb8f68f62ba60447392c94953830b0cab627 /OpenSim/Region
parentAdds support for unlink-region command in hypergrid. (diff)
downloadopensim-SC_OLD-c0c929665f652900b36f31f2446c8ae39ffd1291.zip
opensim-SC_OLD-c0c929665f652900b36f31f2446c8ae39ffd1291.tar.gz
opensim-SC_OLD-c0c929665f652900b36f31f2446c8ae39ffd1291.tar.bz2
opensim-SC_OLD-c0c929665f652900b36f31f2446c8ae39ffd1291.tar.xz
* Apply http://opensimulator.org/mantis/view.php?id=3311
* Store script timers in a dictionary rather than a list to make unset much more efficient * Thanks dslake
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs32
1 files changed, 22 insertions, 10 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index d08790c..09351fd 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -45,6 +45,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
45 // 45 //
46 // TIMER 46 // TIMER
47 // 47 //
48 static private string MakeTimerKey(uint localID, UUID itemID)
49 {
50 return localID.ToString() + itemID.ToString();
51 }
52
53
48 private class TimerClass 54 private class TimerClass
49 { 55 {
50 public uint localID; 56 public uint localID;
@@ -55,15 +61,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
55 public long next; 61 public long next;
56 } 62 }
57 63
58 private List<TimerClass> Timers = new List<TimerClass>(); 64 private Dictionary<string,TimerClass> Timers = new Dictionary<string,TimerClass>();
59 private object TimerListLock = new object(); 65 private object TimerListLock = new object();
60 66
61 public void SetTimerEvent(uint m_localID, UUID m_itemID, double sec) 67 public void SetTimerEvent(uint m_localID, UUID m_itemID, double sec)
62 { 68 {
63 // Always remove first, in case this is a re-set
64 UnSetTimerEvents(m_localID, m_itemID);
65 if (sec == 0) // Disabling timer 69 if (sec == 0) // Disabling timer
70 {
71 UnSetTimerEvents(m_localID, m_itemID);
66 return; 72 return;
73 }
67 74
68 // Add to timer 75 // Add to timer
69 TimerClass ts = new TimerClass(); 76 TimerClass ts = new TimerClass();
@@ -75,21 +82,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
75 82
76 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); 83 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
77 ts.next = DateTime.Now.Ticks + ts.interval; 84 ts.next = DateTime.Now.Ticks + ts.interval;
85
86 string key = MakeTimerKey(m_localID, m_itemID);
78 lock (TimerListLock) 87 lock (TimerListLock)
79 { 88 {
80 Timers.Add(ts); 89 // Adds if timer doesn't exist, otherwise replaces with new timer
90 Timers[key] = ts;
81 } 91 }
82 } 92 }
83 93
84 public void UnSetTimerEvents(uint m_localID, UUID m_itemID) 94 public void UnSetTimerEvents(uint m_localID, UUID m_itemID)
85 { 95 {
86 // Remove from timer 96 // Remove from timer
97 string key = MakeTimerKey(m_localID, m_itemID);
87 lock (TimerListLock) 98 lock (TimerListLock)
88 { 99 {
89 foreach (TimerClass ts in new ArrayList(Timers)) 100 if (Timers.ContainsKey(key))
90 { 101 {
91 if (ts.localID == m_localID && ts.itemID == m_itemID) 102 Timers.Remove(key);
92 Timers.Remove(ts);
93 } 103 }
94 } 104 }
95 } 105 }
@@ -103,7 +113,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
103 lock (TimerListLock) 113 lock (TimerListLock)
104 { 114 {
105 // Go through all timers 115 // Go through all timers
106 foreach (TimerClass ts in Timers) 116 Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values;
117 foreach (TimerClass ts in tvals)
107 { 118 {
108 // Time has passed? 119 // Time has passed?
109 if (ts.next < DateTime.Now.Ticks) 120 if (ts.next < DateTime.Now.Ticks)
@@ -128,7 +139,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
128 139
129 lock (TimerListLock) 140 lock (TimerListLock)
130 { 141 {
131 foreach (TimerClass ts in Timers) 142 Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values;
143 foreach (TimerClass ts in tvals)
132 { 144 {
133 if (ts.itemID == itemID) 145 if (ts.itemID == itemID)
134 { 146 {
@@ -155,7 +167,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
155 ts.next = DateTime.Now.Ticks + (long)data[idx+1]; 167 ts.next = DateTime.Now.Ticks + (long)data[idx+1];
156 idx += 2; 168 idx += 2;
157 169
158 Timers.Add(ts); 170 Timers.Add(MakeTimerKey(localID,itemID), ts);
159 } 171 }
160 } 172 }
161 } 173 }