-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Make std::lock_guard
available with _LIBCPP_HAS_NO_THREADS
#98717
Changes from 12 commits
1aec8cd
2b4d430
e06a8e6
896cdc3
d717ad2
252198d
3ffe2d1
b5d686e
cd00542
757a485
38d2425
d7eb493
f07b064
da38a9f
5cdda4a
9f95bb1
c1384a3
09c8e0c
5273378
2ed78f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,9 @@ | |
|
||
#include <mutex> | ||
|
||
int main(int, char**) | ||
{ | ||
std::mutex m; | ||
std::lock_guard<std::mutex> lg0(m); | ||
std::lock_guard<std::mutex> lg(lg0); | ||
class MyMutex; | ||
|
||
int main(int, char**) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
static_assert(!std::is_copy_constructible<std::lock_guard<MyMutex> >::value, ""); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 lock_guard; | ||
|
||
// explicit lock_guard(mutex_type& m); | ||
|
||
// template<class _Mutex> lock_guard(lock_guard<_Mutex>) | ||
// -> lock_guard<_Mutex>; // C++17 | ||
|
||
#include <mutex> | ||
#include <cassert> | ||
|
||
#include "test_macros.h" | ||
|
||
struct MyMutex { | ||
bool locked = false; | ||
|
||
MyMutex() = default; | ||
~MyMutex() { assert(!locked); } | ||
|
||
void lock() { | ||
assert(!locked); | ||
locked = true; | ||
} | ||
void unlock() { | ||
assert(locked); | ||
locked = false; | ||
} | ||
|
||
MyMutex(MyMutex const&) = delete; | ||
MyMutex& operator=(MyMutex const&) = delete; | ||
}; | ||
|
||
int main(int, char**) { | ||
MyMutex m; | ||
{ | ||
std::lock_guard<MyMutex> lg(m); | ||
assert(m.locked); | ||
} | ||
|
||
m.lock(); | ||
m.unlock(); | ||
|
||
#if TEST_STD_VER >= 17 | ||
std::lock_guard lg(m); | ||
static_assert((std::is_same<decltype(lg), std::lock_guard<decltype(m)>>::value), ""); | ||
#endif | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ | |
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: no-threads | ||
|
||
// <mutex> | ||
|
||
// template <class Mutex> class lock_guard; | ||
|
@@ -16,10 +14,12 @@ | |
|
||
#include <mutex> | ||
|
||
struct MyMutex {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to use a valid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
int main(int, char**) | ||
{ | ||
std::mutex m; | ||
std::lock_guard<std::mutex> lg = m; // expected-error{{no viable conversion}} | ||
MyMutex m; | ||
std::lock_guard<MyMutex> lg = m; // expected-error{{no viable conversion}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, we should do something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// UNSUPPORTED: no-threads | ||
|
||
// <mutex> | ||
|
||
|
@@ -23,10 +21,10 @@ | |
|
||
#include "test_macros.h" | ||
|
||
int main(int, char**) | ||
{ | ||
static_assert((std::is_same<std::lock_guard<std::mutex>::mutex_type, | ||
std::mutex>::value), ""); | ||
struct MyMutex {}; | ||
|
||
int main(int, char**) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
static_assert((std::is_same<std::lock_guard<MyMutex>::mutex_type, MyMutex>::value), ""); | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a matter of style, we don't use
main
function in these compile-only tests when they are not needed to avoid any confusion about the test running.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.