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

Method UserCodeRunningLoop

src/brpc/details/usercode_backup_pool.cpp:114–144  ·  view source on GitHub ↗

Entry of backup thread for running user code.

Source from the content-addressed store, hash-verified

112
113// Entry of backup thread for running user code.
114void UserCodeBackupPool::UserCodeRunningLoop() {
115 bthread::run_worker_startfn();
116#ifdef BAIDU_INTERNAL
117 logging::ComlogInitializer comlog_initializer;
118#endif
119
120 int64_t last_time = butil::cpuwide_time_us();
121 while (true) {
122 bool blocked = false;
123 UserCode usercode = { NULL, NULL };
124 {
125 BAIDU_SCOPED_LOCK(s_usercode_mutex);
126 while (queue.empty()) {
127 pthread_cond_wait(&s_usercode_cond, &s_usercode_mutex);
128 blocked = true;
129 }
130 usercode = queue.front();
131 queue.pop_front();
132 if (g_too_many_usercode &&
133 (int)queue.size() <= FLAGS_usercode_backup_threads) {
134 g_too_many_usercode = false;
135 }
136 }
137 const int64_t begin_time = (blocked ? butil::cpuwide_time_us() : last_time);
138 usercode.fn(usercode.arg);
139 const int64_t end_time = butil::cpuwide_time_us();
140 inpool_count << 1;
141 inpool_elapse_us << (end_time - begin_time);
142 last_time = end_time;
143 }
144}
145
146static void InitUserCodeBackupPool() {
147 s_usercode_pool = new UserCodeBackupPool;

Callers 1

UserCodeRunnerFunction · 0.80

Calls 6

run_worker_startfnFunction · 0.85
cpuwide_time_usFunction · 0.85
emptyMethod · 0.45
frontMethod · 0.45
pop_frontMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected