少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/**
 * \file
 * Low-level threading
 *
 * Author:
 *    Rodrigo Kumpera (kumpera@gmail.com)
 *
 * (C) 2011 Novell, Inc
 */
 
#ifndef __MONO_THREADS_H__
#define __MONO_THREADS_H__
 
#include <mono/utils/mono-os-semaphore.h>
#include <mono/utils/mono-stack-unwinding.h>
#include <mono/utils/mono-linked-list-set.h>
#include <mono/utils/mono-tls.h>
#include <mono/utils/mono-coop-semaphore.h>
#include <mono/utils/os-event.h>
#include <mono/utils/refcount.h>
 
#include <glib.h>
#include <config.h>
#ifdef HOST_WIN32
 
#include <windows.h>
 
typedef DWORD MonoNativeThreadId;
typedef HANDLE MonoNativeThreadHandle; /* unused */
 
typedef DWORD mono_native_thread_return_t;
typedef DWORD mono_thread_start_return_t;
 
#define MONO_NATIVE_THREAD_ID_TO_UINT(tid) (tid)
#define MONO_UINT_TO_NATIVE_THREAD_ID(tid) ((MonoNativeThreadId)(tid))
 
typedef LPTHREAD_START_ROUTINE MonoThreadStart;
 
#else
 
#include <pthread.h>
 
#if defined(__MACH__)
#include <mono/utils/mach-support.h>
 
typedef thread_port_t MonoNativeThreadHandle;
 
#else
 
#include <unistd.h>
 
typedef pid_t MonoNativeThreadHandle;
 
#endif /* defined(__MACH__) */
 
typedef pthread_t MonoNativeThreadId;
 
typedef void* mono_native_thread_return_t;
typedef gsize mono_thread_start_return_t;
 
#define MONO_NATIVE_THREAD_ID_TO_UINT(tid) (gsize)(tid)
#define MONO_UINT_TO_NATIVE_THREAD_ID(tid) (MonoNativeThreadId)(gsize)(tid)
 
typedef gsize (*MonoThreadStart)(gpointer);
 
#if !defined(__HAIKU__)
#define MONO_THREADS_PLATFORM_HAS_ATTR_SETSCHED
#endif /* !defined(__HAIKU__) */
 
#endif /* #ifdef HOST_WIN32 */
 
#ifndef MONO_INFINITE_WAIT
#define MONO_INFINITE_WAIT ((guint32) 0xFFFFFFFF)
#endif
 
typedef struct {
    MonoRefCount ref;
    MonoOSEvent event;
} MonoThreadHandle;
 
/*
THREAD_INFO_TYPE is a way to make the mono-threads module parametric - or sort of.
The GC using mono-threads might extend the MonoThreadInfo struct to add its own
data, this avoid a pointer indirection on what is on a lot of hot paths.
 
But extending MonoThreadInfo has de disavantage that all functions here return type
would require a cast, something like the following:
 
typedef struct {
    MonoThreadInfo info;
    int stuff;
}  MyThreadInfo;
 
...
((MyThreadInfo*)mono_thread_info_current ())->stuff = 1;
 
While porting sgen to use mono-threads, the number of casts required was too much and
code ended up looking horrible. So we use this cute little hack. The idea is that
whomever is including this header can set the expected type to be used by functions here
and reduce the number of casts drastically.
 
*/
#ifndef THREAD_INFO_TYPE
#define THREAD_INFO_TYPE MonoThreadInfo
#endif
 
/* Mono Threads internal configuration knows*/
 
/* If this is defined, use the signals backed on Mach. Debug only as signals can't be made usable on OSX. */
// #define USE_SIGNALS_ON_MACH
 
#ifdef HOST_WASM
#define USE_WASM_BACKEND
#elif defined (_POSIX_VERSION)
#if defined (__MACH__) && !defined (USE_SIGNALS_ON_MACH)
#define USE_MACH_BACKEND
#else
#define USE_POSIX_BACKEND
#endif
#elif HOST_WIN32
#define USE_WINDOWS_BACKEND
#else
#error "no backend support for current platform"
#endif /* defined (_POSIX_VERSION) */
 
