source: filezilla/trunk/fuentes/src/interface/ipcmutex.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 1.9 KB
Line 
1#ifndef __IPCMUTEX_H__
2#define __IPCMUTEX_H__
3
4/*
5 * Unfortunately wxWidgets does not provide interprocess mutexes, so I've to
6 * use platform specific code here.
7 * CInterProcessMutex represents an interprocess mutex. The mutex will be
8 * created and locked in the constructor and released in the destructor.
9 * Under Windows we use the normal Windows mutexes, under all other platforms
10 * we use lockfiles using fcntl advisory locks.
11 */
12
13enum t_ipcMutexType
14{
15        // Important: Never ever change a value.
16        // If adding a new mutex type, give it the value of MUTEX_LASTFREE and
17        // increase MUTEX_LASTFREE by one.
18        // Otherwise this will cause interesting effects between different
19        // versions of FileZilla
20        MUTEX_OPTIONS = 1,
21        MUTEX_SITEMANAGER = 2,
22        MUTEX_SITEMANAGERGLOBAL = 3,
23        MUTEX_QUEUE = 4,
24        MUTEX_FILTERS = 5,
25        MUTEX_LAYOUT = 6,
26        MUTEX_MOSTRECENTSERVERS = 7,
27        MUTEX_TRUSTEDCERTS = 8,
28        MUTEX_GLOBALBOOKMARKS = 9,
29        MUTEX_SEARCHCONDITIONS = 10,
30
31        MUTEX_LASTFREE = 11
32};
33
34class CInterProcessMutex
35{
36public:
37        CInterProcessMutex(enum t_ipcMutexType mutexType, bool initialLock = true);
38        ~CInterProcessMutex();
39
40        bool Lock();
41        int TryLock(); // Tries to lock the mutex. Returns 1 on success, 0 if held by other process, -1 on failure
42        void Unlock();
43
44        bool IsLocked() const { return m_locked; }
45
46        enum t_ipcMutexType GetType() const { return m_type; }
47
48private:
49
50#ifdef __WXMSW__
51        // Under windows use normal mutexes
52        HANDLE hMutex;
53#else
54        // Use a lockfile under all other systems
55        static int m_fd;
56        static int m_instanceCount;
57#endif
58        enum t_ipcMutexType m_type;
59
60        bool m_locked;
61};
62
63class CReentrantInterProcessMutexLocker
64{
65public:
66        CReentrantInterProcessMutexLocker(enum t_ipcMutexType mutexType);
67        ~CReentrantInterProcessMutexLocker();
68
69protected:
70        struct t_data
71        {
72                CInterProcessMutex* pMutex;
73                unsigned int lockCount;
74        };
75        static std::list<t_data> m_mutexes;
76
77        enum t_ipcMutexType m_type;
78};
79
80#endif //__IPCMUTEX_H__
Note: See TracBrowser for help on using the repository browser.