add nocache flag, use for sequential file ops

stop it caching sequential file read (eg. sequential tiff read), since
you can only read sequentially once
This commit is contained in:
John Cupitt 2012-06-06 19:33:11 +01:00
parent b6f902560f
commit 1ee48e4cd6
5 changed files with 43 additions and 4 deletions

View File

@ -4,6 +4,7 @@
- much faster vips_argument_map() - much faster vips_argument_map()
- make jpeg pyramids work with tiff4 - make jpeg pyramids work with tiff4
- tiff loader always offers THINSTRIP (thanks Diuming) - tiff loader always offers THINSTRIP (thanks Diuming)
- add "nocache" operation flag, set for sequential load (thanks Diuming)
19/4/12 started 7.28.5 19/4/12 started 7.28.5
- ifthenelse blend mode was broken - ifthenelse blend mode was broken

View File

@ -698,6 +698,10 @@ vips_foreign_load_temp( VipsForeignLoad *load )
printf( "vips_foreign_load_temp: partial sequential temp\n" ); printf( "vips_foreign_load_temp: partial sequential temp\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
/* You can't reuse sequential operations.
*/
vips_operation_set_nocache( VIPS_OPERATION( load ), TRUE );
return( vips_image_new() ); return( vips_image_new() );
} }

View File

@ -66,6 +66,12 @@ typedef struct _VipsOperation {
guint hash; guint hash;
gboolean found_hash; gboolean found_hash;
/* Set this before the end of _build() to stop this operation from
* being cached. Some things, like sequential read from a TIFF file,
* can't be reused.
*/
gboolean nocache;
} VipsOperation; } VipsOperation;
typedef struct _VipsOperationClass { typedef struct _VipsOperationClass {
@ -89,6 +95,7 @@ void vips_call_options( GOptionGroup *group, VipsOperation *operation );
int vips_call_argv( VipsOperation *operation, int argc, char **argv ); int vips_call_argv( VipsOperation *operation, int argc, char **argv );
void vips_cache_drop_all( void ); void vips_cache_drop_all( void );
void vips_operation_set_nocache( VipsOperation *operation, gboolean nocache );
int vips_cache_operation_buildp( VipsOperation **operation ); int vips_cache_operation_buildp( VipsOperation **operation );
VipsOperation *vips_cache_operation_build( VipsOperation *operation ); VipsOperation *vips_cache_operation_build( VipsOperation *operation );
void vips_cache_set_max( int max ); void vips_cache_set_max( int max );

View File

@ -621,7 +621,7 @@ vips_cache_operation_buildp( VipsOperation **operation )
#ifdef VIPS_DEBUG #ifdef VIPS_DEBUG
printf( "vips_cache_operation_build: " ); printf( "vips_cache_operation_build: " );
vips_object_print_summary_stdout( VIPS_OBJECT( *operation ) ); vips_object_print_dump( VIPS_OBJECT( *operation ) );
#endif /*VIPS_DEBUG*/ #endif /*VIPS_DEBUG*/
vips_cache_init(); vips_cache_init();
@ -643,15 +643,22 @@ vips_cache_operation_buildp( VipsOperation **operation )
} }
else { else {
if( vips__cache_trace ) { if( vips__cache_trace ) {
printf( "vips cache: miss %p\n ", *operation ); if( (*operation)->nocache )
printf( "vips cache: uncacheable %p\n ",
*operation );
else
printf( "vips cache: miss %p\n ", *operation );
vips_object_print_summary( VIPS_OBJECT( *operation ) ); vips_object_print_summary( VIPS_OBJECT( *operation ) );
} }
if( vips_object_build( VIPS_OBJECT( *operation ) ) ) if( vips_object_build( VIPS_OBJECT( *operation ) ) )
return( -1 ); return( -1 );
vips_cache_ref( *operation ); if( !(*operation)->nocache ) {
g_hash_table_insert( vips_cache_table, *operation, *operation ); vips_cache_ref( *operation );
g_hash_table_insert( vips_cache_table,
*operation, *operation );
}
} }
return( 0 ); return( 0 );

View File

@ -946,3 +946,23 @@ vips_call_argv( VipsOperation *operation, int argc, char **argv )
return( 0 ); return( 0 );
} }
/**
* vips_operation_set_nocache:
* @operation: operation to set
* @nocache: TRUE means don't cache this operation
*
* Set this before the end of _build() to stop this operation being cached.
* Some operations, like sequential read from a TIFF file, for example, cannot
* be reused.
*/
void
vips_operation_set_nocache( VipsOperation *operation, gboolean nocache )
{
#ifdef VIPS_DEBUG
printf( "vips_operation_set_nocache: " );
vips_object_print_name( VIPS_OBJECT( operation ) );
printf( " %d\n", nocache );
#endif /*VIPS_DEBUG*/
operation->nocache = nocache;
}