kodi
RecursiveMutex.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <mutex>
12 
13 #include <pthread.h>
14 namespace XbmcThreads
15 {
16 
25 {
26 private:
27  pthread_mutex_t m_mutex;
28 
29  static pthread_mutexattr_t& getRecursiveAttr();
30 
31 public:
32  CRecursiveMutex(const CRecursiveMutex&) = delete;
33  CRecursiveMutex& operator=(const CRecursiveMutex&) = delete;
34 
35  inline CRecursiveMutex() { pthread_mutex_init(&m_mutex, &getRecursiveAttr()); }
36 
37  inline ~CRecursiveMutex() { pthread_mutex_destroy(&m_mutex); }
38 
39  inline void lock() { pthread_mutex_lock(&m_mutex); }
40 
41  inline void unlock() { pthread_mutex_unlock(&m_mutex); }
42 
43  inline bool try_lock() { return (pthread_mutex_trylock(&m_mutex) == 0); }
44 
45  inline std::recursive_mutex::native_handle_type native_handle() { return &m_mutex; }
46 };
47 
48 } // namespace XbmcThreads
This class exists purely for the ability to set mutex attribute PTHREAD_PRIO_INHERIT. Currently there is no way to set this using std::recursive_mutex.
Definition: RecursiveMutex.h:24
Definition: RecursiveMutex.cpp:11