5 #ifndef _MONO_METADATA_W32HANDLE_H_
6 #define _MONO_METADATA_W32HANDLE_H_
15 #ifndef INVALID_HANDLE_VALUE
16 #define INVALID_HANDLE_VALUE (gpointer)-1
19 #define MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS 64
21 #ifndef MONO_INFINITE_WAIT
22 #define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
26 MONO_W32HANDLE_UNUSED
= 0,
28 MONO_W32HANDLE_CONSOLE
,
29 MONO_W32HANDLE_THREAD
,
33 MONO_W32HANDLE_SOCKET
,
35 MONO_W32HANDLE_PROCESS
,
37 MONO_W32HANDLE_NAMEDMUTEX
,
38 MONO_W32HANDLE_NAMEDSEM
,
39 MONO_W32HANDLE_NAMEDEVENT
,
44 MONO_W32HANDLE_WAIT_RET_SUCCESS_0
= 0,
45 MONO_W32HANDLE_WAIT_RET_ABANDONED_0
= MONO_W32HANDLE_WAIT_RET_SUCCESS_0
+ MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS
,
46 MONO_W32HANDLE_WAIT_RET_ALERTED
= -1,
47 MONO_W32HANDLE_WAIT_RET_TIMEOUT
= -2,
48 MONO_W32HANDLE_WAIT_RET_FAILED
= -3,
49 } MonoW32HandleWaitRet
;
53 void (*close
)(gpointer handle
, gpointer data
);
55 /* mono_w32handle_signal_and_wait */
56 void (*signal
)(gpointer signal
, gpointer data
);
58 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
59 * with the handle locked (shared handles aren't locked.)
60 * Returns TRUE if ownership was established, false otherwise.
61 * If TRUE, *abandoned contains a status code such as
62 * WAIT_OBJECT_0 or WAIT_ABANDONED_0.
64 gboolean (*own_handle
)(gpointer handle
, gboolean
*abandoned
);
66 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple, if the
67 * handle in question is "ownable" (ie mutexes), to see if the current
68 * thread already owns this handle
70 gboolean (*is_owned
)(gpointer handle
);
72 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
73 * if the handle in question needs a special wait function
74 * instead of using the normal handle signal mechanism.
75 * Returns the mono_w32handle_wait_one return code.
77 MonoW32HandleWaitRet (*special_wait
)(gpointer handle
, guint32 timeout
, gboolean
*alerted
);
79 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
80 * if the handle in question needs some preprocessing before the
83 void (*prewait
)(gpointer handle
);
85 /* Called when dumping the handles */
86 void (*details
)(gpointer data
);
88 /* Called to get the name of the handle type */
89 const gchar
* (*typename
) (void);
91 /* Called to get the size of the handle type */
92 gsize (*typesize
) (void);
96 MONO_W32HANDLE_CAP_WAIT
= 0x01,
97 MONO_W32HANDLE_CAP_SIGNAL
= 0x02,
98 MONO_W32HANDLE_CAP_OWN
= 0x04,
99 MONO_W32HANDLE_CAP_SPECIAL_WAIT
= 0x08,
100 } MonoW32HandleCapability
;
102 extern guint32 mono_w32handle_fd_reserve
;
105 mono_w32handle_init (void);
108 mono_w32handle_cleanup (void);
111 mono_w32handle_register_ops (MonoW32HandleType type
, MonoW32HandleOps
*ops
);
114 mono_w32handle_new (MonoW32HandleType type
, gpointer handle_specific
);
117 mono_w32handle_new_fd (MonoW32HandleType type
, int fd
, gpointer handle_specific
);
120 mono_w32handle_duplicate (gpointer handle
);
123 mono_w32handle_close (gpointer handle
);
126 mono_w32handle_get_type (gpointer handle
);
129 mono_w32handle_get_typename (MonoW32HandleType type
);
132 mono_w32handle_lookup (gpointer handle
, MonoW32HandleType type
, gpointer
*handle_specific
);
135 mono_w32handle_foreach (gboolean (*on_each
)(gpointer handle
, gpointer data
, gpointer user_data
), gpointer user_data
);
138 mono_w32handle_dump (void);
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_ */