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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines