medfall

A super great game engine
Log | Files | Refs

defs.hpp (3086B)


      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_DEFS_HPP
     11 #define RL_DEFS_HPP
     12 #ifdef _MSC_VER
     13 #   pragma once
     14 #endif
     15 
     16 
     17 namespace rl
     18 {
     19 
     20 typedef int thread_id_t;
     21 typedef size_t timestamp_t;
     22 typedef uint64_t iteration_t;
     23 
     24 size_t const atomic_history_size = 3;
     25 iteration_t const progress_probe_period = 4 * 1024;
     26 
     27 size_t const alignment = 16;
     28 
     29 class context;
     30 class thread_base;
     31 struct win_waitable_object;
     32 
     33 enum sched_type
     34 {
     35     sched_type_sched,
     36     sched_type_atomic_load,
     37     sched_type_cas_fail,
     38     sched_type_mem_realloc,
     39     sched_type_user,
     40 };
     41 
     42 enum unpark_reason
     43 {
     44     unpark_reason_normal,
     45     unpark_reason_timeout,
     46     unpark_reason_spurious,
     47 };
     48 
     49 struct debug_info
     50 {
     51     char const* func_;
     52     char const* file_;
     53     unsigned line_;
     54 
     55     debug_info(char const* func = "", char const* file = "", unsigned line = 0)
     56         : func_(func)
     57         , file_(file)
     58         , line_(line)
     59     {
     60     }
     61 };
     62 
     63 typedef debug_info const& debug_info_param;
     64 
     65 inline void assert_failed(char const* cond, debug_info_param info)
     66 {
     67     std::cout << "RELACY INTERNAL ASSERT FAILED: '" << cond
     68     << "' at " << info.file_ << ":" << info.line_ << " (" << info.func_ << ")" << std::endl;
     69 }
     70 
     71 template<typename T>
     72 struct raw_allocator : std::allocator<T>
     73 {
     74     template<class Y>
     75     struct rebind
     76     {
     77         typedef raw_allocator<Y> other;
     78     };
     79 
     80     template<typename Y>
     81     raw_allocator(raw_allocator<Y> const&)
     82     {
     83     }
     84 
     85     raw_allocator(raw_allocator const& rhs)
     86         : std::allocator<T>(rhs)
     87     {
     88     }
     89 
     90     raw_allocator()
     91         : std::allocator<T>()
     92     {
     93     }
     94 
     95     T* allocate(size_t count, void* = 0)
     96     {
     97         return (T*)(::malloc)(count * sizeof(T));
     98     }
     99 
    100     void deallocate(T* p, size_t)
    101     {
    102         (::free)(p);
    103     }
    104 };
    105 
    106 
    107 template<typename T>
    108 struct vector
    109 {
    110     typedef std::vector<T, raw_allocator<T> > type;
    111 };
    112 
    113 template<typename T>
    114 struct queue
    115 {
    116     typedef std::queue<T, std::deque<T, raw_allocator<T> > > type;
    117 };
    118 
    119 template<typename T>
    120 struct stack
    121 {
    122     typedef std::stack<T, std::vector<T, raw_allocator<T> > > type;
    123 };
    124 
    125 template<typename T>
    126 struct set
    127 {
    128     typedef std::set<T, std::less<T>, raw_allocator<T> > type;
    129 };
    130 
    131 template<typename T, typename Y>
    132 struct map
    133 {
    134     typedef std::map<T, Y, std::less<T>, raw_allocator<std::pair<T, Y> > > type;
    135 };
    136 
    137 typedef std::basic_string<char, std::char_traits<char>, raw_allocator<char> > string;
    138 typedef std::basic_ostringstream<char, std::char_traits<char>, raw_allocator<char> > ostringstream;
    139 typedef std::basic_istringstream<char, std::char_traits<char>, raw_allocator<char> > istringstream;
    140 
    141 }
    142 
    143 
    144 #endif