Warning, file /include/oneapi/tbb/mutex.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_mutex_H
0018 #define __TBB_mutex_H
0019
0020 #include "detail/_namespace_injection.h"
0021 #include "detail/_utils.h"
0022 #include "detail/_scoped_lock.h"
0023 #include "detail/_waitable_atomic.h"
0024 #include "detail/_mutex_common.h"
0025 #include "profiling.h"
0026
0027 namespace tbb {
0028 namespace detail {
0029 namespace d1 {
0030
0031 class mutex {
0032 public:
0033
0034 mutex() {
0035 create_itt_sync(this, "tbb::mutex", "");
0036 };
0037
0038
0039 ~mutex() = default;
0040
0041
0042 mutex(const mutex&) = delete;
0043 mutex& operator=(const mutex&) = delete;
0044
0045 using scoped_lock = unique_scoped_lock<mutex>;
0046
0047
0048 static constexpr bool is_rw_mutex = false;
0049 static constexpr bool is_recursive_mutex = false;
0050 static constexpr bool is_fair_mutex = false;
0051
0052
0053
0054 void lock() {
0055 call_itt_notify(prepare, this);
0056 while (!try_lock()) {
0057 my_flag.wait(true, 0, std::memory_order_relaxed);
0058 }
0059 }
0060
0061
0062
0063 bool try_lock() {
0064 bool result = !my_flag.load(std::memory_order_relaxed) && !my_flag.exchange(true);
0065 if (result) {
0066 call_itt_notify(acquired, this);
0067 }
0068 return result;
0069 }
0070
0071
0072 void unlock() {
0073 call_itt_notify(releasing, this);
0074
0075
0076 my_flag.exchange(false);
0077 my_flag.notify_one_relaxed();
0078 }
0079
0080 private:
0081 waitable_atomic<bool> my_flag{0};
0082 };
0083
0084 }
0085 }
0086
0087 inline namespace v1 {
0088 using detail::d1::mutex;
0089 }
0090
0091 }
0092
0093 #endif