Exemplo n.º 1
0
/**
 * vips_cache_operation_buildp: (skip)
 * @operation: pointer to operation to lookup
 *
 * Look up @operation in the cache. If we get a hit, unref @operation, ref the
 * old one and return that through the argument pointer. 
 *
 * If we miss, build and add @operation.
 *
 * Returns: 0 on success, or -1 on error.
 */
int
vips_cache_operation_buildp( VipsOperation **operation )
{
	VipsOperation *hit;

	g_assert( VIPS_IS_OPERATION( *operation ) );

#ifdef VIPS_DEBUG
	printf( "vips_cache_operation_buildp: " );
	vips_object_print_dump( VIPS_OBJECT( *operation ) );
#endif /*VIPS_DEBUG*/

	if( (hit = vips_cache_operation_lookup( *operation )) ) {
		g_object_unref( *operation );
		*operation = hit;
	}
	else {
		if( vips_object_build( VIPS_OBJECT( *operation ) ) ) 
			return( -1 );

		vips_cache_operation_add( *operation ); 
	}

	return( 0 );
}
Exemplo n.º 2
0
/**
 * vips_cache_operation_lookup:
 * @operation: (transfer none): pointer to operation to lookup
 *
 * Look up an unbuilt @operation in the cache. If we get a hit, ref and 
 * return the old operation. If there's no hit, return NULL.
 *
 * Returns: (transfer full): the cache hit, if any.
 */
VipsOperation *
vips_cache_operation_lookup( VipsOperation *operation )
{
	VipsOperationCacheEntry *hit;
	VipsOperation *result;

	g_assert( VIPS_IS_OPERATION( operation ) );
	g_assert( !VIPS_OBJECT( operation )->constructed ); 

#ifdef VIPS_DEBUG
	printf( "vips_cache_operation_lookup: " );
	vips_object_print_dump( VIPS_OBJECT( operation ) );
#endif /*VIPS_DEBUG*/

	g_mutex_lock( vips_cache_lock );

	result = NULL;

	if( (hit = g_hash_table_lookup( vips_cache_table, operation )) ) {
		if( vips__cache_trace ) {
			printf( "vips cache*: " );
			vips_object_print_summary( VIPS_OBJECT( operation ) );
		}

		result = hit->operation;
		vips_cache_ref( result );
	}

	g_mutex_unlock( vips_cache_lock );

	return( result );
}
Exemplo n.º 3
0
/**
 * vips_cache_operation_buildp: (skip)
 * @operation: pointer to operation to lookup
 *
 * Look up @operation in the cache. If we get a hit, unref @operation, ref the
 * old one and return that through the argument pointer. 
 *
 * If we miss, build and add @operation.
 *
 * Returns: 0 on success, or -1 on error.
 */
int
vips_cache_operation_buildp( VipsOperation **operation )
{
	VipsOperation *hit;

	g_assert( VIPS_IS_OPERATION( *operation ) );

#ifdef VIPS_DEBUG
	printf( "vips_cache_operation_build: " );
	vips_object_print_dump( VIPS_OBJECT( *operation ) );
#endif /*VIPS_DEBUG*/

	vips_cache_trim();

	g_mutex_lock( vips_cache_lock );

	if( (hit = g_hash_table_lookup( vips_cache_table, *operation )) ) {
		if( vips__cache_trace ) {
			printf( "vips cache-: " );
			vips_object_print_summary( VIPS_OBJECT( hit ) );
		}

		/* Ref before unref in case *operation == hit.
		 */
		vips_cache_ref( hit );
		g_object_unref( *operation );

		*operation = hit;
	}

	g_mutex_unlock( vips_cache_lock );

	if( !hit ) {
		if( vips_object_build( VIPS_OBJECT( *operation ) ) ) 
			return( -1 );

		/* Has to be after _build() so we can see output args.
		 */
		if( vips__cache_trace ) {
			if( vips_operation_get_flags( *operation ) & 
				VIPS_OPERATION_NOCACHE )
				printf( "vips cache : " );
			else
				printf( "vips cache+: " );
			vips_object_print_summary( VIPS_OBJECT( *operation ) );
		}

		g_mutex_lock( vips_cache_lock );

		if( !(vips_operation_get_flags( *operation ) & 
			VIPS_OPERATION_NOCACHE) ) {
			vips_cache_ref( *operation );
			g_hash_table_insert( vips_cache_table, 
				*operation, *operation );
		}

		g_mutex_unlock( vips_cache_lock );
	}


	return( 0 );
}