MCPcopy Create free account
hub / github.com/apache/brpc / EndRunningUserCodeInPool

Function EndRunningUserCodeInPool

src/brpc/details/usercode_backup_pool.cpp:161–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161void EndRunningUserCodeInPool(void (*fn)(void*), void* arg) {
162 InitUserCodeBackupPoolOnceOrDie();
163
164 g_usercode_inplace.fetch_sub(1, butil::memory_order_relaxed);
165
166 // Not enough idle workers, run the code in backup threads to prevent
167 // all workers from being blocked and no responses will be processed
168 // anymore (deadlocked).
169 const UserCode usercode = { fn, arg };
170 pthread_mutex_lock(&s_usercode_mutex);
171 s_usercode_pool->queue.push_back(usercode);
172 // If the queue has too many items, we can't drop the user code
173 // directly which often must be run, for example: client-side done.
174 // The solution is that we set a mark which is not cleared before
175 // queue becomes short again. RPC code checks the mark before
176 // submitting tasks that may generate more user code.
177 if ((int)s_usercode_pool->queue.size() >=
178 (FLAGS_usercode_backup_threads *
179 FLAGS_max_pending_in_each_backup_thread)) {
180 g_too_many_usercode = true;
181 }
182 pthread_mutex_unlock(&s_usercode_mutex);
183 pthread_cond_signal(&s_usercode_cond);
184}
185
186} // namespace brpc

Callers 4

RunUserCodeFunction · 0.85

Calls 6

pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
fetch_subMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected