1
0

blockpool_free.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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
  39. lub_blockpool_free(lub_blockpool_t *this,
  40. void *block)
  41. {
  42. lub_blockpool_block_t *newfree = block;
  43. /* simply add this block to the end of the free list */
  44. newfree->next = NULL;
  45. if(NULL != this->m_tail)
  46. {
  47. this->m_tail->next = newfree;
  48. }
  49. else
  50. {
  51. /* first entry in the list */
  52. this->m_head = newfree;
  53. }
  54. /* add to end of list */
  55. this->m_tail = newfree;
  56. /* updated the stats */
  57. --this->m_alloc_blocks;
  58. }
  59. /*--------------------------------------------------------- */