medfall

A super great game engine
Log | Files | Refs

defs.hpp (3090B)


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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*  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_DEFS_HPP
#define RL_DEFS_HPP
#ifdef _MSC_VER
#   pragma once
#endif


namespace rl
{

typedef int thread_id_t;
typedef size_t timestamp_t;
typedef uint64_t iteration_t;

size_t const atomic_history_size = 3;
iteration_t const progress_probe_period = 4 * 1024;

size_t const alignment = 16;

class context;
class thread_base;
struct win_waitable_object;

enum sched_type
{
    sched_type_sched,
    sched_type_atomic_load,
    sched_type_cas_fail,
    sched_type_mem_realloc,
    sched_type_user,
};

enum unpark_reason
{
    unpark_reason_normal,
    unpark_reason_timeout,
    unpark_reason_spurious,
};

struct debug_info
{
    char const* func_;
    char const* file_;
    unsigned line_;

    debug_info(char const* func = "", char const* file = "", unsigned line = 0)
        : func_(func)
        , file_(file)
        , line_(line)
    {
    }
};

typedef debug_info const& debug_info_param;

inline void assert_failed(char const* cond, debug_info_param info)
{
    std::cout << "RELACY INTERNAL ASSERT FAILED: '" << cond
    << "' at " << info.file_ << ":" << info.line_ << " (" << info.func_ << ")" << std::endl;
}

template<typename T>
struct raw_allocator : std::allocator<T>
{
    template<class Y>
    struct rebind
    {
        typedef raw_allocator<Y> other;
    };

    template<typename Y>
    raw_allocator(raw_allocator<Y> const&)
    {
    }

    raw_allocator(raw_allocator const& rhs)
        : std::allocator<T>(rhs)
    {
    }

    raw_allocator()
        : std::allocator<T>()
    {
    }

    T* allocate(size_t count, void* = 0)
    {
        return (T*)(::malloc)(count * sizeof(T));
    }

    void deallocate(T* p, size_t)
    {
        (::free)(p);
    }
};


template<typename T>
struct vector
{
    typedef std::vector<T, raw_allocator<T> > type;
};

template<typename T>
struct queue
{
    typedef std::queue<T, std::deque<T, raw_allocator<T> > > type;
};

template<typename T>
struct stack
{
    typedef std::stack<T, std::vector<T, raw_allocator<T> > > type;
};

template<typename T>
struct set
{
    typedef std::set<T, std::less<T>, raw_allocator<T> > type;
};

template<typename T, typename Y>
struct map
{
    typedef std::map<T, Y, std::less<T>, raw_allocator<std::pair<T, Y> > > type;
};

typedef std::basic_string<char, std::char_traits<char>, raw_allocator<char> > string;
typedef std::basic_ostringstream<char, std::char_traits<char>, raw_allocator<char> > ostringstream;
typedef std::basic_istringstream<char, std::char_traits<char>, raw_allocator<char> > istringstream;

}


#endif