enum {
    STATE_STARTING                = 0x00,
    STATE_RUNNING                = 0x01,
    STATE_DETACHED                = 0x02,
 
    STATE_ASYNC_SUSPENDED            = 0x03,
    STATE_SELF_SUSPENDED            = 0x04,
    STATE_ASYNC_SUSPEND_REQUESTED    = 0x05,
    STATE_SELF_SUSPEND_REQUESTED     = 0x06,
    STATE_BLOCKING                    = 0x07,
    STATE_BLOCKING_AND_SUSPENDED    = 0x8,
 
    STATE_MAX                        = 0x08,
 
    THREAD_STATE_MASK            = 0x00FF,
    THREAD_SUSPEND_COUNT_MASK    = 0xFF00,
    THREAD_SUSPEND_COUNT_SHIFT    = 8,
    THREAD_SUSPEND_COUNT_MAX    = 0xFF,
 
    SELF_SUSPEND_STATE_INDEX = 0,
    ASYNC_SUSPEND_STATE_INDEX = 1,
};
 
typedef struct _MonoThreadInfoInterruptToken MonoThreadInfoInterruptToken;
 
typedef struct {
    MonoLinkedListSetNode node;
    guint32 small_id; /*Used by hazard pointers */
    MonoNativeThreadHandle native_handle; /* Valid on mach, android and Windows */
    int thread_state;
 
    /*Tells if this thread was created by the runtime or not.*/
    gboolean runtime_thread;
 
    /* Tells if this thread should be ignored or not by runtime services such as GC and profiling */
    gboolean tools_thread;
 
    /* Max stack bounds, all valid addresses must be between [stack_start_limit, stack_end[ */
    void *stack_start_limit, *stack_end;
 
    /* suspend machinery, fields protected by suspend_semaphore */
    MonoSemType suspend_semaphore;
    int suspend_count;
 
    MonoSemType resume_semaphore;
 
    /* only needed by the posix backend */
#if defined(USE_POSIX_BACKEND)
    MonoSemType finish_resume_semaphore;
    gboolean syscall_break_signal;
    int signal;
#endif
 
    gboolean suspend_can_continue;
 
    /* This memory pool is used by coop GC to save stack data roots between GC unsafe regions */
    GByteArray *stackdata;
 
    /*In theory, only the posix backend needs this, but having it on mach/win32 simplifies things a lot.*/
    MonoThreadUnwindState thread_saved_state [2]; //0 is self suspend, 1 is async suspend.
 
    /*async call machinery, thread MUST be suspended before accessing those fields*/
    void (*async_target)(void*);
    void *user_data;
 
    /*
    If true, this thread is running a critical region of code and cannot be suspended.
    A critical session is implicitly started when you call mono_thread_info_safe_suspend_sync
    and is ended when you call either mono_thread_info_resume or mono_thread_info_finish_suspend.
    */
    gboolean inside_critical_region;
 
    /*
     * If TRUE, the thread is in async context. Code can use this information to avoid async-unsafe
     * operations like locking without having to pass an 'async' parameter around.
     */
    gboolean is_async_context;
 
    /*
     * Values of TLS variables for this thread.
     * This can be used to obtain the values of TLS variable for threads
     * other than the current one.
     */
    gpointer tls [TLS_KEY_NUM];
 
    /* IO layer handle for this thread */
    /* Set when the thread is started, or in _wapi_thread_duplicate () */
    MonoThreadHandle *handle;
 
    void *jit_data;
 
    MonoThreadInfoInterruptToken *interrupt_token;
 
    /* HandleStack for coop handles */
    gpointer handle_stack;
 
    /* Stack mark for targets that explicitly require one */
    gpointer stack_mark;
 
    /* GCHandle to MonoInternalThread */
    guint32 internal_thread_gchandle;
 
    /*
     * Used by the sampling code in mini-posix.c to ensure that a thread has
     * handled a sampling signal before sending another one.
     */
    gint32 profiler_signal_ack;
 
    gint32 thread_pending_native_join;
 
#ifdef USE_WINDOWS_BACKEND
    gint32 thread_wait_info;
#endif
 
} MonoThreadInfo;
 
