Implemented processing for actions: SPI_GET/SETGRIDGRANULARITY,
[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 #include "object.h"
11
12 /* thread structure */
13
14 struct process;
15 struct thread_wait;
16 struct thread_apc;
17 struct mutex;
18 struct debug_ctx;
19 struct debug_event;
20 struct startup_info;
21 struct msg_queue;
22
23 enum run_state
24 {
25     RUNNING,    /* running normally */
26     TERMINATED  /* terminated */
27 };
28
29 struct apc_queue
30 {
31     struct thread_apc *head;
32     struct thread_apc *tail;
33 };
34
35 /* descriptor for fds currently in flight from client to server */
36 struct inflight_fd
37 {
38     int client;  /* fd on the client side (or -1 if entry is free) */
39     int server;  /* fd on the server side */
40 };
41 #define MAX_INFLIGHT_FDS 16  /* max number of fds in flight per thread */
42
43 struct thread
44 {
45     struct object          obj;           /* object header */
46     struct thread         *next;          /* system-wide thread list */
47     struct thread         *prev;
48     struct thread         *proc_next;     /* per-process thread list */
49     struct thread         *proc_prev;
50     struct process        *process;
51     struct mutex          *mutex;         /* list of currently owned mutexes */
52     struct debug_ctx      *debug_ctx;     /* debugger context if this thread is a debugger */
53     struct debug_event    *debug_event;   /* debug event being sent to debugger */
54     struct msg_queue      *queue;         /* message queue */
55     struct startup_info   *info;          /* startup info for child process */
56     struct thread_wait    *wait;          /* current wait condition if sleeping */
57     struct apc_queue       system_apc;    /* queue of system async procedure calls */
58     struct apc_queue       user_apc;      /* queue of user async procedure calls */
59     struct inflight_fd     inflight[MAX_INFLIGHT_FDS];  /* fds currently in flight */
60     unsigned int           error;         /* current error code */
61     union generic_request  req;           /* current request */
62     void                  *req_data;      /* variable-size data for request */
63     unsigned int           req_toread;    /* amount of data still to read in request */
64     void                  *reply_data;    /* variable-size data for reply */
65     unsigned int           reply_size;    /* size of reply data */
66     unsigned int           reply_towrite; /* amount of data still to write in reply */
67     int                    request_fd;    /* fd for receiving client requests */
68     int                    reply_fd;      /* fd to send a reply to a client */
69     int                    wait_fd;       /* fd to use to wake a sleeping client */
70     enum run_state         state;         /* running state */
71     int                    attached;      /* is thread attached with ptrace? */
72     int                    exit_code;     /* thread exit code */
73     int                    unix_pid;      /* Unix pid of client */
74     CONTEXT               *context;       /* current context if in an exception handler */
75     void                  *teb;           /* TEB address (in client address space) */
76     int                    priority;      /* priority level */
77     int                    affinity;      /* affinity mask */
78     int                    suspend;       /* suspend count */
79 };
80
81 struct thread_snapshot
82 {
83     struct thread  *thread;    /* thread ptr */
84     int             count;     /* thread refcount */
85     int             priority;  /* priority class */
86 };
87
88 extern struct thread *current;
89
90 /* thread functions */
91
92 extern struct thread *create_thread( int fd, struct process *process );
93 extern struct thread *get_thread_from_id( void *id );
94 extern struct thread *get_thread_from_handle( handle_t handle, unsigned int access );
95 extern struct thread *get_thread_from_pid( int pid );
96 extern int suspend_thread( struct thread *thread, int check_limit );
97 extern int resume_thread( struct thread *thread );
98 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
99 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
100 extern void kill_thread( struct thread *thread, int violent_death );
101 extern void wake_up( struct object *obj, int max );
102 extern int thread_queue_apc( struct thread *thread, struct object *owner, void *func,
103                              enum apc_type type, int system, int nb_args, ... );
104 extern void thread_cancel_apc( struct thread *thread, struct object *owner, int system );
105 extern int thread_add_inflight_fd( struct thread *thread, int client, int server );
106 extern int thread_get_inflight_fd( struct thread *thread, int client );
107 extern struct thread_snapshot *thread_snap( int *count );
108
109 /* ptrace functions */
110
111 extern void sigchld_handler();
112 extern void wait4_thread( struct thread *thread, int signal );
113 extern void stop_thread( struct thread *thread );
114 extern void continue_thread( struct thread *thread );
115 extern void detach_thread( struct thread *thread, int sig );
116 extern int suspend_for_ptrace( struct thread *thread );
117 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
118 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
119 extern void *get_thread_ip( struct thread *thread );
120 extern int get_thread_single_step( struct thread *thread );
121
122 extern unsigned int global_error;  /* global error code for when no thread is current */
123
124 static inline unsigned int get_error(void)       { return current ? current->error : global_error; }
125 static inline void set_error( unsigned int err ) { global_error = err; if (current) current->error = err; }
126 static inline void clear_error(void)    { set_error(0); }
127
128 static inline void *get_thread_id( struct thread *thread ) { return thread; }
129
130 #endif  /* __WINE_SERVER_THREAD_H */