Change WSACleanup - wsinfo is a static structure now.
[wine.git] / server / thread.h
blob4b5aa11fc0579bfc414da6c2d9146ef90aa9de21
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;
25 struct msg_queue;
27 enum run_state
29 RUNNING, /* running normally */
30 TERMINATED /* terminated */
33 struct apc_queue
35 struct thread_apc *head;
36 struct thread_apc *tail;
39 struct thread
41 struct object obj; /* object header */
42 struct thread *next; /* system-wide thread list */
43 struct thread *prev;
44 struct thread *proc_next; /* per-process thread list */
45 struct thread *proc_prev;
46 struct process *process;
47 struct mutex *mutex; /* list of currently owned mutexes */
48 struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */
49 struct debug_event *debug_event; /* debug event being sent to debugger */
50 struct msg_queue *queue; /* message queue */
51 struct startup_info*info; /* startup info for child process */
52 struct thread_wait *wait; /* current wait condition if sleeping */
53 struct apc_queue system_apc; /* queue of system async procedure calls */
54 struct apc_queue user_apc; /* queue of user async procedure calls */
55 unsigned int error; /* current error code */
56 struct object *request_fd; /* fd for receiving client requests */
57 int pass_fd; /* fd to pass to the client */
58 int reply_fd; /* fd to use to wake a client waiting on a reply */
59 enum run_state state; /* running state */
60 int attached; /* is thread attached with ptrace? */
61 int exit_code; /* thread exit code */
62 int unix_pid; /* Unix pid of client */
63 CONTEXT *context; /* current context if in an exception handler */
64 void *teb; /* TEB address (in client address space) */
65 int priority; /* priority level */
66 int affinity; /* affinity mask */
67 int suspend; /* suspend count */
68 void *buffer; /* buffer for communication with the client */
69 struct server_buffer_info *buffer_info; /* buffer information structure */
70 enum request last_req; /* last request received (for debugging) */
73 struct thread_snapshot
75 struct thread *thread; /* thread ptr */
76 int count; /* thread refcount */
77 int priority; /* priority class */
80 /* callback function for building the thread reply when sleep_on is finished */
81 typedef void (*sleep_reply)( struct thread *thread, struct object *obj, int signaled );
83 extern struct thread *current;
85 /* thread functions */
87 extern struct thread *create_thread( int fd, struct process *process );
88 extern struct thread *get_thread_from_id( void *id );
89 extern struct thread *get_thread_from_handle( handle_t handle, unsigned int access );
90 extern struct thread *get_thread_from_pid( int pid );
91 extern int suspend_thread( struct thread *thread, int check_limit );
92 extern int resume_thread( struct thread *thread );
93 extern void suspend_all_threads( void );
94 extern void resume_all_threads( void );
95 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
96 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
97 extern void kill_thread( struct thread *thread, int violent_death );
98 extern void wake_up( struct object *obj, int max );
99 extern int sleep_on( int count, struct object *objects[], int flags,
100 int sec, int usec, sleep_reply func );
101 extern int thread_queue_apc( struct thread *thread, struct object *owner, void *func,
102 enum apc_type type, int system, int nb_args, ... );
103 extern void thread_cancel_apc( struct thread *thread, struct object *owner, int system );
104 extern struct thread_snapshot *thread_snap( int *count );
106 /* ptrace functions */
108 extern void sigchld_handler();
109 extern void wait4_thread( struct thread *thread, int signal );
110 extern void stop_thread( struct thread *thread );
111 extern void continue_thread( struct thread *thread );
112 extern void detach_thread( struct thread *thread, int sig );
113 extern int suspend_for_ptrace( struct thread *thread );
114 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
115 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
116 extern void *get_thread_ip( struct thread *thread );
118 extern unsigned int global_error; /* global error code for when no thread is current */
120 static inline unsigned int get_error(void) { return current ? current->error : global_error; }
121 static inline void set_error( unsigned int err ) { global_error = err; if (current) current->error = err; }
122 static inline void clear_error(void) { set_error(0); }
124 static inline void *get_thread_id( struct thread *thread ) { return thread; }
126 #endif /* __WINE_SERVER_THREAD_H */