2004-05-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 13 May 2004 03:37:35 +0000 (03:37 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 13 May 2004 03:37:35 +0000 (03:37 -0000)
* WebAsyncResult.cs: don't create the WaitHandle if not needed.

svn path=/trunk/mcs/; revision=27219

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/WebAsyncResult.cs

index 9350a09c6fbe23d026148af17fbe0458e602b3b1..8a8c2f016d24d131ce2df3a6771a4e71b77b30f6 100644 (file)
@@ -1,3 +1,7 @@
+2004-05-13  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * WebAsyncResult.cs: don't create the WaitHandle if not needed.
+
 2004-05-13  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HttpWebRequest.cs: added 3 missing properties for 1.1. They are not
index f591db8c61730a67b3b26554575235f31f45c22a..4f1cc91dac332734afcb020cc01afe29ae0991e0 100644 (file)
@@ -29,6 +29,7 @@ namespace System.Net
                byte [] buffer;
                int offset;
                int size;
+               object locker = new object ();
 
                public WebAsyncResult (AsyncCallback cb, object state)
                {
@@ -54,50 +55,64 @@ namespace System.Net
 
                internal void SetCompleted (bool synch, Exception e)
                {
-                       isCompleted = true;
                        this.synch = synch;
                        exc = e;
-                       ((ManualResetEvent) AsyncWaitHandle).Set ();
+                       lock (locker) {
+                               isCompleted = true;
+                               if (handle != null)
+                                       handle.Set ();
+                       }
                }
                
                internal void Reset ()
                {
-                       isCompleted = false;
                        callbackDone = false;
                        exc = null;
                        request = null;
                        response = null;
                        writeStream = null;
                        exc = null;
-                       if (handle != null)
-                               handle.Reset ();
+                       lock (locker) {
+                               isCompleted = false;
+                               if (handle != null)
+                                       handle.Reset ();
+                       }
                }
 
                internal void SetCompleted (bool synch, int nbytes)
                {
-                       isCompleted = true;
                        this.synch = synch;
                        this.nbytes = nbytes;
                        exc = null;
-                       ((ManualResetEvent) AsyncWaitHandle).Set ();
+                       lock (locker) {
+                               isCompleted = true;
+                               if (handle != null)
+                                       handle.Set ();
+                       }
                }
                
                internal void SetCompleted (bool synch, Stream writeStream)
                {
-                       isCompleted = true;
                        this.synch = synch;
                        this.writeStream = writeStream;
                        exc = null;
-                       ((ManualResetEvent) AsyncWaitHandle).Set ();
+                       lock (locker) {
+                               isCompleted = true;
+                               if (handle != null)
+                                       handle.Set ();
+                       }
                }
                
                internal void SetCompleted (bool synch, HttpWebResponse response)
                {
-                       isCompleted = true;
                        this.synch = synch;
                        this.response = response;
                        exc = null;
-                       ((ManualResetEvent) AsyncWaitHandle).Set ();
+                       lock (locker) {
+                               isCompleted = true;
+                               if (handle != null)
+                                       handle.Set ();
+                       }
                }
                
                internal void DoCallback ()
@@ -110,7 +125,7 @@ namespace System.Net
                
                internal void WaitUntilComplete ()
                {
-                       if (isCompleted)
+                       if (IsCompleted)
                                return;
 
                        AsyncWaitHandle.WaitOne ();
@@ -118,7 +133,7 @@ namespace System.Net
 
                internal bool WaitUntilComplete (int timeout, bool exitContext)
                {
-                       if (isCompleted)
+                       if (IsCompleted)
                                return true;
 
                        return AsyncWaitHandle.WaitOne (timeout, exitContext);
@@ -130,11 +145,9 @@ namespace System.Net
 
                public WaitHandle AsyncWaitHandle {
                        get {
-                               if (handle == null) {
-                                       lock (this) {
-                                               if (handle == null)
-                                                       handle = new ManualResetEvent (isCompleted);
-                                       }
+                               lock (locker) {
+                                       if (handle == null)
+                                               handle = new ManualResetEvent (isCompleted);
                                }
                                
                                return handle;
@@ -146,7 +159,11 @@ namespace System.Net
                }
 
                public bool IsCompleted {
-                       get { return isCompleted; }
+                       get {
+                               lock (locker) {
+                                       return isCompleted;
+                               }
+                       }
                }
 
                internal bool GotException {