aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PySide/QtCore/typesystem_core.xml36
-rw-r--r--tests/QtCore/CMakeLists.txt1
-rw-r--r--tests/QtCore/bug_686.py85
3 files changed, 120 insertions, 2 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 029fa1fc8..5a53261b7 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -1154,10 +1154,32 @@
<modify-function signature="tryLockForWrite(int)" allow-thread="yes"/>
</object-type>
<object-type name="QReadLocker">
+ <modify-function signature="QReadLocker(QReadWriteLock*)">
+ <modify-argument index="1">
+ <reference-count action="set"/>
+ </modify-argument>
+ </modify-function>
<modify-function signature="relock()" allow-thread="yes" />
+ <add-function signature="__enter__()" />
+ <add-function signature="__exit__(PyObject*, PyObject*, PyObject*)">
+ <inject-code>
+ %CPPSELF.unlock();
+ </inject-code>
+ </add-function>
</object-type>
<object-type name="QWriteLocker">
+ <modify-function signature="QWriteLocker(QReadWriteLock*)">
+ <modify-argument index="1">
+ <reference-count action="set"/>
+ </modify-argument>
+ </modify-function>
<modify-function signature="relock()" allow-thread="yes" />
+ <add-function signature="__enter__()" />
+ <add-function signature="__exit__(PyObject*, PyObject*, PyObject*)">
+ <inject-code>
+ %CPPSELF.unlock();
+ </inject-code>
+ </add-function>
</object-type>
<object-type name="QDirIterator">
<enum-type name="IteratorFlag" flags="IteratorFlags"/>
@@ -2023,13 +2045,23 @@
<enum-type name="LibraryLocation"/>
</object-type>
<object-type name="QMutexLocker" copyable="no">
- <modify-function signature="QMutexLocker(QMutex*)" allow-thread="yes" />
+ <modify-function signature="QMutexLocker(QMutex*)" allow-thread="yes">
+ <modify-argument index="1">
+ <reference-count action="set" variable-name="mutex()const0"/>
+ </modify-argument>
+ </modify-function>
<modify-function signature="relock()" allow-thread="yes"/>
<modify-function signature="mutex() const">
<modify-argument index="return">
- <parent index="this" action="add"/>
+ <reference-count action="set"/>
</modify-argument>
</modify-function>
+ <add-function signature="__enter__()" />
+ <add-function signature="__exit__(PyObject*, PyObject*, PyObject*)">
+ <inject-code>
+ %CPPSELF.unlock();
+ </inject-code>
+ </add-function>
</object-type>
<object-type name="QMutex">
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt
index 84d0ad017..e49e3909a 100644
--- a/tests/QtCore/CMakeLists.txt
+++ b/tests/QtCore/CMakeLists.txt
@@ -7,6 +7,7 @@ PYSIDE_TEST(bug_505.py)
PYSIDE_TEST(bug_515.py)
PYSIDE_TEST(bug_606.py)
PYSIDE_TEST(bug_656.py)
+PYSIDE_TEST(bug_686.py)
PYSIDE_TEST(bug_699.py)
PYSIDE_TEST(bug_706.py)
PYSIDE_TEST(bug_723.py)
diff --git a/tests/QtCore/bug_686.py b/tests/QtCore/bug_686.py
new file mode 100644
index 000000000..97ead98f5
--- /dev/null
+++ b/tests/QtCore/bug_686.py
@@ -0,0 +1,85 @@
+import unittest
+from PySide.QtCore import *
+
+class MyWriteThread(QThread):
+ def __init__(self, lock):
+ QThread.__init__(self)
+ self.lock = lock
+ self.started = False
+ self.canQuit = False
+
+ def run(self):
+ self.started = True
+ while not self.lock.tryLockForWrite():
+ pass
+ self.canQuit = True
+
+class MyReadThread(QThread):
+ def __init__(self, lock):
+ QThread.__init__(self)
+ self.lock = lock
+ self.started = False
+ self.canQuit = False
+
+ def run(self):
+ self.started = True
+ while not self.lock.tryLockForRead():
+ pass
+ self.canQuit = True
+
+class MyMutexedThread(QThread):
+ def __init__(self, mutex):
+ QThread.__init__(self)
+ self.mutex = mutex
+ self.started = False
+ self.canQuit = False
+
+ def run(self):
+ self.started = True
+ while not self.mutex.tryLock():
+ pass
+ self.canQuit = True
+
+class TestQMutex (unittest.TestCase):
+
+ def testReadLocker(self):
+ lock = QReadWriteLock()
+ thread = MyWriteThread(lock)
+
+ with QReadLocker(lock):
+ thread.start()
+ while not thread.started:
+ pass
+ self.assertFalse(thread.canQuit)
+
+ thread.wait()
+ self.assertTrue(thread.canQuit)
+
+ def testWriteLocker(self):
+ lock = QReadWriteLock()
+ thread = MyReadThread(lock)
+
+ with QWriteLocker(lock):
+ thread.start()
+ while not thread.started:
+ pass
+ self.assertFalse(thread.canQuit)
+
+ thread.wait()
+ self.assertTrue(thread.canQuit)
+
+ def testMutexLocker(self):
+ mutex = QMutex()
+ thread = MyMutexedThread(mutex)
+
+ with QMutexLocker(mutex):
+ thread.start()
+ while not thread.started:
+ pass
+ self.assertFalse(thread.canQuit)
+
+ thread.wait()
+ self.assertTrue(thread.canQuit)
+
+if __name__ == '__main__':
+ unittest.main()