From 95cbc98a53e7001dcc7f3bfba072b367ec060ee5 Mon Sep 17 00:00:00 2001 From: t00fcxen Date: Thu, 9 Oct 2014 18:45:38 +0000 Subject: Sync with Mavericks sources. git-svn-id: http://sctp-refimpl.googlecode.com/svn/trunk/KERN/usrsctp/usrsctplib@9042 9df1edf5-d72c-5b5f-11c0-5f5209eb73f7 --- netinet/sctp_callout.c | 89 +++++++++++++++++++++++++++++++++++++++++--------- netinet/sctp_callout.h | 6 +++- netinet/sctp_usrreq.c | 4 ++- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/netinet/sctp_callout.c b/netinet/sctp_callout.c index 67b7566..3174e3f 100755 --- a/netinet/sctp_callout.c +++ b/netinet/sctp_callout.c @@ -30,9 +30,27 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#if defined(__Userspace__) +#include +#if !defined (__Userspace_os_Windows) +#include +#include +#include +#endif +#if defined(__Userspace_os_NaCl) +#include +#endif +#include +#include +#include +#include +#include +#include +#else #include #include #include +#endif /* * Callout/Timer routines for OS that doesn't have them @@ -46,10 +64,8 @@ extern int ticks; /* * SCTP_TIMERQ_LOCK protects: * - SCTP_BASE_INFO(callqueue) - * - sctp_os_timer_current: current timer in process * - sctp_os_timer_next: next timer to check */ -static sctp_os_timer_t *sctp_os_timer_current = NULL; static sctp_os_timer_t *sctp_os_timer_next = NULL; void @@ -117,24 +133,16 @@ sctp_os_timer_stop(sctp_os_timer_t *c) return (1); } -#if defined(__APPLE__) -/* - * For __APPLE__, use a single main timer at a faster resolution than - * fastim. The timer just calls this existing callout infrastructure. - */ -#endif -void -sctp_timeout(void *arg SCTP_UNUSED) +static void +sctp_handle_tick(int delta) { sctp_os_timer_t *c; void (*c_func)(void *); void *c_arg; SCTP_TIMERQ_LOCK(); -#if defined(__APPLE__) /* update our tick count */ - ticks += SCTP_BASE_VAR(sctp_main_timer_ticks); -#endif + ticks += delta; c = TAILQ_FIRST(&SCTP_BASE_INFO(callqueue)); while (c) { if (c->c_time <= ticks) { @@ -143,11 +151,9 @@ sctp_timeout(void *arg SCTP_UNUSED) c_func = c->c_func; c_arg = c->c_arg; c->c_flags &= ~SCTP_CALLOUT_PENDING; - sctp_os_timer_current = c; SCTP_TIMERQ_UNLOCK(); c_func(c_arg); SCTP_TIMERQ_LOCK(); - sctp_os_timer_current = NULL; c = sctp_os_timer_next; } else { c = TAILQ_NEXT(c, tqe); @@ -155,9 +161,60 @@ sctp_timeout(void *arg SCTP_UNUSED) } sctp_os_timer_next = NULL; SCTP_TIMERQ_UNLOCK(); +} #if defined(__APPLE__) - /* restart the main timer */ +void +sctp_timeout(void *arg SCTP_UNUSED) +{ + sctp_handle_tick(SCTP_BASE_VAR(sctp_main_timer_ticks)); sctp_start_main_timer(); +} #endif + +#if defined(__Userspace__) +#define TIMEOUT_INTERVAL 10 + +void * +user_sctp_timer_iterate(void *arg) +{ + for (;;) { +#if defined (__Userspace_os_Windows) + Sleep(TIMEOUT_INTERVAL); +#else + struct timeval timeout; + + timeout.tv_sec = 0; + timeout.tv_usec = 1000 * TIMEOUT_INTERVAL; + select(0, NULL, NULL, NULL, &timeout); +#endif + if (SCTP_BASE_VAR(timer_thread_should_exit)) { + break; + } + sctp_handle_tick(MSEC_TO_TICKS(TIMEOUT_INTERVAL)); + } + return (NULL); } + +void +sctp_start_timer(void) +{ + /* + * No need to do SCTP_TIMERQ_LOCK_INIT(); + * here, it is being done in sctp_pcb_init() + */ +#if defined (__Userspace_os_Windows) + if ((SCTP_BASE_VAR(timer_thread) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)user_sctp_timer_iterate, NULL, 0, NULL)) == NULL) { + SCTP_PRINTF("ERROR; Creating ithread failed\n"); + } +#else + int rc; + + rc = pthread_create(&SCTP_BASE_VAR(timer_thread), NULL, user_sctp_timer_iterate, NULL); + if (rc) { + SCTP_PRINTF("ERROR; return code from pthread_create() is %d\n", rc); + } +#endif +} + +#endif diff --git a/netinet/sctp_callout.h b/netinet/sctp_callout.h index 2782945..c53c5a4 100755 --- a/netinet/sctp_callout.h +++ b/netinet/sctp_callout.h @@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$"); #endif extern int ticks; -extern void sctp_start_timer(); #endif TAILQ_HEAD(calloutlist, sctp_callout); @@ -94,6 +93,11 @@ int sctp_os_timer_stop(sctp_os_timer_t *); #define SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE) #define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE) +#if defined(__Userspace__) +void sctp_start_timer(void); +#endif +#if defined(__APPLE__) void sctp_timeout(void *); +#endif #endif diff --git a/netinet/sctp_usrreq.c b/netinet/sctp_usrreq.c index 1eee82f..362d353 100755 --- a/netinet/sctp_usrreq.c +++ b/netinet/sctp_usrreq.c @@ -56,7 +56,9 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 272750 2014-10-08 15:29:49Z t #include #include #include -#if !defined(__Userspace__) +#if defined(__Userspace__) +#include +#else #include #endif -- cgit v1.2.3