Debian Codegraph @

lib/proc/proc_thread.c

raw symbols SCIP
1 /*
2 Copyright(C) 2009-2018 Brazil
3 Copyright(C) 2021 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "../grn_ctx.h"
21 #include "../grn_output.h"
22 #include "../grn_proc.h"
23 #include "../grn_logger.h"
24 #include "../grn_str.h"
25
26 #include <groonga/plugin.h>
27
28 static grn_obj *
29 command_thread_limit(grn_ctx *ctx,
30 int n_args,
31 grn_obj **args,
32 grn_user_data *user_data)
33 {
34 grn_obj *max_bulk;
35 uint32_t current_limit;
36
37 current_limit = grn_thread_get_limit_with_ctx(ctx);
38 GRN_OUTPUT_INT64(current_limit);
39
40 max_bulk = grn_plugin_proc_get_var(ctx, user_data, "max", -1);
41 if (GRN_TEXT_LEN(max_bulk) > 0) {
42 uint32_t max;
43 const char *max_text = GRN_TEXT_VALUE(max_bulk);
44 const char *max_text_end;
45 const char *max_text_rest;
46
47 max_text_end = max_text + GRN_TEXT_LEN(max_bulk);
48 max = grn_atoui(max_text, max_text_end, &max_text_rest);
49 if (max_text_rest != max_text_end) {
50 ERR(GRN_INVALID_ARGUMENT,
51 "[thread_limit] max must be unsigned integer value: <%.*s>",
52 (int)GRN_TEXT_LEN(max_bulk),
53 max_text);
54 return NULL;
55 }
56 if (max == 0) {
57 ERR(GRN_INVALID_ARGUMENT,
58 "[thread_limit] max must be 1 or larger: <%.*s>",
59 (int)GRN_TEXT_LEN(max_bulk),
60 max_text);
61 return NULL;
62 }
63 grn_thread_set_limit_with_ctx(ctx, max);
64 }
65
66 return NULL;
67 }
68
69 void
70 grn_proc_init_thread_limit(grn_ctx *ctx)
71 {
72 grn_expr_var vars[1];
73 grn_plugin_expr_var_init(ctx, &(vars[0]), "max", -1);
74 grn_plugin_command_create(ctx,
75 "thread_limit", -1,
76 command_thread_limit,
77 1,
78 vars);
79 }
80
81 static grn_obj *
82 command_thread_dump(grn_ctx *ctx,
83 int n_args,
84 grn_obj **args,
85 grn_user_data *user_data)
86 {
87 grn_thread_dump(ctx);
88 GRN_OUTPUT_BOOL(ctx->rc == GRN_SUCCESS);
89 return NULL;
90 }
91
92 void
93 grn_proc_init_thread_dump(grn_ctx *ctx)
94 {
95 grn_plugin_command_create(ctx,
96 "thread_dump", -1,
97 command_thread_dump,
98 0,
99 NULL);
100 }