1 /* $NetBSD: rf_shutdown.c,v 1.8 2001/10/04 15:58:56 oster Exp $ */ 2 /* 3 * rf_shutdown.c 4 */ 5 /* 6 * Copyright (c) 1996 Carnegie-Mellon University. 7 * All rights reserved. 8 * 9 * Author: Jim Zelenka 10 * 11 * Permission to use, copy, modify and distribute this software and 12 * its documentation is hereby granted, provided that both the copyright 13 * notice and this permission notice appear in all copies of the 14 * software, derivative works or modified versions, and any portions 15 * thereof, and that both notices appear in supporting documentation. 16 * 17 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 18 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 19 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 20 * 21 * Carnegie Mellon requests users of this software to return to 22 * 23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 24 * School of Computer Science 25 * Carnegie Mellon University 26 * Pittsburgh PA 15213-3890 27 * 28 * any improvements or extensions that they make and grant Carnegie the 29 * rights to redistribute these changes. 30 */ 31 /* 32 * Maintain lists of cleanup functions. Also, mechanisms for coordinating 33 * thread startup and shutdown. 34 */ 35 36 #include <dev/raidframe/raidframevar.h> 37 38 #include "rf_archs.h" 39 #include "rf_threadstuff.h" 40 #include "rf_shutdown.h" 41 #include "rf_debugMem.h" 42 #include "rf_freelist.h" 43 44 static void 45 rf_FreeShutdownEnt(RF_ShutdownList_t * ent) 46 { 47 FREE(ent, M_RAIDFRAME); 48 } 49 50 int 51 _rf_ShutdownCreate( 52 RF_ShutdownList_t ** listp, 53 void (*cleanup) (void *arg), 54 void *arg, 55 char *file, 56 int line) 57 { 58 RF_ShutdownList_t *ent; 59 60 /* 61 * Have to directly allocate memory here, since we start up before 62 * and shutdown after RAIDframe internal allocation system. 63 */ 64 /* ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t), 65 M_RAIDFRAME, M_WAITOK); */ 66 ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t), 67 M_RAIDFRAME, M_NOWAIT); 68 if (ent == NULL) 69 return (ENOMEM); 70 ent->cleanup = cleanup; 71 ent->arg = arg; 72 ent->file = file; 73 ent->line = line; 74 ent->next = *listp; 75 *listp = ent; 76 return (0); 77 } 78 79 int 80 rf_ShutdownList(RF_ShutdownList_t ** list) 81 { 82 RF_ShutdownList_t *r, *next; 83 char *file; 84 int line; 85 86 for (r = *list; r; r = next) { 87 next = r->next; 88 file = r->file; 89 line = r->line; 90 91 if (rf_shutdownDebug) { 92 printf("call shutdown, created %s:%d\n", file, line); 93 } 94 r->cleanup(r->arg); 95 96 if (rf_shutdownDebug) { 97 printf("completed shutdown, created %s:%d\n", file, line); 98 } 99 rf_FreeShutdownEnt(r); 100 } 101 *list = NULL; 102 return (0); 103 } 104