X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fsgen%2Fsgen-thread-pool.h;h=b62e85fe35ba6e552814e9d68b62a7a4000e31f6;hb=2e1afbd7b750d537528fb712353f4b189dce92fa;hp=6e227521a3f6a0932f8fc2ff398abc726078808c;hpb=d34b34c449c9031a3cd3854a072266a1f769276a;p=mono.git diff --git a/mono/sgen/sgen-thread-pool.h b/mono/sgen/sgen-thread-pool.h index 6e227521a3f..b62e85fe35b 100644 --- a/mono/sgen/sgen-thread-pool.h +++ b/mono/sgen/sgen-thread-pool.h @@ -1,28 +1,30 @@ -/* - * sgen-thread-pool.h: Threadpool for all concurrent GC work. +/** + * \file + * Threadpool for all concurrent GC work. * * Copyright (C) 2015 Xamarin Inc * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License 2.0 as published by the Free Software Foundation; - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License 2.0 along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #ifndef __MONO_SGEN_THREAD_POOL_H__ #define __MONO_SGEN_THREAD_POOL_H__ +#include "mono/sgen/sgen-pointer-queue.h" +#include "mono/utils/mono-threads.h" + +#define SGEN_THREADPOOL_MAX_NUM_THREADS 8 +#define SGEN_THREADPOOL_MAX_NUM_CONTEXTS 3 + typedef struct _SgenThreadPoolJob SgenThreadPoolJob; +typedef struct _SgenThreadPoolContext SgenThreadPoolContext; typedef void (*SgenThreadPoolJobFunc) (void *thread_data, SgenThreadPoolJob *job); +typedef void (*SgenThreadPoolThreadInitFunc) (void*); +typedef void (*SgenThreadPoolIdleJobFunc) (void*); +typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void*, int); +typedef gboolean (*SgenThreadPoolShouldWorkFunc) (void*); +typedef gboolean (*SgenThreadPoolContinueIdleWaitFunc) (int, int*); struct _SgenThreadPoolJob { const char *name; @@ -31,11 +33,22 @@ struct _SgenThreadPoolJob { volatile gint32 state; }; -typedef void (*SgenThreadPoolThreadInitFunc) (void*); -typedef void (*SgenThreadPoolIdleJobFunc) (void*); -typedef gboolean (*SgenThreadPoolContinueIdleJobFunc) (void); +struct _SgenThreadPoolContext { + /* Only accessed with the lock held. */ + SgenPointerQueue job_queue; + + SgenThreadPoolThreadInitFunc thread_init_func; + SgenThreadPoolIdleJobFunc idle_job_func; + SgenThreadPoolContinueIdleJobFunc continue_idle_job_func; + SgenThreadPoolShouldWorkFunc should_work_func; + + void **thread_datas; + int num_threads; +}; + -void sgen_thread_pool_init (int num_threads, SgenThreadPoolThreadInitFunc init_func, SgenThreadPoolIdleJobFunc idle_func, SgenThreadPoolContinueIdleJobFunc continue_idle_func, void **thread_datas); +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); +void sgen_thread_pool_start (void); void sgen_thread_pool_shutdown (void); @@ -43,15 +56,15 @@ SgenThreadPoolJob* sgen_thread_pool_job_alloc (const char *name, SgenThreadPoolJ /* This only needs to be called on jobs that are not enqueued. */ void sgen_thread_pool_job_free (SgenThreadPoolJob *job); -void sgen_thread_pool_job_enqueue (SgenThreadPoolJob *job); +void sgen_thread_pool_job_enqueue (int context_id, SgenThreadPoolJob *job); /* This must only be called after the job has been enqueued. */ -void sgen_thread_pool_job_wait (SgenThreadPoolJob *job); +void sgen_thread_pool_job_wait (int context_id, SgenThreadPoolJob *job); -void sgen_thread_pool_idle_signal (void); -void sgen_thread_pool_idle_wait (void); +void sgen_thread_pool_idle_signal (int context_id); +void sgen_thread_pool_idle_wait (int context_id, SgenThreadPoolContinueIdleWaitFunc continue_wait); -void sgen_thread_pool_wait_for_all_jobs (void); +void sgen_thread_pool_wait_for_all_jobs (int context_id); -gboolean sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread); +int sgen_thread_pool_is_thread_pool_thread (MonoNativeThreadId thread); #endif