Author: gonzalo
Date: 2005-04-28 20:19:42 -0400 (Thu, 28 Apr 2005)
New Revision: 43757

Modified:
   trunk/mcs/class/corlib/System.Threading/ChangeLog
   trunk/mcs/class/corlib/System.Threading/ReaderWriterLock.cs
Log:
2005-04-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * ReaderWriterLock.cs: fix random ApplicationException errors. Tested
        with the System.Web.Cache stress program. Patch by Eyal Alayuf
        (Mainsoft). Fixes 74598.



Modified: trunk/mcs/class/corlib/System.Threading/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ChangeLog   2005-04-28 23:48:39 UTC 
(rev 43756)
+++ trunk/mcs/class/corlib/System.Threading/ChangeLog   2005-04-29 00:19:42 UTC 
(rev 43757)
@@ -1,3 +1,9 @@
+2005-04-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * ReaderWriterLock.cs: fix random ApplicationException errors. Tested
+       with the System.Web.Cache stress program. Patch by Eyal Alayuf
+       (Mainsoft). Fixes 74598.
+
 2005-04-28  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Thread.cs: Added property to get the ExecutionContext in 2.0. Fixed
@@ -16,6 +22,7 @@
        * HostExecutionContextManager.cs: Updated wrt beta2.
        * Thread.cs: Added internal property to get the ExecutionContext.
 
+>>>>>>> .r43756
 2005-04-19  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * Thread.cs: Add some unused fields.

Modified: trunk/mcs/class/corlib/System.Threading/ReaderWriterLock.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ReaderWriterLock.cs 2005-04-28 
23:48:39 UTC (rev 43756)
+++ trunk/mcs/class/corlib/System.Threading/ReaderWriterLock.cs 2005-04-29 
00:19:42 UTC (rev 43757)
@@ -40,12 +40,11 @@
        public sealed class ReaderWriterLock
        {
                private int seq_num = 1;
-               private int state = 0;
-               private int readers = 0;
+               private int state;
+               private int readers;
                private LockQueue writer_queue;
                private Hashtable reader_locks;
                private int writer_lock_owner;
-               private int readyWaitingReaders = 0;
 
                public ReaderWriterLock()
                {
@@ -92,10 +91,11 @@
                                        readers++;
                                        try {
                                                if (state < 0 || 
!writer_queue.IsEmpty) {
-                                                       if (!Monitor.Wait 
(this, millisecondsTimeout))
-                                                               throw new 
ApplicationException ("Timeout expired");
+                                                       do {
+                                                               if 
(!Monitor.Wait (this, millisecondsTimeout))
+                                                                       throw 
new ApplicationException ("Timeout expired");
+                                                       } while (state < 0);
                                                }
-                                               readyWaitingReaders--;
                                        }
                                        finally {
                                                readers--;
@@ -132,9 +132,11 @@
                                
                                // wait while there are reader locks or another 
writer lock, or
                                // other threads waiting for the writer lock
-                               if (state != 0 || !writer_queue.IsEmpty || 
readers > 0) {
-                                       if (!writer_queue.Wait 
(millisecondsTimeout))
-                                               throw new ApplicationException 
("Timeout expited");
+                               if (state != 0 || !writer_queue.IsEmpty) {
+                                       do {
+                                               if (!writer_queue.Wait 
(millisecondsTimeout))
+                                                       throw new 
ApplicationException ("Timeout expired");
+                                       } while (state != 0);
                                }
 
                                state = -initialLockCount;
@@ -163,7 +165,6 @@
                                state = lockCookie.ReaderLocks;
                                reader_locks [Thread.CurrentThreadId] = state;
                                if (readers > 0) {
-                                       readyWaitingReaders = readers;
                                        Monitor.PulseAll (this);
                                }
                                
@@ -200,6 +201,7 @@
                                                return;
                                        }
                                }
+
                                throw new ApplicationException ("The thread 
does not have any reader or writer locks.");
                        }
                }
@@ -214,7 +216,7 @@
                                reader_locks [Thread.CurrentThreadId] = 
new_count;
                                
                        state -= releaseCount;
-                       if (state == 0 && (readers == 0 || readyWaitingReaders 
<= 0) && !writer_queue.IsEmpty)
+                       if (state == 0 && !writer_queue.IsEmpty)
                                writer_queue.Pulse ();
                }
 
@@ -233,7 +235,6 @@
                        state += releaseCount;
                        if (state == 0) {
                                if (readers > 0) {
-                                       readyWaitingReaders = readers;
                                        Monitor.PulseAll (this);
                                }
                                else if (!writer_queue.IsEmpty)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to