1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

(trunk libT) resolve thread condition in libtransmission by moving the `waiting' state variable to the stack in tr_sessionSet() and tr_sessionInit()

This commit is contained in:
Charles Kerr 2010-01-01 22:35:49 +00:00
parent 283b6d6a36
commit 696aa7aba6
2 changed files with 7 additions and 7 deletions

View file

@ -499,6 +499,7 @@ struct init_data
{
tr_session * session;
const char * configDir;
tr_bool done;
tr_bool messageQueuingEnabled;
tr_benc * clientSettings;
};
@ -535,13 +536,13 @@ tr_sessionInit( const char * tag,
assert( session->events != NULL );
/* run the rest in the libtransmission thread */
++session->waiting;
data.done = FALSE;
data.session = session;
data.configDir = configDir;
data.messageQueuingEnabled = messageQueuingEnabled;
data.clientSettings = clientSettings;
tr_runInEventThread( session, tr_sessionInitImpl, &data );
while( session->waiting > 0 )
while( !data.done )
tr_wait_msec( 100 );
return session;
@ -639,7 +640,6 @@ tr_sessionInitImpl( void * vdata )
tr_statsInit( session );
session->web = tr_webInit( session );
--session->waiting;
tr_sessionSet( session, &settings );
@ -650,6 +650,7 @@ tr_sessionInitImpl( void * vdata )
/* cleanup */
tr_bencFree( &settings );
data->done = TRUE;
}
static void
@ -805,20 +806,20 @@ sessionSetImpl( void * vdata )
else if( tr_bencDictFindBool( settings, TR_PREFS_KEY_ALT_SPEED_ENABLED, &boolVal ) )
useAltSpeed( session, boolVal, FALSE );
--session->waiting;
data->done = TRUE;
}
void
tr_sessionSet( tr_session * session, struct tr_benc * settings )
{
struct init_data data;
data.done = FALSE;
data.session = session;
data.clientSettings = settings;
/* run the rest in the libtransmission thread */
++session->waiting;
tr_runInEventThread( session, sessionSetImpl, &data );
while( session->waiting > 0 )
while( !data.done )
tr_wait_msec( 100 );
}

View file

@ -57,7 +57,6 @@ struct tr_session
tr_benc removedTorrents;
int waiting;
int umask;
int speedLimit[2];