implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / libatomic_ops / src / atomic_ops / sysdeps / msftc / common32_defs.h
1 /*
2  * Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 /* This file contains AO primitives based on VC++ built-in intrinsic    */
24 /* functions commonly available across 32-bit architectures.            */
25
26 /* This file should be included from arch-specific header files.        */
27 /* Define AO_USE_INTERLOCKED_INTRINSICS if _Interlocked primitives      */
28 /* (used below) are available as intrinsic ones for a target arch       */
29 /* (otherwise "Interlocked" functions family is used instead).          */
30 /* Define AO_ASSUME_WINDOWS98 if CAS is available.                      */
31
32 #include <windows.h>
33         /* Seems like over-kill, but that's what MSDN recommends.       */
34         /* And apparently winbase.h is not always self-contained.       */
35
36 #if _MSC_VER < 1310 || !defined(AO_USE_INTERLOCKED_INTRINSICS)
37
38 # define _InterlockedIncrement       InterlockedIncrement
39 # define _InterlockedDecrement       InterlockedDecrement
40 # define _InterlockedExchange        InterlockedExchange
41 # define _InterlockedExchangeAdd     InterlockedExchangeAdd
42 # define _InterlockedCompareExchange InterlockedCompareExchange
43
44 # define AO_INTERLOCKED_VOLATILE /**/
45
46 #else /* elif _MSC_VER >= 1310 */
47
48 # if _MSC_VER >= 1400
49 #   ifndef _WIN32_WCE
50 #     include <intrin.h>
51 #   endif
52
53 #   pragma intrinsic (_ReadWriteBarrier)
54
55 # else /* elif _MSC_VER < 1400 */
56 #  ifdef __cplusplus
57      extern "C" {
58 #  endif
59    LONG __cdecl _InterlockedIncrement(LONG volatile *);
60    LONG __cdecl _InterlockedDecrement(LONG volatile *);
61    LONG __cdecl _InterlockedExchangeAdd(LONG volatile *, LONG);
62    LONG __cdecl _InterlockedExchange(LONG volatile *, LONG);
63    LONG __cdecl _InterlockedCompareExchange(LONG volatile *,
64                                         LONG /* Exchange */, LONG /* Comp */);
65 #  ifdef __cplusplus
66      }
67 #  endif
68 # endif /* _MSC_VER < 1400 */
69
70 # pragma intrinsic (_InterlockedIncrement)
71 # pragma intrinsic (_InterlockedDecrement)
72 # pragma intrinsic (_InterlockedExchange)
73 # pragma intrinsic (_InterlockedExchangeAdd)
74 # pragma intrinsic (_InterlockedCompareExchange)
75
76 # define AO_INTERLOCKED_VOLATILE volatile
77
78 #endif /* _MSC_VER >= 1310 */
79
80 AO_INLINE AO_t
81 AO_fetch_and_add_full(volatile AO_t *p, AO_t incr)
82 {
83   return _InterlockedExchangeAdd((LONG AO_INTERLOCKED_VOLATILE *)p,
84                                  (LONG)incr);
85 }
86 #define AO_HAVE_fetch_and_add_full
87
88 AO_INLINE AO_t
89 AO_fetch_and_add1_full(volatile AO_t *p)
90 {
91   return _InterlockedIncrement((LONG AO_INTERLOCKED_VOLATILE *)p) - 1;
92 }
93 #define AO_HAVE_fetch_and_add1_full
94
95 AO_INLINE AO_t
96 AO_fetch_and_sub1_full(volatile AO_t *p)
97 {
98   return _InterlockedDecrement((LONG AO_INTERLOCKED_VOLATILE *)p) + 1;
99 }
100 #define AO_HAVE_fetch_and_sub1_full
101
102 #ifdef AO_ASSUME_WINDOWS98
103 /* Returns nonzero if the comparison succeeded. */
104 AO_INLINE int
105 AO_compare_and_swap_full(volatile AO_t *addr, AO_t old, AO_t new_val)
106 {
107 # ifdef AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE
108     return _InterlockedCompareExchange((PVOID AO_INTERLOCKED_VOLATILE *)addr,
109                                        (PVOID)new_val, (PVOID)old)
110            == (PVOID)old;
111 # else
112     return _InterlockedCompareExchange((LONG AO_INTERLOCKED_VOLATILE *)addr,
113                                        (LONG)new_val, (LONG)old)
114            == (LONG)old;
115 # endif
116 }
117 # define AO_HAVE_compare_and_swap_full
118 #endif /* AO_ASSUME_WINDOWS98 */