Home | History | Annotate | Line # | Download | only in raidframe
rf_shutdown.c revision 1.1
      1 /*	$NetBSD: rf_shutdown.c,v 1.1 1998/11/13 04:20:34 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 #ifdef KERNEL
     46   FREE(ent, M_DEVBUF);
     47 #else /* KERNEL */
     48   free(ent);
     49 #endif /* KERNEL */
     50 }
     51 
     52 int _rf_ShutdownCreate(
     53   RF_ShutdownList_t  **listp,
     54   void               (*cleanup)(void *arg),
     55   void                *arg,
     56   char                *file,
     57   int                  line)
     58 {
     59   RF_ShutdownList_t *ent;
     60 
     61   /*
     62    * Have to directly allocate memory here, since we start up before
     63    * and shutdown after RAIDframe internal allocation system.
     64    */
     65 #ifdef KERNEL
     66   ent = (RF_ShutdownList_t *)malloc( sizeof(RF_ShutdownList_t), M_DEVBUF, M_WAITOK);
     67 #if 0
     68   MALLOC(ent, RF_ShutdownList_t *, sizeof(RF_ShutdownList_t), M_DEVBUF, M_WAITOK);
     69 #endif
     70 #else /* KERNEL */
     71   ent = (RF_ShutdownList_t *)malloc(sizeof(RF_ShutdownList_t));
     72 #endif /* KERNEL */
     73   if (ent == NULL)
     74     return(ENOMEM);
     75   ent->cleanup = cleanup;
     76   ent->arg = arg;
     77   ent->file = file;
     78   ent->line = line;
     79   ent->next = *listp;
     80   *listp = ent;
     81   return(0);
     82 }
     83 
     84 int rf_ShutdownList(RF_ShutdownList_t **list)
     85 {
     86   RF_ShutdownList_t *r, *next;
     87   char *file;
     88   int line;
     89 
     90   for(r=*list;r;r=next) {
     91     next = r->next;
     92     file = r->file;
     93     line = r->line;
     94 
     95     if (rf_shutdownDebug) {
     96       int tid;
     97       rf_get_threadid(tid);
     98       printf("[%d] call shutdown, created %s:%d\n", tid, file, line);
     99     }
    100 
    101     r->cleanup(r->arg);
    102 
    103     if (rf_shutdownDebug) {
    104       int tid;
    105       rf_get_threadid(tid);
    106       printf("[%d] completed shutdown, created %s:%d\n", tid, file, line);
    107     }
    108 
    109     rf_FreeShutdownEnt(r);
    110   }
    111   *list = NULL;
    112   return(0);
    113 }
    114