2 #ifndef _MONO_METADATA_W32HANDLE_H_
3 #define _MONO_METADATA_W32HANDLE_H_
12 #ifndef INVALID_HANDLE_VALUE
13 #define INVALID_HANDLE_VALUE (gpointer)-1
16 #define MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS 64
18 #ifndef MONO_INFINITE_WAIT
19 #define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
23 MONO_W32HANDLE_UNUSED = 0,
25 MONO_W32HANDLE_CONSOLE,
26 MONO_W32HANDLE_THREAD,
30 MONO_W32HANDLE_SOCKET,
32 MONO_W32HANDLE_PROCESS,
34 MONO_W32HANDLE_NAMEDMUTEX,
35 MONO_W32HANDLE_NAMEDSEM,
36 MONO_W32HANDLE_NAMEDEVENT,
41 MONO_W32HANDLE_WAIT_RET_SUCCESS_0 = 0,
42 MONO_W32HANDLE_WAIT_RET_ABANDONED_0 = MONO_W32HANDLE_WAIT_RET_SUCCESS_0 + MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS,
43 MONO_W32HANDLE_WAIT_RET_ALERTED = -1,
44 MONO_W32HANDLE_WAIT_RET_TIMEOUT = -2,
45 MONO_W32HANDLE_WAIT_RET_FAILED = -3,
46 } MonoW32HandleWaitRet;
50 void (*close)(gpointer handle, gpointer data);
52 /* mono_w32handle_signal_and_wait */
53 void (*signal)(gpointer signal);
55 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
56 * with the handle locked (shared handles aren't locked.)
57 * Returns TRUE if ownership was established, false otherwise.
58 * If TRUE, *abandoned contains a status code such as
59 * WAIT_OBJECT_0 or WAIT_ABANDONED_0.
61 gboolean (*own_handle)(gpointer handle, gboolean *abandoned);
63 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple, if the
64 * handle in question is "ownable" (ie mutexes), to see if the current
65 * thread already owns this handle
67 gboolean (*is_owned)(gpointer handle);
69 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
70 * if the handle in question needs a special wait function
71 * instead of using the normal handle signal mechanism.
72 * Returns the mono_w32handle_wait_one return code.
74 MonoW32HandleWaitRet (*special_wait)(gpointer handle, guint32 timeout, gboolean *alerted);
76 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
77 * if the handle in question needs some preprocessing before the
80 void (*prewait)(gpointer handle);
82 /* Called when dumping the handles */
83 void (*details)(gpointer data);
85 /* Called to get the name of the handle type */
86 const gchar* (*typename) (void);
88 /* Called to get the size of the handle type */
89 gsize (*typesize) (void);
93 MONO_W32HANDLE_CAP_WAIT = 0x01,
94 MONO_W32HANDLE_CAP_SIGNAL = 0x02,
95 MONO_W32HANDLE_CAP_OWN = 0x04,
96 MONO_W32HANDLE_CAP_SPECIAL_WAIT = 0x08,
97 } MonoW32HandleCapability;
99 extern guint32 mono_w32handle_fd_reserve;
102 mono_w32handle_init (void);
105 mono_w32handle_cleanup (void);
108 mono_w32handle_register_ops (MonoW32HandleType type, MonoW32HandleOps *ops);
111 mono_w32handle_new (MonoW32HandleType type, gpointer handle_specific);
114 mono_w32handle_new_fd (MonoW32HandleType type, int fd, gpointer handle_specific);
117 mono_w32handle_close (gpointer handle);
120 mono_w32handle_get_type (gpointer handle);
123 mono_w32handle_get_typename (MonoW32HandleType type);
126 mono_w32handle_lookup (gpointer handle, MonoW32HandleType type, gpointer *handle_specific);
129 mono_w32handle_foreach (gboolean (*on_each)(gpointer handle, gpointer data, gpointer user_data), gpointer user_data);
132 mono_w32handle_dump (void);
135 mono_w32handle_ref (gpointer handle);
138 mono_w32handle_unref (gpointer handle);
141 mono_w32handle_register_capabilities (MonoW32HandleType type, MonoW32HandleCapability caps);
144 mono_w32handle_test_capabilities (gpointer handle, MonoW32HandleCapability caps);
147 mono_w32handle_force_close (gpointer handle, gpointer data);
150 mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast);
153 mono_w32handle_issignalled (gpointer handle);
156 mono_w32handle_lock_handle (gpointer handle);
159 mono_w32handle_trylock_handle (gpointer handle);
162 mono_w32handle_unlock_handle (gpointer handle);
165 mono_w32handle_wait_one (gpointer handle, guint32 timeout, gboolean alertable);
168 mono_w32handle_wait_multiple (gpointer *handles, gsize nhandles, gboolean waitall, guint32 timeout, gboolean alertable);
171 mono_w32handle_signal_and_wait (gpointer signal_handle, gpointer wait_handle, guint32 timeout, gboolean alertable);
174 static inline MonoW32HandleWaitRet
175 mono_w32handle_convert_wait_ret (guint32 res, guint32 numobjects)
177 if (res >= WAIT_OBJECT_0 && res <= WAIT_OBJECT_0 + numobjects - 1)
178 return MONO_W32HANDLE_WAIT_RET_SUCCESS_0 + (res - WAIT_OBJECT_0);
179 else if (res >= WAIT_ABANDONED_0 && res <= WAIT_ABANDONED_0 + numobjects - 1)
180 return MONO_W32HANDLE_WAIT_RET_ABANDONED_0 + (res - WAIT_ABANDONED_0);
181 else if (res == WAIT_IO_COMPLETION)
182 return MONO_W32HANDLE_WAIT_RET_ALERTED;
183 else if (res == WAIT_TIMEOUT)
184 return MONO_W32HANDLE_WAIT_RET_TIMEOUT;
185 else if (res == WAIT_FAILED)
186 return MONO_W32HANDLE_WAIT_RET_FAILED;
188 g_error ("%s: unknown res value %d", __func__, res);
193 #endif /* _MONO_METADATA_W32HANDLE_H_ */