medfall

A super great game engine
Log | Files | Refs

atomic_events.hpp (3319B)


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