[libc-commits] [libc] [libc] Replace `MutexLock` with `cpp::lock_guard` (PR #89340)
Vlad Mishel via libc-commits
libc-commits at lists.llvm.org
Fri Apr 19 18:14:23 PDT 2024
================
@@ -27,7 +28,7 @@ ErrorOr<Dir *> Dir::open(const char *path) {
}
ErrorOr<struct ::dirent *> Dir::read() {
- MutexLock lock(&mutex);
+ cpp::lock_guard<Mutex> lock(mutex);
----------------
vmishelcs wrote:
> We're C++17; does that let us omit the `<Mutex>` part?
I was getting warnings about template deduction, but I think that's because I hadn't explicitly set my C++ standard in VS Code. In any case, I see that engineers working on libcxx added this macro to their config file in (libcxx/include/__config)[https://github.com/llvm/llvm-project/blob/main/libcxx/include/__config]:
```C++
// There are a handful of public standard library types that are intended to
// support CTAD but don't need any explicit deduction guides to do so. This
// macro is used to mark them as such, which suppresses the
// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
// with these classes.
# if _LIBCPP_STD_VER >= 17
# ifdef _LIBCPP_COMPILER_CLANG_BASED
# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
template <class... _Tag> \
[[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
# else
# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
template <class... _Tag> \
ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
# endif
# else
# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
# endif
```
https://github.com/llvm/llvm-project/pull/89340
More information about the libc-commits
mailing list