+/**
+ * Returns the readable end of a pipe that becomes readable whenever
+ * an object is signaled. This can be used to wait for VLC object events
+ * inside select(), poll() loops or frameworks providing an event loop.
+ *
+ * Note that the pipe will remain the same for the lifetime of the object.
+ * DO NOT close it yourself. Ever.
+ *
+ * DO NOT try to read from the pipe either: call vlc_object_wait() instead.
+ * Assuming the pipe is readable, vlc_object_wait() will not block.
+ * Also note that, as with vlc_object_wait(), there may be spurious wakeups.
+ *
+ * @param obj object that would be signaled (object lock MUST hold)
+ * @return a readable pipe descriptor, or -1 on error.
+ */
+int vlc_object_waitpipe( vlc_object_t *obj )
+{
+ int *pipes = obj->p_internals->pipes;
+ vlc_assert_locked( &obj->object_lock );
+
+ if( pipes[1] == -1 )
+ {
+ /* This can only ever happen if someone killed us without locking */
+ assert( pipes[0] == -1 );
+
+#ifndef WIN32
+ if( pipe( pipes ) )
+#else
+ if( _pipe( pipes, 1, _O_BINARY ) )
+#endif
+ return -1;
+ }
+
+ return pipes[0];
+}
+
+