Doxygen Source Code Documentation
thd_purgedblk.c File Reference
#include "mrilib.h"#include "thd.h"Go to the source code of this file.
Functions | |
| Boolean | THD_purge_datablock (THD_datablock *blk, int mem_type) |
| Boolean | THD_purge_one_brick (THD_datablock *blk, int iv) |
Function Documentation
|
||||||||||||
|
Definition at line 10 of file thd_purgedblk.c. References THD_datablock::brick, DATABLOCK_MEM_MALLOC, DATABLOCK_MEM_MMAP, DATABLOCK_MEM_SHARED, DBLK_ARRAY, DBLK_BRICK, DBLK_LOCKED, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_clear_data_pointer, THD_datablock::nvals, and THD_datablock::total_bytes. Referenced by THD_delete_datablock(), THD_force_malloc_type(), THD_load_datablock(), and THD_write_datablock().
00011 {
00012 int ibr , nfreed ;
00013 void * ptr ;
00014
00015 /*-- sanity checks --*/
00016
00017 if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00018 if( (blk->malloc_type & mem_type) == 0 ) return False ;
00019 if( DBLK_LOCKED(blk) ) return False ;
00020
00021 /*-- free the data space --*/
00022
00023 nfreed = 0 ;
00024 switch( blk->malloc_type ){
00025
00026 case DATABLOCK_MEM_MALLOC:
00027 for( ibr=0 ; ibr < blk->nvals ; ibr++ ){
00028 ptr = DBLK_ARRAY(blk,ibr) ;
00029 if( ptr != NULL ){ free(ptr) ; nfreed++ ; }
00030 mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00031 }
00032 return True ;
00033
00034 case DATABLOCK_MEM_MMAP:
00035 ptr = DBLK_ARRAY(blk,0) ;
00036 if( ptr != NULL ){ munmap( ptr , (size_t)blk->total_bytes ) ; nfreed++ ; }
00037 for( ibr=0 ; ibr < blk->nvals ; ibr++ )
00038 mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00039 return True ;
00040
00041 case DATABLOCK_MEM_SHARED: /* can't be purged */
00042 return False ;
00043 }
00044
00045 return False ; /* shouldn't be reached */
00046 }
|
|
||||||||||||
|
Definition at line 52 of file thd_purgedblk.c. References THD_datablock::brick, DATABLOCK_MEM_MALLOC, DBLK_ARRAY, DBLK_BRICK, DBLK_LOCKED, free, ISVALID_DATABLOCK, THD_datablock::malloc_type, mri_clear_data_pointer, and THD_datablock::nvals.
00053 {
00054 void * ptr ;
00055
00056 /* sanity checks */
00057
00058 if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00059 if( DBLK_LOCKED(blk) ) return False ;
00060 if( iv < 0 || iv >= blk->nvals ) return False ;
00061 if( blk->malloc_type != DATABLOCK_MEM_MALLOC ) return False ;
00062
00063 ptr = DBLK_ARRAY(blk,iv) ;
00064 if( ptr != NULL ) free(ptr) ;
00065 mri_clear_data_pointer( DBLK_BRICK(blk,iv) ) ;
00066 return True ;
00067 }
|