medfall

A super great game engine
Log | Files | Refs

base.hpp (2736B)


      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_BASE_HPP
     11 #define RL_BASE_HPP
     12 #ifdef _MSC_VER
     13 #   pragma once
     14 #endif
     15 
     16 #include "pch.hpp"
     17 #include "platform.hpp"
     18 
     19 namespace rl
     20 {
     21 size_t const subsequent_timed_wait_limit = 4;
     22 }
     23 
     24 #define RL_TEST
     25 
     26 #ifdef RL_JAVA_MODE
     27 #   define RL_GC
     28 #   define RL_NO_MALLOC
     29 #   define RL_JAVA_API
     30 #   define RL_JAVA_MM
     31 #endif
     32 
     33 #ifdef RL_CLI_MODE
     34 #   define RL_GC
     35 #   define RL_NO_MALLOC
     36 #   define RL_CLI_API
     37 #   define RL_CLI_MM
     38 #endif
     39 
     40 #ifdef RL_POSIX_MODE
     41 #   define RL_POSIX_API
     42 #endif
     43 
     44 #ifdef RL_WIN_MODE
     45 #   define RL_WIN_API
     46 #endif
     47 
     48 #ifdef RL_CPP_MODE
     49 #   define RL_CPP_API
     50 #   define RL_CPP_MM
     51 #endif
     52 
     53 #if defined(RL_JAVA_MM) || defined(RL_CLI_MM)
     54 #   define RL_IMPROVED_SEQ_CST_FENCE
     55 #   define RL_IMPROVED_SEQ_CST_RMW
     56 #endif
     57 
     58 namespace rl
     59 {
     60 
     61 #define RL_NOCOPY(CLASS) \
     62     private: \
     63     CLASS(CLASS const&); \
     64     CLASS& operator = (CLASS const&);
     65 /**/
     66 
     67 
     68 template<typename T = void>
     69 class nocopy
     70 {
     71     nocopy(nocopy const&);
     72     nocopy& operator = (nocopy const&);
     73 
     74 protected:
     75     nocopy() {}
     76 };
     77 
     78 
     79 template<size_t sz, size_t base = 4>
     80 struct align_pad
     81 {
     82     template<bool perfect, bool fit, int fake> struct helper
     83     {
     84         struct type { char pad [base - sz]; };
     85     };
     86 
     87     template<int fake> struct helper<true, true, fake>
     88     {
     89         struct type {};
     90     };
     91 
     92     template<bool perfect, int fake> struct helper<perfect, false, fake>
     93     {
     94         typedef typename align_pad<sz, base * 2>::type type;
     95     };
     96 
     97     typedef typename helper<sz == base, sz <= base, 0>::type type;
     98 };
     99 
    100 
    101 template<typename T>
    102 struct aligned : T, align_pad<sizeof(T)>::type
    103 {};
    104 
    105 template<typename T>
    106 T val(T x)
    107 {
    108     return x;
    109 }
    110 
    111 }
    112 
    113 
    114 #include "defs.hpp"
    115 
    116 
    117 #define RL_INFO ::rl::debug_info(__FUNCTION__, __FILE__, __LINE__)
    118 #define $ RL_INFO
    119 
    120 
    121 #ifdef RL_DO_ASSERT
    122 #   if RL_DO_ASSERT
    123 #       define RL_DO_ASSERT_IMPL
    124 #   endif
    125 #else
    126 #   ifdef _DEBUG
    127 #       define RL_DO_ASSERT_IMPL
    128 #   endif
    129 #endif
    130 
    131 #ifdef _MSC_VER
    132 #   define RL_INT3() __debugbreak(); abort()
    133 #else
    134 #   define RL_INT3() abort()
    135 #endif
    136 
    137 #ifdef RL_DO_ASSERT_IMPL
    138 #   define RL_VERIFY(x) do { if (!((void)0, (x))) { \
    139         ::rl::assert_failed(#x, $); RL_INT3(); } } while ((void)0, 0)
    140 #else
    141 #   define RL_VERIFY(x) (void)0
    142 #endif
    143 
    144 #endif