[sgen] Separate header for the hash table.
authorMark Probst <mark.probst@gmail.com>
Tue, 18 Sep 2012 13:17:27 +0000 (15:17 +0200)
committerMark Probst <mark.probst@gmail.com>
Wed, 3 Oct 2012 16:22:31 +0000 (18:22 +0200)
This is so that we can use the hash table more easily in the
mobile-master branch which doesn't yet have the hash table factored
out.

mono/metadata/sgen-bridge.c
mono/metadata/sgen-gc.c
mono/metadata/sgen-gc.h
mono/metadata/sgen-hash-table.c
mono/metadata/sgen-hash-table.h [new file with mode: 0644]
mono/metadata/sgen-pinning-stats.c

index be2cbf4db40bd2180fe47fa8949759991b84848e..a0780edc688ab7dc9e17e3fe0ca3a7dd79f8c558 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "sgen-gc.h"
 #include "sgen-bridge.h"
+#include "sgen-hash-table.h"
 #include "utils/mono-logger-internal.h"
 #include "utils/mono-time.h"
 
index b32e70d19c5310fd61cc8b63e1af8c6d516c03ef..c8618d9050aa4b2e24583c6e48bbd1a1b65eb72d 100644 (file)
 #include "metadata/sgen-archdep.h"
 #include "metadata/sgen-bridge.h"
 #include "metadata/sgen-memory-governor.h"
+#include "metadata/sgen-hash-table.h"
 #include "metadata/mono-gc.h"
 #include "metadata/method-builder.h"
 #include "metadata/profiler-private.h"
index e3b9dfc9e2039b74c2a63d3c7924d40f7cee1dbe..64bcffe26ec4ca8c16bc1c95a7937fa727e9f388 100644 (file)
@@ -857,67 +857,6 @@ void sgen_nursery_alloc_prepare_for_major (void) MONO_INTERNAL;
 char* sgen_alloc_for_promotion (char *obj, size_t objsize, gboolean has_references) MONO_INTERNAL;
 char* sgen_par_alloc_for_promotion (char *obj, size_t objsize, gboolean has_references) MONO_INTERNAL;
 
-/* hash tables */
-
-typedef struct _SgenHashTableEntry SgenHashTableEntry;
-struct _SgenHashTableEntry {
-       SgenHashTableEntry *next;
-       gpointer key;
-       char data [MONO_ZERO_LEN_ARRAY]; /* data is pointer-aligned */
-};
-
-typedef struct {
-       int table_mem_type;
-       int entry_mem_type;
-       size_t data_size;
-       GHashFunc hash_func;
-       GEqualFunc equal_func;
-       SgenHashTableEntry **table;
-       guint size;
-       guint num_entries;
-} SgenHashTable;
-
-#define SGEN_HASH_TABLE_INIT(table_type,entry_type,data_size,hash_func,equal_func)     { (table_type), (entry_type), (data_size), (hash_func), (equal_func), NULL, 0, 0 }
-#define SGEN_HASH_TABLE_ENTRY_SIZE(data_size)                  ((data_size) + sizeof (SgenHashTableEntry*) + sizeof (gpointer))
-
-gpointer sgen_hash_table_lookup (SgenHashTable *table, gpointer key) MONO_INTERNAL;
-gboolean sgen_hash_table_replace (SgenHashTable *table, gpointer key, gpointer new_value, gpointer old_value) MONO_INTERNAL;
-gboolean sgen_hash_table_set_value (SgenHashTable *table, gpointer key, gpointer new_value, gpointer old_value) MONO_INTERNAL;
-gboolean sgen_hash_table_set_key (SgenHashTable *hash_table, gpointer old_key, gpointer new_key) MONO_INTERNAL;
-gboolean sgen_hash_table_remove (SgenHashTable *table, gpointer key, gpointer data_return) MONO_INTERNAL;
-
-void sgen_hash_table_clean (SgenHashTable *table) MONO_INTERNAL;
-
-#define sgen_hash_table_num_entries(h) ((h)->num_entries)
-
-#define SGEN_HASH_TABLE_FOREACH(h,k,v) do {                            \
-               SgenHashTable *__hash_table = (h);                      \
-               SgenHashTableEntry **__table = __hash_table->table;     \
-               guint __i;                                              \
-               for (__i = 0; __i < (h)->size; ++__i) {                 \
-                       SgenHashTableEntry **__iter, **__next;                  \
-                       for (__iter = &__table [__i]; *__iter; __iter = __next) {       \
-                               SgenHashTableEntry *__entry = *__iter;  \
-                               __next = &__entry->next;        \
-                               (k) = __entry->key;                     \
-                               (v) = (gpointer)__entry->data;
-
-/* The loop must be continue'd after using this! */
-#define SGEN_HASH_TABLE_FOREACH_REMOVE(free)   do {                    \
-               *__iter = *__next;      \
-               __next = __iter;        \
-               --__hash_table->num_entries;                            \
-               if ((free))                                             \
-                       sgen_free_internal (__entry, __hash_table->entry_mem_type); \
-       } while (0)
-
-#define SGEN_HASH_TABLE_FOREACH_SET_KEY(k)     ((__entry)->key = (k))
-
-#define SGEN_HASH_TABLE_FOREACH_END                                    \
-                       }                                               \
-               }                                                       \
-       } while (0)
-
 /* TLS Data */
 
 extern MonoNativeTlsKey thread_info_key;
