Changeset 10524


Ignore:
Timestamp:
Apr 23, 2010, 11:45:44 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #2842 "Transmission crashes randomly on ARM-based Synology NAS" -- experimental commit based on giovannibajo's suggestion in comment:39 about the list struct's alignment

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/list.c

    r9891 r10524  
    158158    return size;
    159159}
    160 
    161 
    162 
    163 /*
    164  * Double-linked list with easy memory management and fast
    165  * insert/remove operations
    166  */
    167 
    168 
    169 void
    170 __tr_list_insert( struct __tr_list * list,
    171                   struct __tr_list * prev,
    172                   struct __tr_list * next)
    173 {
    174     next->prev = list;
    175     list->next = next;
    176     list->prev = prev;
    177     prev->next = list;
    178 }
    179 
    180 static void
    181 __tr_list_splice( struct __tr_list * prev,
    182                   struct __tr_list * next)
    183 {
    184     next->prev = prev;
    185     prev->next = next;
    186 }
    187 
    188 void
    189 __tr_list_remove( struct __tr_list * head )
    190 {
    191     __tr_list_splice( head->prev, head->next );
    192     head->next = head->prev = NULL;
    193 }
    194 
    195 void
    196 __tr_list_destroy( struct __tr_list * head,
    197                    __tr_list_free_t   func)
    198 {
    199     while ( head->next != head )
    200     {
    201         struct __tr_list * list = head->next;
    202         __tr_list_splice( list->prev, list->next );
    203 
    204         func( list );
    205     }
    206 }
  • trunk/libtransmission/list.h

    r9891 r10524  
    102102
    103103
    104 /** @brief Double-linked list with easy memory management and fast insert/remove operations */
    105 struct __tr_list
    106 {
    107     struct __tr_list * next, * prev;
    108 };
    109 
    110 /**
    111  * @brief Given a __tr_list node that's embedded in a struct, returns a pointer to the struct.
    112  * @param ptr     pointer to the embedded __tr_list
    113  * @param type    struct type that has contains the __tr_list
    114  * @param field   the name of the struct's _tr_list field
    115  */
    116 #define __tr_list_entry(ptr,type,field) ((type*) (((char*)ptr) - offsetof(type,field)))
    117 
    118 typedef int  ( *__tr_list_cmp_t ) ( const void * a, const void * b );
    119 typedef void ( *__tr_list_free_t )( void * );
    120 
    121 
    122 /** @brief Init @head as an empty list. */
    123 static inline void
    124 __tr_list_init( struct __tr_list * head )
    125 {
    126     head->next = head->prev = head;
    127 }
    128 
    129 
    130 /** @brief Insert @list between @prev and @next. */
    131 void
    132 __tr_list_insert( struct __tr_list * list,
    133                   struct __tr_list * prev,
    134                   struct __tr_list * next);
    135 
    136 /** @brief Append @list to the end of @head. */
    137 static inline void
    138 __tr_list_append( struct __tr_list * head, struct __tr_list * list)
    139 {
    140     __tr_list_insert( list, head->prev, head );
    141 }
    142 
    143 /** @brief Remove @head from the list it is in. */
    144 void __tr_list_remove( struct __tr_list * head );
    145 
    146 /** @brief Destroy the list and free all nodes */
    147 void __tr_list_destroy( struct __tr_list * head, __tr_list_free_t func );
    148 
    149104/* @} */
    150105#endif /* TR_LIST_H */
  • trunk/libtransmission/peer-io.c

    r10509 r10524  
    7676    tr_bool  isPieceData;
    7777    size_t   length;
    78     struct __tr_list head;
    7978};
    8079
     
    8887     while( bytes_transferred && tr_isPeerIo( io ) )
    8988     {
    90         struct tr_datatype * next = __tr_list_entry( io->outbuf_datatypes.next, struct tr_datatype, head );
     89        struct tr_datatype * next = io->outbuf_datatypes->data;
     90
    9191        const size_t payload = MIN( next->length, bytes_transferred );
    9292        const size_t overhead = guessPacketOverhead( payload );
     
    105105            next->length -= payload;
    106106            if( !next->length ) {
    107                 __tr_list_remove( io->outbuf_datatypes.next );
     107                tr_list_pop_front( &io->outbuf_datatypes );
    108108                tr_free( next );
    109109            }
     
    414414    event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io );
    415415
    416     __tr_list_init( &io->outbuf_datatypes );
    417 
    418416    return io;
    419417}
     
    464462    assert( io->session != NULL );
    465463    assert( io->session->events != NULL );
     464    assert( io->socket >= 0 );
    466465    assert( event_initialized( &io->event_read ) );
    467466    assert( event_initialized( &io->event_write ) );
     
    527526****
    528527***/
    529 
    530 static void
    531 trDatatypeFree( void * data )
    532 {
    533     struct tr_datatype * dt = __tr_list_entry( data, struct tr_datatype, head );
    534     tr_free(dt);
    535 }
    536528
    537529static void
     
    551543    tr_netClose( io->session, io->socket );
    552544    tr_cryptoFree( io->crypto );
    553     __tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree );
     545    tr_list_free( &io->outbuf_datatypes, tr_free );
    554546
    555547    memset( io, ~0, sizeof( tr_peerIo ) );
     
    817809    datatype->isPieceData = isPieceData != 0;
    818810    datatype->length = byteCount;
    819 
    820     __tr_list_init( &datatype->head );
    821     __tr_list_append( &io->outbuf_datatypes, &datatype->head );
     811    tr_list_append( &io->outbuf_datatypes, datatype );
    822812
    823813    switch( io->encryptionMode )
     
    998988{
    999989    size_t byteCount = 0;
    1000     struct __tr_list * walk;
    1001     struct __tr_list * fencepost = &io->outbuf_datatypes;
     990    tr_list * it;
    1002991
    1003992    /* count up how many bytes are used by non-piece-data messages
    1004993       at the front of our outbound queue */
    1005     for( walk=fencepost->next; walk!=fencepost; walk=walk->next ) {
    1006         struct tr_datatype * d = __tr_list_entry( walk, struct tr_datatype, head );
     994    for( it=io->outbuf_datatypes; it!=NULL; it=it->next )
     995    {
     996        struct tr_datatype * d = it->data;
     997
    1007998        if( d->isPieceData )
    1008999            break;
     1000
    10091001        byteCount += d->length;
    10101002    }
  • trunk/libtransmission/peer-io.h

    r9868 r10524  
    2828#include "transmission.h"
    2929#include "bandwidth.h"
    30 #include "list.h" /* __tr_list */
     30#include "list.h" /* tr_list */
    3131#include "net.h" /* tr_address */
    3232
     
    107107    struct evbuffer     * inbuf;
    108108    struct evbuffer     * outbuf;
    109     struct __tr_list      outbuf_datatypes; /* struct tr_datatype */
     109    struct tr_list      * outbuf_datatypes; /* struct tr_datatype */
    110110
    111111    struct event          event_read;
Note: See TracChangeset for help on using the changeset viewer.