typedef struct {
    void* (*thread_attach)(THREAD_INFO_TYPE *info);
    /*
    This callback is called right before thread_detach_with_lock. This is called
    without any locks held so it's the place for complicated cleanup.
 
    The thread must remain operational between this call and thread_detach_with_lock.
    It must be possible to successfully suspend it after thread_detach completes.
    */
    void (*thread_detach)(THREAD_INFO_TYPE *info);
    /*
    This callback is called with @info still on the thread list.
    This call is made while holding the suspend lock, so don't do callbacks.
    SMR remains functional as its small_id has not been reclaimed.
    */
    void (*thread_detach_with_lock)(THREAD_INFO_TYPE *info);
    gboolean (*ip_in_critical_region) (MonoDomain *domain, gpointer ip);
    gboolean (*thread_in_critical_region) (THREAD_INFO_TYPE *info);
} MonoThreadInfoCallbacks;
 
typedef struct {
    void (*setup_async_callback) (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data);
    gboolean (*thread_state_init_from_sigctx) (MonoThreadUnwindState *state, void *sigctx);
    gboolean (*thread_state_init_from_handle) (MonoThreadUnwindState *tctx, MonoThreadInfo *info, /*optional*/ void *sigctx);
    void (*thread_state_init) (MonoThreadUnwindState *tctx);
} MonoThreadInfoRuntimeCallbacks;
 
//Not using 0 and 1 to ensure callbacks are not returning bad data
typedef enum {
    MonoResumeThread = 0x1234,
    KeepSuspended = 0x4321,
} SuspendThreadResult;
 
typedef SuspendThreadResult (*MonoSuspendThreadCallback) (THREAD_INFO_TYPE *info, gpointer user_data);
 
static inline gboolean
mono_threads_filter_tools_threads (THREAD_INFO_TYPE *info)
{
    return !((MonoThreadInfo*)info)->tools_thread;
}
 
/*
Requires the world to be stoped
*/
#define FOREACH_THREAD(thread) \
    MONO_LLS_FOREACH_FILTERED (mono_thread_info_list_head (), THREAD_INFO_TYPE, thread, mono_threads_filter_tools_threads)
 
#define FOREACH_THREAD_END \
    MONO_LLS_FOREACH_END
 
/*
Snapshot iteration.
*/
#define FOREACH_THREAD_SAFE(thread) \
    MONO_LLS_FOREACH_FILTERED_SAFE (mono_thread_info_list_head (), THREAD_INFO_TYPE, thread, mono_threads_filter_tools_threads)
 
#define FOREACH_THREAD_SAFE_END \
    MONO_LLS_FOREACH_SAFE_END
 
static inline MonoNativeThreadId
mono_thread_info_get_tid (THREAD_INFO_TYPE *info)
{
    return MONO_UINT_TO_NATIVE_THREAD_ID (((MonoThreadInfo*) info)->node.key);
}
 
static inline void
mono_thread_info_set_tid (THREAD_INFO_TYPE *info, MonoNativeThreadId tid)
{
    ((MonoThreadInfo*) info)->node.key = (uintptr_t) MONO_NATIVE_THREAD_ID_TO_UINT (tid);
}
 
void
mono_thread_info_cleanup (void);
 
/*
 * @thread_info_size is sizeof (GcThreadInfo), a struct the GC defines to make it possible to have
 * a single block with info from both camps. 
 */
void
mono_thread_info_init (size_t thread_info_size);
 
void
mono_thread_info_callbacks_init (MonoThreadInfoCallbacks *callbacks);
 
void
mono_thread_info_signals_init (void);
 
void
mono_thread_info_runtime_init (MonoThreadInfoRuntimeCallbacks *callbacks);
 
