Changeset 2829


Ignore:
Timestamp:
Aug 18, 2007, 3:02:32 AM (14 years ago)
Author:
charles
Message:

do all the libevent enqueuing from a single thread.

Location:
trunk/libtransmission
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r2762 r2829  
    3737    tracker.c \
    3838    transmission.c \
     39    trevent.c \
    3940    upnp.c \
    4041    utils.c \
     
    7677    transmission.h \
    7778    trcompat.h \
     79    trevent.h \
    7880    upnp.h \
    7981    utils.h \
  • trunk/libtransmission/internal.h

    r2805 r2829  
    173173struct tr_handle_s
    174174{
     175    struct tr_event_handle_s * events;
     176
    175177    int                        torrentCount;
    176178    tr_torrent_t             * torrentList;
  • trunk/libtransmission/timer.c

    r2757 r2829  
    1515
    1616#include "transmission.h"
     17#include "trevent.h"
    1718#include "timer.h"
    1819#include "utils.h"
     
    8182
    8283tr_timer_tag
    83 tr_timerNew( tr_timer_func        func,
     84tr_timerNew( tr_handle_t        * handle,
     85             tr_timer_func        func,
    8486             void               * user_data,
    8587             tr_data_free_func    free_func,
     
    100102    node->tv.tv_usec = microseconds % 1000000;
    101103    timeout_set( &node->event, timerCB, node );
    102     timeout_add( &node->event, &node->tv );
     104    tr_event_add( handle, &node->event, &node->tv );
    103105    return node;
    104106}
  • trunk/libtransmission/timer.h

    r2757 r2829  
    2424 * if user_data has resources that need to be freed.
    2525 */
    26 tr_timer_tag  tr_timerNew( int     timer_func( void * user_data ),
    27                            void  * user_data,
    28                            void    free_func( void * user_data ),
    29                            int     timeout_milliseconds );
     26tr_timer_tag  tr_timerNew( struct tr_handle_s   * handle,
     27                           int                    timer_func( void * user_data ),
     28                           void                 * user_data,
     29                           void                   free_func( void * user_data ),
     30                           int                    timeout_milliseconds );
    3031
    3132/**
  • trunk/libtransmission/tracker.c

    r2821 r2829  
    2929#include "timer.h"
    3030#include "tracker.h"
     31#include "trevent.h"
    3132#include "utils.h"
    3233
     
    6162typedef struct
    6263{
     64    tr_handle_t * handle;
     65
    6366    tr_ptrArray_t * torrents;
    6467    tr_ptrArray_t * scraping;
     
    229232
    230233    if( !t->scrapeTag )
    231          t->scrapeTag = tr_timerNew( onTrackerScrapeNow, t, NULL, 1000 );
     234         t->scrapeTag = tr_timerNew( t->handle, onTrackerScrapeNow, t, NULL, 1000 );
    232235}
    233236
    234237static Tracker*
    235 tr_trackerGet( const tr_info_t * info )
    236 {
     238tr_trackerGet( const tr_torrent_t * tor )
     239{
     240    const tr_info_t * info = &tor->info;
    237241    tr_ptrArray_t * trackers = getTrackerLookupTable( );
    238242    Tracker *t, tmp;
     
    251255
    252256        t = tr_new0( Tracker, 1 );
     257        t->handle = tor->handle;
    253258        t->primaryAddress = tr_strdup( info->primaryAddress );
    254259        t->scrapeIntervalMsec      = DEFAULT_SCRAPE_INTERVAL_MSEC;
     
    354359{
    355360    Torrent * tor;
    356     Tracker * t = tr_trackerGet( &torrent->info );
     361    Tracker * t = tr_trackerGet( torrent );
    357362    assert( getExistingTorrent( t, torrent->info.hash ) == NULL );
    358363
     
    397402    if( !req )
    398403    {
     404        tr_inf( "Connecting to %s got a NULL response",
     405                t->addresses[t->addressIndex].announce );
    399406        moveToNextAddress = TRUE;
    400407    }
     
    549556
    550557                assert( !tor->scrapeTag );
    551                 tor->scrapeTag = tr_timerNew( onTorrentScrapeNow,
     558                tor->scrapeTag = tr_timerNew( t->handle,
     559                                              onTorrentScrapeNow,
    552560                                              tor, NULL,
    553561                                              t->scrapeIntervalMsec );
     
    657665        assert( req );
    658666        addCommonHeaders( t, req );
    659         evhttp_make_request( evcon, req, EVHTTP_REQ_GET, uri );
    660 
    661         tr_free( uri );
     667        tr_evhttp_make_request( t->handle, evcon, req, EVHTTP_REQ_GET, uri );
    662668    }
    663669
     
    869875        tr_inf( "torrent '%s' reannouncing in %d seconds",
    870876                tor->torrent->info.name, (reannounceInterval/1000) );
    871         tor->reannounceTag = tr_timerNew( onReannounceNow, tor, NULL,
     877        tor->reannounceTag = tr_timerNew( tor->tracker->handle,
     878                                          onReannounceNow, tor, NULL,
    872879                                          reannounceInterval );
    873880        tor->manualAnnounceAllowedAt
     
    899906        tor->httpReq = evhttp_request_new( onTrackerResponse, tor );
    900907        addCommonHeaders( tor->tracker, tor->httpReq );
    901         evhttp_make_request( evcon, tor->httpReq, EVHTTP_REQ_GET, uri );
     908        tr_evhttp_make_request( tor->tracker->handle, evcon, tor->httpReq, EVHTTP_REQ_GET, uri );
    902909    }
    903910
  • trunk/libtransmission/transmission.c

    r2816 r2829  
    3434#include <dirent.h> /* opendir */
    3535
    36 #include <event.h>
    37 
    3836#include "transmission.h"
    3937#include "fdlimit.h"
     
    4341#include "ratecontrol.h"
    4442#include "shared.h"
     43#include "trevent.h"
    4544#include "utils.h"
    4645
     
    6463}
    6564
    66 static int shuttingDown = FALSE;
    67 
    68 static void
    69 libeventThreadFunc( void * unused UNUSED )
    70 {
    71     tr_dbg( "libevent thread starting" );
    72     event_init( );
    73     while( !shuttingDown )
    74     {
    75         event_dispatch( );
    76         tr_wait( 50 ); /* 1/20th of a second */
    77     }
    78     tr_dbg( "libevent thread exiting" );
    79 }
     65/***
     66****
     67***/
    8068
    8169
     
    9179
    9280    tr_msgInit();
    93     tr_threadNew( libeventThreadFunc, NULL, "libeventThreadFunc" );
     81
     82    h = tr_new0( tr_handle_t, 1 );
     83    if( !h )
     84        return NULL;
     85
     86    tr_eventInit( h );
    9487    tr_netInit();
    9588    tr_netResolveThreadInit();
    96 
    97     h = calloc( 1, sizeof( tr_handle_t ) );
    98     if( !h )
    99         return NULL;
    10089
    10190    h->tag = strdup( tag );
     
    249238
    250239    tr_netResolveThreadClose();
    251 
    252     /* end the event thread */
    253     shuttingDown = TRUE;
     240    tr_eventClose( h );
    254241}
    255242
Note: See TracChangeset for help on using the changeset viewer.