]> git.sesse.net Git - plocate/blobdiff - access_rx_cache.h
Move AccessRXCache into its own file.
[plocate] / access_rx_cache.h
diff --git a/access_rx_cache.h b/access_rx_cache.h
new file mode 100644 (file)
index 0000000..8757b94
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _ACCESS_RX_CACHE_H
+#define _ACCESS_RX_CACHE_H 1
+
+#include <functional>
+#include <map>
+#include <mutex>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+class IOUringEngine;
+
+class AccessRXCache {
+public:
+       AccessRXCache(IOUringEngine *engine)
+               : engine(engine) {}
+       void check_access(const char *filename, bool allow_async, std::function<void(bool)> cb);
+
+private:
+       std::unordered_map<std::string, bool> cache;
+       struct PendingStat {
+               std::string filename;
+               std::function<void(bool)> cb;
+       };
+       std::map<std::string, std::vector<PendingStat>> pending_stats;
+       IOUringEngine *engine;
+       std::mutex mu;
+};
+
+#endif  // !defined(_ACCESS_RX_CACHE_H)