#ifndef FILESERVER_TIMED_MUTEX_HXX
#define FILESERVER_TIMED_MUTEX_HXX

#include <spdlog/spdlog.h>
#include <shared_mutex>

struct TimedSharedMutex {
    std::shared_mutex m;

    using clock = std::chrono::high_resolution_clock;

    void lock_shared() {
        auto start = clock::now();
        m.lock_shared();
        auto end = clock::now();
        auto d = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
        spdlog::info("Lock s took {} ms", d.count());
    }
    void unlock_shared() { m.unlock_shared(); spdlog::info("Unlock s"); }
    void lock() {
        auto start = clock::now();
        m.lock();
        auto end = clock::now();
        auto d = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
        spdlog::info("Lock took {} ms", d.count());
    }
    void unlock() { m.unlock(); spdlog::info("Unlock"); }
};

#endif //FILESERVER_TIMED_MUTEX_HXX
