Changeset 7a4d005e335d72525c197cfc552fd74273f36a49
- 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
| r6b7540a |
r7a4d005 |
|
| 93 | 93 | /* The messages window */ |
|---|
| 94 | 94 | msg_subscription_t * p_sub; |
|---|
| 95 | | |
|---|
| 96 | 95 | }; |
|---|
| 97 | 96 | |
|---|
| … | … | |
| 306 | 305 | int i_lastShownVolume; |
|---|
| 307 | 306 | |
|---|
| | 307 | /* the manage thread */ |
|---|
| | 308 | pthread_t manage_thread; |
|---|
| | 309 | |
|---|
| 308 | 310 | AppleRemote * o_remote; |
|---|
| 309 | 311 | BOOL b_remote_button_hold; /* true as long as the user holds the left,right,plus or minus on the remote control */ |
|---|
| r19d9683 |
r7a4d005 |
|
| 133 | 133 | |
|---|
| 134 | 134 | /***************************************************************************** |
|---|
| 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 | | /***************************************************************************** |
|---|
| 157 | 135 | * Run: main loop |
|---|
| 158 | 136 | *****************************************************************************/ |
|---|
| … | … | |
| 187 | 165 | [NSBundle loadNibNamed: @"MainMenu" owner: NSApp]; |
|---|
| 188 | 166 | |
|---|
| 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 | | |
|---|
| 193 | 167 | /* Install a jmpbuffer to where we can go back before the NSApp exit |
|---|
| 194 | 168 | * see applicationWillTerminate: */ |
|---|
| … | … | |
| 196 | 170 | [NSApp run]; |
|---|
| 197 | 171 | |
|---|
| 198 | | pthread_join( killer_thread, NULL ); |
|---|
| 199 | | |
|---|
| 200 | 172 | [o_pool release]; |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | /***************************************************************************** |
|---|
| | 176 | * ManageThread: An ugly thread that polls |
|---|
| | 177 | *****************************************************************************/ |
|---|
| | 178 | static void * ManageThread( void *user_data ) |
|---|
| | 179 | { |
|---|
| | 180 | id self = user_data; |
|---|
| | 181 | |
|---|
| | 182 | [self manage]; |
|---|
| | 183 | |
|---|
| | 184 | return NULL; |
|---|
| 201 | 185 | } |
|---|
| 202 | 186 | |
|---|
| … | … | |
| 799 | 783 | userInfo: nil repeats: FALSE]; |
|---|
| 800 | 784 | |
|---|
| 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 ); |
|---|
| 804 | 787 | |
|---|
| 805 | 788 | [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf |
|---|
| … | … | |
| 1268 | 1251 | |
|---|
| 1269 | 1252 | 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()); |
|---|
| 1273 | 1255 | } |
|---|
| 1274 | 1256 | vlc_object_unlock( p_intf ); |
|---|
| 1275 | 1257 | [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]; |
|---|
| 1276 | 1265 | } |
|---|
| 1277 | 1266 | |
|---|
| … | … | |
| 1281 | 1270 | playlist_t * p_playlist; |
|---|
| 1282 | 1271 | 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 | | } |
|---|
| 1292 | 1272 | |
|---|
| 1293 | 1273 | if( p_intf->p_sys->b_input_update ) |
|---|
| … | … | |
| 1467 | 1447 | target: self selector: @selector(manageIntf:) |
|---|
| 1468 | 1448 | userInfo: nil repeats: FALSE]; |
|---|
| 1469 | | vlc_object_unlock( p_intf ); |
|---|
| 1470 | 1449 | } |
|---|
| 1471 | 1450 | |
|---|
| … | … | |
| 1778 | 1757 | msg_Dbg( p_intf, "Terminating" ); |
|---|
| 1779 | 1758 | |
|---|
| | 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 | |
|---|
| 1780 | 1768 | /* make sure that the current volume is saved */ |
|---|
| 1781 | 1769 | config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume ); |
|---|