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

[IoContext] Add castIfIoFuture() helper function

parent 75d444d3
Branches cast-if-future
No related tags found
No related merge requests found
Pipeline #57433 passed
......@@ -31,13 +31,20 @@
static const uintptr_t IOCONTEXT_TAG = 1L << (sizeof(size_t) * 8 - 1);
static const uintptr_t IOCONTEXT_TAG_MASK = IOCONTEXT_TAG - 1;
static inline auto isIoContext(uintptr_t ptr) -> bool { return (ptr & IOCONTEXT_TAG) != 0; }
namespace emper::io {
static inline auto castIfIoFuture(uintptr_t ptr) -> Future * {
if (ptr & IOCONTEXT_TAG) {
return nullptr;
}
return reinterpret_cast<Future *>(ptr);
}
static inline auto stripIoContextTag(uintptr_t ptr) -> IoContext * {
return reinterpret_cast<IoContext *>(ptr & IOCONTEXT_TAG_MASK);
}
namespace emper::io {
thread_local IoContext *IoContext::workerIo = nullptr;
pthread_t IoContext::globalCompleter;
......@@ -258,9 +265,8 @@ auto IoContext::globalCompleterFunc(void *arg) -> void * {
auto data = (uintptr_t)io_uring_cqe_get_data(cqe);
// The cqe is for a completed Future
if (unlikely(!isIoContext(data))) {
auto *future = reinterpret_cast<Future *>(data);
auto *future = castIfIoFuture(data);
if (unlikely(future)) {
uint32_t res = cqe->res;
io_uring_cqe_seen(&io.ring, cqe);
......
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