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