forked from enlightenment/efl
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
This commit is contained in:
parent
6d8e39a642
commit
d5c8d05292
|
@ -447,36 +447,30 @@ struct event_definition_generator
|
|||
scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << "add\n"
|
||||
<< scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "if (obj != null)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "if (obj != null)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << event_args
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "try\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << event_args
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "try\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "value?.Invoke(obj, args);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "catch (Exception e)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error(e.ToString());\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "value?.Invoke(obj, args);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "};\n\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "}\n" // End of lock block
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "catch (Exception e)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Log.Error(e.ToString());\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "};\n\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "AddNativeEventHandler(" << library_name << ", key, callerCb, value);\n"
|
||||
<< scope_tab << scope_tab << "}\n\n"
|
||||
<< scope_tab << scope_tab << "remove\n"
|
||||
<< scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "{\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
|
||||
<< scope_tab << scope_tab << scope_tab << scope_tab << "RemoveNativeEventHandler(" << library_name << ", key, value);\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "}\n" // End of lock block
|
||||
<< scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
|
||||
<< scope_tab << scope_tab << scope_tab << "RemoveNativeEventHandler(" << library_name << ", key, value);\n"
|
||||
<< scope_tab << scope_tab << "}\n"
|
||||
<< scope_tab << "}\n\n"
|
||||
).generate(sink, attributes::unused, context);
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Eo
|
|||
public abstract class EoWrapper : IWrapper, IDisposable
|
||||
{
|
||||
/// <summary>Object used to synchronize access to EFL events.</summary>
|
||||
protected readonly object eflBindingEventLock = new object();
|
||||
private readonly object eflBindingEventLock = new object();
|
||||
private bool generated = true;
|
||||
private System.IntPtr handle = IntPtr.Zero;
|
||||
|
||||
|
@ -214,6 +214,8 @@ public abstract class EoWrapper : IWrapper, IDisposable
|
|||
/// <param name="evtCaller">Delegate to be called by native code on event raising.</param>
|
||||
/// <param name="evtDelegate">Managed delegate that will be called by evtCaller on event raising.</param>
|
||||
protected void AddNativeEventHandler(string lib, string key, Efl.EventCb evtCaller, object evtDelegate)
|
||||
{
|
||||
lock (eflBindingEventLock)
|
||||
{
|
||||
IntPtr desc = Efl.EventDescription.GetNative(lib, key);
|
||||
if (desc == IntPtr.Zero)
|
||||
|
@ -240,12 +242,15 @@ public abstract class EoWrapper : IWrapper, IDisposable
|
|||
ws.EoEvents[(desc, evtDelegate)] = (evtCallerPtr, evtCaller);
|
||||
Eina.Error.RaiseIfUnhandledException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Removes the given event handler for the given event. For internal use only.</summary>
|
||||
/// <param name="lib">The name of the native library definining the event.</param>
|
||||
/// <param name="key">The name of the native event.</param>
|
||||
/// <param name="evtDelegate">The delegate to be removed.</param>
|
||||
protected void RemoveNativeEventHandler(string lib, string key, object evtDelegate)
|
||||
{
|
||||
lock (eflBindingEventLock)
|
||||
{
|
||||
IntPtr desc = Efl.EventDescription.GetNative(lib, key);
|
||||
if (desc == IntPtr.Zero)
|
||||
|
@ -273,6 +278,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
|
|||
Eina.Log.Error($"Trying to remove proxy for event {key} when it is not registered.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue