]> pd.if.org Git - liblfds/blob - liblfds/liblfds6.1.1/liblfds611/src/lfds611_abstraction/lfds611_abstraction_increment.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds6.1.1 / liblfds611 / src / lfds611_abstraction / lfds611_abstraction_increment.c
1 #include "lfds611_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 LFDS611_INLINE lfds611_atom_t lfds611_abstraction_increment( volatile lfds611_atom_t *value )
17   {
18     lfds611_atom_t
19       rv;
20
21     assert( value != NULL );
22
23     LFDS611_BARRIER_COMPILER_FULL;
24
25     rv = (lfds611_atom_t) _InterlockedIncrement64( (__int64 *) value );
26
27     LFDS611_BARRIER_COMPILER_FULL;
28
29     return( rv );
30   }
31
32 #endif
33
34
35
36
37
38 /****************************************************************************/
39 #if (!defined _WIN64 && defined _WIN32 && defined _MSC_VER)
40
41   /* TRD : 32 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler
42
43            (!defined _WIN64 && defined _WIN32)  indicates 32 bit Windows
44            _MSC_VER                             indicates Microsoft C compiler
45   */
46
47   static LFDS611_INLINE lfds611_atom_t lfds611_abstraction_increment( volatile lfds611_atom_t *value )
48   {
49     lfds611_atom_t
50       rv;
51
52     assert( value != NULL );
53
54     LFDS611_BARRIER_COMPILER_FULL;
55
56     rv = (lfds611_atom_t) _InterlockedIncrement( (long int *) value );
57
58     LFDS611_BARRIER_COMPILER_FULL;
59
60     return( rv );
61   }
62
63 #endif
64
65
66
67
68
69 /****************************************************************************/
70 #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 1 && __GNUC_PATCHLEVEL__ >= 0)
71
72   /* TRD : any OS on any CPU with GCC 4.1.0 or better
73
74            GCC 4.1.0 introduced the __sync_*() atomic intrinsics
75
76            __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__  indicates GCC and which version
77   */
78
79   static LFDS611_INLINE lfds611_atom_t lfds611_abstraction_increment( volatile lfds611_atom_t *value )
80   {
81     lfds611_atom_t
82       rv;
83
84     assert( value != NULL );
85
86     // TRD : no need for casting here, GCC has a __sync_add_and_fetch() for all native types
87
88     LFDS611_BARRIER_COMPILER_FULL;
89
90     rv = (lfds611_atom_t) __sync_add_and_fetch( value, 1 );
91
92     LFDS611_BARRIER_COMPILER_FULL;
93
94     return( rv );
95   }
96
97 #endif
98