Remove specificdata_setspecific_nowait() as result of discussion on tech-kern.

Add _lwp_getspecific_by_lwp() to get lwp specific data from other lwp's.
Protected by #ifdef _LWP_API_PRIVATE.

Approved by: Jason Thorpe <thorpej@netbsd.org>
This commit is contained in:
hannken 2006-10-24 10:05:45 +00:00
parent fb72156a3c
commit 8ea60a7f23
3 changed files with 31 additions and 64 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_lwp.c,v 1.46 2006/10/12 01:32:16 christos Exp $ */
/* $NetBSD: kern_lwp.c,v 1.47 2006/10/24 10:05:45 hannken Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,10 +37,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.46 2006/10/12 01:32:16 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.47 2006/10/24 10:05:45 hannken Exp $");
#include "opt_multiprocessor.h"
#define _LWP_API_PRIVATE
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/pool.h>
@ -831,6 +833,14 @@ lwp_getspecific(specificdata_key_t key)
&curlwp->l_specdataref, key));
}
void *
_lwp_getspecific_by_lwp(struct lwp *l, specificdata_key_t key)
{
return (specificdata_getspecific_unlocked(lwp_specificdata_domain,
&l->l_specdataref, key));
}
/*
* lwp_setspecific --
* Set lwp-specific data corresponding to the specified key.

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_specificdata.c,v 1.5 2006/10/12 01:32:18 christos Exp $ */
/* $NetBSD: subr_specificdata.c,v 1.6 2006/10/24 10:05:45 hannken Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -63,7 +63,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_specificdata.c,v 1.5 2006/10/12 01:32:18 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_specificdata.c,v 1.6 2006/10/24 10:05:45 hannken Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@ -115,13 +115,6 @@ specificdata_domain_lock(specificdata_domain_t sd)
lockmgr(&sd->sd_lock, LK_EXCLUSIVE, 0);
}
static int
specificdata_domain_trylock(specificdata_domain_t sd)
{
return (lockmgr(&sd->sd_lock, LK_EXCLUSIVE|LK_NOWAIT, 0));
}
static void
specificdata_domain_unlock(specificdata_domain_t sd)
{
@ -383,15 +376,17 @@ specificdata_getspecific_unlocked(specificdata_domain_t sd __unused,
return (NULL);
}
static int
specificdata_setspecific_internal(specificdata_domain_t sd,
specificdata_reference *ref,
specificdata_key_t key, void *data,
boolean_t waitok)
/*
* specificdata_setspecific --
* Put a datum into a container.
*/
void
specificdata_setspecific(specificdata_domain_t sd,
specificdata_reference *ref,
specificdata_key_t key, void *data)
{
specificdata_container_t sc, newsc;
size_t newnkey, sz;
int error;
ASSERT_SLEEPABLE(NULL, __func__);
@ -401,7 +396,7 @@ specificdata_setspecific_internal(specificdata_domain_t sd,
if (__predict_true(sc != NULL && key < sc->sc_nkey)) {
sc->sc_data[key] = data;
specdataref_unlock(ref);
return (0);
return;
}
specdataref_unlock(ref);
@ -410,26 +405,15 @@ specificdata_setspecific_internal(specificdata_domain_t sd,
* Slow path: need to resize.
*/
if (waitok)
specificdata_domain_lock(sd);
else {
error = specificdata_domain_trylock(sd);
if (error)
return (error);
}
specificdata_domain_lock(sd);
newnkey = sd->sd_nkey;
if (key >= newnkey) {
specificdata_domain_unlock(sd);
panic("specificdata_setspecific");
}
sz = SPECIFICDATA_CONTAINER_BYTESIZE(newnkey);
newsc = kmem_zalloc(sz, waitok ? KM_SLEEP : KM_NOSLEEP);
if (waitok) {
KASSERT(newsc != NULL);
} else if (newsc == NULL) {
specificdata_domain_unlock(sd);
return (EWOULDBLOCK);
}
newsc = kmem_zalloc(sz, KM_SLEEP);
KASSERT(newsc != NULL);
newsc->sc_nkey = newnkey;
specdataref_lock(ref);
@ -445,7 +429,7 @@ specificdata_setspecific_internal(specificdata_domain_t sd,
specdataref_unlock(ref);
specificdata_domain_unlock(sd);
kmem_free(newsc, sz);
return (0);
return;
}
specificdata_container_unlink(sd, sc);
memcpy(newsc->sc_data, sc->sc_data,
@ -460,34 +444,4 @@ specificdata_setspecific_internal(specificdata_domain_t sd,
if (sc != NULL)
kmem_free(sc, SPECIFICDATA_CONTAINER_BYTESIZE(sc->sc_nkey));
return (0);
}
/*
* specificdata_setspecific --
* Put a datum into a container.
*/
void
specificdata_setspecific(specificdata_domain_t sd, specificdata_reference *ref,
specificdata_key_t key, void *data)
{
int rv;
rv = specificdata_setspecific_internal(sd, ref, key, data, TRUE);
KASSERT(rv == 0);
}
/*
* specificdata_setspecific_nowait --
* Put a datum into a container. Caller has indicated that it does
* not want to sleep.
*/
int
specificdata_setspecific_nowait(specificdata_domain_t sd,
specificdata_reference *ref,
specificdata_key_t key, void *data)
{
return (specificdata_setspecific_internal(sd, ref, key, data, FALSE));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lwp.h,v 1.45 2006/10/11 04:51:06 thorpej Exp $ */
/* $NetBSD: lwp.h,v 1.46 2006/10/24 10:05:45 hannken Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -207,6 +207,9 @@ void lwp_specific_key_delete(specificdata_key_t);
void lwp_initspecific(struct lwp *);
void lwp_finispecific(struct lwp *);
void * lwp_getspecific(specificdata_key_t);
#if defined(_LWP_API_PRIVATE)
void * _lwp_getspecific_by_lwp(struct lwp *, specificdata_key_t);
#endif
void lwp_setspecific(specificdata_key_t, void *);
#endif /* _KERNEL */