mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
b0765887fc
Summary: I found the logic for whether the config should be reloaded unnecessarily complicated, so reduce it to deciding whether to reload or not. This removes the need to acquire a write lock in autoreload's common case. Reviewed By: wez Differential Revision: D17847699 fbshipit-source-id: 50fee1aac15cc8f896333c93459fea6510646600
53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <memory>
|
|
|
|
#include <folly/Synchronized.h>
|
|
|
|
#include "eden/fs/config/gen-cpp2/eden_config_types.h"
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
class EdenConfig;
|
|
|
|
/**
|
|
* An interface that defines how to obtain a possibly reloaded EdenConfig
|
|
* instance.
|
|
*/
|
|
class ReloadableConfig {
|
|
public:
|
|
explicit ReloadableConfig(std::shared_ptr<const EdenConfig> config);
|
|
~ReloadableConfig();
|
|
|
|
/**
|
|
* Get the EdenConfig data.
|
|
*
|
|
* The config data may be reloaded from disk depending on the value of the
|
|
* reload parameter.
|
|
*/
|
|
std::shared_ptr<const EdenConfig> getEdenConfig(
|
|
ConfigReloadBehavior reload = ConfigReloadBehavior::AutoReload);
|
|
|
|
private:
|
|
struct ConfigState {
|
|
explicit ConfigState(const std::shared_ptr<const EdenConfig>& config)
|
|
: config{config} {}
|
|
std::shared_ptr<const EdenConfig> config;
|
|
};
|
|
|
|
folly::Synchronized<ConfigState> state_;
|
|
std::atomic<std::chrono::steady_clock::time_point::rep> lastCheck_;
|
|
};
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|