-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrw_spinlock_test5.cpp
More file actions
40 lines (33 loc) · 873 Bytes
/
rw_spinlock_test5.cpp
File metadata and controls
40 lines (33 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include "rw_spinlock.hpp"
#include <boost/core/lightweight_test.hpp>
#include <mutex>
#include <shared_mutex>
static rw_spinlock sp;
int main()
{
{
BOOST_TEST( sp.try_lock_shared() );
BOOST_TEST( sp.try_lock_shared() );
sp.unlock_shared();
sp.unlock_shared();
}
{
BOOST_TEST( sp.try_lock() );
BOOST_TEST( !sp.try_lock_shared() );
sp.unlock();
}
{
std::lock_guard<rw_spinlock> lock( sp );
BOOST_TEST( !sp.try_lock_shared() );
}
{
std::shared_lock<rw_spinlock> lock( sp );
BOOST_TEST( !sp.try_lock() );
BOOST_TEST( sp.try_lock_shared() );
sp.unlock_shared();
}
return boost::report_errors();
}