Changeset 7a4d005e335d72525c197cfc552fd74273f36a49

Show
Ignore:
Timestamp:
05/07/08 01:46:14 (3 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1215215174 +0200
git-parent:

[19d9683044017341da6a5335aea1007cf05bf230]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1215215120 +0200
Message:

macosx: Merge the KillerThread? and the manage thread. Make sure we properly exit the manage_thread. Don't only msleep() but use timedwait() to make sure we don't have to wait more than needed when destroying the thread.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/macosx/intf.h

    r6b7540a r7a4d005  
    9393    /* The messages window */ 
    9494    msg_subscription_t * p_sub; 
    95  
    9695}; 
    9796 
     
    306305    int     i_lastShownVolume; 
    307306 
     307    /* the manage thread */ 
     308    pthread_t manage_thread; 
     309 
    308310    AppleRemote * o_remote; 
    309311    BOOL b_remote_button_hold; /* true as long as the user holds the left,right,plus or minus on the remote control */ 
  • modules/gui/macosx/intf.m

    r19d9683 r7a4d005  
    133133 
    134134/***************************************************************************** 
    135  * KillerThread: Thread that kill the application 
    136  *****************************************************************************/ 
    137 static void * KillerThread( void *user_data ) 
    138 { 
    139     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; 
    140  
    141     intf_thread_t *p_intf = user_data; 
    142      
    143     vlc_object_lock ( p_intf ); 
    144     while( vlc_object_alive( p_intf ) ) 
    145         vlc_object_wait( p_intf ); 
    146     vlc_object_unlock( p_intf ); 
    147  
    148     msg_Dbg( p_intf, "Killing the Mac OS X module" ); 
    149  
    150     /* We are dead, terminate */ 
    151     [NSApp terminate: nil]; 
    152     [o_pool release]; 
    153     return NULL; 
    154 } 
    155  
    156 /***************************************************************************** 
    157135 * Run: main loop 
    158136 *****************************************************************************/ 
     
    187165    [NSBundle loadNibNamed: @"MainMenu" owner: NSApp]; 
    188166 
    189     /* Setup a thread that will monitor the module killing */ 
    190     pthread_t killer_thread; 
    191     pthread_create( &killer_thread, NULL, KillerThread, p_intf ); 
    192  
    193167    /* Install a jmpbuffer to where we can go back before the NSApp exit 
    194168     * see applicationWillTerminate: */ 
     
    196170        [NSApp run]; 
    197171 
    198     pthread_join( killer_thread, NULL ); 
    199  
    200172    [o_pool release]; 
     173} 
     174 
     175/***************************************************************************** 
     176 * ManageThread: An ugly thread that polls 
     177 *****************************************************************************/ 
     178static void * ManageThread( void *user_data ) 
     179{ 
     180    id self = user_data; 
     181 
     182    [self manage]; 
     183 
     184    return NULL; 
    201185} 
    202186 
     
    799783                                   userInfo: nil repeats: FALSE]; 
    800784 
    801     /* FIXME: don't poll */ 
    802     [NSThread detachNewThreadSelector: @selector(manage) 
    803                              toTarget: self withObject: nil]; 
     785    /* Note: we use the pthread API to support pre-10.5 */ 
     786    pthread_create( &manage_thread, NULL, ManageThread, self ); 
    804787 
    805788    [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf 
     
    12681251 
    12691252        vlc_mutex_unlock( &p_intf->change_lock ); 
    1270         vlc_object_unlock( p_intf ); 
    1271         msleep( 100000 ); 
    1272         vlc_object_lock( p_intf ); 
     1253 
     1254        vlc_object_timedwait( p_intf, 100000 + mdate()); 
    12731255    } 
    12741256    vlc_object_unlock( p_intf ); 
    12751257    [o_pool release]; 
     1258 
     1259    pthread_testcancel(); /* If we were cancelled stop here */ 
     1260 
     1261    msg_Info( p_intf, "Killing the Mac OS X module" ); 
     1262 
     1263    /* We are dead, terminate */ 
     1264    [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO]; 
    12761265} 
    12771266 
     
    12811270    playlist_t * p_playlist; 
    12821271    input_thread_t * p_input; 
    1283  
    1284     vlc_object_lock( p_intf ); 
    1285  
    1286     if( !vlc_object_alive( p_intf ) ) 
    1287     { 
    1288         vlc_object_unlock( p_intf ); 
    1289         [o_timer invalidate]; 
    1290         return; 
    1291     } 
    12921272 
    12931273    if( p_intf->p_sys->b_input_update ) 
     
    14671447        target: self selector: @selector(manageIntf:) 
    14681448        userInfo: nil repeats: FALSE]; 
    1469     vlc_object_unlock( p_intf ); 
    14701449} 
    14711450 
     
    17781757    msg_Dbg( p_intf, "Terminating" ); 
    17791758 
     1759    /* Make sure the manage_thread won't call -terminate: again */ 
     1760    pthread_cancel( manage_thread ); 
     1761 
     1762    /* Make sure the intf object is getting killed */ 
     1763    vlc_object_kill( p_intf ); 
     1764 
     1765    /* Make sure our manage_thread ends */ 
     1766    pthread_join( manage_thread, NULL ); 
     1767 
    17801768    /* make sure that the current volume is saved */ 
    17811769    config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );