summaryrefslogtreecommitdiff
path: root/src/bindings/mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-10-03 20:52:25 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-10-04 10:12:57 -0300
commitd5c8d0529278300eb889881b4774deebc4d46f31 (patch)
treef5af4c8c4fb6851ad8b1efecae7597c0c5297a9f /src/bindings/mono
parent6d8e39a6425e721eb40e0cb1e67f1cbf5b223cc0 (diff)
csharp: Move locks inside AddRemove native handlers
Summary: Instead of using a lock block in every method definition, we just need them inside the actual methods adding/removing the handlers. Kudos to @herb for the suggestion. Reviewers: felipealmeida, herb, brunobelo Reviewed By: brunobelo Subscribers: cedric, #reviewers, herb, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9758
Diffstat (limited to 'src/bindings/mono')
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 79d597c..eae4eea 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -20,7 +20,7 @@ namespace Eo
20public abstract class EoWrapper : IWrapper, IDisposable 20public abstract class EoWrapper : IWrapper, IDisposable
21{ 21{
22 /// <summary>Object used to synchronize access to EFL events.</summary> 22 /// <summary>Object used to synchronize access to EFL events.</summary>
23 protected readonly object eflBindingEventLock = new object(); 23 private readonly object eflBindingEventLock = new object();
24 private bool generated = true; 24 private bool generated = true;
25 private System.IntPtr handle = IntPtr.Zero; 25 private System.IntPtr handle = IntPtr.Zero;
26 26
@@ -215,30 +215,33 @@ public abstract class EoWrapper : IWrapper, IDisposable
215 /// <param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param> 215 /// <param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param>
216 protected void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate) 216 protected void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate)
217 { 217 {
218 IntPtr desc = Efl.EventDescription.GetNative(lib, key); 218 lock (eflBindingEventLock)
219 if (desc == IntPtr.Zero)
220 { 219 {
221 Eina.Log.Error($"Failed to get native event {key}"); 220 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
222 return; 221 if (desc == IntPtr.Zero)
223 } 222 {
223 Eina.Log.Error($"Failed to get native event {key}");
224 return;
225 }
224 226
225 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle); 227 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
226 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr); 228 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
227 if (ws.EoEvents.ContainsKey((desc, evtDelegate))) 229 if (ws.EoEvents.ContainsKey((desc, evtDelegate)))
228 { 230 {
229 Eina.Log.Warning($"Event proxy for event {key} already registered!"); 231 Eina.Log.Warning($"Event proxy for event {key} already registered!");
230 return; 232 return;
231 } 233 }
232 234
233 IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller); 235 IntPtr evtCallerPtr = Marshal.GetFunctionPointerForDelegate(evtCaller);
234 if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, wsPtr)) 236 if (!Efl.Eo.Globals.efl_event_callback_priority_add(handle, desc, 0, evtCallerPtr, wsPtr))
235 { 237 {
236 Eina.Log.Error($"Failed to add event proxy for event {key}"); 238 Eina.Log.Error($"Failed to add event proxy for event {key}");
237 return; 239 return;
238 } 240 }
239 241
240 ws.EoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller); 242 ws.EoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller);
241 Eina.Error.RaiseIfUnhandledException(); 243 Eina.Error.RaiseIfUnhandledException();
244 }
242 } 245 }
243 246
244 /// <summary>Removes the given event handler for the given event. For internal use only.</summary> 247 /// <summary>Removes the given event handler for the given event. For internal use only.</summary>
@@ -247,30 +250,33 @@ public abstract class EoWrapper : IWrapper, IDisposable
247 /// <param name="evtDelegate">The delegate to be removed.</param> 250 /// <param name="evtDelegate">The delegate to be removed.</param>
248 protected void RemoveNativeEventHandler(string lib, string key, object evtDelegate) 251 protected void RemoveNativeEventHandler(string lib, string key, object evtDelegate)
249 { 252 {
250 IntPtr desc = Efl.EventDescription.GetNative(lib, key); 253 lock (eflBindingEventLock)
251 if (desc == IntPtr.Zero)
252 { 254 {
253 Eina.Log.Error($"Failed to get native event {key}"); 255 IntPtr desc = Efl.EventDescription.GetNative(lib, key);
254 return; 256 if (desc == IntPtr.Zero)
255 }
256
257 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
258 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
259 var evtPair = (desc, evtDelegate);
260 if (ws.EoEvents.TryGetValue(evtPair, out var caller))
261 {
262 if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, wsPtr))
263 { 257 {
264 Eina.Log.Error($"Failed to remove event proxy for event {key}"); 258 Eina.Log.Error($"Failed to get native event {key}");
265 return; 259 return;
266 } 260 }
267 261
268 ws.EoEvents.Remove(evtPair); 262 var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(handle);
269 Eina.Error.RaiseIfUnhandledException(); 263 var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(wsPtr);
270 } 264 var evtPair = (desc, evtDelegate);
271 else 265 if (ws.EoEvents.TryGetValue(evtPair, out var caller))
272 { 266 {
273 Eina.Log.Error($"Trying to remove proxy for event {key} when it is not registered."); 267 if (!Efl.Eo.Globals.efl_event_callback_del(handle, desc, caller.evtCallerPtr, wsPtr))
268 {
269 Eina.Log.Error($"Failed to remove event proxy for event {key}");
270 return;
271 }
272
273 ws.EoEvents.Remove(evtPair);
274 Eina.Error.RaiseIfUnhandledException();
275 }
276 else
277 {
278 Eina.Log.Error($"Trying to remove proxy for event {key} when it is not registered.");
279 }
274 } 280 }
275 } 281 }
276 282