Browse Source

* only wake up readers if all recursive write locks have been freed

git-svn-id: trunk@14831 -
Jonas Maebe 15 years ago
parent
commit
89e4e0fd25
1 changed files with 11 additions and 8 deletions
  1. 11 8
      rtl/objpas/sysutils/sysuthrd.inc

+ 11 - 8
rtl/objpas/sysutils/sysuthrd.inc

@@ -107,14 +107,17 @@ begin
     afterwards will certainly see these results }
     afterwards will certainly see these results }
   WriteBarrier;
   WriteBarrier;
 
 
-  { signal potential readers that the coast is clear }
-  System.InterlockedDecrement(fwritelocked);
-  { wake up waiting readers (if any); do not check first whether freadercount
-    is <> 0, because the InterlockedDecrement in the while loop of BeginRead
-    can have already occurred, so a single reader may be about to wait on
-    freaderqueue even though freadercount=0. Setting an event multiple times
-    is no problem. }
-  BasicEventSetEvent(freaderqueue);
+  { signal potential readers that the coast is clear if all recursive
+    write locks have been freed }
+  if System.InterlockedDecrement(fwritelocked)=0 then
+    begin
+      { wake up waiting readers (if any); do not check first whether freadercount
+        is <> 0, because the InterlockedDecrement in the while loop of BeginRead
+        can have already occurred, so a single reader may be about to wait on
+        freaderqueue even though freadercount=0. Setting an event multiple times
+        is no problem. }
+      BasicEventSetEvent(freaderqueue);
+    end;
   { free the writer lock so another writer can become active }
   { free the writer lock so another writer can become active }
   System.LeaveCriticalSection(fwritelock);
   System.LeaveCriticalSection(fwritelock);
 end;
 end;