1 /*****************************************************************************
2 * thread.c : Playlist management functions
3 *****************************************************************************
4 * Copyright © 1999-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include <vlc_common.h>
30 #include <vlc_input.h>
31 #include <vlc_interface.h>
32 #include <vlc_playlist.h>
33 #include "playlist_internal.h"
35 /*****************************************************************************
37 *****************************************************************************/
38 static void* RunControlThread ( vlc_object_t * );
40 /*****************************************************************************
41 * Main functions for the global thread
42 *****************************************************************************/
45 * Create the main playlist thread
46 * Additionally to the playlist, this thread controls :
50 * \return an object with a started thread
52 void __playlist_ThreadCreate( vlc_object_t *p_parent )
54 playlist_t *p_playlist = playlist_Create( p_parent );
59 playlist_private_t *p_sys = pl_priv(p_playlist);
62 p_sys->p_fetcher = playlist_fetcher_New( p_playlist );
63 if( !p_sys->p_fetcher )
64 msg_Err( p_playlist, "cannot create playlist fetcher" );
67 p_sys->p_preparser = playlist_preparser_New( p_playlist, p_sys->p_fetcher );
68 if( !p_sys->p_preparser )
69 msg_Err( p_playlist, "cannot create playlist preparser" );
71 /* Start the playlist thread */
72 if( vlc_thread_create( p_playlist, "playlist", RunControlThread,
73 VLC_THREAD_PRIORITY_LOW, false ) )
75 msg_Err( p_playlist, "cannot spawn playlist thread" );
76 vlc_object_release( p_playlist );
80 /* The object has been initialized, now attach it */
81 vlc_object_attach( p_playlist, p_parent );
85 * Run the main control thread itself
87 static void* RunControlThread ( vlc_object_t *p_this )
89 playlist_t *p_playlist = (playlist_t*)p_this;
91 int canc = vlc_savecancel ();
92 vlc_object_lock( p_playlist );
93 while( vlc_object_alive( p_playlist ) )
95 playlist_MainLoop( p_playlist );
97 /* The playlist lock has been unlocked, so we can't tell if
98 * someone has killed us in the meantime. Check now. */
99 if( !vlc_object_alive( p_playlist ) )
102 if( pl_priv(p_playlist)->b_cant_sleep )
104 /* 100 ms is an acceptable delay for playlist operations */
105 vlc_object_unlock( p_playlist );
107 msleep( INTF_IDLE_SLEEP*2 );
109 vlc_object_lock( p_playlist );
113 vlc_object_wait( p_playlist );
116 vlc_object_unlock( p_playlist );
118 playlist_LastLoop( p_playlist );
119 vlc_restorecancel (canc);