+
+ FREENULL( p_this->psz_object_name );
+
+#if defined(WIN32) || defined(UNDER_CE)
+ /* if object has an associated thread, close it now */
+ if( p_priv->thread_id )
+ CloseHandle(p_priv->thread_id);
+#endif
+
+ vlc_spin_destroy( &p_priv->ref_spin );
+ vlc_mutex_destroy( &p_this->object_lock );
+ vlc_cond_destroy( &p_this->object_wait );
+ vlc_spin_destroy( &p_priv->spin );
+ if( p_priv->pipes[1] != -1 )
+ close( p_priv->pipes[1] );
+ if( p_priv->pipes[0] != -1 )
+ close( p_priv->pipes[0] );
+
+ free( p_priv );
+}
+
+
+/** Inter-object signaling */
+
+void __vlc_object_lock( vlc_object_t *obj )
+{
+ vlc_mutex_lock( &obj->object_lock );
+}
+
+void __vlc_object_unlock( vlc_object_t *obj )
+{
+ vlc_assert_locked( &obj->object_lock );
+ vlc_mutex_unlock( &obj->object_lock );
+}
+
+#ifdef WIN32
+# include <winsock2.h>
+# include <ws2tcpip.h>
+
+/**
+ * select()-able pipes emulated using Winsock
+ */
+static int pipe (int fd[2])
+{
+ SOCKADDR_IN addr;
+ int addrlen = sizeof (addr);
+
+ SOCKET l = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP), a,
+ c = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if ((l == INVALID_SOCKET) || (c == INVALID_SOCKET))
+ goto error;
+
+ memset (&addr, 0, sizeof (addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+ if (bind (l, (PSOCKADDR)&addr, sizeof (addr))
+ || getsockname (l, (PSOCKADDR)&addr, &addrlen)
+ || listen (l, 1)
+ || connect (c, (PSOCKADDR)&addr, addrlen))
+ goto error;
+
+ a = accept (l, NULL, NULL);
+ if (a == INVALID_SOCKET)
+ goto error;
+
+ closesocket (l);
+ //shutdown (a, 0);
+ //shutdown (c, 1);
+ fd[0] = c;
+ fd[1] = a;
+ return 0;
+
+error:
+ if (l != INVALID_SOCKET)
+ closesocket (l);
+ if (c != INVALID_SOCKET)
+ closesocket (c);
+ return -1;
+}
+
+#undef read
+#define read( a, b, c ) recv (a, b, c, 0)
+#undef write
+#define write( a, b, c ) send (a, b, c, 0)
+#undef close
+#define close( a ) closesocket (a)
+#endif /* WIN32 */
+
+/**
+ * Returns the readable end of a pipe that becomes readable once termination
+ * of the object is requested (vlc_object_kill()).
+ * This can be used to wake-up out of a select() or poll() event loop, such
+ * typically when doing network I/O.
+ *
+ * Note that the pipe will remain the same for the lifetime of the object.
+ * DO NOT read the pipe nor close it yourself. Ever.
+ *
+ * @param obj object that would be "killed"
+ * @return a readable pipe descriptor, or -1 on error.
+ */
+int __vlc_object_waitpipe( vlc_object_t *obj )
+{
+ int pfd[2] = { -1, -1 };
+ vlc_object_internals_t *internals = vlc_internals( obj );
+ bool killed = false;
+
+ vlc_spin_lock (&internals->spin);
+ if (internals->pipes[0] == -1)