Kouhei Sutou
null+****@clear*****
Fri Jul 24 19:07:34 JST 2015
Kouhei Sutou 2015-07-24 19:07:34 +0900 (Fri, 24 Jul 2015) New Revision: 71485a3fdd61d0edb689ba5c18aa91dc8fea991a https://github.com/groonga/groonga/commit/71485a3fdd61d0edb689ba5c18aa91dc8fea991a Message: groonga: support changing the number of threads by thread_count command It's experimental feature. Modified files: src/groonga.c Modified: src/groonga.c (+37 -0) =================================================================== --- src/groonga.c 2015-07-24 19:06:51 +0900 (988fe15) +++ src/groonga.c 2015-07-24 19:07:34 +0900 (e3fff2d) @@ -478,6 +478,32 @@ static grn_mutex q_mutex; static grn_cond q_cond; static uint32_t nthreads = 0, nfthreads = 0, max_nfthreads; +static uint32_t +groonga_get_thread_count(void *data) +{ + return max_nfthreads; +} + +static void +groonga_set_thread_count(uint32_t new_count, void *data) +{ + uint32_t i; + uint32_t current_nfthreads; + + MUTEX_LOCK(q_mutex); + current_nfthreads = nfthreads; + max_nfthreads = new_count; + MUTEX_UNLOCK(q_mutex); + + if (current_nfthreads > new_count) { + for (i = 0; i < current_nfthreads; i++) { + MUTEX_LOCK(q_mutex); + COND_SIGNAL(q_cond); + MUTEX_UNLOCK(q_mutex); + } + } +} + static void reset_ready_notify_pipe(void) { @@ -1921,6 +1947,10 @@ h_worker(void *arg) nfthreads--; goto exit; } + if (nthreads > max_nfthreads) { + nfthreads--; + goto exit; + } } nfthreads--; MUTEX_UNLOCK(q_mutex); @@ -1995,6 +2025,10 @@ g_worker(void *arg) nfthreads--; goto exit; } + if (nthreads > max_nfthreads) { + nfthreads--; + goto exit; + } } ctx = &edge->ctx; nfthreads--; @@ -2946,6 +2980,9 @@ main(int argc, char **argv) max_nfthreads = default_max_num_threads; } + grn_thread_set_get_count_func(groonga_get_thread_count, NULL); + grn_thread_set_set_count_func(groonga_set_thread_count, NULL); + if (input_path) { if (!freopen(input_path, "r", stdin)) { fprintf(stderr, "can't open input file: %s (%s)\n", -------------- next part -------------- HTML����������������������������...Download