1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00
This commit is contained in:
Eric Petit 2007-01-19 01:39:33 +00:00
parent f55c1b05cd
commit 3e6d071e0d
4 changed files with 46 additions and 38 deletions

View file

@ -73,7 +73,7 @@ void tr_netResolveThreadInit()
resolveQueue = NULL;
tr_lockInit( &resolveLock );
tr_condInit( &resolveCond );
tr_threadCreate( &resolveThread, resolveFunc, NULL );
tr_threadCreate( &resolveThread, resolveFunc, NULL, "resolve" );
}
/***********************************************************************
@ -182,8 +182,6 @@ static void resolveFunc( void * arg UNUSED )
tr_resolve_t * r;
struct hostent * host;
tr_dbg( "Resolve thread started" );
tr_lockLock( &resolveLock );
while( !resolveDie )
@ -221,8 +219,6 @@ static void resolveFunc( void * arg UNUSED )
resolveQueue = r->next;
resolveRelease( r );
}
tr_dbg( "Resolve thread exited" );
}

View file

@ -194,13 +194,33 @@ char * tr_getTorrentsDirectory()
return torrentsDirectory;
}
void tr_threadCreate( tr_thread_t * t, void (*func)(void *), void * arg )
static void ThreadFunc( void * _t )
{
tr_thread_t * t = _t;
#ifdef SYS_BEOS
*t = spawn_thread( (void *) func, "torrent-tx", B_NORMAL_PRIORITY, arg );
resume_thread( *t );
/* This is required because on BeOS, SIGINT is sent to each thread,
which kills them not nicely */
signal( SIGINT, SIG_IGN );
#endif
tr_dbg( "Thread '%s' started", t->name );
t->func( t->arg );
tr_dbg( "Thread '%s' exited", t->name );
}
void tr_threadCreate( tr_thread_t * t, void (*func)(void *), void * arg,
char * name )
{
t->func = func;
t->arg = arg;
t->name = strdup( name );
#ifdef SYS_BEOS
t->thread = spawn_thread( (void *) ThreadFunc, name,
B_NORMAL_PRIORITY, t );
resume_thread( t->thread );
#else
pthread_create( t, NULL, (void *) func, arg );
pthread_create( &t->thread, NULL, (void *) ThreadFunc, t );
#endif
}
@ -208,10 +228,12 @@ void tr_threadJoin( tr_thread_t * t )
{
#ifdef SYS_BEOS
long exit;
wait_for_thread( *t, &exit );
wait_for_thread( t->thread, &exit );
#else
pthread_join( *t, NULL );
pthread_join( t->thread, NULL );
#endif
tr_dbg( "Thread '%s' joined", t->name );
free( t->name );
}
void tr_lockInit( tr_lock_t * l )

View file

@ -26,20 +26,29 @@
#ifdef SYS_BEOS
#include <kernel/OS.h>
typedef thread_id tr_thread_t;
typedef thread_id tr_thread_id_t;
typedef sem_id tr_lock_t;
typedef int tr_cond_t;
#else
#include <pthread.h>
typedef pthread_t tr_thread_t;
typedef pthread_t tr_thread_id_t;
typedef pthread_mutex_t tr_lock_t;
typedef pthread_cond_t tr_cond_t;
#endif
typedef struct tr_thread_s
{
void (* func ) ( void * );
void * arg;
char * name;
tr_thread_id_t thread;;
}
tr_thread_t;
char * tr_getCacheDirectory();
char * tr_getTorrentsDirectory();
void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void * arg );
void tr_threadCreate ( tr_thread_t *, void (*func)(void *),
void * arg, char * name );
void tr_threadJoin ( tr_thread_t * );
void tr_lockInit ( tr_lock_t * );
void tr_lockClose ( tr_lock_t * );

View file

@ -83,7 +83,7 @@ tr_handle_t * tr_init()
h->acceptDie = 0;
tr_lockInit( &h->acceptLock );
tr_threadCreate( &h->acceptThread, acceptLoop, h );
tr_threadCreate( &h->acceptThread, acceptLoop, h, "accept" );
return h;
}
@ -367,6 +367,8 @@ char * tr_torrentGetFolder( tr_torrent_t * tor )
void tr_torrentStart( tr_torrent_t * tor )
{
char name[32];
if( tor->status & ( TR_STATUS_STOPPING | TR_STATUS_STOPPED ) )
{
/* Join the thread first */
@ -384,7 +386,8 @@ void tr_torrentStart( tr_torrent_t * tor )
tor->date = tr_date();
tor->die = 0;
tr_threadCreate( &tor->thread, downloadLoop, tor );
snprintf( name, sizeof( name ), "torrent %p", tor );
tr_threadCreate( &tor->thread, downloadLoop, tor, name );
}
static void torrentStop( tr_torrent_t * tor )
@ -413,7 +416,6 @@ static void torrentReallyStop( tr_torrent_t * tor )
{
tor->die = 1;
tr_threadJoin( &tor->thread );
tr_dbg( "Thread joined" );
tr_trackerClose( tor->tracker );
tor->tracker = NULL;
@ -763,14 +765,6 @@ static void downloadLoop( void * _tor )
uint64_t date1, date2;
int ret;
tr_dbg( "Thread started" );
#ifdef SYS_BEOS
/* This is required because on BeOS, SIGINT is sent to each thread,
which kills them not nicely */
signal( SIGINT, SIG_IGN );
#endif
tr_lockLock( &tor->lock );
tr_cpReset( tor->completion );
@ -826,8 +820,6 @@ static void downloadLoop( void * _tor )
tr_ioClose( tor->io );
tor->status = TR_STATUS_STOPPED;
tr_dbg( "Thread exited" );
}
/***********************************************************************
@ -841,14 +833,6 @@ static void acceptLoop( void * _h )
uint8_t * hash;
tr_torrent_t * tor;
tr_dbg( "Accept thread started" );
#ifdef SYS_BEOS
/* This is required because on BeOS, SIGINT is sent to each thread,
which kills them not nicely */
signal( SIGINT, SIG_IGN );
#endif
tr_lockLock( &h->acceptLock );
while( !h->acceptDie )
@ -939,8 +923,6 @@ static void acceptLoop( void * _h )
}
tr_lockUnlock( &h->acceptLock );
tr_dbg( "Accept thread exited" );
}
/***********************************************************************
@ -955,7 +937,6 @@ static void acceptStop( tr_handle_t * h )
h->acceptDie = 1;
tr_threadJoin( &h->acceptThread );
tr_lockClose( &h->acceptLock );
tr_dbg( "Accept thread joined" );
for( ii = 0; ii < h->acceptPeerCount; ii++ )
{