1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11 |
10 | // REQUIRES: availability-synchronization_library-missing |
11 | |
12 | // Test the availability markup on std::counting_semaphore and std::binary_semaphore. |
13 | |
14 | #include <chrono> |
15 | #include <semaphore> |
16 | |
17 | void f() { |
18 | { |
19 | // Tests for std::counting_semaphore with non-default template argument |
20 | std::counting_semaphore<20> sem(10); |
21 | sem.release(); // expected-error {{is unavailable}} |
22 | sem.release(5); // expected-error {{is unavailable}} |
23 | sem.acquire(); // expected-error {{is unavailable}} |
24 | sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}} |
25 | sem.try_acquire(); // expected-error {{is unavailable}} |
26 | sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}} |
27 | } |
28 | { |
29 | // Tests for std::counting_semaphore with default template argument |
30 | std::counting_semaphore<> sem(10); |
31 | sem.release(); // expected-error {{is unavailable}} |
32 | sem.release(5); // expected-error {{is unavailable}} |
33 | sem.acquire(); // expected-error {{is unavailable}} |
34 | sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}} |
35 | sem.try_acquire(); // expected-error {{is unavailable}} |
36 | sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}} |
37 | } |
38 | { |
39 | // Tests for std::binary_semaphore |
40 | std::binary_semaphore sem(10); |
41 | sem.release(); // expected-error {{is unavailable}} |
42 | sem.release(5); // expected-error {{is unavailable}} |
43 | sem.acquire(); // expected-error {{is unavailable}} |
44 | sem.try_acquire_for(std::chrono::milliseconds{3}); // expected-error 1-2 {{is unavailable}} |
45 | sem.try_acquire(); // expected-error {{is unavailable}} |
46 | sem.try_acquire_until(std::chrono::steady_clock::now()); // expected-error 1-2 {{is unavailable}} |
47 | } |
48 | } |
49 | |