2008-03-24 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / threads-types.h
1 /*
2  * threads-types.h: Generic thread typedef support (includes
3  * system-specific files)
4  *
5  * Author:
6  *      Dick Porter (dick@ximian.com)
7  *
8  * (C) 2001 Ximian, Inc
9  * (C) Copyright 2002-2006 Novell, Inc
10  */
11
12 #ifndef _MONO_METADATA_THREADS_TYPES_H_
13 #define _MONO_METADATA_THREADS_TYPES_H_
14
15 #include <glib.h>
16
17 #include <mono/io-layer/io-layer.h>
18 #include "mono/utils/mono-compiler.h"
19
20 /* This is a copy of System.Threading.ThreadState */
21 typedef enum {
22         ThreadState_Running = 0x00000000,
23         ThreadState_StopRequested = 0x00000001,
24         ThreadState_SuspendRequested = 0x00000002,
25         ThreadState_Background = 0x00000004,
26         ThreadState_Unstarted = 0x00000008,
27         ThreadState_Stopped = 0x00000010,
28         ThreadState_WaitSleepJoin = 0x00000020,
29         ThreadState_Suspended = 0x00000040,
30         ThreadState_AbortRequested = 0x00000080,
31         ThreadState_Aborted = 0x00000100
32 } MonoThreadState; 
33
34 /* This is a copy of System.Threading.ApartmentState */
35 typedef enum {
36         ThreadApartmentState_STA = 0x00000000,
37         ThreadApartmentState_MTA = 0x00000001,
38         ThreadApartmentState_Unknown = 0x00000002
39 } MonoThreadApartmentState;
40
41 typedef void (*MonoThreadNotifyPendingExcFunc) (void);
42
43 #define SPECIAL_STATIC_NONE 0
44 #define SPECIAL_STATIC_THREAD 1
45 #define SPECIAL_STATIC_CONTEXT 2
46
47 void mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread) MONO_INTERNAL;
48
49 HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this_obj, MonoObject *start) MONO_INTERNAL;
50 void ves_icall_System_Threading_Thread_Thread_init(MonoThread *this_obj) MONO_INTERNAL;
51 void ves_icall_System_Threading_Thread_Thread_free_internal(MonoThread *this_obj, HANDLE thread) MONO_INTERNAL;
52 void ves_icall_System_Threading_Thread_Sleep_internal(int ms) MONO_INTERNAL;
53 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms, HANDLE thread) MONO_INTERNAL;
54 gint32 ves_icall_System_Threading_Thread_GetDomainID (void) MONO_INTERNAL;
55 MonoString* ves_icall_System_Threading_Thread_GetName_internal (MonoThread *this_obj) MONO_INTERNAL;
56 void ves_icall_System_Threading_Thread_SetName_internal (MonoThread *this_obj, MonoString *name) MONO_INTERNAL;
57 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentCulture (MonoThread *this_obj) MONO_INTERNAL;
58 MonoArray* ves_icall_System_Threading_Thread_GetSerializedCurrentCulture (MonoThread *this_obj) MONO_INTERNAL;
59 void ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread *this_obj, MonoObject *culture) MONO_INTERNAL;
60 void ves_icall_System_Threading_Thread_SetSerializedCurrentCulture (MonoThread *this_obj, MonoArray *arr) MONO_INTERNAL;
61 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoThread *this_obj) MONO_INTERNAL;
62 MonoArray* ves_icall_System_Threading_Thread_GetSerializedCurrentUICulture (MonoThread *this_obj) MONO_INTERNAL;
63 void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *this_obj, MonoObject *culture) MONO_INTERNAL;
64 void ves_icall_System_Threading_Thread_SetSerializedCurrentUICulture (MonoThread *this_obj, MonoArray *arr) MONO_INTERNAL;
65 HANDLE ves_icall_System_Threading_Mutex_CreateMutex_internal(MonoBoolean owned, MonoString *name, MonoBoolean *created) MONO_INTERNAL;
66 MonoBoolean ves_icall_System_Threading_Mutex_ReleaseMutex_internal (HANDLE handle ) MONO_INTERNAL;
67 HANDLE ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name, gint32 rights, gint32 *error) MONO_INTERNAL;
68 HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, MonoBoolean *created) MONO_INTERNAL;
69 gint32 ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, MonoBoolean *fail) MONO_INTERNAL;
70 HANDLE ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error) MONO_INTERNAL;
71 HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created) MONO_INTERNAL;
72 gboolean ves_icall_System_Threading_Events_SetEvent_internal (HANDLE handle) MONO_INTERNAL;
73 gboolean ves_icall_System_Threading_Events_ResetEvent_internal (HANDLE handle) MONO_INTERNAL;
74 void ves_icall_System_Threading_Events_CloseEvent_internal (HANDLE handle) MONO_INTERNAL;
75 HANDLE ves_icall_System_Threading_Events_OpenEvent_internal (MonoString *name, gint32 rights, gint32 *error) MONO_INTERNAL;
76
77 gboolean ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext) MONO_INTERNAL;
78 gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext) MONO_INTERNAL;
79 gboolean ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject *this_obj, HANDLE handle, gint32 ms, gboolean exitContext) MONO_INTERNAL;
80
81 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location) MONO_INTERNAL;
82 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location) MONO_INTERNAL;
83 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location) MONO_INTERNAL;
84 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location) MONO_INTERNAL;
85
86 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value) MONO_INTERNAL;
87 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value) MONO_INTERNAL;
88 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value) MONO_INTERNAL;
89 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value) MONO_INTERNAL;
90 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value) MONO_INTERNAL;
91
92 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand) MONO_INTERNAL;
93 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand) MONO_INTERNAL;
94 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand) MONO_INTERNAL;
95 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand) MONO_INTERNAL;
96 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand) MONO_INTERNAL;
97 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand) MONO_INTERNAL;
98 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value) MONO_INTERNAL;
99
100 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value) MONO_INTERNAL;
101 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value) MONO_INTERNAL;
102 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location) MONO_INTERNAL;
103
104 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location) MONO_INTERNAL;
105 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location) MONO_INTERNAL;
106
107 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location) MONO_INTERNAL;
108 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location) MONO_INTERNAL;
109
110 void ves_icall_System_Threading_Thread_Abort (MonoThread *thread, MonoObject *state) MONO_INTERNAL;
111 void ves_icall_System_Threading_Thread_ResetAbort (void) MONO_INTERNAL;
112 void ves_icall_System_Threading_Thread_Suspend (MonoThread *thread) MONO_INTERNAL;
113 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread) MONO_INTERNAL;
114 void ves_icall_System_Threading_Thread_ClrState (MonoThread *thread, guint32 state) MONO_INTERNAL;
115 void ves_icall_System_Threading_Thread_SetState (MonoThread *thread, guint32 state) MONO_INTERNAL;
116 guint32 ves_icall_System_Threading_Thread_GetState (MonoThread *thread) MONO_INTERNAL;
117
118 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr) MONO_INTERNAL;
119 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr) MONO_INTERNAL;
120 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr) MONO_INTERNAL;
121 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr) MONO_INTERNAL;
122 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr) MONO_INTERNAL;
123
124 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8) MONO_INTERNAL;
125 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16) MONO_INTERNAL;
126 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32) MONO_INTERNAL;
127 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64) MONO_INTERNAL;
128 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *) MONO_INTERNAL;
129
130 void ves_icall_System_Threading_Thread_MemoryBarrier (void) MONO_INTERNAL;
131 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoThread *this_obj) MONO_INTERNAL;
132 void ves_icall_System_Threading_Thread_SpinWait_internal (gint32) MONO_INTERNAL;
133
134 void mono_alloc_special_static_data_free (GHashTable *special_static_fields) MONO_INTERNAL;
135 void mono_thread_free_local_slot_values (int slot, MonoBoolean thread_local) MONO_INTERNAL;
136 void mono_thread_current_check_pending_interrupt (void) MONO_INTERNAL;
137 void mono_thread_get_stack_bounds (guint8 **staddr, size_t *stsize) MONO_INTERNAL;
138
139 void mono_thread_set_state (MonoThread *thread, MonoThreadState state) MONO_INTERNAL;
140 void mono_thread_clr_state (MonoThread *thread, MonoThreadState state) MONO_INTERNAL;
141 gboolean mono_thread_test_state (MonoThread *thread, MonoThreadState test) MONO_INTERNAL;
142
143 void mono_thread_init_apartment_state (void) MONO_INTERNAL;
144 void mono_thread_cleanup_apartment_state (void) MONO_INTERNAL;
145
146 gboolean mono_threads_set_shutting_down (void) MONO_INTERNAL;
147 gboolean mono_threads_is_shutting_down (void) MONO_INTERNAL;
148
149 MonoException* mono_thread_get_undeniable_exception (void);
150
151 MonoException* mono_thread_get_and_clear_pending_exception (void) MONO_INTERNAL;
152
153 typedef struct {
154         gpointer hazard_pointers [2];
155 } MonoThreadHazardPointers;
156
157 typedef void (*MonoHazardousFreeFunc) (gpointer p);
158
159 void mono_thread_hazardous_free_or_queue (gpointer p, MonoHazardousFreeFunc free_func);
160
161 MonoThreadHazardPointers* mono_hazard_pointer_get (void);
162
163 void mono_threads_install_notify_pending_exc (MonoThreadNotifyPendingExcFunc func) MONO_INTERNAL;
164
165 #define mono_hazard_pointer_set(hp,i,v) \
166         do { g_assert ((i) == 0 || (i) == 1); \
167                 (hp)->hazard_pointers [(i)] = (v); \
168                 mono_memory_write_barrier (); \
169         } while (0)
170 #define mono_hazard_pointer_clear(hp,i) \
171         do { g_assert ((i) == 0 || (i) == 1); \
172                 (hp)->hazard_pointers [(i)] = NULL; \
173         } while (0)
174
175 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */