Browse Source

* replaced writelock of TMultiReadExclusiveWriteSynchronizer with a
critical section, so that it can be entered recursively just like
the one from TSimpleRWSync + test
- reverted r14593, since the reason for using TRWSync instead of
TMultiReadExclusiveWriteSynchronizer was because the former
supported recursive write locks

git-svn-id: trunk@14594 -

Jonas Maebe 15 years ago
parent
commit
49f01e7b64

+ 1 - 1
rtl/objpas/classes/classes.inc

@@ -1688,7 +1688,7 @@ begin
   ClassList := TThreadList.Create;
   ClassAliasList := TStringList.Create;
   { on unix this maps to a simple rw synchornizer }
-  GlobalNameSpace := TSimpleRWSync.Create;
+  GlobalNameSpace := TMultiReadExclusiveWriteSynchronizer.Create;
   RegisterInitComponentHandler(TComponent,@DefaultInitHandler);
 end;
 

+ 1 - 1
rtl/objpas/sysutils/systhrdh.inc

@@ -36,7 +36,7 @@ type
    TMultiReadExclusiveWriteSynchronizer = class(TInterfacedObject,IReadWriteSync)
    private
       freaderqueue: peventstate;
-      fwritelock,
+      fwritelock : TRtlCriticalSection;
       fwaitingwriterlock: prtlevent;
       freadercount: cardinal;
       fwritelocked: longint;

+ 4 - 5
rtl/objpas/sysutils/sysuthrd.inc

@@ -47,8 +47,7 @@ end;
 
 constructor TMultiReadExclusiveWriteSynchronizer.Create;
 begin
-  fwritelock:=RTLEventCreate;
-  RTLeventSetEvent(fwritelock);
+  System.InitCriticalSection(fwritelock);
   fwaitingwriterlock:=RTLEventCreate;
   RTLEventResetEvent(fwaitingwriterlock);
   fwritelocked:=0;
@@ -60,7 +59,7 @@ end;
 destructor TMultiReadExclusiveWriteSynchronizer.Destroy;
 begin
   System.InterlockedExchange(fwritelocked,0);
-  RtlEventDestroy(fwritelock);
+  System.DoneCriticalSection(fwritelock);
   RtlEventDestroy(fwaitingwriterlock);
   BasicEventDestroy(freaderqueue);
 end;
@@ -73,7 +72,7 @@ begin
   if IsMultiThread then
     begin
       { wait for any other writers that may be in progress }
-      RTLEventWaitFor(fwritelock);
+      System.EnterCriticalSection(fwritelock);
       { it is possible that we earlier on missed waiting on the
         fwaitingwriterlock and that it's still set (must be done
         after aquiring the fwritelock, because otherwise one
@@ -120,7 +119,7 @@ begin
         is no problem. }
       BasicEventSetEvent(freaderqueue);
       { free the writer lock so another writer can become active }
-      RTLeventSetEvent(fwritelock);
+      System.LeaveCriticalSection(fwritelock);
     end;
 end;
 

+ 6 - 0
tests/test/units/sysutils/trwsync.pp

@@ -115,6 +115,12 @@ begin
   terrorcheck.create(false);
   randomize;
   lock:=TMultiReadExclusiveWriteSynchronizer.create;
+  { verify that the lock is recursive }
+  lock.beginwrite;
+  lock.beginwrite;
+  lock.endwrite;
+  lock.endwrite;
+
   { first try some writers }
   w1:=twritecounter.create;
   w2:=twritecounter.create;