oro_msvc/oro_arch.h
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Philippe Hamelin Wed Apr 13 13:02:01 2011 -0400 oro_arch.h
3 
4  oro_arch.h - description
5  -------------------
6  begin : Wed Apr 13 2011
7  copyright : (C) 2005 Peter Soetens
8  copyright : (C) 2011 Philippe Hamelin
9  email : philippe.hamelin@gmail.com
10 
11  ***************************************************************************
12  * This library is free software; you can redistribute it and/or *
13  * modify it under the terms of the GNU General Public *
14  * License as published by the Free Software Foundation; *
15  * version 2 of the License. *
16  * *
17  * As a special exception, you may use this file as part of a free *
18  * software library without restriction. Specifically, if other files *
19  * instantiate templates or use macros or inline functions from this *
20  * file, or you compile this file and link it with other files to *
21  * produce an executable, this file does not by itself cause the *
22  * resulting executable to be covered by the GNU General Public *
23  * License. This exception does not however invalidate any other *
24  * reasons why the executable file might be covered by the GNU General *
25  * Public License. *
26  * *
27  * This library is distributed in the hope that it will be useful, *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
30  * General Public License for more details. *
31  * *
32  * You should have received a copy of the GNU General Public *
33  * License along with this library; if not, write to the Free Software *
34  * Foundation, Inc., 59 Temple Place, *
35  * Suite 330, Boston, MA 02111-1307 USA *
36  * *
37  ***************************************************************************/
38 
39 
40 #include "../../rtt-config.h"
41 #ifndef __ARCH_MSVC_ORO_ATOMIC__
42 #define __ARCH_MSVC_ORO_ATOMIC__
43 
44 #include <windows.h>
45 #undef interface
46 #include <intrin.h>
47 
48 typedef volatile long oro_atomic_t;
49 
50 #define ORO_ATOMIC_SETUP oro_atomic_set
51 #define ORO_ATOMIC_CLEANUP(a_int)
52 
53 #define oro_atomic_read(a_int) (*(a_int))
54 
55 #define oro_atomic_set(a_int,n) (*(a_int) = (n))
56 
57 static __forceinline void oro_atomic_add(oro_atomic_t *a_int, int n)
58 {
59  _InterlockedExchangeAdd((long *)a_int, n);
60 }
61 
62 static __forceinline void oro_atomic_sub(oro_atomic_t *a_int, int n)
63 {
64  oro_atomic_add(a_int, -n);
65 }
66 
67 static __forceinline int oro_atomic_sub_and_test(oro_atomic_t *a_int, int n)
68 {
69  return ((_InterlockedExchangeAdd((long *)a_int, -n) - n) == 0);
70 }
71 
72 static __forceinline void oro_atomic_inc(oro_atomic_t *a_int)
73 {
74  _InterlockedIncrement((long *)a_int);
75 }
76 
77 static __forceinline void oro_atomic_dec(oro_atomic_t *a_int)
78 {
79  _InterlockedDecrement((long *)a_int);
80 }
81 
82 static __forceinline int oro_atomic_dec_and_test(oro_atomic_t *a_int)
83 {
84  return (_InterlockedDecrement((long *)a_int) == 0);
85 }
86 
87 static __forceinline int oro_atomic_inc_and_test(oro_atomic_t *a_int)
88 {
89  return (_InterlockedIncrement((long *)a_int) == 0);
90 }
91 
92 static __forceinline int oro_atomic_add_negative(oro_atomic_t *a_int, int n)
93 {
94  return ((_InterlockedExchangeAdd((long *)a_int, n) + n) < 0);
95 }
96 
97 static __forceinline int oro_atomic_add_return(oro_atomic_t *a_int, int n)
98 {
99  return _InterlockedExchangeAdd((long *)a_int, n) + n;
100 }
101 
102 static __forceinline int oro_atomic_sub_return(oro_atomic_t *a_int, int n)
103 {
104  return oro_atomic_add_return(a_int, -n);
105 }
106 
107 static __forceinline int oro_atomic_inc_return(oro_atomic_t *a_int)
108 {
109  return _InterlockedIncrement((long *)a_int);
110 }
111 
112 static __forceinline int oro_atomic_dec_return(oro_atomic_t *a_int)
113 {
114  return _InterlockedDecrement((long *)a_int);
115 }
116 
117 static __forceinline int oro_atomic_clear_mask(oro_atomic_t *a_int, int mask)
118 {
119  return _InterlockedAnd((long *)a_int, ~mask);
120 }
121 
122 static __forceinline int oro_atomic_set_mask(oro_atomic_t *a_int, int mask)
123 {
124  return _InterlockedOr((long *)a_int, mask);
125 }
126 
127 #pragma warning(push)
128 #pragma warning(disable : 4715) // Disable warning on "specified function can potentially not return a value"
129 
130 template<typename T> inline T oro_cmpxchg(volatile void * ptr, T old, T _new)
131 {
132  switch(sizeof(T))
133  {
134  case 2:
135  return (T)(_InterlockedCompareExchange16((short *)ptr, (short)_new, (short)old));
136  case 4:
137  return (T)(_InterlockedCompareExchange((long *)ptr, (long)_new, (long)old));
138  case 8:
139  return (T)(_InterlockedCompareExchange64((__int64 *)ptr, (__int64)_new, (__int64)old));
140  }
141 }
142 
143 #pragma warning(pop)
144 
145 #endif
static __forceinline int oro_atomic_inc_return(oro_atomic_t *a_int)
static __forceinline void oro_atomic_add(oro_atomic_t *a_int, int n)
static __forceinline void oro_atomic_dec(oro_atomic_t *a_int)
static __forceinline int oro_atomic_dec_and_test(oro_atomic_t *a_int)
static __forceinline void oro_atomic_sub(oro_atomic_t *a_int, int n)
static __forceinline int oro_atomic_add_negative(oro_atomic_t *a_int, int n)
volatile long oro_atomic_t
static __forceinline int oro_atomic_inc_and_test(oro_atomic_t *a_int)
static __forceinline int oro_atomic_sub_return(oro_atomic_t *a_int, int n)
static __forceinline int oro_atomic_set_mask(oro_atomic_t *a_int, int mask)
static __forceinline int oro_atomic_sub_and_test(oro_atomic_t *a_int, int n)
static __forceinline int oro_atomic_dec_return(oro_atomic_t *a_int)
static __forceinline int oro_atomic_clear_mask(oro_atomic_t *a_int, int mask)
static __forceinline int oro_atomic_add_return(oro_atomic_t *a_int, int n)
T oro_cmpxchg(volatile void *ptr, T old, T _new)
static __forceinline void oro_atomic_inc(oro_atomic_t *a_int)


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34