xref: /netbsd-src/sys/dev/raidframe/rf_callback.c (revision dc306354b0b29af51801a7632f1e95265a68cd81)
1 /*	$NetBSD: rf_callback.c,v 1.1 1998/11/13 04:20:26 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@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 /*****************************************************************************************
30  *
31  * callback.c -- code to manipulate callback descriptor
32  *
33  ****************************************************************************************/
34 
35 /* :
36  * Log: rf_callback.c,v
37  * Revision 1.11  1996/06/17 03:18:04  jimz
38  * include shutdown.h for macroized ShutdownCreate
39  *
40  * Revision 1.10  1996/06/10  11:55:47  jimz
41  * Straightened out some per-array/not-per-array distinctions, fixed
42  * a couple bugs related to confusion. Added shutdown lists. Removed
43  * layout shutdown function (now subsumed by shutdown lists).
44  *
45  * Revision 1.9  1996/05/23  21:46:35  jimz
46  * checkpoint in code cleanup (release prep)
47  * lots of types, function names have been fixed
48  *
49  * Revision 1.8  1996/05/18  19:51:34  jimz
50  * major code cleanup- fix syntax, make some types consistent,
51  * add prototypes, clean out dead code, et cetera
52  *
53  * Revision 1.7  1996/05/17  16:30:41  jimz
54  * convert to RF_FREELIST stuff
55  *
56  * Revision 1.6  1995/12/01  15:16:04  root
57  * added copyright info
58  *
59  */
60 
61 #ifndef _KERNEL
62 #ifdef __NetBSD__
63 #include <unistd.h>
64 #endif /* __NetBSD__ */
65 #endif
66 
67 #include "rf_types.h"
68 #include "rf_threadstuff.h"
69 #include "rf_callback.h"
70 #include "rf_debugMem.h"
71 #include "rf_freelist.h"
72 #include "rf_shutdown.h"
73 
74 static RF_FreeList_t *rf_callback_freelist;
75 
76 #define RF_MAX_FREE_CALLBACK 64
77 #define RF_CALLBACK_INC       4
78 #define RF_CALLBACK_INITIAL   4
79 
80 static void rf_ShutdownCallback(void *);
81 static void rf_ShutdownCallback(ignored)
82   void  *ignored;
83 {
84 	RF_FREELIST_DESTROY(rf_callback_freelist,next,(RF_CallbackDesc_t *));
85 }
86 
87 int rf_ConfigureCallback(listp)
88   RF_ShutdownList_t  **listp;
89 {
90 	int rc;
91 
92 	RF_FREELIST_CREATE(rf_callback_freelist, RF_MAX_FREE_CALLBACK,
93 		RF_CALLBACK_INC, sizeof(RF_CallbackDesc_t));
94 	if (rf_callback_freelist == NULL)
95 		return(ENOMEM);
96 	rc = rf_ShutdownCreate(listp, rf_ShutdownCallback, NULL);
97 	if (rc) {
98 		RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
99 			__LINE__, rc);
100 		rf_ShutdownCallback(NULL);
101 		return(rc);
102 	}
103 	RF_FREELIST_PRIME(rf_callback_freelist, RF_CALLBACK_INITIAL,next,
104 		(RF_CallbackDesc_t *));
105 	return(0);
106 }
107 
108 RF_CallbackDesc_t *rf_AllocCallbackDesc()
109 {
110 	RF_CallbackDesc_t *p;
111 
112 	RF_FREELIST_GET(rf_callback_freelist,p,next,(RF_CallbackDesc_t *));
113 	return(p);
114 }
115 
116 void rf_FreeCallbackDesc(p)
117   RF_CallbackDesc_t *p;
118 {
119 	RF_FREELIST_FREE(rf_callback_freelist,p,next);
120 }
121