Changeset b19e8e in git


Ignore:
Timestamp:
Mar 22, 2024, 2:19:48 PM (7 weeks ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '854dc24078c9c998b9967f75c5e6fbe0e43b963e')
Children:
c1b4b44600babf6d7a56f4684f4ff14c98a41e20
Parents:
c1cb4469fcf4806587c032c0165d48cf7891316f
Message:
use poll for waitfirst/waitall
Location:
Singular
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/iparith.cc

    rc1cb44 rb19e8e  
    55765576    }
    55775577    j = 1;
    5578     Lforks->m[i-1].CleanUp();
    5579     Lforks->m[i-1].rtyp=DEF_CMD;
    5580     Lforks->m[i-1].data=NULL;
     5578    if (i>0)
     5579    {
     5580      Lforks->m[i-1].CleanUp();
     5581      Lforks->m[i-1].rtyp=DEF_CMD;
     5582      Lforks->m[i-1].data=NULL;
     5583    }
    55815584  }
    55825585  res->data = (void*)(long)j;
  • Singular/links/ssiLink.cc

    rc1cb44 rb19e8e  
    19541954  ssiInfo *d=NULL;
    19551955  int d_fd;
    1956   fd_set  mask, fdmask;
    1957   FD_ZERO(&fdmask);
    1958   FD_ZERO(&mask);
    1959   int max_fd=0; /* 1 + max fd in fd_set */
    1960 
    1961   /* timeout */
    1962   struct timeval wt;
    1963   struct timeval *wt_ptr=&wt;
    1964   int startingtime = getRTimer()/TIMER_RESOLUTION;  // in seconds
    1965   if (timeout== -1)
    1966   {
    1967     wt_ptr=NULL;
    1968   }
    1969   else
    1970   {
    1971     wt.tv_sec  = timeout / 1000000;
    1972     wt.tv_usec = timeout % 1000000;
    1973   }
    1974 
    1975   /* auxiliary variables */
    1976   int i;
    1977   int j;
    1978   int k;
    19791956  int s;
    1980   char fdmaskempty;
    1981 
    1982   /* check the links and fill in fdmask */
    1983   /* check ssi links for ungetc_buf */
    1984   for(i=L->nr; i>=0; i--)
     1957#ifdef HAVE_POLL
     1958  int nfd=L->nr+1;
     1959  int wait_for=0;
     1960  pollfd *pfd=(pollfd*)omAlloc0(nfd*sizeof(pollfd));
     1961  for(int i=L->nr; i>=0; i--)
    19851962  {
    19861963    if (L->m[i].Typ()!=DEF_CMD)
     
    20041981        if (!s_isready(d->f_read))
    20051982        {
     1983          pfd[i].fd=d_fd;
     1984          pfd[i].events=POLLIN;
     1985          wait_for++;
     1986        }
     1987        else
     1988        {
     1989          return i+1;
     1990        }
     1991      }
     1992      else
     1993      {
     1994        Werror("wrong link type >>%s<<",l->m->type);
     1995        return -2;
     1996      }
     1997    }
     1998  }
     1999  if (timeout>0) timeout=timeout/1000000;
     2000do_poll:
     2001  s=poll(pfd,nfd,timeout);
     2002  if (s==-1)
     2003  {
     2004    WerrorS("error in poll call");
     2005    return -2; /*error*/
     2006  }
     2007  if(s==0)
     2008  {
     2009    return 0; /*timeout*/
     2010  }
     2011  for(int i=L->nr; i>=0; i--)
     2012  {
     2013    if (L->m[i].rtyp==LINK_CMD)
     2014    {
     2015      // the link type is ssi, that's already tested
     2016      l=(si_link)L->m[i].Data();
     2017      d=(ssiInfo*)l->data;
     2018      d_fd=d->fd_read;
     2019      //for(int j=nfd-1;j>=0;j--)
     2020      if (!s_isready(d->f_read))
     2021      {
     2022        if (pfd[i].fd==d_fd)
     2023        {
     2024          if (pfd[i].revents &POLLIN)
     2025          {
     2026            omFree(pfd);
     2027            return i+1;
     2028          }
     2029          if (pfd[i].revents &POLLERR)
     2030          {
     2031            wait_for--;
     2032            pfd[i].events=0;
     2033          }
     2034        }
     2035      }
     2036    }
     2037  }
     2038  // none ready, wait again:
     2039  if ((timeout!=0)&&(wait_for>0)) goto do_poll;
     2040  return 0;
     2041#else
     2042  fd_set  mask, fdmask;
     2043  FD_ZERO(&fdmask);
     2044  FD_ZERO(&mask);
     2045  int max_fd=0; /* 1 + max fd in fd_set */
     2046
     2047  /* timeout */
     2048  struct timeval wt;
     2049  struct timeval *wt_ptr=&wt;
     2050  int startingtime = getRTimer()/TIMER_RESOLUTION;  // in seconds
     2051  if (timeout== -1)
     2052  {
     2053    wt_ptr=NULL;
     2054  }
     2055  else
     2056  {
     2057    wt.tv_sec  = timeout / 1000000;
     2058    wt.tv_usec = timeout % 1000000;
     2059  }
     2060
     2061  /* auxiliary variables */
     2062  int i;
     2063  int j;
     2064  int k;
     2065  char fdmaskempty;
     2066
     2067  /* check the links and fill in fdmask */
     2068  /* check ssi links for ungetc_buf */
     2069  for(i=L->nr; i>=0; i--)
     2070  {
     2071    if (L->m[i].Typ()!=DEF_CMD)
     2072    {
     2073      if (L->m[i].Typ()!=LINK_CMD)
     2074      { WerrorS("all elements must be of type link"); return -2;}
     2075      l=(si_link)L->m[i].Data();
     2076      if(SI_LINK_OPEN_P(l)==0)
     2077      { WerrorS("all links must be open"); return -2;}
     2078      if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
     2079      || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
     2080        && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
     2081      {
     2082        WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
     2083        return -2;
     2084      }
     2085      if (strcmp(l->m->type,"ssi")==0)
     2086      {
     2087        d=(ssiInfo*)l->data;
     2088        d_fd=d->fd_read;
     2089        if (!s_isready(d->f_read))
     2090        {
    20062091          if (FD_SETSIZE<=d_fd)
    20072092          {
     
    20602145      {
    20612146        l=(si_link)L->m[i].Data();
    2062         if (strcmp(l->m->type,"ssi")==0)
    2063         {
    2064           d=(ssiInfo*)l->data;
    2065           d_fd=d->fd_read;
    2066           if(j==d_fd) break;
    2067         }
    2068         else
    2069         {
    2070           Werror("wrong link type >>%s<<",l->m->type);
    2071           return -2;
    2072         }
    2073       }
    2074     }
    2075     // only ssi links:
     2147        // only ssi links:
     2148        d=(ssiInfo*)l->data;
     2149        d_fd=d->fd_read;
     2150        if(j==d_fd) break;
     2151      }
     2152    }
    20762153    loop
    20772154    {
     
    21182195    }
    21192196  }
     2197#endif
    21202198}
    21212199
Note: See TracChangeset for help on using the changeset viewer.