home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / MsgOps / bufferCode.c next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  4.4 KB  |  131 lines

  1.  
  2. /* File: Eden/Kernel/MsgOps/BufferCode.c */
  3.  
  4. /*
  5.  * $Header:   /u1/Eden/Kernel/MsgOps/RCS/BufferCode.v  Revision 1.10 85/03/14 19:04:23  eric Exp$
  6.  * INTERFACE:    Defined by exported procedures.
  7.  *
  8.  * FUNCTION:    Provides the Message Module Buffer Services.
  9.  *              These services consist of the management of
  10.  *              small packets of memory allocated in 4-word
  11.  *              chunks.
  12.  *
  13.  * IMPORTS:    Eden/Source/MsgOps/Types.h,
  14.  *              Eden/ErrCodes/MMcodes.h,
  15.  *              Eden/Source/MsgOps/BufferTypes.h,
  16.  *              malloc, free,
  17.  *              Eden/Source/ProcessA/Events.h.
  18.  *
  19.  * EXPORTS:    MMAllocateData, MMDeallocateData.
  20.  *
  21.  * DESIGN:      Currently implemented using Almes' malloc, modified to be
  22.  *              optimal for message sizes. 
  23.  *
  24.  *              
  25.  * $Log:    /u1/Eden/Source/MsgOps/RCS/BufferCode.v $
  26.  * Revision 1.10 85/03/14  00:00:30  eric
  27.  * Modified trace level.
  28.  *
  29.  * Revision 1.9  84/11/29  19:04:23  schwartz
  30.  * Changed all calls to malloc so they don't call HoldSigs and ReleaseSigs
  31.  * before and after, since this is now done in (Almes' version of) malloc.
  32.  *
  33.  * Revision 1.8  83/10/14  17:17:09  mager
  34.  * Changed xalloc back to malloc, and revised library malloc routine.
  35.  * 
  36.  * Revision 1.7  83/10/14  16:35:23  mager
  37.  * Changed calls to malloc and free with xalloc and xfree.
  38.  * 
  39.  * Revision 1.5  83/02/25  12:14:13  cady
  40.  * Added new trace levels.
  41.  * 
  42.  * Revision 1.4  83/02/24  16:39:13  cady
  43.  * Replaced conditional debug trace with dynamic trace.
  44.  * Added conditional Kernel compilation.
  45.  * 
  46.  * Revision 1.3  83/02/22  12:05:16  cady
  47.  * Replaced #if Debug with #ifdef Debug.
  48.  * 
  49.  * Revision 1.2  83/01/04  15:12:45  cady
  50.  * Revised include file specification.
  51.  * 
  52.  * Revision 1.1  83/01/03  10:59:40  cady
  53.  * Initial revision
  54.  * 
  55.  * 4-Nov-1982    Initial implementation. S. Cady
  56.  */
  57.  
  58. /****************************************************************/
  59. /*                                                              */
  60. /*                  Message Module Buffer Library               */
  61. /*                                                              */
  62. /****************************************************************/
  63.  
  64. #include "Kernel/h/system.h"
  65. #include "Kernel/h/mmCodes.h"
  66. #include "Kernel/h/mmBufTypes.h"
  67.  
  68. /*  Data buffer size (in bytes) increment */
  69.  
  70. #define CHUNKSIZE   16
  71.  
  72.  
  73. /****************************************************************/
  74. /*                                                              */
  75. /*                      MMAllocateData                          */
  76. /*                                                              */
  77. /*  MMAllocateData allocates a buffer of at least fSize bytes   */
  78. /*  and returns a pointer to the buffer.  Buffers are actually  */
  79. /*  allocated in 16 byte chunks in the malloc routine.         */
  80. /*                                                              */
  81. /*  Possible status codes:                                      */
  82. /*      MMSS_Success, MMSK_NoMem, MMSF_BadRange                 */
  83. /*                                                              */
  84. /****************************************************************/
  85.  
  86. KKStatus  MMAllocateData( fSize,   /* in bytes */
  87.             /* returns */ fData
  88.                         )
  89.   unsigned int   fSize;
  90.   char         **fData;
  91. {
  92.   MXTraceMsg(5, "MMAllocateData( %d )\n", fSize);
  93.  
  94.   if ( fSize > MAXDATASIZE)
  95.     return MMSF_BadRange;
  96.  
  97.   *fData = malloc( (unsigned) fSize );
  98.  
  99.   if ( *fData == NULL )
  100.     return MMSK_NoMem;
  101.  
  102.   MXTraceMsg(6, "%d allocated (%d bytes).\n", *fData, fSize);
  103.  
  104.   return MMSS_Success;
  105. }
  106.  
  107. /****************************************************************/
  108. /*                                                              */
  109. /*                       MMDeallocateData                       */
  110. /*                                                              */
  111. /*  The specified packet is released and returned to the pool   */
  112. /*  of available packets. 
  113. /*                                                              */
  114. /****************************************************************/
  115.  
  116. void  MMDeallocateData( fSize, /* in bytes */
  117.                         fData
  118.                       )
  119.   unsigned int fSize;
  120.   char        *fData;
  121. {
  122.   MXTraceMsg(5, "MMDeallocateData( %d, %d )\n", fSize, fData);
  123.  
  124.   if ( fData != NULL )
  125.     free( fData );
  126. }
  127.  
  128. /****************************************************************/
  129. /* End of Message Module Buffer Library                         */
  130. /****************************************************************/
  131.