- Timestamp:
- Apr 5, 2024, 9:56:50 AM (6 weeks ago)
- Branches:
- (u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
- Children:
- 805b275bfbf361cabc7496aecd096561cf92d6d6
- Parents:
- a62276379e845035043ef5363b2130f08145d39e
- Location:
- Singular
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/tasks.lib
ra622763 rac408e 746 746 if (code == 3) { // got result 747 747 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); 751 755 } 752 756 links[assignment[id]] = def(0); -
Singular/iparith.cc
ra622763 rac408e 3695 3695 if(t < 0) 3696 3696 { 3697 WerrorS("negative timeout"); return TRUE;3698 } 3699 int i = slStatusSsiL(Lforks, t *1000);3697 t= -1; 3698 } 3699 int i = slStatusSsiL(Lforks, t); 3700 3700 if(i == -2) /* error */ 3701 3701 { … … 3711 3711 // v: timeout for select in milliseconds 3712 3712 // or 0 for polling 3713 // or -1 for infinite 3713 3714 // 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 3715 3716 // 0: timeout (or polling): none ready 3716 3717 // 1: all links are ready 3717 3718 // (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(); 3720 3722 if(timeout < 0) 3721 3723 { 3722 WerrorS("negative timeout"); return TRUE;3724 timeout=-1; 3723 3725 } 3724 3726 int t = getRTimer()/TIMER_RESOLUTION; // in seconds 3725 3727 int i; 3726 3728 int ret = -1; 3727 for(unsigned nfinished = 0; nfinished < ((unsigned)Lforks->nr)+1; nfinished++)3728 { 3729 i = slStatusSsiL(L forks, timeout);3730 if(i > 0) /* L forks[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 */ 3731 3733 { 3732 3734 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; 3736 3736 timeout = si_max(0,timeout - 1000*(getRTimer()/TIMER_RESOLUTION - t)); 3737 3737 } 3738 3738 else /* terminate the for loop */ 3739 3739 { 3740 omFreeSize(ignore,(L->nr+1)*sizeof(BOOLEAN)); 3740 3741 if(i == -2) /* error */ 3741 3742 { … … 3749 3750 } 3750 3751 } 3751 Lforks->Clean();3752 3752 res->data = (void*)(long)ret; 3753 3753 return FALSE; … … 5543 5543 // input: u: a list with links of type 5544 5544 // 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 5546 5546 // i>0: (at least) u[i] is ready 5547 5547 lists Lforks = (lists)u->Data(); … … 5558 5558 // input: u: a list with links of type 5559 5559 // 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 5561 5561 // 1: all links are ready 5562 5562 // (caution: at least one is ready, but some maybe dead) 5563 lists L forks = (lists)u->CopyD();5563 lists L = (lists)u->Data(); 5564 5564 int i; 5565 5565 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); 5569 5570 if(i == -2) /* error */ 5570 5571 { 5571 Lforks->Clean();5572 omFreeSize(ignore,(L->nr+1)*sizeof(BOOLEAN)); 5572 5573 return TRUE; 5573 5574 } 5574 if(i == -1) 5575 { 5575 if((i == -1)||(j==0)) 5576 { 5577 j=-1; 5576 5578 break; 5577 5579 } 5578 j = 1;5579 5580 if (i>0) 5580 5581 { 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)); 5586 5587 res->data = (void*)(long)j; 5587 Lforks->Clean();5588 5588 return FALSE; 5589 5589 } -
Singular/links/silink.h
ra622763 rac408e 115 115 EXTERN_VAR omBin ip_link_bin; 116 116 117 int slStatusSsiL(lists L, int timeout );117 int slStatusSsiL(lists L, int timeout, BOOLEAN* ignore=NULL); 118 118 int ssiBatch(const char *host, const char * port); 119 119 -
Singular/links/ssiLink.cc
ra622763 rac408e 1955 1955 } 1956 1956 1957 int slStatusSsiL(lists L, int timeout )1957 int slStatusSsiL(lists L, int timeout, BOOLEAN *ignore) 1958 1958 { 1959 1959 // input: L: a list with links of type 1960 1960 // ssi-connect, ssi-fork, ssi-tcp, MPtcp-fork or MPtcp-launch. 1961 1961 // Note: Not every entry in L must be set. 1962 // timeout: timeout for select in mi cro-seconds1962 // timeout: timeout for select in milli-seconds 1963 1963 // or -1 for infinity 1964 1964 // or 0 for polling 1965 1965 // returns: ERROR (via Werror): L has wrong elements or link not open 1966 // -2: select returns an error1966 // -2: error in L 1967 1967 // -1: the read state of all links is eof 1968 1968 // 0: timeout (or polling): none ready, … … 1975 1975 int nfd=L->nr+1; 1976 1976 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 1977 1994 for(int i=L->nr; i>=0; i--) 1978 1995 { 1996 #if defined(HAVE_POLL) && !defined(__APPLE__) 1979 1997 pfd[i].fd=-1; 1998 #endif 1980 1999 if (L->m[i].Typ()!=DEF_CMD) 1981 2000 { … … 1998 2017 if (!s_isready(d->f_read)) 1999 2018 { 2019 #if defined(HAVE_POLL) && !defined(__APPLE__) 2000 2020 pfd[i].fd=d_fd; 2001 2021 pfd[i].events=POLLIN; 2002 }2003 else2004 {2005 return i+1;2006 }2007 }2008 else2009 {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 tested2031 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 ready2045 return 0;2046 2022 #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 seconds2056 if (timeout== -1)2057 {2058 wt_ptr=NULL;2059 }2060 else2061 {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 {2096 2023 if (FD_SETSIZE<=d_fd) 2097 2024 { … … 2101 2028 FD_SET(d_fd, &fdmask); 2102 2029 if (d_fd > max_fd) max_fd=d_fd; 2030 #endif 2103 2031 } 2104 2032 else 2033 { 2105 2034 return i+1; 2035 } 2106 2036 } 2107 2037 else … … 2111 2041 } 2112 2042 } 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 2134 2053 if (s==-1) 2135 2054 { 2136 WerrorS("error in select call");2055 WerrorS("error in poll/select call"); 2137 2056 return -2; /*error*/ 2138 2057 } 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 } 2202 2087 #endif 2088 } 2089 } 2090 // no ready 2091 return 0; 2203 2092 } 2204 2093
Note: See TracChangeset
for help on using the changeset viewer.