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
12 #ifndef _MONO_METADATA_THREADS_TYPES_H_
13 #define _MONO_METADATA_THREADS_TYPES_H_
17 #include <mono/io-layer/io-layer.h>
18 #include "mono/utils/mono-compiler.h"
19 #include "mono/utils/mono-membar.h"
21 /* This is a copy of System.Threading.ThreadState */
23 ThreadState_Running
= 0x00000000,
24 ThreadState_StopRequested
= 0x00000001,
25 ThreadState_SuspendRequested
= 0x00000002,
26 ThreadState_Background
= 0x00000004,
27 ThreadState_Unstarted
= 0x00000008,
28 ThreadState_Stopped
= 0x00000010,
29 ThreadState_WaitSleepJoin
= 0x00000020,
30 ThreadState_Suspended
= 0x00000040,
31 ThreadState_AbortRequested
= 0x00000080,
32 ThreadState_Aborted
= 0x00000100
35 /* This is a copy of System.Threading.ApartmentState */
37 ThreadApartmentState_STA
= 0x00000000,
38 ThreadApartmentState_MTA
= 0x00000001,
39 ThreadApartmentState_Unknown
= 0x00000002
40 } MonoThreadApartmentState
;
42 typedef void (*MonoThreadNotifyPendingExcFunc
) (void);
44 #define SPECIAL_STATIC_NONE 0
45 #define SPECIAL_STATIC_THREAD 1
46 #define SPECIAL_STATIC_CONTEXT 2
49 typedef SECURITY_ATTRIBUTES WapiSecurityAttributes
;
50 typedef LPTHREAD_START_ROUTINE WapiThreadStart
;
53 typedef struct _MonoInternalThread MonoInternalThread
;
55 gpointer
mono_create_thread (WapiSecurityAttributes
*security
,
56 guint32 stacksize
, WapiThreadStart start
,
57 gpointer param
, guint32 create
, gsize
*tid
) MONO_INTERNAL
;
59 MonoInternalThread
* mono_thread_create_internal (MonoDomain
*domain
, gpointer func
, gpointer arg
, gboolean threadpool_thread
) MONO_INTERNAL
;
61 void ves_icall_System_Threading_Thread_ConstructInternalThread (MonoThread
*this) MONO_INTERNAL
;
62 HANDLE
ves_icall_System_Threading_Thread_Thread_internal(MonoThread
*this_obj
, MonoObject
*start
) MONO_INTERNAL
;
63 void ves_icall_System_Threading_InternalThread_Thread_free_internal(MonoInternalThread
*this_obj
, HANDLE thread
) MONO_INTERNAL
;
64 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms
) MONO_INTERNAL
;
65 gboolean
ves_icall_System_Threading_Thread_Join_internal(MonoInternalThread
*this_obj
, int ms
, HANDLE thread
) MONO_INTERNAL
;
66 gint32
ves_icall_System_Threading_Thread_GetDomainID (void) MONO_INTERNAL
;
67 gboolean
ves_icall_System_Threading_Thread_Yield (void) MONO_INTERNAL
;
68 MonoString
* ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread
*this_obj
) MONO_INTERNAL
;
69 void ves_icall_System_Threading_Thread_SetName_internal (MonoInternalThread
*this_obj
, MonoString
*name
) MONO_INTERNAL
;
70 MonoObject
* ves_icall_System_Threading_Thread_GetCachedCurrentCulture (MonoInternalThread
*this_obj
) MONO_INTERNAL
;
71 void ves_icall_System_Threading_Thread_SetCachedCurrentCulture (MonoThread
*this_obj
, MonoObject
*culture
) MONO_INTERNAL
;
72 MonoObject
* ves_icall_System_Threading_Thread_GetCachedCurrentUICulture (MonoInternalThread
*this_obj
) MONO_INTERNAL
;
73 void ves_icall_System_Threading_Thread_SetCachedCurrentUICulture (MonoThread
*this_obj
, MonoObject
*culture
) MONO_INTERNAL
;
74 HANDLE
ves_icall_System_Threading_Mutex_CreateMutex_internal(MonoBoolean owned
, MonoString
*name
, MonoBoolean
*created
) MONO_INTERNAL
;
75 MonoBoolean
ves_icall_System_Threading_Mutex_ReleaseMutex_internal (HANDLE handle
) MONO_INTERNAL
;
76 HANDLE
ves_icall_System_Threading_Mutex_OpenMutex_internal (MonoString
*name
, gint32 rights
, gint32
*error
) MONO_INTERNAL
;
77 HANDLE
ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCount
, gint32 maximumCount
, MonoString
*name
, MonoBoolean
*created
) MONO_INTERNAL
;
78 gint32
ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (HANDLE handle
, gint32 releaseCount
, MonoBoolean
*fail
) MONO_INTERNAL
;
79 HANDLE
ves_icall_System_Threading_Semaphore_OpenSemaphore_internal (MonoString
*name
, gint32 rights
, gint32
*error
) MONO_INTERNAL
;
80 HANDLE
ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual
, MonoBoolean initial
, MonoString
*name
, MonoBoolean
*created
) MONO_INTERNAL
;
81 gboolean
ves_icall_System_Threading_Events_SetEvent_internal (HANDLE handle
) MONO_INTERNAL
;
82 gboolean
ves_icall_System_Threading_Events_ResetEvent_internal (HANDLE handle
) MONO_INTERNAL
;
83 void ves_icall_System_Threading_Events_CloseEvent_internal (HANDLE handle
) MONO_INTERNAL
;
84 HANDLE
ves_icall_System_Threading_Events_OpenEvent_internal (MonoString
*name
, gint32 rights
, gint32
*error
) MONO_INTERNAL
;
86 gboolean
ves_icall_System_Threading_WaitHandle_WaitAll_internal(MonoArray
*mono_handles
, gint32 ms
, gboolean exitContext
) MONO_INTERNAL
;
87 gint32
ves_icall_System_Threading_WaitHandle_WaitAny_internal(MonoArray
*mono_handles
, gint32 ms
, gboolean exitContext
) MONO_INTERNAL
;
88 gboolean
ves_icall_System_Threading_WaitHandle_WaitOne_internal(MonoObject
*this_obj
, HANDLE handle
, gint32 ms
, gboolean exitContext
) MONO_INTERNAL
;
89 gboolean
ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (HANDLE toSignal
, HANDLE toWait
, gint32 ms
, gboolean exitContext
) MONO_INTERNAL
;
91 MonoArray
* ves_icall_System_Threading_Thread_ByteArrayToRootDomain (MonoArray
*arr
) MONO_INTERNAL
;
92 MonoArray
* ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray
*arr
) MONO_INTERNAL
;
94 gint32
ves_icall_System_Threading_Interlocked_Increment_Int(gint32
*location
) MONO_INTERNAL
;
95 gint64
ves_icall_System_Threading_Interlocked_Increment_Long(gint64
*location
) MONO_INTERNAL
;
96 gint32
ves_icall_System_Threading_Interlocked_Decrement_Int(gint32
*location
) MONO_INTERNAL
;
97 gint64
ves_icall_System_Threading_Interlocked_Decrement_Long(gint64
* location
) MONO_INTERNAL
;
99 gint32
ves_icall_System_Threading_Interlocked_Exchange_Int(gint32
*location
, gint32 value
) MONO_INTERNAL
;
100 gint64
ves_icall_System_Threading_Interlocked_Exchange_Long(gint64
*location
, gint64 value
) MONO_INTERNAL
;
101 MonoObject
*ves_icall_System_Threading_Interlocked_Exchange_Object(MonoObject
**location
, MonoObject
*value
) MONO_INTERNAL
;
102 gpointer
ves_icall_System_Threading_Interlocked_Exchange_IntPtr(gpointer
*location
, gpointer value
) MONO_INTERNAL
;
103 gfloat
ves_icall_System_Threading_Interlocked_Exchange_Single(gfloat
*location
, gfloat value
) MONO_INTERNAL
;
104 gdouble
ves_icall_System_Threading_Interlocked_Exchange_Double(gdouble
*location
, gdouble value
) MONO_INTERNAL
;
106 gint32
ves_icall_System_Threading_Interlocked_CompareExchange_Int(gint32
*location
, gint32 value
, gint32 comparand
) MONO_INTERNAL
;
107 gint64
ves_icall_System_Threading_Interlocked_CompareExchange_Long(gint64
*location
, gint64 value
, gint64 comparand
) MONO_INTERNAL
;
108 MonoObject
*ves_icall_System_Threading_Interlocked_CompareExchange_Object(MonoObject
**location
, MonoObject
*value
, MonoObject
*comparand
) MONO_INTERNAL
;
109 gpointer
ves_icall_System_Threading_Interlocked_CompareExchange_IntPtr(gpointer
*location
, gpointer value
, gpointer comparand
) MONO_INTERNAL
;
110 gfloat
ves_icall_System_Threading_Interlocked_CompareExchange_Single(gfloat
*location
, gfloat value
, gfloat comparand
) MONO_INTERNAL
;
111 gdouble
ves_icall_System_Threading_Interlocked_CompareExchange_Double(gdouble
*location
, gdouble value
, gdouble comparand
) MONO_INTERNAL
;
112 MonoObject
* ves_icall_System_Threading_Interlocked_CompareExchange_T(MonoObject
**location
, MonoObject
*value
, MonoObject
*comparand
) MONO_INTERNAL
;
113 MonoObject
* ves_icall_System_Threading_Interlocked_Exchange_T(MonoObject
**location
, MonoObject
*value
) MONO_INTERNAL
;
115 gint32
ves_icall_System_Threading_Interlocked_Add_Int(gint32
*location
, gint32 value
) MONO_INTERNAL
;
116 gint64
ves_icall_System_Threading_Interlocked_Add_Long(gint64
*location
, gint64 value
) MONO_INTERNAL
;
117 gint64
ves_icall_System_Threading_Interlocked_Read_Long(gint64
*location
) MONO_INTERNAL
;
119 gint32
ves_icall_System_Threading_Interlocked_Increment_Int(gint32
*location
) MONO_INTERNAL
;
120 gint64
ves_icall_System_Threading_Interlocked_Increment_Long(gint64
*location
) MONO_INTERNAL
;
122 gint32
ves_icall_System_Threading_Interlocked_Decrement_Int(gint32
*location
) MONO_INTERNAL
;
123 gint64
ves_icall_System_Threading_Interlocked_Decrement_Long(gint64
* location
) MONO_INTERNAL
;
125 void ves_icall_System_Threading_Thread_Abort (MonoInternalThread
*thread
, MonoObject
*state
) MONO_INTERNAL
;
126 void ves_icall_System_Threading_Thread_ResetAbort (void) MONO_INTERNAL
;
127 MonoObject
* ves_icall_System_Threading_Thread_GetAbortExceptionState (MonoThread
*thread
) MONO_INTERNAL
;
128 void ves_icall_System_Threading_Thread_Suspend (MonoInternalThread
*thread
) MONO_INTERNAL
;
129 void ves_icall_System_Threading_Thread_Resume (MonoThread
*thread
) MONO_INTERNAL
;
130 void ves_icall_System_Threading_Thread_ClrState (MonoInternalThread
*thread
, guint32 state
) MONO_INTERNAL
;
131 void ves_icall_System_Threading_Thread_SetState (MonoInternalThread
*thread
, guint32 state
) MONO_INTERNAL
;
132 guint32
ves_icall_System_Threading_Thread_GetState (MonoInternalThread
*thread
) MONO_INTERNAL
;
134 gint8
ves_icall_System_Threading_Thread_VolatileRead1 (void *ptr
) MONO_INTERNAL
;
135 gint16
ves_icall_System_Threading_Thread_VolatileRead2 (void *ptr
) MONO_INTERNAL
;
136 gint32
ves_icall_System_Threading_Thread_VolatileRead4 (void *ptr
) MONO_INTERNAL
;
137 gint64
ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr
) MONO_INTERNAL
;
138 void * ves_icall_System_Threading_Thread_VolatileReadIntPtr (void *ptr
) MONO_INTERNAL
;
140 void ves_icall_System_Threading_Thread_VolatileWrite1 (void *ptr
, gint8
) MONO_INTERNAL
;
141 void ves_icall_System_Threading_Thread_VolatileWrite2 (void *ptr
, gint16
) MONO_INTERNAL
;
142 void ves_icall_System_Threading_Thread_VolatileWrite4 (void *ptr
, gint32
) MONO_INTERNAL
;
143 void ves_icall_System_Threading_Thread_VolatileWrite8 (void *ptr
, gint64
) MONO_INTERNAL
;
144 void ves_icall_System_Threading_Thread_VolatileWriteIntPtr (void *ptr
, void *) MONO_INTERNAL
;
145 void ves_icall_System_Threading_Thread_VolatileWriteObject (void *ptr
, void *) MONO_INTERNAL
;
147 void ves_icall_System_Threading_Thread_MemoryBarrier (void) MONO_INTERNAL
;
148 void ves_icall_System_Threading_Thread_Interrupt_internal (MonoInternalThread
*this_obj
) MONO_INTERNAL
;
149 void ves_icall_System_Threading_Thread_SpinWait_nop (void) MONO_INTERNAL
;
151 MonoInternalThread
*mono_thread_internal_current (void) MONO_INTERNAL
;
153 void mono_thread_internal_stop (MonoInternalThread
*thread
) MONO_INTERNAL
;
155 gboolean
mono_thread_internal_has_appdomain_ref (MonoInternalThread
*thread
, MonoDomain
*domain
) MONO_INTERNAL
;
157 void mono_thread_internal_reset_abort (MonoInternalThread
*thread
) MONO_INTERNAL
;
159 void mono_alloc_special_static_data_free (GHashTable
*special_static_fields
) MONO_INTERNAL
;
160 void mono_thread_free_local_slot_values (int slot
, MonoBoolean thread_local
) MONO_INTERNAL
;
161 void mono_thread_current_check_pending_interrupt (void) MONO_INTERNAL
;
162 void mono_thread_get_stack_bounds (guint8
**staddr
, size_t *stsize
) MONO_INTERNAL
;
164 void mono_thread_set_state (MonoInternalThread
*thread
, MonoThreadState state
) MONO_INTERNAL
;
165 void mono_thread_clr_state (MonoInternalThread
*thread
, MonoThreadState state
) MONO_INTERNAL
;
166 gboolean
mono_thread_test_state (MonoInternalThread
*thread
, MonoThreadState test
) MONO_INTERNAL
;
168 void mono_thread_init_apartment_state (void) MONO_INTERNAL
;
169 void mono_thread_cleanup_apartment_state (void) MONO_INTERNAL
;
171 void mono_threads_set_shutting_down (void) MONO_INTERNAL
;
172 gboolean
mono_threads_is_shutting_down (void) MONO_INTERNAL
;
174 gunichar2
* mono_thread_get_name (MonoInternalThread
*this_obj
, guint32
*name_len
) MONO_INTERNAL
;
176 MonoException
* mono_thread_get_undeniable_exception (void);
178 MonoException
* mono_thread_get_and_clear_pending_exception (void) MONO_INTERNAL
;
181 gpointer hazard_pointers
[2];
182 } MonoThreadHazardPointers
;
184 typedef void (*MonoHazardousFreeFunc
) (gpointer p
);
186 void mono_thread_hazardous_free_or_queue (gpointer p
, MonoHazardousFreeFunc free_func
);
187 void mono_thread_hazardous_try_free_all (void);
189 MonoThreadHazardPointers
* mono_hazard_pointer_get (void);
191 void mono_threads_install_notify_pending_exc (MonoThreadNotifyPendingExcFunc func
) MONO_INTERNAL
;
193 #define mono_hazard_pointer_set(hp,i,v) \
194 do { g_assert ((i) == 0 || (i) == 1); \
195 (hp)->hazard_pointers [(i)] = (v); \
196 mono_memory_write_barrier (); \
198 #define mono_hazard_pointer_clear(hp,i) \
199 do { g_assert ((i) == 0 || (i) == 1); \
200 (hp)->hazard_pointers [(i)] = NULL; \
203 MonoObject
* mono_thread_get_execution_context (void) MONO_INTERNAL
;
204 void mono_thread_set_execution_context (MonoObject
*ec
) MONO_INTERNAL
;
206 void mono_runtime_set_has_tls_get (gboolean val
) MONO_INTERNAL
;
207 gboolean
mono_runtime_has_tls_get (void) MONO_INTERNAL
;
209 int mono_thread_get_abort_signal (void) MONO_INTERNAL
;
211 void mono_thread_abort_all_other_threads (void) MONO_INTERNAL
;
212 void mono_thread_suspend_all_other_threads (void) MONO_INTERNAL
;
213 gboolean
mono_threads_abort_appdomain_threads (MonoDomain
*domain
, int timeout
) MONO_INTERNAL
;
215 void mono_thread_push_appdomain_ref (MonoDomain
*domain
) MONO_INTERNAL
;
216 void mono_thread_pop_appdomain_ref (void) MONO_INTERNAL
;
217 gboolean
mono_thread_has_appdomain_ref (MonoThread
*thread
, MonoDomain
*domain
) MONO_INTERNAL
;
219 void mono_threads_clear_cached_culture (MonoDomain
*domain
) MONO_INTERNAL
;
221 MonoException
* mono_thread_request_interruption (mono_bool running_managed
) MONO_INTERNAL
;
222 gboolean
mono_thread_interruption_requested (void) MONO_INTERNAL
;
223 void mono_thread_interruption_checkpoint (void) MONO_INTERNAL
;
224 void mono_thread_force_interruption_checkpoint (void) MONO_INTERNAL
;
225 gint32
* mono_thread_interruption_request_flag (void) MONO_INTERNAL
;
227 uint32_t mono_alloc_special_static_data (uint32_t static_type
, uint32_t size
, uint32_t align
, uintptr_t *bitmap
, int max_set
) MONO_INTERNAL
;
228 void* mono_get_special_static_data (uint32_t offset
) MONO_INTERNAL
;
230 MonoException
* mono_thread_resume_interruption (void) MONO_INTERNAL
;
232 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */