diff --git a/src/passthrough.cpp b/src/passthrough.cpp new file mode 100644 index 00000000..edf2e617 --- /dev/null +++ b/src/passthrough.cpp @@ -0,0 +1,59 @@ +#include "passthrough.hpp" + +#include "boost/unordered/concurrent_flat_map.hpp" + +#include + +typedef boost::unordered::concurrent_flat_map PTMap; +static PTMap g_PT; + +namespace PassthroughStuff +{ + std::mutex* + get_mutex(const char *fusepath_) + { + std::mutex *m = nullptr; + + g_PT.visit(fusepath_, + [&](const PTMap::value_type &x_) + { + m = &x_.second.mutex; + }); + + if(!m) + { + g_PT.insert(PTMap::value_type{fusepath_,PTInfo{}}); + g_PT.visit(fusepath_, + [&](const PTMap::value_type &x_) + { + m = &x_.second.mutex; + }); + } + + return m; + } + + PTInfo* + get_pti(const char *fusepath_) + { + PTInfo *pti = nullptr; + + g_PT.visit(fusepath_, + [&](PTMap::value_type &x_) + { + pti = &x_.second; + }); + + if(!pti) + { + g_PT.insert(PTMap::value_type{fusepath_,PTInfo{}}); + g_PT.visit(fusepath_, + [&](PTMap::value_type &x_) + { + pti = &x_.second; + }); + } + + return pti; + } +}; diff --git a/src/passthrough.hpp b/src/passthrough.hpp new file mode 100644 index 00000000..d9b1c16a --- /dev/null +++ b/src/passthrough.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +struct PTInfo +{ + PTInfo() + : path_fd(-1), + backing_id(0), + open_count(0) + { + } + + PTInfo(PTInfo &&pti_) + { + std::lock_guard _(mutex); + + path_fd = pti_.path_fd; + backing_id = pti_.backing_id; + filepath = pti_.filepath; + open_count = pti_.open_count; + } + + int path_fd; + int backing_id; + unsigned open_count; + std::string filepath; + mutable std::mutex mutex; +}; + +namespace PassthroughStuff +{ + PTInfo* get_pti(const char *fusepath); +}