| From a7910aa05fa8ba6e551a4566e187a71d994ebcd2 Mon Sep 17 00:00:00 2001 |
| From: Matt Johnston <matt@codeconstruct.com.au> |
| Date: Thu, 27 Apr 2023 14:25:54 +0800 |
| Subject: [PATCH 03/16] nvme: Simplify Worker::post |
| |
| Add comment for future timeout |
| |
| Signed-off-by: Matt Johnston <matt@codeconstruct.com.au> |
| Change-Id: Ifc05082e737a6d108bc94da5634fc6e95402a232 |
| (cherry picked from commit 393a3e58fcfb8fd5643b8ec42d5d6e37853bdd6b) |
| --- |
| src/NVMeMi.cpp | 17 ++++++++--------- |
| 1 file changed, 8 insertions(+), 9 deletions(-) |
| |
| diff --git a/src/NVMeMi.cpp b/src/NVMeMi.cpp |
| index 695bec8..17825ac 100644 |
| --- a/src/NVMeMi.cpp |
| +++ b/src/NVMeMi.cpp |
| @@ -229,17 +229,16 @@ NVMeMi::~NVMeMi() |
| |
| void NVMeMi::Worker::post(std::function<void(void)>&& func) |
| { |
| - if (!workerStop) |
| + if (workerStop) |
| { |
| - std::unique_lock<std::mutex> lock(workerMtx); |
| - if (!workerStop) |
| - { |
| - workerIO.post(std::move(func)); |
| - workerCv.notify_all(); |
| - return; |
| - } |
| + throw std::runtime_error("NVMeMi has been stopped"); |
| } |
| - throw std::runtime_error("NVMeMi has been stopped"); |
| + |
| + // TODO: need a timeout on this lock so we can return |
| + // a useful "busy" error message when the NVMe-MI endpoint is in-use |
| + std::unique_lock<std::mutex> lock(workerMtx); |
| + workerIO.post(std::move(func)); |
| + workerCv.notify_all(); |
| } |
| |
| void NVMeMi::post(std::function<void(void)>&& func) |
| -- |
| 2.42.0.283.g2d96d420d3-goog |
| |