Unix port: improve support for the Hurd

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
Joan Lledó
2019-07-14 12:30:40 +02:00
committed by Simon Goldschmidt
parent 602a66fe58
commit 2f5305c259
2 changed files with 33 additions and 9 deletions

View File

@@ -68,6 +68,9 @@
#include "lwip/stats.h"
#include "lwip/tcpip.h"
/* Return code for an interrupted timed wait */
#define SYS_ARCH_INTR 0xfffffffeUL
u32_t
lwip_port_rand(void)
{
@@ -489,14 +492,20 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
struct timespec rtime1, rtime2, ts;
int ret;
#ifdef __GNU__
#ifdef LWIP_UNIX_HURD
#define pthread_cond_wait pthread_hurd_cond_wait_np
#define pthread_cond_timedwait pthread_hurd_cond_timedwait_np
#endif
if (timeout == 0) {
pthread_cond_wait(cond, mutex);
return 0;
ret = pthread_cond_wait(cond, mutex);
return
#ifdef LWIP_UNIX_HURD
/* On the Hurd, ret == 1 means the RPC has been cancelled.
* The thread is awakened (not terminated) and execution must continue */
ret == 1 ? SYS_ARCH_INTR :
#endif
(u32_t)ret;
}
/* Get a timestamp and add the timeout value. */
@@ -517,6 +526,12 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
#endif
if (ret == ETIMEDOUT) {
return SYS_ARCH_TIMEOUT;
#ifdef LWIP_UNIX_HURD
/* On the Hurd, ret == 1 means the RPC has been cancelled.
* The thread is awakened (not terminated) and execution must continue */
} else if (ret == EINTR) {
return SYS_ARCH_INTR;
#endif
}
/* Calculate for how long we waited for the cond. */
@@ -546,11 +561,18 @@ sys_arch_sem_wait(struct sys_sem **s, u32_t timeout)
if (time_needed == SYS_ARCH_TIMEOUT) {
pthread_mutex_unlock(&(sem->mutex));
return SYS_ARCH_TIMEOUT;
#ifdef LWIP_UNIX_HURD
} else if(time_needed == SYS_ARCH_INTR) {
pthread_mutex_unlock(&(sem->mutex));
return 0;
#endif
}
/* pthread_mutex_unlock(&(sem->mutex));
return time_needed; */
} else {
cond_wait(&(sem->cond), &(sem->mutex), 0);
} else if(cond_wait(&(sem->cond), &(sem->mutex), 0)) {
/* Some error happened or the thread has been awakened but not by lwip */
pthread_mutex_unlock(&(sem->mutex));
return 0;
}
}
sem->c--;