]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/shared_grids_std.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / srs / shared_grids_std.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2018-2019, Oracle and/or its affiliates.
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #ifndef BOOST_GEOMETRY_SRS_SHARED_GRIDS_STD_HPP
11 #define BOOST_GEOMETRY_SRS_SHARED_GRIDS_STD_HPP
12
13
14 #include <boost/config.hpp>
15
16 #ifdef BOOST_NO_CXX14_HDR_SHARED_MUTEX
17 #error "C++14 <shared_mutex> header required."
18 #endif
19
20 #include <boost/geometry/srs/projections/grids.hpp>
21
22 #include <mutex>
23 #include <shared_mutex>
24
25
26 namespace boost { namespace geometry
27 {
28
29 namespace srs
30 {
31
32 class shared_grids_std
33 {
34
35 // VS 2015 Update 2
36 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023918)
37 typedef std::shared_mutex mutex_type;
38 // Other C++17
39 #elif !defined(BOOST_NO_CXX14_HDR_SHARED_MUTEX) && (__cplusplus > 201402L)
40 typedef std::shared_mutex mutex_type;
41 #else
42 typedef std::shared_timed_mutex mutex_type;
43 #endif
44
45 public:
46 std::size_t size() const
47 {
48 std::shared_lock<mutex_type> lock(mutex);
49 return gridinfo.size();
50 }
51
52 bool empty() const
53 {
54 std::shared_lock<mutex_type> lock(mutex);
55 return gridinfo.empty();
56 }
57
58 typedef projections::detail::shared_grids_tag tag;
59
60 struct read_locked
61 {
62 read_locked(shared_grids_std & g)
63 : gridinfo(g.gridinfo)
64 , lock(g.mutex)
65 {}
66
67 // should be const&
68 projections::detail::pj_gridinfo & gridinfo;
69
70 private:
71 std::shared_lock<mutex_type> lock;
72 };
73
74 struct write_locked
75 {
76 write_locked(shared_grids_std & g)
77 : gridinfo(g.gridinfo)
78 , lock(g.mutex)
79 {}
80
81 projections::detail::pj_gridinfo & gridinfo;
82
83 private:
84 std::unique_lock<mutex_type> lock;
85 };
86
87 private:
88 projections::detail::pj_gridinfo gridinfo;
89 mutable mutex_type mutex;
90 };
91
92
93 } // namespace srs
94
95
96 }} // namespace boost::geometry
97
98
99 #endif // BOOST_GEOMETRY_SRS_SHARED_GRIDS_STD_HPP