netwerk/sctp/src/netinet/sctp_callout.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/sctp/src/netinet/sctp_callout.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +/*-
     1.5 + * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
     1.6 + * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
     1.7 + * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 3. Neither the name of the project nor the names of its contributors
    1.18 + *    may be used to endorse or promote products derived from this software
    1.19 + *    without specific prior written permission.
    1.20 + *
    1.21 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
    1.22 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.24 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
    1.25 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.26 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.27 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.28 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.29 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.30 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.31 + * SUCH DAMAGE.
    1.32 + */
    1.33 +
    1.34 +#ifdef __FreeBSD__
    1.35 +#include <sys/cdefs.h>
    1.36 +__FBSDID("$FreeBSD$");
    1.37 +#endif
    1.38 +
    1.39 +#ifndef _NETINET_SCTP_CALLOUT_
    1.40 +#define _NETINET_SCTP_CALLOUT_
    1.41 +
    1.42 +/*
    1.43 + * NOTE: the following MACROS are required for locking the callout
    1.44 + * queue along with a lock/mutex in the OS specific headers and
    1.45 + * implementation files::
    1.46 + * - SCTP_TIMERQ_LOCK()
    1.47 + * - SCTP_TIMERQ_UNLOCK()
    1.48 + * - SCTP_TIMERQ_LOCK_INIT()
    1.49 + * - SCTP_TIMERQ_LOCK_DESTROY()
    1.50 + */
    1.51 +
    1.52 +#define _SCTP_NEEDS_CALLOUT_ 1
    1.53 +
    1.54 +#define SCTP_TICKS_PER_FASTTIMO 20	/* called about every 20ms */
    1.55 +
    1.56 +#if defined(__Userspace__)
    1.57 +#if defined(__Userspace_os_Windows)
    1.58 +#define SCTP_TIMERQ_LOCK()          EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
    1.59 +#define SCTP_TIMERQ_UNLOCK()        LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
    1.60 +#define SCTP_TIMERQ_LOCK_INIT()     InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
    1.61 +#define SCTP_TIMERQ_LOCK_DESTROY()  DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx))
    1.62 +#else
    1.63 +#define SCTP_TIMERQ_LOCK()          (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx))
    1.64 +#define SCTP_TIMERQ_UNLOCK()        (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx))
    1.65 +#define SCTP_TIMERQ_LOCK_INIT()     (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), NULL)
    1.66 +#define SCTP_TIMERQ_LOCK_DESTROY()  (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx))
    1.67 +#endif
    1.68 +
    1.69 +extern int ticks;
    1.70 +#endif
    1.71 +
    1.72 +TAILQ_HEAD(calloutlist, sctp_callout);
    1.73 +
    1.74 +struct sctp_callout {
    1.75 +	TAILQ_ENTRY(sctp_callout) tqe;
    1.76 +	int c_time;		/* ticks to the event */
    1.77 +	void *c_arg;		/* function argument */
    1.78 +	void (*c_func)(void *);	/* function to call */
    1.79 +	int c_flags;		/* state of this entry */
    1.80 +};
    1.81 +typedef struct sctp_callout sctp_os_timer_t;
    1.82 +
    1.83 +#define	SCTP_CALLOUT_ACTIVE	0x0002	/* callout is currently active */
    1.84 +#define	SCTP_CALLOUT_PENDING	0x0004	/* callout is waiting for timeout */
    1.85 +
    1.86 +void sctp_os_timer_init(sctp_os_timer_t *tmr);
    1.87 +void sctp_os_timer_start(sctp_os_timer_t *, int, void (*)(void *), void *);
    1.88 +int sctp_os_timer_stop(sctp_os_timer_t *);
    1.89 +
    1.90 +#define SCTP_OS_TIMER_INIT	sctp_os_timer_init
    1.91 +#define SCTP_OS_TIMER_START	sctp_os_timer_start
    1.92 +#define SCTP_OS_TIMER_STOP	sctp_os_timer_stop
    1.93 +/* MT FIXME: Is the following correct? */
    1.94 +#define SCTP_OS_TIMER_STOP_DRAIN SCTP_OS_TIMER_STOP
    1.95 +#define	SCTP_OS_TIMER_PENDING(tmr) ((tmr)->c_flags & SCTP_CALLOUT_PENDING)
    1.96 +#define	SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE)
    1.97 +#define	SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
    1.98 +
    1.99 +#if defined(__Userspace__)
   1.100 +void sctp_start_timer(void);
   1.101 +#endif
   1.102 +#if defined(__APPLE__)
   1.103 +void sctp_timeout(void *);
   1.104 +#endif
   1.105 +
   1.106 +#endif

mercurial