]> granicus.if.org Git - transmission/commitdiff
(trunk libT) wrap tr_inf(), tr_msg(), tr_dbg() calls inside a check to see if that...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 29 Dec 2008 18:11:56 +0000 (18:11 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 29 Dec 2008 18:11:56 +0000 (18:11 +0000)
libtransmission/utils.c
libtransmission/utils.h
libtransmission/web.c

index af05c8c5bd8d015b95a4f1b0ea2a9bf2b8c616cd..eda4ef2af7f462811c16edbb27f24f84f52c35c5 100644 (file)
@@ -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 );
 
+    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 );
 
+    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 );
 }
 
 /***
index d1d310f75dc5af65d087d5b7023e9bdd2e4295a2..a9e6b24b70b0277f5ce5b0290ff17c5c03af1441 100644 (file)
@@ -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
index 43a49665124172b646528b08924455d9dd285fb9..725906d788b95d02119b58af619f1fbf99bf4cb7 100644 (file)
@@ -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 );