H5MPpkg.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  * Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
00018  *              Monday, May  2, 2005
00019  *
00020  * Purpose:     This file contains declarations which are visible only within
00021  *              the H5MP package.  Source files outside the H5MP package should
00022  *              include H5MPprivate.h instead.
00023  */
00024 #ifndef H5MP_PACKAGE
00025 #error "Do not include this file outside the H5MP package!"
00026 #endif
00027 
00028 #ifndef _H5MPpkg_H
00029 #define _H5MPpkg_H
00030 
00031 /* Get package's private header */
00032 #include "H5MPprivate.h"        /* Memory Pools                         */
00033 
00034 /* Other private headers needed by this file */
00035 #include "H5FLprivate.h"        /* Free Lists                           */
00036 
00037 /**************************/
00038 /* Package Private Macros */
00039 /**************************/
00040 
00041 /* Alignment macros */
00042 /* (Ideas from Apache APR :-) */
00043 
00044 /* Default alignment necessary */
00045 #define H5MP_BLOCK_ALIGNMENT    8
00046 
00047 /* General alignment macro */
00048 /* (this only works for aligning to power of 2 boundary) */
00049 #define H5MP_ALIGN(x, a) \
00050        (((x) + ((size_t)(a)) - 1) & ~(((size_t)(a)) - 1))
00051 
00052 /* Default alignment */
00053 #define H5MP_BLOCK_ALIGN(x) H5MP_ALIGN(x, H5MP_BLOCK_ALIGNMENT)
00054 
00055 
00056 /****************************/
00057 /* Package Private Typedefs */
00058 /****************************/
00059 
00060 /* Free block in pool */
00061 typedef struct H5MP_page_blk_t {
00062     size_t size;                        /* Size of block (includes this H5MP_page_blk_t info) */
00063     unsigned is_free:1;                 /* Flag to indicate the block is free */
00064     struct H5MP_page_t *page;           /* Pointer to page block is located in */
00065     struct H5MP_page_blk_t *prev;       /* Pointer to previous block in page */
00066     struct H5MP_page_blk_t *next;       /* Pointer to next block in page */
00067 } H5MP_page_blk_t;
00068 
00069 /* Memory pool page */
00070 typedef struct H5MP_page_t {
00071     size_t free_size;                   /* Total amount of free space in page */
00072     unsigned fac_alloc:1;               /* Flag to indicate the page was allocated by the pool's factory */
00073     H5MP_page_blk_t *free_blk;          /* Pointer to first free block in page */
00074     struct H5MP_page_t *next;           /* Pointer to next page in pool */
00075     struct H5MP_page_t *prev;           /* Pointer to previous page in pool */
00076 } H5MP_page_t;
00077 
00078 /* Memory pool header */
00079 struct H5MP_pool_t {
00080     H5FL_fac_head_t *page_fac;  /* Free-list factory for pages */
00081     size_t page_size;           /* Page size for pool */
00082     size_t free_size;           /* Total amount of free space in pool */
00083     size_t max_size;            /* Maximum block that will fit in a standard page */
00084     H5MP_page_t *first;         /* Pointer to first page in pool */
00085     unsigned flags;             /* Bit flags for pool settings */
00086 };
00087 
00088 
00089 /*****************************************/
00090 /* Package Private Variable Declarations */
00091 /*****************************************/
00092 
00093 
00094 /******************************/
00095 /* Package Private Prototypes */
00096 /******************************/
00097 #ifdef H5MP_TESTING
00098 H5_DLL herr_t H5MP_get_pool_free_size (const H5MP_pool_t *mp, size_t *free_size);
00099 H5_DLL htri_t H5MP_pool_is_free_size_correct(const H5MP_pool_t *mp);
00100 H5_DLL herr_t H5MP_get_pool_first_page(const H5MP_pool_t *mp, H5MP_page_t **page);
00101 H5_DLL herr_t H5MP_get_page_free_size(const H5MP_page_t *mp, size_t *page);
00102 H5_DLL herr_t H5MP_get_page_next_page(const H5MP_page_t *page, H5MP_page_t **next_page);
00103 #endif /* H5MP_TESTING */
00104 
00105 #endif /* _H5MPpkg_H */
00106