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
47template<class Mutex>
49public:
50 void lock()
51 {
52 AiProfileBlock("thread blocked");
53 mutex.lock();
54 }
55 bool try_lock()
56 {
57 AiProfileBlock("thread blocked");
58 return mutex.try_lock();
59 }
60 void unlock() { mutex.unlock(); }
61
62 using mutex_type = Mutex;
63
64// native_handle() does not exist in VS 2022 v17.8 and newer
65#if !defined(_MSC_VER) || _MSC_VER < 1937
66 using native_handle_type = typename Mutex::native_handle_type;
67 native_handle_type native_handle() { return mutex.native_handle(); }
68#endif
69
70 const mutex_type& get() const { return mutex; }
71 mutex_type& get() { return mutex; }
72
73private:
74 Mutex mutex;
75};
76
77// Visual Studio 2015, VS2015 Update 1, and maybe Update 2 will produce a warning when
78// including mutex header. Upgrade VS compiler to at least VS 2015 Update 3 in order to use stl mutexes
79#if !(defined _MSC_FULL_VER && _MSC_FULL_VER <= 190023918) // 190023918 is VS 2015 Update 2
80# include <mutex>
86#endif
87
88/*\}*/
89
90/*\}*/
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:48
#define AiProfileBlock(...)
Macro to measure total time spent in a code block.
Definition: ai_stats.h:69

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