2006-11-16 04:32:37 +03:00
|
|
|
/* $NetBSD: rf_mcpair.c,v 1.21 2006/11/16 01:33:23 christos Exp $ */
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Jim Zelenka
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* rf_mcpair.c
|
|
|
|
* an mcpair is a structure containing a mutex and a condition variable.
|
|
|
|
* it's used to block the current thread until some event occurs.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:11:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-16 04:32:37 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rf_mcpair.c,v 1.21 2006/11/16 01:33:23 christos Exp $");
|
2001-11-13 10:11:12 +03:00
|
|
|
|
2001-10-04 19:58:51 +04:00
|
|
|
#include <dev/raidframe/raidframevar.h>
|
|
|
|
|
2001-09-26 06:52:57 +04:00
|
|
|
#include "rf_archs.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_threadstuff.h"
|
|
|
|
#include "rf_mcpair.h"
|
|
|
|
#include "rf_debugMem.h"
|
2003-12-29 06:33:47 +03:00
|
|
|
#include "rf_general.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_shutdown.h"
|
2004-03-08 01:15:19 +03:00
|
|
|
#include "rf_netbsd.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2003-12-29 06:33:47 +03:00
|
|
|
#include <sys/pool.h>
|
1998-11-13 07:20:26 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#define RF_MAX_FREE_MCPAIR 128
|
2004-03-05 05:53:55 +03:00
|
|
|
#define RF_MIN_FREE_MCPAIR 24
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
static void rf_ShutdownMCPair(void *);
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
rf_ShutdownMCPair(void *ignored)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
2004-03-08 01:15:19 +03:00
|
|
|
pool_destroy(&rf_pools.mcpair);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
int
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_ConfigureMCPair(RF_ShutdownList_t **listp)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
|
2004-03-08 01:15:19 +03:00
|
|
|
rf_pool_init(&rf_pools.mcpair, sizeof(RF_MCPair_t),
|
|
|
|
"rf_mcpair_pl", RF_MIN_FREE_MCPAIR, RF_MAX_FREE_MCPAIR);
|
2004-02-29 07:03:50 +03:00
|
|
|
rf_ShutdownCreate(listp, rf_ShutdownMCPair, NULL);
|
2003-12-29 06:33:47 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_MCPair_t *
|
|
|
|
rf_AllocMCPair()
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
RF_MCPair_t *t;
|
|
|
|
|
2004-03-08 01:15:19 +03:00
|
|
|
t = pool_get(&rf_pools.mcpair, PR_WAITOK);
|
2004-03-02 22:36:21 +03:00
|
|
|
simple_lock_init(&t->mutex);
|
|
|
|
t->cond = 0;
|
|
|
|
t->flag = 0;
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
return (t);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_FreeMCPair(RF_MCPair_t *t)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
2004-03-08 01:15:19 +03:00
|
|
|
pool_put(&rf_pools.mcpair, t);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
2003-12-29 07:34:36 +03:00
|
|
|
|
|
|
|
/* the callback function used to wake you up when you use an mcpair to
|
|
|
|
wait for something */
|
2005-02-27 03:26:58 +03:00
|
|
|
void
|
2003-12-31 00:59:03 +03:00
|
|
|
rf_MCPairWakeupFunc(RF_MCPair_t *mcpair)
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
RF_LOCK_MUTEX(mcpair->mutex);
|
|
|
|
mcpair->flag = 1;
|
2000-09-11 06:23:14 +04:00
|
|
|
wakeup(&(mcpair->cond));
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_UNLOCK_MUTEX(mcpair->mutex);
|
|
|
|
}
|