-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
InterlockedOps.pas
10544 lines (7405 loc) · 296 KB
/
InterlockedOps.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
InterlockedOps
This library provides a set of functions, each performing an atomic
operation on a variable - that is, each function is guaranteed to complete
its operation in a thread-safe manner.
It has been created as a replacement and extension of WinAPI-provided
interlocked functions, but can be used on any system.
Note that some functions, although equally named, behave differently than
those from WinAPI - see description of each function for details.
WARNING - almost entire library is implemented in assembly, and because
of that, it can only be compiled for x86 (IA-32) and x86-64
(AMD64) processors.
Functions for 8bit, 16bit, 32bit and 64bit integer variables, both signed
and unsigned, are implemented. There are also variants for pointers and
some functions are implemented for boolean variables.
64bit variants are available in 32bit environment only when symbol
EnableVal64onSys32 is defined (see symbols define section for more
information). In 64bit environment, they are always available.
There are also some functions accepting 128bit variables, but these are
only available in 64bit environment and only when symbol EnableVal128 is
defined.
Unless noted otherwise in function description, there are no requirements
for memory alignment of any of the passed parameters (as-per Intel
Developers Manual, which explicitly states "The integrity of the LOCK
prefix is not affected by the alignment of the memory field. Memory locking
is observed for arbitrarily misaligned fields.").
Note that upon return of any of the provided function, the accessed variable
can already have a different value than expected if it was accessed by other
thread(s). Whatever the function returns is a state that was valid during
the internal lock.
Version 1.5 (2024-08-17)
Last change 2024-08-17
©2021-2024 František Milt
Contacts:
František Milt: frantisek.milt@gmail.com
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.InterlockedOps
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
* SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
Library AuxExceptions is required only when rebasing local exception classes
(see symbol InterlockedOps_UseAuxExceptions for details).
SimpleCPUID is required only when symbol AssertInstructions is defined.
Libraries AuxExceptions and SimpleCPUID might also be required as an indirect
dependencies.
Indirect dependencies:
StrRect - github.com/TheLazyTomcat/Lib.StrRect
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit InterlockedOps;
{
InterlockedOps_PurePascal
If you want to compile this unit without ASM, don't want to or cannot define
PurePascal for the entire project and at the same time you don't want to or
cannot make changes to this unit, define this symbol for the entire project
and this unit will be compiled in PurePascal mode.
NOTE - this unit cannot be compiled without asm, but there it is for the
sake of completeness.
}
{$IFDEF InterlockedOps_PurePascal}
{$DEFINE PurePascal}
{$ENDIF}
{
InterlockedOps_UseAuxExceptions
If you want library-specific exceptions to be based on more advanced classes
provided by AuxExceptions library instead of basic Exception class, and don't
want to or cannot change code in this unit, you can define global symbol
InterlockedOps_UseAuxExceptions to achieve this.
}
{$IF Defined(InterlockedOps_UseAuxExceptions)}
{$DEFINE UseAuxExceptions}
{$IFEND}
//------------------------------------------------------------------------------
{$IF defined(CPUX86_64) or defined(CPUX64)}
{$DEFINE x64}
{$ELSEIF defined(CPU386)}
{$DEFINE x86}
{$ELSE}
{$MESSAGE FATAL 'Unsupported CPU architecture.'}
{$IFEND}
{$IF Defined(WINDOWS) or Defined(MSWINDOWS)}
{$DEFINE Windows}
{$IFEND}
{$IFOPT Q+}
{$DEFINE OverflowChecks}
{$ENDIF}
{$IFDEF FPC}
{$MODE ObjFPC}
{$INLINE ON}
{$DEFINE CanInline}
{$ASMMODE Intel}
{$DEFINE FPC_DisableWarns}
{$MACRO ON}
{$ELSE}
{$IF CompilerVersion >= 17} // Delphi 2005+
{$DEFINE CanInline}
{$ELSE}
{$UNDEF CanInline}
{$IFEND}
{$ENDIF}
{$H+}
//------------------------------------------------------------------------------
{
EnableVal64onSys32
When defined, 64bit variants of all functions (that is, variants working with
64bit parameters) are provided in 32bit environment. When not defined, these
variants are available only in 64bit environment.
Since implementing proper locking of 64bit primitive in 32bit mode is
depending on instructions CMPXCHG8B and CMOV, which are not present on very
old processors, this symbol is here to disable such code if there is a need
to run this library on legacy hardware.
Note that whether the unit was compiled with support for 64bit variables
can be discerned from public constant ILO_64BIT_VARS - when true, the 64bit
variants are provided, otherwise they are not.
WARNING - when binary compiled with both this symbol and symbol
AssertInstructions defined is run on hardware that does not
support needed instructions, then an exception of type
EILOUnsupportedInstruction is raised during unit initialization.
By default enabled.
To disable/undefine this symbol in a project without changing this library,
define project-wide symbol InterlockedOps_EnableVal64onSys32_Off.
}
{$DEFINE EnableVal64onSys32}
{$IFDEF InterlockedOps_EnableVal64onSys32_Off}
{$UNDEF EnableVal64onSys32}
{$ENDIF}
{
EnableVal128
When enabled, 128bit variants of function InterlockedCompareExchange are
provided, otherwise they are not.
Whether the unit was compiled with support for 128bit variables can be
discerned from public constant ILO_128BIT_VARS - when true, the 128bit
variants are provided, otherwise they are not.
WARNING - these functions are available only in 64bit mode, never in 32bit
mode. Therefore, this symbol has no effect in 32bit mode.
WARNING - when binary compiled with both this symbol and symbol
AssertInstructions defined is run on hardware that does not
support needed instructions, then an exception of type
EILOUnsupportedInstruction is raised during unit initialization.
By default enabled.
To disable/undefine this symbol in a project without changing this library,
define project-wide symbol InterlockedOps_EnableVal128_Off.
}
{$DEFINE EnableVal128}
{$IFDEF InterlockedOps_EnableVal128_Off}
{$UNDEF EnableVal128}
{$ENDIF}
{
AssertInstructions
When defined, a check whether the current CPU supports needed instructions
is performed during unit initialization. If they are not supported, then an
EILOUnsupportedInstruction exception is raised.
When not defined, no check is made - but be warned that this may lead to
errors when calling functions that are using those instructions.
This symbol is here for situations where CPU can run the instruction but
CPUID for some reason reports it as unsupported (behavior observed on
virtualized guest systems).
By default enabled.
To disable/undefine this symbol in a project without changing this library,
define project-wide symbol InterlockedOps_AssertInstructions_Off.
}
{$DEFINE AssertInstructions}
{$IFDEF InterlockedOps_AssertInstructions_Off}
{$UNDEF AssertInstructions}
{$ENDIF}
//------------------------------------------------------------------------------
// do not touch following define checks
{$IF Defined(EnableVal64onSys32) or Defined(x64)}
{$DEFINE IncludeVal64}
{$IFEND}
{$IF Defined(EnableVal128) and Defined(x64)}
{$DEFINE IncludeVal128}
{$IFEND}
{$IF Defined(PurePascal) and not Defined(CompTest)}
{$MESSAGE WARN 'This unit cannot be compiled in PurePascal mode.'}
{$IFEND}
interface
uses
SysUtils,
AuxTypes{$IFDEF UseAuxExceptions}, AuxExceptions{$ENDIF};
{===============================================================================
Informative public constants
===============================================================================}
const
ILO_64BIT_VARS = {$IFDEF IncludeVal64}True{$ELSE}False{$ENDIF};
ILO_128BIT_VARS = {$IFDEF IncludeVal128}True{$ELSE}False{$ENDIF};
{===============================================================================
Some helper types
===============================================================================}
{
Type UInt128 is here only to provide 128 bits long type that could be used in
calls to 128bit variants of provided functions.
}
type
UInt128 = packed record
case Integer of
0:(Low: UInt64;
High: UInt64);
1:(QWords: array[0..1] of UInt64);
2:(DWords: array[0..3] of UInt32);
3:(Words: array[0..7] of UInt16);
4:(Bytes: array[0..15] of UInt8);
end;
PUInt128 = ^UInt128;
PPUInt128 = ^PUInt128;
{===============================================================================
Library-specific exception classes
===============================================================================}
type
EILOException = class({$IFDEF UseAuxExceptions}EAEGeneralException{$ELSE}Exception{$ENDIF});
EILOUnsupportedInstruction = class(EILOException);
EILOUnsupportedImplementation = class(EILOException);
{===============================================================================
--------------------------------------------------------------------------------
Interlocked increment
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedIncrement
Increments variable (pointed to by) I by one and returns the resulting
(incremented) value.
-------------------------------------------------------------------------------}
Function InterlockedIncrement8(I: Pointer): UInt8; register; assembler;
Function InterlockedIncrement16(I: Pointer): UInt16; register; assembler;
Function InterlockedIncrement32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedIncrement64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedIncrementPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedIncrement(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedIncrement(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedIncrement(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedIncrement(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked decrement
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedDecrement
Decrements variable (pointed to by) I by one and returns the resulting
(decremented) value.
-------------------------------------------------------------------------------}
Function InterlockedDecrement8(I: Pointer): UInt8; register; assembler;
Function InterlockedDecrement16(I: Pointer): UInt16; register; assembler;
Function InterlockedDecrement32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedDecrement64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedDecrementPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedDecrement(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedDecrement(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrement(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedDecrement(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked decrement if positive
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedDecrementIfPositive
Decrements variable (pointed to by) I by one, but only when it is
greater/above 0, and returns the original value - note that this differs
from normal decrement, where the new value is returned. This is to allow
checks whether the decrement actually took place or not.
Function behaves differently for signed and unsigned integers. For example,
signed value of -1 will NOT be decremented, whereas the same value as
unsigned (255 for 8bit integer) will be decremented.
Variants accepting only pointer are treating the pointed variable as
unsigned integer, pointers are also treated as unsigned integers.
WARNING - Unlike InterlockedDecrement, this function returns the original
value of I, not the new value!
-------------------------------------------------------------------------------}
Function InterlockedDecrementIfPositive8(I: Pointer): UInt8;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrementIfPositive16(I: Pointer): UInt16;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedDecrementIfPositive32(I: Pointer): UInt32;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedDecrementIfPositive64(I: Pointer): UInt64;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedDecrementIfPositivePtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedDecrementIfPositive(var I: UInt8): UInt8; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: Int8): Int8; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: UInt16): UInt16; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: Int16): Int16; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: UInt32): UInt32; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: Int32): Int32; overload; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedDecrementIfPositive(var I: UInt64): UInt64; overload; register; assembler;
Function InterlockedDecrementIfPositive(var I: Int64): Int64; overload; register; assembler;
{$ENDIF}
Function InterlockedDecrementIfPositive(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked addition
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedAdd
Sets variable (pointed to by) A to a sum A and B and returns the resulting
value.
-------------------------------------------------------------------------------}
Function InterlockedAdd8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedAdd16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedAdd32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedAdd64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedAddPtr(A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAddPtr(A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedAdd(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedAdd(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedAdd(var A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAdd(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked subtraction
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedSub
Subtracts B from variable (pointed to by) A and returns the resulting
value.
-------------------------------------------------------------------------------}
Function InterlockedSub8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedSub16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedSub32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedSub64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedSubPtr(A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSubPtr(A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedSub(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: UInt32; B: UInt32): UInt32; overload{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedSub(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedSub(var A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedSub(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked negation
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedNeg
Negates (changes sign) of variable (pointed to by) I and returns the
resulting value.
Note that unsigned integers are treated as signed integers with the same
bit pattern. For example UInt8(255) is seen as Int8(-1), and its negative
is therefore UInt8(1).
-------------------------------------------------------------------------------}
Function InterlockedNeg8(I: Pointer): UInt8; register; assembler;
Function InterlockedNeg16(I: Pointer): UInt16; register; assembler;
Function InterlockedNeg32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedNeg64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedNegPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedNeg(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedNeg(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNeg(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedNeg(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked logical not
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedNot
Performs logical NOT (flips all bits) of variable (pointed to by) I and
returns the resulting value.
-------------------------------------------------------------------------------}
Function InterlockedNot8(I: Pointer): UInt8; register; assembler;
Function InterlockedNot16(I: Pointer): UInt16; register; assembler;
Function InterlockedNot32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedNot64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedNotPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNotBool(I: Pointer): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedNot(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedNot(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedNot(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedNot(var I: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked logical and
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedAnd
Performs logical AND of variable (pointed to by) A with B, stores the
result back in A and returns it.
WARNING - this function differs from InterlockedAnd provided by WinAPI.
There, it returns original value of the variable, here it returns
the resulting value.
WinAPI behavior is provided by function InterlockedExchangeAnd.
-------------------------------------------------------------------------------}
Function InterlockedAnd8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedAnd16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedAnd32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedAnd64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedAndPtr(A: Pointer; B: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAndBool(A: Pointer; B: Boolean): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedAnd(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedAnd(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedAnd(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedAnd(var A: Boolean; B: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked logical or
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedOr
Performs logical OR of variable (pointed to by) A with B, stores the
result back in A and returns it.
WARNING - this function differs from InterlockedOr provided by WinAPI.
There, it returns original value of the variable, here it returns
the resulting value.
WinAPI behavior is provided by function InterlockedExchangeOr.
-------------------------------------------------------------------------------}
Function InterlockedOr8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedOr16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedOr32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedOr64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedOrPtr(A: Pointer; B: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOrBool(A: Pointer; B: Boolean): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedOr(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedOr(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedOr(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedOr(var A: Boolean; B: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked logical xor
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedXor
Performs logical XOR of variable (pointed to by) A with B, stores the
result back in A and returns it.
WARNING - this function differs from InterlockedXor provided by WinAPI.
There, it returns original value of the variable, here it returns
the resulting value.
WinAPI behavior is provided by function InterlockedExchangeXor.
-------------------------------------------------------------------------------}
Function InterlockedXor8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedXor16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedXor32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedXor64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedXorPtr(A: Pointer; B: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXorBool(A: Pointer; B: Boolean): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedXor(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedXor(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedXor(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedXor(var A: Boolean; B: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchange
Sets variable (pointed to by) A to a value of B and returns original value
of A.
-------------------------------------------------------------------------------}
Function InterlockedExchange8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedExchange16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedExchange32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchange64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangePtr(A: Pointer; B: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeBool(A: Pointer; B: Boolean): Boolean;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedExchange(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchange(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchange(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchange(var A: Boolean; B: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and add
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchangeAdd
Sets variable (pointed to by) A to a sum of A and B, stores the result back
in A and returns original value of A.
-------------------------------------------------------------------------------}
Function InterlockedExchangeAdd8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedExchangeAdd16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedExchangeAdd32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchangeAdd64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangeAddPtr(A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAddPtr(A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedExchangeAdd(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchangeAdd(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchangeAdd(var A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAdd(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and subtract
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchangeSub
Subtracts B from variable (pointed to by) A, stores the result back in A
and returns original value of A.
-------------------------------------------------------------------------------}
Function InterlockedExchangeSub8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedExchangeSub16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedExchangeSub32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchangeSub64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangeSubPtr(A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSubPtr(A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedExchangeSub(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchangeSub(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchangeSub(var A: Pointer; B: PtrInt): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeSub(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and negation
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchangeNeg
Negates (changes sign) of variable (pointed to by) I and returns its
original value.
Note that unsigned integers are treated as signed integers with the same
bit pattern. For example UInt8(255) is seen as Int8(-1), and its negative
is therefore UInt8(1).
-------------------------------------------------------------------------------}
Function InterlockedExchangeNeg8(I: Pointer): UInt8; register; assembler;
Function InterlockedExchangeNeg16(I: Pointer): UInt16; register; assembler;
Function InterlockedExchangeNeg32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchangeNeg64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangeNegPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function InterlockedExchangeNeg(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchangeNeg(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNeg(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchangeNeg(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and logical not
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchangeNot
Performs logical NOT (flips all bits) of variable (pointed to by) I and
returns its original value.
-------------------------------------------------------------------------------}
Function InterlockedExchangeNot8(I: Pointer): UInt8; register; assembler;
Function InterlockedExchangeNot16(I: Pointer): UInt16; register; assembler;
Function InterlockedExchangeNot32(I: Pointer): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchangeNot64(I: Pointer): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangeNotPtr(I: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNotBool(I: Pointer): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedExchangeNot(var I: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchangeNot(var I: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchangeNot(var I: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeNot(var I: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and logical and
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
InterlockedExchangeAnd
Performs logical AND of variable (pointed to by) A with B, stores the
result back in A and returns original value of A.
-------------------------------------------------------------------------------}
Function InterlockedExchangeAnd8(A: Pointer; B: UInt8): UInt8; register; assembler;
Function InterlockedExchangeAnd16(A: Pointer; B: UInt16): UInt16; register; assembler;
Function InterlockedExchangeAnd32(A: Pointer; B: UInt32): UInt32; register; assembler;
{$IFDEF IncludeVal64}
Function InterlockedExchangeAnd64(A: Pointer; B: UInt64): UInt64; register; assembler;
{$ENDIF}
Function InterlockedExchangeAndPtr(A: Pointer; B: Pointer): Pointer;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAndBool(A: Pointer; B: Boolean): Boolean; register; assembler;
//------------------------------------------------------------------------------
Function InterlockedExchangeAnd(var A: UInt8; B: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: Int8; B: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: UInt16; B: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: Int16; B: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: UInt32; B: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: Int32; B: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFDEF IncludeVal64}
Function InterlockedExchangeAnd(var A: UInt64; B: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: Int64; B: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$ENDIF}
Function InterlockedExchangeAnd(var A: Pointer; B: Pointer): Pointer; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function InterlockedExchangeAnd(var A: Boolean; B: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Interlocked exchange and logical or
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------