69e14c5a03e51b892d1e750f53e609e34fbe563b
[mono.git] / mono / io-layer / thread-private.h
1 /*
2  * thread-private.h:  Private definitions for thread handles
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #ifndef _WAPI_THREAD_PRIVATE_H_
11 #define _WAPI_THREAD_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15 #include <pthread.h>
16 #include <mono/utils/mono-semaphore.h>
17
18 /* There doesn't seem to be a defined symbol for this */
19 #define _WAPI_THREAD_CURRENT (gpointer)0xFFFFFFFE
20 extern gpointer _wapi_thread_duplicate (void);
21
22 extern struct _WapiHandleOps _wapi_thread_ops;
23
24 typedef enum {
25         THREAD_STATE_START,
26         THREAD_STATE_EXITED
27 } WapiThreadState;
28
29 #define INTERRUPTION_REQUESTED_HANDLE (gpointer)0xFFFFFFFE
30
31 struct _WapiHandle_thread
32 {
33         guint32 exitstatus;
34         WapiThreadState state : 2;
35         guint joined : 1;
36         guint has_apc : 1;
37         /* Fields below this point are only valid for the owning process */
38         pthread_t id;
39         GPtrArray *owned_mutexes;
40         gpointer handle;
41         /* 
42      * Handle this thread waits on. If this is INTERRUPTION_REQUESTED_HANDLE,
43          * it means the thread is interrupted by another thread, and shouldn't enter
44          * a wait.
45          * This also acts as a reference for the handle.
46          */
47         gpointer wait_handle;
48         MonoSemType suspend_sem;
49         guint32 (*start_routine)(gpointer arg);
50         gpointer start_arg;
51 };
52
53 typedef struct
54 {
55         guint32 (*callback)(gpointer arg);
56         gpointer param;
57 } ApcInfo;
58
59 extern gboolean _wapi_thread_apc_pending (gpointer handle);
60 extern gboolean _wapi_thread_cur_apc_pending (void);
61 extern gboolean _wapi_thread_dispatch_apc_queue (gpointer handle);
62 extern void _wapi_thread_own_mutex (gpointer mutex);
63 extern void _wapi_thread_disown_mutex (gpointer mutex);
64 extern gpointer _wapi_thread_handle_from_id (pthread_t tid);
65 extern void _wapi_thread_set_termination_details (gpointer handle,
66                                                   guint32 exitstatus);
67 extern void _wapi_thread_cleanup (void);
68
69 #endif /* _WAPI_THREAD_PRIVATE_H_ */