qlockfile.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qlockfile.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4QLockFile::QLockFile(const QString &fileName)-
5 : d_ptr(new QLockFilePrivate(fileName))-
6{-
7}-
8-
9-
10-
11-
12-
13QLockFile::~QLockFile()-
14{-
15 unlock();-
16}-
17void QLockFile::setStaleLockTime(int staleLockTime)-
18{-
19 QLockFilePrivate * const d = d_func();-
20 d->staleLockTime = staleLockTime;-
21}-
22-
23-
24-
25-
26-
27-
28-
29int QLockFile::staleLockTime() const-
30{-
31 const QLockFilePrivate * const d = d_func();-
32 return d->staleLockTime;-
33}-
34-
35-
36-
37-
38-
39-
40-
41bool QLockFile::isLocked() const-
42{-
43 const QLockFilePrivate * const d = d_func();-
44 return d->isLocked;-
45}-
46bool QLockFile::lock()-
47{-
48 return tryLock(-1);-
49}-
50bool QLockFile::tryLock(int timeout)-
51{-
52 QLockFilePrivate * const d = d_func();-
53 QElapsedTimer timer;-
54 if (timeout > 0
timeout > 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 582 times by 8 tests
Evaluated by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
)
4-582
55 timer.start();
executed 4 times by 1 test: timer.start();
Executed by:
  • tst_QLockFile
4
56 int sleepTime = 100;-
57 for(;;) {-
58 d->lockError = d->tryLock_sys();-
59 switch (d->lockError) {-
60 case
executed 580 times by 8 tests: case NoError:
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
NoError:
executed 580 times by 8 tests: case NoError:
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
580
61 d->isLocked = true;-
62 return
executed 580 times by 8 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
true;
executed 580 times by 8 tests: return true;
Executed by:
  • tst_QColorDialog
  • tst_QFileDialog2
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QLockFile
  • tst_QSettings
  • tst_languageChange
  • tst_qlockfile - unknown status
580
63 case
executed 1 time by 1 test: case PermissionError:
Executed by:
  • tst_QLockFile
PermissionError:
executed 1 time by 1 test: case PermissionError:
Executed by:
  • tst_QLockFile
1
64 case
never executed: case UnknownError:
UnknownError:
never executed: case UnknownError:
0
65 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QLockFile
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QLockFile
1
66 case
executed 17 times by 1 test: case LockFailedError:
Executed by:
  • tst_QLockFile
LockFailedError:
executed 17 times by 1 test: case LockFailedError:
Executed by:
  • tst_QLockFile
17
67 if (!d->isLocked
!d->isLockedDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QLockFile
&& d->isApparentlyStale()
d->isApparentlyStale()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QLockFile
) {
1-13
68-
69-
70 QLockFile rmlock(d->fileName + ([]() -> QString { enum { Size = sizeof(u"" ".rmlock")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" ".rmlock"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));));-
71 if (rmlock.tryLock()
rmlock.tryLock()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
) {
0-1
72 if (d->isApparentlyStale()
d->isApparentlyStale()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
&& d->removeStaleLock()
d->removeStaleLock()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
)
0-1
73 continue;
executed 1 time by 1 test: continue;
Executed by:
  • tst_QLockFile
1
74 }
never executed: end of block
0
75 }
never executed: end of block
0
76 break;
executed 16 times by 1 test: break;
Executed by:
  • tst_QLockFile
16
77 }-
78 if (timeout == 0
timeout == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
|| (timeout > 0
timeout > 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QLockFile
&& timer.hasExpired(timeout)
timer.hasExpired(timeout)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QLockFile
))
2-13
79 return
executed 5 times by 1 test: return false;
Executed by:
  • tst_QLockFile
false;
executed 5 times by 1 test: return false;
Executed by:
  • tst_QLockFile
5
80 QThread::msleep(sleepTime);-
81 if (sleepTime < 5 * 1000
sleepTime < 5 * 1000Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
)
0-11
82 sleepTime *= 2;
executed 11 times by 1 test: sleepTime *= 2;
Executed by:
  • tst_QLockFile
11
83 }
executed 11 times by 1 test: end of block
Executed by:
  • tst_QLockFile
11
84-
85 return
never executed: return false;
false;
never executed: return false;
0
86}-
87bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const-
88{-
89 const QLockFilePrivate * const d = d_func();-
90 return d->getLockInfo(pid, hostname, appname);-
91}-
92-
93bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const-
94{-
95 QFile reader(fileName);-
96 if (!reader.open(QIODevice::ReadOnly)
!reader.open(Q...ice::ReadOnly)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • tst_QLockFile
)
0-15
97 return
never executed: return false;
false;
never executed: return false;
0
98-
99 QByteArray pidLine = reader.readLine();-
100 pidLine.chop(1);-
101 if (pidLine.isEmpty()
pidLine.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
)
2-13
102 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QLockFile
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QLockFile
2
103 QByteArray appNameLine = reader.readLine();-
104 appNameLine.chop(1);-
105 QByteArray hostNameLine = reader.readLine();-
106 hostNameLine.chop(1);-
107-
108 if (pidLine.isEmpty())-
return false;qint64 thePid = pidLine.toLongLong();
109 if (pid
pidDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
)
0-13
110 *
executed 13 times by 1 test: *pid = thePid;
Executed by:
  • tst_QLockFile
pid = thePid;
executed 13 times by 1 test: *pid = thePid;
Executed by:
  • tst_QLockFile
13
111 if (appname
appnameDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
)
0-13
112 *
executed 13 times by 1 test: *appname = QString::fromUtf8(appNameLine);
Executed by:
  • tst_QLockFile
appname = QString::fromUtf8(appNameLine);
executed 13 times by 1 test: *appname = QString::fromUtf8(appNameLine);
Executed by:
  • tst_QLockFile
13
113 if (hostname
hostnameDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QLockFile
FALSEnever evaluated
)
0-13
114 *
executed 13 times by 1 test: *hostname = QString::fromUtf8(hostNameLine);
Executed by:
  • tst_QLockFile
hostname = QString::fromUtf8(hostNameLine);
executed 13 times by 1 test: *hostname = QString::fromUtf8(hostNameLine);
Executed by:
  • tst_QLockFile
13
115 return
executed 13 times by 1 test: return thePid > 0;
Executed by:
  • tst_QLockFile
thePid > 0;
executed 13 times by 1 test: return thePid > 0;
Executed by:
  • tst_QLockFile
13
116}-
117bool QLockFile::removeStaleLockFile()-
118{-
119 QLockFilePrivate * const d = d_func();-
120 if (d->isLocked) {-
121 QMessageLogger(__FILE__, 324330, __PRETTY_FUNCTION__).warning("removeStaleLockFile can only be called when not holding the lock");-
122 return false;-
123 }-
124 return d->removeStaleLock();-
125}-
126-
127-
128-
129-
130-
131-
132-
133QLockFile::LockError QLockFile::error() const-
134{-
135 const QLockFilePrivate * const d = d_func();-
136 return d->lockError;-
137}-
138-
139-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9