Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_atomic-mutex.h
Go to the documentation of this file.
1
33#ifndef _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
34#define _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
35
36
37#ifndef _RWSTD_RW_MUTEX_H_INCLUDED
38# include <rw/_mutex.h>
39#endif // _RWSTD_RW_MUTEX_H_INCLUDED
40
41
43
44// helper functions for atomic value [in|de]crement and exchange
45// the functions are atomic with respect to each other as long as
46// they are passed the same mutex by the callers
47template <class _TypeT>
48inline
49_TypeT __rw_atomic_preincrement (_TypeT &__t, __rw_mutex_base &__mutex)
50{
51 _RWSTD_MT_GUARD (__mutex);
52
53 return ++__t;
54}
55
56
57template <class _TypeT>
58inline
59_TypeT __rw_atomic_predecrement (_TypeT &__t, __rw_mutex_base &__mutex)
60{
61 _RWSTD_MT_GUARD (__mutex);
62
63 return --__t;
64}
65
66
67template <class _TypeT, class _TypeU>
68inline
69_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u,
70 __rw_mutex_base &__mutex)
71{
72 _RWSTD_MT_GUARD (__mutex);
73
74 _TypeT __tmp = __t;
75
76#ifndef _WIN64
77 __t = __u;
78#else
79 // silence MSVC conversion warnings (cast breaks SunPro 5.3 and prior)
80 __t = _RWSTD_STATIC_CAST (_TypeT, __u);
81#endif
82
83 return __tmp;
84}
85
86
87// for use on class statics or on namespace-scope variables
88// the unused argument is only here so that all functions
89// can be called from the same set of macros
90
91template <class _TypeT>
92inline
93_TypeT __rw_atomic_preincrement (_TypeT &__t, bool)
94{
95 return __rw_atomic_preincrement (__t,
96 __rw_get_static_mutex ((_TypeT*)0));
97}
98
99
100template <class _TypeT>
101inline
102_TypeT __rw_atomic_predecrement (_TypeT &__t, bool)
103{
104 return __rw_atomic_predecrement (__t,
105 __rw_get_static_mutex ((_TypeT*)0));
106}
107
108
109template <class _TypeT, class _TypeU>
110inline
111_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
112{
113 return __rw_atomic_exchange (__t, __u,
114 __rw_get_static_mutex ((_TypeT*)0));
115}
116
117} // namespace __rw
118
119#endif // _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_MT_GUARD(ignore)
Definition _defs.h:695