Home | History | Annotate | Line # | Download | only in raidframe
rf_mcpair.c revision 1.10
      1 /*	$NetBSD: rf_mcpair.c,v 1.10 2003/12/29 04:33:31 oster Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Jim Zelenka
      7  *
      8  * Permission to use, copy, modify and distribute this software and
      9  * its documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  */
     28 
     29 /* rf_mcpair.c
     30  * an mcpair is a structure containing a mutex and a condition variable.
     31  * it's used to block the current thread until some event occurs.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: rf_mcpair.c,v 1.10 2003/12/29 04:33:31 oster Exp $");
     36 
     37 #include <dev/raidframe/raidframevar.h>
     38 
     39 #include "rf_archs.h"
     40 #include "rf_threadstuff.h"
     41 #include "rf_mcpair.h"
     42 #include "rf_debugMem.h"
     43 #include "rf_general.h"
     44 #include "rf_shutdown.h"
     45 
     46 #include <sys/pool.h>
     47 #include <sys/proc.h>
     48 
     49 static struct pool rf_mcpair_pool;
     50 #define RF_MAX_FREE_MCPAIR 128
     51 #define RF_MCPAIR_INC       16
     52 #define RF_MCPAIR_INITIAL   24
     53 
     54 static void rf_ShutdownMCPair(void *);
     55 
     56 static void
     57 rf_ShutdownMCPair(ignored)
     58 	void   *ignored;
     59 {
     60 	pool_destroy(&rf_mcpair_pool);
     61 }
     62 
     63 int
     64 rf_ConfigureMCPair(listp)
     65 	RF_ShutdownList_t **listp;
     66 {
     67 	int     rc;
     68 
     69 	pool_init(&rf_mcpair_pool, sizeof(RF_MCPair_t), 0, 0, 0,
     70 		  "rf_mcpair_pl", NULL);
     71 	pool_sethiwat(&rf_mcpair_pool, RF_MAX_FREE_MCPAIR);
     72 	pool_prime(&rf_mcpair_pool, RF_MCPAIR_INITIAL);
     73 
     74 	rc = rf_ShutdownCreate(listp, rf_ShutdownMCPair, NULL);
     75 	if (rc) {
     76 		rf_print_unable_to_add_shutdown(__FILE__, __LINE__, rc);
     77 		rf_ShutdownMCPair(NULL);
     78 		return (rc);
     79 	}
     80 
     81 	return (0);
     82 }
     83 
     84 RF_MCPair_t *
     85 rf_AllocMCPair()
     86 {
     87 	RF_MCPair_t *t;
     88 
     89 	t = pool_get(&rf_mcpair_pool, PR_WAITOK);
     90 	if (t) {
     91 		simple_lock_init(&t->mutex);
     92 		t->cond = 0;
     93 		t->flag = 0;
     94 		t->next = NULL;
     95 	}
     96 	return (t);
     97 }
     98 
     99 void
    100 rf_FreeMCPair(t)
    101 	RF_MCPair_t *t;
    102 {
    103 	pool_put(&rf_mcpair_pool, t);
    104 }
    105 /* the callback function used to wake you up when you use an mcpair to wait for something */
    106 void
    107 rf_MCPairWakeupFunc(mcpair)
    108 	RF_MCPair_t *mcpair;
    109 {
    110 	RF_LOCK_MUTEX(mcpair->mutex);
    111 	mcpair->flag = 1;
    112 	wakeup(&(mcpair->cond));
    113 	RF_UNLOCK_MUTEX(mcpair->mutex);
    114 }
    115