Merge pull request #2582 from ludovic-henry/fix-threadpool-starvation
[mono-project.git] / mono / sgen / sgen-thread-pool.h
blob4dcb3a9a14b76195c06f3ccaf396cdf67dd1e9df
1 /*
2 * sgen-thread-pool.h: Threadpool for all concurrent GC work.
4 * Copyright (C) 2015 Xamarin Inc
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;
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.
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.
20 #ifndef __MONO_SGEN_THREAD_POOL_H__
21 #define __MONO_SGEN_THREAD_POOL_H__
23 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
25 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
27 struct _SgenThreadPoolJob {
28 const char *name;
29 SgenThreadPoolJobFunc func;
30 size_t size;
31 volatile gint32 state;
34 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
35 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
36 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void);
38 void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, void **thread_datas);
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);
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);
48 void sgen_thread_pool_idle_signal (void);
49 void sgen_thread_pool_idle_wait (void);
51 void sgen_thread_pool_wait_for_all_jobs (void);
53 gboolean sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);
55 #endif