Ignore:
Timestamp:
Apr 18, 2009, 11:17:30 PM (13 years ago)
Author:
charles
Message:

(trunk) experimental support for tr_torrentSetPriority()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7791 r8254  
    149149static void
    150150allocateBandwidth( tr_bandwidth  * b,
     151                   tr_priority_t   parent_priority,
    151152                   tr_direction    dir,
    152153                   int             period_msec,
    153154                   tr_ptrArray   * peer_pool )
    154155{
     156    tr_priority_t priority;
     157
    155158    assert( tr_isBandwidth( b ) );
    156159    assert( tr_isDirection( dir ) );
     
    171174    }
    172175
     176    priority = MAX( parent_priority, b->priority );
     177
    173178    /* add this bandwidth's peer, if any, to the peer pool */
    174     if( b->peer != NULL )
     179    if( b->peer != NULL ) {
     180        b->peer->priority = priority;
    175181        tr_ptrArrayAppend( peer_pool, b->peer );
     182    }
    176183
    177184#ifdef DEBUG_DIRECTION
     
    186193        const int n = tr_ptrArraySize( &b->children );
    187194        for( i=0; i<n; ++i )
    188             allocateBandwidth( children[i], dir, period_msec, peer_pool );
    189     }
    190 }
    191 
    192 void
    193 tr_bandwidthAllocate( tr_bandwidth  * b,
    194                       tr_direction    dir,
    195                       int             period_msec )
    196 {
    197     int i, n, peerCount;
    198     tr_ptrArray tmp = TR_PTR_ARRAY_INIT;
    199     struct tr_peerIo ** peers;
    200 
    201     /* allocateBandwidth() is a helper function with two purposes:
    202      * 1. allocate bandwidth to b and its subtree
    203      * 2. accumulate an array of all the peerIos from b and its subtree. */
    204     allocateBandwidth( b, dir, period_msec, &tmp );
    205     peers = (struct tr_peerIo**) tr_ptrArrayBase( &tmp );
    206     peerCount = tr_ptrArraySize( &tmp );
    207 
    208     for( i=0; i<peerCount; ++i )
    209         tr_peerIoRef( peers[i] );
     195            allocateBandwidth( children[i], priority, dir, period_msec, peer_pool );
     196    }
     197}
     198
     199static void
     200phaseOne( tr_ptrArray * peerArray, tr_direction dir )
     201{
     202    int i, n;
     203    int peerCount = tr_ptrArraySize( peerArray );
     204    struct tr_peerIo ** peers = (struct tr_peerIo**) tr_ptrArrayBase( peerArray );
    210205
    211206    /* First phase of IO.  Tries to distribute bandwidth fairly to keep faster
     
    236231            i = 0;
    237232    }
     233}
     234
     235void
     236tr_bandwidthAllocate( tr_bandwidth  * b,
     237                      tr_direction    dir,
     238                      int             period_msec )
     239{
     240    int i, peerCount;
     241    tr_ptrArray tmp = TR_PTR_ARRAY_INIT;
     242    tr_ptrArray low = TR_PTR_ARRAY_INIT;
     243    tr_ptrArray high = TR_PTR_ARRAY_INIT;
     244    tr_ptrArray normal = TR_PTR_ARRAY_INIT;
     245    struct tr_peerIo ** peers;
     246
     247    /* allocateBandwidth() is a helper function with two purposes:
     248     * 1. allocate bandwidth to b and its subtree
     249     * 2. accumulate an array of all the peerIos from b and its subtree. */
     250    allocateBandwidth( b, TR_PRI_LOW, dir, period_msec, &tmp );
     251    peers = (struct tr_peerIo**) tr_ptrArrayBase( &tmp );
     252    peerCount = tr_ptrArraySize( &tmp );
     253
     254    for( i=0; i<peerCount; ++i ) {
     255        tr_peerIoRef( peers[i] );
     256        switch( peers[i]->priority ) {
     257            case TR_PRI_HIGH: tr_ptrArrayAppend( &high,   peers[i] ); break;
     258            case TR_PRI_LOW:  tr_ptrArrayAppend( &low,    peers[i] ); break;
     259            default:          tr_ptrArrayAppend( &normal, peers[i] ); break;
     260        }
     261    }
     262
     263    /* First phase of IO.  Tries to distribute bandwidth fairly to keep faster
     264     * peers from starving the others.  Loop through the peers, giving each a
     265     * small chunk of bandwidth.  Keep looping until we run out of bandwidth
     266     * and/or peers that can use it */
     267    phaseOne( &high, dir );
     268    phaseOne( &normal, dir );
     269    phaseOne( &low, dir );
    238270
    239271    /* Second phase of IO.  To help us scale in high bandwidth situations,
     
    248280
    249281    /* cleanup */
     282    tr_ptrArrayDestruct( &normal, NULL );
     283    tr_ptrArrayDestruct( &high, NULL );
     284    tr_ptrArrayDestruct( &low, NULL );
    250285    tr_ptrArrayDestruct( &tmp, NULL );
    251286}
Note: See TracChangeset for help on using the changeset viewer.