This commit is contained in:
Pavel 2022-06-07 16:23:43 +03:00
parent c1e230cc5a
commit 23293839ea

View File

@ -71,7 +71,8 @@ implementation
Uses Uses
atomic, atomic,
sys_kernel; sys_kernel,
sys_signal;
Procedure backoff_exp.Wait; Procedure backoff_exp.Wait;
Var Var
@ -177,18 +178,20 @@ end;
function spin_trylock(var t:r_spin_lock):Boolean; function spin_trylock(var t:r_spin_lock):Boolean;
begin begin
Result:=True; Result:=True;
if spin_trylock(t._lock) then _sig_lock;
begin if spin_trylock(t._lock) then
t.count:=0; begin
t.owner:=GetCurrentThreadId; t.count:=0;
end else t.owner:=GetCurrentThreadId;
if (t.owner=GetCurrentThreadId) then end else
begin if (t.owner=GetCurrentThreadId) then
Inc(t.count); begin
end else Inc(t.count);
begin end else
Result:=False; begin
end; Result:=False;
end;
_sig_unlock;
end; end;
procedure spin_lock(var t:r_spin_lock); procedure spin_lock(var t:r_spin_lock);
@ -201,15 +204,16 @@ end;
procedure spin_unlock(var t:r_spin_lock); procedure spin_unlock(var t:r_spin_lock);
begin begin
if (t.count<=1) then _sig_lock;
begin if (t.count=0) then
t.count:=0; begin
t.owner:=DWORD(-1); t.owner:=DWORD(-1);
spin_unlock(t._lock); spin_unlock(t._lock);
end else end else
begin begin
Dec(t.count); Dec(t.count);
end; end;
_sig_unlock;
end; end;
// //