home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / sys / zalloc.h < prev   
Encoding:
C/C++ Source or Header  |  1992-04-22  |  3.3 KB  |  123 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    zalloc.h,v $
  29.  * Revision 2.1  92/04/21  17:15:27  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. #ifndef    _ZALLOC_
  36. #define    _ZALLOC_
  37.  
  38. #include <uxkern/import_mach.h>
  39.  
  40. #include <sys/macro_help.h>
  41.  
  42. /*
  43.  *    A zone is a collection of fixed size blocks for which there
  44.  *    is fast allocation/deallocation access.  Kernel routines can
  45.  *    use zones to manage data structures dynamically, creating a zone
  46.  *    for each type of data structure to be managed.
  47.  *
  48.  */
  49.  
  50. typedef struct zone {
  51.     struct mutex    lock;        /* generic lock */
  52.     int        count;        /* Number of elements used now */
  53.     vm_offset_t    free_elements;
  54.     vm_size_t    cur_size;    /* current memory utilization */
  55.     vm_size_t    max_size;    /* how large can this zone grow */
  56.     vm_size_t    elem_size;    /* size of an element */
  57.     vm_size_t    alloc_size;    /* size used for more memory */
  58.     boolean_t    doing_alloc;    /* is zone expanding now? */
  59.     char        *zone_name;    /* a name for the zone */
  60.     unsigned int
  61.     /* boolean_t */    pageable :1,    /* zone pageable? */
  62.     /* boolean_t */    sleepable :1,    /* sleep if empty? */
  63.     /* boolean_t */ exhaustible :1;    /* merely return if empty? */
  64. } *zone_t;
  65.  
  66. #define        ZONE_NULL    ((zone_t) 0)
  67.  
  68. vm_offset_t    zalloc();
  69. vm_offset_t    zget();
  70. zone_t        zinit();
  71. void        zfree();
  72. void        zchange();
  73.  
  74. #define ADD_TO_ZONE(zone, element) \
  75.     MACRO_BEGIN                            \
  76.         *((vm_offset_t *)(element)) = (zone)->free_elements;    \
  77.         (zone)->free_elements = (vm_offset_t) (element);    \
  78.         (zone)->count--;                    \
  79.     MACRO_END
  80.  
  81. #define REMOVE_FROM_ZONE(zone, ret, type)                \
  82.     MACRO_BEGIN                            \
  83.     (ret) = (type) (zone)->free_elements;                \
  84.     if ((ret) != (type) 0) {                    \
  85.         (zone)->count++;                    \
  86.         (zone)->free_elements = *((vm_offset_t *)(ret));    \
  87.     }                                \
  88.     MACRO_END
  89.  
  90. #define ZFREE(zone, element)        \
  91.     MACRO_BEGIN            \
  92.     register zone_t    z = (zone);    \
  93.                     \
  94.     mutex_lock(&z->lock);        \
  95.     ADD_TO_ZONE(z, element);    \
  96.     mutex_unlock(&z->lock);        \
  97.     MACRO_END
  98.  
  99. #define    ZALLOC(zone, ret, type)            \
  100.     MACRO_BEGIN                \
  101.     register zone_t    z = (zone);        \
  102.                         \
  103.     mutex_lock(&z->lock);            \
  104.     REMOVE_FROM_ZONE(zone, ret, type);    \
  105.     mutex_unlock(&z->lock);            \
  106.     if ((ret) == (type)0)            \
  107.         (ret) = (type)zalloc(z);    \
  108.     MACRO_END
  109.  
  110. #define    ZGET(zone, ret, type)            \
  111.     MACRO_BEGIN                \
  112.     register zone_t    z = (zone);        \
  113.                         \
  114.     mutex_lock(&z->lock);            \
  115.     REMOVE_FROM_ZONE(zone, ret, type);    \
  116.     mutex_unlock(&z->lock);            \
  117.     MACRO_END
  118.  
  119. void        zcram();
  120. void        zone_init();
  121.  
  122. #endif    _ZALLOC_
  123.