[threads] Remove mono_threads_create_thread (#4411)
[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  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12
13 #ifndef _MONO_METADATA_THREADS_TYPES_H_
14 #define _MONO_METADATA_THREADS_TYPES_H_
15
16 #include <glib.h>
17
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"
22
23 /* This is a copy of System.Threading.ThreadState */
24 typedef enum {
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
35 } MonoThreadState; 
36
37 /* This is a copy of System.Threading.ApartmentState */
38 typedef enum {
39         ThreadApartmentState_STA = 0x00000000,
40         ThreadApartmentState_MTA = 0x00000001,
41         ThreadApartmentState_Unknown = 0x00000002
42 } MonoThreadApartmentState;
43
44 typedef enum {
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,
50 } MonoThreadPriority;
51
52 #define SPECIAL_STATIC_NONE 0
53 #define SPECIAL_STATIC_THREAD 1
54 #define SPECIAL_STATIC_CONTEXT 2
55
56 typedef struct _MonoInternalThread MonoInternalThread;
57
58 typedef void (*MonoThreadCleanupFunc) (MonoNativeThreadId tid);
59 /* INFO has type MonoThreadInfo* */
60 typedef void (*MonoThreadNotifyPendingExcFunc) (gpointer info);
61
62 typedef enum {
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;
69
70 MonoInternalThread*
71 mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, MonoThreadCreateFlags flags, MonoError *error);
72
73 void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
74
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);
91
92 gint32 ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms);
93 gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms);
94 gint32 ves_icall_System_Threading_WaitHandle_WaitOne_internal(gpointer handle, gint32 ms);
95 gint32 ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal, gpointer toWait, gint32 ms);
96
97 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray *arr);
98 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr);
99
100 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
101 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
102 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
103 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
104
105 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value);
106 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value);
107 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value);
108 gpointer ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer *location, gpointer value);
109 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value);
110 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value);
111
112 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand);
113 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success(gint32 *location, gint32 value, gint32 comparand, MonoBoolean *success);
114 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand);
115 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand);
116 gpointer ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer *location, gpointer value, gpointer comparand);
117 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand);
118 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand);
119 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand);
120 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value);
121
122 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value);
123 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value);
124 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location);
125
126 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
127 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
128
129 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
130 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
131
132 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject *state);
133 void ves_icall_System_Threading_Thread_ResetAbort (MonoThread *this_obj);
134 MonoObject* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread *thread);
135 void ves_icall_System_Threading_Thread_Suspend (MonoThread *this_obj);
136 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread);
137 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread *thread, guint32 state);
138 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread *thread, guint32 state);
139 guint32 ves_icall_System_Threading_Thread_GetState (MonoInternalThread *thread);
140
141 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr);
142 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr);
143 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr);
144 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr);
145 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr);
146 void * ves_icall_System_Threading_Thread_VolatileReadObject (void *ptr);
147 double ves_icall_System_Threading_Thread_VolatileReadDouble (void *ptr);
148 float ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr);
149
150 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8);
151 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16);
152 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32);
153 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64);
154 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *);
155 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr, MonoObject *);
156 void ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float);
157 void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double);
158
159 gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr);
160 gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr);
161 gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr);
162 gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr);
163 void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr);
164 double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr);
165 float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr);
166 MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr);
167
168 void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8);
169 void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16);
170 void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32);
171 void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64);
172 void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *);
173 void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float);
174 void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double);
175 void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value);
176
177 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
178 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoThread *this_obj);
179 void ves_icall_System_Threading_Thread_SpinWait_nop (void);
180
181 void ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContext *ctx);
182 void ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContext *ctx);
183
184 MonoInternalThread *mono_thread_internal_current (void);
185
186 void mono_thread_internal_check_for_interruption_critical (MonoInternalThread *thread);
187
188 void mono_thread_internal_abort (MonoInternalThread *thread);
189 void mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread);
190
191 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
192
193 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
194
195 void mono_thread_internal_unhandled_exception (MonoObject* exc);
196
197 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
198 gboolean mono_thread_current_check_pending_interrupt (void);
199
200 void mono_thread_set_state (MonoInternalThread *thread, MonoThreadState state);
201 void mono_thread_clr_state (MonoInternalThread *thread, MonoThreadState state);
202 gboolean mono_thread_test_state (MonoInternalThread *thread, MonoThreadState test);
203 gboolean mono_thread_test_and_set_state (MonoInternalThread *thread, MonoThreadState test, MonoThreadState set);
204
205 void mono_thread_init_apartment_state (void);
206 void mono_thread_cleanup_apartment_state (void);
207
208 void mono_threads_set_shutting_down (void);
209
210 gunichar2* mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len);
211
212 MONO_API MonoException* mono_thread_get_undeniable_exception (void);
213
214 void mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean permanent, gboolean reset, MonoError *error);
215
216 void mono_thread_suspend_all_other_threads (void);
217 gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout);
218
219 void mono_thread_push_appdomain_ref (MonoDomain *domain);
220 void mono_thread_pop_appdomain_ref (void);
221 gboolean mono_thread_has_appdomain_ref (MonoThread *thread, MonoDomain *domain);
222
223 MonoException* mono_thread_request_interruption (mono_bool running_managed);
224 gboolean mono_thread_interruption_requested (void);
225 MonoException* mono_thread_interruption_checkpoint (void);
226 MonoException* mono_thread_force_interruption_checkpoint_noraise (void);
227 gint32* mono_thread_interruption_request_flag (void);
228
229 uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, uint32_t align, uintptr_t *bitmap, int numbits);
230 void*    mono_get_special_static_data   (uint32_t offset);
231 gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset);
232
233 MonoException* mono_thread_resume_interruption (void);
234 void mono_threads_perform_thread_dump (void);
235
236 gboolean
237 mono_thread_create_checked (MonoDomain *domain, gpointer func, gpointer arg, MonoError *error);
238
239 MonoThread *
240 mono_thread_attach_full (MonoDomain *domain, gboolean force_attach);
241
242 /* Can't include utils/mono-threads.h because of the THREAD_INFO_TYPE wizardry */
243 void mono_threads_add_joinable_thread (gpointer tid);
244 void mono_threads_join_threads (void);
245 void mono_thread_join (gpointer tid);
246
247 void mono_thread_detach_internal (MonoInternalThread *thread);
248
249 void ves_icall_System_Threading_Thread_GetStackTraces (MonoArray **out_threads, MonoArray **out_stack_traces);
250
251 MONO_API gpointer
252 mono_threads_attach_coop (MonoDomain *domain, gpointer *dummy);
253
254 MONO_API void
255 mono_threads_detach_coop (gpointer cookie, gpointer *dummy);
256
257 void mono_threads_begin_abort_protected_block (void);
258 gboolean mono_threads_end_abort_protected_block (void);
259 MonoException* mono_thread_try_resume_interruption (void);
260
261 gboolean
262 mono_thread_internal_current_is_attached (void);
263
264 void
265 mono_thread_internal_describe (MonoInternalThread *internal, GString *str);
266
267 gboolean
268 mono_thread_internal_is_current (MonoInternalThread *internal);
269
270 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */