-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
The only visible effect of this change is that the constructor no longer takes a name for the finisher thread. Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
// vim: ts=8 sw=2 smarttab | ||
|
||
#include "common/config.h" | ||
#include "common/ceph_time.h" | ||
|
||
#include "Finisher.h" | ||
|
||
#include "common/debug.h" | ||
|
@@ -12,52 +14,53 @@ | |
void Finisher::start() | ||
{ | ||
ldout(cct, 10) << __func__ << dendl; | ||
finisher_thread.create(thread_name.c_str()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cbodley
|
||
finisher_thread = std::thread(&Finisher::finisher_thread_entry, this); | ||
} | ||
|
||
void Finisher::stop() | ||
{ | ||
ldout(cct, 10) << __func__ << dendl; | ||
finisher_lock.Lock(); | ||
finisher_stop = true; | ||
// we don't have any new work to do, but we want the worker to wake up anyway | ||
// to process the stop condition. | ||
finisher_cond.Signal(); | ||
finisher_lock.Unlock(); | ||
{ | ||
lock_guard l(finisher_lock); | ||
finisher_stop = true; | ||
// we don't have any new work to do, but we want the worker to | ||
// wake up anyway to process the stop condition. | ||
finisher_cond.notify_one(); | ||
} | ||
finisher_thread.join(); // wait until the worker exits completely | ||
ldout(cct, 10) << __func__ << " finish" << dendl; | ||
} | ||
|
||
void Finisher::wait_for_empty() | ||
{ | ||
finisher_lock.Lock(); | ||
while (!finisher_queue.empty() || finisher_running) { | ||
ldout(cct, 10) << "wait_for_empty waiting" << dendl; | ||
finisher_empty_cond.Wait(finisher_lock); | ||
} | ||
unique_lock l(finisher_lock); | ||
ldout(cct, 10) << "wait_for_empty waiting" << dendl; | ||
finisher_empty_cond.wait(l, [this] { | ||
return finisher_queue.empty() && !finisher_running; | ||
}); | ||
ldout(cct, 10) << "wait_for_empty empty" << dendl; | ||
finisher_lock.Unlock(); | ||
} | ||
|
||
void *Finisher::finisher_thread_entry() | ||
void Finisher::finisher_thread_entry() | ||
{ | ||
finisher_lock.Lock(); | ||
unique_lock l(finisher_lock); | ||
ldout(cct, 10) << "finisher_thread start" << dendl; | ||
|
||
utime_t start; | ||
ceph::coarse_mono_time start; | ||
while (!finisher_stop) { | ||
/// Every time we are woken up, we process the queue until it is empty. | ||
while (!finisher_queue.empty()) { | ||
if (logger) | ||
start = ceph_clock_now(cct); | ||
start = ceph::coarse_mono_clock::now(); | ||
// To reduce lock contention, we swap out the queue to process. | ||
// This way other threads can submit new contexts to complete while we are working. | ||
// This way other threads can submit new contexts to complete | ||
// while we are working. | ||
vector<Context*> ls; | ||
list<pair<Context*,int> > ls_rval; | ||
ls.swap(finisher_queue); | ||
ls_rval.swap(finisher_queue_rval); | ||
finisher_running = true; | ||
finisher_lock.Unlock(); | ||
l.unlock(); | ||
ldout(cct, 10) << "finisher_thread doing " << ls << dendl; | ||
|
||
// Now actually process the contexts. | ||
|
@@ -78,30 +81,29 @@ void *Finisher::finisher_thread_entry() | |
} | ||
if (logger) { | ||
logger->dec(l_finisher_queue_len); | ||
logger->tinc(l_finisher_complete_lat, ceph_clock_now(cct) - start); | ||
} | ||
logger->tinc(l_finisher_complete_lat, | ||
ceph::coarse_mono_clock::now() - start); | ||
} | ||
} | ||
ldout(cct, 10) << "finisher_thread done with " << ls << dendl; | ||
ls.clear(); | ||
|
||
finisher_lock.Lock(); | ||
l.lock(); | ||
finisher_running = false; | ||
} | ||
ldout(cct, 10) << "finisher_thread empty" << dendl; | ||
finisher_empty_cond.Signal(); | ||
finisher_empty_cond.notify_all(); | ||
if (finisher_stop) | ||
break; | ||
|
||
ldout(cct, 10) << "finisher_thread sleeping" << dendl; | ||
finisher_cond.Wait(finisher_lock); | ||
finisher_cond.wait(l); | ||
} | ||
// If we are exiting, we signal the thread waiting in stop(), | ||
// otherwise it would never unblock | ||
finisher_empty_cond.Signal(); | ||
finisher_empty_cond.notify_all(); | ||
|
||
ldout(cct, 10) << "finisher_thread stop" << dendl; | ||
finisher_stop = false; | ||
finisher_lock.Unlock(); | ||
return 0; | ||
} | ||
|
What about thread names? It appears to me that this reverts ceph#5882 without providing any replacement (or I just don't see it...).