[netcore] Implement/fix enum/nullable comparers.
[mono-project.git] / mono / sgen / sgen-thread-pool.h
blobb62e85fe35ba6e552814e9d68b62a7a4000e31f6
1 /**
2 * \file
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.
8 */
10 #ifndef __MONO_SGEN_THREAD_POOL_H__
11 #define __MONO_SGEN_THREAD_POOL_H__
13 #include "mono/sgen/sgen-pointer-queue.h"
14 #include "mono/utils/mono-threads.h"
16 #define SGEN_THREADPOOL_MAX_NUM_THREADS 8
17 #define SGEN_THREADPOOL_MAX_NUM_CONTEXTS 3
19 typedef struct _SgenThreadPoolJob SgenThreadPoolJob;
20 typedef struct _SgenThreadPoolContext SgenThreadPoolContext;
22 typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job);
23 typedef void (*SgenThreadPoolThreadInitFunc) (void*);
24 typedef void (*SgenThreadPoolIdleJobFunc) (void*);
25 typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void*, int);
26 typedef gboolean (*SgenThreadPoolShouldWorkFunc) (void*);
27 typedef gboolean (*SgenThreadPoolContinueIdleWaitFunc) (int, int*);
29 struct _SgenThreadPoolJob {
30 const char *name;
31 SgenThreadPoolJobFunc func;
32 size_t size;
33 volatile gint32 state;
36 struct _SgenThreadPoolContext {
37 /* Only accessed with the lock held. */
38 SgenPointerQueue job_queue;
40 SgenThreadPoolThreadInitFunc thread_init_func;
41 SgenThreadPoolIdleJobFunc idle_job_func;
42 SgenThreadPoolContinueIdleJobFunc continue_idle_job_func;
43 SgenThreadPoolShouldWorkFunc should_work_func;
45 void **thread_datas;
46 int num_threads;
50 int sgen_thread_pool_create_context (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, SgenThreadPoolShouldWorkFunc should_work_func, void **thread_datas);
51 void sgen_thread_pool_start (void);
53 void sgen_thread_pool_shutdown (void);
55 SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJobFunc func, size_t size);
56 /* This only needs to be called on jobs that are not enqueued. */
57 void sgen_thread_pool_job_free (SgenThreadPoolJob *job);
59 void sgen_thread_pool_job_enqueue (int context_id, SgenThreadPoolJob *job);
60 /* This must only be called after the job has been enqueued. */
61 void sgen_thread_pool_job_wait (int context_id, SgenThreadPoolJob *job);
63 void sgen_thread_pool_idle_signal (int context_id);
64 void sgen_thread_pool_idle_wait (int context_id, SgenThreadPoolContinueIdleWaitFunc continue_wait);
66 void sgen_thread_pool_wait_for_all_jobs (int context_id);
68 int sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread);
70 #endif