Changeset ac408e in git for Singular


Ignore:
Timestamp:
Apr 5, 2024, 9:56:50 AM (6 weeks ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
805b275bfbf361cabc7496aecd096561cf92d6d6
Parents:
a62276379e845035043ef5363b2130f08145d39e
Message:
new select/poll call for waitfirst/waitall
Location:
Singular
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/tasks.lib

    ra622763 rac408e  
    746746            if (code == 3) {   // got result
    747747                id = read(l(pid_parent));
    748                 close(links[assignment[id]]);
    749                 if (nlinks > granted_leaves) {
    750                     tmp = system("semaphore", "release", sem_leaves);
     748                if(typeof(links[assignment[id]])=="link")
     749                {
     750                  close(links[assignment[id]]);
     751                }
     752                if (nlinks > granted_leaves)
     753                {
     754                  tmp = system("semaphore", "release", sem_leaves);
    751755                }
    752756                links[assignment[id]] = def(0);
  • Singular/iparith.cc

    ra622763 rac408e  
    36953695  if(t < 0)
    36963696  {
    3697     WerrorS("negative timeout"); return TRUE;
    3698   }
    3699   int i = slStatusSsiL(Lforks, t*1000);
     3697    t= -1;
     3698  }
     3699  int i = slStatusSsiL(Lforks, t);
    37003700  if(i == -2) /* error */
    37013701  {
     
    37113711//        v: timeout for select in milliseconds
    37123712//           or 0 for polling
     3713//           or -1 for infinite
    37133714// returns: ERROR (via Werror): timeout negative
    3714 //           -1: the read state of all links is eof
     3715//           -1: the read state of all links is eof or error
    37153716//           0: timeout (or polling): none ready
    37163717//           1: all links are ready
    37173718//              (caution: at least one is ready, but some maybe dead)
    3718   lists Lforks = (lists)u->CopyD();
    3719   int timeout = 1000*(int)(long)v->Data();
     3719  lists L = (lists)u->Data();
     3720  BOOLEAN* ignore=(BOOLEAN*)omAlloc0((L->nr+1)*sizeof(BOOLEAN));
     3721  int timeout = (int)(long)v->Data();
    37203722  if(timeout < 0)
    37213723  {
    3722     WerrorS("negative timeout"); return TRUE;
     3724    timeout=-1;
    37233725  }
    37243726  int t = getRTimer()/TIMER_RESOLUTION;  // in seconds
    37253727  int i;
    37263728  int ret = -1;
    3727   for(unsigned nfinished = 0; nfinished < ((unsigned)Lforks->nr)+1; nfinished++)
    3728   {
    3729     i = slStatusSsiL(Lforks, timeout);
    3730     if(i > 0) /* Lforks[i] is ready */
     3729  for(unsigned nfinished = 0; nfinished <= ((unsigned)L->nr); nfinished++)
     3730  {
     3731    i = slStatusSsiL(L, timeout, ignore);
     3732    if(i > 0) /* L[i] is ready */
    37313733    {
    37323734      ret = 1;
    3733       Lforks->m[i-1].CleanUp();
    3734       Lforks->m[i-1].rtyp=DEF_CMD;
    3735       Lforks->m[i-1].data=NULL;
     3735      ignore[i-1]=TRUE;
    37363736      timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t));
    37373737    }
    37383738    else /* terminate the for loop */
    37393739    {
     3740      omFreeSize(ignore,(L->nr+1)*sizeof(BOOLEAN));
    37403741      if(i == -2) /* error */
    37413742      {
     
    37493750    }
    37503751  }
    3751   Lforks->Clean();
    37523752  res->data = (void*)(long)ret;
    37533753  return FALSE;
     
    55435543// input: u: a list with links of type
    55445544//           ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
    5545 // returns: -1:  the read state of all links is eof
     5545// returns: -1:  the read state of all links is eof or error
    55465546//          i>0: (at least) u[i] is ready
    55475547  lists Lforks = (lists)u->Data();
     
    55585558// input: u: a list with links of type
    55595559//           ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch
    5560 // returns: -1: the read state of all links is eof
     5560// returns: -1: the read state of all links is eof or error
    55615561//           1: all links are ready
    55625562//              (caution: at least one is ready, but some maybe dead)
    5563   lists Lforks = (lists)u->CopyD();
     5563  lists L = (lists)u->Data();
    55645564  int i;
    55655565  int j = -1;
    5566   for(int nfinished = 0; nfinished < Lforks->nr+1; nfinished++)
    5567   {
    5568     i = slStatusSsiL(Lforks, -1);
     5566  BOOLEAN* ignore=(BOOLEAN*)omAlloc0((L->nr+1)*sizeof(BOOLEAN));
     5567  for(int nfinished = 0; nfinished <= L->nr; nfinished++)
     5568  {
     5569    i = slStatusSsiL(L, -1, ignore);
    55695570    if(i == -2) /* error */
    55705571    {
    5571       Lforks->Clean();
     5572      omFreeSize(ignore,(L->nr+1)*sizeof(BOOLEAN));
    55725573      return TRUE;
    55735574    }
    5574     if(i == -1)
    5575     {
     5575    if((i == -1)||(j==0))
     5576    {
     5577      j=-1;
    55765578      break;
    55775579    }
    5578     j = 1;
    55795580    if (i>0)
    55805581    {
    5581       Lforks->m[i-1].CleanUp();
    5582       Lforks->m[i-1].rtyp=DEF_CMD;
    5583       Lforks->m[i-1].data=NULL;
    5584     }
    5585   }
     5582      j=1;
     5583      ignore[i-1]=TRUE;
     5584    }
     5585  }
     5586  omFreeSize(ignore,(L->nr+1)*sizeof(BOOLEAN));
    55865587  res->data = (void*)(long)j;
    5587   Lforks->Clean();
    55885588  return FALSE;
    55895589}
  • Singular/links/silink.h

    ra622763 rac408e  
    115115EXTERN_VAR omBin ip_link_bin;
    116116
    117 int slStatusSsiL(lists L, int timeout);
     117int slStatusSsiL(lists L, int timeout, BOOLEAN* ignore=NULL);
    118118int ssiBatch(const char *host, const char * port);
    119119
  • Singular/links/ssiLink.cc

    ra622763 rac408e  
    19551955}
    19561956
    1957 int slStatusSsiL(lists L, int timeout)
     1957int slStatusSsiL(lists L, int timeout, BOOLEAN *ignore)
    19581958{
    19591959// input: L: a list with links of type
    19601960//           ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch.
    19611961//           Note: Not every entry in L must be set.
    1962 //        timeout: timeout for select in micro-seconds
     1962//        timeout: timeout for select in milli-seconds
    19631963//           or -1 for infinity
    19641964//           or 0 for polling
    19651965// returns: ERROR (via Werror): L has wrong elements or link not open
    1966 //           -2: select returns an error
     1966//           -2: error in L
    19671967//           -1: the read state of all links is eof
    19681968//           0:  timeout (or polling): none ready,
     
    19751975  int nfd=L->nr+1;
    19761976  pollfd *pfd=(pollfd*)omAlloc0(nfd*sizeof(pollfd));
     1977#else
     1978  fd_set  fdmask;
     1979  FD_ZERO(&fdmask);
     1980  int max_fd=0; /* 1 + max fd in fd_set */
     1981  /* timeout */
     1982  struct timeval wt;
     1983  struct timeval *wt_ptr=&wt;
     1984  if (timeout== -1)
     1985  {
     1986    wt_ptr=NULL;
     1987  }
     1988  else
     1989  {
     1990    wt.tv_sec  = timeout / 1000;
     1991    wt.tv_usec = (timeout % 1000)*1000;
     1992  }
     1993#endif
    19771994  for(int i=L->nr; i>=0; i--)
    19781995  {
     1996#if defined(HAVE_POLL) && !defined(__APPLE__)
    19791997    pfd[i].fd=-1;
     1998#endif
    19801999    if (L->m[i].Typ()!=DEF_CMD)
    19812000    {
     
    19982017        if (!s_isready(d->f_read))
    19992018        {
     2019#if defined(HAVE_POLL) && !defined(__APPLE__)
    20002020          pfd[i].fd=d_fd;
    20012021          pfd[i].events=POLLIN;
    2002         }
    2003         else
    2004         {
    2005           return i+1;
    2006         }
    2007       }
    2008       else
    2009       {
    2010         Werror("wrong link type >>%s<<",l->m->type);
    2011         return -2;
    2012       }
    2013     }
    2014   }
    2015   if (timeout>0) timeout=timeout/1000;
    2016   s=si_poll(pfd,nfd,timeout);
    2017   if (s==-1)
    2018   {
    2019     WerrorS("error in poll call");
    2020     return -2; /*error*/
    2021   }
    2022   if(s==0)
    2023   {
    2024     return 0; /*timeout*/
    2025   }
    2026   for(int i=L->nr; i>=0; i--)
    2027   {
    2028     if (L->m[i].rtyp==LINK_CMD)
    2029     {
    2030       // the link type is ssi, that's already tested
    2031       l=(si_link)L->m[i].Data();
    2032       d=(ssiInfo*)l->data;
    2033       d_fd=d->fd_read;
    2034       if (pfd[i].fd==d_fd)
    2035       {
    2036         if (pfd[i].revents &POLLIN)
    2037         {
    2038           omFree(pfd);
    2039           return i+1;
    2040         }
    2041       }
    2042     }
    2043   }
    2044   // none ready
    2045   return 0;
    20462022#else
    2047   fd_set  mask, fdmask;
    2048   FD_ZERO(&fdmask);
    2049   FD_ZERO(&mask);
    2050   int max_fd=0; /* 1 + max fd in fd_set */
    2051 
    2052   /* timeout */
    2053   struct timeval wt;
    2054   struct timeval *wt_ptr=&wt;
    2055   int startingtime = getRTimer()/TIMER_RESOLUTION;  // in seconds
    2056   if (timeout== -1)
    2057   {
    2058     wt_ptr=NULL;
    2059   }
    2060   else
    2061   {
    2062     wt.tv_sec  = timeout / 1000000;
    2063     wt.tv_usec = timeout % 1000000;
    2064   }
    2065 
    2066   /* auxiliary variables */
    2067   int i;
    2068   int j;
    2069   int k;
    2070   char fdmaskempty;
    2071 
    2072   /* check the links and fill in fdmask */
    2073   /* check ssi links for ungetc_buf */
    2074   for(i=L->nr; i>=0; i--)
    2075   {
    2076     if (L->m[i].Typ()!=DEF_CMD)
    2077     {
    2078       if (L->m[i].Typ()!=LINK_CMD)
    2079       { WerrorS("all elements must be of type link"); return -2;}
    2080       l=(si_link)L->m[i].Data();
    2081       if(SI_LINK_OPEN_P(l)==0)
    2082       { WerrorS("all links must be open"); return -2;}
    2083       if (((strcmp(l->m->type,"ssi")!=0) && (strcmp(l->m->type,"MPtcp")!=0))
    2084       || ((strcmp(l->mode,"fork")!=0) && (strcmp(l->mode,"tcp")!=0)
    2085         && (strcmp(l->mode,"launch")!=0) && (strcmp(l->mode,"connect")!=0)))
    2086       {
    2087         WerrorS("all links must be of type ssi:fork, ssi:tcp, ssi:connect");
    2088         return -2;
    2089       }
    2090       if (strcmp(l->m->type,"ssi")==0)
    2091       {
    2092         d=(ssiInfo*)l->data;
    2093         d_fd=d->fd_read;
    2094         if (!s_isready(d->f_read))
    2095         {
    20962023          if (FD_SETSIZE<=d_fd)
    20972024          {
     
    21012028          FD_SET(d_fd, &fdmask);
    21022029          if (d_fd > max_fd) max_fd=d_fd;
     2030#endif
    21032031        }
    21042032        else
     2033        {
    21052034          return i+1;
     2035        }
    21062036      }
    21072037      else
     
    21112041      }
    21122042    }
    2113   }
    2114   max_fd++;
    2115   if (FD_SETSIZE<=max_fd)
    2116   {
    2117     Werror("file descriptor number too high (%d)",max_fd);
    2118     return -2;
    2119   }
    2120 
    2121 do_select:
    2122   /* copy fdmask to mask */
    2123   FD_ZERO(&mask);
    2124   for(k = 0; k < max_fd; k++)
    2125   {
    2126     if(FD_ISSET(k, &fdmask))
    2127     {
    2128       FD_SET(k, &mask);
    2129     }
    2130   }
    2131 
    2132   /* check with select: chars waiting: no -> not ready */
    2133   s = si_select(max_fd, &mask, NULL, NULL, wt_ptr);
     2043    else if (ignore!=NULL)
     2044    {
     2045      ignore[i]=TRUE; // not a link
     2046    }
     2047  }
     2048#if defined(HAVE_POLL) && !defined(__APPLE__)
     2049  s=si_poll(pfd,nfd,timeout);
     2050#else
     2051  s = si_select(max_fd, &fdmask, NULL, NULL, wt_ptr);
     2052#endif
    21342053  if (s==-1)
    21352054  {
    2136     WerrorS("error in select call");
     2055    WerrorS("error in poll/select call");
    21372056    return -2; /*error*/
    21382057  }
    2139   if (s==0)
    2140   {
    2141     return 0; /*poll: not ready */
    2142   }
    2143   else /* s>0, at least one ready  (the number of fd which are ready is s)*/
    2144   {
    2145     j=0;
    2146     while (j<=max_fd) { if (FD_ISSET(j,&mask)) break; j++; }
    2147     for(i=L->nr; i>=0; i--)
    2148     {
    2149       if (L->m[i].rtyp==LINK_CMD)
    2150       {
    2151         l=(si_link)L->m[i].Data();
    2152         // only ssi links:
    2153         d=(ssiInfo*)l->data;
    2154         d_fd=d->fd_read;
    2155         if(j==d_fd) break;
    2156       }
    2157     }
    2158     loop
    2159     {
    2160       /* yes: read 1 char*/
    2161       /* if \n, check again with select else ungetc(c), ready*/
    2162       /* setting: d: current ssiInfo, j current fd, i current entry in L*/
    2163       int c=s_getc(d->f_read);
    2164       //Print("try c=%d\n",c);
    2165       if (c== -1) /* eof */
    2166       {
    2167         FD_CLR(j,&fdmask);
    2168         fdmaskempty = 1;
    2169         for(k = 0; k < max_fd; k++)
    2170         {
    2171           if(FD_ISSET(k, &fdmask))
    2172           {
    2173             fdmaskempty = 0;
    2174             break;
    2175           }
    2176         }
    2177         if(fdmaskempty)
    2178         {
    2179           return -1;
    2180         }
    2181         if(timeout != -1)
    2182         {
    2183           timeout = si_max(0,
    2184              timeout - 1000000*(getRTimer()/TIMER_RESOLUTION - startingtime));
    2185           wt.tv_sec  = timeout / 1000000;
    2186           wt.tv_usec = (timeout % 1000000);
    2187         }
    2188         goto do_select;
    2189       }
    2190 
    2191       else if (isdigit(c))
    2192       { s_ungetc(c,d->f_read); return i+1; }
    2193       else if (c>' ')
    2194       {
    2195         Werror("unknown char in ssiLink(%d)",c);
    2196         return -2;
    2197       }
    2198       /* else: next char */
    2199       goto do_select;
    2200     }
    2201   }
     2058  if(s==0)
     2059  {
     2060    return 0; /*timeout*/
     2061  }
     2062  for(int i=L->nr; i>=0; i--)
     2063  {
     2064    if ((L->m[i].rtyp==LINK_CMD)
     2065    && ((ignore==NULL)||(ignore[i]==FALSE)))
     2066    {
     2067      // the link type is ssi, that's already tested
     2068      l=(si_link)L->m[i].Data();
     2069      d=(ssiInfo*)l->data;
     2070      d_fd=d->fd_read;
     2071#if defined(HAVE_POLL) && !defined(__APPLE__)
     2072      if (pfd[i].fd==d_fd)
     2073      {
     2074        if (pfd[i].revents &POLLIN)
     2075        {
     2076          omFree(pfd);
     2077          if (ignore!=NULL) ignore[i]=TRUE;
     2078          return i+1;
     2079        }
     2080      }
     2081#else
     2082      if (FD_ISSET(d_fd, &fdmask))
     2083      {
     2084        if (ignore!=NULL) ignore[i]=TRUE;
     2085        return i+1;
     2086      }
    22022087#endif
     2088    }
     2089  }
     2090  // no ready
     2091  return 0;
    22032092}
    22042093
Note: See TracChangeset for help on using the changeset viewer.