1 //===-- UserIDResolver.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/UserIDResolver.h"
10 #include "llvm/Support/ManagedStatic.h"
13 using namespace lldb_private
;
15 UserIDResolver::~UserIDResolver() = default;
17 std::optional
<llvm::StringRef
> UserIDResolver::Get(
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
);
24 iter_bool
.first
->second
= (this->*do_get
)(id
);
25 if (iter_bool
.first
->second
)
26 return llvm::StringRef(*iter_bool
.first
->second
);
31 class NoopResolver
: public UserIDResolver
{
33 std::optional
<std::string
> DoGetUserName(id_t uid
) override
{
37 std::optional
<std::string
> DoGetGroupName(id_t gid
) override
{
43 static llvm::ManagedStatic
<NoopResolver
> g_noop_resolver
;
45 UserIDResolver
&UserIDResolver::GetNoopResolver() { return *g_noop_resolver
; }