blockpool.h

00001 
00022 /*---------------------------------------------------------------
00023  * HISTORY
00024  * 7-Dec-2004       Graeme McKerrell    
00025  *    Updated to use the "lub" prefix
00026  * 6-Feb-2004       Graeme McKerrell    
00027  *    removed init_fn type definition and parameter, the client had
00028  *    more flexiblity in defining their own initialisation operation with
00029  *    arguments rather than use a "one-size-fits-all" approach.
00030  *    Modified blockpool structure to support FIFO block allocation.
00031  * 23-Jan-2004      Graeme McKerrell    
00032  *    Initial version
00033  *---------------------------------------------------------------
00034  * Copyright (C) 2004 3Com Corporation. All Rights Reserved.
00035  *--------------------------------------------------------------- */
00036 #ifndef _lub_blockpool_h
00037 #define _lub_blockpool_h
00038 #include <stddef.h>
00039 
00040 /****************************************************************
00041  * TYPE DEFINITIONS
00042  **************************************************************** */
00043 typedef struct _lub_blockpool_block lub_blockpool_block_t;
00047 typedef struct _lub_blockpool lub_blockpool_t;
00048 struct _lub_blockpool
00049 {
00050     /* CLIENTS MUSTN'T TOUCH THESE DETAILS */
00051     lub_blockpool_block_t *m_head;
00052     lub_blockpool_block_t *m_tail;
00053     size_t                 m_block_size;
00054     size_t                 m_num_blocks;
00055     unsigned               m_alloc_blocks;
00056     unsigned               m_alloc_total_blocks;
00057     unsigned               m_alloc_hightide_blocks;
00058     unsigned               m_alloc_failures;
00059 };
00063 typedef struct _lub_blockpool_stats lub_blockpool_stats_t;
00064 struct _lub_blockpool_stats
00065 {
00066     /*----------------------------------------------------- */
00070     size_t block_size;
00074     size_t num_blocks;
00075     /*----------------------------------------------------- */
00080     size_t alloc_blocks;
00085     size_t alloc_bytes;
00089     size_t free_blocks;
00093     size_t free_bytes;
00094     /*----------------------------------------------------- */
00099     size_t alloc_total_blocks;
00104     size_t alloc_total_bytes;
00105     /*----------------------------------------------------- */
00110     size_t alloc_hightide_blocks;
00116     size_t alloc_hightide_bytes;
00121     size_t free_hightide_blocks;
00125     size_t free_hightide_bytes;
00126     /*----------------------------------------------------- */
00130     size_t alloc_failures;
00131     /*----------------------------------------------------- */
00132 };
00133 /****************************************************************
00134  * BLOCKPOOL OPERATIONS
00135  **************************************************************** */
00147 extern void
00148     lub_blockpool_init(
00152         lub_blockpool_t *blockpool,
00156         void *memory,
00160         size_t blocksize,
00165         unsigned blockcount
00166     );
00167 
00182 extern void *
00183     lub_blockpool_alloc(
00187         lub_blockpool_t *blockpool
00188     );
00189 
00201 extern void
00202     lub_blockpool_free(
00206         lub_blockpool_t *blockpool,
00210         void *block
00211     );
00223 void
00224     lub_blockpool__get_stats(
00228         lub_blockpool_t *instance,
00232         lub_blockpool_stats_t *stats
00233     );
00234 
00235 #endif /* _lub_blockpool_h */
00236 

Generated on Tue Apr 29 13:41:07 2008 for CLISH by  doxygen 1.5.1