Move hazard pointer and small_id code to utils/hazard-pointer.
[mono.git] / mono / utils / hazard-pointer.h
1 /*
2  * hazard-pointer.h: Hazard pointer related code.
3  *
4  * (C) Copyright 2011 Novell, Inc
5  */
6 #ifndef __MONO_HAZARD_POINTER_H__
7 #define __MONO_HAZARD_POINTER_H__
8
9 #include <glib.h>
10 #include <mono/metadata/object-internals.h>
11 #include <mono/utils/mono-compiler.h>
12
13 typedef struct {
14         gpointer hazard_pointers [2];
15 } MonoThreadHazardPointers;
16
17 typedef void (*MonoHazardousFreeFunc) (gpointer p);
18
19 void mono_thread_hazardous_free_or_queue (gpointer p, MonoHazardousFreeFunc free_func) MONO_INTERNAL;
20 void mono_thread_hazardous_try_free_all (void) MONO_INTERNAL;
21 MonoThreadHazardPointers* mono_hazard_pointer_get (void) MONO_INTERNAL;
22
23 #define mono_hazard_pointer_set(hp,i,v) \
24         do { g_assert ((i) == 0 || (i) == 1); \
25                 (hp)->hazard_pointers [(i)] = (v); \
26                 mono_memory_write_barrier (); \
27         } while (0)
28
29 #define mono_hazard_pointer_get_val(hp,i)       \
30         ((hp)->hazard_pointers [(i)])
31
32 #define mono_hazard_pointer_clear(hp,i) \
33         do { g_assert ((i) == 0 || (i) == 1); \
34                 (hp)->hazard_pointers [(i)] = NULL; \
35         } while (0)
36
37
38 void mono_thread_small_id_free (int id) MONO_INTERNAL;
39 int mono_thread_small_id_alloc (MonoInternalThread *thread) MONO_INTERNAL;
40
41 void mono_thread_smr_init (void) MONO_INTERNAL;
42 void mono_thread_smr_cleanup (void) MONO_INTERNAL;
43 #endif /*__MONO_HAZARD_POINTER_H__*/