mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-12 02:23:45 +00:00
Use shared_mutex for fuse log config
- Guard fuse_cfg_t log file and filepath shared pointers with a shared mutex - Replace atomic shared pointer loads and stores with shared and unique locks
This commit is contained in:
committed by
trapexit
parent
02dc36080c
commit
30d59d4458
@@ -5,6 +5,7 @@
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
|
||||
#define FUSE_CFG_INVALID_ID -1
|
||||
@@ -33,6 +34,7 @@ struct fuse_cfg_t
|
||||
std::shared_ptr<std::string> log_filepath() const;
|
||||
void log_filepath(const std::string &);
|
||||
private:
|
||||
mutable std::shared_mutex _log_mutex;
|
||||
std::shared_ptr<FILE> _log_file = sp<FILE>(stderr,[](FILE*){});
|
||||
std::shared_ptr<std::string> _log_filepath = sp<std::string>();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "fuse_cfg.hpp"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
fuse_cfg_t fuse_cfg;
|
||||
|
||||
bool
|
||||
@@ -23,24 +25,32 @@ fuse_cfg_t::valid_umask() const
|
||||
std::shared_ptr<FILE>
|
||||
fuse_cfg_t::log_file() const
|
||||
{
|
||||
return std::atomic_load(&_log_file);
|
||||
std::shared_lock<std::shared_mutex> lk(_log_mutex);
|
||||
|
||||
return _log_file;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_cfg_t::log_file(std::shared_ptr<FILE> f_)
|
||||
{
|
||||
std::atomic_store(&_log_file, f_);
|
||||
std::unique_lock<std::shared_mutex> lk(_log_mutex);
|
||||
|
||||
_log_file = std::move(f_);
|
||||
}
|
||||
|
||||
std::shared_ptr<std::string>
|
||||
fuse_cfg_t::log_filepath() const
|
||||
{
|
||||
return std::atomic_load(&_log_filepath);
|
||||
std::shared_lock<std::shared_mutex> lk(_log_mutex);
|
||||
|
||||
return _log_filepath;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_cfg_t::log_filepath(const std::string &s_)
|
||||
{
|
||||
std::atomic_store(&_log_filepath,
|
||||
std::make_shared<std::string>(s_));
|
||||
auto filepath = std::make_shared<std::string>(s_);
|
||||
std::unique_lock<std::shared_mutex> lk(_log_mutex);
|
||||
|
||||
_log_filepath = std::move(filepath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user