Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ben Boeckel
QtTesting
Commits
e5a5666c
Commit
e5a5666c
authored
Mar 03, 2007
by
Clinton Stimpson
Browse files
BUG: Fix a race condition. Hopefully fix the timeouts on some tests.
parent
a4eb74c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
pqPythonEventSource.cxx
View file @
e5a5666c
...
...
@@ -47,7 +47,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QVariant>
#include <QFile>
#include <QtDebug>
#include <QMutex>
#include <QCoreApplication>
#include <QEvent>
#include <QStringList>
...
...
@@ -120,10 +119,8 @@ QtTesting_getProperty(PyObject* /*self*/, PyObject* args)
if
(
Instance
&&
QThread
::
currentThread
()
!=
QApplication
::
instance
()
->
thread
())
{
QMutex
mut
;
mut
.
lock
();
QMetaObject
::
invokeMethod
(
Instance
,
"threadGetProperty"
,
Qt
::
QueuedConnection
);
if
(
!
Instance
->
waitForGUI
(
mut
))
if
(
!
Instance
->
waitForGUI
())
{
PyErr_SetString
(
PyExc_ValueError
,
"error getting property"
);
return
NULL
;
...
...
@@ -171,10 +168,8 @@ QtTesting_setProperty(PyObject* /*self*/, PyObject* args)
if
(
Instance
&&
QThread
::
currentThread
()
!=
QApplication
::
instance
()
->
thread
())
{
QMutex
mut
;
mut
.
lock
();
QMetaObject
::
invokeMethod
(
Instance
,
"threadSetProperty"
,
Qt
::
QueuedConnection
);
if
(
!
Instance
->
waitForGUI
(
mut
))
if
(
!
Instance
->
waitForGUI
())
{
PyErr_SetString
(
PyExc_ValueError
,
"error setting property"
);
return
NULL
;
...
...
@@ -253,10 +248,8 @@ QtTesting_getChildren(PyObject* /*self*/, PyObject* args)
if
(
Instance
&&
QThread
::
currentThread
()
!=
QApplication
::
instance
()
->
thread
())
{
QMutex
mut
;
mut
.
lock
();
QMetaObject
::
invokeMethod
(
Instance
,
"threadGetChildren"
,
Qt
::
QueuedConnection
);
if
(
!
Instance
->
waitForGUI
(
mut
))
if
(
!
Instance
->
waitForGUI
())
{
PyErr_SetString
(
PyExc_ValueError
,
"error getting children"
);
return
NULL
;
...
...
@@ -305,10 +298,8 @@ QtTesting_invokeMethod(PyObject* /*self*/, PyObject* args)
if
(
Instance
&&
QThread
::
currentThread
()
!=
QApplication
::
instance
()
->
thread
())
{
QMutex
mut
;
mut
.
lock
();
QMetaObject
::
invokeMethod
(
Instance
,
"threadInvokeMethod"
,
Qt
::
QueuedConnection
);
if
(
!
Instance
->
waitForGUI
(
mut
))
if
(
!
Instance
->
waitForGUI
())
{
PyErr_SetString
(
PyExc_ValueError
,
"error invoking method"
);
return
NULL
;
...
...
pqThreadedEventSource.cxx
View file @
e5a5666c
...
...
@@ -59,12 +59,22 @@ public:
pqThreadedEventSource
&
Source
;
QWaitCondition
WaitCondition
;
QAtomic
Waiting
;
QAtomic
ShouldStop
;
QAtomic
GotEvent
;
QString
CurrentObject
;
QString
CurrentCommand
;
QString
CurrentArgument
;
class
ThreadHelper
:
public
QThread
{
public:
static
void
msleep
(
int
msecs
)
{
QThread
::
msleep
(
msecs
);
}
};
};
pqThreadedEventSource
::
pqThreadedEventSource
(
QObject
*
p
)
...
...
@@ -125,14 +135,12 @@ bool pqThreadedEventSource::postNextEvent(const QString& object,
const
QString
&
command
,
const
QString
&
argument
)
{
QMutex
mut
;
mut
.
lock
();
QMetaObject
::
invokeMethod
(
this
,
"relayEvent"
,
Qt
::
QueuedConnection
,
Q_ARG
(
QString
,
object
),
Q_ARG
(
QString
,
command
),
Q_ARG
(
QString
,
argument
));
return
this
->
waitForGUI
(
mut
);
return
this
->
waitForGUI
();
}
void
pqThreadedEventSource
::
start
()
...
...
@@ -143,22 +151,31 @@ void pqThreadedEventSource::start()
void
pqThreadedEventSource
::
stop
()
{
this
->
Internal
->
ShouldStop
=
1
;
this
->
guiAcknowledge
();
}
bool
pqThreadedEventSource
::
waitForGUI
(
QMutex
&
m
)
bool
pqThreadedEventSource
::
waitForGUI
()
{
if
(
this
->
Internal
->
ShouldStop
)
this
->
Internal
->
Waiting
=
true
;
while
(
this
->
Internal
->
Waiting
==
true
&&
!
this
->
Internal
->
ShouldStop
)
{
return
false
;
pqInternal
::
ThreadHelper
::
msleep
(
50
)
;
}
this
->
Internal
->
WaitCondition
.
wait
(
&
m
);
this
->
Internal
->
Waiting
=
false
;
return
!
this
->
Internal
->
ShouldStop
;
}
void
pqThreadedEventSource
::
guiAcknowledge
()
{
this
->
Internal
->
WaitCondition
.
wakeAll
();
while
(
this
->
Internal
->
Waiting
==
false
)
{
pqInternal
::
ThreadHelper
::
msleep
(
10
);
}
this
->
Internal
->
Waiting
=
false
;
}
void
pqThreadedEventSource
::
done
(
int
success
)
...
...
pqThreadedEventSource.h
View file @
e5a5666c
...
...
@@ -75,7 +75,7 @@ public:
For use by the testing thread.
If return value is false, an error occurred and
the testing thread should terminate. */
bool
waitForGUI
(
QMutex
&
m
);
bool
waitForGUI
();
/** Give the testing thread an acknowledgement.
For use by the GUI thread */
...
...
Write
Preview
Supports
Markdown
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