| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-audio-pipewire-lib |
| 6 |
* Created on: 2 мая 2026 г. |
| 7 |
* |
| 8 |
* lsp-audio-pipewire-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-audio-pipewire-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-audio-pipewire-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_AUDIO_PIPEWIRE_MUTEX_H_ |
| 23 |
#define LSP_PLUG_IN_AUDIO_PIPEWIRE_MUTEX_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/audio/pipewire/version.h> |
| 26 |
#include <lsp-plug.in/common/status.h> |
| 27 |
|
| 28 |
namespace lsp |
| 29 |
{ |
| 30 |
namespace audio |
| 31 |
{ |
| 32 |
namespace pipewire |
| 33 |
{ |
| 34 |
struct mutex_t; |
| 35 |
|
| 36 |
/** |
| 37 |
* Create mutex |
| 38 |
* @return pointer to mutex or NULL |
| 39 |
*/ |
| 40 |
inline mutex_t *mutex_create(); |
| 41 |
|
| 42 |
/** |
| 43 |
* Destroy mutex |
| 44 |
* @param mutex pointer to mutex |
| 45 |
*/ |
| 46 |
inline void mutex_destroy(mutex_t *mutex); |
| 47 |
|
| 48 |
/** |
| 49 |
* Lock mutex |
| 50 |
* @param mutex pointer to mutex |
| 51 |
*/ |
| 52 |
inline void mutex_lock(mutex_t *mutex); |
| 53 |
|
| 54 |
/** |
| 55 |
* Ty to lock mutex |
| 56 |
* @param mutex pointer to mutex |
| 57 |
* @return true if mutex has been locked |
| 58 |
*/ |
| 59 |
inline bool mutex_trylock(mutex_t *mutex); |
| 60 |
|
| 61 |
/** |
| 62 |
* Unlock mutex |
| 63 |
* @param mutex mutex to unlock |
| 64 |
*/ |
| 65 |
inline void mutex_unlock(mutex_t *mutex); |
| 66 |
|
| 67 |
/** |
| 68 |
* Wait for the mutex |
| 69 |
* @param mutex mutex to wait |
| 70 |
*/ |
| 71 |
inline status_t mutex_wait(mutex_t *mutex, uint32_t millis); |
| 72 |
|
| 73 |
/** |
| 74 |
* Wait for the mutex |
| 75 |
* @param mutex mutex to wait |
| 76 |
* @return true on success |
| 77 |
*/ |
| 78 |
inline bool mutex_notify(mutex_t *mutex); |
| 79 |
|
| 80 |
/** |
| 81 |
* Mutex guard |
| 82 |
*/ |
| 83 |
struct mutex_guard |
| 84 |
{ |
| 85 |
private: |
| 86 |
mutex_t *pMutex; |
| 87 |
|
| 88 |
public: |
| 89 |
explicit inline mutex_guard(mutex_t *mutex); |
| 90 |
inline mutex_guard(const mutex_guard & src); |
| 91 |
inline mutex_guard(mutex_guard && src); |
| 92 |
inline ~mutex_guard(); |
| 93 |
|
| 94 |
inline mutex_guard & operator = (const mutex_guard & src); |
| 95 |
inline mutex_guard & operator = (mutex_guard && src); |
| 96 |
}; |
| 97 |
|
| 98 |
#define MUTEX_SCOPED_LOCK__2(mutex, counter) mutex_guard guard ## counter (mutex) |
| 99 |
#define MUTEX_SCOPED_LOCK__1(mutex, counter) MUTEX_SCOPED_LOCK__2(mutex, counter) |
| 100 |
#define MUTEX_SCOPED_LOCK(mutex) MUTEX_SCOPED_LOCK__1(mutex, __COUNTER__) |
| 101 |
|
| 102 |
} /* namespace pipewire */ |
| 103 |
} /* namespace audio */ |
| 104 |
} /* namespace lsp */ |
| 105 |
|
| 106 |
#endif /* LSP_PLUG_IN_AUDIO_PIPEWIRE_MUTEX_H_ */ |