Skip to content

Commit

Permalink
issue=#936 threadpool +1ms
Browse files Browse the repository at this point in the history
  • Loading branch information
taocp authored and 00k committed Aug 29, 2016
1 parent c6aa8c1 commit f522974
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/common/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class CondVar {
PthreadCall("condvar wait", pthread_cond_wait(&cond_, &mu_->mu_));
mu_->AfterLock(msg, msg_threshold);
}
// Time wait in ms
// Time wait in us
// timeout < 0 would cause ETIMEOUT and return false immediately
bool TimeWait(int timeout, const char* msg = NULL) {
bool TimeWaitInUs(int timeout, const char* msg = NULL) {
timespec ts;
struct timeval tv;
gettimeofday(&tv, NULL);
int64_t usec = tv.tv_usec + timeout * 1000LL;
int64_t usec = tv.tv_usec + timeout;
ts.tv_sec = tv.tv_sec + usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
int64_t msg_threshold = mu_->msg_threshold_;
Expand All @@ -146,6 +146,11 @@ class CondVar {
mu_->AfterLock(msg, msg_threshold);
return (ret == 0);
}
// Time wait in ms
// timeout < 0 would cause ETIMEOUT and return false immediately
bool TimeWait(int timeout, const char* msg = NULL) {
return TimeWaitInUs(timeout * 1000LL, msg);
}
void Signal() {
PthreadCall("signal", pthread_cond_signal(&cond_));
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ThreadPool {
if (!time_queue_.empty()) {
int64_t now_time = timer::get_micros();
BGItem bg_item = time_queue_.top();
int64_t wait_time = (bg_item.exe_time - now_time) / 1000; // in ms
int64_t wait_time = bg_item.exe_time - now_time; // in us
if (wait_time <= 0) {
time_queue_.pop();
BGMap::iterator it = latest_.find(bg_item.id);
Expand All @@ -207,7 +207,7 @@ class ThreadPool {
}
continue;
} else if (queue_.empty() && !stop_) {
work_cv_.TimeWait(wait_time, "ThreadProcTimeWait");
work_cv_.TimeWaitInUs(wait_time, "ThreadProcTimeWait");
continue;
}
}
Expand Down

0 comments on commit f522974

Please sign in to comment.