mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-04 21:39:49 +00:00
Unix port: improve support for the Hurd
Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
parent
602a66fe58
commit
2f5305c259
@ -4,12 +4,14 @@ set (CMAKE_CONFIGURATION_TYPES "Debug;Release")
|
|||||||
|
|
||||||
project(lwipunittests C)
|
project(lwipunittests C)
|
||||||
|
|
||||||
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "GNU")
|
||||||
message(FATAL_ERROR "Unit test are currently only working on Linux or Darwin")
|
message(FATAL_ERROR "Unit test are currently only working on Linux, Darwin or Hurd")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
|
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
|
||||||
set(LWIP_USE_SANITIZERS true)
|
if (NOT CMAKE_SYSTEM_NAME STREQUAL "GNU")
|
||||||
|
set(LWIP_USE_SANITIZERS true)
|
||||||
|
endif()
|
||||||
include(${LWIP_DIR}/contrib/ports/CMakeCommon.cmake)
|
include(${LWIP_DIR}/contrib/ports/CMakeCommon.cmake)
|
||||||
|
|
||||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||||
@ -45,7 +47,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|||||||
target_link_libraries(lwip_unittests ${LIBSUBUNIT})
|
target_link_libraries(lwip_unittests ${LIBSUBUNIT})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "GNU")
|
||||||
find_library(LIBUTIL util)
|
find_library(LIBUTIL util)
|
||||||
find_library(LIBPTHREAD pthread)
|
find_library(LIBPTHREAD pthread)
|
||||||
find_library(LIBRT rt)
|
find_library(LIBRT rt)
|
||||||
|
@ -68,6 +68,9 @@
|
|||||||
#include "lwip/stats.h"
|
#include "lwip/stats.h"
|
||||||
#include "lwip/tcpip.h"
|
#include "lwip/tcpip.h"
|
||||||
|
|
||||||
|
/* Return code for an interrupted timed wait */
|
||||||
|
#define SYS_ARCH_INTR 0xfffffffeUL
|
||||||
|
|
||||||
u32_t
|
u32_t
|
||||||
lwip_port_rand(void)
|
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;
|
struct timespec rtime1, rtime2, ts;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef __GNU__
|
#ifdef LWIP_UNIX_HURD
|
||||||
#define pthread_cond_wait pthread_hurd_cond_wait_np
|
#define pthread_cond_wait pthread_hurd_cond_wait_np
|
||||||
#define pthread_cond_timedwait pthread_hurd_cond_timedwait_np
|
#define pthread_cond_timedwait pthread_hurd_cond_timedwait_np
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (timeout == 0) {
|
if (timeout == 0) {
|
||||||
pthread_cond_wait(cond, mutex);
|
ret = pthread_cond_wait(cond, mutex);
|
||||||
return 0;
|
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. */
|
/* 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
|
#endif
|
||||||
if (ret == ETIMEDOUT) {
|
if (ret == ETIMEDOUT) {
|
||||||
return SYS_ARCH_TIMEOUT;
|
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. */
|
/* 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) {
|
if (time_needed == SYS_ARCH_TIMEOUT) {
|
||||||
pthread_mutex_unlock(&(sem->mutex));
|
pthread_mutex_unlock(&(sem->mutex));
|
||||||
return SYS_ARCH_TIMEOUT;
|
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));
|
/* pthread_mutex_unlock(&(sem->mutex));
|
||||||
return time_needed; */
|
return time_needed; */
|
||||||
} else {
|
} else if(cond_wait(&(sem->cond), &(sem->mutex), 0)) {
|
||||||
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--;
|
sem->c--;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user