home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / exec / freepooled.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.6 KB  |  117 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: freepooled.c,v 1.6 1996/10/24 15:50:50 aros Exp $
  4.     $Log: freepooled.c,v $
  5.     Revision 1.6  1996/10/24 15:50:50  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.5  1996/10/19 17:07:26  aros
  9.     Include <aros/machine.h> instead of machine.h
  10.  
  11.     Revision 1.4  1996/08/13 13:56:02  digulla
  12.     Replaced AROS_LA by AROS_LHA
  13.     Replaced some AROS_LH*I by AROS_LH*
  14.     Sorted and added includes
  15.  
  16.     Revision 1.3  1996/08/01 17:41:11  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang:
  21. */
  22. #include "exec_intern.h"
  23. #include <aros/libcall.h>
  24. #include <aros/machine.h>
  25. #include "memory.h"
  26.  
  27. /*****************************************************************************
  28.  
  29.     NAME */
  30.     #include <exec/memory.h>
  31.     #include <clib/exec_protos.h>
  32.  
  33.     AROS_LH3(void,FreePooled,
  34.  
  35. /*  SYNOPSIS */
  36.     AROS_LHA(APTR, poolHeader,A0),
  37.     AROS_LHA(APTR, memory,    A1),
  38.     AROS_LHA(ULONG,memSize,   D0),
  39.  
  40. /* LOCATION */
  41.     struct ExecBase *, SysBase, 119, Exec)
  42.  
  43. /*  FUNCTION
  44.     Free memory allocated out of a private memory pool.
  45.  
  46.     INPUTS
  47.     poolHeader - Handle of the memory pool
  48.     memory       - Pointer to the memory
  49.     memSize    - Size of the memory chunk
  50.  
  51.     RESULT
  52.  
  53.     NOTES
  54.  
  55.     EXAMPLE
  56.  
  57.     BUGS
  58.  
  59.     SEE ALSO
  60.     CreatePool(), DeletePool(), AllocPooled()
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.     16-10-95    created by M. Fleischer
  66.  
  67. ******************************************************************************/
  68. {
  69.     AROS_LIBFUNC_INIT
  70.     struct Pool *pool=(struct Pool *)poolHeader;
  71.  
  72.     /* If memSize is bigger than the ThreshSize it's allocated seperately. */
  73.     if(memSize>pool->ThreshSize)
  74.     {
  75.     struct Block *bl;
  76.  
  77.     /* Get pointer to header */
  78.     bl=(struct Block *)((UBYTE *)memory-BLOCK_TOTAL);
  79.  
  80.     /* Remove it from the list */
  81.     Remove((struct Node *)&bl->Node);
  82.  
  83.     /* And Free the memory */
  84.     FreeMem(bl,bl->Size);
  85.     }else
  86.     {
  87.     /* Look for the right MemHeader */
  88.     struct MemHeader *mh=(struct MemHeader *)pool->PuddleList.mlh_Head;
  89.  
  90.     for(;;)
  91.     {
  92.         /* The memory must be between the two borders */
  93.         if(memory>=mh->mh_Lower&&memory<mh->mh_Upper)
  94.         {
  95.         /* Found the MemHeader. Free the memory. */
  96.         Deallocate(mh,memory,memSize);
  97.  
  98.         /* Is this MemHeader completely free now? */
  99.         if(mh->mh_Free==pool->PuddleSize)
  100.         {
  101.             /* Yes. Remove it from the list. */
  102.             Remove(&mh->mh_Node);
  103.  
  104.             /* And free it. */
  105.             FreeMem(mh,pool->PuddleSize+sizeof(struct MemHeader));
  106.         }
  107.         /* All done. */
  108.         break;
  109.         }
  110.         /* Try next MemHeader */
  111.         mh=(struct MemHeader *)mh->mh_Node.ln_Succ;
  112.     }
  113.     }
  114.     AROS_LIBFUNC_EXIT
  115. } /* FreePooled */
  116.  
  117.