4dcb3a9a14b76195c06f3ccaf396cdf67dd1e9df
[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  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License 2.0 as published by the Free Software Foundation;
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License 2.0 along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #ifndef __MONO_SGEN_THREAD_POOL_H__
21 #define __MONO_SGEN_THREAD_POOL_H__
22
23 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
24
25 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
26
27 struct _SgenThreadPoolJob {
28         const char *name;
29         SgenThreadPoolJobFunc func;
30         size_t size;
31         volatile gint32 state;
32 };
33
34 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
35 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
36 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void);
37
38 void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, void **thread_datas);
39
40 SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJobFunc func, size_t size);
41 /* This only needs to be called on jobs that are not enqueued. */
42 void sgen_thread_pool_job_free (SgenThreadPoolJob *job);
43
44 void sgen_thread_pool_job_enqueue (SgenThreadPoolJob *job);
45 /* This must only be called after the job has been enqueued. */
46 void sgen_thread_pool_job_wait (SgenThreadPoolJob *job);
47
48 void sgen_thread_pool_idle_signal (void);
49 void sgen_thread_pool_idle_wait (void);
50
51 void sgen_thread_pool_wait_for_all_jobs (void);
52
53 gboolean sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);
54
55 #endif