Convert the global thread list to a standard list.
diff --git a/server/thread.c b/server/thread.c
index 816f3bf..de23684 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -103,7 +103,7 @@
no_cancel_async /* cancel_async */
};
-static struct thread *first_thread;
+static struct list thread_list = LIST_INIT(thread_list);
static struct thread *booting_thread;
/* initialize the structure for a newly allocated thread */
@@ -130,8 +130,6 @@
thread->state = RUNNING;
thread->attached = 0;
thread->exit_code = 0;
- thread->next = NULL;
- thread->prev = NULL;
thread->priority = THREAD_PRIORITY_NORMAL;
thread->affinity = 1;
thread->suspend = 0;
@@ -164,8 +162,7 @@
lock_master_socket(1);
}
- if ((thread->next = first_thread) != NULL) thread->next->prev = thread;
- first_thread = thread;
+ list_add_head( &thread_list, &thread->entry );
if (!(thread->id = alloc_ptid( thread )))
{
@@ -241,9 +238,7 @@
assert( obj->ops == &thread_ops );
assert( !thread->debug_ctx ); /* cannot still be debugging something */
- if (thread->next) thread->next->prev = thread->prev;
- if (thread->prev) thread->prev->next = thread->next;
- else first_thread = thread->next;
+ list_remove( &thread->entry );
while ((apc = thread_dequeue_apc( thread, 0 ))) free( apc );
cleanup_thread( thread );
release_object( thread->process );
@@ -287,10 +282,16 @@
/* find a thread from a Unix pid */
struct thread *get_thread_from_pid( int pid )
{
- struct thread *t;
+ struct thread *thread;
- for (t = first_thread; t; t = t->next) if (t->unix_tid == pid) return t;
- for (t = first_thread; t; t = t->next) if (t->unix_pid == pid) return t;
+ LIST_FOR_EACH_ENTRY( thread, &thread_list, struct thread, entry )
+ {
+ if (thread->unix_tid == pid) return thread;
+ }
+ LIST_FOR_EACH_ENTRY( thread, &thread_list, struct thread, entry )
+ {
+ if (thread->unix_pid == pid) return thread;
+ }
return NULL;
}
@@ -754,11 +755,11 @@
struct thread *thread;
int total = 0;
- for (thread = first_thread; thread; thread = thread->next)
+ LIST_FOR_EACH_ENTRY( thread, &thread_list, struct thread, entry )
if (thread->state != TERMINATED) total++;
if (!total || !(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL;
ptr = snapshot;
- for (thread = first_thread; thread; thread = thread->next)
+ LIST_FOR_EACH_ENTRY( thread, &thread_list, struct thread, entry )
{
if (thread->state == TERMINATED) continue;
ptr->thread = thread;
diff --git a/server/thread.h b/server/thread.h
index 924c471..a7c544b 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -50,8 +50,7 @@
struct thread
{
struct object obj; /* object header */
- struct thread *next; /* system-wide thread list */
- struct thread *prev;
+ struct list entry; /* entry in system-wide thread list */
struct thread *proc_next; /* per-process thread list */
struct thread *proc_prev;
struct process *process;