1
0

blockpool_free.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*********************** -*- Mode: C -*- ***********************
  2. * File : blockpool_free.c
  3. *---------------------------------------------------------------
  4. * Description
  5. * ===========
  6. * This operation de-allocates a "block" of memory back into a "blockpool"
  7. *
  8. * blockpool - the "blockpool" instance to invoke this operation upon
  9. *
  10. * PRE-CONDITIONS
  11. * The specified block must have been previously allocated using
  12. * lub_blockpool_alloc.
  13. *
  14. * POST-CONDITIONS
  15. * The de-allocated block become available for subsequent
  16. * lub_blockpool_alloc() requests.
  17. *---------------------------------------------------------------
  18. * Author : Graeme McKerrell
  19. * Created On : Thu Jan 29 14:08:41 2004
  20. * Status : TESTED
  21. *---------------------------------------------------------------
  22. * HISTORY
  23. * 7-Dec-2004 Graeme McKerrell
  24. * updated to use the "lub_" namespace
  25. * 5-May-2004 Graeme McKerrell
  26. * updates following review
  27. * 1-Apr-2004 Peter Kennedy
  28. * updated to free the tail as well as the head
  29. * 6-Feb-2004 Graeme McKerrell
  30. * updated to use FIFO allocation of blocks
  31. * 29-Jan-2004 Graeme McKerrell
  32. * Initial version
  33. *---------------------------------------------------------------
  34. * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
  35. **************************************************************** */
  36. #include "private.h"
  37. /*--------------------------------------------------------- */
  38. void lub_blockpool_free(lub_blockpool_t * this, void *block)
  39. {
  40. lub_blockpool_block_t *newfree = block;
  41. /* simply add this block to the end of the free list */
  42. newfree->next = NULL;
  43. if (NULL != this->m_tail) {
  44. this->m_tail->next = newfree;
  45. } else {
  46. /* first entry in the list */
  47. this->m_head = newfree;
  48. }
  49. /* add to end of list */
  50. this->m_tail = newfree;
  51. /* updated the stats */
  52. --this->m_alloc_blocks;
  53. }
  54. /*--------------------------------------------------------- */