medfall

A super great game engine
Log | Files | Refs

backoff.hpp (1107B)


      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_BACKOFF_HPP
     11 #define RL_BACKOFF_HPP
     12 #ifdef _MSC_VER
     13 #   pragma once
     14 #endif
     15 
     16 #include "base.hpp"
     17 #include "context_base.hpp"
     18 
     19 
     20 namespace rl
     21 {
     22 
     23 
     24 inline void yield(unsigned count, debug_info_param info)
     25 {
     26     ctx().yield(count, info);
     27 }
     28 
     29 
     30 template<unsigned factor_t, unsigned add_t>
     31 class backoff_t
     32 {
     33 public:
     34     backoff_t()
     35         : count_(1)
     36     {
     37     }
     38 
     39     void yield(debug_info_param info)
     40     {
     41         rl::yield(count_, info);
     42         count_ = count_ * factor_t + add_t;
     43     }
     44 
     45 private:
     46     unsigned count_;
     47 };
     48 
     49 
     50 typedef backoff_t<1, 0> backoff;
     51 typedef backoff_t<1, 1> linear_backoff;
     52 typedef backoff_t<2, 0> exp_backoff;
     53 
     54 
     55 }
     56 
     57 #endif