ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/etp.c
(Generate patch)

Comparing libeio/etp.c (file contents):
Revision 1.3 by root, Thu Jun 25 15:59:57 2015 UTC vs.
Revision 1.13 by root, Tue Aug 14 11:44:53 2018 UTC

1/* 1/*
2 * libetp implementation 2 * libetp implementation
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libetp@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2015 Marc Alexander Lehmann <libetp@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
35 * and other provisions required by the GPL. If you do not delete the 35 * and other provisions required by the GPL. If you do not delete the
36 * provisions above, a recipient may use your version of this file under 36 * provisions above, a recipient may use your version of this file under
37 * either the BSD or the GPL. 37 * either the BSD or the GPL.
38 */ 38 */
39 39
40#if HAVE_SYS_PRCTL_H
41# include <sys/prctl.h>
42#endif
43
40#ifndef ETP_API_DECL 44#ifndef ETP_API_DECL
41# define ETP_API_DECL static 45# define ETP_API_DECL static
42#endif 46#endif
43 47
44#ifndef ETP_PRI_MIN 48#ifndef ETP_PRI_MIN
52 56
53#ifndef ETP_TYPE_GROUP 57#ifndef ETP_TYPE_GROUP
54# define ETP_TYPE_GROUP 1 58# define ETP_TYPE_GROUP 1
55#endif 59#endif
56 60
61#ifndef ETP_WANT_POLL
62# define ETP_WANT_POLL(pool) pool->want_poll_cb (pool->userdata)
63#endif
64#ifndef ETP_DONE_POLL
65# define ETP_DONE_POLL(pool) pool->done_poll_cb (pool->userdata)
66#endif
67
57#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) 68#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
58 69
59#define ETP_TICKS ((1000000 + 1023) >> 10) 70#define ETP_TICKS ((1000000 + 1023) >> 10)
71
72enum {
73 ETP_FLAG_GROUPADD = 0x04, /* some request was added to the group */
74 ETP_FLAG_DELAYED = 0x08, /* groiup request has been delayed */
75};
60 76
61/* calculate time difference in ~1/ETP_TICKS of a second */ 77/* calculate time difference in ~1/ETP_TICKS of a second */
62ecb_inline int 78ecb_inline int
63etp_tvdiff (struct timeval *tv1, struct timeval *tv2) 79etp_tvdiff (struct timeval *tv1, struct timeval *tv2)
64{ 80{
65 return (tv2->tv_sec - tv1->tv_sec ) * ETP_TICKS 81 return (tv2->tv_sec - tv1->tv_sec ) * ETP_TICKS
66 + ((tv2->tv_usec - tv1->tv_usec) >> 10); 82 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
67} 83}
68 84
69static unsigned int started, idle, wanted = 4;
70
71static void (*want_poll_cb) (void);
72static void (*done_poll_cb) (void);
73
74static unsigned int max_poll_time; /* reslock */
75static unsigned int max_poll_reqs; /* reslock */
76
77static unsigned int nreqs; /* reqlock */
78static unsigned int nready; /* reqlock */
79static unsigned int npending; /* reqlock */
80static unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */
81static unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */
82
83static xmutex_t wrklock;
84static xmutex_t reslock;
85static xmutex_t reqlock;
86static xcond_t reqwait;
87
88struct etp_tmpbuf 85struct etp_tmpbuf
89{ 86{
90 void *ptr; 87 void *ptr;
91 int len; 88 int len;
92}; 89};
99 free (buf->ptr); 96 free (buf->ptr);
100 buf->ptr = malloc (buf->len = len); 97 buf->ptr = malloc (buf->len = len);
101 } 98 }
102 99
103 return buf->ptr; 100 return buf->ptr;
104}
105
106typedef struct etp_worker
107{
108 struct etp_tmpbuf tmpbuf;
109
110 /* locked by wrklock */
111 struct etp_worker *prev, *next;
112
113 xthread_t tid;
114
115#ifdef ETP_WORKER_COMMON
116 ETP_WORKER_COMMON
117#endif
118} etp_worker;
119
120static etp_worker wrk_first; /* NOT etp */
121
122#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
123#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
124
125/* worker threads management */
126
127static void
128etp_worker_clear (etp_worker *wrk)
129{
130}
131
132static void ecb_cold
133etp_worker_free (etp_worker *wrk)
134{
135 free (wrk->tmpbuf.ptr);
136
137 wrk->next->prev = wrk->prev;
138 wrk->prev->next = wrk->next;
139
140 free (wrk);
141}
142
143ETP_API_DECL unsigned int
144etp_nreqs (void)
145{
146 int retval;
147 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
148 retval = nreqs;
149 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
150 return retval;
151}
152
153ETP_API_DECL unsigned int
154etp_nready (void)
155{
156 unsigned int retval;
157
158 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
159 retval = nready;
160 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
161
162 return retval;
163}
164
165ETP_API_DECL unsigned int
166etp_npending (void)
167{
168 unsigned int retval;
169
170 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
171 retval = npending;
172 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
173
174 return retval;
175}
176
177ETP_API_DECL unsigned int
178etp_nthreads (void)
179{
180 unsigned int retval;
181
182 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
183 retval = started;
184 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
185
186 return retval;
187} 101}
188 102
189/* 103/*
190 * a somewhat faster data structure might be nice, but 104 * a somewhat faster data structure might be nice, but
191 * with 8 priorities this actually needs <20 insns 105 * with 8 priorities this actually needs <20 insns
192 * per shift, the most expensive operation. 106 * per shift, the most expensive operation.
193 */ 107 */
194typedef struct { 108typedef struct
109{
195 ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */ 110 ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */
196 int size; 111 int size;
197} etp_reqq; 112} etp_reqq;
198 113
114typedef struct etp_pool *etp_pool;
115
116typedef struct etp_worker
117{
118 etp_pool pool;
119
120 struct etp_tmpbuf tmpbuf;
121
122 /* locked by pool->wrklock */
123 struct etp_worker *prev, *next;
124
125 xthread_t tid;
126
127#ifdef ETP_WORKER_COMMON
128 ETP_WORKER_COMMON
129#endif
130} etp_worker;
131
132struct etp_pool
133{
134 void *userdata;
135
199static etp_reqq req_queue; 136 etp_reqq req_queue;
200static etp_reqq res_queue; 137 etp_reqq res_queue;
138
139 unsigned int started, idle, wanted;
140
141 unsigned int max_poll_time; /* pool->reslock */
142 unsigned int max_poll_reqs; /* pool->reslock */
143
144 unsigned int nreqs; /* pool->reqlock */
145 unsigned int nready; /* pool->reqlock */
146 unsigned int npending; /* pool->reqlock */
147 unsigned int max_idle; /* maximum number of threads that can pool->idle indefinitely */
148 unsigned int idle_timeout; /* number of seconds after which an pool->idle threads exit */
149
150 void (*want_poll_cb) (void *userdata);
151 void (*done_poll_cb) (void *userdata);
152
153 xmutex_t wrklock;
154 xmutex_t reslock;
155 xmutex_t reqlock;
156 xcond_t reqwait;
157
158 etp_worker wrk_first;
159};
160
161#define ETP_WORKER_LOCK(wrk) X_LOCK (pool->wrklock)
162#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (pool->wrklock)
163
164/* worker threads management */
165
166static void
167etp_worker_clear (etp_worker *wrk)
168{
169}
170
171static void ecb_cold
172etp_worker_free (etp_worker *wrk)
173{
174 free (wrk->tmpbuf.ptr);
175
176 wrk->next->prev = wrk->prev;
177 wrk->prev->next = wrk->next;
178
179 free (wrk);
180}
181
182ETP_API_DECL unsigned int
183etp_nreqs (etp_pool pool)
184{
185 int retval;
186 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
187 retval = pool->nreqs;
188 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
189 return retval;
190}
191
192ETP_API_DECL unsigned int
193etp_nready (etp_pool pool)
194{
195 unsigned int retval;
196
197 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
198 retval = pool->nready;
199 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
200
201 return retval;
202}
203
204ETP_API_DECL unsigned int
205etp_npending (etp_pool pool)
206{
207 unsigned int retval;
208
209 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
210 retval = pool->npending;
211 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
212
213 return retval;
214}
215
216ETP_API_DECL unsigned int
217etp_nthreads (etp_pool pool)
218{
219 unsigned int retval;
220
221 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
222 retval = pool->started;
223 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
224
225 return retval;
226}
201 227
202static void ecb_noinline ecb_cold 228static void ecb_noinline ecb_cold
203reqq_init (etp_reqq *q) 229reqq_init (etp_reqq *q)
204{ 230{
205 int pri; 231 int pri;
252 278
253 abort (); 279 abort ();
254} 280}
255 281
256ETP_API_DECL int ecb_cold 282ETP_API_DECL int ecb_cold
257etp_init (void (*want_poll)(void), void (*done_poll)(void)) 283etp_init (etp_pool pool, void *userdata, void (*want_poll)(void *userdata), void (*done_poll)(void *userdata))
258{ 284{
259 X_MUTEX_CREATE (wrklock); 285 X_MUTEX_CREATE (pool->wrklock);
260 X_MUTEX_CREATE (reslock); 286 X_MUTEX_CREATE (pool->reslock);
261 X_MUTEX_CREATE (reqlock); 287 X_MUTEX_CREATE (pool->reqlock);
262 X_COND_CREATE (reqwait); 288 X_COND_CREATE (pool->reqwait);
263 289
264 reqq_init (&req_queue); 290 reqq_init (&pool->req_queue);
265 reqq_init (&res_queue); 291 reqq_init (&pool->res_queue);
266 292
267 wrk_first.next = 293 pool->wrk_first.next =
268 wrk_first.prev = &wrk_first; 294 pool->wrk_first.prev = &pool->wrk_first;
269 295
270 started = 0; 296 pool->started = 0;
271 idle = 0; 297 pool->idle = 0;
272 nreqs = 0; 298 pool->nreqs = 0;
273 nready = 0; 299 pool->nready = 0;
274 npending = 0; 300 pool->npending = 0;
301 pool->wanted = 4;
275 302
303 pool->max_idle = 4; /* maximum number of threads that can pool->idle indefinitely */
304 pool->idle_timeout = 10; /* number of seconds after which an pool->idle threads exit */
305
306 pool->userdata = userdata;
276 want_poll_cb = want_poll; 307 pool->want_poll_cb = want_poll;
277 done_poll_cb = done_poll; 308 pool->done_poll_cb = done_poll;
278 309
279 return 0; 310 return 0;
280} 311}
281 312
282/* not yet in etp.c */ 313static void ecb_noinline ecb_cold
314etp_proc_init (void)
315{
316#if HAVE_PRCTL_SET_NAME
317 /* provide a more sensible "thread name" */
318 char name[16 + 1];
319 const int namelen = sizeof (name) - 1;
320 int len;
321
322 prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0);
323 name [namelen] = 0;
324 len = strlen (name);
325 strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio");
326 prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0);
327#endif
328}
329
283X_THREAD_PROC (etp_proc); 330X_THREAD_PROC (etp_proc)
331{
332 ETP_REQ *req;
333 struct timespec ts;
334 etp_worker *self = (etp_worker *)thr_arg;
335 etp_pool pool = self->pool;
336
337 etp_proc_init ();
338
339 /* try to distribute timeouts somewhat evenly */
340 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
341
342 for (;;)
343 {
344 ts.tv_sec = 0;
345
346 X_LOCK (pool->reqlock);
347
348 for (;;)
349 {
350 req = reqq_shift (&pool->req_queue);
351
352 if (ecb_expect_true (req))
353 break;
354
355 if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */
356 {
357 X_UNLOCK (pool->reqlock);
358 X_LOCK (pool->wrklock);
359 --pool->started;
360 X_UNLOCK (pool->wrklock);
361 goto quit;
362 }
363
364 ++pool->idle;
365
366 if (pool->idle <= pool->max_idle)
367 /* we are allowed to pool->idle, so do so without any timeout */
368 X_COND_WAIT (pool->reqwait, pool->reqlock);
369 else
370 {
371 /* initialise timeout once */
372 if (!ts.tv_sec)
373 ts.tv_sec = time (0) + pool->idle_timeout;
374
375 if (X_COND_TIMEDWAIT (pool->reqwait, pool->reqlock, ts) == ETIMEDOUT)
376 ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */
377 }
378
379 --pool->idle;
380 }
381
382 --pool->nready;
383
384 X_UNLOCK (pool->reqlock);
385
386 if (ecb_expect_false (req->type == ETP_TYPE_QUIT))
387 goto quit;
388
389 ETP_EXECUTE (self, req);
390
391 X_LOCK (pool->reslock);
392
393 ++pool->npending;
394
395 if (!reqq_push (&pool->res_queue, req))
396 ETP_WANT_POLL (pool);
397
398 etp_worker_clear (self);
399
400 X_UNLOCK (pool->reslock);
401 }
402
403quit:
404 free (req);
405
406 X_LOCK (pool->wrklock);
407 etp_worker_free (self);
408 X_UNLOCK (pool->wrklock);
409
410 return 0;
411}
284 412
285static void ecb_cold 413static void ecb_cold
286etp_start_thread (void) 414etp_start_thread (etp_pool pool)
287{ 415{
288 etp_worker *wrk = calloc (1, sizeof (etp_worker)); 416 etp_worker *wrk = calloc (1, sizeof (etp_worker));
289 417
290 /*TODO*/ 418 /*TODO*/
291 assert (("unable to allocate worker thread data", wrk)); 419 assert (("unable to allocate worker thread data", wrk));
292 420
421 wrk->pool = pool;
422
293 X_LOCK (wrklock); 423 X_LOCK (pool->wrklock);
294 424
295 if (xthread_create (&wrk->tid, etp_proc, (void *)wrk)) 425 if (xthread_create (&wrk->tid, etp_proc, (void *)wrk))
296 { 426 {
297 wrk->prev = &wrk_first; 427 wrk->prev = &pool->wrk_first;
298 wrk->next = wrk_first.next; 428 wrk->next = pool->wrk_first.next;
299 wrk_first.next->prev = wrk; 429 pool->wrk_first.next->prev = wrk;
300 wrk_first.next = wrk; 430 pool->wrk_first.next = wrk;
301 ++started; 431 ++pool->started;
302 } 432 }
303 else 433 else
304 free (wrk); 434 free (wrk);
305 435
306 X_UNLOCK (wrklock); 436 X_UNLOCK (pool->wrklock);
307} 437}
308 438
309static void 439static void
310etp_maybe_start_thread (void) 440etp_maybe_start_thread (etp_pool pool)
311{ 441{
312 if (ecb_expect_true (etp_nthreads () >= wanted)) 442 if (ecb_expect_true (etp_nthreads (pool) >= pool->wanted))
313 return; 443 return;
314 444
315 /* todo: maybe use idle here, but might be less exact */ 445 /* todo: maybe use pool->idle here, but might be less exact */
316 if (ecb_expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ())) 446 if (ecb_expect_true (0 <= (int)etp_nthreads (pool) + (int)etp_npending (pool) - (int)etp_nreqs (pool)))
317 return; 447 return;
318 448
319 etp_start_thread (); 449 etp_start_thread (pool);
320} 450}
321 451
322static void ecb_cold 452static void ecb_cold
323etp_end_thread (void) 453etp_end_thread (etp_pool pool)
324{ 454{
325 ETP_REQ *req = calloc (1, sizeof (ETP_REQ)); /* will be freed by worker */ 455 ETP_REQ *req = calloc (1, sizeof (ETP_REQ)); /* will be freed by worker */
326 456
327 req->type = ETP_TYPE_QUIT; 457 req->type = ETP_TYPE_QUIT;
328 req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 458 req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
329 459
330 X_LOCK (reqlock); 460 X_LOCK (pool->reqlock);
331 reqq_push (&req_queue, req); 461 reqq_push (&pool->req_queue, req);
332 X_COND_SIGNAL (reqwait); 462 X_COND_SIGNAL (pool->reqwait);
333 X_UNLOCK (reqlock); 463 X_UNLOCK (pool->reqlock);
334 464
335 X_LOCK (wrklock); 465 X_LOCK (pool->wrklock);
336 --started; 466 --pool->started;
337 X_UNLOCK (wrklock); 467 X_UNLOCK (pool->wrklock);
338} 468}
339 469
340ETP_API_DECL int 470ETP_API_DECL int
341etp_poll (void) 471etp_poll (etp_pool pool)
342{ 472{
343 unsigned int maxreqs; 473 unsigned int maxreqs;
344 unsigned int maxtime; 474 unsigned int maxtime;
345 struct timeval tv_start, tv_now; 475 struct timeval tv_start, tv_now;
346 476
347 X_LOCK (reslock); 477 X_LOCK (pool->reslock);
348 maxreqs = max_poll_reqs; 478 maxreqs = pool->max_poll_reqs;
349 maxtime = max_poll_time; 479 maxtime = pool->max_poll_time;
350 X_UNLOCK (reslock); 480 X_UNLOCK (pool->reslock);
351 481
352 if (maxtime) 482 if (maxtime)
353 gettimeofday (&tv_start, 0); 483 gettimeofday (&tv_start, 0);
354 484
355 for (;;) 485 for (;;)
356 { 486 {
357 ETP_REQ *req; 487 ETP_REQ *req;
358 488
359 etp_maybe_start_thread (); 489 etp_maybe_start_thread (pool);
360 490
361 X_LOCK (reslock); 491 X_LOCK (pool->reslock);
362 req = reqq_shift (&res_queue); 492 req = reqq_shift (&pool->res_queue);
363 493
364 if (req) 494 if (ecb_expect_true (req))
365 { 495 {
366 --npending; 496 --pool->npending;
367 497
368 if (!res_queue.size && done_poll_cb) 498 if (!pool->res_queue.size)
369 done_poll_cb (); 499 ETP_DONE_POLL (pool);
370 } 500 }
371 501
372 X_UNLOCK (reslock); 502 X_UNLOCK (pool->reslock);
373 503
374 if (!req) 504 if (ecb_expect_false (!req))
375 return 0; 505 return 0;
376 506
377 X_LOCK (reqlock); 507 X_LOCK (pool->reqlock);
378 --nreqs; 508 --pool->nreqs;
379 X_UNLOCK (reqlock); 509 X_UNLOCK (pool->reqlock);
380 510
381 if (ecb_expect_false (req->type == ETP_TYPE_GROUP && req->size)) 511 if (ecb_expect_false (req->type == ETP_TYPE_GROUP && req->size))
382 { 512 {
383 req->int1 = 1; /* mark request as delayed */ 513 req->flags |= ETP_FLAG_DELAYED; /* mark request as delayed */
384 continue; 514 continue;
385 } 515 }
386 else 516 else
387 { 517 {
388 int res = ETP_FINISH (req); 518 int res = ETP_FINISH (req);
405 errno = EAGAIN; 535 errno = EAGAIN;
406 return -1; 536 return -1;
407} 537}
408 538
409ETP_API_DECL void 539ETP_API_DECL void
410etp_grp_cancel (ETP_REQ *grp); 540etp_grp_cancel (etp_pool pool, ETP_REQ *grp);
411 541
412ETP_API_DECL void 542ETP_API_DECL void
413etp_cancel (ETP_REQ *req) 543etp_cancel (etp_pool pool, ETP_REQ *req)
414{ 544{
415 req->cancelled = 1; 545 req->cancelled = 1;
416 546
417 etp_grp_cancel (req); 547 etp_grp_cancel (pool, req);
418} 548}
419 549
420ETP_API_DECL void 550ETP_API_DECL void
421etp_grp_cancel (ETP_REQ *grp) 551etp_grp_cancel (etp_pool pool, ETP_REQ *grp)
422{ 552{
423 for (grp = grp->grp_first; grp; grp = grp->grp_next) 553 for (grp = grp->grp_first; grp; grp = grp->grp_next)
424 etp_cancel (grp); 554 etp_cancel (pool, grp);
425} 555}
426 556
427ETP_API_DECL void 557ETP_API_DECL void
428etp_submit (ETP_REQ *req) 558etp_submit (etp_pool pool, ETP_REQ *req)
429{ 559{
430 req->pri -= ETP_PRI_MIN; 560 req->pri -= ETP_PRI_MIN;
431 561
432 if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; 562 if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN;
433 if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 563 if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
434 564
435 if (ecb_expect_false (req->type == ETP_TYPE_GROUP)) 565 if (ecb_expect_false (req->type == ETP_TYPE_GROUP))
436 { 566 {
437 /* I hope this is worth it :/ */ 567 /* I hope this is worth it :/ */
438 X_LOCK (reqlock); 568 X_LOCK (pool->reqlock);
439 ++nreqs; 569 ++pool->nreqs;
440 X_UNLOCK (reqlock); 570 X_UNLOCK (pool->reqlock);
441 571
442 X_LOCK (reslock); 572 X_LOCK (pool->reslock);
443 573
444 ++npending; 574 ++pool->npending;
445 575
446 if (!reqq_push (&res_queue, req) && want_poll_cb) 576 if (!reqq_push (&pool->res_queue, req))
447 want_poll_cb (); 577 ETP_WANT_POLL (pool);
448 578
449 X_UNLOCK (reslock); 579 X_UNLOCK (pool->reslock);
450 } 580 }
451 else 581 else
452 { 582 {
453 X_LOCK (reqlock); 583 X_LOCK (pool->reqlock);
454 ++nreqs; 584 ++pool->nreqs;
455 ++nready; 585 ++pool->nready;
456 reqq_push (&req_queue, req); 586 reqq_push (&pool->req_queue, req);
457 X_COND_SIGNAL (reqwait); 587 X_COND_SIGNAL (pool->reqwait);
458 X_UNLOCK (reqlock); 588 X_UNLOCK (pool->reqlock);
459 589
460 etp_maybe_start_thread (); 590 etp_maybe_start_thread (pool);
461 } 591 }
462} 592}
463 593
464ETP_API_DECL void ecb_cold 594ETP_API_DECL void ecb_cold
465etp_set_max_poll_time (double nseconds) 595etp_set_max_poll_time (etp_pool pool, double seconds)
466{ 596{
467 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 597 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock);
468 max_poll_time = nseconds * ETP_TICKS; 598 pool->max_poll_time = seconds * ETP_TICKS;
469 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 599 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
470} 600}
471 601
472ETP_API_DECL void ecb_cold 602ETP_API_DECL void ecb_cold
473etp_set_max_poll_reqs (unsigned int maxreqs) 603etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs)
474{ 604{
475 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 605 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock);
476 max_poll_reqs = maxreqs; 606 pool->max_poll_reqs = maxreqs;
477 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 607 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
478} 608}
479 609
480ETP_API_DECL void ecb_cold 610ETP_API_DECL void ecb_cold
481etp_set_max_idle (unsigned int nthreads) 611etp_set_max_idle (etp_pool pool, unsigned int threads)
482{ 612{
483 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 613 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
484 max_idle = nthreads; 614 pool->max_idle = threads;
485 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 615 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
486} 616}
487 617
488ETP_API_DECL void ecb_cold 618ETP_API_DECL void ecb_cold
489etp_set_idle_timeout (unsigned int seconds) 619etp_set_idle_timeout (etp_pool pool, unsigned int seconds)
490{ 620{
491 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 621 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
492 idle_timeout = seconds; 622 pool->idle_timeout = seconds;
493 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 623 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
494} 624}
495 625
496ETP_API_DECL void ecb_cold 626ETP_API_DECL void ecb_cold
497etp_set_min_parallel (unsigned int nthreads) 627etp_set_min_parallel (etp_pool pool, unsigned int threads)
498{ 628{
499 if (wanted < nthreads) 629 if (pool->wanted < threads)
500 wanted = nthreads; 630 pool->wanted = threads;
501} 631}
502 632
503ETP_API_DECL void ecb_cold 633ETP_API_DECL void ecb_cold
504etp_set_max_parallel (unsigned int nthreads) 634etp_set_max_parallel (etp_pool pool, unsigned int threads)
505{ 635{
506 if (wanted > nthreads) 636 if (pool->wanted > threads)
507 wanted = nthreads; 637 pool->wanted = threads;
508 638
509 while (started > wanted) 639 while (pool->started > pool->wanted)
510 etp_end_thread (); 640 etp_end_thread (pool);
511} 641}
512 642

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines