Merge pull request #3802 from lambdageek/dev-reference-attr-take3
[mono.git] / mono / metadata / w32handle.h
1
2 #ifndef _MONO_METADATA_W32HANDLE_H_
3 #define _MONO_METADATA_W32HANDLE_H_
4
5 #include <config.h>
6 #include <glib.h>
7
8 #ifndef INVALID_HANDLE_VALUE
9 #define INVALID_HANDLE_VALUE (gpointer)-1
10 #endif
11
12 #define MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS 64
13
14 typedef enum {
15         MONO_W32HANDLE_UNUSED = 0,
16         MONO_W32HANDLE_FILE,
17         MONO_W32HANDLE_CONSOLE,
18         MONO_W32HANDLE_THREAD,
19         MONO_W32HANDLE_SEM,
20         MONO_W32HANDLE_MUTEX,
21         MONO_W32HANDLE_EVENT,
22         MONO_W32HANDLE_SOCKET,
23         MONO_W32HANDLE_FIND,
24         MONO_W32HANDLE_PROCESS,
25         MONO_W32HANDLE_PIPE,
26         MONO_W32HANDLE_NAMEDMUTEX,
27         MONO_W32HANDLE_NAMEDSEM,
28         MONO_W32HANDLE_NAMEDEVENT,
29         MONO_W32HANDLE_COUNT
30 } MonoW32HandleType;
31
32 typedef struct 
33 {
34         void (*close)(gpointer handle, gpointer data);
35
36         /* SignalObjectAndWait */
37         void (*signal)(gpointer signal);
38
39         /* Called by WaitForSingleObject and WaitForMultipleObjects,
40          * with the handle locked (shared handles aren't locked.)
41          * Returns TRUE if ownership was established, false otherwise.
42          * If TRUE, *statuscode contains a status code such as
43          * WAIT_OBJECT_0 or WAIT_ABANDONED_0.
44          */
45         gboolean (*own_handle)(gpointer handle, guint32 *statuscode);
46
47         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
48          * handle in question is "ownable" (ie mutexes), to see if the current
49          * thread already owns this handle
50          */
51         gboolean (*is_owned)(gpointer handle);
52
53         /* Called by WaitForSingleObject and WaitForMultipleObjects,
54          * if the handle in question needs a special wait function
55          * instead of using the normal handle signal mechanism.
56          * Returns the WaitForSingleObject return code.
57          */
58         guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean *alerted);
59
60         /* Called by WaitForSingleObject and WaitForMultipleObjects,
61          * if the handle in question needs some preprocessing before the
62          * signal wait.
63          */
64         void (*prewait)(gpointer handle);
65
66         /* Called when dumping the handles */
67         void (*details)(gpointer data);
68
69         /* Called to get the name of the handle type */
70         const gchar* (*typename) (void);
71
72         /* Called to get the size of the handle type */
73         gsize (*typesize) (void);
74 } MonoW32HandleOps;
75
76 typedef enum {
77         MONO_W32HANDLE_CAP_WAIT         = 0x01,
78         MONO_W32HANDLE_CAP_SIGNAL       = 0x02,
79         MONO_W32HANDLE_CAP_OWN          = 0x04,
80         MONO_W32HANDLE_CAP_SPECIAL_WAIT = 0x08,
81 } MonoW32HandleCapability;
82
83 extern guint32 mono_w32handle_fd_reserve;
84
85 void
86 mono_w32handle_init (void);
87
88 void
89 mono_w32handle_cleanup (void);
90
91 void
92 mono_w32handle_register_ops (MonoW32HandleType type, MonoW32HandleOps *ops);
93
94 gpointer
95 mono_w32handle_new (MonoW32HandleType type, gpointer handle_specific);
96
97 gpointer
98 mono_w32handle_new_fd (MonoW32HandleType type, int fd, gpointer handle_specific);
99
100 MonoW32HandleType
101 mono_w32handle_get_type (gpointer handle);
102
103 gboolean
104 mono_w32handle_lookup (gpointer handle, MonoW32HandleType type, gpointer *handle_specific);
105
106 gpointer
107 mono_w32handle_search (MonoW32HandleType type, gboolean (*check)(gpointer, gpointer), gpointer user_data, gpointer *handle_specific, gboolean search_shared);
108
109 void
110 mono_w32handle_foreach (gboolean (*on_each)(gpointer handle, gpointer data, gpointer user_data), gpointer user_data);
111
112 void
113 mono_w32handle_dump (void);
114
115 void
116 mono_w32handle_ref (gpointer handle);
117
118 void
119 mono_w32handle_unref (gpointer handle);
120
121 void
122 mono_w32handle_register_capabilities (MonoW32HandleType type, MonoW32HandleCapability caps);
123
124 gboolean
125 mono_w32handle_test_capabilities (gpointer handle, MonoW32HandleCapability caps);
126
127 void
128 mono_w32handle_ops_close (gpointer handle, gpointer data);
129
130 void
131 mono_w32handle_ops_signal (gpointer handle);
132
133 gboolean
134 mono_w32handle_ops_own (gpointer handle, guint32 *statuscode);
135
136 gboolean
137 mono_w32handle_ops_isowned (gpointer handle);
138
139 guint32
140 mono_w32handle_ops_specialwait (gpointer handle, guint32 timeout, gboolean *alerted);
141
142 void
143 mono_w32handle_ops_prewait (gpointer handle);
144
145 void
146 mono_w32handle_ops_details (MonoW32HandleType type, gpointer data);
147
148 const gchar*
149 mono_w32handle_ops_typename (MonoW32HandleType type);
150
151 gsize
152 mono_w32handle_ops_typesize (MonoW32HandleType type);
153
154 void
155 mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast);
156
157 gboolean
158 mono_w32handle_issignalled (gpointer handle);
159
160 int
161 mono_w32handle_lock_handle (gpointer handle);
162
163 int
164 mono_w32handle_trylock_handle (gpointer handle);
165
166 int
167 mono_w32handle_unlock_handle (gpointer handle);
168
169 typedef enum {
170         MONO_W32HANDLE_WAIT_RET_SUCCESS_0   =  0,
171         MONO_W32HANDLE_WAIT_RET_ABANDONED_0 =  MONO_W32HANDLE_WAIT_RET_SUCCESS_0 + MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS,
172         MONO_W32HANDLE_WAIT_RET_ALERTED     = -1,
173         MONO_W32HANDLE_WAIT_RET_TIMEOUT     = -2,
174         MONO_W32HANDLE_WAIT_RET_FAILED      = -3,
175 } MonoW32HandleWaitRet;
176
177 MonoW32HandleWaitRet
178 mono_w32handle_wait_one (gpointer handle, guint32 timeout, gboolean alertable);
179
180 MonoW32HandleWaitRet
181 mono_w32handle_wait_multiple (gpointer *handles, gsize nhandles, gboolean waitall, guint32 timeout, gboolean alertable);
182
183 MonoW32HandleWaitRet
184 mono_w32handle_signal_and_wait (gpointer signal_handle, gpointer wait_handle, guint32 timeout, gboolean alertable);
185
186 #endif /* _MONO_METADATA_W32HANDLE_H_ */