RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
MutexUtils.hpp
1 /*
2  * MutexUtils.hpp
3  *
4  * Copyright (C) 2020 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 
25 #ifndef LAUNCHER_PLUGINS_MUTEX_UTILS_HPP
26 #define LAUNCHER_PLUGINS_MUTEX_UTILS_HPP
27 
28 #include <mutex>
29 #include <system_error>
30 
31 #include <Error.hpp>
32 #include <logging/Logger.hpp>
33 
34 #define LOCK_MUTEX(in_mutex) \
35 try { \
36  std::lock_guard<std::mutex> lockGuard(in_mutex); \
37 
38 #define LOCK_RECURSIVE_MUTEX(in_mutex) \
39 try { \
40  std::lock_guard<std::recursive_mutex> uniqueLock(in_mutex); \
41 
42 #define UNIQUE_LOCK_MUTEX(in_mutex) \
43 try { \
44  std::unique_lock<std::mutex> uniqueLock(in_mutex); \
45 
46 #define UNIQUE_LOCK_RECURSIVE_MUTEX(in_mutex) \
47 try { \
48  std::unique_lock<std::recursive_mutex> uniqueLock(in_mutex); \
49 
50 #define END_LOCK_MUTEX \
51 } \
52 catch (const std::system_error& e) \
53 { \
54  using namespace rstudio::launcher_plugins; \
55  logging::logError( \
56  systemError(e, ERROR_LOCATION)); \
57 } \
58 CATCH_UNEXPECTED_EXCEPTION; \
59 
60 #endif
Logger.hpp