From: Michael Vrable Date: Tue, 16 Mar 2010 00:22:19 +0000 (-0700) Subject: Provide a simple configurable limit on the number of threads. X-Git-Url: http://git.vrable.net/?p=bluesky.git;a=commitdiff_plain;h=fb15c75f3c8eeb3d7b277795ced44bb4928273a1 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). --- 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);