* 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 -
This commit is contained in:
Jonas Maebe 2010-01-10 12:14:21 +00:00
parent 47882716cf
commit 49f01e7b64
4 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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