-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Make std::lock_guard
available with _LIBCPP_HAS_NO_THREADS
#98717
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1aec8cd
[libcxx] Make locks available with _LIBCPP_HAS_NO_THREADS
petrhosek 2b4d430
Update test annotations
petrhosek e06a8e6
More tests
petrhosek 896cdc3
Fix formatting
petrhosek d717ad2
Make defer_lock_t, try_to_lock_t and adopt_lock_t available also
petrhosek 252198d
Make std::lock and std::try_lock available also
petrhosek 3ffe2d1
Exclude std::unique_lock, std::scoped_lock and std::shared_lock
petrhosek b5d686e
Merge remote-tracking branch 'origin/main' into libcxx-no-threads-locks
petrhosek cd00542
Update tests
petrhosek 757a485
Update test
petrhosek 38d2425
Update tests
petrhosek d7eb493
Fix formatting
petrhosek f07b064
Extract helper class into a header
petrhosek da38a9f
Missing include
petrhosek 5cdda4a
std::is_convertible_v is only available since C++17
petrhosek 9f95bb1
Apply minor review comments
ldionne c1384a3
Fix out-of-scope issue
ldionne 09c8e0c
Fix other ref issue
ldionne 5273378
Fix issues in C++03 mode
petrhosek 2ed78f1
Update test name
petrhosek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/std.mutex.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: no-threads | ||
// UNSUPPORTED: c++03 | ||
|
||
// Test the interoperation of std::lock_guard with std::mutex, since that is such | ||
// a common use case. | ||
|
||
#include <cassert> | ||
#include <mutex> | ||
#include <type_traits> | ||
#include <functional> | ||
|
||
#include "make_test_thread.h" | ||
#include "test_macros.h" | ||
|
||
void do_try_lock(std::mutex& m) { assert(m.try_lock() == false); } | ||
|
||
int main(int, char**) { | ||
{ | ||
std::mutex m; | ||
{ | ||
std::lock_guard<std::mutex> lg(m); | ||
std::thread t = support::make_test_thread(do_try_lock, std::ref(m)); | ||
t.join(); | ||
} | ||
|
||
// This should work because the lock_guard unlocked the mutex when it was destroyed above. | ||
m.lock(); | ||
m.unlock(); | ||
} | ||
|
||
// Test CTAD | ||
#if TEST_STD_VER >= 17 | ||
{ | ||
std::mutex m; | ||
std::lock_guard lg(m); | ||
static_assert(std::is_same<decltype(lg), std::lock_guard<std::mutex>>::value, ""); | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/types.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TEST_STD_THREAD_THREAD_MUTEX_THREAD_LOCK_THREAD_LOCK_GUARD_TYPES_H | ||
#define TEST_STD_THREAD_THREAD_MUTEX_THREAD_LOCK_THREAD_LOCK_GUARD_TYPES_H | ||
|
||
#include <cassert> | ||
|
||
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; | ||
}; | ||
|
||
#endif // TEST_STD_THREAD_THREAD_MUTEX_THREAD_LOCK_THREAD_LOCK_GUARD_TYPES_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.