libeio/etp.c

filter: Statementstmt 73.6% 176 / 239 Branchbran 68.0% 49 / 72 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 72.3% 225 / 311 SCAR 0
CC
0
Cov
0%
CRAP 0
« schmorp.h ↑ Summary libeio/xthread.h »
1 /*
2 * libetp implementation
3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2015 Marc Alexander Lehmann <libetp@schmorp.de>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26 * OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU General Public License ("GPL") version 2 or any later version,
30 * in which case the provisions of the GPL are applicable instead of
31 * the above. If you wish to allow the use of your version of this file
32 * only under the terms of the GPL and not to allow others to use your
33 * version of this file under the BSD license, indicate your decision
34 * by deleting the provisions above and replace them with the notice
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
37 * either the BSD or the GPL.
38 */
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  
49 #ifndef ETP_API_DECL
50 # define ETP_API_DECL static
51 #endif
52  
53 #ifndef ETP_PRI_MIN
54 # define ETP_PRI_MIN 0
55 # define ETP_PRI_MAX 0
56 #endif
57  
58 #ifndef ETP_TYPE_QUIT
59 # define ETP_TYPE_QUIT 0
60 #endif
61  
62 #ifndef ETP_TYPE_GROUP
63 # define ETP_TYPE_GROUP 1
64 #endif
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  
73 #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
74  
75 #define ETP_TICKS ((1000000 + 1023) >> 10)
76  
77 enum {
78 ETP_FLAG_GROUPADD = 0x04, /* some request was added to the group */
79 ETP_FLAG_DELAYED = 0x08, /* groiup request has been delayed */
80 };
81  
82 /* calculate time difference in ~1/ETP_TICKS of a second */
83 ecb_inline int
84 0 etp_tvdiff (struct timeval *tv1, struct timeval *tv2)
85 {
86 0 return (tv2->tv_sec - tv1->tv_sec ) * ETP_TICKS
87 0 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
88 }
89  
90 struct etp_tmpbuf
91 {
92 void *ptr;
93 int len;
94 };
95  
96 static void *
97 1 etp_tmpbuf_get (struct etp_tmpbuf *buf, int len)
98 {
99 1 ▶ if (buf->len < len)
Branch: 1 branch
BranchTrueFalseTotal
if (buf->len < len) 1 0 1
100 {
101 1 free (buf->ptr);
102 1 buf->ptr = malloc (buf->len = len);
103 }
104  
105 1 return buf->ptr;
106 }
107  
108 /*
109 * a somewhat faster data structure might be nice, but
110 * with 8 priorities this actually needs <20 insns
111 * per shift, the most expensive operation.
112 */
113 typedef struct
114 {
115 ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */
116 int size;
117 } etp_reqq;
118  
119 typedef struct etp_pool *etp_pool;
120  
121 typedef 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  
137 struct etp_pool
138 {
139 void *userdata;
140  
141 etp_reqq req_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  
171 static void
172 57 etp_worker_clear (etp_worker *wrk)
173 {
174 57 }
175  
176 static void ecb_cold
177 0 etp_worker_free (etp_worker *wrk)
178 {
179 0 free (wrk->tmpbuf.ptr);
180  
181 0 wrk->next->prev = wrk->prev;
182 0 wrk->prev->next = wrk->next;
183  
184 0 free (wrk);
185 0 }
186  
187 ETP_API_DECL unsigned int
188 256 etp_nreqs (etp_pool pool)
189 {
190 int retval;
191 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
192 256 retval = pool->nreqs;
193 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
194 256 return retval;
195 }
196  
197 ETP_API_DECL unsigned int
198 0 etp_nready (etp_pool pool)
199 {
200 unsigned int retval;
201  
202 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
203 0 retval = pool->nready;
204 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
205  
206 0 return retval;
207 }
208  
209 ETP_API_DECL unsigned int
210 152 etp_npending (etp_pool pool)
211 {
212 unsigned int retval;
213  
214 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
215 152 retval = pool->npending;
216 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
217  
218 152 return retval;
219 }
220  
221 ETP_API_DECL unsigned int
222 306 etp_nthreads (etp_pool pool)
223 {
224 unsigned int retval;
225  
226 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
227 306 retval = pool->started;
228 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
229  
230 306 return retval;
231 }
232  
233 static void ecb_noinline ecb_cold
234 20 reqq_init (etp_reqq *q)
235 {
236 int pri;
237  
238 200 ▶ for (pri = 0; pri < ETP_NUM_PRI; ++pri)
Branch: 1 branch
BranchTrueFalseTotal
for (pri = 0; pri < ETP_NUM_PRI; ++pri) 180 20 200
239 180 q->qs[pri] = q->qe[pri] = 0;
240  
241 20 q->size = 0;
242 20 }
243  
244 static int ecb_noinline
245 122 reqq_push (etp_reqq *q, ETP_REQ *req)
246 {
247 122 int pri = req->pri;
248 122 req->next = 0;
249  
250 122 ▶ if (q->qe[pri])
Branch: 1 branch
BranchTrueFalseTotal
if (q->qe[pri]) 24 98 122
251 {
252 24 q->qe[pri]->next = req;
253 24 q->qe[pri] = req;
254 }
255 else
256 98 q->qe[pri] = q->qs[pri] = req;
257  
258 122 return q->size++;
259 }
260  
261 static ETP_REQ * ecb_noinline
262 191 reqq_shift (etp_reqq *q)
263 {
264 int pri;
265  
266 191 ▶ if (!q->size)
Branch: 1 branch
BranchTrueFalseTotal
if (!q->size) 89 102 191
267 89 return 0;
268  
269 102 --q->size;
270  
271 374 ▶ for (pri = ETP_NUM_PRI; pri--; )
Branch: 1 branch
BranchTrueFalseTotal
for (pri = ETP_NUM_PRI; pri--; ) 374 0 374
272 {
273 374 ETP_REQ *req = q->qs[pri];
274  
275 374 ▶ if (req)
Branch: 1 branch
BranchTrueFalseTotal
if (req) 102 272 374
276 {
277 102 ▶ if (!(q->qs[pri] = (ETP_REQ *)req->next))
Branch: 1 branch
BranchTrueFalseTotal
if (!(q->qs[pri] = (ETP_REQ *)req->next)) 88 14 102
278 88 q->qe[pri] = 0;
279  
280 102 return req;
281 }
282 }
283  
284 0 abort ();
285 }
286  
287 ETP_API_DECL int ecb_cold
288 10 etp_init (etp_pool pool, void *userdata, void (*want_poll)(void *userdata), void (*done_poll)(void *userdata))
289 {
290 10 X_MUTEX_CREATE (pool->wrklock);
291 10 X_MUTEX_CREATE (pool->reslock);
292 10 X_MUTEX_CREATE (pool->reqlock);
293 10 X_COND_CREATE (pool->reqwait);
294  
295 10 reqq_init (&pool->req_queue);
296 10 reqq_init (&pool->res_queue);
297  
298 10 pool->wrk_first.next =
299 10 pool->wrk_first.prev = &pool->wrk_first;
300  
301 10 pool->started = 0;
302 10 pool->idle = 0;
303 10 pool->nreqs = 0;
304 10 pool->nready = 0;
305 10 pool->npending = 0;
306 10 pool->wanted = 4;
307  
308 10 pool->max_idle = 4; /* maximum number of threads that can pool->idle indefinitely */
309 10 pool->idle_timeout = 10; /* number of seconds after which an pool->idle threads exit */
310  
311 10 pool->userdata = userdata;
312 10 pool->want_poll_cb = want_poll;
313 10 pool->done_poll_cb = done_poll;
314  
315 10 return 0;
316 }
317  
318 static void ecb_noinline ecb_cold
319 18 etp_proc_init (void)
320 {
321 #if HAVE_PRCTL_SET_NAME
322 /* provide a more sensible "thread name" */
323 char name[16 + 1];
324 18 const int namelen = sizeof (name) - 1;
325 int len;
326  
327 18 prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0);
328 18 name [namelen] = 0;
329 18 len = strlen (name);
330 18 strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio");
331 18 prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0);
332 #endif
333 18 }
334  
335 18 X_THREAD_PROC (etp_proc)
336 {
337 ETP_REQ *req;
338 struct timespec ts;
339 18 etp_worker *self = (etp_worker *)thr_arg;
340 18 etp_pool pool = self->pool;
341  
342 18 etp_proc_init ();
343  
344 /* try to distribute timeouts somewhat evenly */
345 18 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
346  
347 for (;;)
348 {
349 75 ts.tv_sec = 0;
350  
351 75 X_LOCK (pool->reqlock);
352  
353 for (;;)
354 {
355 112 req = reqq_shift (&pool->req_queue);
356  
357 112 ▶ if (ecb_expect_true (req))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_true (req)) 58 54 112
358 58 break;
359  
360 54 ▶ if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */
Branch: 1 branch
BranchTrueFalseTotal
if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ 0 54 54
361 {
362 0 X_UNLOCK (pool->reqlock);
363 0 X_LOCK (pool->wrklock);
364 0 --pool->started;
365 0 X_UNLOCK (pool->wrklock);
366 0 goto quit;
367 }
368  
369 54 ++pool->idle;
370  
371 54 ▶ if (pool->idle <= pool->max_idle)
Branch: 1 branch
BranchTrueFalseTotal
if (pool->idle <= pool->max_idle) 54 0 54
372 /* we are allowed to pool->idle, so do so without any timeout */
373 54 X_COND_WAIT (pool->reqwait, pool->reqlock);
374 else
375 {
376 /* initialise timeout once */
377 0 ▶ if (!ts.tv_sec)
Branch: 1 branch
BranchTrueFalseTotal
if (!ts.tv_sec) 0 0 0
378 0 ts.tv_sec = time (0) + pool->idle_timeout;
379  
380 0 ▶ if (X_COND_TIMEDWAIT (pool->reqwait, pool->reqlock, ts) == ETIMEDOUT)
Branch: 1 branch
BranchTrueFalseTotal
if (X_COND_TIMEDWAIT (pool->reqwait, pool->reqlock, ts) == ETIMEDOUT) 0 0 0
381 0 ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */
382 }
383  
384 37 --pool->idle;
385 }
386  
387 58 --pool->nready;
388  
389 58 X_UNLOCK (pool->reqlock);
390
391 58 ▶ if (ecb_expect_false (req->type == ETP_TYPE_QUIT))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (req->type == ETP_TYPE_QUIT)) 0 58 58
392 0 goto quit;
393  
394 58 ETP_EXECUTE (self, req);
395  
396 57 X_LOCK (pool->reslock);
397  
398 57 ++pool->npending;
399  
400 57 ▶ if (!reqq_push (&pool->res_queue, req))
Branch: 1 branch
BranchTrueFalseTotal
if (!reqq_push (&pool->res_queue, req)) 39 18 57
401 39 ETP_WANT_POLL (pool);
402  
403 57 etp_worker_clear (self);
404  
405 57 X_UNLOCK (pool->reslock);
406 }
407  
408 0 quit:
409 0 free (req);
410  
411 0 X_LOCK (pool->wrklock);
412 0 etp_worker_free (self);
413 0 X_UNLOCK (pool->wrklock);
414  
415 0 return 0;
416 }
417  
418 static void ecb_cold
419 18 etp_start_thread (etp_pool pool)
420 {
421 18 etp_worker *wrk = calloc (1, sizeof (etp_worker));
422  
423 /*TODO*/
424 assert (("unable to allocate worker thread data", wrk));
425  
426 18 wrk->pool = pool;
427  
428 18 X_LOCK (pool->wrklock);
429  
430 18 ▶ if (xthread_create (&wrk->tid, etp_proc, (void *)wrk))
Branch: 1 branch
BranchTrueFalseTotal
if (xthread_create (&wrk->tid, etp_proc, (void *)wrk)) 18 0 18
431 {
432 18 wrk->prev = &pool->wrk_first;
433 18 wrk->next = pool->wrk_first.next;
434 18 pool->wrk_first.next->prev = wrk;
435 18 pool->wrk_first.next = wrk;
436 18 ++pool->started;
437 }
438 else
439 0 free (wrk);
440  
441 18 X_UNLOCK (pool->wrklock);
442 18 }
443  
444 static void
445 154 etp_maybe_start_thread (etp_pool pool)
446 {
447 154 ▶ if (ecb_expect_true (etp_nthreads (pool) >= pool->wanted))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_true (etp_nthreads (pool) >= pool->wanted)) 2 152 154
448 2 return;
449
450 /* todo: maybe use pool->idle here, but might be less exact */
451 152 ▶ if (ecb_expect_true (0 <= (int)etp_nthreads (pool) + (int)etp_npending (pool) - (int)etp_nreqs (pool)))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_true (0 <= (int)etp_nthreads (pool) + (int)etp_npending (pool) - (int)etp_nreqs (pool))) 134 18 152
452 134 return;
453  
454 18 etp_start_thread (pool);
455 }
456  
457 static void ecb_cold
458 0 etp_end_thread (etp_pool pool)
459 {
460 0 ETP_REQ *req = calloc (1, sizeof (ETP_REQ)); /* will be freed by worker */
461  
462 0 req->type = ETP_TYPE_QUIT;
463 0 req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
464  
465 0 X_LOCK (pool->reqlock);
466 0 reqq_push (&pool->req_queue, req);
467 0 X_COND_SIGNAL (pool->reqwait);
468 0 X_UNLOCK (pool->reqlock);
469  
470 0 X_LOCK (pool->wrklock);
471 0 --pool->started;
472 0 X_UNLOCK (pool->wrklock);
473 0 }
474  
475 ETP_API_DECL int
476 35 etp_poll (etp_pool pool)
477 {
478 unsigned int maxreqs;
479 unsigned int maxtime;
480 struct timeval tv_start, tv_now;
481  
482 35 X_LOCK (pool->reslock);
483 35 maxreqs = pool->max_poll_reqs;
484 35 maxtime = pool->max_poll_time;
485 35 X_UNLOCK (pool->reslock);
486  
487 35 ▶ if (maxtime)
Branch: 1 branch
BranchTrueFalseTotal
if (maxtime) 0 35 35
488 0 gettimeofday (&tv_start, 0);
489  
490 for (;;)
491 45 {
492 ETP_REQ *req;
493  
494 80 etp_maybe_start_thread (pool);
495  
496 80 X_LOCK (pool->reslock);
497 80 req = reqq_shift (&pool->res_queue);
498  
499 80 ▶ if (ecb_expect_true (req))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_true (req)) 45 35 80
500 {
501 45 --pool->npending;
502  
503 45 ▶ if (!pool->res_queue.size)
Branch: 1 branch
BranchTrueFalseTotal
if (!pool->res_queue.size) 35 10 45
504 35 ETP_DONE_POLL (pool);
505 }
506  
507 80 X_UNLOCK (pool->reslock);
508  
509 80 ▶ if (ecb_expect_false (!req))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (!req)) 35 45 80
510 35 return 0;
511  
512 45 X_LOCK (pool->reqlock);
513 45 --pool->nreqs;
514 45 X_UNLOCK (pool->reqlock);
515  
516 45 ▶ if (ecb_expect_false (req->type == ETP_TYPE_GROUP && req->size))
Branch: 2 branches
BranchTrueFalseTotal
if (ecb_expect_false (req->type == ETP_TYPE_GROUP && req->size)) 5 40 45
if (ecb_expect_false (req->type == ETP_TYPE_GROUP && req->size)) 3 2 5
517 {
518 3 req->flags |= ETP_FLAG_DELAYED; /* mark request as delayed */
519 3 continue;
520 }
521 else
522 {
523 42 int res = ETP_FINISH (req);
524 42 ▶ if (ecb_expect_false (res))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (res)) 0 42 42
525 0 return res;
526 }
527  
528 42 ▶ if (ecb_expect_false (maxreqs && !--maxreqs))
Branch: 2 branches
BranchTrueFalseTotal
if (ecb_expect_false (maxreqs && !--maxreqs)) 0 42 42
if (ecb_expect_false (maxreqs && !--maxreqs)) 0 0 0
529 0 break;
530  
531 42 ▶ if (maxtime)
Branch: 1 branch
BranchTrueFalseTotal
if (maxtime) 0 42 42
532 {
533 0 gettimeofday (&tv_now, 0);
534  
535 0 ▶ if (etp_tvdiff (&tv_start, &tv_now) >= maxtime)
Branch: 1 branch
BranchTrueFalseTotal
if (etp_tvdiff (&tv_start, &tv_now) >= maxtime) 0 0 0
536 0 break;
537 }
538 }
539  
540 0 errno = EAGAIN;
541 0 return -1;
542 }
543  
544 ETP_API_DECL void
545 etp_grp_cancel (etp_pool pool, ETP_REQ *grp);
546  
547 ETP_API_DECL void
548 3 etp_cancel (etp_pool pool, ETP_REQ *req)
549 {
550 3 req->cancelled = 1;
551  
552 3 etp_grp_cancel (pool, req);
553 3 }
554  
555 ETP_API_DECL void
556 3 etp_grp_cancel (etp_pool pool, ETP_REQ *grp)
557 {
558 4 ▶ for (grp = grp->grp_first; grp; grp = grp->grp_next)
Branch: 1 branch
BranchTrueFalseTotal
for (grp = grp->grp_first; grp; grp = grp->grp_next) 1 3 4
559 1 etp_cancel (pool, grp);
560 3 }
561  
562 ETP_API_DECL void
563 65 etp_submit (etp_pool pool, ETP_REQ *req)
564 {
565 65 req->pri -= ETP_PRI_MIN;
566  
567 65 ▶ if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN;
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; 0 65 65
568 65 ▶ if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 0 65 65
569  
570 65 ▶ if (ecb_expect_false (req->type == ETP_TYPE_GROUP))
Branch: 1 branch
BranchTrueFalseTotal
if (ecb_expect_false (req->type == ETP_TYPE_GROUP)) 5 60 65
571 {
572 /* I hope this is worth it :/ */
573 5 X_LOCK (pool->reqlock);
574 5 ++pool->nreqs;
575 5 X_UNLOCK (pool->reqlock);
576  
577 5 X_LOCK (pool->reslock);
578  
579 5 ++pool->npending;
580  
581 5 ▶ if (!reqq_push (&pool->res_queue, req))
Branch: 1 branch
BranchTrueFalseTotal
if (!reqq_push (&pool->res_queue, req)) 5 0 5
582 5 ETP_WANT_POLL (pool);
583  
584 5 X_UNLOCK (pool->reslock);
585 }
586 else
587 {
588 60 X_LOCK (pool->reqlock);
589 60 ++pool->nreqs;
590 60 ++pool->nready;
591 60 reqq_push (&pool->req_queue, req);
592 60 X_COND_SIGNAL (pool->reqwait);
593 60 X_UNLOCK (pool->reqlock);
594  
595 60 etp_maybe_start_thread (pool);
596 }
597 65 }
598  
599 ETP_API_DECL void ecb_cold
600 0 etp_set_max_poll_time (etp_pool pool, double seconds)
601 {
602 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock);
603 0 pool->max_poll_time = seconds * ETP_TICKS;
604 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
605 0 }
606  
607 ETP_API_DECL void ecb_cold
608 0 etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs)
609 {
610 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock);
611 0 pool->max_poll_reqs = maxreqs;
612 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
613 0 }
614  
615 ETP_API_DECL void ecb_cold
616 0 etp_set_max_idle (etp_pool pool, unsigned int threads)
617 {
618 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
619 0 pool->max_idle = threads;
620 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
621 0 }
622  
623 ETP_API_DECL void ecb_cold
624 0 etp_set_idle_timeout (etp_pool pool, unsigned int seconds)
625 {
626 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
627 0 pool->idle_timeout = seconds;
628 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
629 0 }
630  
631 ETP_API_DECL void ecb_cold
632 16 etp_set_min_parallel (etp_pool pool, unsigned int threads)
633 {
634 16 ▶ if (pool->wanted < threads)
Branch: 1 branch
BranchTrueFalseTotal
if (pool->wanted < threads) 10 6 16
635 10 pool->wanted = threads;
636 16 }
637  
638 ETP_API_DECL void ecb_cold
639 1 etp_set_max_parallel (etp_pool pool, unsigned int threads)
640 {
641 1 ▶ if (pool->wanted > threads)
Branch: 1 branch
BranchTrueFalseTotal
if (pool->wanted > threads) 1 0 1
642 1 pool->wanted = threads;
643  
644 1 ▶ while (pool->started > pool->wanted)
Branch: 1 branch
BranchTrueFalseTotal
while (pool->started > pool->wanted) 0 1 1
645 0 etp_end_thread (pool);
646 1 }
647  
« schmorp.h ↑ Summary libeio/xthread.h »