]> git.sesse.net Git - plocate/commitdiff
Support building without io_uring.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Wed, 30 Sep 2020 19:20:33 +0000 (21:20 +0200)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Wed, 30 Sep 2020 19:20:33 +0000 (21:20 +0200)
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
io_uring_engine.cpp
io_uring_engine.h

index 3799b57fc2ac803cd5b340f266a1369338a4f503..c51c41f40f7b7a70b365aa3e73701f2d595b4ee2 100644 (file)
--- 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
index b10639df526d49e306f7a499f42917a5010e0d10..7714cdb4f8295f69f6909e712eaf3a9c2523e98f 100644 (file)
@@ -1,5 +1,7 @@
 #include <string.h>
+#ifndef WITHOUT_URING
 #include <liburing.h>
+#endif
 #include <stdint.h>
 #include <unistd.h>
 #include <memory>
@@ -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<void(
                return;
        }
 
+#ifndef WITHOUT_URING
        if (pending_reads < queue_depth) {
                io_uring_sqe *sqe = io_uring_get_sqe(&ring);
                if (sqe == nullptr) {
@@ -36,8 +43,10 @@ void IOUringEngine::submit_read(int fd, size_t len, off_t offset, function<void(
        } else {
                queued_reads.push(QueuedRead{ fd, len, offset, move(cb) });
        }
+#endif
 }
 
+#ifndef WITHOUT_URING
 void IOUringEngine::submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, function<void(string)> 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)
index 93e7a0dc22c21b79fc21a9cdb63c608e9c3d1348..59a9d6651f506e28f9675e910e18fbba34dfd13d 100644 (file)
@@ -5,7 +5,10 @@
 #include <queue>
 #include <string>
 #include <stdint.h>
+#ifndef WITHOUT_URING
 #include <liburing.h>
+#endif
+#include <sys/socket.h>
 
 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<void(std::string)> cb);
 
        io_uring ring;
+#endif
        size_t pending_reads = 0;  // Number of requests we have going in the ring.
        bool using_uring;