[w32handle] Fix deadlock on SignalAndWait (#4973)
[mono.git] / mono / metadata / w32handle.c
index d4fae9dd09e1543bca9224dce1aa1ab07e27cf39..f6862a9a7dba737452b39cb840286b84d52883c1 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * w32handle.c:  Generic and internal operations on handles
+/**
+ * \file
+ * Generic and internal operations on handles
  *
  * Author:
  *     Dick Porter (dick@ximian.com)
@@ -24,7 +25,7 @@
 
 #undef DEBUG_REFS
 
-#define SLOT_MAX               (1024 * 16)
+#define SLOT_MAX               (1024 * 32)
 
 /* must be a power of 2 */
 #define HANDLE_PER_SLOT        (256)
@@ -249,11 +250,6 @@ mono_w32handle_unlock_handle (gpointer handle)
        mono_w32handle_unref (handle);
 }
 
-/*
- * wapi_init:
- *
- *   Initialize the io-layer.
- */
 void
 mono_w32handle_init (void)
 {
@@ -482,6 +478,24 @@ gpointer mono_w32handle_new_fd (MonoW32HandleType type, int fd,
        return(GUINT_TO_POINTER(fd));
 }
 
+gboolean
+mono_w32handle_close (gpointer handle)
+{
+       if (handle == INVALID_HANDLE_VALUE)
+               return FALSE;
+       if (handle == (gpointer) 0 && mono_w32handle_get_type (handle) != MONO_W32HANDLE_CONSOLE) {
+               /* Problem: because we map file descriptors to the
+                * same-numbered handle we can't tell the difference
+                * between a bogus handle and the handle to stdin.
+                * Assume that it's the console handle if that handle
+                * exists... */
+               return FALSE;
+       }
+
+       mono_w32handle_unref (handle);
+       return TRUE;
+}
+
 gboolean
 mono_w32handle_lookup (gpointer handle, MonoW32HandleType type,
                              gpointer *handle_specific)
@@ -795,7 +809,7 @@ mono_w32handle_ops_signal (gpointer handle)
        type = handle_data->type;
 
        if (handle_ops[type] != NULL && handle_ops[type]->signal != NULL) {
-               handle_ops[type]->signal (handle);
+               handle_ops[type]->signal (handle, handle_data->specific);
        }
 }