From 15741411fbd21162f0ba06c55ddeadaf6efdd758 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 30 Sep 2020 21:20:33 +0200 Subject: [PATCH] Support building without io_uring. This is pretty hackish! It would be nice to be able to switch to meson, but TurboPFor makes that a bit tricky right now. --- Makefile | 7 ++++++- io_uring_engine.cpp | 12 ++++++++++++ io_uring_engine.h | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3799b57..c51c41f 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,16 @@ CXXFLAGS ?= -O2 -g -Wall -std=gnu++17 CPPFLAGS=-ITurboPFor-Integer-Compression/ INSTALL ?= install PREFIX ?= /usr/local +URING_LIBS = $(shell pkg-config --libs liburing) + +ifeq ($(URING_LIBS),) + CPPFLAGS += -DWITHOUT_URING +endif all: plocate plocate-build plocate: plocate.o io_uring_engine.o TurboPFor-Integer-Compression/libic.a - $(CXX) -o $@ $^ -lzstd $(shell pkg-config --libs liburing) + $(CXX) -o $@ $^ -lzstd $(URING_LIBS) plocate-build: plocate-build.o TurboPFor-Integer-Compression/libic.a $(CXX) -o $@ $^ -lzstd diff --git a/io_uring_engine.cpp b/io_uring_engine.cpp index b10639d..7714cdb 100644 --- a/io_uring_engine.cpp +++ b/io_uring_engine.cpp @@ -1,5 +1,7 @@ #include +#ifndef WITHOUT_URING #include +#endif #include #include #include @@ -11,7 +13,11 @@ using namespace std; IOUringEngine::IOUringEngine() { +#ifdef WITHOUT_URING + int ret = -1; +#else int ret = io_uring_queue_init(queue_depth, &ring, 0); +#endif using_uring = (ret >= 0); } @@ -26,6 +32,7 @@ void IOUringEngine::submit_read(int fd, size_t len, off_t offset, function cb) { void *buf; @@ -51,6 +60,7 @@ void IOUringEngine::submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, io_uring_sqe_set_data(sqe, pending); ++pending_reads; } +#endif void IOUringEngine::finish() { @@ -58,6 +68,7 @@ void IOUringEngine::finish() return; } +#ifndef WITHOUT_URING int ret = io_uring_submit(&ring); if (ret < 0) { fprintf(stderr, "io_uring_submit: %s\n", strerror(-ret)); @@ -133,6 +144,7 @@ void IOUringEngine::finish() } } } +#endif } void complete_pread(int fd, void *ptr, size_t len, off_t offset) diff --git a/io_uring_engine.h b/io_uring_engine.h index 93e7a0d..59a9d66 100644 --- a/io_uring_engine.h +++ b/io_uring_engine.h @@ -5,7 +5,10 @@ #include #include #include +#ifndef WITHOUT_URING #include +#endif +#include class IOUringEngine { public: @@ -15,9 +18,11 @@ public: size_t get_waiting_reads() const { return pending_reads + queued_reads.size(); } private: +#ifndef WITHOUT_URING void submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, std::function cb); io_uring ring; +#endif size_t pending_reads = 0; // Number of requests we have going in the ring. bool using_uring; -- 2.39.2