michael@0: /*- michael@0: * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * 3. Neither the name of the project nor the names of its contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND michael@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT michael@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY michael@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: * SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD$"); michael@0: #endif michael@0: michael@0: #ifndef _NETINET_SCTP_CALLOUT_ michael@0: #define _NETINET_SCTP_CALLOUT_ michael@0: michael@0: /* michael@0: * NOTE: the following MACROS are required for locking the callout michael@0: * queue along with a lock/mutex in the OS specific headers and michael@0: * implementation files:: michael@0: * - SCTP_TIMERQ_LOCK() michael@0: * - SCTP_TIMERQ_UNLOCK() michael@0: * - SCTP_TIMERQ_LOCK_INIT() michael@0: * - SCTP_TIMERQ_LOCK_DESTROY() michael@0: */ michael@0: michael@0: #define _SCTP_NEEDS_CALLOUT_ 1 michael@0: michael@0: #define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */ michael@0: michael@0: #if defined(__Userspace__) michael@0: #if defined(__Userspace_os_Windows) michael@0: #define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx)) michael@0: #define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx)) michael@0: #define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx)) michael@0: #define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx)) michael@0: #else michael@0: #define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) michael@0: #define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) michael@0: #define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), NULL) michael@0: #define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx)) michael@0: #endif michael@0: michael@0: extern int ticks; michael@0: #endif michael@0: michael@0: TAILQ_HEAD(calloutlist, sctp_callout); michael@0: michael@0: struct sctp_callout { michael@0: TAILQ_ENTRY(sctp_callout) tqe; michael@0: int c_time; /* ticks to the event */ michael@0: void *c_arg; /* function argument */ michael@0: void (*c_func)(void *); /* function to call */ michael@0: int c_flags; /* state of this entry */ michael@0: }; michael@0: typedef struct sctp_callout sctp_os_timer_t; michael@0: michael@0: #define SCTP_CALLOUT_ACTIVE 0x0002 /* callout is currently active */ michael@0: #define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */ michael@0: michael@0: void sctp_os_timer_init(sctp_os_timer_t *tmr); michael@0: void sctp_os_timer_start(sctp_os_timer_t *, int, void (*)(void *), void *); michael@0: int sctp_os_timer_stop(sctp_os_timer_t *); michael@0: michael@0: #define SCTP_OS_TIMER_INIT sctp_os_timer_init michael@0: #define SCTP_OS_TIMER_START sctp_os_timer_start michael@0: #define SCTP_OS_TIMER_STOP sctp_os_timer_stop michael@0: /* MT FIXME: Is the following correct? */ michael@0: #define SCTP_OS_TIMER_STOP_DRAIN SCTP_OS_TIMER_STOP michael@0: #define SCTP_OS_TIMER_PENDING(tmr) ((tmr)->c_flags & SCTP_CALLOUT_PENDING) michael@0: #define SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE) michael@0: #define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE) michael@0: michael@0: #if defined(__Userspace__) michael@0: void sctp_start_timer(void); michael@0: #endif michael@0: #if defined(__APPLE__) michael@0: void sctp_timeout(void *); michael@0: #endif michael@0: michael@0: #endif