for(uint64_t i = oldcount; i < newcount; i++)
{
// All threads created with the same name
- discard_threads.emplace_back(new DiscardThread(this, i));
+ discard_threads.emplace_back(new DiscardThread(this));
discard_threads.back()->create("bstore_discard");
}
// Decrease? Signal threads after telling them to stop
} else if (newcount < oldcount) {
- std::vector<std::shared_ptr<DiscardThread>> discard_threads_to_stop;
+ std::vector<DiscardThread*> discard_threads_to_stop;
dout(10) << __func__ << " stopping " << (oldcount - newcount) << " existing discard threads" << dendl;
// Signal the last threads to quit, and stop tracking them
discard_cond.notify_all();
discard_threads.resize(newcount);
l.unlock();
- for (auto &t : discard_threads_to_stop) {
+ for (auto t : discard_threads_to_stop) {
t->join();
+ delete t;
}
}
logger->set(l_blk_kernel_discard_threads, discard_threads.size());
discard_queued.swap(other);
}
-void KernelDevice::_discard_thread(uint64_t tid)
+void KernelDevice::_discard_thread(DiscardThread* thr)
{
- dout(10) << __func__ << " thread " << tid << " start" << dendl;
+ dout(10) << __func__ << " thread " << thr << " start" << dendl;
// Thread-local list of processing discards
interval_set<uint64_t> discard_processing;
std::unique_lock l(discard_lock);
discard_cond.notify_all();
- // Keeps the shared pointer around until erased from the vector
- // and until we leave this function
- auto thr = discard_threads[tid];
-
while (true) {
ceph_assert(discard_processing.empty());
if (discard_queued.empty()) {
}
}
- dout(10) << __func__ << " thread " << tid << " finish" << dendl;
+ dout(10) << __func__ << " thread " << thr << " finish" << dendl;
}
// this is private and is expected that the caller checks that discard
struct DiscardThread : public Thread {
KernelDevice *bdev;
- const uint64_t id;
bool stop = false;
- explicit DiscardThread(KernelDevice *b, uint64_t id) : bdev(b), id(id) {}
+ explicit DiscardThread(KernelDevice *b) : bdev(b) {
+ }
void *entry() override {
- bdev->_discard_thread(id);
+ bdev->_discard_thread(this);
return NULL;
}
};
- std::vector<std::shared_ptr<DiscardThread>> discard_threads;
+ std::vector<DiscardThread*> discard_threads;
std::atomic_int injecting_crash;
virtual void _pre_close() { } // hook for child implementations
void _aio_thread();
- void _discard_thread(uint64_t tid);
+ void _discard_thread(DiscardThread* thr);
bool _queue_discard(interval_set<uint64_t> &to_release);
bool try_discard(interval_set<uint64_t> &to_release, bool async = true) override;