medfall

A super great game engine
Log | Files | Refs

atomic_fence.hpp (1690B)


      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_FENCE_HPP
     11 #define RL_FENCE_HPP
     12 #ifdef _MSC_VER
     13 #   pragma once
     14 #endif
     15 
     16 #include "base.hpp"
     17 #include "context.hpp"
     18 #include "memory_order.hpp"
     19 
     20 
     21 namespace rl
     22 {
     23 
     24 
     25 struct atomic_fence_event
     26 {
     27     memory_order mo_;
     28     bool is_thread_fence_;
     29 
     30     void output(std::ostream& s) const
     31     {
     32         s << (is_thread_fence_ ? "" : "compiler ")
     33             << format(mo_) << " fence";
     34     }
     35 };
     36 
     37 
     38 
     39 
     40 RL_INLINE
     41 void atomic_thread_fence(memory_order mo, debug_info_param info)
     42 {
     43     context& c = ctx();
     44     RL_VERIFY(false == c.invariant_executing);
     45 
     46     switch (mo)
     47     {
     48     case mo_relaxed:
     49         RL_VERIFY(false);
     50         break;
     51     case mo_consume:
     52     case mo_acquire:
     53         c.atomic_thread_fence_acquire();
     54         break;
     55     case mo_release:
     56         c.atomic_thread_fence_release();
     57         break;
     58     case mo_acq_rel:
     59         c.atomic_thread_fence_acq_rel();
     60         break;
     61     case mo_seq_cst:
     62         c.atomic_thread_fence_seq_cst();
     63         break;
     64     }
     65 
     66     RL_HIST(atomic_fence_event) {mo, true} RL_HIST_END();
     67 }
     68 
     69 
     70 
     71 
     72 RL_INLINE
     73 void atomic_signal_fence(memory_order mo, debug_info_param info)
     74 {
     75     context& c = ctx();
     76     RL_HIST(atomic_fence_event) {mo, false} RL_HIST_END();
     77 }
     78 
     79 
     80 }
     81 
     82 
     83 #endif