Entry of backup thread for running user code.
| 112 | |
| 113 | // Entry of backup thread for running user code. |
| 114 | void 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 | |
| 146 | static void InitUserCodeBackupPool() { |
| 147 | s_usercode_pool = new UserCodeBackupPool; |
no test coverage detected