1 /*****************************************************************************
2 * exit.c: LibVLC termination event
3 *****************************************************************************
4 * Copyright (C) 2009-2010 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_interface.h>
28 #include "../lib/libvlc_internal.h"
30 void vlc_ExitInit( vlc_exit_t
*exit
)
32 vlc_mutex_init( &exit
->lock
);
38 void vlc_ExitDestroy( vlc_exit_t
*exit
)
40 vlc_mutex_destroy( &exit
->lock
);
45 * Registers a callback for the LibVLC exit event.
47 * @note This function conflicts with libvlc_InternalWait().
48 * Use either or none of them, but not both.
50 void libvlc_SetExitHandler( libvlc_int_t
*p_libvlc
, void (*handler
) (void *),
53 vlc_exit_t
*exit
= &libvlc_priv( p_libvlc
)->exit
;
55 vlc_mutex_lock( &exit
->lock
);
56 if( exit
->killed
) /* already exited! (race condition) */
58 exit
->handler
= handler
;
59 exit
->opaque
= opaque
;
60 vlc_mutex_unlock( &exit
->lock
);
64 * Posts an exit signal to LibVLC instance. This only emits a notification to
65 * the main thread. It might take a while before the actual cleanup occurs.
66 * This function should only be called on behalf of the user.
68 void libvlc_Quit( libvlc_int_t
*p_libvlc
)
70 vlc_exit_t
*exit
= &libvlc_priv( p_libvlc
)->exit
;
72 vlc_mutex_lock( &exit
->lock
);
75 msg_Dbg( p_libvlc
, "exiting" );
77 if( exit
->handler
!= NULL
)
78 exit
->handler( exit
->opaque
);
80 vlc_mutex_unlock( &exit
->lock
);
84 static void exit_wakeup( void *data
)
86 vlc_cond_signal( data
);
90 * Waits until the LibVLC instance gets an exit signal.
91 * This normally occurs when the user "exits" an interface plugin. But it can
92 * also be triggered by the special vlc://quit item, the update checker, or
93 * the playlist engine.
95 void libvlc_InternalWait( libvlc_int_t
*p_libvlc
)
97 vlc_exit_t
*exit
= &libvlc_priv( p_libvlc
)->exit
;
100 vlc_cond_init( &wait
);
102 vlc_mutex_lock( &exit
->lock
);
103 exit
->handler
= exit_wakeup
;
104 exit
->opaque
= &wait
;
105 while( !exit
->killed
)
106 vlc_cond_wait( &wait
, &exit
->lock
);
107 vlc_mutex_unlock( &exit
->lock
);
109 vlc_cond_destroy( &wait
);