MeshLib C++ Docs
Loading...
Searching...
No Matches
MRTbbThreadMutex.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4
5#include "MRPch/MRBindingMacros.h"
6
7#include <atomic>
8#include <optional>
9#include <thread>
10
11namespace MR
12{
13
31class MR_BIND_IGNORE TbbThreadMutex
32{
33public:
36 MRMESH_API explicit TbbThreadMutex( std::thread::id id = std::this_thread::get_id() );
37
40 {
41 friend class TbbThreadMutex;
42 TbbThreadMutex* mutex_{ nullptr };
43
44 explicit LockGuard( TbbThreadMutex& mutex ) : mutex_( &mutex ) {}
45
46 public:
47 LockGuard( const LockGuard& ) = delete;
49
51 };
52
55 MRMESH_API std::optional<LockGuard> tryLock();
56
57private:
58 std::thread::id id_;
59 std::atomic_flag lockFlag_;
60};
61
62} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
RAII-style lock guard for the mutex; releases it on destruction.
Definition MRTbbThreadMutex.h:40
MRMESH_API LockGuard(LockGuard &&other)
LockGuard(const LockGuard &)=delete
Definition MRTbbThreadMutex.h:32
MRMESH_API TbbThreadMutex(std::thread::id id=std::this_thread::get_id())
MRMESH_API std::optional< LockGuard > tryLock()