Convert the global process list to a standard list.

This commit is contained in:
Alexandre Julliard 2005-02-25 19:31:26 +00:00
parent 3b78212f1d
commit 48c0d51dc3
2 changed files with 33 additions and 30 deletions

View File

@ -48,7 +48,7 @@
/* process structure */ /* process structure */
static struct process *first_process; static struct list process_list = LIST_INIT(process_list);
static int running_processes; static int running_processes;
/* process operations */ /* process operations */
@ -249,8 +249,6 @@ struct thread *create_process( int fd )
int request_pipe[2]; int request_pipe[2];
if (!(process = alloc_object( &process_ops ))) goto error; if (!(process = alloc_object( &process_ops ))) goto error;
process->next = NULL;
process->prev = NULL;
process->parent = NULL; process->parent = NULL;
process->thread_list = NULL; process->thread_list = NULL;
process->debugger = NULL; process->debugger = NULL;
@ -283,8 +281,7 @@ struct thread *create_process( int fd )
list_init( &process->classes ); list_init( &process->classes );
gettimeofday( &process->start_time, NULL ); gettimeofday( &process->start_time, NULL );
if ((process->next = first_process) != NULL) process->next->prev = process; list_add_head( &process_list, &process->entry );
first_process = process;
if (!(process->id = alloc_ptid( process ))) goto error; if (!(process->id = alloc_ptid( process ))) goto error;
if (!(process->msg_fd = create_anonymous_fd( &process_fd_ops, fd, &process->obj ))) goto error; if (!(process->msg_fd = create_anonymous_fd( &process_fd_ops, fd, &process->obj ))) goto error;
@ -409,9 +406,7 @@ static void process_destroy( struct object *obj )
if (process->console) release_object( process->console ); if (process->console) release_object( process->console );
if (process->parent) release_object( process->parent ); if (process->parent) release_object( process->parent );
if (process->msg_fd) release_object( process->msg_fd ); if (process->msg_fd) release_object( process->msg_fd );
if (process->next) process->next->prev = process->prev; list_remove( &process->entry );
if (process->prev) process->prev->next = process->next;
else first_process = process->next;
if (process->idle_event) release_object( process->idle_event ); if (process->idle_event) release_object( process->idle_event );
if (process->queue) release_object( process->queue ); if (process->queue) release_object( process->queue );
if (process->atom_table) release_object( process->atom_table ); if (process->atom_table) release_object( process->atom_table );
@ -427,8 +422,7 @@ static void process_dump( struct object *obj, int verbose )
struct process *process = (struct process *)obj; struct process *process = (struct process *)obj;
assert( obj->ops == &process_ops ); assert( obj->ops == &process_ops );
fprintf( stderr, "Process id=%04x next=%p prev=%p handles=%p\n", fprintf( stderr, "Process id=%04x handles=%p\n", process->id, process->handles );
process->id, process->next, process->prev, process->handles );
} }
static int process_signaled( struct object *obj, struct thread *thread ) static int process_signaled( struct object *obj, struct thread *thread )
@ -548,11 +542,14 @@ void kill_all_processes( struct process *skip, int exit_code )
{ {
for (;;) for (;;)
{ {
struct process *process = first_process; struct process *process;
while (process && (!process->running_threads || process == skip)) LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
process = process->next; {
if (!process) break; if (process == skip) continue;
if (process->running_threads) break;
}
if (&process->entry == &process_list) break; /* no process found */
kill_process( process, NULL, exit_code ); kill_process( process, NULL, exit_code );
} }
} }
@ -562,16 +559,16 @@ void kill_console_processes( struct thread *renderer, int exit_code )
{ {
for (;;) /* restart from the beginning of the list every time */ for (;;) /* restart from the beginning of the list every time */
{ {
struct process *process = first_process; struct process *process;
/* find the first process being attached to 'renderer' and still running */ /* find the first process being attached to 'renderer' and still running */
while (process && LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
(process == renderer->process || !process->console ||
process->console->renderer != renderer || !process->running_threads))
{ {
process = process->next; if (process == renderer->process) continue;
if (!process->running_threads) continue;
if (process->console && process->console->renderer == renderer) break;
} }
if (!process) break; if (&process->entry == &process_list) break; /* no process found */
kill_process( process, NULL, exit_code ); kill_process( process, NULL, exit_code );
} }
} }
@ -685,11 +682,15 @@ void kill_debugged_processes( struct thread *debugger, int exit_code )
{ {
for (;;) /* restart from the beginning of the list every time */ for (;;) /* restart from the beginning of the list every time */
{ {
struct process *process = first_process; struct process *process;
/* find the first process being debugged by 'debugger' and still running */ /* find the first process being debugged by 'debugger' and still running */
while (process && (process->debugger != debugger || !process->running_threads)) LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
process = process->next; {
if (!process) return; if (!process->running_threads) continue;
if (process->debugger == debugger) break;
}
if (&process->entry == &process_list) break; /* no process found */
process->debugger = NULL; process->debugger = NULL;
kill_process( process, NULL, exit_code ); kill_process( process, NULL, exit_code );
} }
@ -700,7 +701,8 @@ void kill_debugged_processes( struct thread *debugger, int exit_code )
void detach_debugged_processes( struct thread *debugger ) void detach_debugged_processes( struct thread *debugger )
{ {
struct process *process; struct process *process;
for (process = first_process; process; process = process->next)
LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
{ {
if (process->debugger == debugger && process->running_threads) if (process->debugger == debugger && process->running_threads)
{ {
@ -712,9 +714,11 @@ void detach_debugged_processes( struct thread *debugger )
void enum_processes( int (*cb)(struct process*, void*), void *user ) void enum_processes( int (*cb)(struct process*, void*), void *user )
{ {
struct process *process; struct list *ptr, *next;
for (process = first_process; process; process = process->next)
LIST_FOR_EACH_SAFE( ptr, next, &process_list )
{ {
struct process *process = LIST_ENTRY( ptr, struct process, entry );
if ((cb)(process, user)) break; if ((cb)(process, user)) break;
} }
} }
@ -828,7 +832,7 @@ struct process_snapshot *process_snap( int *count )
if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes ))) if (!(snapshot = mem_alloc( sizeof(*snapshot) * running_processes )))
return NULL; return NULL;
ptr = snapshot; ptr = snapshot;
for (process = first_process; process; process = process->next) LIST_FOR_EACH_ENTRY( process, &process_list, struct process, entry )
{ {
if (!process->running_threads) continue; if (!process->running_threads) continue;
ptr->process = process; ptr->process = process;

View File

@ -50,8 +50,7 @@ struct process_dll
struct process struct process
{ {
struct object obj; /* object header */ struct object obj; /* object header */
struct process *next; /* system-wide process list */ struct list entry; /* entry in system-wide process list */
struct process *prev;
struct process *parent; /* parent process */ struct process *parent; /* parent process */
struct thread *thread_list; /* head of the thread list */ struct thread *thread_list; /* head of the thread list */
struct thread *debugger; /* thread debugging this process */ struct thread *debugger; /* thread debugging this process */