4
4
#include <string.h>
5
5
6
6
7
- int equeue_create (struct equeue * q , unsigned size ) {
7
+ int equeue_create (equeue_t * q , unsigned size ) {
8
8
void * buffer = malloc (size );
9
9
if (!buffer ) {
10
10
return -1 ;
@@ -15,7 +15,7 @@ int equeue_create(struct equeue *q, unsigned size) {
15
15
return err ;
16
16
}
17
17
18
- int equeue_create_inplace (struct equeue * q , unsigned size , void * buffer ) {
18
+ int equeue_create_inplace (equeue_t * q , unsigned size , void * buffer ) {
19
19
q -> slab .size = size ;
20
20
q -> slab .data = buffer ;
21
21
q -> chunks = 0 ;
@@ -47,7 +47,7 @@ int equeue_create_inplace(struct equeue *q, unsigned size, void *buffer) {
47
47
return 0 ;
48
48
}
49
49
50
- void equeue_destroy (struct equeue * q ) {
50
+ void equeue_destroy (equeue_t * q ) {
51
51
while (q -> queue ) {
52
52
struct event * e = q -> queue ;
53
53
q -> queue = e -> next ;
@@ -61,7 +61,7 @@ void equeue_destroy(struct equeue *q) {
61
61
}
62
62
63
63
// equeue allocation functions
64
- static void * equeue_alloc (struct equeue * q , unsigned size ) {
64
+ static void * equeue_alloc (equeue_t * q , unsigned size ) {
65
65
size = size + sizeof (unsigned );
66
66
size = (size + sizeof (unsigned )-1 ) & ~(sizeof (unsigned )-1 );
67
67
if (size < sizeof (struct equeue_chunk )) {
@@ -97,7 +97,7 @@ static void *equeue_alloc(struct equeue *q, unsigned size) {
97
97
return 0 ;
98
98
}
99
99
100
- static void equeue_dealloc (struct equeue * q , void * e ) {
100
+ static void equeue_dealloc (equeue_t * q , void * e ) {
101
101
struct equeue_chunk * c = (struct equeue_chunk * )((unsigned * )e - 1 );
102
102
103
103
events_mutex_lock (& q -> freelock );
@@ -120,15 +120,15 @@ static void equeue_dealloc(struct equeue *q, void *e) {
120
120
}
121
121
122
122
// event allocation functions
123
- static inline int event_next_id (struct equeue * q ) {
123
+ static inline int event_next_id (equeue_t * q ) {
124
124
int id = q -> next_id ++ ;
125
125
if (q -> next_id < 0 ) {
126
126
q -> next_id = 42 ;
127
127
}
128
128
return id ;
129
129
}
130
130
131
- void * event_alloc (struct equeue * q , unsigned size ) {
131
+ void * event_alloc (equeue_t * q , unsigned size ) {
132
132
struct event * e = equeue_alloc (q , sizeof (struct event ) + size );
133
133
if (!e ) {
134
134
return 0 ;
@@ -142,7 +142,7 @@ void *event_alloc(struct equeue *q, unsigned size) {
142
142
return e + 1 ;
143
143
}
144
144
145
- void event_dealloc (struct equeue * q , void * p ) {
145
+ void event_dealloc (equeue_t * q , void * p ) {
146
146
struct event * e = (struct event * )p - 1 ;
147
147
148
148
if (e -> dtor ) {
@@ -157,7 +157,7 @@ static inline int equeue_tickdiff(unsigned a, unsigned b) {
157
157
return (int )(a - b );
158
158
}
159
159
160
- static int equeue_enqueue (struct equeue * q , struct event * e , int ms ) {
160
+ static int equeue_enqueue (equeue_t * q , struct event * e , int ms ) {
161
161
e -> target = events_tick () + (unsigned )ms ;
162
162
163
163
struct event * * p = & q -> queue ;
@@ -171,7 +171,7 @@ static int equeue_enqueue(struct equeue *q, struct event *e, int ms) {
171
171
return e -> id ;
172
172
}
173
173
174
- static struct event * equeue_dequeue (struct equeue * q , int id ) {
174
+ static struct event * equeue_dequeue (equeue_t * q , int id ) {
175
175
for (struct event * * p = & q -> queue ; * p ; p = & (* p )-> next ) {
176
176
if ((* p )-> id == id ) {
177
177
struct event * e = * p ;
@@ -183,15 +183,15 @@ static struct event *equeue_dequeue(struct equeue *q, int id) {
183
183
return 0 ;
184
184
}
185
185
186
- static int equeue_post (struct equeue * q , struct event * e , int ms ) {
186
+ static int equeue_post (equeue_t * q , struct event * e , int ms ) {
187
187
events_mutex_lock (& q -> queuelock );
188
188
int id = equeue_enqueue (q , e , ms );
189
189
events_mutex_unlock (& q -> queuelock );
190
190
events_sema_release (& q -> eventsema );
191
191
return id ;
192
192
}
193
193
194
- static void equeue_cancel (struct equeue * q , int id ) {
194
+ static void equeue_cancel (equeue_t * q , int id ) {
195
195
events_mutex_lock (& q -> queuelock );
196
196
struct event * e = equeue_dequeue (q , id );
197
197
events_mutex_unlock (& q -> queuelock );
@@ -201,11 +201,11 @@ static void equeue_cancel(struct equeue *q, int id) {
201
201
}
202
202
}
203
203
204
- void equeue_break (struct equeue * q ) {
204
+ void equeue_break (equeue_t * q ) {
205
205
equeue_post (q , & q -> break_ , 0 );
206
206
}
207
207
208
- void equeue_dispatch (struct equeue * q , int ms ) {
208
+ void equeue_dispatch (equeue_t * q , int ms ) {
209
209
if (ms >= 0 ) {
210
210
equeue_post (q , & q -> break_ , ms );
211
211
}
@@ -271,14 +271,14 @@ void event_dtor(void *p, void (*dtor)(void *)) {
271
271
}
272
272
273
273
// event operations
274
- int event_post (struct equeue * q , void (* cb )(void * ), void * p ) {
274
+ int event_post (equeue_t * q , void (* cb )(void * ), void * p ) {
275
275
struct event * e = (struct event * )p - 1 ;
276
276
e -> cb = cb ;
277
277
int id = equeue_post (q , e , e -> target );
278
278
return id ;
279
279
}
280
280
281
- void event_cancel (struct equeue * q , int id ) {
281
+ void event_cancel (equeue_t * q , int id ) {
282
282
return equeue_cancel (q , id );
283
283
}
284
284
@@ -293,7 +293,7 @@ static void ecallback_dispatch(void *p) {
293
293
e -> cb (e -> data );
294
294
}
295
295
296
- int event_call (struct equeue * q , void (* cb )(void * ), void * data ) {
296
+ int event_call (equeue_t * q , void (* cb )(void * ), void * data ) {
297
297
struct ecallback * e = event_alloc (q , sizeof (struct ecallback ));
298
298
if (!e ) {
299
299
return 0 ;
@@ -304,7 +304,7 @@ int event_call(struct equeue *q, void (*cb)(void*), void *data) {
304
304
return event_post (q , ecallback_dispatch , e );
305
305
}
306
306
307
- int event_call_in (struct equeue * q , void (* cb )(void * ), void * data , int ms ) {
307
+ int event_call_in (equeue_t * q , int ms , void (* cb )(void * ), void * data ) {
308
308
struct ecallback * e = event_alloc (q , sizeof (struct ecallback ));
309
309
if (!e ) {
310
310
return 0 ;
@@ -316,7 +316,7 @@ int event_call_in(struct equeue *q, void (*cb)(void*), void *data, int ms) {
316
316
return event_post (q , ecallback_dispatch , e );
317
317
}
318
318
319
- int event_call_every (struct equeue * q , void (* cb )(void * ), void * data , int ms ) {
319
+ int event_call_every (equeue_t * q , int ms , void (* cb )(void * ), void * data ) {
320
320
struct ecallback * e = event_alloc (q , sizeof (struct ecallback ));
321
321
if (!e ) {
322
322
return 0 ;
0 commit comments