- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / sys / sys / sysref2.h
blobce9bf0871a82284230288189f793310d82ba6b0b
1 /*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sys/sys/sysref2.h,v 1.2 2007/05/06 19:23:33 dillon Exp $
37 * System resource registration, reference counter, and allocation
38 * management subsystem.
40 * All major system resources use this structure and API to associate
41 * a machine-unique sysref with a major system resource structure, to
42 * reference count that structure, to register the structure and provide
43 * a dictionary lookup feature for remote access, and to provide an
44 * allocation and release backend.
47 #ifndef _SYS_SYSREF2_H_
48 #define _SYS_SYSREF2_H_
50 #ifndef _SYS_SYSREF_H_
51 #include <sys/sysref.h>
52 #endif
53 #ifndef _MACHINE_ATOMIC_H_
54 #include <machine/atomic.h>
55 #endif
57 void _sysref_put(struct sysref *);
60 * Normally only 1+ transitions can occur. Note that a negative ref count
61 * is used as a marker to indicate that a structure is undergoing deletion
62 * and that temporary refs during the process of deletion may occur.
64 * The get interface is the primary reference counting interface.
66 static __inline
67 void
68 sysref_get(struct sysref *sr)
70 atomic_add_int(&sr->refcnt, 1);
74 * 1->0 transitions, and transitions occuring with negative ref counts,
75 * require special handling. All other transitions can be done with a
76 * trivial locked bus cycle.
78 static __inline
79 void
80 sysref_put(struct sysref *sr)
82 int count = sr->refcnt;
84 if (count <= 1 || atomic_cmpset_int(&sr->refcnt, count, count - 1) == 0)
85 _sysref_put(sr);
89 * Return true of the object is fully active
91 static __inline
92 int
93 sysref_isactive(struct sysref *sr)
95 return(sr->refcnt > 0);
99 * Return true of the object is being deactivated
101 static __inline
103 sysref_isinactive(struct sysref *sr)
105 return(sr->refcnt <= 0);
109 * Return true if we control the last deactivation ref on the object
111 static __inline
113 sysref_islastdeactivation(struct sysref *sr)
115 return(sr->refcnt == -0x40000000);
118 #ifdef _KERNEL
120 void sysref_init(struct sysref *sr, struct sysref_class *);
121 void *sysref_alloc(struct sysref_class *class);
122 void sysref_activate(struct sysref *);
124 #endif
126 #endif