MonoThreadInfoRuntimeCallbacks *
mono_threads_get_runtime_callbacks (void);
 
MONO_API int
mono_thread_info_register_small_id (void);
 
THREAD_INFO_TYPE *
mono_thread_info_attach (void);
 
MONO_API void
mono_thread_info_detach (void);
 
gboolean
mono_thread_info_try_get_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 *gchandle);
 
void
mono_thread_info_set_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 gchandle);
 
void
mono_thread_info_unset_internal_thread_gchandle (THREAD_INFO_TYPE *info);
 
gboolean
mono_thread_info_is_exiting (void);
 
THREAD_INFO_TYPE *
mono_thread_info_current (void);
 
THREAD_INFO_TYPE*
mono_thread_info_current_unchecked (void);
 
MONO_API int
mono_thread_info_get_small_id (void);
 
MonoLinkedListSet*
mono_thread_info_list_head (void);
 
THREAD_INFO_TYPE*
mono_thread_info_lookup (MonoNativeThreadId id);
 
gboolean
mono_thread_info_resume (MonoNativeThreadId tid);
 
void
mono_thread_info_safe_suspend_and_run (MonoNativeThreadId id, gboolean interrupt_kernel, MonoSuspendThreadCallback callback, gpointer user_data);
 
void
mono_thread_info_setup_async_call (THREAD_INFO_TYPE *info, void (*target_func)(void*), void *user_data);
 
void
mono_thread_info_suspend_lock (void);
 
void
mono_thread_info_suspend_unlock (void);
 
void
mono_thread_info_abort_socket_syscall_for_close (MonoNativeThreadId tid);
 
void
mono_thread_info_set_is_async_context (gboolean async_context);
 
gboolean
mono_thread_info_is_async_context (void);
 
void
mono_thread_info_get_stack_bounds (guint8 **staddr, size_t *stsize);
 
MONO_API gboolean
mono_thread_info_yield (void);
 
gint
mono_thread_info_sleep (guint32 ms, gboolean *alerted);
 
gint
mono_thread_info_usleep (guint64 us);
 
gpointer
mono_thread_info_tls_get (THREAD_INFO_TYPE *info, MonoTlsKey key);
 
void
mono_thread_info_tls_set (THREAD_INFO_TYPE *info, MonoTlsKey key, gpointer value);
 
void
mono_thread_info_exit (gsize exit_code);
 
void
mono_thread_info_install_interrupt (void (*callback) (gpointer data), gpointer data, gboolean *interrupted);
 
void
mono_thread_info_uninstall_interrupt (gboolean *interrupted);
 
MonoThreadInfoInterruptToken*
mono_thread_info_prepare_interrupt (THREAD_INFO_TYPE *info);
 
void
mono_thread_info_finish_interrupt (MonoThreadInfoInterruptToken *token);
 
void
mono_thread_info_self_interrupt (void);
 
void
mono_thread_info_clear_self_interrupt (void);
 
gboolean
mono_thread_info_is_interrupt_state (THREAD_INFO_TYPE *info);
 
void
mono_thread_info_describe_interrupt_token (THREAD_INFO_TYPE *info, GString *text);
 
gboolean
mono_thread_info_is_live (THREAD_INFO_TYPE *info);
 
int
mono_threads_get_max_stack_size (void);
 
MonoThreadHandle*
mono_threads_open_thread_handle (MonoThreadHandle *handle);
 
void
mono_threads_close_thread_handle (MonoThreadHandle *handle);
 
MONO_API void
mono_threads_attach_tools_thread (void);
 
 
#if !defined(HOST_WIN32)
 
/*Use this instead of pthread_kill */
int
mono_threads_pthread_kill (THREAD_INFO_TYPE *info, int signum);
 
#endif /* !defined(HOST_WIN32) */
 
/* Internal API between mono-threads and its backends. */
 
/* Backend functions - a backend must implement all of the following */
/*
This is called very early in the runtime, it cannot access any runtime facilities.
 
*/
void mono_threads_suspend_init (void); //ok
 
void mono_threads_suspend_init_signals (void);
 
