atomic_events.hpp (3323B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | /* Relacy Race Detector * Copyright (c) 2008-2010, Dmitry S. Vyukov * All rights reserved. * This software is provided AS-IS with no warranty, either express or implied. * This software is distributed under a license and may not be copied, * modified or distributed except as expressly authorized under the * terms of the license contained in the file LICENSE.TXT in this distribution. */ #ifndef RL_ATOMIC_EVENTS_HPP #define RL_ATOMIC_EVENTS_HPP #ifdef _MSC_VER # pragma once #endif #include "base.hpp" #include "memory_order.hpp" #include "rmw.hpp" namespace rl { template<typename T> class atomic; template<typename T, bool strong_init> class generic_atomic; template<typename T> struct atomic_add_type { typedef T type; typedef T output_type; }; template<typename T> struct atomic_add_type<T*> { typedef ptrdiff_t type; typedef void* output_type; }; template<typename T> struct atomic_cas_event { typedef typename atomic_add_type<T>::output_type type; debug_info var_info_; void const* var_addr_; type cur_value_; type cmp_value_; type xchg_value_; memory_order mo_; bool success_; bool spurious_failure_; bool aba_; void output(std::ostream& s) const { s << "<" << std::hex << var_addr_ << std::dec << ">" << " CAS " << (success_ ? "succ " : "fail ") << (spurious_failure_ ? "[SPURIOUSLY] " : "") << (aba_ ? "[ABA] " : "") << "orig=" << cur_value_ << ", cmp=" << cmp_value_ << ", xchg=" << xchg_value_ << ", order=" << format(mo_); } }; template<typename T> struct atomic_load_event { typedef typename atomic_add_type<T>::output_type type; void const* var_addr_; type value_; memory_order mo_; bool not_current_; void output(std::ostream& s) const { s << "<" << std::hex << var_addr_ << std::dec << ">" << " atomic load, value=" << value_ << (not_current_ ? " [NOT CURRENT]" : "") << ", order=" << format(mo_); } }; template<typename T> struct atomic_store_event { typedef typename atomic_add_type<T>::output_type type; void const* var_addr_; type prev_value_; type value_; memory_order mo_; void output(std::ostream& s) const { s << "<" << std::hex << var_addr_ << std::dec << ">" << " atomic store, value=" << value_ << ", (prev value=" << prev_value_ << ")" << ", order=" << format(mo_); } }; template<typename T, typename Y> struct atomic_rmw_event { typedef typename atomic_add_type<T>::output_type type; debug_info var_info_; void const* var_addr_; type prev_value_; Y op_value_; type new_value_; memory_order mo_; rmw_type_e type_; void output(std::ostream& s) const { s << "<" << std::hex << var_addr_ << std::dec << ">" << " " << format(type_) << " " << ", prev=" << prev_value_ << ", arg=" << op_value_ << ", new=" << new_value_ << ", order=" << format(mo_); } }; } #endif |