proper return value handling
This commit is contained in:
parent
cf112a57fa
commit
6f8e168ae3
@ -175,23 +175,36 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
||||
gettimeofday(&tv, NULL);
|
||||
tv.tv_sec += timeout/1000;
|
||||
tv.tv_usec += timeout%1000;
|
||||
if (tv.tv_usec>1000) {
|
||||
tv.tv_usec-=1000;
|
||||
if (tv.tv_usec>1000000) {
|
||||
tv.tv_usec-=1000000;
|
||||
++tv.tv_sec;
|
||||
}
|
||||
ts.tv_sec = tv.tv_sec;
|
||||
ts.tv_nsec = tv.tv_usec * 1000;
|
||||
#ifdef __dietlibc__
|
||||
r=cnd_timedwait(&c->sem,&c->mtx,&ts);
|
||||
switch (r) {
|
||||
case thrd_success:
|
||||
continue;
|
||||
case thrd_timedout:
|
||||
return 0;
|
||||
case thrd_error:
|
||||
return -1;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
r=pthread_cond_timedwait(&c->sem,&c->mtx,&ts);
|
||||
switch (r) {
|
||||
case 0: continue;
|
||||
case ETIMEDOUT: return 0;
|
||||
default: return -1;
|
||||
}
|
||||
#else
|
||||
r=sem_timedwait(&c->sem,&ts);
|
||||
#endif
|
||||
if (r==-1) {
|
||||
if (errno==ETIMEDOUT) return 0;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
/* fall through into next loop iteration */
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ int worker(void* arg) {
|
||||
uintptr_t i=(uintptr_t)arg;
|
||||
char buf[100];
|
||||
int64 s;
|
||||
int events;
|
||||
unsigned int events;
|
||||
|
||||
write(1,buf,sprintf(buf,"starting thread %ld\n",i));
|
||||
|
||||
@ -73,7 +73,10 @@ int main() {
|
||||
if (thrd_join(x[i],&r)==-1)
|
||||
#else
|
||||
void* tmp;
|
||||
if (pthread_join(x[i],&tmp)==-1, r=(int)(uintptr_t)tmp)
|
||||
|
||||
if (pthread_join(x[i],&tmp)!=-1)
|
||||
r=(int)(uintptr_t)tmp;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
perror("thrd_join");
|
||||
@ -82,5 +85,7 @@ int main() {
|
||||
printf("thread %d returned %d\n",i,r);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user