oro_gcc/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 #ifndef __GCC_ORO_ARCH__
41 #define __GCC_ORO_ARCH__
42 
43 #include "../../rtt-config.h"
44 
49 typedef struct {
50  int volatile cnt;
51 } oro_atomic_t;
52 
53 #define ORO_ATOMIC_SETUP oro_atomic_set
54 #define ORO_ATOMIC_CLEANUP(a_int)
55 
56 #define oro_atomic_read(a_int) ((a_int)->cnt)
57 
58 #define oro_atomic_set(a_int,n) (((a_int)->cnt) = (n))
59 
63 static __inline__ void oro_atomic_add(oro_atomic_t *a_int, int n)
64 {
65  (void)__sync_add_and_fetch(&a_int->cnt, n);
66 }
67 
72 {
73  return __sync_add_and_fetch(&a_int->cnt, n);
74 }
75 
79 static __inline__ void oro_atomic_sub(oro_atomic_t *a_int, int n)
80 {
81  (void)__sync_sub_and_fetch(&a_int->cnt, n);
82 }
83 
88 {
89  return __sync_sub_and_fetch(&a_int->cnt, n);
90 }
91 
96 {
97  return !(__sync_sub_and_fetch(&a_int->cnt, n));
98 }
99 
104 {
105  (void)__sync_fetch_and_add(&a_int->cnt, 1);
106 }
107 
112 {
113  return __sync_fetch_and_add(&a_int->cnt, 1);
114 }
115 
120 {
121  (void)__sync_fetch_and_sub(&a_int->cnt, 1);
122 }
123 
128 {
129  return __sync_fetch_and_sub(&a_int->cnt, 1);
130 }
131 
136 {
137  return !(__sync_sub_and_fetch(&a_int->cnt, 1));
138 }
139 
144 {
145  return !(__sync_add_and_fetch(&a_int->cnt, 1));
146 }
147 
151 #define oro_cmpxchg(ptr,o,n)\
152  ((__typeof__(*(ptr)))__sync_val_compare_and_swap((ptr),(o),(n)))
153 
154 
155 #endif // __GCC_ORO_ARCH__
static __inline__ int oro_atomic_inc_return(oro_atomic_t *a_int)
static __inline__ void oro_atomic_dec(oro_atomic_t *a_int)
static __inline__ int oro_atomic_dec_and_test(oro_atomic_t *a_int)
static __inline__ int oro_atomic_sub_return(oro_atomic_t *a_int, int n)
static __inline__ int oro_atomic_inc_and_test(oro_atomic_t *a_int)
static __inline__ void oro_atomic_add(oro_atomic_t *a_int, int n)
#define __inline__
static __inline__ void oro_atomic_inc(oro_atomic_t *a_int)
int volatile cnt
static __inline__ void oro_atomic_sub(oro_atomic_t *a_int, int n)
static __inline__ int oro_atomic_add_return(oro_atomic_t *a_int, int n)
static __inline__ int oro_atomic_dec_return(oro_atomic_t *a_int)
struct oro_atomic_t_interface oro_atomic_t
static __inline__ int oro_atomic_sub_and_test(oro_atomic_t *a_int, int n)


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