diff options
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | 78 |
1 files changed, 43 insertions, 35 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 19f3ce1..f6c8e38 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -51,8 +51,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
51 | { | 51 | { |
52 | get | 52 | get |
53 | { | 53 | { |
54 | lock (SenseRepeatListLock) | 54 | return SenseRepeaters.Count; |
55 | return SenseRepeaters.Count; | ||
56 | } | 55 | } |
57 | } | 56 | } |
58 | 57 | ||
@@ -115,6 +114,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
115 | public double distance; | 114 | public double distance; |
116 | } | 115 | } |
117 | 116 | ||
117 | /// <summary> | ||
118 | /// Sensors to process. | ||
119 | /// </summary> | ||
120 | /// <remarks> | ||
121 | /// Do not add or remove sensors from this list directly. Instead, copy the list and substitute the updated | ||
122 | /// copy. This is to avoid locking the list for the duration of the sensor sweep, which increases the danger | ||
123 | /// of deadlocks with future code updates. | ||
124 | /// | ||
125 | /// Always lock SenseRepeatListLock when updating this list. | ||
126 | /// </remarks> | ||
118 | private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>(); | 127 | private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>(); |
119 | private object SenseRepeatListLock = new object(); | 128 | private object SenseRepeatListLock = new object(); |
120 | 129 | ||
@@ -124,6 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
124 | { | 133 | { |
125 | // Always remove first, in case this is a re-set | 134 | // Always remove first, in case this is a re-set |
126 | UnSetSenseRepeaterEvents(m_localID, m_itemID); | 135 | UnSetSenseRepeaterEvents(m_localID, m_itemID); |
136 | |||
127 | if (sec == 0) // Disabling timer | 137 | if (sec == 0) // Disabling timer |
128 | return; | 138 | return; |
129 | 139 | ||
@@ -143,9 +153,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
143 | ts.host = host; | 153 | ts.host = host; |
144 | 154 | ||
145 | ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); | 155 | ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); |
156 | |||
157 | AddSenseRepeater(ts); | ||
158 | } | ||
159 | |||
160 | private void AddSenseRepeater(SenseRepeatClass senseRepeater) | ||
161 | { | ||
146 | lock (SenseRepeatListLock) | 162 | lock (SenseRepeatListLock) |
147 | { | 163 | { |
148 | SenseRepeaters.Add(ts); | 164 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(SenseRepeaters); |
165 | newSenseRepeaters.Add(senseRepeater); | ||
166 | SenseRepeaters = newSenseRepeaters; | ||
149 | } | 167 | } |
150 | } | 168 | } |
151 | 169 | ||
@@ -154,39 +172,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
154 | // Remove from timer | 172 | // Remove from timer |
155 | lock (SenseRepeatListLock) | 173 | lock (SenseRepeatListLock) |
156 | { | 174 | { |
157 | List<SenseRepeatClass> NewSensors = new List<SenseRepeatClass>(); | 175 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(); |
158 | foreach (SenseRepeatClass ts in SenseRepeaters) | 176 | foreach (SenseRepeatClass ts in SenseRepeaters) |
159 | { | 177 | { |
160 | if (ts.localID != m_localID || ts.itemID != m_itemID) | 178 | if (ts.localID != m_localID || ts.itemID != m_itemID) |
161 | { | 179 | { |
162 | NewSensors.Add(ts); | 180 | newSenseRepeaters.Add(ts); |
163 | } | 181 | } |
164 | } | 182 | } |
165 | SenseRepeaters.Clear(); | 183 | |
166 | SenseRepeaters = NewSensors; | 184 | SenseRepeaters = newSenseRepeaters; |
167 | } | 185 | } |
168 | } | 186 | } |
169 | 187 | ||
170 | public void CheckSenseRepeaterEvents() | 188 | public void CheckSenseRepeaterEvents() |
171 | { | 189 | { |
172 | lock (SenseRepeatListLock) | 190 | // Go through all timers |
191 | foreach (SenseRepeatClass ts in SenseRepeaters) | ||
173 | { | 192 | { |
174 | // Nothing to do here? | 193 | // Time has passed? |
175 | if (SenseRepeaters.Count == 0) | 194 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) |
176 | return; | ||
177 | |||
178 | // Go through all timers | ||
179 | foreach (SenseRepeatClass ts in SenseRepeaters) | ||
180 | { | 195 | { |
181 | // Time has passed? | 196 | SensorSweep(ts); |
182 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) | 197 | // set next interval |
183 | { | 198 | ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); |
184 | SensorSweep(ts); | ||
185 | // set next interval | ||
186 | ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); | ||
187 | } | ||
188 | } | 199 | } |
189 | } // lock | 200 | } |
190 | } | 201 | } |
191 | 202 | ||
192 | public void SenseOnce(uint m_localID, UUID m_itemID, | 203 | public void SenseOnce(uint m_localID, UUID m_itemID, |
@@ -619,21 +630,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
619 | { | 630 | { |
620 | List<Object> data = new List<Object>(); | 631 | List<Object> data = new List<Object>(); |
621 | 632 | ||
622 | lock (SenseRepeatListLock) | 633 | foreach (SenseRepeatClass ts in SenseRepeaters) |
623 | { | 634 | { |
624 | foreach (SenseRepeatClass ts in SenseRepeaters) | 635 | if (ts.itemID == itemID) |
625 | { | 636 | { |
626 | if (ts.itemID == itemID) | 637 | data.Add(ts.interval); |
627 | { | 638 | data.Add(ts.name); |
628 | data.Add(ts.interval); | 639 | data.Add(ts.keyID); |
629 | data.Add(ts.name); | 640 | data.Add(ts.type); |
630 | data.Add(ts.keyID); | 641 | data.Add(ts.range); |
631 | data.Add(ts.type); | 642 | data.Add(ts.arc); |
632 | data.Add(ts.range); | ||
633 | data.Add(ts.arc); | ||
634 | } | ||
635 | } | 643 | } |
636 | } | 644 | } |
645 | |||
637 | return data.ToArray(); | 646 | return data.ToArray(); |
638 | } | 647 | } |
639 | 648 | ||
@@ -667,8 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
667 | ts.next = | 676 | ts.next = |
668 | DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); | 677 | DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); |
669 | 678 | ||
670 | lock (SenseRepeatListLock) | 679 | AddSenseRepeater(ts); |
671 | SenseRepeaters.Add(ts); | ||
672 | 680 | ||
673 | idx += 6; | 681 | idx += 6; |
674 | } | 682 | } |