3 * Threadpool for all concurrent GC work.
5 * Copyright (C) 2015 Xamarin Inc
7 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 #ifndef __MONO_SGEN_THREAD_POOL_H__
11 #define __MONO_SGEN_THREAD_POOL_H__
13 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
15 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
17 struct _SgenThreadPoolJob {
19 SgenThreadPoolJobFunc func;
21 volatile gint32 state;
24 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
25 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
26 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void*);
27 typedef gboolean (*SgenThreadPoolShouldWorkFunc) (void*);
29 void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, SgenThreadPoolShouldWorkFunc should_work_func, void **thread_datas);
31 void sgen_thread_pool_shutdown (void);
33 SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJobFunc func, size_t size);
34 /* This only needs to be called on jobs that are not enqueued. */
35 void sgen_thread_pool_job_free (SgenThreadPoolJob *job);
37 void sgen_thread_pool_job_enqueue (SgenThreadPoolJob *job);
38 /* This must only be called after the job has been enqueued. */
39 void sgen_thread_pool_job_wait (SgenThreadPoolJob *job);
41 void sgen_thread_pool_idle_signal (void);
42 void sgen_thread_pool_idle_wait (void);
44 void sgen_thread_pool_wait_for_all_jobs (void);
46 int sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);