Skip to content

Commit

Permalink
disabled TRWLock.ReadOnlyLock asm on Delphi
Browse files Browse the repository at this point in the history
- some incomprehensible error was reported
  • Loading branch information
Arnaud Bouchez committed Feb 2, 2023
1 parent 0f944e5 commit c532605
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
34 changes: 5 additions & 29 deletions src/core/mormot.core.os.pas
Expand Up @@ -3492,9 +3492,9 @@ TRWLock = record
Flags: PtrUInt; // bit 0 = WriteLock, 1 = ReadWriteLock, >1 = ReadOnlyLock
LastReadWriteLockThread, LastWriteLockThread: TThreadID; // to be reentrant
LastReadWriteLockCount, LastWriteLockCount: cardinal;
{$ifndef ASMINTEL}
{$ifndef FPC_ASMX64}
procedure ReadOnlyLockSpin;
{$endif ASMINTEL}
{$endif FPC_ASMX64}
public
/// initialize the R/W lock
// - not needed if TRWLock is part of a class - i.e. if was filled with 0
Expand All @@ -3514,7 +3514,7 @@ TRWLock = record
// ! rwlock.ReadOnlyUnLock;
// ! end;
procedure ReadOnlyLock;
{$ifndef ASMINTEL} inline; {$endif}
{$ifdef HASINLINE} {$ifndef FPC_ASMX64} inline; {$endif} {$endif}
/// release a previous ReadOnlyLock call
procedure ReadOnlyUnLock;
{$ifdef HASINLINE} inline; {$endif}
Expand Down Expand Up @@ -7710,7 +7710,7 @@ procedure TRWLock.AssertDone;
end;

// dedicated asm for this most simple (and used) method
{$ifdef ASMX64}
{$ifdef FPC_ASMX64} // some Delphi version was reported to fail with no clue why

procedure TRWLock.ReadOnlyLock;
asm // since we may call SwitchToThread we need to have a stackframe
Expand All @@ -7735,29 +7735,6 @@ procedure TRWLock.ReadOnlyLock;

{$else}

{$ifdef ASMX86}

procedure TRWLock.ReadOnlyLock;
{$ifdef FPCWINDOWS} nostackframe; assembler; {$endif}
asm // since we may call SwitchToThread we need to have a stackframe
push ebx
mov ebx, eax
@retry: mov ecx, SPIN_COUNT
@spin: mov eax, dword ptr [ebx + TRWLock.Flags]
and eax, not 1
lea edx, [eax + 4]
lock cmpxchg dword ptr [ebx + TRWLock.Flags], edx
jz @done
pause
dec ecx
jnz @spin
call SwitchToThread
jmp @retry
@done: pop ebx
end; // restore the stack frame on systems which expects it

{$else}

procedure TRWLock.ReadOnlyLock;
var
f: PtrUInt;
Expand All @@ -7780,8 +7757,7 @@ procedure TRWLock.ReadOnlyLockSpin;
LockedExc(Flags, f + 4, f);
end;

{$endif ASMX86}
{$endif ASMX64}
{$endif FPC_ASMX64}

procedure TRWLock.ReadOnlyUnLock;
begin
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.0.4817'
'2.0.4818'

0 comments on commit c532605

Please sign in to comment.