+ vlc_assert_locked( &obj->object_lock );
+ vlc_cond_wait( &obj->object_wait, &obj->object_lock );
+ return obj->b_die;
+}
+
+
+/**
+ * Waits for the object to be signaled (using vlc_object_signal()), or for
+ * a timer to expire.
+ * If the object already has a signal pending, this function will return
+ * immediately. It is asserted that the caller holds the object lock.
+ *
+ * @return negative if the object is dying and should terminate,
+ * positive if the the object has been signaled but is not dying,
+ * 0 if timeout has been reached.
+ */
+int __vlc_object_timedwait( vlc_object_t *obj, mtime_t deadline )
+{
+ int v;
+
+ vlc_assert_locked( &obj->object_lock );
+ v = vlc_cond_timedwait( &obj->object_wait, &obj->object_lock, deadline );
+ if( v == 0 ) /* signaled */
+ return obj->b_die ? -1 : 1;
+ return 0;
+}
+
+
+/**
+ * Checks whether an object has been "killed".
+ * The object lock must be held.
+ *
+ * Typical code for an object thread could be:
+ *
+ vlc_object_lock (self);
+ ...initialization...
+ while (vlc_object_alive (self))
+ {
+ ...preprocessing...
+
+ if (vlc_object_wait (self))
+ continue;
+
+ ...postprocessing...
+ }
+ ...deinitialization...
+ vlc_object_unlock (self);
+ *
+ *
+ * @return true iff the object has not been killed yet
+ */
+vlc_bool_t __vlc_object_alive( vlc_object_t *obj )
+{
+ vlc_assert_locked( &obj->object_lock );
+ return !obj->b_die;
+}
+
+
+/**
+ * Signals an object for which the lock is held.
+ */
+void __vlc_object_signal_unlocked( vlc_object_t *obj )
+{
+ vlc_assert_locked (&obj->object_lock);
+ vlc_cond_signal( &obj->object_wait );
+}
+
+
+/**
+ * Requests termination of an object.
+ * If the object is LibVLC, also request to terminate all its children.
+ */
+void __vlc_object_kill( vlc_object_t *p_this )
+{
+ struct vlc_object_internals_t *internals = p_this->p_internals;
+ int fd;
+
+ vlc_mutex_lock( &p_this->object_lock );
+ p_this->b_die = VLC_TRUE;
+
+ vlc_spin_lock (&internals->spin);
+ fd = internals->pipes[1];
+ internals->pipes[1] = -1;
+ vlc_spin_unlock (&internals->spin);
+
+ if( fd != -1 )
+ {
+ msg_Dbg (p_this, "waitpipe: object killed");
+ close (fd);
+ }
+
+ if( p_this->i_object_type == VLC_OBJECT_LIBVLC )
+ for( int i = 0; i < p_this->i_children ; i++ )
+ vlc_object_kill( p_this->pp_children[i] );
+
+ vlc_object_signal_unlocked( p_this );
+ vlc_mutex_unlock( &p_this->object_lock );