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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines