From fb15c75f3c8eeb3d7b277795ced44bb4928273a1 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Mon, 15 Mar 2010 17:22:19 -0700 Subject: [PATCH] Provide a simple configurable limit on the number of threads. Primarily this is meant to make running under valgrind easier, since valgrind can only handle so many threads. By default leave the limit unbounded (the old behavior). --- bluesky/bluesky.h | 4 ++++ bluesky/init.c | 4 ++++ bluesky/store-kv.cc | 3 ++- bluesky/store.c | 4 ++-- nfs3/rpc.c | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index e30f5b0..fdc2e39 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -37,6 +37,10 @@ typedef struct { extern BlueSkyOptions bluesky_options; +/* Maximum number of threads to use in any particular thread pool, or -1 for no + * limit */ +extern int bluesky_max_threads; + /* BlueSky status and error codes. Various frontends should translate these to * the appropriate error code for whatever protocol they implement. */ typedef enum { diff --git a/bluesky/init.c b/bluesky/init.c index 9fb9332..9a7a6eb 100644 --- a/bluesky/init.c +++ b/bluesky/init.c @@ -15,6 +15,10 @@ BlueSkyOptions bluesky_options; +/* Maximum number of threads to use in any particular thread pool, or -1 for no + * limit */ +int bluesky_max_threads = -1; + /* Environment variables that can be used to initialize settings. */ static struct { const char *env; diff --git a/bluesky/store-kv.cc b/bluesky/store-kv.cc index de16832..1318126 100644 --- a/bluesky/store-kv.cc +++ b/bluesky/store-kv.cc @@ -75,7 +75,8 @@ static gpointer kvstore_new(const gchar *path) static volatile gsize once = 0; if (g_once_init_enter(&once)) { - thread_pool = g_thread_pool_new(kvstore_task, NULL, -1, FALSE, NULL); + thread_pool = g_thread_pool_new(kvstore_task, NULL, + bluesky_max_threads, FALSE, NULL); g_once_init_leave(&once, 1); } diff --git a/bluesky/store.c b/bluesky/store.c index 888bd1b..eea44f2 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -472,8 +472,8 @@ static BlueSkyStoreImplementation filestore_impl = { void bluesky_store_init() { store_implementations = g_hash_table_new(g_str_hash, g_str_equal); - notifier_thread_pool = g_thread_pool_new(notifier_task, NULL, -1, FALSE, - NULL); + notifier_thread_pool = g_thread_pool_new(notifier_task, NULL, + bluesky_max_threads, FALSE, NULL); bluesky_store_register(&memstore_impl, "mem"); bluesky_store_register(&filestore_impl, "file"); } diff --git a/nfs3/rpc.c b/nfs3/rpc.c index e1cb4d1..76de1cd 100644 --- a/nfs3/rpc.c +++ b/nfs3/rpc.c @@ -508,7 +508,8 @@ static async_rpc_init() main_context = g_main_context_new(); main_loop = g_main_loop_new(main_context, FALSE); - rpc_thread_pool = g_thread_pool_new(async_rpc_task, NULL, -1, FALSE, NULL); + rpc_thread_pool = g_thread_pool_new(async_rpc_task, NULL, + bluesky_max_threads, FALSE, NULL); /* Arrange to have the cache writeback code run every five seconds. */ GSource *source = g_timeout_source_new_seconds(5); -- 2.20.1