void mono_threads_coop_init (void);
 
/*
This begins async suspend. This function must do the following:
 
-Ensure the target will EINTR any syscalls if @interrupt_kernel is true
-Call mono_threads_transition_finish_async_suspend as part of its async suspend.
-Register the thread for pending suspend with mono_threads_add_to_pending_operation_set if needed.
 
If begin suspend fails the thread must be left uninterrupted and resumed.
*/
gboolean mono_threads_suspend_begin_async_suspend (THREAD_INFO_TYPE *info, gboolean interrupt_kernel);
 
/*
This verifies the outcome of an async suspend operation.
 
Some targets, such as posix, verify suspend results assynchronously. Suspend results must be
available (in a non blocking way) after mono_threads_wait_pending_operations completes.
*/
gboolean mono_threads_suspend_check_suspend_result (THREAD_INFO_TYPE *info);
 
/*
This begins async resume. This function must do the following:
 
- Install an async target if one was requested.
- Notify the target to resume.
- Register the thread for pending ack with mono_threads_add_to_pending_operation_set if needed.
*/
gboolean mono_threads_suspend_begin_async_resume (THREAD_INFO_TYPE *info);
 
void mono_threads_suspend_register (THREAD_INFO_TYPE *info); //ok
void mono_threads_suspend_free (THREAD_INFO_TYPE *info);
void mono_threads_suspend_abort_syscall (THREAD_INFO_TYPE *info);
gint mono_threads_suspend_search_alternative_signal (void);
gint mono_threads_suspend_get_suspend_signal (void);
gint mono_threads_suspend_get_restart_signal (void);
gint mono_threads_suspend_get_abort_signal (void);
 
gboolean
mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data,
    gsize* const stack_size, MonoNativeThreadId *tid);
 
void mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize);
void mono_threads_platform_init (void);
gboolean mono_threads_platform_in_critical_region (MonoNativeThreadId tid);
gboolean mono_threads_platform_yield (void);
void mono_threads_platform_exit (gsize exit_code);
 
void mono_threads_coop_begin_global_suspend (void);
void mono_threads_coop_end_global_suspend (void);
 
MONO_API MonoNativeThreadId
mono_native_thread_id_get (void);
 
MONO_API gboolean
mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2);
 
MONO_API gboolean
mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg);
 
MONO_API void
mono_native_thread_set_name (MonoNativeThreadId tid, const char *name);
 
MONO_API gboolean
mono_native_thread_join (MonoNativeThreadId tid);
 
/*Mach specific internals */
void mono_threads_init_dead_letter (void);
void mono_threads_install_dead_letter (void);
 
/* mono-threads internal API used by the backends. */
/*
This tells the suspend initiator that we completed suspend and will now be waiting for resume.
*/
void mono_threads_notify_initiator_of_suspend (THREAD_INFO_TYPE* info);
/*
This tells the resume initiator that we completed resume duties and will return to runnable state.
*/
void mono_threads_notify_initiator_of_resume (THREAD_INFO_TYPE* info);
 
/*
This tells the resume initiator that we completed abort duties and will return to previous state.
*/
void mono_threads_notify_initiator_of_abort (THREAD_INFO_TYPE* info);
 
/* Thread state machine functions */
 
typedef enum {
    ResumeError,
    ResumeOk,
    ResumeInitSelfResume,
    ResumeInitAsyncResume,
    ResumeInitBlockingResume,
} MonoResumeResult;
 
typedef enum {
    SelfSuspendResumed,
    SelfSuspendWait,
    SelfSuspendNotifyAndWait,
} MonoSelfSupendResult;
 
typedef enum {
    AsyncSuspendAlreadySuspended,
    AsyncSuspendWait,
    AsyncSuspendInitSuspend,
    AsyncSuspendBlocking,
} MonoRequestAsyncSuspendResult;
 
typedef enum {
    DoBlockingContinue, //in blocking mode, continue
    DoBlockingPollAndRetry, //async suspend raced blocking and won, pool and retry
} MonoDoBlockingResult;
 
