Changeset 9593


Ignore:
Timestamp:
Nov 26, 2009, 6:47:08 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #2610 "avoid unnecessary calls to time(NULL)"

Location:
trunk/libtransmission
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r9549 r9593  
    392392    tr_tier * t;
    393393    static int nextKey = 1;
    394     const time_t now = time( NULL );
     394    const time_t now = tr_time( );
    395395
    396396    t = tr_new0( tr_tier, 1 );
     
    818818{
    819819    return tier->isRunning
    820         && tier->manualAnnounceAllowedAt <= time( NULL );
     820        && tier->manualAnnounceAllowedAt <= tr_time( );
    821821}
    822822
     
    901901tr_announcerManualAnnounce( tr_torrent * tor )
    902902{
    903     torrentSetNextAnnounce( tor, "manual", time( NULL ) );
     903    torrentSetNextAnnounce( tor, "manual", tr_time( ) );
    904904}
    905905void
    906906tr_announcerTorrentStarted( tr_torrent * tor )
    907907{
    908     torrentSetNextAnnounce( tor, "started", time( NULL ) );
     908    torrentSetNextAnnounce( tor, "started", tr_time( ) );
    909909}
    910910void
    911911tr_announcerTorrentStopped( tr_torrent * tor )
    912912{
    913     torrentSetNextAnnounce( tor, "stopped", time( NULL ) );
     913    torrentSetNextAnnounce( tor, "stopped", tr_time( ) );
    914914}
    915915void
    916916tr_announcerTorrentCompleted( tr_torrent * tor )
    917917{
    918     torrentSetNextAnnounce( tor, "completed", time( NULL ) );
     918    torrentSetNextAnnounce( tor, "completed", tr_time( ) );
    919919}
    920920void
     
    981981    /* working domains come before non-working */
    982982    if( !ret ) {
    983         const time_t now = time( NULL );
     983        const time_t now = tr_time( );
    984984        af = tierIsNotResponding( a, now );
    985985        bf = tierIsNotResponding( b, now );
     
    13571357    struct announce_data * data;
    13581358    const tr_torrent * tor = tier->tor;
    1359     const time_t now = time( NULL );
     1359    const time_t now = tr_time( );
    13601360
    13611361    assert( !tier->isAnnouncing );
     
    14531453    struct announce_data * data = vdata;
    14541454    tr_tier * tier = getTier( announcer, data->torrentId, data->tierId );
    1455     const time_t now = time( NULL );
     1455    const time_t now = tr_time( );
    14561456    tr_bool success = FALSE;
    14571457
     
    15291529    struct evbuffer * buf;
    15301530    struct announce_data * data;
    1531     const time_t now = time( NULL );
     1531    const time_t now = tr_time( );
    15321532
    15331533    assert( tier );
     
    15981598    const tr_bool canScrape = announcer->scrapeSlotsAvailable > 0;
    15991599    tr_torrent * tor = NULL;
    1600     const time_t now = time( NULL );
     1600    const time_t now = tr_time( );
    16011601
    16021602    if( announcer->announceSlotsAvailable > 0 )
     
    17061706    int tierCount;
    17071707    tr_tracker_stat * ret;
    1708     const time_t now = time( NULL );
     1708    const time_t now = tr_time( );
    17091709
    17101710    assert( tr_isTorrent( torrent ) );
  • trunk/libtransmission/natpmp.c

    r9418 r9593  
    100100canSendCommand( const struct tr_natpmp * nat )
    101101{
    102     return time( NULL ) >= nat->commandTime;
     102    return tr_time( ) >= nat->commandTime;
    103103}
    104104
     
    106106setCommandTime( struct tr_natpmp * nat )
    107107{
    108     nat->commandTime = time( NULL ) + COMMAND_WAIT_SECS;
     108    nat->commandTime = tr_time( ) + COMMAND_WAIT_SECS;
    109109}
    110110
     
    190190            nat->state = TR_NATPMP_SEND_MAP;
    191191
    192         else if( nat->isMapped && time( NULL ) >= nat->renewTime )
     192        else if( nat->isMapped && tr_time( ) >= nat->renewTime )
    193193            nat->state = TR_NATPMP_SEND_MAP;
    194194    }
     
    215215            nat->state = TR_NATPMP_IDLE;
    216216            nat->isMapped = 1;
    217             nat->renewTime = time( NULL ) + LIFETIME_SECS;
     217            nat->renewTime = tr_time( ) + LIFETIME_SECS;
    218218            nat->port = resp.pnu.newportmapping.privateport;
    219219            tr_ninf( getKey( ), _(
  • trunk/libtransmission/net.c

    r9513 r9593  
    613613    static time_t last_time = 0;
    614614    static int have_ipv6 = 0;
    615     const time_t now = time( NULL );
     615    const time_t now = tr_time( );
    616616
    617617    /* Re-check every half hour */
  • trunk/libtransmission/peer-io.c

    r9387 r9593  
    386386    io->isIncoming = isIncoming != 0;
    387387    io->hasFinishedConnecting = FALSE;
    388     io->timeCreated = time( NULL );
     388    io->timeCreated = tr_time( );
    389389    io->inbuf = evbuffer_new( );
    390390    io->outbuf = evbuffer_new( );
  • trunk/libtransmission/peer-mgr.c

    r9592 r9593  
    409409    assert( atom );
    410410
    411     atom->time = time( NULL );
     411    atom->time = tr_time( );
    412412
    413413    removed = tr_ptrArrayRemoveSorted( &t->peers, peer, peerCompare );
     
    917917    struct weighted_piece * pieces;
    918918    const tr_bitset * have = &peer->have;
    919     const time_t now = time( NULL );
     919    const time_t now = tr_time( );
    920920
    921921    /* sanity clause */
     
    10331033    managerLock( mgr );
    10341034
    1035     now = time( NULL );
     1035    now = tr_time( );
    10361036    too_old = now - REQUEST_TTL_SECS;
    10371037
     
    12161216        case TR_PEER_PEER_GOT_DATA:
    12171217        {
    1218             const time_t now = time( NULL );
     1218            const time_t now = tr_time( );
    12191219            tr_torrent * tor = t->tor;
    12201220
     
    12641264        case TR_PEER_CLIENT_GOT_DATA:
    12651265        {
    1266             const time_t now = time( NULL );
     1266            const time_t now = tr_time( );
    12671267            tr_torrent * tor = t->tor;
    12681268
     
    14111411static void
    14121412ensureAtomExists( Torrent           * t,
    1413                   const time_t        now,
    14141413                  const tr_address  * addr,
    14151414                  const tr_port       port,
     
    14301429        a->flags = flags;
    14311430        a->from = from;
    1432         a->shelf_date = now + getDefaultShelfLife( from ) + jitter;
     1431        a->shelf_date = tr_time( ) + getDefaultShelfLife( from ) + jitter;
    14331432        tr_ptrArrayInsertSorted( &t->pool, a, compareAtomsByAddress );
    14341433
     
    15011500    {
    15021501        struct peer_atom * atom;
    1503         const time_t now = time( NULL );
    1504 
    1505         ensureAtomExists( t, now, addr, port, 0, TR_PEER_FROM_INCOMING );
     1502
     1503        ensureAtomExists( t, addr, port, 0, TR_PEER_FROM_INCOMING );
    15061504        atom = getExistingAtom( t, addr );
    1507         atom->time = now;
     1505        atom->time = tr_time( );
    15081506        atom->piece_data_time = 0;
    15091507
     
    16151613        if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) )
    16161614            if( tr_isValidPeerAddress( &pex->addr, pex->port ) )
    1617                 ensureAtomExists( t, time( NULL ), &pex->addr, pex->port, pex->flags, from );
     1615                ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from );
    16181616
    16191617        managerUnlock( t->manager );
     
    25972595    static time_t prevTime = 0;
    25982596    static int    newConnectionsThisSecond = 0;
    2599     const time_t  now = time( NULL );
     2597    const time_t  now = tr_time( );
    26002598
    26012599    if( prevTime != now )
     
    30383036            i = 0;
    30393037            if( keepCount < maxAtomCount ) {
    3040                 tr_now = time( NULL );
     3038                tr_now = tr_time( );
    30413039                qsort( test, testCount, sizeof( struct peer_atom * ), compareAtomPtrsByShelfDate );
    30423040                while( i<testCount && keepCount<maxAtomCount )
  • trunk/libtransmission/peer-msgs.c

    r9582 r9593  
    784784                     int           choke )
    785785{
    786     const time_t now = time( NULL );
     786    const time_t now = tr_time( );
    787787    const time_t fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
    788788
     
    19971997{
    19981998    tr_peermsgs * msgs = vmsgs;
    1999     const time_t  now = time( NULL );
     1999    const time_t  now = tr_time( );
    20002000
    20012001    if ( tr_isPeerIo( msgs->peer->io ) ) {
     
    23262326        tr_free( newPex6 );
    23272327
    2328         /*msgs->clientSentPexAt = time( NULL );*/
     2328        /*msgs->clientSentPexAt = tr_time( );*/
    23292329    }
    23302330}
  • trunk/libtransmission/rpc-server.c

    r9387 r9593  
    9393get_current_session_id( struct tr_rpc_server * server )
    9494{
    95     const time_t now = time( NULL );
     95    const time_t now = tr_time( );
    9696
    9797    if( !server->sessionId || ( now >= server->sessionIdExpiresAt ) )
     
    423423        {
    424424            struct evbuffer * out;
    425             const time_t now = time( NULL );
     425            const time_t now = tr_time( );
    426426
    427427            errno = error;
  • trunk/libtransmission/rpcimpl.c

    r9582 r9593  
    151151        {
    152152            tr_torrent * tor = NULL;
    153             const time_t now = time( NULL );
     153            const time_t now = tr_time( );
    154154            const time_t window = RECENTLY_ACTIVE_SECONDS;
    155155            const int n = tr_sessionCountTorrents( session );
     
    626626        int n = 0;
    627627        tr_benc * d;
    628         const time_t now = time( NULL );
     628        const time_t now = tr_time( );
    629629        const int interval = RECENTLY_ACTIVE_SECONDS;
    630630        tr_benc * removed_out = tr_bencDictAddList( args_out, "removed", 0 );
  • trunk/libtransmission/session.c

    r9564 r9593  
    629629static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUser );
    630630
     631static void
     632onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
     633{
     634    struct timeval tv;
     635    tr_session * session = vsession;
     636
     637    assert( tr_isSession( session ) );
     638    assert( session->nowTimer != NULL );
     639
     640    /* schedule the next timer for right after the next second begins */
     641    gettimeofday( &tv, NULL );
     642    tr_timerAdd( session->nowTimer, 0, 1000000 - tv.tv_usec );
     643    tr_timeUpdate( tv.tv_sec );
     644    /* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec );  */
     645}
     646
    631647static void
    632648tr_sessionInitImpl( void * vdata )
     
    646662    tr_sessionGetDefaultSettings( data->configDir, &settings );
    647663    tr_bencMergeDicts( &settings, clientSettings );
     664
     665    session->nowTimer = tr_new0( struct event, 1 );
     666    evtimer_set( session->nowTimer, onNowTimer, session );
     667    onNowTimer( 0, 0, session );
    648668
    649669#ifndef WIN32
     
    15161536    tr_free( session->saveTimer );
    15171537    session->saveTimer = NULL;
     1538
     1539    evtimer_del( session->nowTimer );
     1540    tr_free( session->nowTimer );
     1541    session->nowTimer = NULL;
    15181542
    15191543    evtimer_del( session->altTimer );
  • trunk/libtransmission/session.h

    r9387 r9593  
    131131
    132132    struct event               * altTimer;
     133    struct event               * nowTimer;
    133134    struct event               * saveTimer;
    134135
  • trunk/libtransmission/stats.c

    r8588 r9593  
    114114    loadCumulativeStats( session, &stats->old );
    115115    stats->single.sessionCount = 1;
    116     stats->startTime = time( NULL );
     116    stats->startTime = tr_time( );
    117117    session->sessionStats = stats;
    118118}
     
    168168    {
    169169        *setme = stats->single;
    170         setme->secondsActive = time( NULL ) - stats->startTime;
     170        setme->secondsActive = tr_time( ) - stats->startTime;
    171171        updateRatio( setme );
    172172    }
     
    200200
    201201    session->sessionStats->single = session->sessionStats->old = zero;
    202     session->sessionStats->startTime = time( NULL );
     202    session->sessionStats->startTime = tr_time( );
    203203}
    204204
  • trunk/libtransmission/torrent.c

    r9591 r9593  
    672672    tr_torrentUncheck( tor );
    673673
    674     tr_torrentSetAddedDate( tor, time( NULL ) ); /* this is a default value to be
    675                                                     overwritten by the resume file */
     674    tr_torrentSetAddedDate( tor, tr_time( ) ); /* this is a default value to be
     675                                                  overwritten by the resume file */
    676676
    677677    torrentInitFromInfo( tor );
     
    892892tr_torrentStatCached( tr_torrent * tor )
    893893{
    894     const time_t now = time( NULL );
     894    const time_t now = tr_time( );
    895895
    896896    return tr_isTorrent( tor ) && ( now == tor->lastStatTime )
     
    906906
    907907    tor->verifyState = state;
    908     tor->anyDate = time( NULL );
     908    tor->anyDate = tr_time( );
    909909}
    910910
     
    944944    tr_torrentLock( tor );
    945945
    946     tor->lastStatTime = time( NULL );
     946    tor->lastStatTime = tr_time( );
    947947
    948948    s = &tor->stats;
     
    13551355    else
    13561356    {
    1357         const time_t now = time( NULL );
     1357        const time_t now = tr_time( );
    13581358        tor->isRunning = TRUE;
    13591359        tor->needsSeedRatioCheck = TRUE;
     
    15341534    d = tr_bencListAddDict( &tor->session->removedTorrents, 2 );
    15351535    tr_bencDictAddInt( d, "id", tor->uniqueId );
    1536     tr_bencDictAddInt( d, "date", time( NULL ) );
     1536    tr_bencDictAddInt( d, "date", tr_time( ) );
    15371537
    15381538    stopTorrent( tor );
     
    16831683            tr_announcerTorrentCompleted( tor );
    16841684
    1685             tor->doneDate = tor->anyDate = time( NULL );
     1685            tor->doneDate = tor->anyDate = tr_time( );
    16861686        }
    16871687
  • trunk/libtransmission/utils.c

    r9589 r9593  
    4545#include "version.h"
    4646
     47
    4748static tr_lock *      messageLock = NULL;
    4849static int            messageLevel = 0;
     
    5657    static void OutputDebugString( const void * unused UNUSED ) { }
    5758#endif
     59
     60/***
     61****
     62***/
     63
     64time_t transmission_now = 0;
     65
     66void
     67tr_timeUpdate( time_t now )
     68{
     69    transmission_now = now;
     70}
     71
     72/***
     73****
     74***/
     75
    5876
    5977static void
     
    202220{
    203221    char           tmp[64];
    204     time_t         now;
    205222    struct tm      now_tm;
    206223    struct timeval tv;
    207224    int            milliseconds;
    208225
    209     now = time( NULL );
    210226    gettimeofday( &tv, NULL );
    211227
    212     tr_localtime_r( &now, &now_tm );
     228    tr_localtime_r( &tv.tv_sec, &now_tm );
    213229    strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm );
    214230    milliseconds = (int)( tv.tv_usec / 1000 );
     
    326342                newmsg = tr_new0( tr_msg_list, 1 );
    327343                newmsg->level = level;
    328                 newmsg->when = time( NULL );
     344                newmsg->when = tr_time( );
    329345                newmsg->message = tr_strdup( buf );
    330346                newmsg->file = file;
  • trunk/libtransmission/utils.h

    r9589 r9593  
    2020#include <string.h> /* memcpy()* */
    2121#include <stdlib.h> /* malloc() */
    22 #include <time.h> /* time_t* */
     22#include <time.h> /* time_t */
    2323
    2424#include "transmission.h"
     
    431431                                size_t sizeof_element, size_t nmemb );
    432432
     433/***
     434****
     435***/
     436
     437extern time_t transmission_now;
     438
     439static TR_INLINE time_t tr_time( void ) { return transmission_now; }
     440
     441void tr_timeUpdate( time_t now );
     442
     443/***
     444****
     445***/
     446
    433447#ifdef __cplusplus
    434448}
  • trunk/libtransmission/verify.c

    r9328 r9593  
    5858    const int64_t buflen = tor->info.pieceSize;
    5959    uint8_t * buffer = tr_new( uint8_t, buflen );
    60     const time_t begin = time( NULL );
     60    const time_t begin = tr_time( );
    6161    time_t end;
    6262
     
    128128            }
    129129            tr_torrentSetPieceChecked( tor, pieceIndex, TRUE );
    130             now = time( NULL );
     130            now = tr_time( );
    131131            tor->anyDate = now;
    132132
     
    160160
    161161    /* stopwatch */
    162     end = time( NULL );
     162    end = tr_time( );
    163163    tr_tordbg( tor, "it took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)",
    164164               (int)(end-begin), tor->info.totalSize, (uint64_t)(tor->info.totalSize/(1+(end-begin))) );
Note: See TracChangeset for help on using the changeset viewer.