Fixed MSVC build by explicitly providing "ssize_t".
[mono.git] / mono / utils / mono-linked-list-set.c
index 3f34359f2731ae779c1b37a0a52f0068fe0d1db8..b7391962eaae5d35ab1e704801f7d36e533224aa 100644 (file)
@@ -16,8 +16,7 @@
 
 #include <mono/utils/mono-linked-list-set.h>
 
-/*atomics.*/
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/atomic.h>
 
 static inline gpointer
 mask (gpointer n, uintptr_t bit)
@@ -56,7 +55,8 @@ 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 is null the caller is responsible for releasing node memory.
+@free_node_func must be lock-free.  That implies that it cannot use malloc/free.
 */
 void
 mono_lls_init (MonoLinkedListSet *list, void (*free_node_func)(void *))
@@ -125,7 +125,7 @@ try_again:
                                mono_memory_write_barrier ();
                                mono_hazard_pointer_clear (hp, 1);
                                if (list->free_node_func)
-                                       mono_thread_hazardous_free_or_queue (cur, list->free_node_func);
+                                       mono_thread_hazardous_free_or_queue (cur, list->free_node_func, FALSE, TRUE);
                        } else
                                goto try_again;
                }
@@ -188,12 +188,12 @@ mono_lls_remove (MonoLinkedListSet *list, MonoThreadHazardPointers *hp, MonoLink
                        continue;
                /* The second CAS must happen before the first. */
                mono_memory_write_barrier ();
-               if (InterlockedCompareExchangePointer ((volatile gpointer*)prev, next, cur) == cur) {
+               if (InterlockedCompareExchangePointer ((volatile gpointer*)prev, mono_lls_pointer_unmask (next), cur) == cur) {
                        /* The CAS must happen before the hazard pointer clear. */
                        mono_memory_write_barrier ();
                        mono_hazard_pointer_clear (hp, 1);
                        if (list->free_node_func)
-                               mono_thread_hazardous_free_or_queue (value, list->free_node_func);
+                               mono_thread_hazardous_free_or_queue (value, list->free_node_func, FALSE, TRUE);
                } else
                        mono_lls_find (list, hp, value->key);
                return TRUE;