webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
sctp_callout.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the project nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifdef __FreeBSD__
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 #endif
35 
36 #ifndef _NETINET_SCTP_CALLOUT_
37 #define _NETINET_SCTP_CALLOUT_
38 
39 /*
40  * NOTE: the following MACROS are required for locking the callout
41  * queue along with a lock/mutex in the OS specific headers and
42  * implementation files::
43  * - SCTP_TIMERQ_LOCK()
44  * - SCTP_TIMERQ_UNLOCK()
45  * - SCTP_TIMERQ_LOCK_INIT()
46  * - SCTP_TIMERQ_LOCK_DESTROY()
47  */
48 
49 #define _SCTP_NEEDS_CALLOUT_ 1
50 
51 #define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
52 
53 #if defined(__Userspace__)
54 #if defined(__Userspace_os_Windows)
55 #define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
56 #define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
57 #define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
58 #define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx))
59 #else
60 #ifdef INVARIANTS
61 #define SCTP_TIMERQ_LOCK() KASSERT(pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx already locked", __func__))
62 #define SCTP_TIMERQ_UNLOCK() KASSERT(pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx not locked", __func__))
63 #else
64 #define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx))
65 #define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx))
66 #endif
67 #define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), &SCTP_BASE_VAR(mtx_attr))
68 #define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx))
69 #endif
70 #endif
71 
72 int sctp_get_tick_count(void);
73 
74 TAILQ_HEAD(calloutlist, sctp_callout);
75 
76 struct sctp_callout {
78  int c_time; /* ticks to the event */
79  void *c_arg; /* function argument */
80  void (*c_func)(void *); /* function to call */
81  int c_flags; /* state of this entry */
82 };
84 
85 #define SCTP_CALLOUT_ACTIVE 0x0002 /* callout is currently active */
86 #define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
87 
89 void sctp_os_timer_start(sctp_os_timer_t *, int, void (*)(void *), void *);
91 
92 #define SCTP_OS_TIMER_INIT sctp_os_timer_init
93 #define SCTP_OS_TIMER_START sctp_os_timer_start
94 #define SCTP_OS_TIMER_STOP sctp_os_timer_stop
95 /* MT FIXME: Is the following correct? */
96 #define SCTP_OS_TIMER_STOP_DRAIN SCTP_OS_TIMER_STOP
97 #define SCTP_OS_TIMER_PENDING(tmr) ((tmr)->c_flags & SCTP_CALLOUT_PENDING)
98 #define SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE)
99 #define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
100 
101 #if defined(__Userspace__)
102 void sctp_start_timer(void);
103 #endif
104 #if defined(__APPLE__)
105 void sctp_timeout(void *);
106 #endif
107 
108 #endif
TAILQ_HEAD(calloutlist, sctp_callout)
void sctp_os_timer_start(sctp_os_timer_t *, int, void(*)(void *), void *)
Definition: sctp_callout.c:87
int c_flags
Definition: sctp_callout.h:81
int sctp_os_timer_stop(sctp_os_timer_t *)
Definition: sctp_callout.c:125
void * c_arg
Definition: sctp_callout.h:79
void
Definition: AVFoundationCFSoftLinking.h:81
void sctp_os_timer_init(sctp_os_timer_t *tmr)
Definition: sctp_callout.c:81
int c_time
Definition: sctp_callout.h:78
Definition: sctp_callout.h:76
TAILQ_ENTRY(sctp_callout) tqe
void(* c_func)(void *)
Definition: sctp_callout.h:80
int sctp_get_tick_count(void)
Definition: sctp_callout.c:64