csharp: FunctionPtr wrappers are not IDisposable

Summary:
They don't actually store unmanaged memory and we already rely on the GC
to free them (not calling Dispose() directly through the managedCb
closure, so we don't need IDisposable.

Just making sure we release the Function Pointer data in the main loop
as the GC runs in a different thread.

Ref T8423

Depends on D10672

Reviewers: brunobelo, felipealmeida, YOhoho

Reviewed By: brunobelo

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8423

Differential Revision: https://phab.enlightenment.org/D10673
This commit is contained in:
Lauro Moura 2019-11-15 00:09:29 -03:00
parent 2272e21b3c
commit e130d808cd
1 changed files with 2 additions and 23 deletions

View File

@ -72,7 +72,7 @@ struct function_pointer {
return false;
// Wrapper type, with callback matching the Unamanaged one
if (!as_generator("internal class " << f_name << "Wrapper : IDisposable\n"
if (!as_generator("internal class " << f_name << "Wrapper\n"
<< "{\n\n"
<< scope_tab << "private " << f_name << "Internal _cb;\n"
<< scope_tab << "private IntPtr _cb_data;\n"
@ -87,33 +87,12 @@ struct function_pointer {
<< scope_tab << "~" << f_name << "Wrapper()\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "Dispose(false);\n"
<< scope_tab << "}\n\n"
<< scope_tab << "protected virtual void Dispose(bool disposing)\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "if (this._cb_free_cb != null)\n"
<< scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << "if (disposing)\n"
<< scope_tab << scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "this._cb_free_cb(this._cb_data);\n"
<< scope_tab << scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << scope_tab << "else\n"
<< scope_tab << scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.ThreadSafeFreeCbExec(this._cb_free_cb, this._cb_data);\n"
<< scope_tab << scope_tab << scope_tab << "}\n"
<< scope_tab << scope_tab << scope_tab << "this._cb_free_cb = null;\n"
<< scope_tab << scope_tab << scope_tab << "this._cb_data = IntPtr.Zero;\n"
<< scope_tab << scope_tab << scope_tab << "this._cb = null;\n"
<< scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.ThreadSafeFreeCbExec(this._cb_free_cb, this._cb_data);\n"
<< scope_tab << scope_tab << "}\n"
<< scope_tab << "}\n\n"
<< scope_tab << "public void Dispose()\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "Dispose(true);\n"
<< scope_tab << scope_tab << "GC.SuppressFinalize(this);\n"
<< scope_tab << "}\n\n"
<< scope_tab << "internal " << type << " ManagedCb(" << (parameter % ", ") << ")\n"
<< scope_tab << "{\n"
<< function_definition_preamble << "_cb(_cb_data, " << (argument_invocation % ", ") << ");\n"