Sorted out a few misplaced definitions.
[wine/wine-kai.git] / server / thread.h
blob3340d5ee93805e7c44a3dc265fbb4a1d6f7bf16b
1 /*
2 * Wine server threads
4 * Copyright (C) 1998 Alexandre Julliard
5 */
7 #ifndef __WINE_SERVER_THREAD_H
8 #define __WINE_SERVER_THREAD_H
10 #ifndef __WINE_SERVER__
11 #error This file can only be used in the Wine server
12 #endif
14 #include "object.h"
16 /* thread structure */
18 struct process;
19 struct thread_wait;
20 struct thread_apc;
21 struct mutex;
22 struct debug_ctx;
23 struct debug_event;
24 struct startup_info;
26 enum run_state
28 RUNNING, /* running normally */
29 TERMINATED /* terminated */
33 struct thread
35 struct object obj; /* object header */
36 struct thread *next; /* system-wide thread list */
37 struct thread *prev;
38 struct thread *proc_next; /* per-process thread list */
39 struct thread *proc_prev;
40 struct process *process;
41 struct mutex *mutex; /* list of currently owned mutexes */
42 struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */
43 struct debug_event *debug_event; /* debug event being sent to debugger */
44 struct startup_info*info; /* startup info for child process */
45 struct thread_wait *wait; /* current wait condition if sleeping */
46 struct thread_apc *apc; /* list of async procedure calls */
47 int apc_count; /* number of outstanding APCs */
48 int error; /* current error code */
49 int pass_fd; /* fd to pass to the client */
50 enum run_state state; /* running state */
51 int attached; /* is thread attached with ptrace? */
52 int exit_code; /* thread exit code */
53 int unix_pid; /* Unix pid of client */
54 CONTEXT *context; /* current context if in an exception handler */
55 void *teb; /* TEB address (in client address space) */
56 int priority; /* priority level */
57 int affinity; /* affinity mask */
58 int suspend; /* suspend count */
59 void *buffer; /* buffer for communication with the client */
60 enum request last_req; /* last request received (for debugging) */
63 struct thread_snapshot
65 struct thread *thread; /* thread ptr */
66 int count; /* thread refcount */
67 int priority; /* priority class */
70 /* callback function for building the thread reply when sleep_on is finished */
71 typedef void (*sleep_reply)( struct thread *thread, struct object *obj, int signaled );
73 extern struct thread *current;
75 /* thread functions */
77 extern struct thread *create_thread( int fd, struct process *process );
78 extern struct thread *get_thread_from_id( void *id );
79 extern struct thread *get_thread_from_handle( int handle, unsigned int access );
80 extern struct thread *get_thread_from_pid( int pid );
81 extern int suspend_thread( struct thread *thread, int check_limit );
82 extern int resume_thread( struct thread *thread );
83 extern void suspend_all_threads( void );
84 extern void resume_all_threads( void );
85 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
86 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
87 extern void kill_thread( struct thread *thread, int violent_death );
88 extern void wake_up( struct object *obj, int max );
89 extern int sleep_on( int count, struct object *objects[], int flags,
90 int timeout, sleep_reply func );
91 extern struct thread_snapshot *thread_snap( int *count );
93 /* ptrace functions */
95 extern void sigchld_handler();
96 extern void wait4_thread( struct thread *thread, int signal );
97 extern void stop_thread( struct thread *thread );
98 extern void continue_thread( struct thread *thread );
99 extern void detach_thread( struct thread *thread, int sig );
100 extern int suspend_for_ptrace( struct thread *thread );
101 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
102 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
103 extern void *get_thread_ip( struct thread *thread );
106 static inline int get_error(void) { return current->error; }
107 static inline void set_error( int err ) { current->error = err; }
108 static inline void clear_error(void) { set_error(0); }
110 static inline void *get_thread_id( struct thread *thread ) { return thread; }
112 #endif /* __WINE_SERVER_THREAD_H */