3 * Generic thread typedef support (includes system-specific files)
6 * Dick Porter (dick@ximian.com)
9 * (C) Copyright 2002-2006 Novell, Inc
10 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13 #ifndef _MONO_METADATA_THREADS_TYPES_H_
14 #define _MONO_METADATA_THREADS_TYPES_H_
18 #include <mono/metadata/object.h>
19 #include "mono/metadata/handle.h"
20 #include "mono/utils/mono-compiler.h"
21 #include "mono/utils/mono-membar.h"
22 #include "mono/utils/mono-threads.h"
24 /* This is a copy of System.Threading.ThreadState */
26 ThreadState_Running = 0x00000000,
27 ThreadState_SuspendRequested = 0x00000002,
28 ThreadState_Background = 0x00000004,
29 ThreadState_Unstarted = 0x00000008,
30 ThreadState_Stopped = 0x00000010,
31 ThreadState_WaitSleepJoin = 0x00000020,
32 ThreadState_Suspended = 0x00000040,
33 ThreadState_AbortRequested = 0x00000080,
34 ThreadState_Aborted = 0x00000100
37 /* This is a copy of System.Threading.ApartmentState */
39 ThreadApartmentState_STA = 0x00000000,
40 ThreadApartmentState_MTA = 0x00000001,
41 ThreadApartmentState_Unknown = 0x00000002
42 } MonoThreadApartmentState;
45 MONO_THREAD_PRIORITY_LOWEST = 0,
46 MONO_THREAD_PRIORITY_BELOW_NORMAL = 1,
47 MONO_THREAD_PRIORITY_NORMAL = 2,
48 MONO_THREAD_PRIORITY_ABOVE_NORMAL = 3,
49 MONO_THREAD_PRIORITY_HIGHEST = 4,
52 #define SPECIAL_STATIC_NONE 0
53 #define SPECIAL_STATIC_THREAD 1
54 #define SPECIAL_STATIC_CONTEXT 2
56 typedef struct _MonoInternalThread MonoInternalThread;
58 typedef void (*MonoThreadCleanupFunc) (MonoNativeThreadId tid);
59 /* INFO has type MonoThreadInfo* */
60 typedef void (*MonoThreadNotifyPendingExcFunc) (gpointer info);
63 MONO_THREAD_CREATE_FLAGS_NONE = 0x0,
64 MONO_THREAD_CREATE_FLAGS_THREADPOOL = 0x1,
65 MONO_THREAD_CREATE_FLAGS_DEBUGGER = 0x2,
66 MONO_THREAD_CREATE_FLAGS_FORCE_CREATE = 0x4,
67 MONO_THREAD_CREATE_FLAGS_SMALL_STACK = 0x8,
68 } MonoThreadCreateFlags;
71 mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, MonoThreadCreateFlags flags, MonoError *error);
73 void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
75 void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread *this_obj);
76 gpointer ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this_obj, MonoObject *start);
77 void ves_icall_System_Threading_InternalThread_Thread_free_internal(MonoInternalThread *this_obj);
78 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms);
79 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms);
80 gint32 ves_icall_System_Threading_Thread_GetDomainID (void);
81 gboolean ves_icall_System_Threading_Thread_Yield (void);
82 MonoString* ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread *this_obj);
83 void ves_icall_System_Threading_Thread_SetName_internal (MonoInternalThread *this_obj, MonoString *name);
84 int ves_icall_System_Threading_Thread_GetPriority (MonoThread *this_obj);
85 void ves_icall_System_Threading_Thread_SetPriority (MonoThread *this_obj, int priority);
86 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentCulture (MonoInternalThread *this_obj);
87 void ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread *this_obj, MonoObject *culture);
88 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoInternalThread *this_obj);
89 void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *this_obj, MonoObject *culture);
90 MonoThread *ves_icall_System_Threading_Thread_GetCurrentThread (void);
92 gint32 ves_icall_System_Threading_WaitHandle_Wait_internal(gpointer *handles, gint32 numhandles, MonoBoolean waitall, gint32 ms, MonoError *error);
93 gint32 ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal, gpointer toWait, gint32 ms, MonoError *error);
95 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray *arr);
96 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr);
98 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
99 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
100 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
101 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
103 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value);
104 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value);
105 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value);
106 gpointer ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer *location, gpointer value);
107 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value);
108 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value);
110 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand);
111 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success(gint32 *location, gint32 value, gint32 comparand, MonoBoolean *success);
112 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand);
113 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand);
114 gpointer ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer *location, gpointer value, gpointer comparand);
115 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand);
116 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand);
117 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand);
118 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value);
120 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value);
121 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value);
122 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location);
124 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
125 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
127 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
128 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
130 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject *state);
131 void ves_icall_System_Threading_Thread_ResetAbort (MonoThread *this_obj);
132 MonoObject* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread *thread);
133 void ves_icall_System_Threading_Thread_Suspend (MonoThread *this_obj);
134 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread);
135 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread *thread, guint32 state);
136 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread *thread, guint32 state);
137 guint32 ves_icall_System_Threading_Thread_GetState (MonoInternalThread *thread);
139 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr);
140 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr);
141 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr);
142 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr);
143 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr);
144 void * ves_icall_System_Threading_Thread_VolatileReadObject (void *ptr);
145 double ves_icall_System_Threading_Thread_VolatileReadDouble (void *ptr);
146 float ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr);
148 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8);
149 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16);
150 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32);
151 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64);
152 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *);
153 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr, MonoObject *);
154 void ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float);
155 void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double);
157 gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr);
158 gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr);
159 gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr);
160 gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr);
161 void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr);
162 double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr);
163 float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr);
164 MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr);
166 void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8);
167 void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16);
168 void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32);
169 void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64);
170 void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *);
171 void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float);
172 void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double);
173 void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value);
175 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
176 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoThread *this_obj);
177 void ves_icall_System_Threading_Thread_SpinWait_nop (void);
180 mono_threads_register_app_context (MonoAppContext* ctx, MonoError *error);
182 mono_threads_release_app_context (MonoAppContext* ctx, MonoError *error);
184 void ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContextHandle ctx, MonoError *error);
185 void ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContextHandle ctx, MonoError *error);
187 MonoInternalThread *mono_thread_internal_current (void);
189 void mono_thread_internal_abort (MonoInternalThread *thread);
190 void mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread);
192 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
194 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
196 void mono_thread_internal_unhandled_exception (MonoObject* exc);
198 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
199 gboolean mono_thread_current_check_pending_interrupt (void);
201 void mono_thread_set_state (MonoInternalThread *thread, MonoThreadState state);
202 void mono_thread_clr_state (MonoInternalThread *thread, MonoThreadState state);
203 gboolean mono_thread_test_state (MonoInternalThread *thread, MonoThreadState test);
204 gboolean mono_thread_test_and_set_state (MonoInternalThread *thread, MonoThreadState test, MonoThreadState set);
206 void mono_thread_init_apartment_state (void);
207 void mono_thread_cleanup_apartment_state (void);
209 void mono_threads_set_shutting_down (void);
211 gunichar2* mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len);
213 MONO_API MonoException* mono_thread_get_undeniable_exception (void);
215 void mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean permanent, gboolean reset, MonoError *error);
217 void mono_thread_suspend_all_other_threads (void);
218 gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout);
220 void mono_thread_push_appdomain_ref (MonoDomain *domain);
221 void mono_thread_pop_appdomain_ref (void);
222 gboolean mono_thread_has_appdomain_ref (MonoThread *thread, MonoDomain *domain);
224 MonoException* mono_thread_request_interruption (mono_bool running_managed);
225 gboolean mono_thread_interruption_requested (void);
226 MonoException* mono_thread_interruption_checkpoint (void);
227 MonoException* mono_thread_force_interruption_checkpoint_noraise (void);
228 gint32* mono_thread_interruption_request_flag (void);
230 uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, uint32_t align, uintptr_t *bitmap, int numbits);
231 void* mono_get_special_static_data (uint32_t offset);
232 gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset);
234 MonoException* mono_thread_resume_interruption (gboolean exec);
235 void mono_threads_perform_thread_dump (void);
238 mono_thread_create_checked (MonoDomain *domain, gpointer func, gpointer arg, MonoError *error);
241 mono_thread_attach_full (MonoDomain *domain, gboolean force_attach);
243 /* Can't include utils/mono-threads.h because of the THREAD_INFO_TYPE wizardry */
244 void mono_threads_add_joinable_thread (gpointer tid);
245 void mono_threads_join_threads (void);
246 void mono_thread_join (gpointer tid);
248 void mono_thread_detach_internal (MonoInternalThread *thread);
250 void ves_icall_System_Threading_Thread_GetStackTraces (MonoArray **out_threads, MonoArray **out_stack_traces);
253 mono_threads_attach_coop (MonoDomain *domain, gpointer *dummy);
256 mono_threads_detach_coop (gpointer cookie, gpointer *dummy);
258 void mono_threads_begin_abort_protected_block (void);
259 gboolean mono_threads_end_abort_protected_block (void);
262 mono_thread_internal_current_is_attached (void);
265 mono_thread_internal_describe (MonoInternalThread *internal, GString *str);
268 mono_thread_internal_is_current (MonoInternalThread *internal);
270 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */