Moved idle event handling to the server.

diff --git a/server/thread.c b/server/thread.c
index f98982d..1899132 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -34,14 +34,6 @@
 
 /* thread queues */
 
-struct wait_queue_entry
-{
-    struct wait_queue_entry *next;
-    struct wait_queue_entry *prev;
-    struct object           *obj;
-    struct thread           *thread;
-};
-
 struct thread_wait
 {
     int                     count;      /* count of objects */
@@ -131,6 +123,7 @@
     thread->mutex       = NULL;
     thread->debug_ctx   = NULL;
     thread->debug_event = NULL;
+    thread->queue       = NULL;
     thread->info        = NULL;
     thread->wait        = NULL;
     thread->apc         = NULL;
@@ -196,6 +189,7 @@
     else first_thread = thread->next;
     if (thread->apc) free( thread->apc );
     if (thread->info) release_object( thread->info );
+    if (thread->queue) release_object( thread->queue );
     if (thread->buffer != (void *)-1) munmap( thread->buffer, MAX_REQUEST_LENGTH );
     if (thread->pass_fd != -1) close( thread->pass_fd );
 }