1 //===--- ThreadsafeFS.h ------------------------------------------*- C++-*-===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_THREADSAFEFS_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_THREADSAFEFS_H
13 #include "llvm/ADT/IntrusiveRefCntPtr.h"
14 #include "llvm/ADT/None.h"
15 #include "llvm/Support/VirtualFileSystem.h"
21 /// Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
22 /// As FileSystem is not threadsafe, concurrent threads must each obtain one.
23 /// Implementations may choose to depend on Context::current() e.g. to implement
24 /// snapshot semantics. clangd will not create vfs::FileSystems for use in
25 /// different contexts, so either ThreadsafeFS::view or the returned FS may
26 /// contain this logic.
29 virtual ~ThreadsafeFS() = default;
31 /// Obtain a vfs::FileSystem with an arbitrary initial working directory.
32 llvm::IntrusiveRefCntPtr
<llvm::vfs::FileSystem
>
33 view(llvm::NoneType CWD
) const {
37 /// Obtain a vfs::FileSystem with a specified working directory.
38 /// If the working directory can't be set (e.g. doesn't exist), logs and
39 /// returns the FS anyway.
40 llvm::IntrusiveRefCntPtr
<llvm::vfs::FileSystem
> view(PathRef CWD
) const;
43 /// Overridden by implementations to provide a vfs::FileSystem.
44 /// This is distinct from view(NoneType) to avoid GCC's -Woverloaded-virtual.
45 virtual llvm::IntrusiveRefCntPtr
<llvm::vfs::FileSystem
> viewImpl() const = 0;
48 class RealThreadsafeFS
: public ThreadsafeFS
{
50 llvm::IntrusiveRefCntPtr
<llvm::vfs::FileSystem
> viewImpl() const override
;