Moving BSTR conv to native code in SecureStringToBSTR.
[mono.git] / mono / metadata / mono-hash.c
index 63a6b680c0bb0056c6e70639847ce34886a43aa5..075c62f129bbd06f19442241c2ee0777aca36c8b 100644 (file)
@@ -30,8 +30,9 @@
 #include <math.h>
 #include <glib.h>
 #include "mono-hash.h"
-#include "metadata/gc-internal.h"
+#include "metadata/gc-internals.h"
 #include <mono/utils/checked-build.h>
+#include <mono/utils/mono-threads-coop.h>
 
 #ifdef HAVE_BOEHM_GC
 #define mg_new0(type,n)  ((type *) GC_MALLOC(sizeof(type) * (n)))
@@ -173,7 +174,7 @@ typedef struct {
 static void*
 do_rehash (void *_data)
 {
-       RehashData *data = _data;
+       RehashData *data = (RehashData *)_data;
        MonoGHashTable *hash = data->hash;
        int current_size, i;
        Slot **table;
@@ -219,12 +220,13 @@ rehash (MonoGHashTable *hash)
        data.new_size = g_spaced_primes_closest (hash->in_use);
        data.table = mg_new0 (Slot *, data.new_size);
 
-#ifdef USE_COOP_GC
-       /* We cannot be preempted */
-       old_table = do_rehash (&data);
-#else
-       old_table = mono_gc_invoke_with_gc_lock (do_rehash, &data);
-#endif
+       if (!mono_threads_is_coop_enabled ()) {
+               old_table = mono_gc_invoke_with_gc_lock (do_rehash, &data);
+       } else {
+               /* We cannot be preempted */
+               old_table = do_rehash (&data);
+       }
+
        mg_free (old_table);
 }
 
@@ -424,17 +426,17 @@ mono_g_hash_table_insert_replace (MonoGHashTable *hash, gpointer key, gpointer v
                        if (replace){
                                if (hash->key_destroy_func != NULL)
                                        (*hash->key_destroy_func)(s->key);
-                               s->key = key;
+                               s->key = (MonoObject *)key;
                        }
                        if (hash->value_destroy_func != NULL)
                                (*hash->value_destroy_func) (s->value);
-                       s->value = value;
+                       s->value = (MonoObject *)value;
                        return;
                }
        }
        s = new_slot (hash);
-       s->key = key;
-       s->value = value;
+       s->key = (MonoObject *)key;
+       s->value = (MonoObject *)value;
        s->next = hash->table [hashcode];
        hash->table [hashcode] = s;
        hash->in_use++;