[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / source / Utility / UserIDResolver.cpp
blob83e033f32310bcbb80b7203ed5d7df6d0863e372
1 //===-- UserIDResolver.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/UserIDResolver.h"
10 #include "llvm/Support/ManagedStatic.h"
11 #include <optional>
13 using namespace lldb_private;
15 UserIDResolver::~UserIDResolver() = default;
17 std::optional<llvm::StringRef> UserIDResolver::Get(
18 id_t id, Map &cache,
19 std::optional<std::string> (UserIDResolver::*do_get)(id_t)) {
21 std::lock_guard<std::mutex> guard(m_mutex);
22 auto iter_bool = cache.try_emplace(id, std::nullopt);
23 if (iter_bool.second)
24 iter_bool.first->second = (this->*do_get)(id);
25 if (iter_bool.first->second)
26 return llvm::StringRef(*iter_bool.first->second);
27 return std::nullopt;
30 namespace {
31 class NoopResolver : public UserIDResolver {
32 protected:
33 std::optional<std::string> DoGetUserName(id_t uid) override {
34 return std::nullopt;
37 std::optional<std::string> DoGetGroupName(id_t gid) override {
38 return std::nullopt;
41 } // namespace
43 static llvm::ManagedStatic<NoopResolver> g_noop_resolver;
45 UserIDResolver &UserIDResolver::GetNoopResolver() { return *g_noop_resolver; }