From 89aadb22c2034ab2d228054b0608093fe7bfea5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Balogh?= Date: Sun, 24 May 2015 21:31:13 +0000 Subject: [PATCH] Amiga/m68k: software atomic operations implementation for multithreading git-svn-id: trunk@30901 - --- .gitattributes | 1 + rtl/amiga/m68k/m68kamiga.inc | 66 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 rtl/amiga/m68k/m68kamiga.inc diff --git a/.gitattributes b/.gitattributes index a43fda6e48..556cef3af1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8046,6 +8046,7 @@ rtl/amiga/doslibd.inc svneol=native#text/plain rtl/amiga/m68k/doslibf.inc svneol=native#text/plain rtl/amiga/m68k/execd.inc svneol=native#text/plain rtl/amiga/m68k/execf.inc svneol=native#text/plain +rtl/amiga/m68k/m68kamiga.inc svneol=native#text/plain rtl/amiga/m68k/prt0.as svneol=native#text/plain rtl/amiga/m68k/utild1.inc svneol=native#text/plain rtl/amiga/m68k/utild2.inc svneol=native#text/plain diff --git a/rtl/amiga/m68k/m68kamiga.inc b/rtl/amiga/m68k/m68kamiga.inc new file mode 100644 index 0000000000..2cc85f2870 --- /dev/null +++ b/rtl/amiga/m68k/m68kamiga.inc @@ -0,0 +1,66 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2015 by Karoly Balogh, + member of the Free Pascal development team. + + m68k/Amiga atomic operations implementation + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{ The Amiga hardware doesn't support the m68k CPU's atomic operations + like TAS, CAS, CAS2 and so on. Therefore we must "emulate" them from + software. The easiest way is the Forbid()/Permit() OS call pair around + the ops themselves. It of course won't be hardware-atomic, but should + be safe for multithreading. (KB) } + +function InterLockedDecrement (var Target: longint) : longint; + begin + Forbid(); + Dec(Target); + Result := Target; + Permit(); + end; + + +function InterLockedIncrement (var Target: longint) : longint; + begin + Forbid() + Inc(Target); + Result := Target; + Permit(); + end; + + +function InterLockedExchange (var Target: longint;Source : longint) : longint; + begin + Forbid(); + Result := Target; + Target := Source; + Permit(); + end; + + +function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; + begin + Forbid(); + Result := Target; + Target := Target + Source; + Permit(); + end; + + +function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; + begin + Forbid(); + Result := Target; + if Target = Comperand then + Target := NewValue; + Permit(); + end;