New mechanism to transfer file descriptors from client to server.
[wine/multimedia.git] / server / thread.h
blob5d25f3c9cc627234d064107a1b47d447f42b5c80
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 /* descriptor for fds currently in flight from client to server */
40 struct inflight_fd
42 int client; /* fd on the client side (or -1 if entry is free) */
43 int server; /* fd on the server side */
45 #define MAX_INFLIGHT_FDS 16 /* max number of fds in flight per thread */
47 struct thread
49 struct object obj; /* object header */
50 struct thread *next; /* system-wide thread list */
51 struct thread *prev;
52 struct thread *proc_next; /* per-process thread list */
53 struct thread *proc_prev;
54 struct process *process;
55 struct mutex *mutex; /* list of currently owned mutexes */
56 struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */
57 struct debug_event *debug_event; /* debug event being sent to debugger */
58 struct msg_queue *queue; /* message queue */
59 struct startup_info*info; /* startup info for child process */
60 struct thread_wait *wait; /* current wait condition if sleeping */
61 struct apc_queue system_apc; /* queue of system async procedure calls */
62 struct apc_queue user_apc; /* queue of user async procedure calls */
63 struct inflight_fd inflight[MAX_INFLIGHT_FDS]; /* fds currently in flight */
64 unsigned int error; /* current error code */
65 struct object *request_fd; /* fd for receiving client requests */
66 int reply_fd; /* fd to send a reply to a client */
67 int wait_fd; /* fd to use to wake a sleeping client */
68 enum run_state state; /* running state */
69 int attached; /* is thread attached with ptrace? */
70 int exit_code; /* thread exit code */
71 int unix_pid; /* Unix pid of client */
72 CONTEXT *context; /* current context if in an exception handler */
73 void *teb; /* TEB address (in client address space) */
74 int priority; /* priority level */
75 int affinity; /* affinity mask */
76 int suspend; /* suspend count */
77 void *buffer; /* buffer for communication with the client */
78 enum request last_req; /* last request received (for debugging) */
81 struct thread_snapshot
83 struct thread *thread; /* thread ptr */
84 int count; /* thread refcount */
85 int priority; /* priority class */
88 extern struct thread *current;
90 /* thread functions */
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 void suspend_all_threads( void );
99 extern void resume_all_threads( void );
100 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
101 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
102 extern void kill_thread( struct thread *thread, int violent_death );
103 extern void wake_up( struct object *obj, int max );
104 extern int thread_queue_apc( struct thread *thread, struct object *owner, void *func,
105 enum apc_type type, int system, int nb_args, ... );
106 extern void thread_cancel_apc( struct thread *thread, struct object *owner, int system );
107 extern int thread_add_inflight_fd( struct thread *thread, int client, int server );
108 extern int thread_get_inflight_fd( struct thread *thread, int client );
109 extern struct thread_snapshot *thread_snap( int *count );
111 /* ptrace functions */
113 extern void sigchld_handler();
114 extern void wait4_thread( struct thread *thread, int signal );
115 extern void stop_thread( struct thread *thread );
116 extern void continue_thread( struct thread *thread );
117 extern void detach_thread( struct thread *thread, int sig );
118 extern int suspend_for_ptrace( struct thread *thread );
119 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
120 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
121 extern void *get_thread_ip( struct thread *thread );
123 extern unsigned int global_error; /* global error code for when no thread is current */
125 static inline unsigned int get_error(void) { return current ? current->error : global_error; }
126 static inline void set_error( unsigned int err ) { global_error = err; if (current) current->error = err; }
127 static inline void clear_error(void) { set_error(0); }
129 static inline void *get_thread_id( struct thread *thread ) { return thread; }
131 #endif /* __WINE_SERVER_THREAD_H */