Changeset 4044


Ignore:
Timestamp:
Dec 3, 2007, 3:27:38 PM (14 years ago)
Author:
charles
Message:

finish fixing the recursive mutex + cond bug reported by sedatg & Waldorf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r4043 r4044  
    191191tr_fdFileCheckout( const char * filename, int write )
    192192{
    193     int i, winner;
     193    int i, winner = -1;
    194194    struct tr_openfile * o;
    195195
     
    214214        if( fileIsCheckedOut( o ) ) {
    215215            dbgmsg( "found it!  it's open, but checked out.  waiting..." );
    216             tr_wait( 100 );
     216            tr_lockUnlock( gFd->lock );
     217            tr_wait( 200 );
     218            tr_lockLock( gFd->lock );
    217219            i = -1; /* reloop */
    218220            continue;
     
    227229        dbgmsg( "found it!  it's ready for use!" );
    228230        winner = i;
    229         goto done;
    230     }
    231 
     231        break;
     232    }
    232233
    233234    dbgmsg( "it's not already open.  looking for an open slot or an old file." );
    234     for( ;; )
     235    while( winner < 0 )
    235236    {
    236237        uint64_t date = tr_date( ) + 1;
    237         winner = -1;
    238 
     238
     239        /* look for the file that's been open longest */
    239240        for( i=0; i<TR_MAX_OPEN_FILES; ++i )
    240241        {
     
    244245                winner = i;
    245246                dbgmsg( "found an empty slot in %d", winner );
    246                 goto done;
     247                break;
    247248            }
    248249
     
    256257            dbgmsg( "closing file '%s', slot #%d", gFd->open[winner].filename, winner );
    257258            TrCloseFile( winner );
    258             goto done;
    259         }
    260 
    261         /* All used! Wait a bit and try again */
    262         dbgmsg( "everything's full!  waiting for someone else to finish something" );
    263         tr_wait( 100 );
    264     }
    265 
    266 done:
    267 
     259        } else {
     260            dbgmsg( "everything's full!  waiting for someone else to finish something" );
     261            tr_lockUnlock( gFd->lock );
     262            tr_wait( 200 );
     263            tr_lockLock( gFd->lock );
     264        }
     265    }
     266
     267    assert( winner >= 0 );
    268268    o = &gFd->open[winner];
    269269    if( !fileIsOpen( o ) )
Note: See TracChangeset for help on using the changeset viewer.