chromium/third_party/abseil-cpp/absl/log/internal/vlog_config.cc

// Copyright 2022 The Abseil Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "absl/log/internal/vlog_config.h"

#include <stddef.h>

#include <algorithm>
#include <atomic>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/const_init.h"
#include "absl/base/internal/spinlock.h"
#include "absl/base/no_destructor.h"
#include "absl/base/optimization.h"
#include "absl/base/thread_annotations.h"
#include "absl/log/internal/fnmatch.h"
#include "absl/memory/memory.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/optional.h"

namespace absl {
ABSL_NAMESPACE_BEGIN
namespace log_internal {

namespace {
bool ModuleIsPath(absl::string_view module_pattern) {}
}  // namespace

bool VLogSite::SlowIsEnabled(int stale_v, int level) {}

bool VLogSite::SlowIsEnabled0(int stale_v) {}
bool VLogSite::SlowIsEnabled1(int stale_v) {}
bool VLogSite::SlowIsEnabled2(int stale_v) {}
bool VLogSite::SlowIsEnabled3(int stale_v) {}
bool VLogSite::SlowIsEnabled4(int stale_v) {}
bool VLogSite::SlowIsEnabled5(int stale_v) {}

namespace {
struct VModuleInfo final {};

// `mutex` guards all of the data structures that aren't lock-free.
// To avoid problems with the heap checker which calls into `VLOG`, `mutex` must
// be a `SpinLock` that prevents fiber scheduling instead of a `Mutex`.
ABSL_CONST_INIT absl::base_internal::SpinLock mutex(
    absl::kConstInit, absl::base_internal::SCHEDULE_KERNEL_ONLY);

// `GetUpdateSitesMutex()` serializes updates to all of the sites (i.e. those in
// `site_list_head`) themselves.
absl::Mutex* GetUpdateSitesMutex() {}

ABSL_CONST_INIT int global_v ABSL_GUARDED_BY(mutex) =;
// `site_list_head` is the head of a singly-linked list.  Traversal, insertion,
// and reads are atomic, so no locks are required, but updates to existing
// elements are guarded by `GetUpdateSitesMutex()`.
ABSL_CONST_INIT std::atomic<VLogSite*> site_list_head{};
ABSL_CONST_INIT std::vector<VModuleInfo>* vmodule_info ABSL_GUARDED_BY(mutex)
    ABSL_PT_GUARDED_BY(mutex){};

// Only used for lisp.
ABSL_CONST_INIT std::vector<std::function<void()>>* update_callbacks
    ABSL_GUARDED_BY(GetUpdateSitesMutex())
        ABSL_PT_GUARDED_BY(GetUpdateSitesMutex()){};

// Allocates memory.
std::vector<VModuleInfo>& get_vmodule_info()
    ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {}

// Does not allocate or take locks.
int VLogLevel(absl::string_view file, const std::vector<VModuleInfo>* infos,
              int current_global_v) {}

// Allocates memory.
int AppendVModuleLocked(absl::string_view module_pattern, int log_level)
    ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {}

// Allocates memory.
int PrependVModuleLocked(absl::string_view module_pattern, int log_level)
    ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {}
}  // namespace

int VLogLevel(absl::string_view file) ABSL_LOCKS_EXCLUDED(mutex) {}

int RegisterAndInitialize(VLogSite* v) ABSL_LOCKS_EXCLUDED(mutex) {}

void UpdateVLogSites() ABSL_UNLOCK_FUNCTION(mutex)
    ABSL_LOCKS_EXCLUDED(GetUpdateSitesMutex()) {}

void UpdateVModule(absl::string_view vmodule)
    ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {}

int UpdateGlobalVLogLevel(int v)
    ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {}

int PrependVModule(absl::string_view module_pattern, int log_level)
    ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {}

void OnVLogVerbosityUpdate(std::function<void()> cb)
    ABSL_LOCKS_EXCLUDED(GetUpdateSitesMutex()) {}

VLogSite* SetVModuleListHeadForTestOnly(VLogSite* v) {}

}  // namespace log_internal
ABSL_NAMESPACE_END
}  // namespace absl