Pull aio wait code into an IOContext method too.
Signed-off-by: Sage Weil <sage@redhat.com>
void IOContext::aio_wait()
{
- Mutex::Locker l(lock);
+ std::unique_lock<std::mutex> l(lock);
// see _aio_thread for waker logic
num_waiting.inc();
while (num_running.read() > 0 || num_reading.read() > 0) {
dout(10) << __func__ << " " << this
<< " waiting for " << num_running.read() << " aios and/or "
<< num_reading.read() << " readers to complete" << dendl;
- cond.Wait(lock);
+ cond.wait(l);
}
num_waiting.dec();
dout(20) << __func__ << " " << this << " done" << dendl;
void BlockDevice::queue_reap_ioc(IOContext *ioc)
{
- Mutex::Locker l(ioc_reap_lock);
+ std::lock_guard<std::mutex> l(ioc_reap_lock);
if (ioc_reap_count.read() == 0)
ioc_reap_count.inc();
ioc_reap_queue.push_back(ioc);
void BlockDevice::reap_ioc()
{
if (ioc_reap_count.read()) {
- Mutex::Locker l(ioc_reap_lock);
+ std::lock_guard<std::mutex> l(ioc_reap_lock);
for (auto p : ioc_reap_queue) {
dout(20) << __func__ << " reap ioc " << p << dendl;
delete p;
#ifndef CEPH_OS_BLUESTORE_BLOCKDEVICE_H
#define CEPH_OS_BLUESTORE_BLOCKDEVICE_H
+#include <mutex>
+#include <condition_variable>
+
#include "acconfig.h"
#include "os/fs/FS.h"
void *nvme_task_last = nullptr;
#endif
- Mutex lock;
- Cond cond;
- //interval_set<uint64_t> blocks; ///< blocks with aio in flight
+ std::mutex lock;
+ std::condition_variable cond;
list<FS::aio_t> pending_aios; ///< not yet submitted
list<FS::aio_t> running_aios; ///< submitting or submitted
atomic_t num_waiting;
explicit IOContext(void *p)
- : priv(p),
- lock("IOContext::lock")
+ : priv(p)
{}
// no copying
IOContext &operator=(const IOContext& other);
bool has_aios() {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
return num_pending.read() || num_running.read();
}
void aio_wait();
+
+ void aio_wake() {
+ if (num_waiting.read()) {
+ std::lock_guard<std::mutex> l(lock);
+ cond.notify_all();
+ }
+ }
};
class BlockDevice {
- Mutex ioc_reap_lock;
+ std::mutex ioc_reap_lock;
vector<IOContext*> ioc_reap_queue;
atomic_t ioc_reap_count;
public:
- BlockDevice(): ioc_reap_lock("BlockDevice::ioc_reap_lock") {}
- virtual ~BlockDevice() {}
+ BlockDevice() = default;
+ virtual ~BlockDevice() = default;
typedef void (*aio_callback_t)(void *handle, void *aio);
static BlockDevice *create(
if (left == 0) {
// check waiting count before doing callback (which may
// destroy this ioc).
- if (ioc->num_waiting.read()) {
- dout(20) << __func__ << " waking waiter" << dendl;
- Mutex::Locker l(ioc->lock);
- ioc->cond.Signal();
- }
+ ioc->aio_wake();
if (ioc->priv) {
aio_callback(aio_callback_priv, ioc->priv);
}
out:
_aio_log_finish(ioc, off, len);
ioc->num_reading.dec();
- if (ioc->num_waiting.read()) {
- dout(20) << __func__ << " waking waiter" << dendl;
- Mutex::Locker l(ioc->lock);
- ioc->cond.Signal();
- }
+ ioc->aio_wake();
return r < 0 ? r : 0;
}