Atomic.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Tue Dec 21 22:43:04 CET 2004 Atomic.hpp
3 
4  Atomic.hpp - description
5  -------------------
6  begin : Tue December 21 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef OS_COMMON_ORO_ATOMIC_HPP
40 #define OS_COMMON_ORO_ATOMIC_HPP
41 
42 #include "oro_arch.h"
43 
44 namespace RTT
45 { namespace os {
49  class RTT_API AtomicInt
50  {
52  public:
53  AtomicInt( int value = 0 )
54  {
55  ORO_ATOMIC_SETUP( &_val, value);
56  }
57 
58  AtomicInt(const AtomicInt& orig)
59  {
60  ORO_ATOMIC_SETUP( &_val, oro_atomic_read( &(orig._val) ) );
61  }
62 
64  {
65  ORO_ATOMIC_CLEANUP( &_val );
66  }
67 
68  const AtomicInt& operator=(const AtomicInt& orig)
69  {
70  oro_atomic_set( &_val, oro_atomic_read( &(orig._val)));
71  return *this;
72  }
73 
77  int read() const { return oro_atomic_read( &_val); }
78 
82  void set(int i) { oro_atomic_set( &_val, i ); }
83 
84  void add(int i) { oro_atomic_add( &_val, i ); }
85 
86  void sub(int i) { oro_atomic_sub( &_val, i ); }
87 
93  bool sub_and_test(int i) { return oro_atomic_sub_and_test( &_val, i) != 0; }
94 
95  void inc() { oro_atomic_inc( &_val ); }
96 
97  void dec() { oro_atomic_dec( &_val ); }
98 
104  bool dec_and_test() { return oro_atomic_dec_and_test( &_val ) != 0; }
105 
111  bool inc_and_test() { return oro_atomic_inc_and_test( &_val ) != 0; }
112  };
113 
114 }}
115 
116 #endif
AtomicInt(const AtomicInt &orig)
Definition: Atomic.hpp:58
bool sub_and_test(int i)
Definition: Atomic.hpp:93
int oro_atomic_inc_and_test(oro_atomic_t *a)
int oro_atomic_read(oro_atomic_t *a)
bool inc_and_test()
Definition: Atomic.hpp:111
oro_atomic_t _val
Definition: Atomic.hpp:51
bool dec_and_test()
Definition: Atomic.hpp:104
void oro_atomic_inc(oro_atomic_t *a)
void ORO_ATOMIC_SETUP(oro_atomic_t *a, int n)
AtomicInt(int value=0)
Definition: Atomic.hpp:53
const AtomicInt & operator=(const AtomicInt &orig)
Definition: Atomic.hpp:68
void ORO_ATOMIC_CLEANUP(oro_atomic_t *a)
void oro_atomic_sub(int n, oro_atomic_t *a, int n)
int oro_atomic_dec_and_test(oro_atomic_t *a)
int oro_atomic_sub_and_test(oro_atomic_t *a, int n)
void sub(int i)
Definition: Atomic.hpp:86
void oro_atomic_set(oro_atomic_t *a, int n)
int read() const
Definition: Atomic.hpp:77
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
void add(int i)
Definition: Atomic.hpp:84
void oro_atomic_dec(oro_atomic_t *a)
void oro_atomic_add(oro_atomic_t *a, int n)


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