5 #ifndef _MONO_METADATA_W32HANDLE_H_
6 #define _MONO_METADATA_W32HANDLE_H_
15 #include "mono/utils/mono-coop-mutex.h"
16 #include "mono/utils/mono-error.h"
18 #ifndef INVALID_HANDLE_VALUE
19 #define INVALID_HANDLE_VALUE ((gpointer)-1)
22 #define MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS 64
24 #ifndef MONO_INFINITE_WAIT
25 #define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
29 MONO_W32TYPE_UNUSED
= 0,
34 MONO_W32TYPE_NAMEDMUTEX
,
35 MONO_W32TYPE_NAMEDSEM
,
36 MONO_W32TYPE_NAMEDEVENT
,
45 MonoCoopMutex signal_mutex
;
46 MonoCoopCond signal_cond
;
51 MONO_W32HANDLE_WAIT_RET_SUCCESS_0
= 0,
52 MONO_W32HANDLE_WAIT_RET_ABANDONED_0
= MONO_W32HANDLE_WAIT_RET_SUCCESS_0
+ MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS
,
53 MONO_W32HANDLE_WAIT_RET_ALERTED
= -1,
54 MONO_W32HANDLE_WAIT_RET_TIMEOUT
= -2,
55 MONO_W32HANDLE_WAIT_RET_FAILED
= -3,
56 } MonoW32HandleWaitRet
;
60 void (*close
)(gpointer data
);
62 /* mono_w32handle_signal_and_wait */
63 void (*signal
)(MonoW32Handle
*handle_data
);
65 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
66 * with the handle locked (shared handles aren't locked.)
67 * Returns TRUE if ownership was established, false otherwise.
68 * If TRUE, *abandoned contains a status code such as
69 * WAIT_OBJECT_0 or WAIT_ABANDONED_0.
71 gboolean (*own_handle
)(MonoW32Handle
*handle_data
, gboolean
*abandoned
);
73 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple, if the
74 * handle in question is "ownable" (ie mutexes), to see if the current
75 * thread already owns this handle
77 gboolean (*is_owned
)(MonoW32Handle
*handle_data
);
79 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
80 * if the handle in question needs a special wait function
81 * instead of using the normal handle signal mechanism.
82 * Returns the mono_w32handle_wait_one return code.
84 MonoW32HandleWaitRet (*special_wait
)(MonoW32Handle
*handle_data
, guint32 timeout
, gboolean
*alerted
);
86 /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
87 * if the handle in question needs some preprocessing before the
90 void (*prewait
)(MonoW32Handle
*handle_data
);
92 /* Called when dumping the handles */
93 void (*details
)(MonoW32Handle
*handle_data
);
95 /* Called to get the name of the handle type */
96 const char* (*type_name
) (void);
98 /* Called to get the size of the handle type */
99 gsize (*typesize
) (void);
103 MONO_W32HANDLE_CAP_WAIT
= 0x01,
104 MONO_W32HANDLE_CAP_SIGNAL
= 0x02,
105 MONO_W32HANDLE_CAP_OWN
= 0x04,
106 MONO_W32HANDLE_CAP_SPECIAL_WAIT
= 0x08,
107 } MonoW32HandleCapability
;
110 mono_w32handle_init (void);
113 mono_w32handle_cleanup (void);
116 mono_w32handle_register_ops (MonoW32Type type
, const MonoW32HandleOps
*ops
);
119 mono_w32handle_new (MonoW32Type type
, gpointer handle_specific
);
122 mono_w32handle_duplicate (MonoW32Handle
*handle_data
);
125 mono_w32handle_close (gpointer handle
);
128 mono_w32handle_get_typename (MonoW32Type type
);
131 mono_w32handle_lookup_and_ref (gpointer handle
, MonoW32Handle
**handle_data
);
134 mono_w32handle_unref (MonoW32Handle
*handle_data
);
137 mono_w32handle_foreach (gboolean (*on_each
)(MonoW32Handle
*handle_data
, gpointer user_data
), gpointer user_data
);
140 mono_w32handle_dump (void);
143 mono_w32handle_register_capabilities (MonoW32Type type
, MonoW32HandleCapability caps
);
146 mono_w32handle_set_signal_state (MonoW32Handle
*handle_data
, gboolean state
, gboolean broadcast
);
149 mono_w32handle_issignalled (MonoW32Handle
*handle_data
);
152 mono_w32handle_lock (MonoW32Handle
*handle_data
);
155 mono_w32handle_trylock (MonoW32Handle
*handle_data
);
158 mono_w32handle_unlock (MonoW32Handle
*handle_data
);
161 mono_w32handle_wait_one (gpointer handle
, guint32 timeout
, gboolean alertable
);
164 mono_w32handle_wait_multiple (gpointer
*handles
, gsize nhandles
, gboolean waitall
, guint32 timeout
, gboolean alertable
, MonoError
*error
);
167 mono_w32handle_signal_and_wait (gpointer signal_handle
, gpointer wait_handle
, guint32 timeout
, gboolean alertable
);
170 static inline MonoW32HandleWaitRet
171 mono_w32handle_convert_wait_ret (guint32 res
, guint32 numobjects
)
173 if (res
>= WAIT_OBJECT_0
&& res
<= WAIT_OBJECT_0
+ numobjects
- 1)
174 return (MonoW32HandleWaitRet
)(MONO_W32HANDLE_WAIT_RET_SUCCESS_0
+ (res
- WAIT_OBJECT_0
));
175 else if (res
>= WAIT_ABANDONED_0
&& res
<= WAIT_ABANDONED_0
+ numobjects
- 1)
176 return (MonoW32HandleWaitRet
)(MONO_W32HANDLE_WAIT_RET_ABANDONED_0
+ (res
- WAIT_ABANDONED_0
));
177 else if (res
== WAIT_IO_COMPLETION
)
178 return MONO_W32HANDLE_WAIT_RET_ALERTED
;
179 else if (res
== WAIT_TIMEOUT
)
180 return MONO_W32HANDLE_WAIT_RET_TIMEOUT
;
181 else if (res
== WAIT_FAILED
)
182 return MONO_W32HANDLE_WAIT_RET_FAILED
;
184 g_error ("%s: unknown res value %d", __func__
, res
);
189 #endif /* _MONO_METADATA_W32HANDLE_H_ */