[utils/hp] Remove HazardFreeLocking and HazardFreeContext enums.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 19 Jul 2016 02:43:21 +0000 (04:43 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 30 Aug 2016 08:01:02 +0000 (10:01 +0200)
These are no longer useful in the new hazard free API.

mono/unit-tests/test-mono-linked-list-set.c
mono/utils/hazard-pointer.c
mono/utils/hazard-pointer.h
mono/utils/mono-linked-list-set.c
mono/utils/mono-linked-list-set.h
mono/utils/mono-threads.c

index 3841581e0bb02fd61fe9f407dbcbef8891a0cea9..a5e01ebe09ec6e5f913e1ad936c822596d39ecde 100644 (file)
@@ -74,11 +74,11 @@ worker (void *arg)
                        break;
                case STATE_OUT:
                        if (InterlockedCompareExchange (&nodes [i].state, STATE_BUSY, STATE_OUT) == STATE_OUT) {
-                               result = mono_lls_find (&lls, hp, i, HAZARD_FREE_SAFE_CTX);
+                               result = mono_lls_find (&lls, hp, i);
                                assert (!result);
                                mono_hazard_pointer_clear_all (hp, -1);
 
-                               result = mono_lls_insert (&lls, hp, &nodes [i].node, HAZARD_FREE_SAFE_CTX);
+                               result = mono_lls_insert (&lls, hp, &nodes [i].node);
                                mono_hazard_pointer_clear_all (hp, -1);
 
                                assert (nodes [i].state == STATE_BUSY);
@@ -89,12 +89,12 @@ worker (void *arg)
                        break;
                case STATE_IN:
                        if (InterlockedCompareExchange (&nodes [i].state, STATE_BUSY, STATE_IN) == STATE_IN) {
-                               result = mono_lls_find (&lls, hp, i, HAZARD_FREE_SAFE_CTX);
+                               result = mono_lls_find (&lls, hp, i);
                                assert (result);
                                assert (mono_hazard_pointer_get_val (hp, 1) == &nodes [i].node);
                                mono_hazard_pointer_clear_all (hp, -1);
 
-                               result = mono_lls_remove (&lls, hp, &nodes [i].node, HAZARD_FREE_SAFE_CTX);
+                               result = mono_lls_remove (&lls, hp, &nodes [i].node);
                                mono_hazard_pointer_clear_all (hp, -1);
 
                                ++thread_data->num_removes;
@@ -126,7 +126,7 @@ main (int argc, char *argv [])
 
        mono_threads_init (&thread_callbacks, 0);
 
-       mono_lls_init (&lls, free_node, HAZARD_FREE_NO_LOCK);
+       mono_lls_init (&lls, free_node);
 
        for (i = 0; i < N; ++i) {
                nodes [i].node.key = i;
index efe6b649b3039450cbdc176f0373cd55754a69be..0ae480cc1be999dea8086387289d554353be5172 100644 (file)
@@ -29,7 +29,6 @@
 typedef struct {
        gpointer p;
        MonoHazardousFreeFunc free_func;
-       HazardFreeLocking locking;
 } DelayedFreeItem;
 
 /* The hazard table */
@@ -288,7 +287,7 @@ mono_hazard_pointer_restore_for_signal_handler (int small_id)
 }
 
 static gboolean
-try_free_delayed_free_item (HazardFreeContext context)
+try_free_delayed_free_item (void)
 {
        DelayedFreeItem item;
        gboolean popped = mono_lock_free_array_queue_pop (&delayed_free_queue, &item);
@@ -296,8 +295,7 @@ try_free_delayed_free_item (HazardFreeContext context)
        if (!popped)
                return FALSE;
 
-       if ((context == HAZARD_FREE_ASYNC_CTX && item.locking == HAZARD_FREE_MAY_LOCK) ||
-           (is_pointer_hazardous (item.p))) {
+       if (is_pointer_hazardous (item.p)) {
                mono_lock_free_array_queue_push (&delayed_free_queue, &item);
                return FALSE;
        }
@@ -348,7 +346,7 @@ mono_thread_hazardous_try_free (gpointer p, MonoHazardousFreeFunc free_func)
 void
 mono_thread_hazardous_queue_free (gpointer p, MonoHazardousFreeFunc free_func)
 {
-       DelayedFreeItem item = { p, free_func, HAZARD_FREE_MAY_LOCK };
+       DelayedFreeItem item = { p, free_func };
 
        InterlockedIncrement (&hazardous_pointer_count);
 
@@ -369,7 +367,7 @@ mono_hazard_pointer_install_free_queue_size_callback (MonoHazardFreeQueueSizeCal
 void
 mono_thread_hazardous_try_free_all (void)
 {
-       while (try_free_delayed_free_item (HAZARD_FREE_SAFE_CTX))
+       while (try_free_delayed_free_item ())
                ;
 }
 
@@ -378,7 +376,7 @@ mono_thread_hazardous_try_free_some (void)
 {
        int i;
        for (i = 0; i < 10; ++i)
-               try_free_delayed_free_item (HAZARD_FREE_SAFE_CTX);
+               try_free_delayed_free_item ();
 }
 
 void
index 0102c103f7629785b1eb8c231a88f86269dbc56c..d7c82919d6eaff22003d19b3a21faa0109dcccaf 100644 (file)
@@ -20,16 +20,6 @@ typedef struct {
 
 typedef void (*MonoHazardousFreeFunc) (gpointer p);
 
-typedef enum {
-       HAZARD_FREE_MAY_LOCK,
-       HAZARD_FREE_NO_LOCK,
-} HazardFreeLocking;
-
-typedef enum {
-       HAZARD_FREE_SAFE_CTX,
-       HAZARD_FREE_ASYNC_CTX,
-} HazardFreeContext;
-
 MONO_API gboolean mono_thread_hazardous_try_free (gpointer p, MonoHazardousFreeFunc free_func);
 void mono_thread_hazardous_queue_free (gpointer p, MonoHazardousFreeFunc free_func);
 
index f076034da21d7f0dc9ff4aa6c3e1e535f20c8ef5..a3ce43eb64139c3ca9950a2e3c2d82ccb96e4b09 100644 (file)
@@ -56,28 +56,21 @@ get_hazardous_pointer_with_mask (gpointer volatile *pp, MonoThreadHazardPointers
 /*
 Initialize @list and will use @free_node_func to release memory.
 If @free_node_func is null the caller is responsible for releasing node memory.
-If @free_node_func may lock, @free_node_func_locking must be
-HAZARD_FREE_MAY_LOCK; otherwise, HAZARD_FREE_NO_LOCK. It is ignored if
-@free_node_func is null.
 */
 void
-mono_lls_init (MonoLinkedListSet *list, void (*free_node_func)(void *), HazardFreeLocking free_node_func_locking)
+mono_lls_init (MonoLinkedListSet *list, void (*free_node_func)(void *))
 {
        list->head = NULL;
        list->free_node_func = free_node_func;
-       list->locking = free_node_func_locking;
 }
 
 /*
 Search @list for element with key @key.
-@context specifies whether the function is being called from a lock-free (i.e.
-signal handler or world stopped) context. It is only relevant if a node free
-function was given.
 The nodes next, cur and prev are returned in @hp.
 Returns true if a node with key @key was found.
 */
 gboolean
-mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t key, HazardFreeContext context)
+mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t key)
 {
        MonoLinkedListSetNode *cur, *next;
        MonoLinkedListSetNode **prev;
@@ -137,15 +130,12 @@ try_again:
 
 /*
 Insert @value into @list.
-@context specifies whether the function is being called from a lock-free (i.e.
-signal handler or world stopped) context. It is only relevant if a node free
-function was given.
 The nodes value, cur and prev are returned in @hp.
 Return true if @value was inserted by this call. If it returns FALSE, it's the caller
 resposibility to release memory.
 */
 gboolean
-mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value, HazardFreeContext context)
+mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value)
 {
        MonoLinkedListSetNode *cur, **prev;
        /*We must do a store barrier before inserting 
@@ -153,7 +143,7 @@ mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
        mono_memory_barrier ();
 
        while (1) {
-               if (mono_lls_find (list, hp, value->key, context))
+               if (mono_lls_find (list, hp, value->key))
                        return FALSE;
                cur = (MonoLinkedListSetNode *) mono_hazard_pointer_get_val (hp, 1);
                prev = (MonoLinkedListSetNode **) mono_hazard_pointer_get_val (hp, 2);
@@ -169,18 +159,15 @@ mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
 
 /*
 Search @list for element with key @key and remove it.
-@context specifies whether the function is being called from a lock-free (i.e.
-signal handler or world stopped) context. It is only relevant if a node free
-function was given.
 The nodes next, cur and prev are returned in @hp
 Returns true if @value was removed by this call.
 */
 gboolean
-mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value, HazardFreeContext context)
+mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value)
 {
        MonoLinkedListSetNode *cur, **prev, *next;
        while (1) {
-               if (!mono_lls_find (list, hp, value->key, context))
+               if (!mono_lls_find (list, hp, value->key))
                        return FALSE;
 
                next = (MonoLinkedListSetNode *) mono_hazard_pointer_get_val (hp, 0);
@@ -200,7 +187,7 @@ mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
                        if (list->free_node_func)
                                mono_thread_hazardous_try_free (value, list->free_node_func);
                } else
-                       mono_lls_find (list, hp, value->key, context);
+                       mono_lls_find (list, hp, value->key);
                return TRUE;
        }
 }
index 947602f0c34e2177d3a829fd6863850208d24c6f..24678f005ca84a1a05bab9933eef4f628e25a841 100644 (file)
@@ -24,7 +24,6 @@ struct _MonoLinkedListSetNode {
 typedef struct {
        MonoLinkedListSetNode *head;
        void (*free_node_func)(void *);
-       HazardFreeLocking locking;
 } MonoLinkedListSet;
 
 
@@ -46,16 +45,16 @@ You must manually clean the hazard pointer table after using them.
 */
 
 void
-mono_lls_init (MonoLinkedListSet *list, void (*free_node_func)(void *), HazardFreeLocking free_node_func_locking);
+mono_lls_init (MonoLinkedListSet *list, void (*free_node_func)(void *));
 
 gboolean
-mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t key, HazardFreeContext context);
+mono_lls_find (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, uintptr_t key);
 
 gboolean
-mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value, HazardFreeContext context);
+mono_lls_insert (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value);
 
 gboolean
-mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value, HazardFreeContext context);
+mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLinkedListSetNode *value);
 
 gpointer
 get_hazardous_pointer_with_mask (gpointer volatile *pp, MonoThreadHazardPointers *hp, int hazard_index);
index 5add7fe0f86f32f82803d805762bd4d865e4d78e..980522621b264ca3709ab733d6e76928853a1fb4 100644 (file)
@@ -281,7 +281,7 @@ mono_thread_info_lookup (MonoNativeThreadId id)
 {
                MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
 
-       if (!mono_lls_find (&thread_list, hp, (uintptr_t)id, HAZARD_FREE_ASYNC_CTX)) {
+       if (!mono_lls_find (&thread_list, hp, (uintptr_t)id)) {
                mono_hazard_pointer_clear_all (hp, -1);
                return NULL;
        } 
@@ -295,7 +295,7 @@ mono_thread_info_insert (MonoThreadInfo *info)
 {
        MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
 
-       if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX)) {
+       if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info)) {
                mono_hazard_pointer_clear_all (hp, -1);
                return FALSE;
        } 
@@ -311,7 +311,7 @@ mono_thread_info_remove (MonoThreadInfo *info)
        gboolean res;
 
        THREADS_DEBUG ("removing info %p\n", info);
-       res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX);
+       res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info);
        mono_hazard_pointer_clear_all (hp, -1);
        return res;
 }
@@ -691,7 +691,7 @@ mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
        mono_os_sem_init (&global_suspend_semaphore, 1);
        mono_os_sem_init (&suspend_semaphore, 0);
 
-       mono_lls_init (&thread_list, NULL, HAZARD_FREE_NO_LOCK);
+       mono_lls_init (&thread_list, NULL);
        mono_thread_smr_init ();
        mono_threads_platform_init ();
        mono_threads_suspend_init ();