Ignore:
Timestamp:
Jan 2, 2009, 5:46:22 PM (12 years ago)
Author:
charles
Message:

(trunk libT) inline parts of peer-io and bandwidth, too

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.h

    r7576 r7579  
    1717#ifndef TR_BANDWIDTH_H
    1818#define TR_BANDWIDTH_H
     19
     20#include "transmission.h"
     21#include "ptrarray.h"
     22
     23struct tr_peerIo;
     24
     25/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     26 * it's included in the header for inlining and composition. */
     27enum
     28{
     29    HISTORY_MSEC = 2000,
     30    INTERVAL_MSEC = HISTORY_MSEC,
     31    GRANULARITY_MSEC = 50,
     32    HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ),
     33    MAGIC_NUMBER = 43143
     34};
     35
     36/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     37 * it's included in the header for inlining and composition. */
     38struct bratecontrol
     39{
     40    int newest;
     41    struct { uint64_t date, size; } transfers[HISTORY_SIZE];
     42};
     43
     44/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     45 * it's included in the header for inlining and composition. */
     46struct tr_band
     47{
     48    tr_bool isLimited;
     49    tr_bool honorParentLimits;
     50    size_t bytesLeft;
     51    double desiredSpeed;
     52    struct bratecontrol raw;
     53    struct bratecontrol piece;
     54};
    1955
    2056/**
     
    5793 *   bandwidth they can safely use.
    5894 */
    59 
    60 typedef struct tr_bandwidth tr_bandwidth;
    61 
    62 struct tr_peerIo;
     95typedef struct tr_bandwidth
     96{
     97    /* these are PRIVATE IMPLEMENTATION details that should not be touched.
     98     * it's included in the header for inlining and composition. */
     99
     100    struct tr_band band[2];
     101    struct tr_bandwidth * parent;
     102    int magicNumber;
     103    tr_session * session;
     104    tr_ptrArray children; /* struct tr_bandwidth */
     105    tr_ptrArray peers; /* tr_peerIo */
     106}
     107tr_bandwidth;
     108
    63109
    64110/**
     
    75121
    76122/** @brief test to see if the pointer refers to a live bandwidth object */
    77 extern inline tr_bool
    78          tr_isBandwidth               ( const tr_bandwidth  * bandwidth );
     123static inline tr_bool tr_isBandwidth( const tr_bandwidth  * b )
     124{
     125    return ( b != NULL ) && ( b->magicNumber == MAGIC_NUMBER );
     126}
    79127
    80128/******
     
    87135 * @see tr_bandwidthGetDesiredSpeed
    88136 */
    89 extern inline void
    90         tr_bandwidthSetDesiredSpeed   ( tr_bandwidth        * bandwidth,
    91                                         tr_direction          direction,
    92                                         double                desiredSpeed );
     137static inline void tr_bandwidthSetDesiredSpeed( tr_bandwidth        * bandwidth,
     138                                                tr_direction          dir,
     139                                                double                desiredSpeed )
     140{
     141    bandwidth->band[dir].desiredSpeed = desiredSpeed;
     142}
    93143
    94144/**
     
    96146 * @see tr_bandwidthSetDesiredSpeed
    97147 */
    98 extern inline double
    99         tr_bandwidthGetDesiredSpeed   ( const tr_bandwidth  * bandwidth,
    100                                         tr_direction          direction );
     148static inline double
     149tr_bandwidthGetDesiredSpeed( const tr_bandwidth  * bandwidth,
     150                             tr_direction          dir )
     151{
     152    return bandwidth->band[dir].desiredSpeed;
     153}
    101154
    102155/**
    103156 * @brief Set whether or not this bandwidth should throttle its peer-io's speeds
    104157 */
    105 extern inline void
    106         tr_bandwidthSetLimited        ( tr_bandwidth        * bandwidth,
    107                                         tr_direction          direction,
    108                                         tr_bool               isLimited );
     158static inline void tr_bandwidthSetLimited( tr_bandwidth        * bandwidth,
     159                                           tr_direction          dir,
     160                                           tr_bool               isLimited )
     161{
     162    bandwidth->band[dir].isLimited = isLimited;
     163}
    109164
    110165/**
    111166 * @return nonzero if this bandwidth throttles its peer-ios speeds
    112167 */
    113 extern inline tr_bool
    114         tr_bandwidthIsLimited         ( const tr_bandwidth  * bandwidth,
    115                                         tr_direction          direction );
     168static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth  * bandwidth,
     169                                             tr_direction          dir )
     170{
     171    return bandwidth->band[dir].isLimited;
     172}
    116173
    117174/**
     
    133190******/
    134191
    135 /**
    136  * @brief Get the raw total of bytes read or sent by this bandwidth subtree.
    137  */
    138 extern inline double
    139         tr_bandwidthGetRawSpeed       ( const tr_bandwidth  * bandwidth,
    140                                         tr_direction          direction );
    141 
    142 /**
    143  * @brief Get the number of piece data bytes read or sent by this bandwidth subtree.
    144  */
    145 extern inline double
    146         tr_bandwidthGetPieceSpeed     ( const tr_bandwidth  * bandwidth,
    147                                         tr_direction          direction );
     192/** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */
     193double tr_bandwidthGetRawSpeed( const tr_bandwidth  * bandwidth,
     194                                tr_direction          direction );
     195
     196/** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */
     197double tr_bandwidthGetPieceSpeed( const tr_bandwidth  * bandwidth,
     198                                  tr_direction          direction );
    148199
    149200/**
     
    181232 * They will be notified when more bandwidth is made available for them to consume.
    182233 */
    183 extern inline void
    184         tr_bandwidthAddPeer           ( tr_bandwidth        * bandwidth,
    185                                         struct tr_peerIo    * peerIo );
     234void tr_bandwidthAddPeer( tr_bandwidth        * bandwidth,
     235                          struct tr_peerIo    * peerIo );
    186236
    187237/**
    188238 * @brief remove a peer-io from this bandwidth's list.
    189239 */
    190 extern inline void
    191         tr_bandwidthRemovePeer        ( tr_bandwidth        * bandwidth,
    192                                         struct tr_peerIo    * peerIo );
     240void tr_bandwidthRemovePeer( tr_bandwidth        * bandwidth,
     241                             struct tr_peerIo    * peerIo );
    193242
    194243#endif
Note: See TracChangeset for help on using the changeset viewer.