typedef enum {
    DoneBlockingOk, //exited blocking fine
    DoneBlockingWait, //thread should end suspended
} MonoDoneBlockingResult;
 
 
typedef enum {
    AbortBlockingIgnore, //Ignore
    AbortBlockingIgnoreAndPoll, //Ignore and poll
    AbortBlockingOk, //Abort worked
    AbortBlockingWait, //Abort worked, but should wait for resume
} MonoAbortBlockingResult;
 
 
void mono_threads_transition_attach (THREAD_INFO_TYPE* info);
gboolean mono_threads_transition_detach (THREAD_INFO_TYPE *info);
MonoRequestAsyncSuspendResult mono_threads_transition_request_async_suspension (THREAD_INFO_TYPE *info);
MonoSelfSupendResult mono_threads_transition_state_poll (THREAD_INFO_TYPE *info);
MonoResumeResult mono_threads_transition_request_resume (THREAD_INFO_TYPE* info);
gboolean mono_threads_transition_finish_async_suspend (THREAD_INFO_TYPE* info);
MonoDoBlockingResult mono_threads_transition_do_blocking (THREAD_INFO_TYPE* info);
MonoDoneBlockingResult mono_threads_transition_done_blocking (THREAD_INFO_TYPE* info);
MonoAbortBlockingResult mono_threads_transition_abort_blocking (THREAD_INFO_TYPE* info);
 
MonoThreadUnwindState* mono_thread_info_get_suspend_state (THREAD_INFO_TYPE *info);
 
gpointer
mono_threads_enter_gc_unsafe_region_cookie (void);
 
 
void mono_thread_info_wait_for_resume (THREAD_INFO_TYPE *info);
/* Advanced suspend API, used for suspending multiple threads as once. */
gboolean mono_thread_info_is_running (THREAD_INFO_TYPE *info);
gboolean mono_thread_info_is_live (THREAD_INFO_TYPE *info);
int mono_thread_info_suspend_count (THREAD_INFO_TYPE *info);
int mono_thread_info_current_state (THREAD_INFO_TYPE *info);
const char* mono_thread_state_name (int state);
gboolean mono_thread_is_gc_unsafe_mode (void);
 
gboolean mono_thread_info_in_critical_location (THREAD_INFO_TYPE *info);
gboolean mono_thread_info_begin_suspend (THREAD_INFO_TYPE *info);
gboolean mono_thread_info_begin_resume (THREAD_INFO_TYPE *info);
 
void mono_threads_add_to_pending_operation_set (THREAD_INFO_TYPE* info); //XXX rename to something to reflect the fact that this is used for both suspend and resume
gboolean mono_threads_wait_pending_operations (void);
void mono_threads_begin_global_suspend (void);
void mono_threads_end_global_suspend (void);
 
gboolean
mono_thread_info_is_current (THREAD_INFO_TYPE *info);
 
typedef enum {
    MONO_THREAD_INFO_WAIT_RET_SUCCESS_0   =  0,
    MONO_THREAD_INFO_WAIT_RET_ALERTED     = -1,
    MONO_THREAD_INFO_WAIT_RET_TIMEOUT     = -2,
    MONO_THREAD_INFO_WAIT_RET_FAILED      = -3,
} MonoThreadInfoWaitRet;
 
MonoThreadInfoWaitRet
mono_thread_info_wait_one_handle (MonoThreadHandle *handle, guint32 timeout, gboolean alertable);
 
MonoThreadInfoWaitRet
mono_thread_info_wait_multiple_handle (MonoThreadHandle **thread_handles, gsize nhandles, MonoOSEvent *background_change_event, gboolean waitall, guint32 timeout, gboolean alertable);
 
void mono_threads_join_lock (void);
void mono_threads_join_unlock (void);
 
 
#ifdef HOST_WASM
typedef void (*background_job_cb)(void);
void mono_threads_schedule_background_job (background_job_cb cb);
#endif
 
#endif /* __MONO_THREADS_H__ */