2 * sgen-thread-pool.h: Threadpool for all concurrent GC work.
4 * Copyright (C) 2015 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 #ifndef __MONO_SGEN_THREAD_POOL_H__
10 #define __MONO_SGEN_THREAD_POOL_H__
12 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
14 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
16 struct _SgenThreadPoolJob {
18 SgenThreadPoolJobFunc func;
20 volatile gint32 state;
23 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
24 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
25 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void);
27 void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, void **thread_datas);
29 void sgen_thread_pool_shutdown (void);
31 SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJobFunc func, size_t size);
32 /* This only needs to be called on jobs that are not enqueued. */
33 void sgen_thread_pool_job_free (SgenThreadPoolJob *job);
35 void sgen_thread_pool_job_enqueue (SgenThreadPoolJob *job);
36 /* This must only be called after the job has been enqueued. */
37 void sgen_thread_pool_job_wait (SgenThreadPoolJob *job);
39 void sgen_thread_pool_idle_signal (void);
40 void sgen_thread_pool_idle_wait (void);
42 void sgen_thread_pool_wait_for_all_jobs (void);
44 gboolean sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);