summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-04-15 14:09:49 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-04-15 15:24:29 -0300
commitd775b58a630d6d0fd2ac2176df91bc1142a5276f (patch)
tree38895770f372109df25e6ea64036f1a9cfbd2daf /src/bindings
parent7a552024995861e44c301ea8bd7751895e4f8ceb (diff)
csharp: Fix free_cb calling under dotnet.
Summary: dotnet's GC seems to be more agressive, showing some issues that usually do not appear when running under Mono's. This commit uses for free_cb's the same scheme we already use for regular Eo refs, using a GC handle to keep the cleaning callback alive. Reviewers: vitor.sousa, felipealmeida, woohyun Reviewed By: vitor.sousa Subscribers: segfaultxavi, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8593
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/efl_mono/efl_all.cs21
-rw-r--r--src/bindings/mono/eina_mono/eina_accessor.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_binbuf.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_iterator.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_strbuf.cs2
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs2
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_connection.cs2
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_message.cs2
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_object.cs2
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_proxy.cs2
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs39
14 files changed, 57 insertions, 27 deletions
diff --git a/src/bindings/mono/efl_mono/efl_all.cs b/src/bindings/mono/efl_mono/efl_all.cs
index 70b9825b9d..9a49730093 100644
--- a/src/bindings/mono/efl_mono/efl_all.cs
+++ b/src/bindings/mono/efl_mono/efl_all.cs
@@ -43,6 +43,13 @@ public static class All
43{ 43{
44 private static bool InitializedUi = false; 44 private static bool InitializedUi = false;
45 45
46 public static bool MainLoopInitialized {
47 get;
48 private set;
49 }
50
51 public static readonly object InitLock = new object();
52
46 public static void Init(Efl.Csharp.Components components = Efl.Csharp.Components.Basic) 53 public static void Init(Efl.Csharp.Components components = Efl.Csharp.Components.Basic)
47 { 54 {
48 Eina.Config.Init(); 55 Eina.Config.Init();
@@ -56,24 +63,38 @@ public static class All
56 Efl.Ui.Config.Init(); 63 Efl.Ui.Config.Init();
57 InitializedUi = true; 64 InitializedUi = true;
58 } 65 }
66 Monitor.Enter(InitLock);
67 MainLoopInitialized = true;
68 Monitor.Exit(InitLock);
59 } 69 }
60 70
61 /// <summary>Shutdowns all EFL subsystems.</summary> 71 /// <summary>Shutdowns all EFL subsystems.</summary>
62 public static void Shutdown() 72 public static void Shutdown()
63 { 73 {
64 // Try to cleanup everything before actually shutting down. 74 // Try to cleanup everything before actually shutting down.
75 Eina.Log.Debug("Calling GC before shutdown");
65 System.GC.Collect(); 76 System.GC.Collect();
66 System.GC.WaitForPendingFinalizers(); 77 System.GC.WaitForPendingFinalizers();
67 78
79 Monitor.Enter(InitLock);
80 MainLoopInitialized = false;
81 Monitor.Exit(InitLock);
82
68 if (InitializedUi) 83 if (InitializedUi)
69 { 84 {
85 Eina.Log.Debug("Shutting down Elementary");
70 Efl.Ui.Config.Shutdown(); 86 Efl.Ui.Config.Shutdown();
71 } 87 }
72 88
89 Eina.Log.Debug("Shutting down Eldbus");
73 eldbus.Config.Shutdown(); 90 eldbus.Config.Shutdown();
91 Eina.Log.Debug("Shutting down Evas");
74 evas_shutdown(); 92 evas_shutdown();
93 Eina.Log.Debug("Shutting down Ecore");
75 ecore_shutdown(); 94 ecore_shutdown();
95 Eina.Log.Debug("Shutting down Eo");
76 Efl.Eo.Config.Shutdown(); 96 Efl.Eo.Config.Shutdown();
97 Eina.Log.Debug("Shutting down Eina");
77 Eina.Config.Shutdown(); 98 Eina.Config.Shutdown();
78 } 99 }
79} 100}
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs
index d14a2039d5..bafbbd84fe 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -78,7 +78,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
78 } 78 }
79 else 79 else
80 { 80 {
81 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_accessor_free, Handle); 81 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_accessor_free, Handle);
82 } 82 }
83 Handle = IntPtr.Zero; 83 Handle = IntPtr.Zero;
84 } 84 }
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index afa73e9775..e3bd852e2b 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -155,7 +155,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
155 } 155 }
156 else 156 else
157 { 157 {
158 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_array_free, h); 158 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_array_free, h);
159 } 159 }
160 } 160 }
161 } 161 }
diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs
index 2ae04ec1bd..e5dc817085 100644
--- a/src/bindings/mono/eina_mono/eina_binbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_binbuf.cs
@@ -109,7 +109,7 @@ public class Binbuf : IDisposable
109 } 109 }
110 else 110 else
111 { 111 {
112 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_binbuf_free, Handle); 112 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_binbuf_free, Handle);
113 } 113 }
114 } 114 }
115 } 115 }
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index d74c96970b..8b3c1e7db5 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -193,7 +193,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
193 } 193 }
194 else 194 else
195 { 195 {
196 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_hash_free, h); 196 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_hash_free, h);
197 } 197 }
198 } 198 }
199 } 199 }
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index 8fbd89191c..c7f3151ac1 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -147,7 +147,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
147 } 147 }
148 else 148 else
149 { 149 {
150 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_inarray_free, h); 150 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_inarray_free, h);
151 } 151 }
152 } 152 }
153 } 153 }
diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs
index 75ca1b2785..05b5408606 100644
--- a/src/bindings/mono/eina_mono/eina_iterator.cs
+++ b/src/bindings/mono/eina_mono/eina_iterator.cs
@@ -79,7 +79,7 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
79 } 79 }
80 else 80 else
81 { 81 {
82 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_iterator_free, h); 82 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_iterator_free, h);
83 } 83 }
84 } 84 }
85 } 85 }
diff --git a/src/bindings/mono/eina_mono/eina_strbuf.cs b/src/bindings/mono/eina_mono/eina_strbuf.cs
index 927a21da08..a538de0fd2 100644
--- a/src/bindings/mono/eina_mono/eina_strbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_strbuf.cs
@@ -99,7 +99,7 @@ public class Strbuf : IDisposable
99 } 99 }
100 else 100 else
101 { 101 {
102 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_strbuf_free, Handle); 102 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_strbuf_free, Handle);
103 } 103 }
104 104
105 Handle = IntPtr.Zero; 105 Handle = IntPtr.Zero;
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index 3c9cb53ced..627c7cb343 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -1411,7 +1411,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1411 } 1411 }
1412 else 1412 else
1413 { 1413 {
1414 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eina_value_free, this.Handle); 1414 Efl.Eo.Globals.ThreadSafeFreeCbExec(eina_value_free, this.Handle);
1415 } 1415 }
1416 } 1416 }
1417 1417
diff --git a/src/bindings/mono/eldbus_mono/eldbus_connection.cs b/src/bindings/mono/eldbus_mono/eldbus_connection.cs
index ea8a45f7a1..f88f0ac598 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_connection.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_connection.cs
@@ -167,7 +167,7 @@ public class Connection : IDisposable
167 } 167 }
168 else 168 else
169 { 169 {
170 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_connection_unref, h); 170 Efl.Eo.Globals.ThreadSafeFreeCbExec(eldbus_connection_unref, h);
171 } 171 }
172 } 172 }
173 } 173 }
diff --git a/src/bindings/mono/eldbus_mono/eldbus_message.cs b/src/bindings/mono/eldbus_mono/eldbus_message.cs
index eec9167d18..559c2f10b9 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_message.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_message.cs
@@ -236,7 +236,7 @@ public class Message : IDisposable
236 } 236 }
237 else 237 else
238 { 238 {
239 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_message_unref, h); 239 Efl.Eo.Globals.ThreadSafeFreeCbExec(eldbus_message_unref, h);
240 } 240 }
241 } 241 }
242 } 242 }
diff --git a/src/bindings/mono/eldbus_mono/eldbus_object.cs b/src/bindings/mono/eldbus_mono/eldbus_object.cs
index 136e8407ac..682fda6565 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_object.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_object.cs
@@ -158,7 +158,7 @@ public class Object : System.IDisposable
158 } 158 }
159 else 159 else
160 { 160 {
161 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_object_unref, h); 161 Efl.Eo.Globals.ThreadSafeFreeCbExec(eldbus_object_unref, h);
162 } 162 }
163 } 163 }
164 } 164 }
diff --git a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
index c8ac4d265a..f5eec40d43 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
@@ -117,7 +117,7 @@ public class Proxy : IDisposable
117 } 117 }
118 else 118 else
119 { 119 {
120 Efl.Eo.Globals.efl_mono_thread_safe_free_cb_exec(eldbus_proxy_unref, h); 120 Efl.Eo.Globals.ThreadSafeFreeCbExec(eldbus_proxy_unref, h);
121 } 121 }
122 } 122 }
123 } 123 }
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 4f4181d244..503b71ad28 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -77,7 +77,7 @@ public class Globals
77 efl_mono_thread_safe_efl_unref(IntPtr eo); 77 efl_mono_thread_safe_efl_unref(IntPtr eo);
78 78
79 [DllImport(efl.Libs.CustomExports)] public static extern void 79 [DllImport(efl.Libs.CustomExports)] public static extern void
80 efl_mono_thread_safe_free_cb_exec(EinaFreeCb free_cb, IntPtr cb_data); 80 efl_mono_thread_safe_free_cb_exec(IntPtr free_cb, IntPtr cb_data);
81 81
82 [DllImport(efl.Libs.Eo)] public static extern IntPtr 82 [DllImport(efl.Libs.Eo)] public static extern IntPtr
83 efl_class_name_get(IntPtr eo); 83 efl_class_name_get(IntPtr eo);
@@ -653,6 +653,7 @@ public class Globals
653 return ret; 653 return ret;
654 } 654 }
655 655
656 private static Efl.FreeGCHandleCb FreeGCHandleCallbackDelegate = new Efl.FreeGCHandleCb(FreeGCHandleCallback);
656 public static void FreeGCHandleCallback(IntPtr gcHandlePtr) 657 public static void FreeGCHandleCallback(IntPtr gcHandlePtr)
657 { 658 {
658 try 659 try
@@ -667,6 +668,7 @@ public class Globals
667 } 668 }
668 } 669 }
669 670
671 private static Efl.RemoveEventsCb RemoveEventsCallbackDelegate = new Efl.RemoveEventsCb(RemoveEventsCallback);
670 public static void RemoveEventsCallback(IntPtr obj, IntPtr gcHandlePtr) 672 public static void RemoveEventsCallback(IntPtr obj, IntPtr gcHandlePtr)
671 { 673 {
672 try 674 try
@@ -696,35 +698,42 @@ public class Globals
696 698
697 public static void SetNativeDisposeCallbacks() 699 public static void SetNativeDisposeCallbacks()
698 { 700 {
699 efl_mono_gchandle_callbacks_set(FreeGCHandleCallback, RemoveEventsCallback); 701 efl_mono_gchandle_callbacks_set(FreeGCHandleCallbackDelegate, RemoveEventsCallbackDelegate);
700 } 702 }
701 703
702} // Globals 704 public static void ThreadSafeFreeCbExec(EinaFreeCb cbFreeCb, IntPtr cbData)
705 {
706 EinaFreeCb cb = (IntPtr gcHandlePtr) => {
707 cbFreeCb(cbData);
708 GCHandle gcHandle = GCHandle.FromIntPtr(gcHandlePtr);
709 gcHandle.Free();
710 };
703 711
704public static class Config 712 Monitor.Enter(Efl.All.InitLock);
705{ 713 if (Efl.All.MainLoopInitialized)
714 {
715 IntPtr cbPtr = Marshal.GetFunctionPointerForDelegate(cb);
716 var handle = GCHandle.Alloc(cb);
717 var handlePtr = GCHandle.ToIntPtr(handle);
706 718
707 public static bool Initialized { 719 efl_mono_thread_safe_free_cb_exec(cbPtr, handlePtr);
708 get; 720 }
709 private set; 721 Monitor.Exit(Efl.All.InitLock);
710 } 722 }
711 723
712 public static readonly object InitLock = new object(); 724} // Globals
725
726public static class Config
727{
713 728
714 public static void Init() 729 public static void Init()
715 { 730 {
716 Globals.efl_object_init(); 731 Globals.efl_object_init();
717 Monitor.Enter(InitLock);
718 Initialized = true;
719 Monitor.Exit(InitLock);
720 Globals.SetNativeDisposeCallbacks(); 732 Globals.SetNativeDisposeCallbacks();
721 } 733 }
722 734
723 public static void Shutdown() 735 public static void Shutdown()
724 { 736 {
725 Monitor.Enter(InitLock);
726 Initialized = false;
727 Monitor.Exit(InitLock);
728 Globals.efl_object_shutdown(); 737 Globals.efl_object_shutdown();
729 } 738 }
730} 739}