Convert the global thread list to a standard list.

This commit is contained in:
Alexandre Julliard 2005-02-25 19:33:35 +00:00
parent 48c0d51dc3
commit 73209eb73e
2 changed files with 15 additions and 15 deletions

View File

@ -103,7 +103,7 @@ static const struct fd_ops thread_fd_ops =
no_cancel_async /* cancel_async */ no_cancel_async /* cancel_async */
}; };
static struct thread *first_thread; static struct list thread_list = LIST_INIT(thread_list);
static struct thread *booting_thread; static struct thread *booting_thread;
/* initialize the structure for a newly allocated thread */ /* initialize the structure for a newly allocated thread */
@ -130,8 +130,6 @@ inline static void init_thread_structure( struct thread *thread )
thread->state = RUNNING; thread->state = RUNNING;
thread->attached = 0; thread->attached = 0;
thread->exit_code = 0; thread->exit_code = 0;
thread->next = NULL;
thread->prev = NULL;
thread->priority = THREAD_PRIORITY_NORMAL; thread->priority = THREAD_PRIORITY_NORMAL;
thread->affinity = 1; thread->affinity = 1;
thread->suspend = 0; thread->suspend = 0;
@ -164,8 +162,7 @@ struct thread *create_thread( int fd, struct process *process )
lock_master_socket(1); lock_master_socket(1);
} }
if ((thread->next = first_thread) != NULL) thread->next->prev = thread; list_add_head( &thread_list, &thread->entry );
first_thread = thread;
if (!(thread->id = alloc_ptid( thread ))) if (!(thread->id = alloc_ptid( thread )))
{ {
@ -241,9 +238,7 @@ static void destroy_thread( struct object *obj )
assert( obj->ops == &thread_ops ); assert( obj->ops == &thread_ops );
assert( !thread->debug_ctx ); /* cannot still be debugging something */ assert( !thread->debug_ctx ); /* cannot still be debugging something */
if (thread->next) thread->next->prev = thread->prev; list_remove( &thread->entry );
if (thread->prev) thread->prev->next = thread->next;
else first_thread = thread->next;
while ((apc = thread_dequeue_apc( thread, 0 ))) free( apc ); while ((apc = thread_dequeue_apc( thread, 0 ))) free( apc );
cleanup_thread( thread ); cleanup_thread( thread );
release_object( thread->process ); release_object( thread->process );
@ -287,10 +282,16 @@ struct thread *get_thread_from_handle( obj_handle_t handle, unsigned int access
/* find a thread from a Unix pid */ /* find a thread from a Unix pid */
struct thread *get_thread_from_pid( int 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; LIST_FOR_EACH_ENTRY( thread, &thread_list, struct thread, entry )
for (t = first_thread; t; t = t->next) if (t->unix_pid == pid) return t; {
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; return NULL;
} }
@ -754,11 +755,11 @@ struct thread_snapshot *thread_snap( int *count )
struct thread *thread; struct thread *thread;
int total = 0; 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 (thread->state != TERMINATED) total++;
if (!total || !(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL; if (!total || !(snapshot = mem_alloc( sizeof(*snapshot) * total ))) return NULL;
ptr = snapshot; 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; if (thread->state == TERMINATED) continue;
ptr->thread = thread; ptr->thread = thread;

View File

@ -50,8 +50,7 @@ struct inflight_fd
struct thread struct thread
{ {
struct object obj; /* object header */ struct object obj; /* object header */
struct thread *next; /* system-wide thread list */ struct list entry; /* entry in system-wide thread list */
struct thread *prev;
struct thread *proc_next; /* per-process thread list */ struct thread *proc_next; /* per-process thread list */
struct thread *proc_prev; struct thread *proc_prev;
struct process *process; struct process *process;