xref: /oneTBB/include/oneapi/tbb/null_rw_mutex.h (revision 478de5b1)
1 /*
2     Copyright (c) 2005-2021 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef __TBB_null_rw_mutex_H
18 #define __TBB_null_rw_mutex_H
19 
20 #include "detail/_config.h"
21 #include "detail/_namespace_injection.h"
22 #include "detail/_mutex_common.h"
23 
24 namespace tbb {
25 namespace detail {
26 namespace d1 {
27 
28 //! A rw mutex which does nothing
29 /** A null_rw_mutex is a rw mutex that does nothing and simulates successful operation.
30     @ingroup synchronization */
31 class null_rw_mutex {
32 public:
33     //! Constructors
34     constexpr null_rw_mutex() noexcept = default;
35 
36     //! Destructor
37     ~null_rw_mutex() = default;
38 
39     //! No Copy
40     null_rw_mutex(const null_rw_mutex&) = delete;
41     null_rw_mutex& operator=(const null_rw_mutex&) = delete;
42 
43     //! Represents acquisition of a mutex.
44     class scoped_lock {
45     public:
46         //! Constructors
47         constexpr scoped_lock() noexcept = default;
48         scoped_lock(null_rw_mutex&, bool = true) {}
49 
50         //! Destructor
51         ~scoped_lock() = default;
52 
53         //! No Copy
54         scoped_lock(const scoped_lock&) = delete;
55         scoped_lock& operator=(const scoped_lock&) = delete;
56 
57         void acquire(null_rw_mutex&, bool = true) {}
58         bool try_acquire(null_rw_mutex&, bool = true) { return true; }
release()59         void release() {}
upgrade_to_writer()60         bool upgrade_to_writer() { return true; }
downgrade_to_reader()61         bool downgrade_to_reader() { return true; }
62 
is_writer()63         bool is_writer() const { return true; }
64     };
65 
66     //! Mutex traits
67     static constexpr bool is_rw_mutex = true;
68     static constexpr bool is_recursive_mutex = true;
69     static constexpr bool is_fair_mutex = true;
70 
lock()71     void lock() {}
try_lock()72     bool try_lock() { return true; }
unlock()73     void unlock() {}
lock_shared()74     void lock_shared() {}
try_lock_shared()75     bool try_lock_shared() { return true; }
unlock_shared()76     void unlock_shared() {}
77 }; // class null_rw_mutex
78 
79 } // namespace d1
80 } // namespace detail
81 
82 inline namespace v1 {
83 using detail::d1::null_rw_mutex;
84 } // namespace v1
85 } // namespace tbb
86 
87 #endif /* __TBB_null_rw_mutex_H */
88