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_StopRequested = 0x00000001,
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
57 typedef SECURITY_ATTRIBUTES WapiSecurityAttributes;
60 typedef struct _MonoInternalThread MonoInternalThread;
62 typedef void (*MonoThreadCleanupFunc) (MonoNativeThreadId tid);
63 /* INFO has type MonoThreadInfo* */
64 typedef void (*MonoThreadNotifyPendingExcFunc) (gpointer info);
66 MonoInternalThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread, guint32 stack_size, MonoError *error);
68 void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
70 void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread *this_obj);
71 gpointer ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this_obj, MonoObject *start);
72 void ves_icall_System_Threading_InternalThread_Thread_free_internal(MonoInternalThread *this_obj);
73 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms);
74 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms);
75 gint32 ves_icall_System_Threading_Thread_GetDomainID (void);
76 gboolean ves_icall_System_Threading_Thread_Yield (void);
77 MonoString* ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread *this_obj);
78 void ves_icall_System_Threading_Thread_SetName_internal (MonoInternalThread *this_obj, MonoString *name);
79 int ves_icall_System_Threading_Thread_GetPriority (MonoThread *this_obj);
80 void ves_icall_System_Threading_Thread_SetPriority (MonoThread *this_obj, int priority);
81 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentCulture (MonoInternalThread *this_obj);
82 void ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread *this_obj, MonoObject *culture);
83 MonoObject* ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoInternalThread *this_obj);
84 void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread *this_obj, MonoObject *culture);
85 MonoThread *ves_icall_System_Threading_Thread_GetCurrentThread (void);
87 gint32 ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms);
88 gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms);
89 gint32 ves_icall_System_Threading_WaitHandle_WaitOne_internal(gpointer handle, gint32 ms);
90 gint32 ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal, gpointer toWait, gint32 ms);
92 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray *arr);
93 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr);
95 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
96 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
97 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
98 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
100 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value);
101 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value);
102 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value);
103 gpointer ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer *location, gpointer value);
104 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value);
105 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value);
107 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand);
108 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success(gint32 *location, gint32 value, gint32 comparand, MonoBoolean *success);
109 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand);
110 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand);
111 gpointer ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer *location, gpointer value, gpointer comparand);
112 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand);
113 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand);
114 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand);
115 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value);
117 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value);
118 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value);
119 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location);
121 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
122 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
124 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
125 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
127 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject *state);
128 void ves_icall_System_Threading_Thread_ResetAbort (MonoThread *this_obj);
129 MonoObject* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread *thread);
130 void ves_icall_System_Threading_Thread_Suspend (MonoThread *this_obj);
131 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread);
132 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread *thread, guint32 state);
133 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread *thread, guint32 state);
134 guint32 ves_icall_System_Threading_Thread_GetState (MonoInternalThread *thread);
136 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr);
137 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr);
138 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr);
139 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr);
140 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr);
141 void * ves_icall_System_Threading_Thread_VolatileReadObject (void *ptr);
142 double ves_icall_System_Threading_Thread_VolatileReadDouble (void *ptr);
143 float ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr);
145 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8);
146 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16);
147 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32);
148 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64);
149 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *);
150 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr, MonoObject *);
151 void ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float);
152 void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double);
154 gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr);
155 gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr);
156 gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr);
157 gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr);
158 void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr);
159 double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr);
160 float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr);
161 MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr);
163 void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8);
164 void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16);
165 void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32);
166 void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64);
167 void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *);
168 void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float);
169 void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double);
170 void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value);
172 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
173 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoThread *this_obj);
174 void ves_icall_System_Threading_Thread_SpinWait_nop (void);
176 void ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContext *ctx);
177 void ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContext *ctx);
179 MonoInternalThread *mono_thread_internal_current (void);
181 void mono_thread_internal_check_for_interruption_critical (MonoInternalThread *thread);
183 void mono_thread_internal_stop (MonoInternalThread *thread);
184 void mono_thread_internal_abort (MonoInternalThread *thread);
186 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
188 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
190 void mono_thread_internal_unhandled_exception (MonoObject* exc);
192 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
193 gboolean mono_thread_current_check_pending_interrupt (void);
195 void mono_thread_set_state (MonoInternalThread *thread, MonoThreadState state);
196 void mono_thread_clr_state (MonoInternalThread *thread, MonoThreadState state);
197 gboolean mono_thread_test_state (MonoInternalThread *thread, MonoThreadState test);
198 gboolean mono_thread_test_and_set_state (MonoInternalThread *thread, MonoThreadState test, MonoThreadState set);
200 void mono_thread_init_apartment_state (void);
201 void mono_thread_cleanup_apartment_state (void);
203 void mono_threads_set_shutting_down (void);
205 gunichar2* mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len);
207 MONO_API MonoException* mono_thread_get_undeniable_exception (void);
209 void mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean permanent, MonoError *error);
211 void mono_thread_suspend_all_other_threads (void);
212 gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout);
214 void mono_thread_push_appdomain_ref (MonoDomain *domain);
215 void mono_thread_pop_appdomain_ref (void);
216 gboolean mono_thread_has_appdomain_ref (MonoThread *thread, MonoDomain *domain);
218 void mono_threads_clear_cached_culture (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 (void);
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 void mono_threads_end_abort_protected_block (void);
256 MonoException* mono_thread_try_resume_interruption (void);
259 mono_thread_internal_current_is_attached (void);
262 mono_thread_internal_describe (MonoInternalThread *internal, GString *str);
265 mono_thread_internal_is_current (MonoInternalThread *internal);
267 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */