Debian Codegraph @

lib/request_canceler.c

raw symbols SCIP
1 /*
2 Copyright(C) 2014-2016 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/
20 #include "grn_ctx_impl.h"cxx . . $ `<file>/lib/grn_ctx_impl.h`/
21 #include "grn_request_canceler.h"cxx . . $ `<file>/lib/grn_request_canceler.h`/
22
23 typedef struct _grn_request_cancelercxx . . $ _grn_request_canceler# grn_request_cancelercxx . . $ grn_request_canceler#;
24 struct _grn_request_cancelercxx . . $ _grn_request_canceler# {
25 grn_hashcxx . . $ grn_hash# *entriescxx . . $ _grn_request_canceler#entries.;
26 grn_mutexcxx . . $ grn_mutex# mutexcxx . . $ _grn_request_canceler#mutex.;
27 };
28
29 typedef struct _grn_request_canceler_entrycxx . . $ _grn_request_canceler_entry# grn_request_canceler_entrycxx . . $ grn_request_canceler_entry#;
30 struct _grn_request_canceler_entrycxx . . $ _grn_request_canceler_entry# {
31 grn_ctxcxx . . $ grn_ctx# *ctxcxx . . $ _grn_request_canceler_entry#ctx.;
32 };
33
34 static grn_ctxcxx . . $ grn_ctx# grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.;
35 static grn_request_cancelercxx . . $ grn_request_canceler# *grn_the_request_cancelercxx . . $ grn_the_request_canceler. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
36
37 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
38 grn_request_canceler_initcxx . . $ grn_request_canceler_init(c9857a73d68e59ba).(void)
39 {
40 grn_ctxcxx . . $ grn_ctx# *ctx = &grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.;
41
42 grn_ctx_initcxx . . $ grn_ctx_init(670fdc69e3f5dbb5).(ctx, 0);
43
44 grn_the_request_cancelercxx . . $ grn_the_request_canceler. = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_request_canceler));
45 if (!grn_the_request_cancelercxx . . $ grn_the_request_canceler.) {
46 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
47 "[request-canceler] failed to allocate the global request canceler");
48 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
49 }
50
51 grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries. =
52 grn_hash_createcxx . . $ grn_hash_create(db1bba7e0d64660).(ctx, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!,
53 sizeof(grn_request_canceler_entrycxx . . $ grn_request_canceler_entry#), GRN_OBJ_KEY_VAR_SIZEcxx . . $ `include/groonga/groonga.h:820:9`!);
54 if (!grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.) {
55 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
56 }
57 MUTEX_INITcxx . . $ `lib/grn.h:219:11`!(grn_the_request_canceler->mutex);
58
59 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
60 }
61
62 void
63 grn_request_canceler_registercxx . . $ grn_request_canceler_register(ae297cf89bde2f1f).(grn_ctxcxx . . $ grn_ctx# *ctx,
64 const char *request_id, unsigned int size)
65 {
66 MUTEX_LOCKcxx . . $ `lib/grn.h:220:11`!(grn_the_request_canceler->mutex);
67 {
68 grn_hashcxx . . $ grn_hash# *entries = grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.;
69 grn_idcxx . . $ grn_id# id;
70 void *value;
71 id = grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(&grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.,
72 entries, request_id, size, &value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
73 if (id) {
74 grn_request_canceler_entrycxx . . $ grn_request_canceler_entry# *entry = value;
75 entry->ctxcxx . . $ _grn_request_canceler_entry#ctx. = ctx;
76 }
77 }
78 MUTEX_UNLOCKcxx . . $ `lib/grn.h:222:11`!(grn_the_request_canceler->mutex);
79 }
80
81 void
82 grn_request_canceler_unregistercxx . . $ grn_request_canceler_unregister(ae297cf89bde2f1f).(grn_ctxcxx . . $ grn_ctx# *ctx,
83 const char *request_id, unsigned int size)
84 {
85 MUTEX_LOCKcxx . . $ `lib/grn.h:220:11`!(grn_the_request_canceler->mutex);
86 {
87 grn_hashcxx . . $ grn_hash# *entries = grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.;
88 grn_hash_deletecxx . . $ grn_hash_delete(c1719313595c9549).(&grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.,
89 entries, request_id, size, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
90 }
91 MUTEX_UNLOCKcxx . . $ `lib/grn.h:222:11`!(grn_the_request_canceler->mutex);
92
93 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_CANCELcxx . . $ GRN_CANCEL.) {
94 ERRSETcxx . . $ `lib/grn_error.h:140:9`!(ctx, GRN_LOG_NOTICE, ctx->rc,
95 "[request-canceler] a request is canceled: <%.*s>",
96 size, request_id);
97 }
98 }
99
100 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
101 grn_request_canceler_cancel_entrycxx . . $ grn_request_canceler_cancel_entry(222c1faf785e744f).(grn_request_canceler_entrycxx . . $ grn_request_canceler_entry# *entry)
102 {
103 if (entry->ctxcxx . . $ _grn_request_canceler_entry#ctx.->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
104 entry->ctxcxx . . $ _grn_request_canceler_entry#ctx.->rccxx . . $ _grn_ctx#rc. = GRN_CANCELcxx . . $ GRN_CANCEL.;
105 if (entry->ctxcxx . . $ _grn_request_canceler_entry#ctx.->implcxx . . $ _grn_ctx#impl.->current_request_timer_idcxx . . $ _grn_ctx_impl#current_request_timer_id.) {
106 void *timer_id = entry->ctxcxx . . $ _grn_request_canceler_entry#ctx.->implcxx . . $ _grn_ctx#impl.->current_request_timer_idcxx . . $ _grn_ctx_impl#current_request_timer_id.;
107 entry->ctxcxx . . $ _grn_request_canceler_entry#ctx.->implcxx . . $ _grn_ctx#impl.->current_request_timer_idcxx . . $ _grn_ctx_impl#current_request_timer_id. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
108 grn_request_timer_unregistercxx . . $ grn_request_timer_unregister(5d22bdacc48458e8).(timer_id);
109 }
110 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
111 }
112 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
113 }
114
115 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
116 grn_request_canceler_cancelcxx . . $ grn_request_canceler_cancel(8d229d683d6d7295).(const char *request_id, unsigned int size)
117 {
118 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! canceled = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
119 MUTEX_LOCKcxx . . $ `lib/grn.h:220:11`!(grn_the_request_canceler->mutex);
120 {
121 grn_ctxcxx . . $ grn_ctx# *ctx = &grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.;
122 grn_hashcxx . . $ grn_hash# *entries = grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.;
123 void *value;
124 if (grn_hash_getcxx . . $ grn_hash_get(4e868e5367e71b67).(ctx, entries, request_id, size, &value)) {
125 grn_request_canceler_entrycxx . . $ grn_request_canceler_entry# *entry = value;
126 if (grn_request_canceler_cancel_entrycxx . . $ grn_request_canceler_cancel_entry(222c1faf785e744f).(entry)) {
127 canceled = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
128 }
129 }
130 }
131 MUTEX_UNLOCKcxx . . $ `lib/grn.h:222:11`!(grn_the_request_canceler->mutex);
132 return canceled;
133 }
134
135 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
136 grn_request_canceler_cancel_allcxx . . $ grn_request_canceler_cancel_all(c9857a73d68e59ba).(void)
137 {
138 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! canceled = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
139 MUTEX_LOCKcxx . . $ `lib/grn.h:220:11`!(grn_the_request_canceler->mutex);
140 {
141 grn_ctxcxx . . $ grn_ctx# *ctx = &grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.;
142 grn_hashcxx . . $ grn_hash# *entries = grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.;
143 grn_hash_cursorcxx . . $ grn_hash_cursor# *cursor;
144
145 cursor = grn_hash_cursor_opencxx . . $ grn_hash_cursor_open(d9a98562cd457d90).(ctx, entries,
146 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0,
147 0, -1, 0);
148 if (cursor) {
149 while (grn_hash_cursor_nextcxx . . $ grn_hash_cursor_next(6f2ad840d1580522).(ctx, cursor) != GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
150 void *value;
151 if (grn_hash_cursor_get_valuecxx . . $ grn_hash_cursor_get_value(248c0d78df691c42).(ctx, cursor, &value) > 0) {
152 grn_request_canceler_entrycxx . . $ grn_request_canceler_entry# *entry = value;
153 if (grn_request_canceler_cancel_entrycxx . . $ grn_request_canceler_cancel_entry(222c1faf785e744f).(entry)) {
154 canceled = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
155 }
156 }
157 }
158 grn_hash_cursor_closecxx . . $ grn_hash_cursor_close(7eec73c6b4523bff).(ctx, cursor);
159 }
160 }
161 MUTEX_UNLOCKcxx . . $ `lib/grn.h:222:11`!(grn_the_request_canceler->mutex);
162 return canceled;
163 }
164
165 void
166 grn_request_canceler_fincxx . . $ grn_request_canceler_fin(49f6e7a06ebc5aa8).(void)
167 {
168 grn_ctxcxx . . $ grn_ctx# *ctx = &grn_the_request_canceler_ctxcxx . . $ grn_the_request_canceler_ctx.;
169
170 grn_hash_closecxx . . $ grn_hash_close(c005d027d163fb0b).(ctx, grn_the_request_cancelercxx . . $ grn_the_request_canceler.->entriescxx . . $ _grn_request_canceler#entries.);
171 MUTEX_FINcxx . . $ `lib/grn.h:223:11`!(grn_the_request_canceler->mutex);
172 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(grn_the_request_canceler);
173 grn_the_request_cancelercxx . . $ grn_the_request_canceler. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
174 grn_ctx_fincxx . . $ grn_ctx_fin(2b4fa601bf4f1e5b).(ctx);
175 }