]> git.lyx.org Git - lyx.git/blob - src/support/mutex.cpp
correct format for unsigned long argument, remoteCloseLink is oneway void
[lyx.git] / src / support / mutex.cpp
1 /**
2  * \file mutex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Peter Kümmel
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "mutex.h"
14
15 #include <QMutex>
16
17
18 namespace lyx {
19
20
21 struct Mutex::Private
22 {
23         // QMutex::Recursive: less risks for dead-locks
24         Private() : qmutex_(QMutex::Recursive)
25         {
26         }
27
28         QMutex qmutex_;
29 };
30
31
32 Mutex::Mutex() : d(new Private)
33 {
34 }
35
36
37 Mutex::~Mutex()
38 {
39         delete d;
40 }
41
42
43 // It makes no sense to copy the mutex,
44 // each instance has its own QMutex,
45 // therefore nothing to copy!
46 // TODO review
47 Mutex::Mutex(const Mutex&) : d(new Private)
48 {
49 }
50
51
52 Mutex& Mutex::operator=(const Mutex&)
53 {
54         return *this;
55 }
56
57
58
59 Mutex::Locker::Locker(Mutex* mtx) : mutex_(mtx)
60 {
61         mutex_->d->qmutex_.lock();
62 }
63
64
65 Mutex::Locker::~Locker()
66 {
67         mutex_->d->qmutex_.unlock();
68 }
69
70
71
72 } // namespace lyx