Skip to content
Snippets Groups Projects
Commit f7681b3e authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'future_misuse_exeption' into 'master'

[IO] add FutureError and throw it when wait is called on a Future with callback

See merge request !91
parents d560919f a780df5e
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,10 @@ template PartialCompletableFuture::CompletionType
PartialCompletableFuture::tryComplete<CallerEnvironment::ANYWHERE>(int32_t res);
auto Future::wait() -> int32_t {
if (unlikely(callback)) {
throw FutureError("Futures with registered callback must not be awaited");
}
LOGD("Waiting on " << this);
sem.wait();
......
......@@ -11,6 +11,8 @@
#include <cstdlib> // for abort
#include <functional>
#include <ostream> // for operator<<, ostream, basic_ost...
#include <stdexcept>
#include <string>
#include "BinaryPrivateSemaphore.hpp" // for BPS
#include "CallerEnvironment.hpp" // for CallerEnvironment, ANYWHERE
......@@ -25,6 +27,11 @@ struct io_uring_sqe;
namespace emper::io {
class Stats;
class FutureError : public std::logic_error {
friend class Future;
FutureError(const std::string& what) : std::logic_error(what) {}
};
/*
* @brief Future representing an IO request which can be awaited
*/
......@@ -115,6 +122,11 @@ class Future : public Logger<LogSubsystem::IO> {
: op(op), fd(fd), buf(buf), len(len), offsetOrFlags(offsetOrFlags){};
public:
// Clang-tidy warns about the exception possibly thrown by
// ~Future -> cancel -> wait
// But this exception will never be thrown because wait() throws an exception
// only if callback is set and if callback is set ~Future does not call cancel.
// NOLINTNEXTLINE(bugprone-exception-escape)
virtual ~Future() {
if (isForgotten() || callback) {
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment