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

Comparing libeio/eio.c (file contents):
Revision 1.135 by root, Thu Jun 25 16:39:29 2015 UTC vs.
Revision 1.136 by root, Thu Jun 25 17:05:07 2015 UTC

384static void 384static void
385grp_try_feed (eio_req *grp) 385grp_try_feed (eio_req *grp)
386{ 386{
387 while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) 387 while (grp->size < grp->int2 && !EIO_CANCELLED (grp))
388 { 388 {
389 grp->flags &= ~EIO_FLAG_GROUPADD; 389 grp->flags &= ~ETP_FLAG_GROUPADD;
390 390
391 EIO_FEED (grp); 391 EIO_FEED (grp);
392 392
393 /* stop if no progress has been made */ 393 /* stop if no progress has been made */
394 if (!(grp->flags & EIO_FLAG_GROUPADD)) 394 if (!(grp->flags & ETP_FLAG_GROUPADD))
395 { 395 {
396 grp->feed = 0; 396 grp->feed = 0;
397 break; 397 break;
398 } 398 }
399 } 399 }
406 406
407 /* call feeder, if applicable */ 407 /* call feeder, if applicable */
408 grp_try_feed (grp); 408 grp_try_feed (grp);
409 409
410 /* finish, if done */ 410 /* finish, if done */
411 if (!grp->size && grp->int1) 411 if (!grp->size && grp->flags & ETP_FLAG_DELAYED)
412 return eio_finish (grp); 412 return eio_finish (grp);
413 else 413 else
414 return 0; 414 return 0;
415} 415}
416 416
1715 req->result = -1; \ 1715 req->result = -1; \
1716 break; \ 1716 break; \
1717 } \ 1717 } \
1718 } 1718 }
1719 1719
1720static void ecb_noinline ecb_cold
1721etp_proc_init (void)
1722{
1723#if HAVE_PRCTL_SET_NAME
1724 /* provide a more sensible "thread name" */
1725 char name[16 + 1];
1726 const int namelen = sizeof (name) - 1;
1727 int len;
1728
1729 prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0);
1730 name [namelen] = 0;
1731 len = strlen (name);
1732 strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio");
1733 prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0);
1734#endif
1735}
1736
1737/* TODO: move somehow to etp.c */
1738X_THREAD_PROC (etp_proc)
1739{
1740 ETP_REQ *req;
1741 struct timespec ts;
1742 etp_worker *self = (etp_worker *)thr_arg;
1743
1744 etp_proc_init ();
1745
1746 /* try to distribute timeouts somewhat evenly */
1747 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
1748
1749 for (;;)
1750 {
1751 ts.tv_sec = 0;
1752
1753 X_LOCK (reqlock);
1754
1755 for (;;)
1756 {
1757 req = reqq_shift (&req_queue);
1758
1759 if (req)
1760 break;
1761
1762 if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */
1763 {
1764 X_UNLOCK (reqlock);
1765 X_LOCK (wrklock);
1766 --started;
1767 X_UNLOCK (wrklock);
1768 goto quit;
1769 }
1770
1771 ++idle;
1772
1773 if (idle <= max_idle)
1774 /* we are allowed to idle, so do so without any timeout */
1775 X_COND_WAIT (reqwait, reqlock);
1776 else
1777 {
1778 /* initialise timeout once */
1779 if (!ts.tv_sec)
1780 ts.tv_sec = time (0) + idle_timeout;
1781
1782 if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT)
1783 ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */
1784 }
1785
1786 --idle;
1787 }
1788
1789 --nready;
1790
1791 X_UNLOCK (reqlock);
1792
1793 if (req->type == ETP_TYPE_QUIT)
1794 goto quit;
1795
1796 ETP_EXECUTE (self, req);
1797
1798 X_LOCK (reslock);
1799
1800 ++npending;
1801
1802 if (!reqq_push (&res_queue, req) && want_poll_cb)
1803 want_poll_cb ();
1804
1805 etp_worker_clear (self);
1806
1807 X_UNLOCK (reslock);
1808 }
1809
1810quit:
1811 free (req);
1812
1813 X_LOCK (wrklock);
1814 etp_worker_free (self);
1815 X_UNLOCK (wrklock);
1816
1817 return 0;
1818}
1819
1820/*****************************************************************************/ 1720/*****************************************************************************/
1821 1721
1822int ecb_cold 1722int ecb_cold
1823eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1723eio_init (void (*want_poll)(void), void (*done_poll)(void))
1824{ 1724{
2368void 2268void
2369eio_grp_add (eio_req *grp, eio_req *req) 2269eio_grp_add (eio_req *grp, eio_req *req)
2370{ 2270{
2371 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); 2271 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2));
2372 2272
2373 grp->flags |= EIO_FLAG_GROUPADD; 2273 grp->flags |= ETP_FLAG_GROUPADD;
2374 2274
2375 ++grp->size; 2275 ++grp->size;
2376 req->grp = grp; 2276 req->grp = grp;
2377 2277
2378 req->grp_prev = 0; 2278 req->grp_prev = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines