This is a follow up to https://github.com/llvm/llvm-project/pull/98717, which made lock_guard available under _LIBCPP_HAS_NO_THREADS. We can make unique_lock available under similar circumstances. This patch follows the example in #98717, by: - Removing the preprocessor guards for _LIBCPP_HAS_NO_THREADS in the unique_lock header. - providing a set of custom mutex implementations in a local header. - using custom locks in tests that can be made to work under `no-threads`.
33 lines
772 B
C++
33 lines
772 B
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <mutex>
|
|
|
|
// template <class Mutex> class unique_lock;
|
|
|
|
// mutex_type *mutex() const;
|
|
|
|
#include <cassert>
|
|
#include <mutex>
|
|
|
|
#include "test_macros.h"
|
|
#include "../types.h"
|
|
|
|
MyMutex m;
|
|
|
|
int main(int, char**) {
|
|
std::unique_lock<MyMutex> lk0;
|
|
assert(lk0.mutex() == nullptr);
|
|
std::unique_lock<MyMutex> lk1(m);
|
|
assert(lk1.mutex() == &m);
|
|
lk1.unlock();
|
|
assert(lk1.mutex() == &m);
|
|
|
|
return 0;
|
|
}
|