[runtime] Remove the usage of MONO_INTERNAL, use MONO_API to mark exported functions...
[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/metadata/object.h>
19 #include "mono/utils/mono-compiler.h"
20 #include "mono/utils/mono-membar.h"
21
22 /* This is a copy of System.Threading.ThreadState */
23 typedef enum {
24         ThreadState_Running = 0x00000000,
25         ThreadState_StopRequested = 0x00000001,
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
34 } MonoThreadState; 
35
36 /* This is a copy of System.Threading.ApartmentState */
37 typedef enum {
38         ThreadApartmentState_STA = 0x00000000,
39         ThreadApartmentState_MTA = 0x00000001,
40         ThreadApartmentState_Unknown = 0x00000002
41 } MonoThreadApartmentState;
42
43 typedef enum {
44         ThreadPriority_Lowest = 0,
45         ThreadPriority_BelowNormal = 1,
46         ThreadPriority_Normal = 2,
47         ThreadPriority_AboveNormal = 3,
48         ThreadPriority_Highest = 4
49 } MonoThreadPriority;
50
51 #define SPECIAL_STATIC_NONE 0
52 #define SPECIAL_STATIC_THREAD 1
53 #define SPECIAL_STATIC_CONTEXT 2
54
55 #ifdef HOST_WIN32
56 typedef SECURITY_ATTRIBUTES WapiSecurityAttributes;
57 typedef LPTHREAD_START_ROUTINE WapiThreadStart;
58 #endif
59
60 typedef struct _MonoInternalThread MonoInternalThread;
61
62 typedef void (*MonoThreadCleanupFunc) (MonoInternalThread* thread);
63 /* INFO has type MonoThreadInfo* */
64 typedef void (*MonoThreadNotifyPendingExcFunc) (gpointer info);
65
66 MonoInternalThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread, guint32 stack_size);
67
68 void mono_threads_install_cleanup (MonoThreadCleanupFunc func);
69
70 void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread *this_obj);
71 HANDLE 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, HANDLE thread);
73 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms);
74 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoInternalThread *this_obj, int ms, HANDLE thread);
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 (MonoInternalThread *thread);
80 void ves_icall_System_Threading_Thread_SetPriority (MonoInternalThread *thread, 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 HANDLE ves_icall_System_Threading_Mutex_CreateMutex_internal(MonoBoolean owned, MonoString *name, MonoBoolean *created);
86 MonoBoolean ves_icall_System_Threading_Mutex_ReleaseMutex_internal (HANDLE handle );
87 HANDLE ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString *name, gint32 rights, gint32 *error);
88 HANDLE ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount, gint32 maximumCount, MonoString *name, MonoBoolean *created);
89 gint32 ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle, gint32 releaseCount, MonoBoolean *fail);
90 HANDLE ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString *name, gint32 rights, gint32 *error);
91 HANDLE ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, MonoBoolean *created);
92 gboolean ves_icall_System_Threading_Events_SetEvent_internal (HANDLE handle);
93 gboolean ves_icall_System_Threading_Events_ResetEvent_internal (HANDLE handle);
94 void ves_icall_System_Threading_Events_CloseEvent_internal (HANDLE handle);
95 HANDLE ves_icall_System_Threading_Events_OpenEvent_internal (MonoString *name, gint32 rights, gint32 *error);
96
97 gboolean ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext);
98 gint32 ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray *mono_handles, gint32 ms, gboolean exitContext);
99 gboolean ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject *this_obj, HANDLE handle, gint32 ms, gboolean exitContext);
100 gboolean ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (HANDLE toSignal, HANDLE toWait, gint32 ms, gboolean exitContext);
101
102 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray *arr);
103 MonoArray* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr);
104
105 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
106 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
107 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
108 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
109
110 gint32 ves_icall_System_Threading_Interlocked_Exchange_Int(gint32 *location, gint32 value);
111 gint64 ves_icall_System_Threading_Interlocked_Exchange_Long(gint64 *location, gint64 value);
112 MonoObject *ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject **location, MonoObject *value);
113 gpointer ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer *location, gpointer value);
114 gfloat ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat *location, gfloat value);
115 gdouble ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble *location, gdouble value);
116
117 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32 *location, gint32 value, gint32 comparand);
118 gint32 ves_icall_System_Threading_Interlocked_CompareExchange_Int_Success(gint32 *location, gint32 value, gint32 comparand, MonoBoolean *success);
119 gint64 ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64 *location, gint64 value, gint64 comparand);
120 MonoObject *ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject **location, MonoObject *value, MonoObject *comparand);
121 gpointer ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer *location, gpointer value, gpointer comparand);
122 gfloat ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat *location, gfloat value, gfloat comparand);
123 gdouble ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble *location, gdouble value, gdouble comparand);
124 MonoObject* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject **location, MonoObject *value, MonoObject *comparand);
125 MonoObject* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject **location, MonoObject *value);
126
127 gint32 ves_icall_System_Threading_Interlocked_Add_Int(gint32 *location, gint32 value);
128 gint64 ves_icall_System_Threading_Interlocked_Add_Long(gint64 *location, gint64 value);
129 gint64 ves_icall_System_Threading_Interlocked_Read_Long(gint64 *location);
130
131 gint32 ves_icall_System_Threading_Interlocked_Increment_Int(gint32 *location);
132 gint64 ves_icall_System_Threading_Interlocked_Increment_Long(gint64 *location);
133
134 gint32 ves_icall_System_Threading_Interlocked_Decrement_Int(gint32 *location);
135 gint64 ves_icall_System_Threading_Interlocked_Decrement_Long(gint64 * location);
136
137 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread *thread, MonoObject *state);
138 void ves_icall_System_Threading_Thread_ResetAbort (void);
139 MonoObject* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread *thread);
140 void ves_icall_System_Threading_Thread_Suspend (MonoInternalThread *thread);
141 void ves_icall_System_Threading_Thread_Resume (MonoThread *thread);
142 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread *thread, guint32 state);
143 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread *thread, guint32 state);
144 guint32 ves_icall_System_Threading_Thread_GetState (MonoInternalThread *thread);
145
146 gint8 ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr);
147 gint16 ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr);
148 gint32 ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr);
149 gint64 ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr);
150 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr);
151 void * ves_icall_System_Threading_Thread_VolatileReadObject (void *ptr);
152 double ves_icall_System_Threading_Thread_VolatileReadDouble (void *ptr);
153 float ves_icall_System_Threading_Thread_VolatileReadFloat (void *ptr);
154
155 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr, gint8);
156 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr, gint16);
157 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr, gint32);
158 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr, gint64);
159 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr, void *);
160 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr, MonoObject *);
161 void ves_icall_System_Threading_Thread_VolatileWriteFloat (void *ptr, float);
162 void ves_icall_System_Threading_Thread_VolatileWriteDouble (void *ptr, double);
163
164 gint8 ves_icall_System_Threading_Volatile_Read1 (void *ptr);
165 gint16 ves_icall_System_Threading_Volatile_Read2 (void *ptr);
166 gint32 ves_icall_System_Threading_Volatile_Read4 (void *ptr);
167 gint64 ves_icall_System_Threading_Volatile_Read8 (void *ptr);
168 void * ves_icall_System_Threading_Volatile_ReadIntPtr (void *ptr);
169 double ves_icall_System_Threading_Volatile_ReadDouble (void *ptr);
170 float ves_icall_System_Threading_Volatile_ReadFloat (void *ptr);
171 MonoObject* ves_icall_System_Threading_Volatile_Read_T (void *ptr);
172
173 void ves_icall_System_Threading_Volatile_Write1 (void *ptr, gint8);
174 void ves_icall_System_Threading_Volatile_Write2 (void *ptr, gint16);
175 void ves_icall_System_Threading_Volatile_Write4 (void *ptr, gint32);
176 void ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64);
177 void ves_icall_System_Threading_Volatile_WriteIntPtr (void *ptr, void *);
178 void ves_icall_System_Threading_Volatile_WriteFloat (void *ptr, float);
179 void ves_icall_System_Threading_Volatile_WriteDouble (void *ptr, double);
180 void ves_icall_System_Threading_Volatile_Write_T (void *ptr, MonoObject *value);
181
182 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
183 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoInternalThread *this_obj);
184 void ves_icall_System_Threading_Thread_SpinWait_nop (void);
185
186 MonoInternalThread *mono_thread_internal_current (void);
187
188 void mono_thread_internal_stop (MonoInternalThread *thread);
189
190 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
191
192 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
193
194 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
195 void mono_special_static_data_free_slot (guint32 offset, guint32 size);
196 uint32_t mono_thread_alloc_tls   (MonoReflectionType *type);
197 void     mono_thread_destroy_tls (uint32_t tls_offset);
198 void     mono_thread_destroy_domain_tls (MonoDomain *domain);
199 void mono_thread_free_local_slot_values (int slot, MonoBoolean is_thread_local);
200 void mono_thread_current_check_pending_interrupt (void);
201
202 void mono_thread_set_state (MonoInternalThread *thread, MonoThreadState state);
203 void mono_thread_clr_state (MonoInternalThread *thread, MonoThreadState state);
204 gboolean mono_thread_test_state (MonoInternalThread *thread, MonoThreadState test);
205
206 void mono_thread_init_apartment_state (void);
207 void mono_thread_cleanup_apartment_state (void);
208
209 void mono_threads_set_shutting_down (void);
210
211 gunichar2* mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len);
212
213 MONO_API MonoException* mono_thread_get_undeniable_exception (void);
214
215 MonoException* mono_thread_get_and_clear_pending_exception (void);
216
217 void mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean managed);
218
219 void mono_threads_install_notify_pending_exc (MonoThreadNotifyPendingExcFunc func);
220
221 MonoObject* mono_thread_get_execution_context (void);
222 void mono_thread_set_execution_context (MonoObject *ec);
223
224 void mono_runtime_set_has_tls_get (gboolean val);
225 gboolean mono_runtime_has_tls_get (void);
226
227 int mono_thread_get_abort_signal (void);
228
229 void mono_thread_abort_all_other_threads (void);
230 void mono_thread_suspend_all_other_threads (void);
231 gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout);
232
233 void mono_thread_push_appdomain_ref (MonoDomain *domain);
234 void mono_thread_pop_appdomain_ref (void);
235 gboolean mono_thread_has_appdomain_ref (MonoThread *thread, MonoDomain *domain);
236
237 void mono_threads_clear_cached_culture (MonoDomain *domain);
238
239 MonoException* mono_thread_request_interruption (mono_bool running_managed);
240 gboolean mono_thread_interruption_requested (void);
241 MonoException* mono_thread_interruption_checkpoint (void);
242 MonoException* mono_thread_force_interruption_checkpoint_noraise (void);
243 void mono_thread_force_interruption_checkpoint (void);
244 gint32* mono_thread_interruption_request_flag (void);
245
246 uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, uint32_t align, uintptr_t *bitmap, int numbits);
247 void*    mono_get_special_static_data   (uint32_t offset);
248 gpointer mono_get_special_static_data_for_thread (MonoInternalThread *thread, guint32 offset);
249
250 MonoException* mono_thread_resume_interruption (void);
251 void mono_threads_perform_thread_dump (void);
252 MonoThread *mono_thread_attach_full (MonoDomain *domain, gboolean force_attach);
253
254 void mono_thread_init_tls (void);
255
256 /* Can't include utils/mono-threads.h because of the THREAD_INFO_TYPE wizardry */
257 void mono_threads_add_joinable_thread (gpointer tid);
258 void mono_threads_join_threads (void);
259 void mono_thread_join (gpointer tid);
260
261 void mono_thread_detach_internal (MonoInternalThread *thread);
262
263 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */