17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5cb5caa98Sdjl * Common Development and Distribution License (the "License").
6cb5caa98Sdjl * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*3ea037ccSmichen * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23f166393fSesolom * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * routines to wait and wake up a client waiting on a list for a
307c478bd9Sstevel@tonic-gate * name service request
317c478bd9Sstevel@tonic-gate */
32cb5caa98Sdjl #include "cache.h"
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate int
nscd_wait(nsc_ctx_t * ctx,nsc_db_t * nscdb,nsc_entry_t * entry)35*3ea037ccSmichen nscd_wait(nsc_ctx_t *ctx, nsc_db_t *nscdb, nsc_entry_t *entry)
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate waiter_t mywait;
38*3ea037ccSmichen waiter_t *wchan = &nscdb->db_wait;
39*3ea037ccSmichen
40cb5caa98Sdjl (void) cond_init(&(mywait.w_waitcv), USYNC_THREAD, 0);
41*3ea037ccSmichen mywait.w_key = entry;
42*3ea037ccSmichen mywait.w_signaled = 0;
437c478bd9Sstevel@tonic-gate mywait.w_next = wchan->w_next;
447c478bd9Sstevel@tonic-gate mywait.w_prev = wchan;
457c478bd9Sstevel@tonic-gate if (mywait.w_next)
467c478bd9Sstevel@tonic-gate mywait.w_next->w_prev = &mywait;
477c478bd9Sstevel@tonic-gate wchan->w_next = &mywait;
487c478bd9Sstevel@tonic-gate
49*3ea037ccSmichen (void) mutex_lock(&ctx->stats_mutex);
50*3ea037ccSmichen ctx->stats.wait_count++;
51*3ea037ccSmichen (void) mutex_unlock(&ctx->stats_mutex);
52*3ea037ccSmichen
53*3ea037ccSmichen while (!mywait.w_signaled)
54*3ea037ccSmichen (void) cond_wait(&(mywait.w_waitcv), &nscdb->db_mutex);
557c478bd9Sstevel@tonic-gate if (mywait.w_prev)
567c478bd9Sstevel@tonic-gate mywait.w_prev->w_next = mywait.w_next;
577c478bd9Sstevel@tonic-gate if (mywait.w_next)
587c478bd9Sstevel@tonic-gate mywait.w_next->w_prev = mywait.w_prev;
597c478bd9Sstevel@tonic-gate return (0);
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate int
nscd_signal(nsc_ctx_t * ctx,nsc_db_t * nscdb,nsc_entry_t * entry)63*3ea037ccSmichen nscd_signal(nsc_ctx_t *ctx, nsc_db_t *nscdb, nsc_entry_t *entry)
647c478bd9Sstevel@tonic-gate {
657c478bd9Sstevel@tonic-gate int c = 0;
66*3ea037ccSmichen waiter_t *wchan = &nscdb->db_wait;
677c478bd9Sstevel@tonic-gate waiter_t *tmp = wchan->w_next;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate while (tmp) {
70*3ea037ccSmichen if (tmp->w_key == entry) {
71cb5caa98Sdjl (void) cond_signal(&(tmp->w_waitcv));
72*3ea037ccSmichen tmp->w_signaled = 1;
73*3ea037ccSmichen
74*3ea037ccSmichen (void) mutex_lock(&ctx->stats_mutex);
75*3ea037ccSmichen ctx->stats.wait_count--;
76*3ea037ccSmichen (void) mutex_unlock(&ctx->stats_mutex);
777c478bd9Sstevel@tonic-gate c++;
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate tmp = tmp->w_next;
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate return (c);
837c478bd9Sstevel@tonic-gate }
84