[bcl] Enable tests for the monodroid profile.
[mono.git] / mono / utils / hazard-pointer.h
1 /*
2  * hazard-pointer.h: Hazard pointer related code.
3  *
4  * (C) Copyright 2011 Novell, Inc
5  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
6  */
7 #ifndef __MONO_HAZARD_POINTER_H__
8 #define __MONO_HAZARD_POINTER_H__
9
10 #include <glib.h>
11 #include <mono/utils/mono-compiler.h>
12 #include <mono/utils/mono-membar.h>
13 #include <mono/utils/mono-publib.h>
14
15 #define HAZARD_POINTER_COUNT 3
16
17 typedef struct {
18         gpointer hazard_pointers [HAZARD_POINTER_COUNT];
19 } MonoThreadHazardPointers;
20
21 typedef void (*MonoHazardousFreeFunc) (gpointer p);
22
23 MONO_API gboolean mono_thread_hazardous_try_free (gpointer p, MonoHazardousFreeFunc free_func);
24 MONO_API void mono_thread_hazardous_queue_free (gpointer p, MonoHazardousFreeFunc free_func);
25
26 MONO_API void mono_thread_hazardous_try_free_all (void);
27 void mono_thread_hazardous_try_free_some (void);
28 MONO_API MonoThreadHazardPointers* mono_hazard_pointer_get (void);
29 gpointer mono_get_hazardous_pointer (gpointer volatile *pp, MonoThreadHazardPointers *hp, int hazard_index);
30
31 #define mono_hazard_pointer_set(hp,i,v) \
32         do { g_assert ((i) >= 0 && (i) < HAZARD_POINTER_COUNT); \
33                 (hp)->hazard_pointers [(i)] = (v); \
34                 mono_memory_write_barrier (); \
35         } while (0)
36
37 #define mono_hazard_pointer_get_val(hp,i)       \
38         ((hp)->hazard_pointers [(i)])
39
40 #define mono_hazard_pointer_clear(hp,i) \
41         do { g_assert ((i) >= 0 && (i) < HAZARD_POINTER_COUNT); \
42                 mono_memory_write_barrier (); \
43                 (hp)->hazard_pointers [(i)] = NULL; \
44         } while (0)
45
46
47 void mono_thread_small_id_free (int id);
48 int mono_thread_small_id_alloc (void);
49
50 int mono_hazard_pointer_save_for_signal_handler (void);
51 void mono_hazard_pointer_restore_for_signal_handler (int small_id);
52
53 typedef void (*MonoHazardFreeQueueSizeCallback)(size_t size);
54 void mono_hazard_pointer_install_free_queue_size_callback (MonoHazardFreeQueueSizeCallback cb);
55
56 void mono_thread_smr_init (void);
57 void mono_thread_smr_cleanup (void);
58 #endif /*__MONO_HAZARD_POINTER_H__*/