Fixed typo in HKEY_CURRENT_CONFIG name.
[wine] / server / thread.h
1 /*
2  * Wine server threads
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_SERVER_THREAD_H
8 #define __WINE_SERVER_THREAD_H
9
10 #ifndef __WINE_SERVER__
11 #error This file can only be used in the Wine server
12 #endif
13
14 #include "object.h"
15
16 /* thread structure */
17
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;
25 struct msg_queue;
26
27 enum run_state
28 {
29     RUNNING,    /* running normally */
30     TERMINATED  /* terminated */
31 };
32
33
34 struct thread
35 {
36     struct object       obj;       /* object header */
37     struct thread      *next;      /* system-wide thread list */
38     struct thread      *prev;
39     struct thread      *proc_next; /* per-process thread list */
40     struct thread      *proc_prev;
41     struct process     *process;
42     struct mutex       *mutex;       /* list of currently owned mutexes */
43     struct debug_ctx   *debug_ctx;   /* debugger context if this thread is a debugger */
44     struct debug_event *debug_event; /* debug event being sent to debugger */
45     struct msg_queue   *queue;       /* message queue */
46     struct startup_info*info;        /* startup info for child process */
47     struct thread_wait *wait;        /* current wait condition if sleeping */
48     struct thread_apc  *apc_head;    /* queue of async procedure calls */
49     struct thread_apc  *apc_tail;    /* queue of async procedure calls */
50     int                 error;     /* current error code */
51     int                 pass_fd;   /* fd to pass to the client */
52     enum run_state      state;     /* running state */
53     int                 attached;  /* is thread attached with ptrace? */
54     int                 exit_code; /* thread exit code */
55     int                 unix_pid;  /* Unix pid of client */
56     CONTEXT            *context;   /* current context if in an exception handler */
57     void               *teb;       /* TEB address (in client address space) */
58     int                 priority;  /* priority level */
59     int                 affinity;  /* affinity mask */
60     int                 suspend;   /* suspend count */
61     void               *buffer;    /* buffer for communication with the client */
62     enum request        last_req;  /* last request received (for debugging) */
63 };
64
65 struct thread_snapshot
66 {
67     struct thread  *thread;    /* thread ptr */
68     int             count;     /* thread refcount */
69     int             priority;  /* priority class */
70 };
71
72 /* callback function for building the thread reply when sleep_on is finished */
73 typedef void (*sleep_reply)( struct thread *thread, struct object *obj, int signaled );
74
75 extern struct thread *current;
76
77 /* thread functions */
78
79 extern struct thread *create_thread( int fd, struct process *process );
80 extern struct thread *get_thread_from_id( void *id );
81 extern struct thread *get_thread_from_handle( int handle, unsigned int access );
82 extern struct thread *get_thread_from_pid( int pid );
83 extern int suspend_thread( struct thread *thread, int check_limit );
84 extern int resume_thread( struct thread *thread );
85 extern void suspend_all_threads( void );
86 extern void resume_all_threads( void );
87 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
88 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
89 extern void kill_thread( struct thread *thread, int violent_death );
90 extern void wake_up( struct object *obj, int max );
91 extern int sleep_on( int count, struct object *objects[], int flags,
92                      int timeout, sleep_reply func );
93 extern int thread_queue_apc( struct thread *thread, struct object *owner, void *func,
94                              enum apc_type type, int nb_args, ... );
95 extern void thread_cancel_apc( struct thread *thread, struct object *owner );
96 extern struct thread_snapshot *thread_snap( int *count );
97
98 /* ptrace functions */
99
100 extern void sigchld_handler();
101 extern void wait4_thread( struct thread *thread, int signal );
102 extern void stop_thread( struct thread *thread );
103 extern void continue_thread( struct thread *thread );
104 extern void detach_thread( struct thread *thread, int sig );
105 extern int suspend_for_ptrace( struct thread *thread );
106 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
107 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
108 extern void *get_thread_ip( struct thread *thread );
109
110 extern int global_error;  /* global error code for when no thread is current */
111
112 static inline int get_error(void)       { return current ? current->error : global_error; }
113 static inline void set_error( int err ) { global_error = err; if (current) current->error = err; }
114 static inline void clear_error(void)    { set_error(0); }
115
116 static inline void *get_thread_id( struct thread *thread ) { return thread; }
117
118 #endif  /* __WINE_SERVER_THREAD_H */