1 /* $OpenBSD: rf_callback.c,v 1.3 2002/12/16 07:01:03 tdeval Exp $ */
2 /* $NetBSD: rf_callback.c,v 1.3 1999/02/05 00:06:06 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 *
33 * rf_callback.c -- Code to manipulate callback descriptor.
34 *
35 *****************************************************************************/
36
37
38 #include "rf_types.h"
39 #include "rf_threadstuff.h"
40 #include "rf_callback.h"
41 #include "rf_debugMem.h"
42 #include "rf_freelist.h"
43 #include "rf_shutdown.h"
44
45 static RF_FreeList_t *rf_callback_freelist;
46
47 void rf_ShutdownCallback(void *);
48
49 #define RF_MAX_FREE_CALLBACK 64
50 #define RF_CALLBACK_INC 4
51 #define RF_CALLBACK_INITIAL 4
52
53 void
54 rf_ShutdownCallback(void *ignored)
55 {
56 RF_FREELIST_DESTROY(rf_callback_freelist, next, (RF_CallbackDesc_t *));
57 }
58
59 int
60 rf_ConfigureCallback(RF_ShutdownList_t **listp)
61 {
62 int rc;
63
64 RF_FREELIST_CREATE(rf_callback_freelist, RF_MAX_FREE_CALLBACK,
65 RF_CALLBACK_INC, sizeof(RF_CallbackDesc_t));
66 if (rf_callback_freelist == NULL)
67 return (ENOMEM);
68 rc = rf_ShutdownCreate(listp, rf_ShutdownCallback, NULL);
69 if (rc) {
70 RF_ERRORMSG3("Unable to add to shutdown list file %s line %d"
71 " rc=%d.\n", __FILE__, __LINE__, rc);
72 rf_ShutdownCallback(NULL);
73 return (rc);
74 }
75 RF_FREELIST_PRIME(rf_callback_freelist, RF_CALLBACK_INITIAL, next,
76 (RF_CallbackDesc_t *));
77 return (0);
78 }
79
80 RF_CallbackDesc_t *
81 rf_AllocCallbackDesc(void)
82 {
83 RF_CallbackDesc_t *p;
84
85 RF_FREELIST_GET(rf_callback_freelist, p, next, (RF_CallbackDesc_t *));
86 return (p);
87 }
88
89 void
90 rf_FreeCallbackDesc(RF_CallbackDesc_t *p)
91 {
92 RF_FREELIST_FREE(rf_callback_freelist, p, next);
93 }