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

Comparing libeio/etp.c (file contents):
Revision 1.8 by root, Thu Jun 25 18:14:19 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
343 347
344 for (;;) 348 for (;;)
345 { 349 {
346 req = reqq_shift (&pool->req_queue); 350 req = reqq_shift (&pool->req_queue);
347 351
348 if (req) 352 if (ecb_expect_true (req))
349 break; 353 break;
350 354
351 if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ 355 if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */
352 { 356 {
353 X_UNLOCK (pool->reqlock); 357 X_UNLOCK (pool->reqlock);
377 381
378 --pool->nready; 382 --pool->nready;
379 383
380 X_UNLOCK (pool->reqlock); 384 X_UNLOCK (pool->reqlock);
381 385
382 if (req->type == ETP_TYPE_QUIT) 386 if (ecb_expect_false (req->type == ETP_TYPE_QUIT))
383 goto quit; 387 goto quit;
384 388
385 ETP_EXECUTE (self, req); 389 ETP_EXECUTE (self, req);
386 390
387 X_LOCK (pool->reslock); 391 X_LOCK (pool->reslock);
388 392
389 ++pool->npending; 393 ++pool->npending;
390 394
391 if (!reqq_push (&pool->res_queue, req)) 395 if (!reqq_push (&pool->res_queue, req))
392 ETP_WANT_POLL (poll); 396 ETP_WANT_POLL (pool);
393 397
394 etp_worker_clear (self); 398 etp_worker_clear (self);
395 399
396 X_UNLOCK (pool->reslock); 400 X_UNLOCK (pool->reslock);
397 } 401 }
485 etp_maybe_start_thread (pool); 489 etp_maybe_start_thread (pool);
486 490
487 X_LOCK (pool->reslock); 491 X_LOCK (pool->reslock);
488 req = reqq_shift (&pool->res_queue); 492 req = reqq_shift (&pool->res_queue);
489 493
490 if (req) 494 if (ecb_expect_true (req))
491 { 495 {
492 --pool->npending; 496 --pool->npending;
493 497
494 if (!pool->res_queue.size) 498 if (!pool->res_queue.size)
495 ETP_DONE_POLL (pool->userdata); 499 ETP_DONE_POLL (pool);
496 } 500 }
497 501
498 X_UNLOCK (pool->reslock); 502 X_UNLOCK (pool->reslock);
499 503
500 if (!req) 504 if (ecb_expect_false (!req))
501 return 0; 505 return 0;
502 506
503 X_LOCK (pool->reqlock); 507 X_LOCK (pool->reqlock);
504 --pool->nreqs; 508 --pool->nreqs;
505 X_UNLOCK (pool->reqlock); 509 X_UNLOCK (pool->reqlock);
586 etp_maybe_start_thread (pool); 590 etp_maybe_start_thread (pool);
587 } 591 }
588} 592}
589 593
590ETP_API_DECL void ecb_cold 594ETP_API_DECL void ecb_cold
591etp_set_max_poll_time (etp_pool pool, double nseconds) 595etp_set_max_poll_time (etp_pool pool, double seconds)
592{ 596{
593 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock); 597 if (WORDACCESS_UNSAFE) X_LOCK (pool->reslock);
594 pool->max_poll_time = nseconds * ETP_TICKS; 598 pool->max_poll_time = seconds * ETP_TICKS;
595 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock); 599 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
596} 600}
597 601
598ETP_API_DECL void ecb_cold 602ETP_API_DECL void ecb_cold
599etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs) 603etp_set_max_poll_reqs (etp_pool pool, unsigned int maxreqs)
602 pool->max_poll_reqs = maxreqs; 606 pool->max_poll_reqs = maxreqs;
603 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock); 607 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reslock);
604} 608}
605 609
606ETP_API_DECL void ecb_cold 610ETP_API_DECL void ecb_cold
607etp_set_max_idle (etp_pool pool, unsigned int nthreads) 611etp_set_max_idle (etp_pool pool, unsigned int threads)
608{ 612{
609 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock); 613 if (WORDACCESS_UNSAFE) X_LOCK (pool->reqlock);
610 pool->max_idle = nthreads; 614 pool->max_idle = threads;
611 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock); 615 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
612} 616}
613 617
614ETP_API_DECL void ecb_cold 618ETP_API_DECL void ecb_cold
615etp_set_idle_timeout (etp_pool pool, unsigned int seconds) 619etp_set_idle_timeout (etp_pool pool, unsigned int seconds)
618 pool->idle_timeout = seconds; 622 pool->idle_timeout = seconds;
619 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock); 623 if (WORDACCESS_UNSAFE) X_UNLOCK (pool->reqlock);
620} 624}
621 625
622ETP_API_DECL void ecb_cold 626ETP_API_DECL void ecb_cold
623etp_set_min_parallel (etp_pool pool, unsigned int nthreads) 627etp_set_min_parallel (etp_pool pool, unsigned int threads)
624{ 628{
625 if (pool->wanted < nthreads) 629 if (pool->wanted < threads)
626 pool->wanted = nthreads; 630 pool->wanted = threads;
627} 631}
628 632
629ETP_API_DECL void ecb_cold 633ETP_API_DECL void ecb_cold
630etp_set_max_parallel (etp_pool pool, unsigned int nthreads) 634etp_set_max_parallel (etp_pool pool, unsigned int threads)
631{ 635{
632 if (pool->wanted > nthreads) 636 if (pool->wanted > threads)
633 pool->wanted = nthreads; 637 pool->wanted = threads;
634 638
635 while (pool->started > pool->wanted) 639 while (pool->started > pool->wanted)
636 etp_end_thread (pool); 640 etp_end_thread (pool);
637} 641}
638 642

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines