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 );
55 if( !p_playlist ) return;
58 playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
59 vlc_mutex_init (&p_preparse->lock);
60 vlc_cond_init (&p_preparse->wait);
61 p_preparse->i_waiting = 0;
62 p_preparse->pp_waiting = NULL;
64 if( vlc_clone( &p_preparse->thread, playlist_PreparseLoop, p_preparse,
65 VLC_THREAD_PRIORITY_LOW ) )
67 msg_Err( p_playlist, "cannot spawn preparse thread" );
68 p_preparse->up = false;
71 p_preparse->up = true;
74 playlist_fetcher_t *p_fetcher = &pl_priv(p_playlist)->fetcher;
75 vlc_mutex_init (&p_fetcher->lock);
76 vlc_cond_init (&p_fetcher->wait);
77 p_fetcher->i_waiting = 0;
78 p_fetcher->pp_waiting = NULL;
79 p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, "album-art" );
81 if( vlc_clone( &p_fetcher->thread, playlist_FetcherLoop, p_fetcher,
82 VLC_THREAD_PRIORITY_LOW ) )
84 msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
85 p_fetcher->up = false;
91 if( vlc_thread_create( p_playlist, "playlist", RunControlThread,
92 VLC_THREAD_PRIORITY_LOW, false ) )
94 msg_Err( p_playlist, "cannot spawn playlist thread" );
95 vlc_object_release( p_playlist );
99 /* The object has been initialized, now attach it */
100 vlc_object_attach( p_playlist, p_parent );
106 * Run the main control thread itself
108 static void* RunControlThread ( vlc_object_t *p_this )
110 playlist_t *p_playlist = (playlist_t*)p_this;
112 int canc = vlc_savecancel ();
113 vlc_object_lock( p_playlist );
114 while( vlc_object_alive( p_playlist ) )
116 playlist_MainLoop( p_playlist );
118 /* The playlist lock has been unlocked, so we can't tell if
119 * someone has killed us in the meantime. Check now. */
120 if( !vlc_object_alive( p_playlist ) )
123 if( pl_priv(p_playlist)->b_cant_sleep )
125 /* 100 ms is an acceptable delay for playlist operations */
126 vlc_object_unlock( p_playlist );
128 msleep( INTF_IDLE_SLEEP*2 );
130 vlc_object_lock( p_playlist );
134 vlc_object_wait( p_playlist );
137 vlc_object_unlock( p_playlist );
139 playlist_LastLoop( p_playlist );
140 vlc_restorecancel (canc);