Avoid potential race conditions on the Dispose() method

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9444 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-10-12 23:10:18 +00:00
commit ea6f44edd2
4 changed files with 35 additions and 19 deletions

View file

@ -6,6 +6,9 @@ Version 1.3.30 (in progress)
(it is now a synchronized method, but is now customisable by changing the
methodmodifier attribute in the the javadestruct or javadestruct_derived typemap)
[C#] Remove potential race condition on the proxy class' Dispose() method,
similar to Java's delete() above.
*** POTENTIAL INCOMPATIBILITY ***
10/12/2006: wsfulton

View file

@ -1071,12 +1071,14 @@ public class Base : IDisposable {
}
public virtual void Dispose() {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
examplePINVOKE.delete_Base(swigCPtr);
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
examplePINVOKE.delete_Base(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
public virtual uint UIntMethod(uint x) {

View file

@ -787,23 +787,27 @@
}
%}
%typemap(csdestruct, methodname="Dispose") SWIGTYPE {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
}
%typemap(csdestruct_derived, methodname="Dispose") SWIGTYPE {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
swigCMemOwn = false;
$imcall;
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
base.Dispose();
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
base.Dispose();
}
%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{

View file

@ -1542,17 +1542,24 @@ class CSHARP : public Language {
const String *tm = NULL;
Node *attributes = NewHash();
String *destruct_methodname = NULL;
String *destruct_methodmodifiers = NULL;
if (derived) {
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers");
} else {
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes);
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers");
}
if (!destruct_methodname) {
Swig_error(input_file, line_number,
"No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name);
}
if (!destruct_methodmodifiers) {
Swig_error(input_file, line_number,
"No methodmodifier attribute defined in csdestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name);
}
// Emit the Finalize and Dispose methods
if (tm) {
@ -1569,7 +1576,7 @@ class CSHARP : public Language {
else
Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")");
if (*Char(destruct))
Printv(proxy_class_def, "\n public ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL);
Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL);
}
if (feature_director) {