First set of licensing changes
[mono.git] / mono / sgen / sgen-thread-pool.h
1 /*
2  * sgen-thread-pool.h: Threadpool for all concurrent GC work.
3  *
4  * Copyright (C) 2015 Xamarin Inc
5  *
6  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
7  */
8
9 #ifndef __MONO_SGEN_THREAD_POOL_H__
10 #define __MONO_SGEN_THREAD_POOL_H__
11
12 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
13
14 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
15
16 struct _SgenThreadPoolJob {
17         const char *name;
18         SgenThreadPoolJobFunc func;
19         size_t size;
20         volatile gint32 state;
21 };
22
23 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
24 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
25 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void);
26
27 void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, void **thread_datas);
28
29 SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJobFunc func, size_t size);
30 /* This only needs to be called on jobs that are not enqueued. */
31 void sgen_thread_pool_job_free (SgenThreadPoolJob *job);
32
33 void sgen_thread_pool_job_enqueue (SgenThreadPoolJob *job);
34 /* This must only be called after the job has been enqueued. */
35 void sgen_thread_pool_job_wait (SgenThreadPoolJob *job);
36
37 void sgen_thread_pool_idle_signal (void);
38 void sgen_thread_pool_idle_wait (void);
39
40 void sgen_thread_pool_wait_for_all_jobs (void);
41
42 gboolean sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);
43
44 #endif