Revert "[w32handle] Remove use of w32handle for File, Console, Pipe and Socket (...
[mono.git] / mono / metadata / w32handle.h
index b67ada79afc1620be0dd42275f6219fa509a009a..b7df9a8810e50fbd9a1400cbdf9e443e0cbf732e 100644 (file)
@@ -1,3 +1,6 @@
+/**
+ * \file
+ */
 
 #ifndef _MONO_METADATA_W32HANDLE_H_
 #define _MONO_METADATA_W32HANDLE_H_
@@ -5,12 +8,20 @@
 #include <config.h>
 #include <glib.h>
 
+#ifdef HOST_WIN32
+#include <windows.h>
+#endif
+
 #ifndef INVALID_HANDLE_VALUE
 #define INVALID_HANDLE_VALUE (gpointer)-1
 #endif
 
 #define MONO_W32HANDLE_MAXIMUM_WAIT_OBJECTS 64
 
+#ifndef MONO_INFINITE_WAIT
+#define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
+#endif
+
 typedef enum {
        MONO_W32HANDLE_UNUSED = 0,
        MONO_W32HANDLE_FILE,
@@ -41,31 +52,31 @@ typedef struct
 {
        void (*close)(gpointer handle, gpointer data);
 
-       /* SignalObjectAndWait */
-       void (*signal)(gpointer signal);
+       /* mono_w32handle_signal_and_wait */
+       void (*signal)(gpointer signal, gpointer data);
 
-       /* Called by WaitForSingleObject and WaitForMultipleObjects,
+       /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
         * with the handle locked (shared handles aren't locked.)
         * Returns TRUE if ownership was established, false otherwise.
-        * If TRUE, *statuscode contains a status code such as
+        * If TRUE, *abandoned contains a status code such as
         * WAIT_OBJECT_0 or WAIT_ABANDONED_0.
         */
-       gboolean (*own_handle)(gpointer handle, guint32 *statuscode);
+       gboolean (*own_handle)(gpointer handle, gboolean *abandoned);
 
-       /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
+       /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple, if the
         * handle in question is "ownable" (ie mutexes), to see if the current
         * thread already owns this handle
         */
        gboolean (*is_owned)(gpointer handle);
 
-       /* Called by WaitForSingleObject and WaitForMultipleObjects,
+       /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
         * if the handle in question needs a special wait function
         * instead of using the normal handle signal mechanism.
-        * Returns the WaitForSingleObject return code.
+        * Returns the mono_w32handle_wait_one return code.
         */
        MonoW32HandleWaitRet (*special_wait)(gpointer handle, guint32 timeout, gboolean *alerted);
 
-       /* Called by WaitForSingleObject and WaitForMultipleObjects,
+       /* Called by mono_w32handle_wait_one and mono_w32handle_wait_multiple,
         * if the handle in question needs some preprocessing before the
         * signal wait.
         */
@@ -105,9 +116,18 @@ mono_w32handle_new (MonoW32HandleType type, gpointer handle_specific);
 gpointer
 mono_w32handle_new_fd (MonoW32HandleType type, int fd, gpointer handle_specific);
 
+gpointer
+mono_w32handle_duplicate (gpointer handle);
+
+gboolean
+mono_w32handle_close (gpointer handle);
+
 MonoW32HandleType
 mono_w32handle_get_type (gpointer handle);
 
+const gchar*
+mono_w32handle_get_typename (MonoW32HandleType type);
+
 gboolean
 mono_w32handle_lookup (gpointer handle, MonoW32HandleType type, gpointer *handle_specific);
 
@@ -117,12 +137,6 @@ mono_w32handle_foreach (gboolean (*on_each)(gpointer handle, gpointer data, gpoi
 void
 mono_w32handle_dump (void);
 
-void
-mono_w32handle_ref (gpointer handle);
-
-void
-mono_w32handle_unref (gpointer handle);
-
 void
 mono_w32handle_register_capabilities (MonoW32HandleType type, MonoW32HandleCapability caps);
 
@@ -130,31 +144,7 @@ gboolean
 mono_w32handle_test_capabilities (gpointer handle, MonoW32HandleCapability caps);
 
 void
-mono_w32handle_ops_close (gpointer handle, gpointer data);
-
-void
-mono_w32handle_ops_signal (gpointer handle);
-
-gboolean
-mono_w32handle_ops_own (gpointer handle, guint32 *statuscode);
-
-gboolean
-mono_w32handle_ops_isowned (gpointer handle);
-
-MonoW32HandleWaitRet
-mono_w32handle_ops_specialwait (gpointer handle, guint32 timeout, gboolean *alerted);
-
-void
-mono_w32handle_ops_prewait (gpointer handle);
-
-void
-mono_w32handle_ops_details (MonoW32HandleType type, gpointer data);
-
-const gchar*
-mono_w32handle_ops_typename (MonoW32HandleType type);
-
-gsize
-mono_w32handle_ops_typesize (MonoW32HandleType type);
+mono_w32handle_force_close (gpointer handle, gpointer data);
 
 void
 mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast);
@@ -162,13 +152,13 @@ mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broad
 gboolean
 mono_w32handle_issignalled (gpointer handle);
 
-int
+void
 mono_w32handle_lock_handle (gpointer handle);
 
-int
+gboolean
 mono_w32handle_trylock_handle (gpointer handle);
 
-int
+void
 mono_w32handle_unlock_handle (gpointer handle);
 
 MonoW32HandleWaitRet
@@ -180,4 +170,24 @@ mono_w32handle_wait_multiple (gpointer *handles, gsize nhandles, gboolean waital
 MonoW32HandleWaitRet
 mono_w32handle_signal_and_wait (gpointer signal_handle, gpointer wait_handle, guint32 timeout, gboolean alertable);
 
+#ifdef HOST_WIN32
+static inline MonoW32HandleWaitRet
+mono_w32handle_convert_wait_ret (guint32 res, guint32 numobjects)
+{
+       if (res >= WAIT_OBJECT_0 && res <= WAIT_OBJECT_0 + numobjects - 1)
+               return MONO_W32HANDLE_WAIT_RET_SUCCESS_0 + (res - WAIT_OBJECT_0);
+       else if (res >= WAIT_ABANDONED_0 && res <= WAIT_ABANDONED_0 + numobjects - 1)
+               return MONO_W32HANDLE_WAIT_RET_ABANDONED_0 + (res - WAIT_ABANDONED_0);
+       else if (res == WAIT_IO_COMPLETION)
+               return MONO_W32HANDLE_WAIT_RET_ALERTED;
+       else if (res == WAIT_TIMEOUT)
+               return MONO_W32HANDLE_WAIT_RET_TIMEOUT;
+       else if (res == WAIT_FAILED)
+               return MONO_W32HANDLE_WAIT_RET_FAILED;
+       else
+               g_error ("%s: unknown res value %d", __func__, res);
+}
+#endif
+
+
 #endif /* _MONO_METADATA_W32HANDLE_H_ */