📄 _mutex.h
字号:
inline
unsigned long __rw_atomic_predecrement (unsigned long &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (int));
return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
false);
}
template <class _TypeT>
inline _TypeT* __rw_atomic_predecrement (_TypeT* &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false));
}
/********************** WIN 32/64 ************************************/
#elif defined (_WIN32) && !defined (_RWSTD_NO_ATOMIC_OPERATIONS)
// Interlocked[In|De]crement functions atomically modify their argument
// and return the new value
// InterlockedExchange atomically sets the value pointed to by the first
// argument to that of the second argument and returns the original value
inline
long __rw_atomic_preincrement (long &__x, bool)
{
return InterlockedIncrement (&__x);
}
inline
unsigned long __rw_atomic_preincrement (unsigned long &__x, bool)
{
return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
inline
int __rw_atomic_preincrement (int &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
inline
unsigned int __rw_atomic_preincrement (unsigned int &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline _TypeT* __rw_atomic_preincrement (_TypeT* &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false));
}
#endif // _WIN64
inline
long __rw_atomic_predecrement (long &__x, bool)
{
return InterlockedDecrement (&__x);
}
inline
unsigned long __rw_atomic_predecrement (unsigned long &__x, bool)
{
return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
inline
int __rw_atomic_predecrement (int &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
inline
unsigned int __rw_atomic_predecrement (unsigned int &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline _TypeT* __rw_atomic_predecrement (_TypeT* &__x, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
false));
}
#endif // _WIN64
inline
long __rw_atomic_exchange (long &__x, long __y, bool)
{
return InterlockedExchange (&__x, __y);
}
inline
unsigned long __rw_atomic_exchange (unsigned long &__x, unsigned long __y,
bool)
{
return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
_RWSTD_STATIC_CAST (long, __y), false);
}
inline
int __rw_atomic_exchange (int &__x, int __y, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
_RWSTD_STATIC_CAST (long, __y), false);
}
inline
unsigned int __rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
_RWSTD_STATIC_CAST (long, __y), false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline _TypeT* __rw_atomic_exchange (_TypeT* &__x, const _TypeT* __y, bool)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
_RWSTD_REINTERPRET_CAST (long, __y),
false));
}
#endif // _WIN64
inline
long __rw_atomic_preincrement (long &__x, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_preincrement (__x, false);
}
inline
unsigned long __rw_atomic_preincrement (unsigned long &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_preincrement (__x, false);
}
inline
int __rw_atomic_preincrement (int &__x, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_preincrement (__x, false);
}
inline
unsigned int __rw_atomic_preincrement (unsigned int &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_preincrement (__x, false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline
_TypeT* __rw_atomic_preincrement (_TypeT* &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
__mutex));
}
#endif // _WIN64
inline
long __rw_atomic_predecrement (long &__x, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_predecrement (__x, false);
}
inline
unsigned long __rw_atomic_predecrement (unsigned long &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_predecrement (__x, false);
}
inline
int __rw_atomic_predecrement (int &__x, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_predecrement (__x, false);
}
inline
unsigned int __rw_atomic_predecrement (unsigned int &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_predecrement (__x, false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline
_TypeT* __rw_atomic_predecrement (_TypeT* &__x,
__rw_mutex_base &__mutex)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
__mutex));
}
#endif // _WIN64
inline
long __rw_atomic_exchange (long &__x, long __y, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_exchange (__x, __y, false);
}
inline
unsigned long __rw_atomic_exchange (unsigned long &__x, unsigned long __y,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_exchange (__x, __y, false);
}
inline
int __rw_atomic_exchange (int &__x, int __y, __rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_exchange (__x, __y, false);
}
inline
unsigned int __rw_atomic_exchange (unsigned int &__x, unsigned int __y,
__rw_mutex_base &__mutex)
{
_RWSTD_UNUSED (__mutex);
return __rw_atomic_exchange (__x, __y, false);
}
#if !defined (_WIN64)
template <class _TypeT>
inline
_TypeT* __rw_atomic_exchange (_TypeT* &__x, const _TypeT* __y,
__rw_mutex_base &__mutex)
{
_RWSTD_COMPILE_ASSERT (sizeof __x == sizeof (long));
return _RWSTD_REINTERPRET_CAST (_TypeT*,
__rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
_RWSTD_REINTERPRET_CAST (long, __y),
__mutex));
}
#endif // _WIN64
#endif // _WIN32
_RWSTD_NAMESPACE_END // __rw
#else // if !defined (_RWSTD_MULTI_THREAD)
_RWSTD_NAMESPACE_BEGIN (__rw)
// atomic in a single-threaded environment
template <class _TypeT, class _TypeU>
inline
_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
{
_TypeT __tmp = __t;
__t = __u;
return __tmp;
}
// dummy classes used as a base class in single-threaded environments
struct __rw_mutex_base
{
void _C_acquire () { }
void _C_release () { }
};
struct _RWSTD_EXPORT __rw_mutex: public __rw_mutex_base
{
};
struct __rw_guard
{
__rw_guard (__rw_mutex_base&) { }
__rw_guard (__rw_mutex_base*) { }
__rw_mutex_base* _C_set (__rw_mutex_base*) {
return 0;
}
};
struct __rw_synchronized
{
// static so that it takes up no room
static __rw_mutex _C_mutex;
void _C_lock () { }
void _C_unlock () { }
__rw_guard _C_guard () {
return __rw_guard (_C_mutex);
}
};
_RWSTD_NAMESPACE_END // __rw
#endif // _RWSTD_MULTI_THREAD
_RWSTD_NAMESPACE_BEGIN (__rw)
// available in all environments (ST and MT), used along with
// __rw_atomic_exchange<>() from conditional expressions in iostreams
template <class _TypeT, class _TypeU>
inline
_TypeT __rw_ordinary_exchange (_TypeT &__t, const _TypeU &__u)
{
_TypeT __tmp = __t;
__t = __u;
return __tmp;
}
_RWSTD_NAMESPACE_END // __rw
#endif // _RWSTD_MUTEX_H_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -