ai_critsec.h
Go to the documentation of this file.
1// Copyright 2023 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_api.h"
14#include "ai_stats.h"
15
43template<class Mutex>
45public:
46 void lock()
47 {
48 AiProfileBlock("thread blocked");
49 mutex.lock();
50 }
51 bool try_lock()
52 {
53 AiProfileBlock("thread blocked");
54 return mutex.try_lock();
55 }
56 void unlock() { mutex.unlock(); }
57
58 using mutex_type = Mutex;
59 using native_handle_type = typename Mutex::native_handle_type;
60
61 native_handle_type native_handle() { return mutex.native_handle(); }
62
63 const mutex_type& get() const { return mutex; }
64 mutex_type& get() { return mutex; }
65
66private:
67 Mutex mutex;
68};
69
70// Visual Studio 2015, VS2015 Update 1, and maybe Update 2 will produce a warning when
71// including mutex header. Upgrade VS compiler to at least VS 2015 Update 3 in order to use stl mutexes
72#if !(defined _MSC_FULL_VER && _MSC_FULL_VER <= 190023918) // 190023918 is VS 2015 Update 2
73# include <mutex>
79#endif
80
81/*\}*/
DLL export prefix for API functions (necessary for multi-platform development)
API for render statistics output.
Wrapper for Lockable type mutexes, such as std::mutex and std::recursive_mutex.
Definition: ai_critsec.h:44
#define AiProfileBlock(...)
Macro to measure total time spent in a code block.
Definition: ai_stats.h:69

© 2022 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com