Home | History | Annotate | Line # | Download | only in raidframe
rf_shutdown.c revision 1.7
      1 /*	$NetBSD: rf_shutdown.c,v 1.7 2001/09/26 02:52:57 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 (at) 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 "rf_types.h"
     37 #include "rf_archs.h"
     38 #include "rf_threadstuff.h"
     39 #include "rf_shutdown.h"
     40 #include "rf_debugMem.h"
     41 #include "rf_freelist.h"
     42 
     43 static void
     44 rf_FreeShutdownEnt(RF_ShutdownList_t * ent)
     45 {
     46 	FREE(ent, M_RAIDFRAME);
     47 }
     48 
     49 int
     50 _rf_ShutdownCreate(
     51     RF_ShutdownList_t ** listp,
     52     void (*cleanup) (void *arg),
     53     void *arg,
     54     char *file,
     55     int line)
     56 {
     57 	RF_ShutdownList_t *ent;
     58 
     59 	/*
     60          * Have to directly allocate memory here, since we start up before
     61          * and shutdown after RAIDframe internal allocation system.
     62          */
     63 	/* 	ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t),
     64 		M_RAIDFRAME, M_WAITOK); */
     65 	ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t),
     66 					   M_RAIDFRAME, M_NOWAIT);
     67 	if (ent == NULL)
     68 		return (ENOMEM);
     69 	ent->cleanup = cleanup;
     70 	ent->arg = arg;
     71 	ent->file = file;
     72 	ent->line = line;
     73 	ent->next = *listp;
     74 	*listp = ent;
     75 	return (0);
     76 }
     77 
     78 int
     79 rf_ShutdownList(RF_ShutdownList_t ** list)
     80 {
     81 	RF_ShutdownList_t *r, *next;
     82 	char   *file;
     83 	int     line;
     84 
     85 	for (r = *list; r; r = next) {
     86 		next = r->next;
     87 		file = r->file;
     88 		line = r->line;
     89 
     90 		if (rf_shutdownDebug) {
     91 			printf("call shutdown, created %s:%d\n", file, line);
     92 		}
     93 		r->cleanup(r->arg);
     94 
     95 		if (rf_shutdownDebug) {
     96 			printf("completed shutdown, created %s:%d\n", file, line);
     97 		}
     98 		rf_FreeShutdownEnt(r);
     99 	}
    100 	*list = NULL;
    101 	return (0);
    102 }
    103