10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _SYS_SOCKFS_NL7CURI_H
28 #define _SYS_SOCKFS_NL7CURI_H
29
30 #pragma ident "%Z%%M% %I% %E% SMI"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #include <sys/types.h>
37 #include <sys/atomic.h>
38 #include <sys/cmn_err.h>
39 #include <sys/stropts.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
42
43 #undef PROMIF_DEBUG
44
45 /*
46 * Some usefull chararcter macros:
47 */
48
49 #ifndef tolower
50 #define tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) | 0x20 : (c))
51 #endif
66 /*
67 * ref_t - reference type, ...
68 *
69 * Note, all struct's must contain a single ref_t, all must use
70 * kmem_cache, all must use the REF_* macros for free.
71 */
72
73 typedef struct ref_s {
74 uint32_t cnt; /* Reference count */
75 void (*last)(void *); /* Call-back for last ref */
76 kmem_cache_t *kmc; /* Container allocator cache */
77 } ref_t;
78
79 #define REF_INIT(container, count, inactive, kmem) { \
80 (container)->ref.cnt = (count); \
81 (container)->ref.last = (void (*)(void *))((inactive)); \
82 (container)->ref.kmc = (kmem); \
83 }
84
85 #define REF_HOLD(container) { \
86 atomic_add_32(&(container)->ref.cnt, 1); \
87 ASSERT((container)->ref.cnt != 0); \
88 }
89
90 #define REF_RELE(container) { \
91 if (atomic_add_32_nv(&(container)->ref.cnt, -1) == 0) { \
92 (container)->ref.last((container)); \
93 kmem_cache_free((container)->ref.kmc, (container)); \
94 } \
95 }
96
97 #define REF_COUNT(container) (container)->ref.cnt
98
99 #define REF_ASSERT(container, count) \
100 ASSERT((container)->ref.cnt == (count));
101
102 /*
103 * str_t - string type, used to access a an arbitrary span of a char[].
104 */
105
106 typedef struct str_s {
107 char *cp; /* Char pointer current char */
108 char *ep; /* Char pointer past end of string */
109 } str_t;
110
111 /*
|
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _SYS_SOCKFS_NL7CURI_H
28 #define _SYS_SOCKFS_NL7CURI_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <sys/types.h>
35 #include <sys/atomic.h>
36 #include <sys/cmn_err.h>
37 #include <sys/stropts.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
40
41 #undef PROMIF_DEBUG
42
43 /*
44 * Some usefull chararcter macros:
45 */
46
47 #ifndef tolower
48 #define tolower(c) ((c) >= 'A' && (c) <= 'Z' ? (c) | 0x20 : (c))
49 #endif
64 /*
65 * ref_t - reference type, ...
66 *
67 * Note, all struct's must contain a single ref_t, all must use
68 * kmem_cache, all must use the REF_* macros for free.
69 */
70
71 typedef struct ref_s {
72 uint32_t cnt; /* Reference count */
73 void (*last)(void *); /* Call-back for last ref */
74 kmem_cache_t *kmc; /* Container allocator cache */
75 } ref_t;
76
77 #define REF_INIT(container, count, inactive, kmem) { \
78 (container)->ref.cnt = (count); \
79 (container)->ref.last = (void (*)(void *))((inactive)); \
80 (container)->ref.kmc = (kmem); \
81 }
82
83 #define REF_HOLD(container) { \
84 atomic_inc_32(&(container)->ref.cnt); \
85 ASSERT((container)->ref.cnt != 0); \
86 }
87
88 #define REF_RELE(container) { \
89 if (atomic_dec_32_nv(&(container)->ref.cnt) == 0) { \
90 (container)->ref.last((container)); \
91 kmem_cache_free((container)->ref.kmc, (container)); \
92 } \
93 }
94
95 #define REF_COUNT(container) (container)->ref.cnt
96
97 #define REF_ASSERT(container, count) \
98 ASSERT((container)->ref.cnt == (count));
99
100 /*
101 * str_t - string type, used to access a an arbitrary span of a char[].
102 */
103
104 typedef struct str_s {
105 char *cp; /* Char pointer current char */
106 char *ep; /* Char pointer past end of string */
107 } str_t;
108
109 /*
|