fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/debug.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define __NSC_GEN__
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "nsc_gen.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "nsc_mem.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "nsc_rmspin.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../nsctl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t _nsc_rmspin_slp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rmlock_t _nsc_lock_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t _nsc_global_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint _nsc_global_lock_init;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_mem_t *_nsc_local_mem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_init_rmlock (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise global locks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called at driver initialisation time to allocate necessary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_init_rmlock()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_rmspin_slp, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_lock_top.next = _nsc_lock_top.prev = &_nsc_lock_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_global_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_global_lock_init = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_deinit_rmlock (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * De-initialise global locks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called at driver unload time to de-allocate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resources.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_deinit_rmlock()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_global_lock_init = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_nsc_global_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_nsc_lock_top.next == &_nsc_lock_top);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(_nsc_lock_top.prev == &_nsc_lock_top);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_lock_all_rm (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take all global locks in address order.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 if _nsc_unlock_all_rm() should be called, or -1.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_lock_all_rm()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rmlock_t *lp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.next; lp != &_nsc_lock_top; lp = lp->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_rm_lock(lp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_unlock_all_rm (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release all global locks in reverse address order.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_unlock_all_rm()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rmlock_t *lp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.prev; lp != &_nsc_lock_top; lp = lp->prev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rm_unlock(lp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rmlock_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock_alloc(char *name, int flag, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate and initialise a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The 'flag' parameter should be either KM_SLEEP or KM_NOSLEEP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depending on whether the caller is willing to sleep while memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is allocated or not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The 'arg' parameter is passed directly to the underlying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mutex_init(9f) function call.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns NULL if lock cannot be allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rmlock_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rm_lock_alloc(char *name, int flag, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rmlock_t *lp, *lk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lk = (nsc_rmlock_t *)nsc_kmem_zalloc(sizeof (*lk),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag, _nsc_local_mem)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&lk->lockp, NULL, MUTEX_DRIVER, arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.next; lp != &_nsc_lock_top; lp = lp->next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(lp->name, name) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lp != &_nsc_lock_top) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&lk->lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(lk, sizeof (*lk));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: rmlock double allocation (%s)", name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lk->name = name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lk->next = _nsc_lock_top.next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lk->prev = &_nsc_lock_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_lock_top.next = lk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lk->next->prev = lk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (lk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock_destroy(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release the global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remarks:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The specified global lock is released and made
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * available for reallocation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rm_lock_dealloc(rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rmlock_t *rmlockp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->next->prev = rmlockp->prev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->prev->next = rmlockp->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rmlockp->child) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: rmlock destroyed when locked (%s)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_do_unlock(rmlockp->child);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->child = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rmlockp->lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_rmspin_slp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(rmlockp, sizeof (*rmlockp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Acquire a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rmlockp is the lock to be acquired.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 (success) or errno. Lock is not acquired if rc != 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rm_lock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rmlockp->lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(! rmlockp->child);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* always use a write-lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_do_lock(1, &rmlockp->child);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->child = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rmlockp->lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_unlock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Unlock a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Calling/Exit State:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rmlockp is the lock to be released.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rm_unlock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rmlockp->child) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rmlockp->lockp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_do_unlock(rmlockp->child);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmlockp->child = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rmlockp->lockp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}