[Groonga-commit] groonga/groonga at 3fc90d5 [master] thread_limit: support request cancel

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Aug 8 17:51:22 JST 2018


Kouhei Sutou	2018-08-08 17:51:22 +0900 (Wed, 08 Aug 2018)

  New Revision: 3fc90d56c53139352a10302af4f4e30e286ecc0d
  https://github.com/groonga/groonga/commit/3fc90d56c53139352a10302af4f4e30e286ecc0d

  Message:
    thread_limit: support request cancel

  Modified files:
    src/groonga.c

  Modified: src/groonga.c (+16 -1)
===================================================================
--- src/groonga.c    2018-08-08 17:50:20 +0900 (f54b08e9e)
+++ src/groonga.c    2018-08-08 17:51:22 +0900 (bb53d28aa)
@@ -512,10 +512,11 @@ groonga_get_thread_limit(void *data)
 }
 
 static void
-groonga_set_thread_limit(uint32_t new_limit, void *data)
+groonga_set_thread_limit_with_ctx(grn_ctx *ctx, uint32_t new_limit, void *data)
 {
   uint32_t i;
   uint32_t current_n_floating_threads;
+  uint32_t current_max_n_floating_threads;
   static uint32_t n_changing_threads = 0;
   uint32_t prev_n_changing_threads;
 
@@ -523,6 +524,7 @@ groonga_set_thread_limit(uint32_t new_limit, void *data)
 
   CRITICAL_SECTION_ENTER(q_critical_section);
   current_n_floating_threads = n_floating_threads;
+  current_max_n_floating_threads = max_n_floating_threads;
   max_n_floating_threads = new_limit;
   CRITICAL_SECTION_LEAVE(q_critical_section);
 
@@ -550,12 +552,24 @@ groonga_set_thread_limit(uint32_t new_limit, void *data)
     if (is_reduced) {
       break;
     }
+    if (ctx && ctx->rc == GRN_CANCEL) {
+      CRITICAL_SECTION_ENTER(q_critical_section);
+      max_n_floating_threads = current_max_n_floating_threads;
+      CRITICAL_SECTION_LEAVE(q_critical_section);
+      break;
+    }
     grn_nanosleep(1000000);
   }
 
   GRN_ATOMIC_ADD_EX(&n_changing_threads, -1, prev_n_changing_threads);
 }
 
+static void
+groonga_set_thread_limit(uint32_t new_limit, void *data)
+{
+  groonga_set_thread_limit_with_ctx(NULL, new_limit, data);
+}
+
 typedef struct {
   grn_mutex mutex;
   grn_ctx ctx;
@@ -3571,6 +3585,7 @@ main(int argc, char **argv)
 
   grn_thread_set_get_limit_func(groonga_get_thread_limit, NULL);
   grn_thread_set_set_limit_func(groonga_set_thread_limit, NULL);
+  grn_thread_set_set_limit_with_ctx_func(groonga_set_thread_limit_with_ctx, NULL);
 
   if (output_fd_arg) {
     const char * const end = output_fd_arg + strlen(output_fd_arg);
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180808/649a8f4d/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index