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_mutex_H
18 #define __TBB_null_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 mutex which does nothing
29 /** A null_mutex does no operation and simulates success.
30     @ingroup synchronization */
31 class null_mutex {
32 public:
33     //! Constructors
34     constexpr null_mutex() noexcept = default;
35 
36     //! Destructor
37     ~null_mutex() = default;
38 
39     //! No Copy
40     null_mutex(const null_mutex&) = delete;
41     null_mutex& operator=(const null_mutex&) = delete;
42 
43     //! Represents acquisition of a mutex.
44     class scoped_lock {
45     public:
46         //! Constructors
47         constexpr scoped_lock() noexcept = default;
scoped_lock(null_mutex &)48         scoped_lock(null_mutex&) {}
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 
acquire(null_mutex &)57         void acquire(null_mutex&) {}
try_acquire(null_mutex &)58         bool try_acquire(null_mutex&) { return true; }
release()59         void release() {}
60     };
61 
62     //! Mutex traits
63     static constexpr bool is_rw_mutex = false;
64     static constexpr bool is_recursive_mutex = true;
65     static constexpr bool is_fair_mutex = true;
66 
lock()67     void lock() {}
try_lock()68     bool try_lock() { return true; }
unlock()69     void unlock() {}
70 }; // class null_mutex
71 
72 } // namespace d1
73 } // namespace detail
74 
75 inline namespace v1 {
76 using detail::d1::null_mutex;
77 } // namespace v1
78 } // namespace tbb
79 
80 #endif /* __TBB_null_mutex_H */
81