index 906b534757426fff22553f6797c651e19b1b64b1..7e2a8e49de30b0b95d8718acfe519e3cf3396ec2 100644 (file)
@@ -26,6 +26,7 @@
 #ifdef HAVE_SGEN_GC
 
 #include <mono/metadata/sgen-gc.h>
+#include <mono/metadata/sgen-hash-table.h>
 
 static void
 rehash (SgenHashTable *hash_table)
diff --git a/mono/metadata/sgen-hash-table.h b/mono/metadata/sgen-hash-table.h
new file mode 100644 (file)
index 0000000..4faa3a6
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef __MONO_SGENHASHTABLE_H__
+#define __MONO_SGENHASHTABLE_H__
+
+#include "config.h"
+
+#ifdef HAVE_SGEN_GC
+
+#include <glib.h>
+
+/* hash tables */
+
+typedef struct _SgenHashTableEntry SgenHashTableEntry;
+struct _SgenHashTableEntry {
+       SgenHashTableEntry *next;
+       gpointer key;
+       char data [MONO_ZERO_LEN_ARRAY]; /* data is pointer-aligned */
+};
+
+typedef struct {
+       int table_mem_type;
+       int entry_mem_type;
+       size_t data_size;
+       GHashFunc hash_func;
+       GEqualFunc equal_func;
+       SgenHashTableEntry **table;
+       guint size;
+       guint num_entries;
+} SgenHashTable;
+
+#define SGEN_HASH_TABLE_INIT(table_type,entry_type,data_size,hash_func,equal_func)     { (table_type), (entry_type), (data_size), (hash_func), (equal_func), NULL, 0, 0 }
+#define SGEN_HASH_TABLE_ENTRY_SIZE(data_size)                  ((data_size) + sizeof (SgenHashTableEntry*) + sizeof (gpointer))
+
+gpointer sgen_hash_table_lookup (SgenHashTable *table, gpointer key) MONO_INTERNAL;
+gboolean sgen_hash_table_replace (SgenHashTable *table, gpointer key, gpointer new_value, gpointer old_value) MONO_INTERNAL;
+gboolean sgen_hash_table_set_value (SgenHashTable *table, gpointer key, gpointer new_value, gpointer old_value) MONO_INTERNAL;
+gboolean sgen_hash_table_set_key (SgenHashTable *hash_table, gpointer old_key, gpointer new_key) MONO_INTERNAL;
+gboolean sgen_hash_table_remove (SgenHashTable *table, gpointer key, gpointer data_return) MONO_INTERNAL;
+
+void sgen_hash_table_clean (SgenHashTable *table) MONO_INTERNAL;
+
+#define sgen_hash_table_num_entries(h) ((h)->num_entries)
+
+#define SGEN_HASH_TABLE_FOREACH(h,k,v) do {                            \
+               SgenHashTable *__hash_table = (h);                      \
+               SgenHashTableEntry **__table = __hash_table->table;     \
+               guint __i;                                              \
+               for (__i = 0; __i < (h)->size; ++__i) {                 \
+                       SgenHashTableEntry **__iter, **__next;                  \
+                       for (__iter = &__table [__i]; *__iter; __iter = __next) {       \
+                               SgenHashTableEntry *__entry = *__iter;  \
+                               __next = &__entry->next;        \
+                               (k) = __entry->key;                     \
+                               (v) = (gpointer)__entry->data;
+
+/* The loop must be continue'd after using this! */
+#define SGEN_HASH_TABLE_FOREACH_REMOVE(free)   do {                    \
+               *__iter = *__next;      \
+               __next = __iter;        \
+               --__hash_table->num_entries;                            \
+               if ((free))                                             \
+                       sgen_free_internal (__entry, __hash_table->entry_mem_type); \
+       } while (0)
+
+#define SGEN_HASH_TABLE_FOREACH_SET_KEY(k)     ((__entry)->key = (k))
+
+#define SGEN_HASH_TABLE_FOREACH_END                                    \
+                       }                                               \
+               }                                                       \
+       } while (0)
+
+#endif
+
+#endif
index 5191f42adf71ffe398780c81e993db5d506c9c6d..ae9249b718e48afe86eae3206f1fe7deb10c550c 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-pinning.h"
+#include "metadata/sgen-hash-table.h"
 
 
 typedef struct _PinStatAddress PinStatAddress;