mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-18 05:00:07 +02:00
* 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:
parent
47882716cf
commit
49f01e7b64
@ -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;
|
||||
|
||||
|
@ -36,7 +36,7 @@ type
|
||||
TMultiReadExclusiveWriteSynchronizer = class(TInterfacedObject,IReadWriteSync)
|
||||
private
|
||||
freaderqueue: peventstate;
|
||||
fwritelock,
|
||||
fwritelock : TRtlCriticalSection;
|
||||
fwaitingwriterlock: prtlevent;
|
||||
freadercount: cardinal;
|
||||
fwritelocked: longint;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user