m68kamiga.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2015 by Karoly Balogh,
  4. member of the Free Pascal development team.
  5. m68k/Amiga atomic operations implementation
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { The Amiga hardware doesn't support the m68k CPU's atomic operations
  13. like TAS, CAS, CAS2 and so on. Therefore we must "emulate" them from
  14. software. The easiest way is the Forbid()/Permit() OS call pair around
  15. the ops themselves. It of course won't be hardware-atomic, but should
  16. be safe for multithreading. (KB) }
  17. function InterLockedDecrement (var Target: longint) : longint;
  18. begin
  19. Forbid;
  20. Dec(Target);
  21. Result := Target;
  22. Permit;
  23. end;
  24. function InterLockedIncrement (var Target: longint) : longint;
  25. begin
  26. Forbid;
  27. Inc(Target);
  28. Result := Target;
  29. Permit;
  30. end;
  31. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  32. begin
  33. Forbid;
  34. Result := Target;
  35. Target := Source;
  36. Permit;
  37. end;
  38. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  39. begin
  40. Forbid;
  41. Result := Target;
  42. Target := Target + Source;
  43. Permit;
  44. end;
  45. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  46. begin
  47. Forbid;
  48. Result := Target;
  49. if Target = Comperand then
  50. Target := NewValue;
  51. Permit;
  52. end;