Changeset 3232


Ignore:
Timestamp:
Sep 29, 2007, 2:19:23 PM (15 years ago)
Author:
charles
Message:

more work on the peer-mgr locks

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r3231 r3232  
    10851085    handshake->doneUserData = doneUserData;
    10861086    handshake->handle = tr_peerIoGetHandle( io );
    1087 
    10881087    handshake->startTimer = tr_timerNew( handshake->handle,
    10891088                                         handshakeStart,
  • trunk/libtransmission/peer-mgr.c

    r3231 r3232  
    3232#include "utils.h"
    3333
     34#include "pthread.h"
     35
    3436enum
    3537{
     
    107109    tr_ptrArray * handshakes; /* in-process */
    108110    tr_lock * lock;
    109     uint8_t isLocked;
     111    pthread_t lockThread;
    110112};
    111113
     
    117119managerLock( struct tr_peerMgr * manager )
    118120{
    119     assert( !manager->isLocked );
     121    assert( manager->lockThread != pthread_self() );
    120122    tr_lockLock( manager->lock );
    121     manager->isLocked = TRUE;
     123    manager->lockThread = pthread_self();
    122124}
    123125static void
    124126managerUnlock( struct tr_peerMgr * manager )
    125127{
    126     assert( manager->isLocked );
    127     manager->isLocked = FALSE;
     128    assert( manager->lockThread == pthread_self() );
     129    manager->lockThread = 0;
    128130    tr_lockUnlock( manager->lock );
    129131}
     
    141143torrentIsLocked( Torrent * t )
    142144{
    143     return t!=NULL && t->manager!=NULL && t->manager->isLocked;
    144 }
    145 
    146 #define managerLock(a) fprintf(stderr,"%s:%d locking\n",__FILE__,__LINE__); managerLock(a);
     145    return t!=NULL && t->manager!=NULL && t->manager->lockThread!=0;
     146}
    147147
    148148/**
     
    509509            setme->priority = inf->pieces[piece].priority;
    510510            setme->peerCount = 0;
     511            setme->fastAllowed = 0;
    511512            /* FIXME */
    512513//            setme->fastAllowed = tr_bitfieldHas( t->tor->allowedList, i);
     
    771772    Torrent * t = (Torrent *) vt;
    772773    const tr_peermsgs_event * e = (const tr_peermsgs_event *) vevent;
    773 
    774     torrentLock( t );
     774    const int needLock = !torrentIsLocked( t );
     775
     776    if( needLock )
     777        torrentLock( t );
    775778
    776779    switch( e->eventType )
     
    811814    }
    812815
    813     torrentUnlock( t );
     816    if( needLock )
     817        torrentUnlock( t );
    814818}
    815819
     
    895899    tr_handshake * handshake;
    896900
    897     assert( manager->isLocked );
     901    assert( manager->lockThread!=0 );
    898902    assert( io != NULL );
    899903
Note: See TracChangeset for help on using the changeset viewer.