/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains functions that enables the rpc library to synchronize
* between various threads while they compete for a particular file descriptor.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <errno.h>
#include <syslog.h>
#include <stdlib.h>
#include <unistd.h>
/*
* A block holds an array of maxBlockSize cell and associated recursive locks
*/
typedef struct rpcfd_block {
/* Following functions create and manipulates the dgfd lock object */
void *
rpc_fd_init(void)
{
/*
* Create first chunk of CELLTBLSZ
* (No lock is required for initial creation.)
*/
return (create_block(NULL, 0));
}
/*
* If rpc_fd_lock() fails to acquire a lock, it returns non-zero (ENOMEM).
* (The operation can only fail due to a malloc() failure.)
* The caller of rpc_fd_lock() must call rpc_fd_unlock() even if
* rpc_fd_lock() failed. This keeps _sigoff() and _sigon() balanced.
*
* If search() and create_block() fail for rpc_fd_lock(), then search()
* will fail for rpc_fd_unlock(), so mutex_lock() and mutex_unlock()
* calls will be balanced. In any case, since the mutex is marked
* LOCK_ERRORCHECK, an additional mutex_unlock() does nothing.
*/
int
{
rpcfd_block_t *p;
_sigoff();
(void) mutex_lock(&rpc_fd_list_lock);
if (p != NULL)
}
(void) mutex_unlock(&rpc_fd_list_lock);
return (ENOMEM);
(void) mutex_lock(mp);
return (0);
}
void
{
(void) mutex_lock(&rpc_fd_list_lock);
(void) mutex_unlock(&rpc_fd_list_lock);
(void) mutex_unlock(mp);
_sigon();
}
static rpcfd_block_t *
{
rpcfd_block_t *p;
int i;
p = malloc(sizeof (rpcfd_block_t));
if (p == NULL)
return (NULL);
for (i = 0; i < CELLTBLSZ; i++) {
(void) mutex_init(&p->lock[i],
}
lprev = l;
break;
}
p->next = l;
if (lprev)
if (l)
l->prev = p;
return (p);
}
/*
* Called with rpc_fd_list_lock held.
*/
static mutex_t *
{
rpcfd_block_t *p;
}
return (NULL);
}