2424
2525#include < lsp-plug.in/runtime/version.h>
2626
27+ #include < lsp-plug.in/common/atomic.h>
2728#include < lsp-plug.in/common/status.h>
2829#include < lsp-plug.in/common/types.h>
29-
30+ # include < lsp-plug.in/ipc/Thread.h >
3031#include < lsp-plug.in/runtime/LSPString.h>
31-
3232#include < lsp-plug.in/runtime/system.h>
3333
3434namespace lsp
3535{
3636 namespace ipc
3737 {
38- #ifndef PLATFORM_WINDOWS
38+ #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
39+ #define LSP_ROBUST_MUTEX_SUPPORTED
40+ #endif /* PLATFORM_LINUX, PLATFORM_FREEBSD */
41+
42+ #ifdef LSP_ROBUST_MUTEX_SUPPORTED
3943 struct shared_mutex_t ;
40- #endif /* PLATFORM_WINDOWS */
44+ #endif /* LSP_ROBUST_MUTEX_SUPPORTED */
4145
4246 /* *
4347 * Named global non-recursive shared mutex for inter-process communication.
44- * The object tracks it's lock state and automatically unlocks on close(), so it's implementation
45- * is not thread safe. Dont' share it between threads of a process. Instead of this, use different
46- * SharedMutex object and open() method for the same target string .
48+ * The object tracks it's lock state and automatically unlocks on close().
49+ * Lock operations can be executed by multiple threads on the same mutex object.
50+ * Creation and destruction functions are not thread safe .
4751 */
4852 class SharedMutex
4953 {
@@ -54,10 +58,12 @@ namespace lsp
5458 HANDLE hLock;
5559 #else
5660 int hFD;
61+
62+ #ifdef LSP_ROBUST_MUTEX_SUPPORTED
5763 shared_mutex_t *hLock;
64+ #endif /* LSP_ROBUST_MUTEX_SUPPORTED */
5865 #endif /* PLATFORM_WINDOWS */
59-
60- bool bLocked;
66+ thread_id_t nOwner;
6167
6268 public:
6369 explicit SharedMutex ();
@@ -69,11 +75,17 @@ namespace lsp
6975 SharedMutex & operator = (SharedMutex &&) = delete ;
7076
7177 private:
78+ inline bool is_opened () const ;
79+
7280 status_t open_internal (const LSPString *name);
7381
82+ private:
7483 #ifndef PLATFORM_WINDOWS
75- static status_t lock_memory (int fd, shared_mutex_t *mutex);
76- static status_t unlock_memory (int fd, shared_mutex_t *mutex);
84+ static status_t lock_descriptor (int fd, int flags);
85+ #ifdef LSP_ROBUST_MUTEX_SUPPORTED
86+ static status_t lock_memory (int fd, shared_mutex_t *mutex);
87+ static status_t unlock_memory (int fd, shared_mutex_t *mutex);
88+ #endif /* LSP_ROBUST_MUTEX_SUPPORTED */
7789 #endif /* PLATFORM_WINDOWS */
7890
7991 public:
0 commit comments