tcp: Cache align ACK queue header.
[dragonfly.git] / sys / sys / socketvar2.h
blob1104d5dba026ecc4bc8b491500bf744ff0e4fdab
1 /*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#)socketvar.h 8.3 (Berkeley) 2/19/95
30 * $FreeBSD: src/sys/sys/socketvar.h,v 1.46.2.10 2003/08/24 08:24:39 hsu Exp $
33 #ifndef _SYS_SOCKETVAR2_H_
34 #define _SYS_SOCKETVAR2_H_
36 #ifndef _SYS_SOCKETVAR_H_
37 #include <sys/socketvar.h>
38 #endif
39 #ifndef _SYS_SYSTM_H_
40 #include <sys/systm.h>
41 #endif
42 #ifndef _SYS_MALLOC_H_
43 #include <sys/malloc.h>
44 #endif
45 #include <machine/atomic.h>
48 * Acquire a lock on a signalsockbuf, sleep if the lock is already held.
49 * The sleep is interruptable unless SSB_NOINTR is set in the ssb.
51 * We also acquire the token on success. This token is used to interlock
52 * frontend/backend operations until the sockbuf itself can be made mpsafe.
54 * Returns 0 on success, non-zero if the lock could not be acquired.
56 static __inline int
57 ssb_lock(struct signalsockbuf *ssb, int wf)
59 uint32_t flags;
61 for (;;) {
62 flags = ssb->ssb_flags;
63 cpu_ccfence();
64 if (flags & SSB_LOCK) {
65 if (wf == M_WAITOK)
66 return _ssb_lock(ssb);
67 return EWOULDBLOCK;
69 if (atomic_cmpset_int(&ssb->ssb_flags, flags, flags|SSB_LOCK)) {
70 lwkt_gettoken(&ssb->ssb_token);
71 return(0);
77 * Release a previously acquired lock on a signalsockbuf.
79 * Interlocked wakeup if SSB_WANT was also set.
81 static __inline void
82 ssb_unlock(struct signalsockbuf *ssb)
84 uint32_t flags;
86 KKASSERT(ssb->ssb_flags & SSB_LOCK);
87 lwkt_reltoken(&ssb->ssb_token);
88 for (;;) {
89 flags = ssb->ssb_flags;
90 cpu_ccfence();
91 if (atomic_cmpset_int(&ssb->ssb_flags, flags,
92 flags & ~(SSB_LOCK | SSB_WANT))) {
93 if (flags & SSB_WANT)
94 wakeup(&ssb->ssb_flags);
95 break;
100 static __inline void
101 sosetstate(struct socket *so, short state)
103 atomic_set_short(&so->so_state, state);
106 static __inline void
107 soclrstate(struct socket *so, short state)
109 atomic_clear_short(&so->so_state, state);
112 static __inline void
113 soreference(struct socket *so)
116 * 0 -> 1 transition will happen on an aborted
117 * socket, which is left on the so_comp queue,
118 * e.g. accept(2) the aborted socket, or when
119 * the listen(2) socket owning the so_comp queue
120 * is closed.
122 atomic_add_int(&so->so_refs, 1);
125 #endif