ce4bb11e321ee58668336c2a6989fa7ee71d4e6e
[mono.git] / mono / sgen / sgen-thread-pool.h
1 /**
2  * \file
3  * Threadpool for all concurrent GC work.
4  *
5  * Copyright (C) 2015 Xamarin Inc
6  *
7  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8  */
9
10 #ifndef __MONO_SGEN_THREAD_POOL_H__
11 #define __MONO_SGEN_THREAD_POOL_H__
12
13 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
14
15 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
16
17 struct _SgenThreadPoolJob {
18         const char *name;
19         SgenThreadPoolJobFunc func;
20         size_t size;
21         volatile gint32 state;
22 };
23
24 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
25 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
26 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void*);
27 typedef gboolean (*SgenThreadPoolShouldWorkFunc) (void*);
28
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);
30
31 void sgen_thread_pool_shutdown (void);
32
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);
36
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);
40
41 void sgen_thread_pool_idle_signal (void);
42 void sgen_thread_pool_idle_wait (void);
43
44 void sgen_thread_pool_wait_for_all_jobs (void);
45
46 int sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);
47
48 #endif