T* with additional functionality for twiddling low-order bits.
template<typename T>
class tricky_atomic_pointer: no_copy {
public:
typedef typename atomic_selector<sizeof(T*)>::word word;
template<memory_semantics M>
static T* fetch_and_add( T* volatile * location, word addend ) {
return reinterpret_cast<T*>( atomic_traits<sizeof(T*),M>::fetch_and_add(location, addend) );
}
template<memory_semantics M>
static T* fetch_and_store( T* volatile * location, T* value ) {
return reinterpret_cast<T*>( atomic_traits<sizeof(T*),M>::fetch_and_store(location, reinterpret_cast<word>(value)) );
}
template<memory_semantics M>
static T* compare_and_swap( T* volatile * location, T* value, T* comparand ) {
return reinterpret_cast<T*>(
atomic_traits<sizeof(T*),M>::compare_and_swap(location, reinterpret_cast<word>(value),
reinterpret_cast<word>(comparand))
);
}
T* & ref;
tricky_atomic_pointer( T*& original ) : ref(original) {};
tricky_atomic_pointer( T* volatile & original ) : ref(original) {};
T* operator&( word operand2 ) const {
return reinterpret_cast<T*>( reinterpret_cast<word>(ref) & operand2 );
}
T* operator|( word operand2 ) const {
return reinterpret_cast<T*>( reinterpret_cast<word>(ref) | operand2 );
}
};
typedef tricky_atomic_pointer<queuing_rw_mutex::scoped_lock> tricky_pointer;
Не надо в чат столько кода кидать
Обсуждают сегодня