Changeset 12508


Ignore:
Timestamp:
Jun 19, 2011, 6:30:57 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) avoid thread issues on startup by ensuring that tr_sessionLoadTorrents() runs in the libtransmission thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r12461 r12508  
    18521852}
    18531853
    1854 tr_torrent **
    1855 tr_sessionLoadTorrents( tr_session * session,
    1856                         tr_ctor    * ctor,
    1857                         int        * setmeCount )
    1858 {
    1859     int           i, n = 0;
    1860     struct stat   sb;
    1861     DIR *         odir = NULL;
    1862     const char *  dirname = tr_getTorrentDir( session );
     1854struct sessionLoadTorrentsData
     1855{
     1856    tr_session * session;
     1857    tr_ctor * ctor;
     1858    int * setmeCount;
    18631859    tr_torrent ** torrents;
    1864     tr_list *     l = NULL, *list = NULL;
    1865 
    1866     assert( tr_isSession( session ) );
    1867 
    1868     tr_ctorSetSave( ctor, false ); /* since we already have them */
     1860    bool done;
     1861};
     1862
     1863static void
     1864sessionLoadTorrents( void * vdata )
     1865{
     1866    int i;
     1867    int n = 0;
     1868    struct stat sb;
     1869    DIR * odir = NULL;
     1870    tr_list * l = NULL;
     1871    tr_list * list = NULL;
     1872    struct sessionLoadTorrentsData * data = vdata;
     1873    const char * dirname = tr_getTorrentDir( data->session );
     1874
     1875    assert( tr_isSession( data->session ) );
     1876
     1877    tr_ctorSetSave( data->ctor, false ); /* since we already have them */
    18691878
    18701879    if( !stat( dirname, &sb )
     
    18791888                tr_torrent * tor;
    18801889                char * path = tr_buildPath( dirname, d->d_name, NULL );
    1881                 tr_ctorSetMetainfoFromFile( ctor, path );
    1882                 if(( tor = tr_torrentNew( ctor, NULL )))
     1890                tr_ctorSetMetainfoFromFile( data->ctor, path );
     1891                if(( tor = tr_torrentNew( data->ctor, NULL )))
    18831892                {
    18841893                    tr_list_prepend( &list, tor );
     
    18911900    }
    18921901
    1893     torrents = tr_new( tr_torrent *, n );
     1902    data->torrents = tr_new( tr_torrent *, n );
    18941903    for( i = 0, l = list; l != NULL; l = l->next )
    1895         torrents[i++] = (tr_torrent*) l->data;
     1904        data->torrents[i++] = (tr_torrent*) l->data;
    18961905    assert( i == n );
    18971906
     
    19011910        tr_inf( _( "Loaded %d torrents" ), n );
    19021911
    1903     if( setmeCount )
    1904         *setmeCount = n;
    1905     return torrents;
     1912    if( data->setmeCount )
     1913        *data->setmeCount = n;
     1914
     1915    data->done = true;
     1916}
     1917
     1918tr_torrent **
     1919tr_sessionLoadTorrents( tr_session * session,
     1920                        tr_ctor    * ctor,
     1921                        int        * setmeCount )
     1922{
     1923    struct sessionLoadTorrentsData data;
     1924
     1925    data.session = session;
     1926    data.ctor = ctor;
     1927    data.setmeCount = setmeCount;
     1928    data.torrents = NULL;
     1929    data.done = false;
     1930
     1931    tr_runInEventThread( session, sessionLoadTorrents, &data );
     1932    while( !data.done )
     1933        tr_wait_msec( 100 );
     1934
     1935    return data.torrents;
    19061936}
    19071937
Note: See TracChangeset for help on using the changeset viewer.