[Groonga-commit] groonga/groonga at 5a70bad [master] Add custom thread_limit accessor with grn_ctx

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Aug 8 17:50:20 JST 2018


Kouhei Sutou	2018-08-08 17:50:20 +0900 (Wed, 08 Aug 2018)

  New Revision: 5a70bad32b40b6c18244612ea681850f845ae233
  https://github.com/groonga/groonga/commit/5a70bad32b40b6c18244612ea681850f845ae233

  Message:
    Add custom thread_limit accessor with grn_ctx

  Modified files:
    include/groonga/thread.h
    lib/mrb/mrb_thread.c
    lib/proc.c
    lib/thread.c

  Modified: include/groonga/thread.h (+15 -0)
===================================================================
--- include/groonga/thread.h    2018-08-07 15:00:50 +0900 (c7c8f8014)
+++ include/groonga/thread.h    2018-08-08 17:50:20 +0900 (1ed621e3b)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2015-2016 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -26,6 +27,9 @@ extern "C" {
 GRN_API uint32_t grn_thread_get_limit(void);
 GRN_API void grn_thread_set_limit(uint32_t new_limit);
 
+GRN_API uint32_t grn_thread_get_limit_with_ctx(grn_ctx *ctx);
+GRN_API void grn_thread_set_limit_with_ctx(grn_ctx *ctx, uint32_t new_limit);
+
 
 typedef uint32_t (*grn_thread_get_limit_func)(void *data);
 GRN_API void grn_thread_set_get_limit_func(grn_thread_get_limit_func func,
@@ -34,6 +38,17 @@ typedef void (*grn_thread_set_limit_func)(uint32_t new_limit, void *data);
 GRN_API void grn_thread_set_set_limit_func(grn_thread_set_limit_func func,
                                            void *data);
 
+typedef uint32_t (*grn_thread_get_limit_with_ctx_func)(grn_ctx *ctx,
+                                                       void *data);
+GRN_API void
+grn_thread_set_get_limit_with_ctx_func(grn_thread_get_limit_with_ctx_func func,
+                                       void *data);
+typedef void (*grn_thread_set_limit_with_ctx_func)(grn_ctx *ctx,
+                                                   uint32_t new_limit,
+                                                   void *data);
+GRN_API void grn_thread_set_set_limit_with_ctx_func(grn_thread_set_limit_with_ctx_func func,
+                                                    void *data);
+
 #ifdef __cplusplus
 }
 #endif

  Modified: lib/mrb/mrb_thread.c (+5 -2)
===================================================================
--- lib/mrb/mrb_thread.c    2018-08-07 15:00:50 +0900 (3edab5c37)
+++ lib/mrb/mrb_thread.c    2018-08-08 17:50:20 +0900 (4b3bc4dcb)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2016 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -26,14 +27,16 @@
 static mrb_value
 thread_get_limit(mrb_state *mrb, mrb_value self)
 {
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
   uint32_t limit;
-  limit = grn_thread_get_limit();
+  limit = grn_thread_get_limit_with_ctx(ctx);
   return mrb_fixnum_value(limit);
 }
 
 static mrb_value
 thread_set_limit(mrb_state *mrb, mrb_value self)
 {
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
   mrb_int limit;
 
   mrb_get_args(mrb, "i", &limit);
@@ -42,7 +45,7 @@ thread_set_limit(mrb_state *mrb, mrb_value self)
                "thread limit must be 1 or larger: %S",
                mrb_fixnum_value(limit));
   }
-  grn_thread_set_limit(limit);
+  grn_thread_set_limit_with_ctx(ctx, limit);
   return mrb_nil_value();
 }
 

  Modified: lib/proc.c (+4 -3)
===================================================================
--- lib/proc.c    2018-08-07 15:00:50 +0900 (6d2bca25c)
+++ lib/proc.c    2018-08-08 17:50:20 +0900 (0a4ac0150)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -3772,7 +3773,7 @@ proc_thread_limit(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
   grn_obj *max_bulk;
   uint32_t current_limit;
 
-  current_limit = grn_thread_get_limit();
+  current_limit = grn_thread_get_limit_with_ctx(ctx);
   GRN_OUTPUT_INT64(current_limit);
 
   max_bulk = VAR(0);
@@ -3798,7 +3799,7 @@ proc_thread_limit(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
           max_text);
       return NULL;
     }
-    grn_thread_set_limit(max);
+    grn_thread_set_limit_with_ctx(ctx, max);
   }
 
   return NULL;
@@ -3811,7 +3812,7 @@ proc_database_unmap(grn_ctx *ctx, int nargs, grn_obj **args,
   grn_rc rc;
   uint32_t current_limit;
 
-  current_limit = grn_thread_get_limit();
+  current_limit = grn_thread_get_limit_with_ctx(ctx);
   if (current_limit != 1) {
     ERR(GRN_OPERATION_NOT_PERMITTED,
         "[database_unmap] the max number of threads must be 1: <%u>",

  Modified: lib/thread.c (+42 -0)
===================================================================
--- lib/thread.c    2018-08-07 15:00:50 +0900 (c598b7aa2)
+++ lib/thread.c    2018-08-08 17:50:20 +0900 (f9c3caa55)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2015 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� clear-code.com>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -23,6 +24,11 @@ static void *get_limit_func_data = NULL;
 static grn_thread_set_limit_func set_limit_func = NULL;
 static void *set_limit_func_data = NULL;
 
+static grn_thread_get_limit_with_ctx_func get_limit_with_ctx_func = NULL;
+static void *get_limit_with_ctx_func_data = NULL;
+static grn_thread_set_limit_with_ctx_func set_limit_with_ctx_func = NULL;
+static void *set_limit_with_ctx_func_data = NULL;
+
 uint32_t
 grn_thread_get_limit(void)
 {
@@ -43,6 +49,26 @@ grn_thread_set_limit(uint32_t new_limit)
   set_limit_func(new_limit, set_limit_func_data);
 }
 
+uint32_t
+grn_thread_get_limit_with_ctx(grn_ctx *ctx)
+{
+  if (get_limit_with_ctx_func) {
+    return get_limit_with_ctx_func(ctx, get_limit_with_ctx_func_data);
+  } else {
+    return grn_thread_get_limit();
+  }
+}
+
+void
+grn_thread_set_limit_with_ctx(grn_ctx *ctx, uint32_t new_limit)
+{
+  if (set_limit_with_ctx_func) {
+    set_limit_with_ctx_func(ctx, new_limit, set_limit_func_data);
+  } else {
+    grn_thread_set_limit(new_limit);
+  }
+}
+
 void
 grn_thread_set_get_limit_func(grn_thread_get_limit_func func,
                               void *data)
@@ -57,3 +83,19 @@ grn_thread_set_set_limit_func(grn_thread_set_limit_func func, void *data)
   set_limit_func = func;
   set_limit_func_data = data;
 }
+
+void
+grn_thread_set_get_limit_with_ctx_func(grn_thread_get_limit_with_ctx_func func,
+                                       void *data)
+{
+  get_limit_with_ctx_func = func;
+  get_limit_with_ctx_func_data = data;
+}
+
+void
+grn_thread_set_set_limit_with_ctx_func(grn_thread_set_limit_with_ctx_func func,
+                                       void *data)
+{
+  set_limit_with_ctx_func = func;
+  set_limit_with_ctx_func_data = data;
+}
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180808/ff07e2a0/attachment-0001.htm 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index