1 | // |
2 | // NamedMutex_UNIX.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Processes |
6 | // Module: NamedMutex |
7 | // |
8 | // Definition of the NamedMutexImpl class for Unix. |
9 | // |
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_NamedMutex_UNIX_INCLUDED |
18 | #define Foundation_NamedMutex_UNIX_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> |
24 | #if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__EMSCRIPTEN__) |
25 | #include <semaphore.h> |
26 | #endif |
27 | |
28 | |
29 | namespace Poco { |
30 | |
31 | |
32 | class Foundation_API NamedMutexImpl |
33 | { |
34 | protected: |
35 | NamedMutexImpl(const std::string& name); |
36 | ~NamedMutexImpl(); |
37 | void lockImpl(); |
38 | bool tryLockImpl(); |
39 | void unlockImpl(); |
40 | |
41 | private: |
42 | std::string getFileName(); |
43 | |
44 | std::string _name; |
45 | #if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__EMSCRIPTEN__) |
46 | sem_t* _sem; |
47 | #else |
48 | int _semid; // semaphore id |
49 | bool _owned; |
50 | #endif |
51 | }; |
52 | |
53 | |
54 | } // namespace Poco |
55 | |
56 | |
57 | #endif // Foundation_NamedMutex_UNIX_INCLUDED |
58 | |