Fixed resource loading.
[wine/multimedia.git] / server / thread.h
blob6f836dc35bbd767038e2f7f698b9753be35d6321
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;
25 enum run_state
27 RUNNING, /* running normally */
28 TERMINATED /* terminated */
32 struct thread
34 struct object obj; /* object header */
35 struct thread *next; /* system-wide thread list */
36 struct thread *prev;
37 struct thread *proc_next; /* per-process thread list */
38 struct thread *proc_prev;
39 struct process *process;
40 struct mutex *mutex; /* list of currently owned mutexes */
41 struct debug_ctx *debug_ctx; /* debugger context if this thread is a debugger */
42 struct debug_event *debug_event; /* debug event being sent to debugger */
43 struct thread_wait *wait; /* current wait condition if sleeping */
44 struct thread_apc *apc; /* list of async procedure calls */
45 int apc_count; /* number of outstanding APCs */
46 int error; /* current error code */
47 int pass_fd; /* fd to pass to the client */
48 enum run_state state; /* running state */
49 int attached; /* is thread attached with ptrace? */
50 int exit_code; /* thread exit code */
51 int unix_pid; /* Unix pid of client */
52 CONTEXT *context; /* current context if in an exception handler */
53 void *teb; /* TEB address (in client address space) */
54 int priority; /* priority level */
55 int affinity; /* affinity mask */
56 int suspend; /* suspend count */
57 void *buffer; /* buffer for communication with the client */
58 enum request last_req; /* last request received (for debugging) */
61 struct thread_snapshot
63 struct thread *thread; /* thread ptr */
64 int count; /* thread refcount */
65 int priority; /* priority class */
68 /* callback function for building the thread reply when sleep_on is finished */
69 typedef void (*sleep_reply)( struct thread *thread, struct object *obj, int signaled );
71 extern struct thread *current;
73 /* thread functions */
75 extern struct thread *create_thread( int fd, struct process *process, int suspend );
76 extern struct thread *get_thread_from_id( void *id );
77 extern struct thread *get_thread_from_handle( int handle, unsigned int access );
78 extern struct thread *get_thread_from_pid( int pid );
79 extern int suspend_thread( struct thread *thread, int check_limit );
80 extern int resume_thread( struct thread *thread );
81 extern void suspend_all_threads( void );
82 extern void resume_all_threads( void );
83 extern int add_queue( struct object *obj, struct wait_queue_entry *entry );
84 extern void remove_queue( struct object *obj, struct wait_queue_entry *entry );
85 extern void kill_thread( struct thread *thread, int violent_death );
86 extern void wake_up( struct object *obj, int max );
87 extern int sleep_on( int count, struct object *objects[], int flags,
88 int timeout, sleep_reply func );
89 extern struct thread_snapshot *thread_snap( int *count );
91 /* ptrace functions */
93 extern void sigchld_handler();
94 extern void wait4_thread( struct thread *thread, int signal );
95 extern void stop_thread( struct thread *thread );
96 extern void continue_thread( struct thread *thread );
97 extern void detach_thread( struct thread *thread, int sig );
98 extern int suspend_for_ptrace( struct thread *thread );
99 extern int read_thread_int( struct thread *thread, const int *addr, int *data );
100 extern int write_thread_int( struct thread *thread, int *addr, int data, unsigned int mask );
101 extern void *get_thread_ip( struct thread *thread );
104 static inline int get_error(void) { return current->error; }
105 static inline void set_error( int err ) { current->error = err; }
106 static inline void clear_error(void) { set_error(0); }
108 static inline void *get_thread_id( struct thread *thread ) { return thread; }
110 #endif /* __WINE_SERVER_THREAD_H */