subr_lwp_specificdata.c revision 1.2.6.2 1 1.2.6.2 yamt /* $NetBSD: subr_lwp_specificdata.c,v 1.2.6.2 2010/08/11 22:54:42 yamt Exp $ */
2 1.2.6.2 yamt
3 1.2.6.2 yamt /*-
4 1.2.6.2 yamt * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.2.6.2 yamt * All rights reserved.
6 1.2.6.2 yamt *
7 1.2.6.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2.6.2 yamt * modification, are permitted provided that the following conditions
9 1.2.6.2 yamt * are met:
10 1.2.6.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2.6.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.6.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2.6.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2.6.2 yamt *
16 1.2.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.2.6.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.2.6.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.2.6.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.2.6.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.2.6.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.2.6.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.2.6.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.2.6.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.2.6.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.2.6.2 yamt * POSSIBILITY OF SUCH DAMAGE.
27 1.2.6.2 yamt */
28 1.2.6.2 yamt
29 1.2.6.2 yamt #define _LWP_API_PRIVATE
30 1.2.6.2 yamt
31 1.2.6.2 yamt #include <sys/cdefs.h>
32 1.2.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: subr_lwp_specificdata.c,v 1.2.6.2 2010/08/11 22:54:42 yamt Exp $");
33 1.2.6.2 yamt
34 1.2.6.2 yamt #include <sys/param.h>
35 1.2.6.2 yamt #include <sys/lwp.h>
36 1.2.6.2 yamt #include <sys/specificdata.h>
37 1.2.6.2 yamt
38 1.2.6.2 yamt static specificdata_domain_t lwp_specificdata_domain;
39 1.2.6.2 yamt
40 1.2.6.2 yamt void
41 1.2.6.2 yamt lwpinit_specificdata(void)
42 1.2.6.2 yamt {
43 1.2.6.2 yamt
44 1.2.6.2 yamt lwp_specificdata_domain = specificdata_domain_create();
45 1.2.6.2 yamt KASSERT(lwp_specificdata_domain != NULL);
46 1.2.6.2 yamt }
47 1.2.6.2 yamt
48 1.2.6.2 yamt /*
49 1.2.6.2 yamt * lwp_specific_key_create --
50 1.2.6.2 yamt * Create a key for subsystem lwp-specific data.
51 1.2.6.2 yamt */
52 1.2.6.2 yamt int
53 1.2.6.2 yamt lwp_specific_key_create(specificdata_key_t *keyp, specificdata_dtor_t dtor)
54 1.2.6.2 yamt {
55 1.2.6.2 yamt
56 1.2.6.2 yamt return (specificdata_key_create(lwp_specificdata_domain, keyp, dtor));
57 1.2.6.2 yamt }
58 1.2.6.2 yamt
59 1.2.6.2 yamt /*
60 1.2.6.2 yamt * lwp_specific_key_delete --
61 1.2.6.2 yamt * Delete a key for subsystem lwp-specific data.
62 1.2.6.2 yamt */
63 1.2.6.2 yamt void
64 1.2.6.2 yamt lwp_specific_key_delete(specificdata_key_t key)
65 1.2.6.2 yamt {
66 1.2.6.2 yamt
67 1.2.6.2 yamt specificdata_key_delete(lwp_specificdata_domain, key);
68 1.2.6.2 yamt }
69 1.2.6.2 yamt
70 1.2.6.2 yamt /*
71 1.2.6.2 yamt * lwp_initspecific --
72 1.2.6.2 yamt * Initialize an LWP's specificdata container.
73 1.2.6.2 yamt */
74 1.2.6.2 yamt void
75 1.2.6.2 yamt lwp_initspecific(struct lwp *l)
76 1.2.6.2 yamt {
77 1.2.6.2 yamt int error;
78 1.2.6.2 yamt
79 1.2.6.2 yamt error = specificdata_init(lwp_specificdata_domain, &l->l_specdataref);
80 1.2.6.2 yamt KASSERT(error == 0);
81 1.2.6.2 yamt }
82 1.2.6.2 yamt
83 1.2.6.2 yamt /*
84 1.2.6.2 yamt * lwp_finispecific --
85 1.2.6.2 yamt * Finalize an LWP's specificdata container.
86 1.2.6.2 yamt */
87 1.2.6.2 yamt void
88 1.2.6.2 yamt lwp_finispecific(struct lwp *l)
89 1.2.6.2 yamt {
90 1.2.6.2 yamt
91 1.2.6.2 yamt specificdata_fini(lwp_specificdata_domain, &l->l_specdataref);
92 1.2.6.2 yamt }
93 1.2.6.2 yamt
94 1.2.6.2 yamt /*
95 1.2.6.2 yamt * lwp_getspecific --
96 1.2.6.2 yamt * Return lwp-specific data corresponding to the specified key.
97 1.2.6.2 yamt *
98 1.2.6.2 yamt * Note: LWP specific data is NOT INTERLOCKED. An LWP should access
99 1.2.6.2 yamt * only its OWN SPECIFIC DATA. If it is necessary to access another
100 1.2.6.2 yamt * LWP's specifc data, care must be taken to ensure that doing so
101 1.2.6.2 yamt * would not cause internal data structure inconsistency (i.e. caller
102 1.2.6.2 yamt * can guarantee that the target LWP is not inside an lwp_getspecific()
103 1.2.6.2 yamt * or lwp_setspecific() call).
104 1.2.6.2 yamt */
105 1.2.6.2 yamt void *
106 1.2.6.2 yamt lwp_getspecific(specificdata_key_t key)
107 1.2.6.2 yamt {
108 1.2.6.2 yamt
109 1.2.6.2 yamt return (specificdata_getspecific_unlocked(lwp_specificdata_domain,
110 1.2.6.2 yamt &curlwp->l_specdataref, key));
111 1.2.6.2 yamt }
112 1.2.6.2 yamt
113 1.2.6.2 yamt void *
114 1.2.6.2 yamt _lwp_getspecific_by_lwp(struct lwp *l, specificdata_key_t key)
115 1.2.6.2 yamt {
116 1.2.6.2 yamt
117 1.2.6.2 yamt return (specificdata_getspecific_unlocked(lwp_specificdata_domain,
118 1.2.6.2 yamt &l->l_specdataref, key));
119 1.2.6.2 yamt }
120 1.2.6.2 yamt
121 1.2.6.2 yamt /*
122 1.2.6.2 yamt * lwp_setspecific --
123 1.2.6.2 yamt * Set lwp-specific data corresponding to the specified key.
124 1.2.6.2 yamt */
125 1.2.6.2 yamt void
126 1.2.6.2 yamt lwp_setspecific(specificdata_key_t key, void *data)
127 1.2.6.2 yamt {
128 1.2.6.2 yamt
129 1.2.6.2 yamt specificdata_setspecific(lwp_specificdata_domain,
130 1.2.6.2 yamt &curlwp->l_specdataref, key, data);
131 1.2.6.2 yamt }
132