home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / freepooled.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.8 KB  |  125 lines

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