// $RCSfile: hifi_pool.c,v $Revision: 1.5 $Date: 2005/03/11 15:08:57 //! Implements simple, robust, fixed block size pools. #include "hifi_pool.dox" #include "allnodes.h" #include "node1.h" #include #include "configura.h" #include "err_hdl.h" #include "hifi_pool.h" //----- Local variables ----------------------------------------------- static int * trash_block; //!< If no blocks are free, this trash block is allocated //---- HRS Pool --------------------------------------------------------// static int hrs_frame_pool[HRS_FRAME_POOL_BLOCK_NR*HRS_FRAME_POOL_BLOCK_DIM]; //!< Blocks of HRS_FRAME_POOL static int hrs_frame_pool_used[HRS_FRAME_POOL_BLOCK_NR]; //!< Usage of blocks of HRS_FRAME_POOL static int *hrs_frame_pool_pointers[HRS_FRAME_POOL_BLOCK_NR]; //!< Pointers to the blocks of HRS_FRAME_POOL //---- WBS Pool --------------------------------------------------------// static int wbs_frame_pool[WBS_FRAME_POOL_BLOCK_NR*WBS_FRAME_POOL_BLOCK_DIM]; //!< Blocks of WBS_FRAME_POOL static int wbs_frame_pool_used[WBS_FRAME_POOL_BLOCK_NR]; //!< Usage of blocks of WBS_FRAME_POOL static int *wbs_frame_pool_pointers[WBS_FRAME_POOL_BLOCK_NR]; //!< Pointers to the blocks of WBS_FRAME_POOL //---- Local functions --------------------------------------------------- int * get_pool_pointer(int** pool, int block_nr, int max_block_nr); int get_pool_block(int* pool_used, int block_nr); void pool_free_block(int *pool_used, int block_nr, int max_block_nr); //------------ hifi_pool_init ------------------------------------- //! Inits all the pools void hifi_pool_init (void) { int i; // Init all block to non used for (i=0; i= 0; i--) if (!pool_used[i]) { pool_used[i] = 1; // mark the block as used break; // break in order to return the correct block nr } if ( i == -1) generate_event(EVENT_EVENT_REPORT, RUNTIME_ERROR_EVID, ERR_HIFI_POOL_FULL, 0, NULL); return (i + 1); // returns zero if no block found. Block nr (from 1 to block_nr) if block found. } //------------ hifi_pool_free_block -------------------------------------------- //! External interface: Frees a block void hifi_pool_free_block (int pool_id, int block_nr) { switch (pool_id) { case HRS_FRAME_POOL: pool_free_block(hrs_frame_pool_used, block_nr, HRS_FRAME_POOL_BLOCK_NR); break; case WBS_FRAME_POOL: pool_free_block(wbs_frame_pool_used, block_nr, WBS_FRAME_POOL_BLOCK_NR); break; default: generate_event(EVENT_EVENT_REPORT, RUNTIME_ERROR_EVID, ERR_HIFI_POOL_ID, 1, &pool_id); break; } } //--------- pool_free_block ---------------------------------------------------- //! Internal: Frees a block void pool_free_block (int *pool_used, int block_nr, int max_block_nr) { if ( block_nr <= 0 || block_nr > max_block_nr ) { generate_event(EVENT_EVENT_REPORT, RUNTIME_ERROR_EVID, ERR_HIFI_POOL_BLOCK_NUMBER, 1, &block_nr); return; } else pool_used[block_nr - 1] = 0; } //--------- hifi_pool_get_pointer ---------------------------------------------- //! External Interface: Gets a pointer to the block int * hifi_pool_get_pointer (int pool_id, int block_nr) { switch (pool_id) { case HRS_FRAME_POOL: return get_pool_pointer(hrs_frame_pool_pointers, block_nr, HRS_FRAME_POOL_BLOCK_NR); case WBS_FRAME_POOL: return get_pool_pointer(wbs_frame_pool_pointers, block_nr, WBS_FRAME_POOL_BLOCK_NR); default: generate_event(EVENT_EVENT_REPORT, RUNTIME_ERROR_EVID, ERR_HIFI_POOL_ID, 1, &pool_id); return trash_block; } } //---------- get_pool_pointer -------------------------------------------------- //! Internal: Gets a pointer to the block int * get_pool_pointer (int** pool_pointers, int block_nr, int max_block_nr) { if ( block_nr <= 0 || block_nr > max_block_nr ) { generate_event(EVENT_EVENT_REPORT, RUNTIME_ERROR_EVID, ERR_HIFI_POOL_BLOCK_NUMBER, 1, &block_nr); return trash_block; } else return pool_pointers[block_nr-1]; }