Home | History | Annotate | Line # | Download | only in raidframe
rf_callback.c revision 1.2
      1 /*	$NetBSD: rf_callback.c,v 1.2 1999/01/26 02:33:50 oster Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Jim Zelenka
      7  *
      8  * Permission to use, copy, modify and distribute this software and
      9  * its documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  */
     28 
     29 /*****************************************************************************************
     30  *
     31  * callback.c -- code to manipulate callback descriptor
     32  *
     33  ****************************************************************************************/
     34 
     35 
     36 #include "rf_types.h"
     37 #include "rf_threadstuff.h"
     38 #include "rf_callback.h"
     39 #include "rf_debugMem.h"
     40 #include "rf_freelist.h"
     41 #include "rf_shutdown.h"
     42 
     43 static RF_FreeList_t *rf_callback_freelist;
     44 
     45 #define RF_MAX_FREE_CALLBACK 64
     46 #define RF_CALLBACK_INC       4
     47 #define RF_CALLBACK_INITIAL   4
     48 
     49 static void rf_ShutdownCallback(void *);
     50 static void rf_ShutdownCallback(ignored)
     51   void  *ignored;
     52 {
     53 	RF_FREELIST_DESTROY(rf_callback_freelist,next,(RF_CallbackDesc_t *));
     54 }
     55 
     56 int rf_ConfigureCallback(listp)
     57   RF_ShutdownList_t  **listp;
     58 {
     59 	int rc;
     60 
     61 	RF_FREELIST_CREATE(rf_callback_freelist, RF_MAX_FREE_CALLBACK,
     62 		RF_CALLBACK_INC, sizeof(RF_CallbackDesc_t));
     63 	if (rf_callback_freelist == NULL)
     64 		return(ENOMEM);
     65 	rc = rf_ShutdownCreate(listp, rf_ShutdownCallback, NULL);
     66 	if (rc) {
     67 		RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
     68 			__LINE__, rc);
     69 		rf_ShutdownCallback(NULL);
     70 		return(rc);
     71 	}
     72 	RF_FREELIST_PRIME(rf_callback_freelist, RF_CALLBACK_INITIAL,next,
     73 		(RF_CallbackDesc_t *));
     74 	return(0);
     75 }
     76 
     77 RF_CallbackDesc_t *rf_AllocCallbackDesc()
     78 {
     79 	RF_CallbackDesc_t *p;
     80 
     81 	RF_FREELIST_GET(rf_callback_freelist,p,next,(RF_CallbackDesc_t *));
     82 	return(p);
     83 }
     84 
     85 void rf_FreeCallbackDesc(p)
     86   RF_CallbackDesc_t *p;
     87 {
     88 	RF_FREELIST_FREE(rf_callback_freelist,p,next);
     89 }
     90