Changeset 7288


Ignore:
Timestamp:
Dec 5, 2008, 6:00:53 PM (12 years ago)
Author:
charles
Message:

(1.3x libT) backport #1387: Easy code changes to reduce CPU load

Location:
branches/1.3x/libtransmission
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3x/libtransmission/fdlimit.c

    r6489 r7288  
    6060#endif
    6161
    62 #define dbgmsg(fmt...) tr_deepLog( __FILE__, __LINE__, NULL, ##fmt )
     62#define dbgmsg( ... ) \
     63    do { \
     64        if( tr_deepLoggingIsActive( ) ) \
     65            tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \
     66    } while( 0 )
    6367
    6468/**
  • branches/1.3x/libtransmission/handshake.c

    r7287 r7288  
    135135**/
    136136
    137 #define dbgmsg(handshake, fmt...) tr_deepLog( __FILE__, __LINE__, tr_peerIoGetAddrStr( handshake->io ), ##fmt )
     137#define dbgmsg( handshake, ... ) \
     138    do { \
     139        if( tr_deepLoggingIsActive( ) ) \
     140            tr_deepLog( __FILE__, __LINE__, tr_peerIoGetAddrStr( handshake->io ), __VA_ARGS__ ); \
     141    } while( 0 )
    138142
    139143static const char* getStateName( short state )
  • branches/1.3x/libtransmission/peer-mgr.c

    r7285 r7288  
    128128};
    129129
    130 #define tordbg(t, fmt...) tr_deepLog( __FILE__, __LINE__, t->tor->info.name, ##fmt )
     130#define tordbg( t, ... ) \
     131    do { \
     132        if( tr_deepLoggingIsActive( ) ) \
     133            tr_deepLog( __FILE__, __LINE__, t->tor->info.name, __VA_ARGS__ ); \
     134    } while( 0 )
    131135
    132136/**
  • branches/1.3x/libtransmission/peer-msgs.c

    r7284 r7288  
    588588tr_peerMsgsSetChoke( tr_peermsgs * msgs, int choke )
    589589{
    590     const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
     590    const time_t now = time( NULL );
     591    const time_t fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
    591592
    592593    assert( msgs );
     
    604605            cancelAllRequestsToClientExceptFast( msgs );
    605606        protocolSendChoke( msgs, choke );
    606         msgs->info->chokeChangedAt = time( NULL );
     607        msgs->info->chokeChangedAt = now;
    607608    }
    608609}
     
    780781
    781782static void
    782 expireOldRequests( tr_peermsgs * msgs )
     783expireOldRequests( tr_peermsgs * msgs, const time_t now )
    783784{
    784785    int i;
     
    787788
    788789    /* cancel requests that have been queued for too long */
    789     oldestAllowed = time( NULL ) - QUEUED_REQUEST_TTL_SECS;
     790    oldestAllowed = now - QUEUED_REQUEST_TTL_SECS;
    790791    reqListCopy( &tmp, &msgs->clientWillAskFor );
    791792    for( i=0; i<tmp.count; ++i ) {
     
    797798
    798799    /* cancel requests that were sent too long ago */
    799     oldestAllowed = time( NULL ) - SENT_REQUEST_TTL_SECS;
     800    oldestAllowed = now - SENT_REQUEST_TTL_SECS;
    800801    reqListCopy( &tmp, &msgs->clientAskedFor );
    801802    for( i=0; i<tmp.count; ++i ) {
     
    808809
    809810static void
    810 pumpRequestQueue( tr_peermsgs * msgs )
     811pumpRequestQueue( tr_peermsgs * msgs, const time_t now )
    811812{
    812813    const int max = msgs->maxActiveRequests;
    813814    const int min = msgs->minActiveRequests;
    814     const time_t now = time( NULL );
    815815    int sent = 0;
    816816    int count = msgs->clientAskedFor.count;
     
    14481448
    14491449static void
    1450 peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount )
    1451 {
    1452     msgs->info->pieceDataActivityDate = time( NULL );
     1450peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount, const time_t now )
     1451{
     1452    msgs->info->pieceDataActivityDate = now;
    14531453    tr_rcTransferred( msgs->info->rcToPeer, byteCount );
    14541454    firePeerGotData( msgs, byteCount );
     
    16601660
    16611661    tr_peerIoTryRead( msgs->io );
    1662     pumpRequestQueue( msgs );
    1663     expireOldRequests( msgs );
     1662    pumpRequestQueue( msgs, now );
     1663    expireOldRequests( msgs, now );
    16641664
    16651665    if( msgs->sendingBlock )
     
    16751675            tr_peerIoWrite( msgs->io, EVBUFFER_DATA( msgs->outBlock ), outlen );
    16761676            evbuffer_drain( msgs->outBlock, outlen );
    1677             peerGotBytes( msgs, outlen );
     1677            peerGotBytes( msgs, outlen, now );
    16781678
    16791679            len -= outlen;
  • branches/1.3x/libtransmission/rpc-server.c

    r6585 r7288  
    5151};
    5252
    53 #define dbgmsg(fmt...) tr_deepLog(__FILE__, __LINE__, MY_NAME, ##fmt )
     53#define dbgmsg( ... ) \
     54    do { \
     55        if( tr_deepLoggingIsActive( ) ) \
     56            tr_deepLog( __FILE__, __LINE__, MY_NAME, __VA_ARGS__ ); \
     57    } while( 0 )
    5458
    5559static const char*
  • branches/1.3x/libtransmission/session.c

    r6425 r7288  
    534534#define SHUTDOWN_MAX_SECONDS 30
    535535
    536 #define dbgmsg(fmt...) tr_deepLog( __FILE__, __LINE__, NULL, ##fmt )
     536#define dbgmsg( ... ) \
     537    do { \
     538        if( tr_deepLoggingIsActive( ) ) \
     539            tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \
     540    } while( 0 )
    537541
    538542void
  • branches/1.3x/libtransmission/tracker.c

    r7282 r7288  
    116116};
    117117
    118 #define dbgmsg(name, fmt...) tr_deepLog(__FILE__, __LINE__, name, ##fmt )
     118#define dbgmsg( name, ... ) \
     119    do { \
     120        if( tr_deepLoggingIsActive( ) ) \
     121            tr_deepLog( __FILE__, __LINE__, name, __VA_ARGS__ ); \
     122    } while( 0 )
    119123
    120124/***
  • branches/1.3x/libtransmission/trevent.c

    r6253 r7288  
    6767};
    6868
    69 #define dbgmsg(fmt...) tr_deepLog( __FILE__, __LINE__, "event", ##fmt )
     69#define dbgmsg( ... ) \
     70    do { \
     71        if( tr_deepLoggingIsActive( ) ) \
     72            tr_deepLog( __FILE__, __LINE__, "event", __VA_ARGS__ ); \
     73    } while( 0 )
    7074
    7175static void
  • branches/1.3x/libtransmission/utils.c

    r6768 r7288  
    173173}
    174174
     175int
     176tr_deepLoggingIsActive( void )
     177{
     178    return tr_getLog != NULL;
     179}
     180
    175181void
    176182tr_deepLog( const char * file, int line, const char * name, const char * fmt, ... )
  • branches/1.3x/libtransmission/utils.h

    r6768 r7288  
    111111
    112112FILE* tr_getLog( void );
     113
     114int  tr_deepLoggingIsActive( void );
    113115
    114116void tr_deepLog( const char * file, int line,
  • branches/1.3x/libtransmission/web.c

    r6447 r7288  
    3030#define PULSE_MSEC 500
    3131
    32 #define dbgmsg(fmt...) tr_deepLog( __FILE__, __LINE__, "web", ##fmt )
     32#define dbgmsg( ... ) \
     33    do { \
     34        if( tr_deepLoggingIsActive( ) ) \
     35            tr_deepLog( __FILE__, __LINE__, "web", __VA_ARGS__ ); \
     36    } while( 0 )
    3337
    3438struct tr_web
Note: See TracChangeset for help on using the changeset viewer.