summaryrefslogtreecommitdiffstats
path: root/04_exercise/ppmlib/main.out.c
blob: 5a0bcf19448be38868c6c794facd633fb115ec14 (plain) (blame)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "main.c"
# 1 "../threadpool.h" 1



# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stdatomic.h" 1 3 4
# 29 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stdatomic.h" 3 4

# 29 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stdatomic.h" 3 4
typedef enum {
    memory_order_relaxed = 0,
    memory_order_consume = 1,
    memory_order_acquire = 2,
    memory_order_release = 3,
    memory_order_acq_rel = 4,
    memory_order_seq_cst = 5
} memory_order;


typedef _Atomic _Bool              atomic_bool;
typedef _Atomic char               atomic_char;
typedef _Atomic signed char        atomic_schar;
typedef _Atomic unsigned char      atomic_uchar;
typedef _Atomic short              atomic_short;
typedef _Atomic unsigned short     atomic_ushort;
typedef _Atomic int                atomic_int;
typedef _Atomic unsigned int       atomic_uint;
typedef _Atomic long               atomic_long;
typedef _Atomic unsigned long      atomic_ulong;
typedef _Atomic long long          atomic_llong;
typedef _Atomic unsigned long long atomic_ullong;
typedef _Atomic short unsigned int atomic_char16_t;
typedef _Atomic unsigned int       atomic_char32_t;
typedef _Atomic int                atomic_wchar_t;
typedef _Atomic signed char        atomic_int_least8_t;
typedef _Atomic unsigned char      atomic_uint_least8_t;
typedef _Atomic short int          atomic_int_least16_t;
typedef _Atomic short unsigned int atomic_uint_least16_t;
typedef _Atomic int                atomic_int_least32_t;
typedef _Atomic unsigned int       atomic_uint_least32_t;
typedef _Atomic long int           atomic_int_least64_t;
typedef _Atomic long unsigned int  atomic_uint_least64_t;
typedef _Atomic signed char        atomic_int_fast8_t;
typedef _Atomic unsigned char      atomic_uint_fast8_t;
typedef _Atomic long int           atomic_int_fast16_t;
typedef _Atomic long unsigned int  atomic_uint_fast16_t;
typedef _Atomic long int           atomic_int_fast32_t;
typedef _Atomic long unsigned int  atomic_uint_fast32_t;
typedef _Atomic long int           atomic_int_fast64_t;
typedef _Atomic long unsigned int  atomic_uint_fast64_t;
typedef _Atomic long int           atomic_intptr_t;
typedef _Atomic long unsigned int  atomic_uintptr_t;
typedef _Atomic long unsigned int  atomic_size_t;
typedef _Atomic long int           atomic_ptrdiff_t;
typedef _Atomic long int           atomic_intmax_t;
typedef _Atomic long unsigned int  atomic_uintmax_t;
# 92 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stdatomic.h" 3 4

extern void atomic_thread_fence(memory_order);

extern void atomic_signal_fence(memory_order);

# 218 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stdatomic.h" 3 4
typedef _Atomic struct {

    _Bool __val;


} atomic_flag;


extern _Bool atomic_flag_test_and_set(volatile atomic_flag *);


extern _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *,
                                               memory_order);


extern void atomic_flag_clear(volatile atomic_flag *);

extern void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);

# 5 "../threadpool.h" 2
# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 1 3 4
# 143 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 3 4
typedef long int ptrdiff_t;
# 209 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 3 4
typedef long unsigned int size_t;
# 321 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 3 4
typedef int wchar_t;
# 415 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 3 4
typedef struct {
    long long   __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
    long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
# 426 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 3 4
}           max_align_t;
# 6 "../threadpool.h" 2
# 1 "../ppmlib/ppmlib.h" 1
# 16 "../ppmlib/ppmlib.h"
# 1 "/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/include/stddef.h" 1 3 4
# 17 "../ppmlib/ppmlib.h" 2
# 7 "../threadpool.h" 2







# 13 "../threadpool.h"

typedef void (*ThreadTask_f)(void *);

typedef atomic_char FutureStatus;
enum FurutureStatusEnum {
    FUT_WAITING = 0, FUT_IN_PROGRESS = 1, FUT_DONE = 2
};


typedef struct Future {
    ThreadTask_f fn;

    FutureStatus status;
}                   Future;
# 33 "../threadpool.h"

extern int tpInit(size_t size);


extern void tpRelease(void);

# 52 "../threadpool.h"

extern void tpAsync(Future *future);

# 63 "../threadpool.h"

extern void tpAwait(Future *future);

# 2 "main.c" 2

int test_func(int);

typedef struct {
    Future fut;
    int    int_3;
    int    res;
}                   test_func_fut;

static void test_funcThunk(void *args) {
    test_func_fut *data = args;
    data->res = test_func(data->int_3);
}

static inline test_func_fut test_funcFuture(
        int int_3) { return (test_func_fut) {.fut = {.fn = &test_funcThunk, .status=FUT_WAITING}, .int_3 = int_3}; }

static inline test_func_fut *test_funcAsync(test_func_fut *future) { return tpAsync(&future->fut), future; }

static inline int test_funcAwait(test_func_fut *future) { return tpAwait(&future->fut), future->res; }