2 * threads-types.h: Generic thread typedef support (includes
3 * 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/utils/mono-compiler.h"
20 #include "mono/utils/mono-membar.h"
21 #include "mono/utils/mono-threads.h"
23 /* This is a copy of System.Threading.ThreadState */
25 ThreadState_Running = 0x00000000,
26 ThreadState_SuspendRequested = 0x00000002,
27 ThreadState_Background = 0x00000004,
28 ThreadState_Unstarted = 0x00000008,
29 ThreadState_Stopped = 0x00000010,
30 ThreadState_WaitSleepJoin = 0x00000020,
31 ThreadState_Suspended = 0x00000040,
32 ThreadState_AbortRequested = 0x00000080,
33 ThreadState_Aborted = 0x00000100
36 /* This is a copy of System.Threading.ApartmentState */
38 ThreadApartmentState_STA = 0x00000000,
39 ThreadApartmentState_MTA = 0x00000001,
40 ThreadApartmentState_Unknown = 0x00000002
41 } MonoThreadApartmentState;
44 MONO_THREAD_PRIORITY_LOWEST = 0,
45 MONO_THREAD_PRIORITY_BELOW_NORMAL = 1,
46 MONO_THREAD_PRIORITY_NORMAL = 2,
47 MONO_THREAD_PRIORITY_ABOVE_NORMAL = 3,
48 MONO_THREAD_PRIORITY_HIGHEST = 4,
51 #define SPECIAL_STATIC_NONE 0
52 #define SPECIAL_STATIC_THREAD 1
53 #define SPECIAL_STATIC_CONTEXT 2
55 typedef struct _MonoInternalThread MonoInternalThread;
57 typedef void (*MonoThreadCleanupFunc) (MonoNativeThreadId tid);
58 /* INFO has type MonoThreadInfo* */
59 typedef void (*MonoThreadNotifyPendingExcFunc) (gpointer info);
62 MONO_THREAD_CREATE_FLAGS_NONE = 0x0,
63 MONO_THREAD_CREATE_FLAGS_THREADPOOL = 0x1,
64 MONO_THREAD_CREATE_FLAGS_DEBUGGER = 0x2,
65 MONO_THREAD_CREATE_FLAGS_FORCE_CREATE = 0x4,
66 MONO_THREAD_CREATE_FLAGS_SMALL_STACK = 0x8,
67 } MonoThreadCreateFlags;
70 mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, MonoThreadCreateFlags flags, MonoError *error);
72 void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
74 void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread *this_obj);
75 gpointer ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this_obj, MonoObject *start);
76 void ves_icall_System_Threading_InternalThread_Thread_free_internal(MonoInternalThread *this_obj);
77 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms);
78 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms);
79 gint32 ves_icall_System_Threading_Thread_GetDomainID (void);
80 gboolean ves_icall_System_Threading_Thread_Yield (void);
81 MonoString* ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread *this_obj);
82 void ves_icall_System_Threading_Thread_SetName_internal (MonoInternalThread *this_obj, MonoString *name);
83 int ves_icall_System_Threading_Thread_GetPriority (MonoThread *this_obj);
84 void ves_icall_System_Threading_Thread_SetPriority (MonoThread *this_obj, int priority);
85 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentCulture (MonoInternalThread *this_obj);
86 void ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread *this_obj, MonoObject *culture);
87 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoInternalThread *this_obj);
88 void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *this_obj, MonoObject *culture);
89 MonoThread *ves_icall_System_Threading_Thread_GetCurrentThread (void);
91 gint32 ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms);
92 gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms);
93 gint32 ves_icall_System_Threading_WaitHandle_WaitOne_internal(gpointer handle, gint32 ms);
94 gint32 ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal, gpointer toWait, gint32 ms);
96 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray *arr);
97 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr);
99 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
100 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
101 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
102 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
104 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value);
105 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value);
106 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value);
107 gpointer ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer *location, gpointer value);
108 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value);
109 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value);
111 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand);
112 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success(gint32 *location, gint32 value, gint32 comparand, MonoBoolean *success);
113 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand);
114 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand);
115 gpointer ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer *location, gpointer value, gpointer comparand);
116 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand);
117 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand);
118 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand);
119 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value);
121 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value);
122 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value);
123 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location);
125 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
126 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
128 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
129 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
131 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject *state);
132 void ves_icall_System_Threading_Thread_ResetAbort (MonoThread *this_obj);
133 MonoObject* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread *thread);
134 void ves_icall_System_Threading_Thread_Suspend (MonoThread *this_obj);
135 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread);
136 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread *thread, guint32 state);
137 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread *thread, guint32 state);
138 guint32 ves_icall_System_Threading_Thread_GetState (MonoInternalThread *thread);
140 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr);
141 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr);
142 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr);
143 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr);
144 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr);
145 void * ves_icall_System_Threading_Thread_VolatileReadObject (void *ptr);
146 double ves_icall_System_Threading_Thread_VolatileReadDouble (void *ptr);
147 float ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr);
149 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8);
150 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16);
151 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32);
152 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64);
153 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *);
154 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr, MonoObject *);
155 void ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float);
156 void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double);
158 gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr);
159 gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr);
160 gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr);
161 gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr);
162 void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr);
163 double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr);
164 float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr);
165 MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr);
167 void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8);
168 void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16);
169 void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32);
170 void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64);
171 void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *);
172 void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float);
173 void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double);
174 void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value);
176 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
177 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoThread *this_obj);
178 void ves_icall_System_Threading_Thread_SpinWait_nop (void);
180 void ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContext *ctx);
181 void ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContext *ctx);
183 MonoInternalThread *mono_thread_internal_current (void);
185 void mono_thread_internal_abort (MonoInternalThread *thread);
186 void mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread);
188 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
190 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
192 void mono_thread_internal_unhandled_exception (MonoObject* exc);
194 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
195 gboolean mono_thread_current_check_pending_interrupt (void);
197 void mono_thread_set_state (MonoInternalThread *thread, MonoThreadState state);
198 void mono_thread_clr_state (MonoInternalThread *thread, MonoThreadState state);
199 gboolean mono_thread_test_state (MonoInternalThread *thread, MonoThreadState test);
200 gboolean mono_thread_test_and_set_state (MonoInternalThread *thread, MonoThreadState test, MonoThreadState set);
202 void mono_thread_init_apartment_state (void);
203 void mono_thread_cleanup_apartment_state (void);
205 void mono_threads_set_shutting_down (void);
207 gunichar2* mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len);
209 MONO_API MonoException* mono_thread_get_undeniable_exception (void);
211 void mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean permanent, gboolean reset, MonoError *error);
213 void mono_thread_suspend_all_other_threads (void);
214 gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout);
216 void mono_thread_push_appdomain_ref (MonoDomain *domain);
217 void mono_thread_pop_appdomain_ref (void);
218 gboolean mono_thread_has_appdomain_ref (MonoThread *thread, MonoDomain *domain);
220 MonoException* mono_thread_request_interruption (mono_bool running_managed);
221 gboolean mono_thread_interruption_requested (void);
222 MonoException* mono_thread_interruption_checkpoint (void);
223 MonoException* mono_thread_force_interruption_checkpoint_noraise (void);
224 gint32* mono_thread_interruption_request_flag (void);
226 uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, uint32_t align, uintptr_t *bitmap, int numbits);
227 void* mono_get_special_static_data (uint32_t offset);
228 gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset);
230 MonoException* mono_thread_resume_interruption (gboolean exec);
231 void mono_threads_perform_thread_dump (void);
234 mono_thread_create_checked (MonoDomain *domain, gpointer func, gpointer arg, MonoError *error);
237 mono_thread_attach_full (MonoDomain *domain, gboolean force_attach);
239 /* Can't include utils/mono-threads.h because of the THREAD_INFO_TYPE wizardry */
240 void mono_threads_add_joinable_thread (gpointer tid);
241 void mono_threads_join_threads (void);
242 void mono_thread_join (gpointer tid);
244 void mono_thread_detach_internal (MonoInternalThread *thread);
246 void ves_icall_System_Threading_Thread_GetStackTraces (MonoArray **out_threads, MonoArray **out_stack_traces);
249 mono_threads_attach_coop (MonoDomain *domain, gpointer *dummy);
252 mono_threads_detach_coop (gpointer cookie, gpointer *dummy);
254 void mono_threads_begin_abort_protected_block (void);
255 gboolean mono_threads_end_abort_protected_block (void);
258 mono_thread_internal_current_is_attached (void);
261 mono_thread_internal_describe (MonoInternalThread *internal, GString *str);
264 mono_thread_internal_is_current (MonoInternalThread *internal);
266 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */