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