2 * threads.c: Thread handles
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
12 #include <mono/os/gc_wrapper.h>
13 #include "mono/utils/mono-hash.h"
23 #include <mono/io-layer/wapi.h>
24 #include <mono/io-layer/wapi-private.h>
25 #include <mono/io-layer/timed-thread.h>
26 #include <mono/io-layer/handles-private.h>
27 #include <mono/io-layer/misc-private.h>
28 #include <mono/io-layer/mono-mutex.h>
29 #include <mono/io-layer/thread-private.h>
30 #include <mono/io-layer/mono-spinlock.h>
36 /* Hash threads with tids. I thought of using TLS for this, but that
37 * would have to set the data in the new thread, which is more hassle
39 static mono_once_t thread_hash_once = MONO_ONCE_INIT;
40 static mono_mutex_t thread_hash_mutex = MONO_MUTEX_INITIALIZER;
41 static GHashTable *thread_hash=NULL;
44 static MonoGHashTable *tls_gc_hash = NULL;
47 static void thread_close_private (gpointer handle);
48 static void thread_own (gpointer handle);
50 struct _WapiHandleOps _wapi_thread_ops = {
51 NULL, /* close_shared */
52 thread_close_private, /* close_private */
58 static mono_once_t thread_ops_once=MONO_ONCE_INIT;
60 #ifdef WITH_INCLUDED_LIBGC
61 static void gc_init (void);
64 static void thread_ops_init (void)
66 _wapi_handle_register_capabilities (WAPI_HANDLE_THREAD,
67 WAPI_HANDLE_CAP_WAIT);
69 #ifdef WITH_INCLUDED_LIBGC
74 static void thread_close_private (gpointer handle)
76 struct _WapiHandlePrivate_thread *thread_handle;
79 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD, NULL,
80 (gpointer *)&thread_handle);
82 g_warning (G_GNUC_PRETTY_FUNCTION
83 ": error looking up thread handle %p", handle);
88 g_message(G_GNUC_PRETTY_FUNCTION
89 ": closing thread handle %p with thread %p id %ld",
90 handle, thread_handle->thread,
91 thread_handle->thread->id);
94 if(thread_handle->thread!=NULL) {
95 _wapi_timed_thread_destroy (thread_handle->thread);
99 static void thread_own (gpointer handle)
101 struct _WapiHandle_thread *thread_handle;
102 struct _WapiHandlePrivate_thread *thread_private_handle;
105 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
106 (gpointer *)&thread_handle,
107 (gpointer *)&thread_private_handle);
109 g_warning (G_GNUC_PRETTY_FUNCTION
110 ": error looking up thread handle %p", handle);
114 if(thread_private_handle->joined==FALSE) {
115 _wapi_timed_thread_join (thread_private_handle->thread, NULL,
117 thread_private_handle->joined=TRUE;
121 static void thread_exit(guint32 exitstatus, gpointer handle)
123 struct _WapiHandle_thread *thread_handle;
124 struct _WapiHandlePrivate_thread *thread_private_handle;
128 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
129 (gpointer *)&thread_handle,
130 (gpointer *)&thread_private_handle);
132 g_warning (G_GNUC_PRETTY_FUNCTION
133 ": error looking up thread handle %p", handle);
137 pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
139 thr_ret = _wapi_handle_lock_handle (handle);
140 g_assert (thr_ret == 0);
143 g_message (G_GNUC_PRETTY_FUNCTION
144 ": Recording thread handle %p exit status", handle);
147 thread_handle->exitstatus=exitstatus;
148 thread_handle->state=THREAD_STATE_EXITED;
149 _wapi_handle_set_signal_state (handle, TRUE, TRUE);
151 thr_ret = _wapi_handle_unlock_handle (handle);
152 g_assert (thr_ret == 0);
153 pthread_cleanup_pop (0);
156 g_message(G_GNUC_PRETTY_FUNCTION
157 ": Recording thread handle %p id %ld status as %d",
158 handle, thread_private_handle->thread->id, exitstatus);
161 /* Remove this thread from the hash */
162 pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
163 (void *)&thread_hash_mutex);
164 thr_ret = mono_mutex_lock(&thread_hash_mutex);
165 g_assert (thr_ret == 0);
167 g_hash_table_remove(thread_hash, &thread_private_handle->thread->id);
169 thr_ret = mono_mutex_unlock(&thread_hash_mutex);
170 g_assert (thr_ret == 0);
171 pthread_cleanup_pop (0);
173 /* The thread is no longer active, so unref it */
174 _wapi_handle_unref (handle);
177 static void thread_hash_init(void)
179 thread_hash=g_hash_table_new(g_int_hash, g_int_equal);
184 * @security: Ignored for now.
185 * @stacksize: the size in bytes of the new thread's stack. Use 0 to
186 * default to the normal stack size. (Ignored for now).
187 * @start: The function that the new thread should start with
188 * @param: The parameter to give to @start.
189 * @create: If 0, the new thread is ready to run immediately. If
190 * %CREATE_SUSPENDED, the new thread will be in the suspended state,
191 * requiring a ResumeThread() call to continue running.
192 * @tid: If non-NULL, the ID of the new thread is stored here.
194 * Creates a new threading handle.
196 * Return value: a new handle, or NULL
198 gpointer CreateThread(WapiSecurityAttributes *security G_GNUC_UNUSED, guint32 stacksize,
199 WapiThreadStart start, gpointer param, guint32 create,
202 struct _WapiHandle_thread *thread_handle;
203 struct _WapiHandlePrivate_thread *thread_private_handle;
210 gpointer ct_ret = NULL;
212 mono_once(&thread_hash_once, thread_hash_init);
213 mono_once (&thread_ops_once, thread_ops_init);
219 handle=_wapi_handle_new (WAPI_HANDLE_THREAD);
220 if(handle==_WAPI_HANDLE_INVALID) {
221 g_warning (G_GNUC_PRETTY_FUNCTION
222 ": error creating thread handle");
226 pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
228 thr_ret = _wapi_handle_lock_handle (handle);
229 g_assert (thr_ret == 0);
231 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
232 (gpointer *)&thread_handle,
233 (gpointer *)&thread_private_handle);
235 g_warning (G_GNUC_PRETTY_FUNCTION
236 ": error looking up thread handle %p", handle);
240 /* Hold a reference while the thread is active, because we use
241 * the handle to store thread exit information
243 _wapi_handle_ref (handle);
245 thread_handle->state=THREAD_STATE_START;
247 /* Lock around the thread create, so that the new thread cant
248 * race us to look up the thread handle in GetCurrentThread()
250 pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
251 (void *)&thread_hash_mutex);
252 thr_ret = mono_mutex_lock(&thread_hash_mutex);
253 g_assert (thr_ret == 0);
255 /* Set a 2M stack size. This is the default on Linux, but BSD
256 * needs it. (The original bug report from Martin Dvorak <md@9ll.cz>
257 * set the size to 2M-4k. I don't know why it's short by 4k, so
258 * I'm leaving it as 2M until I'm told differently.)
260 thr_ret = pthread_attr_init(&attr);
261 g_assert (thr_ret == 0);
263 /* defaults of 2Mb for 32bits and 4Mb for 64bits */
265 stacksize = (SIZEOF_VOID_P / 2) * 1024 *1024;
267 #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
268 thr_ret = pthread_attr_setstacksize(&attr, stacksize);
269 g_assert (thr_ret == 0);
272 ret=_wapi_timed_thread_create(&thread_private_handle->thread, &attr,
273 create, start, thread_exit, param,
277 g_message(G_GNUC_PRETTY_FUNCTION ": Thread create error: %s",
280 /* Two, because of the reference we took above */
282 goto thread_hash_cleanup;
286 g_hash_table_insert(thread_hash, &thread_private_handle->thread->id,
290 g_message(G_GNUC_PRETTY_FUNCTION
291 ": Started thread handle %p thread %p ID %ld", handle,
292 thread_private_handle->thread,
293 thread_private_handle->thread->id);
297 #ifdef PTHREAD_POINTER_ID
298 *tid=GPOINTER_TO_UINT(thread_private_handle->thread->id);
300 *tid=thread_private_handle->thread->id;
305 thr_ret = mono_mutex_unlock (&thread_hash_mutex);
306 g_assert (thr_ret == 0);
307 pthread_cleanup_pop (0);
310 thr_ret = _wapi_handle_unlock_handle (handle);
311 g_assert (thr_ret == 0);
312 pthread_cleanup_pop (0);
314 /* Must not call _wapi_handle_unref() with the handle already
317 for (i = 0; i < unrefs; i++) {
318 _wapi_handle_unref (handle);
324 gpointer OpenThread (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED, guint32 tid)
329 mono_once(&thread_hash_once, thread_hash_init);
330 mono_once (&thread_ops_once, thread_ops_init);
333 g_message (G_GNUC_PRETTY_FUNCTION ": looking up thread %d", tid);
336 pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
337 (void *)&thread_hash_mutex);
338 thr_ret = mono_mutex_lock(&thread_hash_mutex);
339 g_assert (thr_ret == 0);
341 ret=g_hash_table_lookup(thread_hash, &tid);
343 thr_ret = mono_mutex_unlock(&thread_hash_mutex);
344 g_assert (thr_ret == 0);
345 pthread_cleanup_pop (0);
348 _wapi_handle_ref (ret);
352 g_message (G_GNUC_PRETTY_FUNCTION ": returning thread handle %p", ret);
360 * @exitcode: Sets the thread's exit code, which can be read from
361 * another thread with GetExitCodeThread().
363 * Terminates the calling thread. A thread can also exit by returning
364 * from its start function. When the last thread in a process
365 * terminates, the process itself terminates.
367 void ExitThread(guint32 exitcode)
369 _wapi_timed_thread_exit(exitcode);
374 * @handle: The thread handle to query
375 * @exitcode: The thread @handle exit code is stored here
377 * Finds the exit code of @handle, and stores it in @exitcode. If the
378 * thread @handle is still running, the value stored is %STILL_ACTIVE.
380 * Return value: %TRUE, or %FALSE on error.
382 gboolean GetExitCodeThread(gpointer handle, guint32 *exitcode)
384 struct _WapiHandle_thread *thread_handle;
385 struct _WapiHandlePrivate_thread *thread_private_handle;
388 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
389 (gpointer *)&thread_handle,
390 (gpointer *)&thread_private_handle);
392 g_warning (G_GNUC_PRETTY_FUNCTION
393 ": error looking up thread handle %p", handle);
398 g_message(G_GNUC_PRETTY_FUNCTION
399 ": Finding exit status for thread handle %p id %ld", handle,
400 thread_private_handle->thread->id);
405 g_message(G_GNUC_PRETTY_FUNCTION
406 ": Nowhere to store exit code");
411 if(thread_handle->state!=THREAD_STATE_EXITED) {
413 g_message(G_GNUC_PRETTY_FUNCTION
414 ": Thread still active (state %d, exited is %d)",
415 thread_handle->state, THREAD_STATE_EXITED);
417 *exitcode=STILL_ACTIVE;
421 *exitcode=thread_handle->exitstatus;
427 * GetCurrentThreadId:
429 * Looks up the thread ID of the current thread. This ID can be
430 * passed to OpenThread() to create a new handle on this thread.
432 * Return value: the thread ID.
434 guint32 GetCurrentThreadId(void)
436 pthread_t tid=pthread_self();
438 #ifdef PTHREAD_POINTER_ID
439 return(GPOINTER_TO_UINT(tid));
445 static gpointer thread_attach(guint32 *tid)
447 struct _WapiHandle_thread *thread_handle;
448 struct _WapiHandlePrivate_thread *thread_private_handle;
454 gpointer ta_ret = NULL;
456 mono_once(&thread_hash_once, thread_hash_init);
457 mono_once (&thread_ops_once, thread_ops_init);
459 handle=_wapi_handle_new (WAPI_HANDLE_THREAD);
460 if(handle==_WAPI_HANDLE_INVALID) {
461 g_warning (G_GNUC_PRETTY_FUNCTION
462 ": error creating thread handle");
466 pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
468 thr_ret = _wapi_handle_lock_handle (handle);
469 g_assert (thr_ret == 0);
471 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
472 (gpointer *)&thread_handle,
473 (gpointer *)&thread_private_handle);
475 g_warning (G_GNUC_PRETTY_FUNCTION
476 ": error looking up thread handle %p", handle);
480 /* Hold a reference while the thread is active, because we use
481 * the handle to store thread exit information
483 _wapi_handle_ref (handle);
485 thread_handle->state=THREAD_STATE_START;
487 /* Lock around the thread create, so that the new thread cant
488 * race us to look up the thread handle in GetCurrentThread()
490 pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
491 (void *)&thread_hash_mutex);
492 thr_ret = mono_mutex_lock(&thread_hash_mutex);
493 g_assert (thr_ret == 0);
495 ret=_wapi_timed_thread_attach(&thread_private_handle->thread,
496 thread_exit, handle);
499 g_message(G_GNUC_PRETTY_FUNCTION ": Thread attach error: %s",
502 /* Two, because of the reference we took above */
505 goto thread_hash_cleanup;
509 g_hash_table_insert(thread_hash, &thread_private_handle->thread->id,
513 g_message(G_GNUC_PRETTY_FUNCTION
514 ": Attached thread handle %p thread %p ID %ld", handle,
515 thread_private_handle->thread,
516 thread_private_handle->thread->id);
520 #ifdef PTHREAD_POINTER_ID
521 *tid=GPOINTER_TO_UINT(thread_private_handle->thread->id);
523 *tid=thread_private_handle->thread->id;
528 thr_ret = mono_mutex_unlock (&thread_hash_mutex);
529 g_assert (thr_ret == 0);
530 pthread_cleanup_pop (0);
533 thr_ret = _wapi_handle_unlock_handle (handle);
534 g_assert (thr_ret == 0);
535 pthread_cleanup_pop (0);
537 /* Must not call _wapi_handle_unref() with the handle already
540 for (i = 0; i < unrefs; i++) {
541 _wapi_handle_unref (handle);
550 * Looks up the handle associated with the current thread. Under
551 * Windows this is a pseudohandle, and must be duplicated with
552 * DuplicateHandle() for some operations.
554 * Return value: The current thread handle, or %NULL on failure.
555 * (Unknown whether Windows has a possible failure here. It may be
556 * necessary to implement the pseudohandle-constant behaviour).
558 gpointer GetCurrentThread(void)
564 mono_once(&thread_hash_once, thread_hash_init);
565 mono_once (&thread_ops_once, thread_ops_init);
567 tid=GetCurrentThreadId();
569 pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
570 (void *)&thread_hash_mutex);
571 thr_ret = mono_mutex_lock(&thread_hash_mutex);
572 g_assert (thr_ret == 0);
574 ret=g_hash_table_lookup(thread_hash, &tid);
576 thr_ret = mono_mutex_unlock(&thread_hash_mutex);
577 g_assert (thr_ret == 0);
578 pthread_cleanup_pop (0);
581 ret = thread_attach (NULL);
589 * @handle: the thread handle to resume
591 * Decrements the suspend count of thread @handle. A thread can only
592 * run if its suspend count is zero.
594 * Return value: the previous suspend count, or 0xFFFFFFFF on error.
596 guint32 ResumeThread(gpointer handle)
598 struct _WapiHandle_thread *thread_handle;
599 struct _WapiHandlePrivate_thread *thread_private_handle;
602 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
603 (gpointer *)&thread_handle,
604 (gpointer *)&thread_private_handle);
606 g_warning (G_GNUC_PRETTY_FUNCTION
607 ": error looking up thread handle %p", handle);
611 #ifdef WITH_INCLUDED_LIBGC
612 if (thread_private_handle->thread->suspend_count <= 1)
613 _wapi_timed_thread_resume (thread_private_handle->thread);
615 return --thread_private_handle->thread->suspend_count;
617 /* This is still a kludge that only copes with starting a
618 * thread that was suspended on create, so don't bother with
619 * the suspend count crap yet
621 _wapi_timed_thread_resume (thread_private_handle->thread);
628 * @handle: the thread handle to suspend
630 * Increments the suspend count of thread @handle. A thread can only
631 * run if its suspend count is zero.
633 * Return value: the previous suspend count, or 0xFFFFFFFF on error.
635 guint32 SuspendThread(gpointer handle)
637 #ifdef WITH_INCLUDED_LIBGC
638 struct _WapiHandle_thread *thread_handle;
639 struct _WapiHandlePrivate_thread *thread_private_handle;
643 current = GetCurrentThread ();
644 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
645 (gpointer *)&thread_handle,
646 (gpointer *)&thread_private_handle);
648 g_warning (G_GNUC_PRETTY_FUNCTION
649 ": error looking up thread handle %p", handle);
653 if (!thread_private_handle->thread->suspend_count) {
654 if (handle == current)
655 _wapi_timed_thread_suspend (thread_private_handle->thread);
657 pthread_kill (thread_private_handle->thread->id, SIGPWR);
658 MONO_SEM_WAIT (&thread_private_handle->thread->suspended_sem);
662 return thread_private_handle->thread->suspend_count++;
669 * We assume here that TLS_MINIMUM_AVAILABLE is less than
670 * PTHREAD_KEYS_MAX, allowing enough overhead for a few TLS keys for
673 * Currently TLS_MINIMUM_AVAILABLE is 64 and _POSIX_THREAD_KEYS_MAX
674 * (the minimum value for PTHREAD_KEYS_MAX) is 128, so we should be
678 static pthread_key_t TLS_keys[TLS_MINIMUM_AVAILABLE];
679 static gboolean TLS_used[TLS_MINIMUM_AVAILABLE]={FALSE};
680 static guint32 TLS_spinlock=0;
685 * Allocates a Thread Local Storage (TLS) index. Any thread in the
686 * same process can use this index to store and retrieve values that
687 * are local to that thread.
689 * Return value: The index value, or %TLS_OUT_OF_INDEXES if no index
692 guint32 TlsAlloc(void)
697 MONO_SPIN_LOCK (TLS_spinlock);
699 for(i=0; i<TLS_MINIMUM_AVAILABLE; i++) {
700 if(TLS_used[i]==FALSE) {
702 thr_ret = pthread_key_create(&TLS_keys[i], NULL);
703 g_assert (thr_ret == 0);
705 MONO_SPIN_UNLOCK (TLS_spinlock);
708 g_message (G_GNUC_PRETTY_FUNCTION ": returning key %d",
716 MONO_SPIN_UNLOCK (TLS_spinlock);
719 g_message (G_GNUC_PRETTY_FUNCTION ": out of indices");
723 return(TLS_OUT_OF_INDEXES);
726 #define MAKE_GC_ID(idx) (GUINT_TO_POINTER((idx)|(GetCurrentThreadId()<<8)))
730 * @idx: The TLS index to free
732 * Releases a TLS index, making it available for reuse. This call
733 * will delete any TLS data stored under index @idx in all threads.
735 * Return value: %TRUE on success, %FALSE otherwise.
737 gboolean TlsFree(guint32 idx)
742 g_message (G_GNUC_PRETTY_FUNCTION ": freeing key %d", idx);
745 MONO_SPIN_LOCK (TLS_spinlock);
747 if(TLS_used[idx]==FALSE) {
748 MONO_SPIN_UNLOCK (TLS_spinlock);
754 thr_ret = pthread_key_delete(TLS_keys[idx]);
755 g_assert (thr_ret == 0);
758 mono_g_hash_table_remove (tls_gc_hash, MAKE_GC_ID (idx));
761 MONO_SPIN_UNLOCK (TLS_spinlock);
768 * @idx: The TLS index to retrieve
770 * Retrieves the TLS data stored under index @idx.
772 * Return value: The value stored in the TLS index @idx in the current
773 * thread, or %NULL on error. As %NULL can be a valid return value,
774 * in this case GetLastError() returns %ERROR_SUCCESS.
776 gpointer TlsGetValue(guint32 idx)
781 g_message (G_GNUC_PRETTY_FUNCTION ": looking up key %d", idx);
784 ret=pthread_getspecific(TLS_keys[idx]);
787 g_message (G_GNUC_PRETTY_FUNCTION ": returning %p", ret);
795 * @idx: The TLS index to store
796 * @value: The value to store under index @idx
798 * Stores @value at TLS index @idx.
800 * Return value: %TRUE on success, %FALSE otherwise.
802 gboolean TlsSetValue(guint32 idx, gpointer value)
807 g_message (G_GNUC_PRETTY_FUNCTION ": setting key %d to %p", idx,
811 MONO_SPIN_LOCK (TLS_spinlock);
813 if(TLS_used[idx]==FALSE) {
815 g_message (G_GNUC_PRETTY_FUNCTION ": key %d unused", idx);
818 MONO_SPIN_UNLOCK (TLS_spinlock);
823 ret=pthread_setspecific(TLS_keys[idx], value);
826 g_message (G_GNUC_PRETTY_FUNCTION
827 ": pthread_setspecific error: %s", strerror (ret));
830 MONO_SPIN_UNLOCK (TLS_spinlock);
837 tls_gc_hash = mono_g_hash_table_new(g_direct_hash, g_direct_equal);
838 mono_g_hash_table_insert (tls_gc_hash, MAKE_GC_ID (idx), value);
841 MONO_SPIN_UNLOCK (TLS_spinlock);
848 * @ms: The time in milliseconds to suspend for
850 * Suspends execution of the current thread for @ms milliseconds. A
851 * value of zero causes the thread to relinquish its time slice. A
852 * value of %INFINITE causes an infinite delay.
854 void Sleep(guint32 ms)
856 struct timespec req, rem;
861 g_message(G_GNUC_PRETTY_FUNCTION ": Sleeping for %d ms", ms);
869 /* FIXME: check for INFINITE and sleep forever */
874 req.tv_nsec=ms_rem*1000000;
877 ret=nanosleep(&req, &rem);
879 /* Sleep interrupted with rem time remaining */
881 guint32 rems=rem.tv_sec*1000 + rem.tv_nsec/1000000;
883 g_message(G_GNUC_PRETTY_FUNCTION ": Still got %d ms to go",
891 /* FIXME: implement alertable */
892 void SleepEx(guint32 ms, gboolean alertable)
894 if(alertable==TRUE) {
895 g_warning(G_GNUC_PRETTY_FUNCTION ": alertable not implemented");
902 BindIoCompletionCallback (gpointer handle,
903 WapiOverlappedCB callback,
908 type = _wapi_handle_type (handle);
909 if (type == WAPI_HANDLE_FILE || type == WAPI_HANDLE_PIPE)
910 return _wapi_io_add_callback (handle, callback, flags);
912 SetLastError (ERROR_NOT_SUPPORTED);
916 #ifdef WITH_INCLUDED_LIBGC
918 static void GC_suspend_handler (int sig)
920 struct _WapiHandle_thread *thread_handle;
921 struct _WapiHandlePrivate_thread *thread_private_handle;
925 handle = GetCurrentThread ();
926 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
927 (gpointer *)&thread_handle,
928 (gpointer *)&thread_private_handle);
930 g_warning (G_GNUC_PRETTY_FUNCTION
931 ": error looking up thread handle %p", handle);
935 thread_private_handle->thread->stack_ptr = &ok;
936 MONO_SEM_POST (&thread_private_handle->thread->suspended_sem);
938 _wapi_timed_thread_suspend (thread_private_handle->thread);
940 thread_private_handle->thread->stack_ptr = NULL;
943 static void gc_init (void)
945 struct sigaction act;
947 act.sa_handler = GC_suspend_handler;
948 g_assert (sigaction (SIGPWR, &act, NULL) == 0);
951 void mono_wapi_push_thread_stack (gpointer handle, gpointer stack_ptr)
953 struct _WapiHandle_thread *thread_handle;
954 struct _WapiHandlePrivate_thread *thread_private_handle;
957 ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
958 (gpointer *)&thread_handle,
959 (gpointer *)&thread_private_handle);
961 g_warning (G_GNUC_PRETTY_FUNCTION
962 ": error looking up thread handle %p", handle);
966 GC_push_all_stack (thread_private_handle->thread->stack_ptr, stack_ptr);
969 #endif /* WITH_INCLUDED_LIBGC */