Annotation of sys/dev/raidframe/rf_mcpair.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: rf_mcpair.c,v 1.3 2002/12/16 07:01:04 tdeval Exp $ */
2: /* $NetBSD: rf_mcpair.c,v 1.3 1999/02/05 00:06:13 oster Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Carnegie-Mellon University.
6: * All rights reserved.
7: *
8: * Author: Jim Zelenka
9: *
10: * Permission to use, copy, modify and distribute this software and
11: * its documentation is hereby granted, provided that both the copyright
12: * notice and this permission notice appear in all copies of the
13: * software, derivative works or modified versions, and any portions
14: * thereof, and that both notices appear in supporting documentation.
15: *
16: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19: *
20: * Carnegie Mellon requests users of this software to return to
21: *
22: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23: * School of Computer Science
24: * Carnegie Mellon University
25: * Pittsburgh PA 15213-3890
26: *
27: * any improvements or extensions that they make and grant Carnegie the
28: * rights to redistribute these changes.
29: */
30:
31: /*
32: * rf_mcpair.c
33: * An mcpair is a structure containing a mutex and a condition variable.
34: * It's used to block the current thread until some event occurs.
35: */
36:
37: #include "rf_types.h"
38: #include "rf_threadstuff.h"
39: #include "rf_mcpair.h"
40: #include "rf_debugMem.h"
41: #include "rf_freelist.h"
42: #include "rf_shutdown.h"
43:
44: #include <sys/proc.h>
45:
46: static RF_FreeList_t *rf_mcpair_freelist;
47:
48: #define RF_MAX_FREE_MCPAIR 128
49: #define RF_MCPAIR_INC 16
50: #define RF_MCPAIR_INITIAL 24
51:
52: int rf_init_mcpair(RF_MCPair_t *);
53: void rf_clean_mcpair(RF_MCPair_t *);
54: void rf_ShutdownMCPair(void *);
55:
56:
57: int
58: rf_init_mcpair(RF_MCPair_t *t)
59: {
60: int rc;
61:
62: rc = rf_mutex_init(&t->mutex);
63: if (rc) {
64: RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n",
65: __FILE__, __LINE__, rc);
66: return (rc);
67: }
68: rc = rf_cond_init(&t->cond);
69: if (rc) {
70: RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n",
71: __FILE__, __LINE__, rc);
72: rf_mutex_destroy(&t->mutex);
73: return (rc);
74: }
75: return (0);
76: }
77:
78: void
79: rf_clean_mcpair(RF_MCPair_t *t)
80: {
81: rf_mutex_destroy(&t->mutex);
82: rf_cond_destroy(&t->cond);
83: }
84:
85: void
86: rf_ShutdownMCPair(void *ignored)
87: {
88: RF_FREELIST_DESTROY_CLEAN(rf_mcpair_freelist, next, (RF_MCPair_t *),
89: rf_clean_mcpair);
90: }
91:
92: int
93: rf_ConfigureMCPair(RF_ShutdownList_t **listp)
94: {
95: int rc;
96:
97: RF_FREELIST_CREATE(rf_mcpair_freelist, RF_MAX_FREE_MCPAIR,
98: RF_MCPAIR_INC, sizeof(RF_MCPair_t));
99: rc = rf_ShutdownCreate(listp, rf_ShutdownMCPair, NULL);
100: if (rc) {
101: RF_ERRORMSG3("Unable to add to shutdown list file %s line %d"
102: " rc=%d\n", __FILE__, __LINE__, rc);
103: rf_ShutdownMCPair(NULL);
104: return (rc);
105: }
106: RF_FREELIST_PRIME_INIT(rf_mcpair_freelist, RF_MCPAIR_INITIAL, next,
107: (RF_MCPair_t *), rf_init_mcpair);
108: return (0);
109: }
110:
111: RF_MCPair_t *
112: rf_AllocMCPair(void)
113: {
114: RF_MCPair_t *t;
115:
116: RF_FREELIST_GET_INIT(rf_mcpair_freelist, t, next, (RF_MCPair_t *),
117: rf_init_mcpair);
118: if (t) {
119: t->flag = 0;
120: t->next = NULL;
121: }
122: return (t);
123: }
124:
125: void
126: rf_FreeMCPair(RF_MCPair_t *t)
127: {
128: RF_FREELIST_FREE_CLEAN(rf_mcpair_freelist, t, next, rf_clean_mcpair);
129: }
130:
131: /*
132: * The callback function used to wake you up when you use an mcpair to wait
133: * for something.
134: */
135: void
136: rf_MCPairWakeupFunc(RF_MCPair_t *mcpair)
137: {
138: RF_LOCK_MUTEX(mcpair->mutex);
139: mcpair->flag = 1;
140: #if 0
141: printf("MCPairWakeupFunc called!\n");
142: #endif
143: wakeup(&(mcpair->flag)); /* XXX Does this do anything useful !!! GO */
144: /*
145: * XXX
146: * Looks like the following is needed to truly get the
147: * functionality they were looking for here... This could be a
148: * side-effect of my using a tsleep in the Net- and OpenBSD port
149: * though...
150: * XXX
151: */
152: wakeup(&(mcpair->cond)); /* XXX XXX XXX GO */
153: RF_UNLOCK_MUTEX(mcpair->mutex);
154: }
CVSweb