]> pd.if.org Git - liblfds/blob - liblfds/liblfds6.1.0/liblfds610/src/lfds610_abstraction/lfds610_abstraction_increment.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds6.1.0 / liblfds610 / src / lfds610_abstraction / lfds610_abstraction_increment.c
1 #include "lfds610_abstraction_internal_body.h"
2
3
4
5
6
7 /****************************************************************************/
8 #if (defined _WIN64 && defined _MSC_VER)
9
10   /* TRD : 64 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler
11
12            _WIN64    indicates 64 bit Windows
13            _MSC_VER  indicates Microsoft C compiler
14   */
15
16   static LFDS610_INLINE lfds610_atom_t lfds610_abstraction_increment( volatile lfds610_atom_t *value )
17   {
18     assert( value != NULL );
19
20     return( (lfds610_atom_t) _InterlockedIncrement64((__int64 *) value) );
21   }
22
23 #endif
24
25
26
27
28
29 /****************************************************************************/
30 #if (!defined _WIN64 && defined _WIN32 && defined _MSC_VER)
31
32   /* TRD : 32 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler
33
34            (!defined _WIN64 && defined _WIN32)  indicates 32 bit Windows
35            _MSC_VER                             indicates Microsoft C compiler
36   */
37
38   static LFDS610_INLINE lfds610_atom_t lfds610_abstraction_increment( volatile lfds610_atom_t *value )
39   {
40     assert( value != NULL );
41
42     return( (lfds610_atom_t) _InterlockedIncrement((long int *) value) );
43   }
44
45 #endif
46
47
48
49
50
51 /****************************************************************************/
52 #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 1 && __GNUC_PATCHLEVEL__ >= 0)
53
54   /* TRD : any OS on any CPU with GCC 4.1.0 or better
55
56            GCC 4.1.0 introduced the __sync_*() atomic intrinsics
57
58            __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__  indicates GCC and which version
59   */
60
61   static LFDS610_INLINE lfds610_atom_t lfds610_abstraction_increment( volatile lfds610_atom_t *value )
62   {
63     assert( value != NULL );
64
65     // TRD : no need for casting here, GCC has a __sync_add_and_fetch() for all native types
66
67     return( (lfds610_atom_t) __sync_add_and_fetch(value, 1) );
68   }
69
70 #endif
71