From 415f04059f50ca27203a8681738f3dab3b987189 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 29 Dec 2008 18:11:56 +0000 Subject: [PATCH] (trunk libT) wrap tr_inf(), tr_msg(), tr_dbg() calls inside a check to see if that debugging level is active. That way that function calls in the vararg list won't be invoked unless that level of verbosity is actually turned on. --- libtransmission/utils.c | 60 +++++++++++++++---------- libtransmission/utils.h | 99 +++++++++++++++++++++++++++++------------ libtransmission/web.c | 15 ++++++- 3 files changed, 120 insertions(+), 54 deletions(-) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index af05c8c5b..eda4ef2af 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -59,11 +59,21 @@ static tr_msg_list ** messageQueueTail = &messageQueue; static void OutputDebugString( const void * unused UNUSED ) { } #endif -void +static void tr_msgInit( void ) { - if( !messageLock ) + static tr_bool initialized = FALSE; + + if( !initialized ) + { + char * env = getenv( "TR_DEBUG" ); + messageLevel = ( env ? atoi( env ) : 0 ) + 1; + messageLevel = MAX( 1, messageLevel ); + messageLock = tr_lockNew( ); + + initialized = TRUE; + } } FILE* @@ -100,7 +110,9 @@ tr_setMessageLevel( int level ) { tr_msgInit( ); tr_lockLock( messageLock ); + messageLevel = MAX( 0, level ); + tr_lockUnlock( messageLock ); } @@ -108,12 +120,12 @@ int tr_getMessageLevel( void ) { int ret; - tr_msgInit( ); tr_lockLock( messageLock ); - ret = messageLevel; - tr_lockUnlock( messageLock ); + ret = messageLevel; + + tr_lockUnlock( messageLock ); return ret; } @@ -122,7 +134,9 @@ tr_setMessageQueuing( tr_bool enabled ) { tr_msgInit( ); tr_lockLock( messageLock ); + messageQueuing = enabled; + tr_lockUnlock( messageLock ); } @@ -130,12 +144,12 @@ tr_bool tr_getMessageQueuing( void ) { int ret; - tr_msgInit( ); tr_lockLock( messageLock ); - ret = messageQueuing; - tr_lockUnlock( messageLock ); + ret = messageQueuing; + + tr_lockUnlock( messageLock ); return ret; } @@ -143,14 +157,14 @@ tr_msg_list * tr_getQueuedMessages( void ) { tr_msg_list * ret; - - assert( NULL != messageLock ); + tr_msgInit( ); tr_lockLock( messageLock ); + ret = messageQueue; messageQueue = NULL; messageQueueTail = &messageQueue; - tr_lockUnlock( messageLock ); + tr_lockUnlock( messageLock ); return ret; } @@ -248,6 +262,15 @@ tr_deepLog( const char * file, /*** **** ***/ + + +int +tr_msgLoggingIsActive( int level ) +{ + tr_msgInit( ); + + return messageLevel >= level; +} void tr_msg( const char * file, @@ -258,19 +281,11 @@ tr_msg( const char * file, ... ) { FILE * fp; - - if( messageLock ) - tr_lockLock( messageLock ); + tr_msgInit( ); + tr_lockLock( messageLock ); fp = tr_getLog( ); - if( !messageLevel ) - { - char * env = getenv( "TR_DEBUG" ); - messageLevel = ( env ? atoi( env ) : 0 ) + 1; - messageLevel = MAX( 1, messageLevel ); - } - if( messageLevel >= level ) { va_list ap; @@ -315,8 +330,7 @@ tr_msg( const char * file, } } - if( messageLock ) - tr_lockUnlock( messageLock ); + tr_lockUnlock( messageLock ); } /*** diff --git a/libtransmission/utils.h b/libtransmission/utils.h index d1d310f75..a9e6b24b7 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -107,22 +107,11 @@ extern "C" { #define _( a ) tr_strip_positional_args( a ) #endif -#define tr_nerr( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__ ) -#define tr_ninf( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__ ) -#define tr_ndbg( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__ ) +/**** +***** +****/ -#define tr_torerr( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, __VA_ARGS__ ) -#define tr_torinf( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, __VA_ARGS__ ) -#define tr_tordbg( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, __VA_ARGS__ ) - -#define tr_err( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__ ) -#define tr_inf( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__ ) -#define tr_dbg( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__ ) - -int tr_wildmat( const char * text, - const char * pattern ); - -void tr_msgInit( void ); +int tr_msgLoggingIsActive( int level ); void tr_msg( const char * file, int line, @@ -131,6 +120,62 @@ void tr_msg( const char * file, const char * fmt, ... ) TR_GNUC_PRINTF( 5, 6 ); +#define tr_nerr( n, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_ninf( n, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_INF) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_ndbg( n, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_DBG) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_torerr( tor, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_torinf( tor, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_tordbg( tor, ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_err( ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_inf( ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__ ); \ + } while( 0 ) + +#define tr_dbg( ... ) \ + do { \ + if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \ + tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__ ); \ + } while( 0 ) + + + FILE* tr_getLog( void ); int tr_deepLoggingIsActive( void ); @@ -144,6 +189,10 @@ void tr_deepLog( const char * file, char* tr_getLogTimeStr( char * buf, int buflen ); + +int tr_wildmat( const char * text, + const char * pattern ); + /** a portability wrapper for basename(). */ char* tr_basename( const char * path ) TR_GNUC_MALLOC; @@ -319,29 +368,21 @@ void tr_bitfieldFree( tr_bitfield* ); void tr_bitfieldClear( tr_bitfield* ); -int tr_bitfieldAdd( tr_bitfield*, - size_t bit ); +int tr_bitfieldAdd( tr_bitfield*, size_t bit ); -int tr_bitfieldRem( tr_bitfield*, - size_t bit ); +int tr_bitfieldRem( tr_bitfield*, size_t bit ); -int tr_bitfieldAddRange( tr_bitfield *, - size_t begin, - size_t end ); +int tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end ); -int tr_bitfieldRemRange( tr_bitfield*, - size_t begin, - size_t end ); +int tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end ); -void tr_bitfieldDifference( tr_bitfield *, - const tr_bitfield * ); +void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * ); int tr_bitfieldIsEmpty( const tr_bitfield* ); size_t tr_bitfieldCountTrueBits( const tr_bitfield* ); -tr_bitfield* tr_bitfieldOr( tr_bitfield*, - const tr_bitfield* ); +tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* ); /** A stripped-down version of bitfieldHas to be used for speed when you're looping quickly. This version diff --git a/libtransmission/web.c b/libtransmission/web.c index 43a496651..725906d78 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -55,7 +55,9 @@ struct tr_web long timer_ms; CURLM * multi; tr_session * session; +#if 0 tr_list * easy_queue; +#endif struct event timer_event; }; @@ -144,11 +146,16 @@ addTask( void * vtask ) else /* don't set encoding on webseeds; it messes up binary data */ curl_easy_setopt( easy, CURLOPT_ENCODING, "" ); - if( web->still_running >= MAX_CONCURRENT_TASKS ) { +#if 0 + if( web->still_running >= MAX_CONCURRENT_TASKS ) + { tr_list_append( &web->easy_queue, easy ); dbgmsg( " >> enqueueing a task ... size is now %d", tr_list_size( web->easy_queue ) ); - } else { + } + else +#endif + { const CURLMcode rc = curl_multi_add_handle( web->multi, easy ); if( rc == CURLM_OK ) ++web->still_running; @@ -243,6 +250,7 @@ restart_timer( tr_web * g ) evtimer_add( &g->timer_event, &interval ); } +#if 0 static void add_tasks_from_queue( tr_web * g ) { @@ -263,6 +271,7 @@ add_tasks_from_queue( tr_web * g ) } } } +#endif static void web_close( tr_web * g ) @@ -295,7 +304,9 @@ tr_multi_socket_action( tr_web * g, int fd, int mask ) remove_finished_tasks( g ); +#if 0 add_tasks_from_queue( g ); +#endif if( !g->still_running ) { stop_timer( g );