6 changes: 3 additions & 3 deletions libcxx/include/latch
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public:
latch(const latch&) = delete;
latch& operator=(const latch&) = delete;

inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void count_down(ptrdiff_t __update = 1)
{
auto const __old = __a.fetch_sub(__update, memory_order_release);
Expand All @@ -81,15 +81,15 @@ public:
{
return 0 == __a.load(memory_order_acquire);
}
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void wait() const
{
auto const __test_fn = [=]() -> bool {
return try_wait();
};
__cxx_atomic_wait(&__a.__a_, __test_fn);
}
inline _LIBCPP_INLINE_VISIBILITY
inline _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void arrive_and_wait(ptrdiff_t __update = 1)
{
count_down(__update);
Expand Down
16 changes: 8 additions & 8 deletions libcxx/include/semaphore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public:
__atomic_semaphore_base(ptrdiff_t __count) : __a(__count)
{
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void release(ptrdiff_t __update = 1)
{
if(0 < __a.fetch_add(__update, memory_order_release))
Expand All @@ -92,7 +92,7 @@ public:
else
__a.notify_one();
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void acquire()
{
auto const __test_fn = [=]() -> bool {
Expand All @@ -102,7 +102,7 @@ public:
__cxx_atomic_wait(&__a.__a_, __test_fn);
}
template <class Rep, class Period>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
{
auto const __test_fn = [=]() -> bool {
Expand Down Expand Up @@ -193,29 +193,29 @@ public:
counting_semaphore(const counting_semaphore&) = delete;
counting_semaphore& operator=(const counting_semaphore&) = delete;

_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void release(ptrdiff_t __update = 1)
{
__semaphore.release(__update);
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
void acquire()
{
__semaphore.acquire();
}
template<class Rep, class Period>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
bool try_acquire_for(chrono::duration<Rep, Period> const& __rel_time)
{
return __semaphore.try_acquire_for(chrono::duration_cast<chrono::nanoseconds>(__rel_time));
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
bool try_acquire()
{
return try_acquire_for(chrono::nanoseconds::zero());
}
template <class Clock, class Duration>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
bool try_acquire_until(chrono::time_point<Clock, Duration> const& __abs_time)
{
auto const current = Clock::now();
Expand Down
81 changes: 81 additions & 0 deletions libcxx/test/libcxx/thread/atomic.availability.fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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: c++98, c++03
// REQUIRES: verify-support
// REQUIRES: with_system_cxx_lib=macosx
// REQUIRES: availability=macosx10.7 || availability=macosx10.8 || availability=macosx10.9 || availability=macosx10.10 || availability=macosx10.11 || availability=macosx10.12 || availability=macosx10.13 || availability=macosx10.14 || availability=macosx10.15

// Test the availability markup on the C++20 Synchronization Library
// additions to <atomic>.

#include <atomic>


int main(int, char**)
{
{
std::atomic<int> i(3);
std::memory_order m = std::memory_order_relaxed;

i.wait(4); // expected-error {{is unavailable}}
i.wait(4, m); // expected-error {{is unavailable}}
i.notify_one(); // expected-error {{is unavailable}}
i.notify_all(); // expected-error {{is unavailable}}

std::atomic_wait(&i, 4); // expected-error {{is unavailable}}
std::atomic_wait_explicit(&i, 4, m); // expected-error {{is unavailable}}
std::atomic_notify_one(&i); // expected-error {{is unavailable}}
std::atomic_notify_all(&i); // expected-error {{is unavailable}}
}

{
std::atomic<int> volatile i(3);
std::memory_order m = std::memory_order_relaxed;

i.wait(4); // expected-error {{is unavailable}}
i.wait(4, m); // expected-error {{is unavailable}}
i.notify_one(); // expected-error {{is unavailable}}
i.notify_all(); // expected-error {{is unavailable}}

std::atomic_wait(&i, 4); // expected-error {{is unavailable}}
std::atomic_wait_explicit(&i, 4, m); // expected-error {{is unavailable}}
std::atomic_notify_one(&i); // expected-error {{is unavailable}}
std::atomic_notify_all(&i); // expected-error {{is unavailable}}
}

{
std::atomic_flag flag;
bool b = false;
std::memory_order m = std::memory_order_relaxed;
flag.wait(b); // expected-error {{is unavailable}}
flag.wait(b, m); // expected-error {{is unavailable}}
flag.notify_one(); // expected-error {{is unavailable}}
flag.notify_all(); // expected-error {{is unavailable}}

std::atomic_flag_wait(&flag, b); // expected-error {{is unavailable}}
std::atomic_flag_wait_explicit(&flag, b, m); // expected-error {{is unavailable}}
std::atomic_flag_notify_one(&flag); // expected-error {{is unavailable}}
std::atomic_flag_notify_all(&flag); // expected-error {{is unavailable}}
}

{
std::atomic_flag volatile flag;
bool b = false;
std::memory_order m = std::memory_order_relaxed;
flag.wait(b); // expected-error {{is unavailable}}
flag.wait(b, m); // expected-error {{is unavailable}}
flag.notify_one(); // expected-error {{is unavailable}}
flag.notify_all(); // expected-error {{is unavailable}}

std::atomic_flag_wait(&flag, b); // expected-error {{is unavailable}}
std::atomic_flag_wait_explicit(&flag, b, m); // expected-error {{is unavailable}}
std::atomic_flag_notify_one(&flag); // expected-error {{is unavailable}}
std::atomic_flag_notify_all(&flag); // expected-error {{is unavailable}}
}
}
44 changes: 44 additions & 0 deletions libcxx/test/libcxx/thread/barrier.availability.fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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: c++98, c++03
// REQUIRES: verify-support
// REQUIRES: with_system_cxx_lib=macosx
// REQUIRES: availability=macosx10.7 || availability=macosx10.8 || availability=macosx10.9 || availability=macosx10.10 || availability=macosx10.11 || availability=macosx10.12 || availability=macosx10.13 || availability=macosx10.14 || availability=macosx10.15

// Test the availability markup on std::barrier.

#include <barrier>
#include <utility>

struct CompletionF {
void operator()() { }
};

int main(int, char**)
{
// Availability markup on std::barrier<>
{
std::barrier<> b(10); // expected-error {{is unavailable}}
auto token = b.arrive(); // expected-error {{is unavailable}}
(void)b.arrive(10); // expected-error {{is unavailable}}
b.wait(std::move(token)); // expected-error {{is unavailable}}
b.arrive_and_wait(); // expected-error {{is unavailable}}
b.arrive_and_drop(); // expected-error {{is unavailable}}
}

// Availability markup on std::barrier<CompletionF> with non-default CompletionF
{
std::barrier<CompletionF> b(10); // expected-error {{is unavailable}}
auto token = b.arrive(); // expected-error {{is unavailable}}
(void)b.arrive(10); // expected-error {{is unavailable}}
b.wait(std::move(token)); // expected-error {{is unavailable}}
b.arrive_and_wait(); // expected-error {{is unavailable}}
b.arrive_and_drop(); // expected-error {{is unavailable}}
}
}
27 changes: 27 additions & 0 deletions libcxx/test/libcxx/thread/latch.availability.fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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: c++98, c++03
// REQUIRES: verify-support
// REQUIRES: with_system_cxx_lib=macosx
// REQUIRES: availability=macosx10.7 || availability=macosx10.8 || availability=macosx10.9 || availability=macosx10.10 || availability=macosx10.11 || availability=macosx10.12 || availability=macosx10.13 || availability=macosx10.14 || availability=macosx10.15

// Test the availability markup on std::latch.

#include <latch>


int main(int, char**)
{
std::latch latch(10);
latch.count_down(); // expected-error {{is unavailable}}
latch.count_down(3); // expected-error {{is unavailable}}
latch.wait(); // expected-error {{is unavailable}}
latch.arrive_and_wait(); // expected-error {{is unavailable}}
latch.arrive_and_wait(3); // expected-error {{is unavailable}}
}
52 changes: 52 additions & 0 deletions libcxx/test/libcxx/thread/semaphore.availability.fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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: c++98, c++03
// REQUIRES: verify-support
// REQUIRES: with_system_cxx_lib=macosx
// REQUIRES: availability=macosx10.7 || availability=macosx10.8 || availability=macosx10.9 || availability=macosx10.10 || availability=macosx10.11 || availability=macosx10.12 || availability=macosx10.13 || availability=macosx10.14 || availability=macosx10.15

// Test the availability markup on std::counting_semaphore and std::binary_semaphore.

#include <chrono>
#include <semaphore>


int main(int, char**)
{
{
// Tests for std::counting_semaphore with non-default template argument
std::counting_semaphore<20> sem(10);
sem.release(); // expected-error {{is unavailable}}
sem.release(5); // expected-error {{is unavailable}}
sem.acquire(); // expected-error {{is unavailable}}
sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}}
sem.try_acquire(); // expected-error {{is unavailable}}
sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}}
}
{
// Tests for std::counting_semaphore with default template argument
std::counting_semaphore<> sem(10);
sem.release(); // expected-error {{is unavailable}}
sem.release(5); // expected-error {{is unavailable}}
sem.acquire(); // expected-error {{is unavailable}}
sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}}
sem.try_acquire(); // expected-error {{is unavailable}}
sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}}
}
{
// Tests for std::binary_semaphore
std::binary_semaphore sem(10);
sem.release(); // expected-error {{is unavailable}}
sem.release(5); // expected-error {{is unavailable}}
sem.acquire(); // expected-error {{is unavailable}}
sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}}
sem.try_acquire(); // expected-error {{is unavailable}}
sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03
// REQUIRES: with_system_cxx_lib=macosx
// REQUIRES: availability=macosx10.7 || availability=macosx10.8 || availability=macosx10.9 || availability=macosx10.10 || availability=macosx10.11 || availability=macosx10.12 || availability=macosx10.13 || availability=macosx10.14

// TODO(ldionne): This test is currently broken when testing libc++ trunk on one of the above macOS's
// UNSUPPORTED: macosx

// Test the availability markup on std::to_chars.

#include <charconv>
Expand Down