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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use ThreadPool;
// #[no_mangle]
// pub static mut MAX_QUEUE_SIZE: size_t = 100000 as libc::c_int as size_t;
// #[no_mangle]
// pub static mut NUM_THREADS: size_t = 16 as libc::c_int as size_t;
// #[no_mangle]
// pub static mut queue: *mut queue_t = 0 as *const queue_t as *mut queue_t;
// #[no_mangle]
// pub unsafe extern "C" fn enqueue_worker(mut arg: *mut libc::c_void) -> *mut libc::c_void {
// let mut thread_id: size_t = *(arg as *mut size_t);
// free(arg);
// let mut i: size_t = thread_id;
// while i < MAX_QUEUE_SIZE {
// let mut value: *mut size_t =
// malloc(::std::mem::size_of::<size_t>() as libc::c_ulong) as *mut size_t;
// if !value.is_null() {
// } else {
// __assert_fail(
// b"value != NULL\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 21 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 29], &[libc::c_char; 29]>(
// b"void *enqueue_worker(void *)\x00",
// ))
// .as_ptr(),
// );
// }
// *value = i;
// queue_enqueue(queue, value as *mut libc::c_void);
// i = (i as libc::c_ulong).wrapping_add(NUM_THREADS) as size_t as size_t
// }
// return 0 as *mut libc::c_void;
// }
// #[no_mangle]
// pub unsafe extern "C" fn dequeue_worker(mut _arg: *mut libc::c_void) -> *mut libc::c_void {
// let mut thread_indices: [size_t; 16] = [
// 0 as libc::c_int as size_t,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// ];
// let mut i: size_t = 0 as libc::c_int as size_t;
// while i < MAX_QUEUE_SIZE {
// let mut value: *mut size_t = queue_dequeue(queue) as *mut size_t;
// let mut thread_id: size_t = (*value).wrapping_rem(NUM_THREADS);
// let fresh0 = thread_indices[thread_id as usize];
// thread_indices[thread_id as usize] = thread_indices[thread_id as usize].wrapping_add(1);
// let mut thread_index: size_t = fresh0;
// if *value
// == thread_index
// .wrapping_mul(NUM_THREADS)
// .wrapping_add(thread_id)
// {
// } else {
// __assert_fail(
// b"*value == thread_index * NUM_THREADS + thread_id\x00" as *const u8
// as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 38 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 29], &[libc::c_char; 29]>(
// b"void *dequeue_worker(void *)\x00",
// ))
// .as_ptr(),
// );
// }
// free(value as *mut libc::c_void);
// i = i.wrapping_add(1)
// }
// let mut i_0: size_t = 0 as libc::c_int as size_t;
// while i_0 < NUM_THREADS {
// if thread_indices[i_0 as usize] == MAX_QUEUE_SIZE.wrapping_div(NUM_THREADS) {
// } else {
// __assert_fail(
// b"thread_indices[i] == MAX_QUEUE_SIZE / NUM_THREADS\x00" as *const u8
// as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 44 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 29], &[libc::c_char; 29]>(
// b"void *dequeue_worker(void *)\x00",
// ))
// .as_ptr(),
// );
// }
// i_0 = i_0.wrapping_add(1)
// }
// return 0 as *mut libc::c_void;
// }
// unsafe fn main_0() -> libc::c_int {
// queue = queue_init();
// let vla = NUM_THREADS as usize;
// let mut enqueue_threads: Vec<pthread_t> = ::std::vec::from_elem(0, vla);
// let mut dequeue_thread: pthread_t = 0;
// let mut result: libc::c_int = pthread_create(
// &mut dequeue_thread,
// 0 as *const pthread_attr_t,
// Some(dequeue_worker as unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void),
// 0 as *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 57 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00")).as_ptr(),
// );
// }
// sleep(5 as libc::c_int as libc::c_uint);
// let mut i: size_t = 0 as libc::c_int as size_t;
// while i < NUM_THREADS {
// let mut thread_id: *mut size_t =
// malloc(::std::mem::size_of::<size_t>() as libc::c_ulong) as *mut size_t;
// if !thread_id.is_null() {
// } else {
// __assert_fail(
// b"thread_id != NULL\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 62 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// *thread_id = i;
// result = pthread_create(
// &mut *enqueue_threads.as_mut_ptr().offset(i as isize),
// 0 as *const pthread_attr_t,
// Some(enqueue_worker as unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void),
// thread_id as *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 65 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i = i.wrapping_add(1)
// }
// let mut i_0: size_t = 0 as libc::c_int as size_t;
// while i_0 < NUM_THREADS {
// result = pthread_join(
// *enqueue_threads.as_mut_ptr().offset(i_0 as isize),
// 0 as *mut *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 70 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i_0 = i_0.wrapping_add(1)
// }
// result = pthread_join(dequeue_thread, 0 as *mut *mut libc::c_void);
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_empty.c\x00" as *const u8 as *const libc::c_char,
// 73 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00")).as_ptr(),
// );
// }
// queue_free(queue);
// return 0;
// }
// pub fn main() {
// unsafe { ::std::process::exit(main_0() as i32) }
// }