atomic_fence.hpp (1694B)
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 | /* 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_FENCE_HPP #define RL_FENCE_HPP #ifdef _MSC_VER # pragma once #endif #include "base.hpp" #include "context.hpp" #include "memory_order.hpp" namespace rl { struct atomic_fence_event { memory_order mo_; bool is_thread_fence_; void output(std::ostream& s) const { s << (is_thread_fence_ ? "" : "compiler ") << format(mo_) << " fence"; } }; RL_INLINE void atomic_thread_fence(memory_order mo, debug_info_param info) { context& c = ctx(); RL_VERIFY(false == c.invariant_executing); switch (mo) { case mo_relaxed: RL_VERIFY(false); break; case mo_consume: case mo_acquire: c.atomic_thread_fence_acquire(); break; case mo_release: c.atomic_thread_fence_release(); break; case mo_acq_rel: c.atomic_thread_fence_acq_rel(); break; case mo_seq_cst: c.atomic_thread_fence_seq_cst(); break; } RL_HIST(atomic_fence_event) {mo, true} RL_HIST_END(); } RL_INLINE void atomic_signal_fence(memory_order mo, debug_info_param info) { context& c = ctx(); RL_HIST(atomic_fence_event) {mo, false} RL_HIST_END(); } } #endif |