Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Unmaintained
KDE Libraries
Commits
6ae2b000
Commit
6ae2b000
authored
Nov 16, 2014
by
René J.V. Bertin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make KGlobal reference counting thread safe.
REVIEW: 121134
parent
a16d6f59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
kdecore/kernel/kglobal.cpp
kdecore/kernel/kglobal.cpp
+12
-8
No files found.
kdecore/kernel/kglobal.cpp
View file @
6ae2b000
...
...
@@ -29,6 +29,7 @@
#include "kglobal.h"
#include "kglobal_p.h"
#include <QThread>
#include <QAtomicInt>
#include <config.h>
...
...
@@ -314,27 +315,30 @@ QString KGlobal::caption()
* e.g. a file copy for a file manager, or 'compacting folders on exit' for a mail client,
* the job progress widget with "keep open" checked, etc.
*/
static
int
s_refCount
=
0
;
static
bool
s_allowQuit
=
false
;
static
QBasicAtomicInt
s_allowQuit
=
Q_BASIC_ATOMIC_INITIALIZER
(
false
);
// this is used a bool
static
QBasicAtomicInt
s_refCount
=
Q_BASIC_ATOMIC_INITIALIZER
(
0
)
;
void
KGlobal
::
ref
()
{
++
s_refCount
;
//kDebug() << "KGlobal::ref() : refCount = " << s_refCount;
s_refCount
.
fetchAndAddOrdered
(
1
);
}
void
KGlobal
::
deref
()
{
--
s_refCount
;
//kDebug() << "KGlobal::deref() : refCount = " << s_refCount;
if
(
s_refCount
<=
0
&&
s_allowQuit
)
{
const
int
prevRefCount
=
s_refCount
.
fetchAndAddOrdered
(
-
1
);
if
(
prevRefCount
<=
1
&&
int
(
s_allowQuit
))
{
QCoreApplication
::
instance
()
->
quit
();
}
}
void
KGlobal
::
setAllowQuit
(
bool
allowQuit
)
{
s_allowQuit
=
allowQuit
;
if
(
QThread
::
currentThread
()
==
qApp
->
thread
())
{
s_allowQuit
.
fetchAndStoreOrdered
(
int
(
allowQuit
));
}
else
{
qWarning
()
<<
"KGlobal::setAllowQuit may only be called from the main thread"
;
}
}
#undef PRIVATE_DATA
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment