sync_var.hpp (1539B)
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 | /* 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_SYNC_VAR_HPP #define RL_SYNC_VAR_HPP #ifdef _MSC_VER # pragma once #endif #include "base.hpp" #include "foreach.hpp" namespace rl { template<thread_id_t thread_count> class sync_var : nocopy<> { public: sync_var() { iteration_begin(); } void iteration_begin() { foreach<thread_count>(order_, &assign_zero); } void acquire(thread_info_base* th) { th->own_acq_rel_order_ += 1; foreach<thread_count>(th->acq_rel_order_, order_, &assign_max); } void release(thread_info_base* th) { th->own_acq_rel_order_ += 1; foreach<thread_count>(order_, th->acq_rel_order_, &assign_max); } void acq_rel(thread_info_base* th) { th->own_acq_rel_order_ += 1; timestamp_t* acq_rel_order = th->acq_rel_order_; timestamp_t* order = order_; foreach<thread_count>(acq_rel_order, order, &assign_max); foreach<thread_count>(order, acq_rel_order, &assign_max); } private: timestamp_t order_ [thread_count]; }; } #endif |