ai_critsec.h
Go to the documentation of this file.
1 // Copyright 2020 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 
43 template<class Mutex>
45 public:
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 
66 private:
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 
91 typedef void* AtCritSec;
92 
93 AI_API AI_DEPRECATED void AiCritSecInit(AtCritSec* cs);
94 AI_API AI_DEPRECATED void AiCritSecInitRecursive(AtCritSec* cs);
95 AI_API AI_DEPRECATED void AiCritSecClose(AtCritSec* cs);
96 AI_API AI_DEPRECATED void AiCritSecEnter(AtCritSec* cs);
97 AI_API AI_DEPRECATED void AiCritSecLeave(AtCritSec* cs);
98 
99 /*\}*/
AI_API AI_DEPRECATED void AiCritSecEnter(AtCritSec *cs)
Enters a critical section.
AI_API AI_DEPRECATED void AiCritSecLeave(AtCritSec *cs)
Leaves a critical section.
DLL export prefix for API functions (necessary for multi-platform development)
void * AtCritSec
Opaque data type for a critical section.
Definition: ai_critsec.h:91
#define AiProfileBlock(...)
Macro to measure total time spent in a code block.
Definition: ai_stats.h:69
AI_API AI_DEPRECATED void AiCritSecInit(AtCritSec *cs)
Initializes a critical section variable.
Definition: ai_critsec.cpp:45
Wrapper for Lockable type mutexes, such as std::mutex and std::recursive_mutex.
Definition: ai_critsec.h:44
AI_API AI_DEPRECATED void AiCritSecClose(AtCritSec *cs)
Releases all resources used by a critical section variable, so it cannot be used again.
AI_API AI_DEPRECATED void AiCritSecInitRecursive(AtCritSec *cs)
Initializes a recursive critical section variable.
Definition: ai_critsec.cpp:69
API for render statistics output.

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