xref: /netbsd-src/share/man/man9/specificdata.9 (revision 6ca7a307a1a9222ae072c5b343f079945c61513b)
1.\"	$NetBSD: specificdata.9,v 1.7 2018/06/15 22:27:40 pgoyette Exp $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd June 16, 2018
31.Dt SPECIFICDATA 9
32.Os
33.Sh NAME
34.Nm specificdata ,
35.Nm specificdata_domain_create ,
36.Nm specificdata_domain_delete ,
37.Nm specificdata_key_create ,
38.Nm specificdata_key_delete ,
39.Nm specificdata_init ,
40.Nm specificdata_fini ,
41.Nm specificdata_getspecific ,
42.Nm specificdata_getspecific_unlocked ,
43.Nm specificdata_setspecific ,
44.Nm specificdata_setspecific_nowait
45.Nd manipulate arbitrary data attached to objects
46.Sh SYNOPSIS
47.In sys/specificdata.h
48.Ft specificdata_domain_t
49.Fn specificdata_domain_create
50.Ft void
51.Fn specificdata_domain_delete "specificdata_domain_t sd"
52.Ft int
53.Fn specificdata_key_create "specificdata_domain_t sd" \
54"specificdata_key_t *keyp" "specificdata_dtor_t dtor"
55.Ft void
56.Fn specificdata_key_delete "specificdata_domain_t sd" "specificdata_key_t key"
57.Ft int
58.Fn specificdata_init "specificdata_domain_t sd" "specificdata_reference *ref"
59.Ft void
60.Fn specificdata_fini "specificdata_domain_t sd" "specificdata_reference *ref"
61.Ft "void *"
62.Fn specificdata_getspecific "specificdata_domain_t sd" \
63"specificdata_reference *ref" "specificdata_key_t key"
64.Ft "void *"
65.Fn specificdata_getspecific_unlocked "specificdata_domain_t sd" \
66"specificdata_reference *ref" "specificdata_key_t key"
67.Ft void
68.Fn specificdata_setspecific "specificdata_domain_t sd" \
69"specificdata_reference *ref" "specificdata_key_t key" "void *data"
70.Ft int
71.Fn specificdata_setspecific_nowait "specificdata_domain_t sd" \
72"specificdata_reference *ref" "specificdata_key_t key" "void *data"
73.Sh DESCRIPTION
74The
75.Nm
76facility provides a mechanism for storing arbitrary data, identified by
77an index key, within containers which exist within the objects associated
78with a particular domain.
79.Sh FUNCTIONS
80.Bl -tag -width abcd
81.It Fn specificdata_domain_create
82Create and initialize a new domain.
83.It Fn specificdata_domain_delete sd
84Deletes domain
85.Fa sd .
86.It Fn specificdata_key_create sd keyp dtor
87Create a new key for
88.Fa sd .
89If the
90.Fa dtor
91argument is not
92.Dv NULL ,
93it specifies a destructor which will be called when a datum associated
94with the specified key is deleted from a container within the
95.Fa sd .
96The unique identifier of the created key is returned in
97.Fa keyp .
98.It Fn specificdata_key_delete sd key
99Delete a key for
100.Fa sd ,
101and delete any associated data from all containers within the domain.
102.It Fn specificdata_init sd ref
103Initialize the container
104.Fa ref
105for use in
106.Fa sd .
107.It Fn specificdata_fini sd ref
108Destroy the container
109.Fa ref ,
110and destroy all of the data stuffed into the container.
111.It Fn specificdata_getspecific sd ref key
112Retrieve the datum from the container
113.Fa ref
114associated with
115.Fa key .
116.It Fn specificdata_getspecific_unlocked sd ref key
117Retrieve the datum from the container
118.Fa ref
119associated with
120.Fa key
121in a lockless manner.
122Care must be taken to ensure that no other thread could cause
123.Fa ref
124to become invalid (i.e. point at the wrong container) by issuing a
125.Fn setspecific
126call or by destroying the container.
127.It Fn specificdata_setspecific sd ref key data
128Store
129.Fa data
130in the container
131.Fa ref
132and associate it with
133.Fa key .
134If a datum has previously been stored, the new value replaces the original;
135the original value is not destroyed, i.e. its destructor is not invoked.
136Note that there is no provision for removing a datum without replacing it.
137.It Fn specificdata_setspecific_nowait sd ref key data
138(Unimplemented)
139.El
140.Sh CODE REFERENCES
141The
142.Nm
143functionality is implemented in
144.Pa sys/kern/subr_specificdata.c .
145.Pp
146The header file
147.In sys/sys/specificdata.h
148describes the public interface.
149.Sh HISTORY
150The
151.Nm
152subsystem first appeared in
153.Nx 4.0 .
154.Sh AUTHORS
155.An -nosplit
156The
157.Nm
158subsystem was written by
159.An Jason Thorpe Aq Mt thorpej@NetBSD.org .
160This manual page was written by
161.An Paul Goyette Aq Mt pgoyette@NetBSD.org .
162