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