From aeefd3fe454bfaed093355278b1e2caa84bfd77a Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 30 Jun 2024 12:33:25 +0900 Subject: Rename threading nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- doc/classchart.doc | 8 +- doc/html/annotated.html | 12 +- doc/html/classchart.html | 8 +- doc/html/classes.html | 66 ++-- doc/html/environment.html | 12 +- doc/html/functions.html | 56 +-- doc/html/headerfilesynonyms | 2 +- doc/html/headers.html | 10 +- doc/html/hierarchy.html | 12 +- doc/html/index | 88 ++--- doc/html/ntqdeepcopy.html | 10 +- doc/html/ntqmutex.html | 195 ----------- doc/html/ntqregexp.html | 4 +- doc/html/ntqsemaphore.html | 149 -------- doc/html/ntqt.html | 2 +- doc/html/ntqthread.html | 247 -------------- doc/html/ntqthreadstorage.html | 189 ---------- doc/html/ntqwaitcondition.html | 197 ----------- doc/html/qmutex-h.html | 159 --------- doc/html/qmutex-members.html | 52 --- doc/html/qmutexlocker-members.html | 49 --- doc/html/qmutexlocker.html | 220 ------------ doc/html/qsemaphore-h.html | 126 ------- doc/html/qsemaphore-members.html | 55 --- doc/html/qt.dcf | 124 +++---- doc/html/qthread-h.html | 166 --------- doc/html/qthread-members.html | 59 ---- doc/html/qthreadstorage-h.html | 140 -------- doc/html/qthreadstorage-members.html | 51 --- doc/html/qwaitcondition-h.html | 124 ------- doc/html/qwaitcondition-members.html | 51 --- doc/html/thread.html | 12 +- doc/html/threads.html | 18 +- doc/html/titleindex | 34 +- doc/html/tqmap.html | 2 +- doc/html/tqmutex-h.html | 159 +++++++++ doc/html/tqmutex-members.html | 52 +++ doc/html/tqmutex.html | 195 +++++++++++ doc/html/tqmutexlocker-members.html | 49 +++ doc/html/tqmutexlocker.html | 220 ++++++++++++ doc/html/tqsemaphore-h.html | 126 +++++++ doc/html/tqsemaphore-members.html | 55 +++ doc/html/tqsemaphore.html | 149 ++++++++ doc/html/tqthread-h.html | 166 +++++++++ doc/html/tqthread-members.html | 59 ++++ doc/html/tqthread.html | 247 ++++++++++++++ doc/html/tqthreadstorage-h.html | 140 ++++++++ doc/html/tqthreadstorage-members.html | 51 +++ doc/html/tqthreadstorage.html | 189 ++++++++++ doc/html/tqvaluelist.html | 2 +- doc/html/tqvaluevector.html | 2 +- doc/html/tqwaitcondition-h.html | 124 +++++++ doc/html/tqwaitcondition-members.html | 51 +++ doc/html/tqwaitcondition.html | 197 +++++++++++ doc/html/whatsthis | 12 +- doc/man/man3/tqdeepcopy.3qt | 2 +- doc/man/man3/tqmap.3qt | 2 +- doc/man/man3/tqmutex.3qt | 30 +- doc/man/man3/tqmutexlocker.3qt | 52 +-- doc/man/man3/tqregexp.3qt | 2 +- doc/man/man3/tqsemaphore.3qt | 34 +- doc/man/man3/tqt.3qt | 2 +- doc/man/man3/tqthread.3qt | 72 ++-- doc/man/man3/tqthreadstorage.3qt | 58 ++-- doc/man/man3/tqvaluelist.3qt | 2 +- doc/man/man3/tqvaluevector.3qt | 2 +- doc/man/man3/tqwaitcondition.3qt | 46 +-- doc/porting3.doc | 2 +- doc/threads.doc | 24 +- doc/tqmap.doc | 2 +- doc/tqvaluelist.doc | 2 +- doc/tqvaluevector.doc | 2 +- examples/thread/prodcons/prodcons.cpp | 6 +- examples/thread/semaphores/main.cpp | 6 +- include/ntqmutex.h | 1 - include/ntqsemaphore.h | 1 - include/ntqthread.h | 1 - include/ntqthreadstorage.h | 1 - include/ntqwaitcondition.h | 1 - include/private/qmutex_p.h | 1 - include/private/qmutexpool_p.h | 1 - include/private/qthreadinstance_p.h | 1 - include/private/tqmutex_p.h | 1 + include/private/tqmutexpool_p.h | 1 + include/private/tqthreadinstance_p.h | 1 + include/tqmutex.h | 1 + include/tqsemaphore.h | 1 + include/tqthread.h | 1 + include/tqthreadstorage.h | 1 + include/tqwaitcondition.h | 1 + qmake/generators/projectgenerator.cpp | 2 +- src/codecs/tqtextcodec.cpp | 2 +- src/codecs/tqtextcodecfactory.cpp | 2 +- src/dialogs/qfiledialog.cpp | 2 +- src/inputmethod/qinputcontextfactory.cpp | 2 +- src/kernel/ntqt.h | 8 +- src/kernel/ntqthread.h | 147 -------- src/kernel/qapplication.cpp | 6 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qeventloop.cpp | 4 +- src/kernel/qeventloop_unix.cpp | 2 +- src/kernel/qeventloop_unix_glib.cpp | 4 +- src/kernel/qeventloop_x11.cpp | 2 +- src/kernel/qeventloop_x11_glib.cpp | 4 +- src/kernel/qmetaobject.cpp | 2 +- src/kernel/qt_kernel.pri | 8 +- src/kernel/qthread.cpp | 271 --------------- src/kernel/qthread_unix.cpp | 569 ------------------------------- src/kernel/tqobject.cpp | 6 +- src/kernel/tqobject.h | 2 +- src/kernel/tqthread.cpp | 271 +++++++++++++++ src/kernel/tqthread.h | 147 ++++++++ src/kernel/tqthread_unix.cpp | 569 +++++++++++++++++++++++++++++++ src/kernel/tqwidget.cpp | 2 +- src/styles/qcommonstyle.cpp | 2 +- src/tools/ntqmutex.h | 117 ------- src/tools/ntqsemaphore.h | 81 ----- src/tools/ntqthreadstorage.h | 95 ------ src/tools/ntqwaitcondition.h | 79 ----- src/tools/qcomlibrary.cpp | 2 +- src/tools/qcstring.cpp | 2 +- src/tools/qdir_unix.cpp | 2 +- src/tools/qgarray.cpp | 2 +- src/tools/qglist.cpp | 2 +- src/tools/qgvector.cpp | 2 +- src/tools/qlocale.cpp | 4 +- src/tools/qmutex_p.h | 74 ---- src/tools/qmutex_unix.cpp | 535 ----------------------------- src/tools/qmutexpool.cpp | 155 --------- src/tools/qmutexpool_p.h | 80 ----- src/tools/qregexp.cpp | 4 +- src/tools/qsemaphore.cpp | 255 -------------- src/tools/qt_tools.pri | 30 +- src/tools/qthreadinstance_p.h | 111 ------ src/tools/qthreadstorage_unix.cpp | 366 -------------------- src/tools/qwaitcondition_unix.cpp | 316 ----------------- src/tools/tqmutex.h | 117 +++++++ src/tools/tqmutex_p.h | 74 ++++ src/tools/tqmutex_unix.cpp | 535 +++++++++++++++++++++++++++++ src/tools/tqmutexpool.cpp | 155 +++++++++ src/tools/tqmutexpool_p.h | 80 +++++ src/tools/tqsemaphore.cpp | 255 ++++++++++++++ src/tools/tqsemaphore.h | 81 +++++ src/tools/tqstring.cpp | 2 +- src/tools/tqthreadinstance_p.h | 111 ++++++ src/tools/tqthreadstorage.h | 95 ++++++ src/tools/tqthreadstorage_unix.cpp | 366 ++++++++++++++++++++ src/tools/tqwaitcondition.h | 79 +++++ src/tools/tqwaitcondition_unix.cpp | 316 +++++++++++++++++ tutorial/t15/main.h | 2 +- 150 files changed, 5969 insertions(+), 5969 deletions(-) delete mode 100644 doc/html/ntqmutex.html delete mode 100644 doc/html/ntqsemaphore.html delete mode 100644 doc/html/ntqthread.html delete mode 100644 doc/html/ntqthreadstorage.html delete mode 100644 doc/html/ntqwaitcondition.html delete mode 100644 doc/html/qmutex-h.html delete mode 100644 doc/html/qmutex-members.html delete mode 100644 doc/html/qmutexlocker-members.html delete mode 100644 doc/html/qmutexlocker.html delete mode 100644 doc/html/qsemaphore-h.html delete mode 100644 doc/html/qsemaphore-members.html delete mode 100644 doc/html/qthread-h.html delete mode 100644 doc/html/qthread-members.html delete mode 100644 doc/html/qthreadstorage-h.html delete mode 100644 doc/html/qthreadstorage-members.html delete mode 100644 doc/html/qwaitcondition-h.html delete mode 100644 doc/html/qwaitcondition-members.html create mode 100644 doc/html/tqmutex-h.html create mode 100644 doc/html/tqmutex-members.html create mode 100644 doc/html/tqmutex.html create mode 100644 doc/html/tqmutexlocker-members.html create mode 100644 doc/html/tqmutexlocker.html create mode 100644 doc/html/tqsemaphore-h.html create mode 100644 doc/html/tqsemaphore-members.html create mode 100644 doc/html/tqsemaphore.html create mode 100644 doc/html/tqthread-h.html create mode 100644 doc/html/tqthread-members.html create mode 100644 doc/html/tqthread.html create mode 100644 doc/html/tqthreadstorage-h.html create mode 100644 doc/html/tqthreadstorage-members.html create mode 100644 doc/html/tqthreadstorage.html create mode 100644 doc/html/tqwaitcondition-h.html create mode 100644 doc/html/tqwaitcondition-members.html create mode 100644 doc/html/tqwaitcondition.html delete mode 120000 include/ntqmutex.h delete mode 120000 include/ntqsemaphore.h delete mode 120000 include/ntqthread.h delete mode 120000 include/ntqthreadstorage.h delete mode 120000 include/ntqwaitcondition.h delete mode 120000 include/private/qmutex_p.h delete mode 120000 include/private/qmutexpool_p.h delete mode 120000 include/private/qthreadinstance_p.h create mode 120000 include/private/tqmutex_p.h create mode 120000 include/private/tqmutexpool_p.h create mode 120000 include/private/tqthreadinstance_p.h create mode 120000 include/tqmutex.h create mode 120000 include/tqsemaphore.h create mode 120000 include/tqthread.h create mode 120000 include/tqthreadstorage.h create mode 120000 include/tqwaitcondition.h delete mode 100644 src/kernel/ntqthread.h delete mode 100644 src/kernel/qthread.cpp delete mode 100644 src/kernel/qthread_unix.cpp create mode 100644 src/kernel/tqthread.cpp create mode 100644 src/kernel/tqthread.h create mode 100644 src/kernel/tqthread_unix.cpp delete mode 100644 src/tools/ntqmutex.h delete mode 100644 src/tools/ntqsemaphore.h delete mode 100644 src/tools/ntqthreadstorage.h delete mode 100644 src/tools/ntqwaitcondition.h delete mode 100644 src/tools/qmutex_p.h delete mode 100644 src/tools/qmutex_unix.cpp delete mode 100644 src/tools/qmutexpool.cpp delete mode 100644 src/tools/qmutexpool_p.h delete mode 100644 src/tools/qsemaphore.cpp delete mode 100644 src/tools/qthreadinstance_p.h delete mode 100644 src/tools/qthreadstorage_unix.cpp delete mode 100644 src/tools/qwaitcondition_unix.cpp create mode 100644 src/tools/tqmutex.h create mode 100644 src/tools/tqmutex_p.h create mode 100644 src/tools/tqmutex_unix.cpp create mode 100644 src/tools/tqmutexpool.cpp create mode 100644 src/tools/tqmutexpool_p.h create mode 100644 src/tools/tqsemaphore.cpp create mode 100644 src/tools/tqsemaphore.h create mode 100644 src/tools/tqthreadinstance_p.h create mode 100644 src/tools/tqthreadstorage.h create mode 100644 src/tools/tqthreadstorage_unix.cpp create mode 100644 src/tools/tqwaitcondition.h create mode 100644 src/tools/tqwaitcondition_unix.cpp diff --git a/doc/classchart.doc b/doc/classchart.doc index 5ca797101..12f6c47e3 100644 --- a/doc/classchart.doc +++ b/doc/classchart.doc @@ -50,7 +50,7 @@ - + @@ -279,7 +279,7 @@ - + @@ -293,7 +293,7 @@ - + @@ -314,7 +314,7 @@ - + diff --git a/doc/html/annotated.html b/doc/html/annotated.html index 57ac9aecf..9633f5286 100644 --- a/doc/html/annotated.html +++ b/doc/html/annotated.html @@ -248,8 +248,8 @@ body { background: #ffffff; color: black; } TQMouseEventParameters that describe a mouse event TQMoveEventEvent parameters for move events TQMovieIncremental loading of animations or images, signalling as it progresses -TQMutexAccess serialization between threads -TQMutexLockerSimplifies locking and unlocking TQMutexes +TQMutexAccess serialization between threads +TQMutexLockerSimplifies locking and unlocking TQMutexes TQNPInstanceTQObject that is a web browser plugin TQNPStreamStream of data provided to a TQNPInstance by the browser TQNPWidgetTQWidget that is a web browser plugin window @@ -298,7 +298,7 @@ body { background: #ffffff; color: black; } TQSGIStyleSGI/Irix look and feel TQScrollBarVertical or horizontal scroll bar TQScrollViewScrolling area with on-demand scroll bars -TQSemaphoreRobust integer semaphore +TQSemaphoreRobust integer semaphore TQServerSocketTCP-based server TQSessionManagerAccess to the session manager TQSettingsPersistent platform-independent application settings @@ -368,8 +368,8 @@ body { background: #ffffff; color: black; } TQTextIStreamConvenience class for input streams TQTextOStreamConvenience class for output streams TQTextStreamBasic functions for reading and writing text using a TQIODevice -TQThreadPlatform-independent threads -TQThreadStoragePer-thread data storage +TQThreadPlatform-independent threads +TQThreadStoragePer-thread data storage TQTimeClock time functions TQTimeEditTime editor TQTimerTimer signals and single-shot timers @@ -399,7 +399,7 @@ body { background: #ffffff; color: black; } TQValueVectorValue-based template class that provides a dynamic array TQVariantActs like a union for the most common TQt data types TQWMatrix2D transformations of a coordinate system -TQWaitConditionAllows waiting/waking for conditions between threads +TQWaitConditionAllows waiting/waking for conditions between threads TQWhatsThisSimple description of any widget, i.e. answering the question "What's this?" TQWheelEventParameters that describe a wheel event TQWidgetThe base class of all user interface objects diff --git a/doc/html/classchart.html b/doc/html/classchart.html index 133d1d5f0..ae9cc1704 100644 --- a/doc/html/classchart.html +++ b/doc/html/classchart.html @@ -40,7 +40,7 @@ body { background: #ffffff; color: black; } - + @@ -269,7 +269,7 @@ body { background: #ffffff; color: black; } - + @@ -283,7 +283,7 @@ body { background: #ffffff; color: black; } - + @@ -304,7 +304,7 @@ body { background: #ffffff; color: black; } - + diff --git a/doc/html/classes.html b/doc/html/classes.html index da7b6b481..7f0ff8e3a 100644 --- a/doc/html/classes.html +++ b/doc/html/classes.html @@ -73,7 +73,7 @@ classes, see TQt's Main Classes. TQAccessibleObject - + TQImageConsumer @@ -233,7 +233,7 @@ classes, see TQt's Main Classes. TQPtrVector -TQThread +TQThread @@ -244,14 +244,14 @@ classes, see TQt's Main Classes. TQPushButton -TQThreadStorage +TQThreadStorage TQDomNode - - + + R TQRadioButton @@ -262,7 +262,7 @@ classes, see TQt's Main Classes. TQDomNodeList - + TQRangeControl @@ -329,9 +329,9 @@ classes, see TQt's Main Classes. TQDragLeaveEvent TQLayoutIterator -S - -* + + + TQToolTip @@ -340,7 +340,7 @@ classes, see TQt's Main Classes. TQDragMoveEvent TQLCDNumber - +S TQScrollBar TQToolTipGroup @@ -363,7 +363,7 @@ classes, see TQt's Main Classes. TQLineEdit -TQSemaphore +TQSemaphore TQTranslatorMessage @@ -557,13 +557,13 @@ classes, see TQt's Main Classes. TQCanvasView - + TQMenuData TQSpacerItem W -TQWaitCondition +TQWaitCondition TQCDEStyle @@ -634,7 +634,7 @@ classes, see TQt's Main Classes. TQChildEvent - + TQMotifDialog * @@ -645,7 +645,7 @@ classes, see TQt's Main Classes. TQClipboard - + TQMotifPlusStyle @@ -680,7 +680,7 @@ classes, see TQt's Main Classes. TQGLColormap - + TQSqlField @@ -691,7 +691,7 @@ classes, see TQt's Main Classes. TQGLContext - + TQSqlFieldInfo @@ -706,7 +706,7 @@ classes, see TQt's Main Classes. TQSqlForm - + TQComboBox @@ -717,7 +717,7 @@ classes, see TQt's Main Classes. TQSqlIndex - + TQComboTableItem @@ -734,22 +734,22 @@ classes, see TQt's Main Classes. TQGridLayout -TQMutex +TQMutex TQSqlQuery - + TQConstString TQGridView -TQMutexLocker +TQMutexLocker TQSqlRecord - + TQContextMenuEvent @@ -760,10 +760,10 @@ classes, see TQt's Main Classes. TQSqlRecordInfo - + - + TQGuardedPtr @@ -924,8 +924,8 @@ classes, see TQt's Main Classes. TQPalette TQStyleSheetItem - - + + TQDesktopWidget @@ -935,8 +935,8 @@ classes, see TQt's Main Classes. TQPen TQSyntaxHighlighter - - + + TQDial @@ -946,8 +946,8 @@ classes, see TQt's Main Classes. TQPicture T TQt - - + + TQDialog @@ -957,8 +957,8 @@ classes, see TQt's Main Classes. TQPixmap TQTab - - + +

* Extension classes of Motif and Netscape. diff --git a/doc/html/environment.html b/doc/html/environment.html index 4805996dc..28860e8b1 100644 --- a/doc/html/environment.html +++ b/doc/html/environment.html @@ -41,16 +41,16 @@ event handling, access to system settings, TQEventThe base class of all event classes. Event objects contain event parameters TQFontDatabaseInformation about the fonts available in the underlying window system TQMimeSourceFactoryExtensible provider of mime-typed data -TQMutexAccess serialization between threads -TQMutexLockerSimplifies locking and unlocking TQMutexes +TQMutexAccess serialization between threads +TQMutexLockerSimplifies locking and unlocking TQMutexes TQPixmapCacheApplication-global cache for pixmaps -TQSemaphoreRobust integer semaphore +TQSemaphoreRobust integer semaphore TQSessionManagerAccess to the session manager -TQThreadPlatform-independent threads -TQThreadStoragePer-thread data storage +TQThreadPlatform-independent threads +TQThreadStoragePer-thread data storage TQTranslatorInternationalization support for text output TQTranslatorMessageTranslator message and its properties -TQWaitConditionAllows waiting/waking for conditions between threads +TQWaitConditionAllows waiting/waking for conditions between threads


diff --git a/doc/html/functions.html b/doc/html/functions.html index e8c20a9b5..e432996ca 100644 --- a/doc/html/functions.html +++ b/doc/html/functions.html @@ -236,7 +236,7 @@ abort: TQButton TQCheckBox TQPushButton TQRadioButton
  • autoReset: TQProgressDialog
  • autoUnload: TQLibrary
  • available: - TQSemaphore TQSound
  • availableGeometry: + TQSemaphore TQSound
  • availableGeometry: TQDesktopWidget
  • awake: TQEventLoop
  • back: @@ -606,7 +606,7 @@ c: TQHttp
  • currentTab: TQTabBar
  • currentText: TQComboBox TQComboTableItem TQListBox
  • currentThread: - TQThread
  • currentTime: + TQThread
  • currentTime: TQTime
  • currentValueText: TQSpinBox
  • currentVerticalAlignmentChanged: TQTextEdit
  • cursor: @@ -887,7 +887,7 @@ echoMode: TQApplication TQDialog TQEventLoop TQPopupMenu TQSqlDatabase TQSqlQuery
  • executedQuery: TQSqlQuery
  • exists: TQDir TQFile TQFileInfo
  • exit: - TQApplication TQEventLoop TQThread
  • exitLoop: + TQApplication TQEventLoop TQThread
  • exitLoop: TQEventLoop
  • exitStatus: TQProcess
  • expand: TQGridLayout
  • expandTo: @@ -938,7 +938,7 @@ falseText: TQBoxLayout TQGridLayout
  • finish: TQSplashScreen
  • finishButton: TQWizard
  • finished: - TQMovie TQNetworkProtocol TQThread TQUrlOperator
  • first: + TQMovie TQNetworkProtocol TQThread TQUrlOperator
  • first: TQDataBrowser TQFocusData TQPtrList TQSqlQuery TQValueList TQValueVector
  • firstChild: TQDomNode TQListView TQListViewItem
  • firstItem: TQIconView TQListBox
  • firstRecordAvailable: @@ -1100,7 +1100,7 @@ hScrollBarMode: TQTabDialog
  • hasHost: TQUrl
  • hasKey: TQHttpHeader
  • hasLocalData: - TQThreadStorage
  • hasMarkedText: + TQThreadStorage
  • hasMarkedText: TQMultiLineEdit
  • hasMouse: TQWidget
  • hasMouseTracking: TQWidget
  • hasOkButton: @@ -1543,13 +1543,13 @@ label: TQImage TQPixmap
  • loadImages: TQWidgetFactory
  • local8Bit: TQString
  • localData: - TQThreadStorage
  • localFileToUri: + TQThreadStorage
  • localFileToUri: TQUriDrag
  • localName: TQDomNode TQXmlAttributes
  • locale: TQTextCodec
  • localeAwareCompare: TQString
  • lock: - TQApplication TQMutex
  • locked: - TQApplication TQMutex
  • logicalDpiX: + TQApplication TQMutex
  • locked: + TQApplication TQMutex
  • logicalDpiX: TQPaintDeviceMetrics
  • logicalDpiY: TQPaintDeviceMetrics
  • logicalFontSize: TQStyleSheetItem
  • logicalFontSizeStep: @@ -1702,9 +1702,9 @@ m11: TQLabel
  • msec: TQTime
  • msecsTo: TQTime
  • msleep: - TQThread
  • multiLinesEnabled: + TQThread
  • multiLinesEnabled: TQListViewItem
  • mutex: - TQMutexLocker
  • + TQMutexLocker
  • name: TQColor TQDomAttr TQDomDocumentType TQFile TQLocale TQMetaProperty TQObject TQSqlCursor TQSqlField TQSqlFieldInfo TQSqlIndex TQStyleSheetItem TQTextCodec TQUrlInfo
  • nameFilter: TQDir TQUrlOperator
  • nameToType: @@ -1810,11 +1810,11 @@ object: TQGuardedPtr TQListViewItemIterator TQMapConstIterator TQMapIterator TQPoint TQPtrListIterator TQSize TQValueListConstIterator TQValueListIterator
  • operator*=: TQPoint TQSize TQWMatrix
  • operator+: TQCString TQCanvasItemList TQPoint TQRegion TQSize TQString TQValueList
  • operator++: - TQAsciiCacheIterator TQAsciiDictIterator TQCacheIterator TQDictIterator TQIntCacheIterator TQIntDictIterator TQLayoutIterator TQListViewItemIterator TQMapConstIterator TQMapIterator TQPtrDictIterator TQPtrListIterator TQSemaphore TQValueListConstIterator TQValueListIterator
  • operator+=: - TQAsciiCacheIterator TQAsciiDictIterator TQCString TQCacheIterator TQIntCacheIterator TQIntDictIterator TQListViewItemIterator TQPoint TQPtrDictIterator TQPtrListIterator TQRegion TQSemaphore TQSize TQString TQValueList TQValueListIterator
  • operator-: + TQAsciiCacheIterator TQAsciiDictIterator TQCacheIterator TQDictIterator TQIntCacheIterator TQIntDictIterator TQLayoutIterator TQListViewItemIterator TQMapConstIterator TQMapIterator TQPtrDictIterator TQPtrListIterator TQSemaphore TQValueListConstIterator TQValueListIterator
  • operator+=: + TQAsciiCacheIterator TQAsciiDictIterator TQCString TQCacheIterator TQIntCacheIterator TQIntDictIterator TQListViewItemIterator TQPoint TQPtrDictIterator TQPtrListIterator TQRegion TQSemaphore TQSize TQString TQValueList TQValueListIterator
  • operator-: TQPoint TQRegion TQSize
  • operator--: - TQAsciiCacheIterator TQCacheIterator TQIntCacheIterator TQListViewItemIterator TQMapConstIterator TQMapIterator TQPtrListIterator TQSemaphore TQValueListConstIterator TQValueListIterator
  • operator-=: - TQAsciiCacheIterator TQCacheIterator TQIntCacheIterator TQListViewItemIterator TQPoint TQPtrListIterator TQRegion TQSemaphore TQSize TQValueListIterator
  • operator->: + TQAsciiCacheIterator TQCacheIterator TQIntCacheIterator TQListViewItemIterator TQMapConstIterator TQMapIterator TQPtrListIterator TQSemaphore TQValueListConstIterator TQValueListIterator
  • operator-=: + TQAsciiCacheIterator TQCacheIterator TQIntCacheIterator TQListViewItemIterator TQPoint TQPtrListIterator TQRegion TQSemaphore TQSize TQValueListIterator
  • operator->: TQGuardedPtr
  • operator/: TQPoint TQSize
  • operator/=: TQPoint TQSize
  • operator<: @@ -2249,8 +2249,8 @@ rBottom: TQTableItem
  • rowStretch: TQGridLayout
  • rtti: TQCanvasEllipse TQCanvasItem TQCanvasLine TQCanvasPolygon TQCanvasPolygonalItem TQCanvasRectangle TQCanvasSpline TQCanvasSprite TQCanvasText TQCheckListItem TQCheckTableItem TQComboTableItem TQIconViewItem TQListBoxItem TQListViewItem TQTableItem
  • run: - TQThread
  • running: - TQMovie TQThread
  • rwidth: + TQThread
  • running: + TQMovie TQThread
  • rwidth: TQSize
  • rx: TQPoint
  • ry: TQPoint
  • @@ -2668,7 +2668,7 @@ sRect: TQTextEdit
  • setListBox: TQComboBox
  • setListStyle: TQStyleSheetItem
  • setLocalData: - TQThreadStorage
  • setLogicalFontSize: + TQThreadStorage
  • setLogicalFontSize: TQStyleSheetItem
  • setLogicalFontSizeStep: TQStyleSheetItem
  • setLooping: TQImageConsumer
  • setLoops: @@ -3062,7 +3062,7 @@ sRect: TQSplitter
  • skipWhiteSpace: TQTextStream
  • skippedEntity: TQXmlContentHandler
  • sleep: - TQThread
  • sliderMoved: + TQThread
  • sliderMoved: TQScrollBar TQSlider
  • sliderPressed: TQScrollBar TQSlider
  • sliderRect: TQScrollBar TQSlider
  • sliderReleased: @@ -3104,7 +3104,7 @@ sRect: TQWidget
  • standardIcon: TQMessageBox
  • standardSizes: TQFontDatabase
  • start: - TQNetworkProtocol TQProcess TQThread TQTime TQTimer TQUrlOperator
  • startCDATA: + TQNetworkProtocol TQProcess TQThread TQTime TQTimer TQUrlOperator
  • startCDATA: TQXmlLexicalHandler
  • startDTD: TQXmlLexicalHandler
  • startDocument: TQXmlContentHandler
  • startDrag: @@ -3208,7 +3208,7 @@ tab: TQIconView TQListBox TQListView TQListViewItem TQTable
  • takeNode: TQPtrList
  • target: TQDomProcessingInstruction TQDragObject
  • terminate: - TQThread
  • testBit: + TQThread
  • testBit: TQBitArray
  • testOption: TQGLFormat
  • testWFlags: TQWidget
  • text: @@ -3323,7 +3323,7 @@ tab: TQScrollView
  • topRight: TQRect
  • topRow: TQTableSelection
  • total: - TQSemaphore
  • totalCost: + TQSemaphore
  • totalCost: TQAsciiCache TQCache TQIntCache
  • totalHeight: TQListViewItem
  • totalSteps: TQProgressBar TQProgressDialog
  • tr: @@ -3340,8 +3340,8 @@ tab: TQPixmap
  • trueText: TQDataTable
  • truncate: TQCString TQMemArray TQString
  • tryAccess: - TQSemaphore
  • tryLock: - TQApplication TQMutex
  • tryTerminate: + TQSemaphore
  • tryLock: + TQApplication TQMutex
  • tryTerminate: TQProcess
  • turnOffChild: TQCheckListItem
  • type: TQApplication TQCheckListItem TQEvent TQMetaProperty TQNPStream TQSocketDevice TQSocketNotifier TQSqlError TQSqlField TQSqlFieldInfo TQVariant TQXmlAttributes
  • typeID: @@ -3363,7 +3363,7 @@ ucs2: TQTabletEvent
  • unite: TQRect TQRegion
  • unload: TQLibrary
  • unlock: - TQApplication TQMutex
  • unparsedEntityDecl: + TQApplication TQMutex
  • unparsedEntityDecl: TQXmlDTDHandler
  • unpause: TQMovie
  • unregisterDecoderFactory: TQImageDecoder
  • unregisterSocketNotifier: @@ -3406,7 +3406,7 @@ ucs2: TQActionGroup
  • usesTextLabel: TQMainWindow TQToolButton
  • usesTextLabelChanged: TQMainWindow
  • usleep: - TQThread
  • utf8: + TQThread
  • utf8: TQString
  • vScrollBarMode: TQScrollView
  • valid: @@ -3444,10 +3444,10 @@ vScrollBarMode: TQScrollView
  • visualRect: TQStyle
  • wait: - TQThread TQWaitCondition
  • waitForMore: + TQThread TQWaitCondition
  • waitForMore: TQSocket TQSocketDevice
  • wakeAll: - TQWaitCondition
  • wakeOne: - TQWaitCondition
  • wakeUp: + TQWaitCondition
  • wakeOne: + TQWaitCondition
  • wakeUp: TQEventLoop
  • wakeUpGuiThread: TQApplication
  • warning: TQMessageBox TQXmlErrorHandler
  • wasCanceled: diff --git a/doc/html/headerfilesynonyms b/doc/html/headerfilesynonyms index c6040d9c3..a9bbf1a54 100644 --- a/doc/html/headerfilesynonyms +++ b/doc/html/headerfilesynonyms @@ -114,7 +114,7 @@ qmimesource.h ntqmime.h qmimesourcefactory.h ntqmime.h qwindowsmime.h ntqmime.h qmacmime.h ntqmime.h -qmutexlocker.h ntqmutex.h +tqmutexlocker.h tqmutex.h qnetworkoperation.h ntqnetworkprotocol.h qnpstream.h ntqnp.h qnpwidget.h ntqnp.h diff --git a/doc/html/headers.html b/doc/html/headers.html index 94af47d1e..00d10c5ad 100644 --- a/doc/html/headers.html +++ b/doc/html/headers.html @@ -147,7 +147,7 @@ body { background: #ffffff; color: black; }
  • qmotifwidget.h
  • ntqmovie.h
  • ntqmultilineedit.h -
  • ntqmutex.h +
  • tqmutex.h
  • ntqnamespace.h
  • ntqnetworkprotocol.h
  • ntqnp.h @@ -187,7 +187,7 @@ body { background: #ffffff; color: black; }
  • ntqrtlcodec.h
  • ntqscrollbar.h
  • ntqscrollview.h -
  • ntqsemaphore.h +
  • tqsemaphore.h
  • ntqserversocket.h
  • ntqsessionmanager.h
  • ntqsettings.h @@ -241,8 +241,8 @@ body { background: #ffffff; color: black; }
  • tqtextedit.h
  • tqtextstream.h
  • tqtextview.h -
  • ntqthread.h -
  • ntqthreadstorage.h +
  • tqthread.h +
  • tqthreadstorage.h
  • tqtimer.h
  • ntqtoolbar.h
  • ntqtoolbox.h @@ -262,7 +262,7 @@ body { background: #ffffff; color: black; }
  • ntqvbox.h
  • ntqvbuttongroup.h
  • ntqvgroupbox.h -
  • ntqwaitcondition.h +
  • tqwaitcondition.h
  • ntqwhatsthis.h
  • tqwidget.h
  • tqwidgetfactory.h diff --git a/doc/html/hierarchy.html b/doc/html/hierarchy.html index 0f13a5781..6ccf95be0 100644 --- a/doc/html/hierarchy.html +++ b/doc/html/hierarchy.html @@ -161,8 +161,8 @@ classes in the TQt API.
  • TQMimeSource
  • TQMimeSourceFactory
  • TQMovie -
  • TQMutex -
  • TQMutexLocker +
  • TQMutex +
  • TQMutexLocker
  • TQNPlugin
  • TQNPStream
  • TQPaintDevice @@ -212,7 +212,7 @@ classes in the TQt API.
  • TQRect
  • TQRegExp
  • TQRegion -
  • TQSemaphore +
  • TQSemaphore
  • TQSettings
  • TQSimpleRichText
  • TQSize @@ -494,7 +494,7 @@ classes in the TQt API.
  • TQCheckTableItem
  • TQComboTableItem -
  • TQThread +
  • TQThread
  • TQToolTip
  • TQWhatsThis @@ -523,7 +523,7 @@ classes in the TQt API.
  • TQTextIStream
  • TQTextOStream -
  • TQThreadStorage +
  • TQThreadStorage
  • TQTime
  • TQTranslatorMessage
  • TQUrl @@ -539,7 +539,7 @@ classes in the TQt API.
  • TQValueListIterator
  • TQValueVector
  • TQVariant -
  • TQWaitCondition +
  • TQWaitCondition
  • TQWidgetFactory
  • TQWidgetPlugin
  • TQWindowsMime diff --git a/doc/html/index b/doc/html/index index fa9d3bf3c..e73b3c12a 100644 --- a/doc/html/index +++ b/doc/html/index @@ -4139,17 +4139,17 @@ "QMultiLineEdit::setCursorPosition" ntqmultilineedit.html#setCursorPosition "QMultiLineEdit::setEdited" ntqmultilineedit.html#setEdited "QMultiLineEdit::textLine" ntqmultilineedit.html#textLine -"QMutex" ntqmutex.html -"QMutex::lock" ntqmutex.html#lock -"QMutex::locked" ntqmutex.html#locked -"QMutex::tryLock" ntqmutex.html#tryLock -"QMutex::unlock" ntqmutex.html#unlock -"QMutex::~QMutex" ntqmutex.html#~QMutex -"QMutexLocker" qmutexlocker.html -"QMutexLocker::mutex" qmutexlocker.html#mutex -"QMutexLocker::~QMutexLocker" qmutexlocker.html#~QMutexLocker -"QMutexPool::get" qmutexpool.html#get -"QMutexPool::~QMutexPool" qmutexpool.html#~QMutexPool +"TQMutex" tqmutex.html +"TQMutex::lock" tqmutex.html#lock +"TQMutex::locked" tqmutex.html#locked +"TQMutex::tryLock" tqmutex.html#tryLock +"TQMutex::unlock" tqmutex.html#unlock +"TQMutex::~TQMutex" tqmutex.html#~TQMutex +"TQMutexLocker" tqmutexlocker.html +"TQMutexLocker::mutex" tqmutexlocker.html#mutex +"TQMutexLocker::~TQMutexLocker" tqmutexlocker.html#~TQMutexLocker +"TQMutexPool::get" tqmutexpool.html#get +"TQMutexPool::~TQMutexPool" tqmutexpool.html#~TQMutexPool "QNPInstance" qnpinstance.html "QNPInstance::InstanceMode" qnpinstance.html#InstanceMode "QNPInstance::Reason" qnpinstance.html#Reason @@ -5186,15 +5186,15 @@ "QScrollView::visibleWidth" ntqscrollview.html#visibleWidth "QScrollView::visibleWidth" ntqscrollview.html#visibleWidth-prop "QScrollView::~QScrollView" ntqscrollview.html#~QScrollView -"QSemaphore" ntqsemaphore.html -"QSemaphore::available" ntqsemaphore.html#available -"QSemaphore::operator++" ntqsemaphore.html#operator++ -"QSemaphore::operator+=" ntqsemaphore.html#operator+-eq -"QSemaphore::operator--" ntqsemaphore.html#operator-- -"QSemaphore::operator-=" ntqsemaphore.html#operator--eq -"QSemaphore::total" ntqsemaphore.html#total -"QSemaphore::tryAccess" ntqsemaphore.html#tryAccess -"QSemaphore::~QSemaphore" ntqsemaphore.html#~QSemaphore +"TQSemaphore" tqsemaphore.html +"TQSemaphore::available" tqsemaphore.html#available +"TQSemaphore::operator++" tqsemaphore.html#operator++ +"TQSemaphore::operator+=" tqsemaphore.html#operator+-eq +"TQSemaphore::operator--" tqsemaphore.html#operator-- +"TQSemaphore::operator-=" tqsemaphore.html#operator--eq +"TQSemaphore::total" tqsemaphore.html#total +"TQSemaphore::tryAccess" tqsemaphore.html#tryAccess +"TQSemaphore::~TQSemaphore" tqsemaphore.html#~TQSemaphore "QServerSocket" ntqserversocket.html "QServerSocket::address" ntqserversocket.html#address "QServerSocket::newConnection" ntqserversocket.html#newConnection @@ -6679,25 +6679,25 @@ "TQTextView::readOnly" tqtextview.html#readOnly-prop "TQTextView::undoDepth" tqtextview.html#undoDepth-prop "TQTextView::undoRedoEnabled" tqtextview.html#undoRedoEnabled-prop -"QThread" ntqthread.html -"QThread::Priority" ntqthread.html#Priority -"QThread::currentThread" ntqthread.html#currentThread -"QThread::exit" ntqthread.html#exit -"QThread::finished" ntqthread.html#finished -"QThread::msleep" ntqthread.html#msleep -"QThread::run" ntqthread.html#run -"QThread::running" ntqthread.html#running -"QThread::sleep" ntqthread.html#sleep -"QThread::start" ntqthread.html#start -"QThread::terminate" ntqthread.html#terminate -"QThread::usleep" ntqthread.html#usleep -"QThread::wait" ntqthread.html#wait -"QThread::~QThread" ntqthread.html#~QThread -"QThreadStorage" ntqthreadstorage.html -"QThreadStorage::hasLocalData" ntqthreadstorage.html#hasLocalData -"QThreadStorage::localData" ntqthreadstorage.html#localData -"QThreadStorage::setLocalData" ntqthreadstorage.html#setLocalData -"QThreadStorage::~QThreadStorage" ntqthreadstorage.html#~QThreadStorage +"TQThread" tqthread.html +"TQThread::Priority" tqthread.html#Priority +"TQThread::currentThread" tqthread.html#currentThread +"TQThread::exit" tqthread.html#exit +"TQThread::finished" tqthread.html#finished +"TQThread::msleep" tqthread.html#msleep +"TQThread::run" tqthread.html#run +"TQThread::running" tqthread.html#running +"TQThread::sleep" tqthread.html#sleep +"TQThread::start" tqthread.html#start +"TQThread::terminate" tqthread.html#terminate +"TQThread::usleep" tqthread.html#usleep +"TQThread::wait" tqthread.html#wait +"TQThread::~TQThread" tqthread.html#~TQThread +"TQThreadStorage" tqthreadstorage.html +"TQThreadStorage::hasLocalData" tqthreadstorage.html#hasLocalData +"TQThreadStorage::localData" tqthreadstorage.html#localData +"TQThreadStorage::setLocalData" tqthreadstorage.html#setLocalData +"TQThreadStorage::~TQThreadStorage" tqthreadstorage.html#~TQThreadStorage "TQTime" tqtime.html "TQTime::addMSecs" tqtime.html#addMSecs "TQTime::addSecs" tqtime.html#addSecs @@ -7249,11 +7249,11 @@ "QWMatrix::shear" ntqwmatrix.html#shear "QWMatrix::transformationMode" ntqwmatrix.html#transformationMode "QWMatrix::translate" ntqwmatrix.html#translate -"QWaitCondition" ntqwaitcondition.html -"QWaitCondition::wait" ntqwaitcondition.html#wait -"QWaitCondition::wakeAll" ntqwaitcondition.html#wakeAll -"QWaitCondition::wakeOne" ntqwaitcondition.html#wakeOne -"QWaitCondition::~QWaitCondition" ntqwaitcondition.html#~QWaitCondition +"TQWaitCondition" tqwaitcondition.html +"TQWaitCondition::wait" tqwaitcondition.html#wait +"TQWaitCondition::wakeAll" tqwaitcondition.html#wakeAll +"TQWaitCondition::wakeOne" tqwaitcondition.html#wakeOne +"TQWaitCondition::~TQWaitCondition" tqwaitcondition.html#~TQWaitCondition "QWhatsThis" ntqwhatsthis.html "QWhatsThis::add" ntqwhatsthis.html#add "QWhatsThis::clicked" ntqwhatsthis.html#clicked diff --git a/doc/html/ntqdeepcopy.html b/doc/html/ntqdeepcopy.html index 2e84c58de..37e76561c 100644 --- a/doc/html/ntqdeepcopy.html +++ b/doc/html/ntqdeepcopy.html @@ -92,24 +92,24 @@ that use shared classes. In the example below, the variable global_stringglobal_string will result in a deep copy.

         TQDeepCopy<TQString> global_string;  // global string data
    -    TQMutex global_mutex;               // mutex to protext global_string
    +    TQMutex global_mutex;               // mutex to protext global_string
     
         ...
     
         void setGlobalString( const TQString &str )
         {
    -        global_mutex.lock();
    +        global_mutex.lock();
             global_string = str;           // global_string is a deep copy of str
    -        global_mutex.unlock();
    +        global_mutex.unlock();
         }
     
         ...
     
         void MyThread::run()
         {
    -        global_mutex.lock();
    +        global_mutex.lock();
             TQString str = global_string;          // str is a deep copy of global_string
    -        global_mutex.unlock();
    +        global_mutex.unlock();
     
             // process the string data
             ...
    diff --git a/doc/html/ntqmutex.html b/doc/html/ntqmutex.html
    deleted file mode 100644
    index a3fa2426f..000000000
    --- a/doc/html/ntqmutex.html
    +++ /dev/null
    @@ -1,195 +0,0 @@
    -
    -
    -
    -
    -
    -TQMutex Class
    -
    -
    -
    -
    -
    -
    -
    -
    - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

    TQMutex Class Reference

    - -

    The TQMutex class provides access serialization between threads. -More... -

    All the functions in this class are thread-safe when TQt is built with thread support.

    -

    #include <ntqmutex.h> -

    List of all member functions. -

    Public Members

    - -

    Detailed Description

    - - - -The TQMutex class provides access serialization between threads. -

    - -

    The purpose of a TQMutex is to protect an object, data structure or -section of code so that only one thread can access it at a time -(This is similar to the Java synchronized keyword). For -example, say there is a method which prints a message to the user -on two lines: -

    -    int number = 6;
    -
    -    void method1()
    -    {
    -        number *= 5;
    -        number /= 4;
    -    }
    -
    -    void method2()
    -    {
    -        number *= 3;
    -        number /= 2;
    -    }
    -    
    - -

    If these two methods are called in succession, the following happens: -

    -    // method1()
    -    number *= 5;        // number is now 30
    -    number /= 4;        // number is now 7
    -
    -    // method2()
    -    number *= 3;        // nubmer is now 21
    -    number /= 2;        // number is now 10
    -    
    - -

    If these two methods are called simultaneously from two threads then the -following sequence could result: -

    -    // Thread 1 calls method1()
    -    number *= 5;        // number is now 30
    -
    -    // Thread 2 calls method2().
    -    //
    -    // Most likely Thread 1 has been put to sleep by the operating
    -    // system to allow Thread 2 to run.
    -    number *= 3;        // number is now 90
    -    number /= 2;        // number is now 45
    -
    -    // Thread 1 finishes executing.
    -    number /= 4;        // number is now 11, instead of 10
    -    
    - -

    If we add a mutex, we should get the result we want: -

    -    TQMutex mutex;
    -    int number = 6;
    -
    -    void method1()
    -    {
    -        mutex.lock();
    -        number *= 5;
    -        number /= 4;
    -        mutex.unlock();
    -    }
    -
    -    void method2()
    -    {
    -        mutex.lock();
    -        number *= 3;
    -        number /= 2;
    -        mutex.unlock();
    -    }
    -    
    - -

    Then only one thread can modify number at any given time and -the result is correct. This is a trivial example, of course, but -applies to any other case where things need to happen in a -particular sequence. -

    When you call lock() in a thread, other threads that try to call -lock() in the same place will block until the thread that got the -lock calls unlock(). A non-blocking alternative to lock() is -tryLock(). -

    See also Environment Classes and Threading. - -


    Member Function Documentation

    -

    TQMutex::TQMutex ( bool recursive = FALSE ) -

    -Constructs a new mutex. The mutex is created in an unlocked state. -A recursive mutex is created if recursive is TRUE; a normal -mutex is created if recursive is FALSE (the default). With a -recursive mutex, a thread can lock the same mutex multiple times -and it will not be unlocked until a corresponding number of -unlock() calls have been made. - -

    TQMutex::~TQMutex () [virtual] -

    -Destroys the mutex. -

    Warning: If you destroy a mutex that still holds a lock the -resultant behavior is undefined. - -

    void TQMutex::lock () -

    -Attempt to lock the mutex. If another thread has locked the mutex -then this call will block until that thread has unlocked it. -

    See also unlock() and locked(). - -

    bool TQMutex::locked () -

    -Returns TRUE if the mutex is locked by another thread; otherwise -returns FALSE. -

    Warning: Due to differing implementations of recursive mutexes on -various platforms, calling this function from the same thread that -previously locked the mutex will return undefined results. -

    See also lock() and unlock(). - -

    bool TQMutex::tryLock () -

    -Attempt to lock the mutex. If the lock was obtained, this function -returns TRUE. If another thread has locked the mutex, this -function returns FALSE, instead of waiting for the mutex to become -available, i.e. it does not block. -

    If the lock was obtained, the mutex must be unlocked with unlock() -before another thread can successfully lock it. -

    See also lock(), unlock(), and locked(). - -

    void TQMutex::unlock () -

    -Unlocks the mutex. Attempting to unlock a mutex in a different -thread to the one that locked it results in an error. Unlocking a -mutex that is not locked results in undefined behaviour (varies -between different Operating Systems' thread implementations). -

    See also lock() and locked(). - - -


    -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


    - -
    Copyright © 2007 -TrolltechTrademarks -
    TQt 3.3.8
    -
    - diff --git a/doc/html/ntqregexp.html b/doc/html/ntqregexp.html index 6bfdc27bb..f75a27a82 100644 --- a/doc/html/ntqregexp.html +++ b/doc/html/ntqregexp.html @@ -112,8 +112,8 @@ similar way to command shells. A good text on regexps is Mastering Regular E

    Experienced regexp users may prefer to skip the introduction and go directly to the relevant information.

    In case of multi-threaded programming, note that TQRegExp depends on -TQThreadStorage internally. For that reason, TQRegExp should only be -used with threads started with TQThread, i.e. not with threads +TQThreadStorage internally. For that reason, TQRegExp should only be +used with threads started with TQThread, i.e. not with threads started with platform-specific APIs.

      diff --git a/doc/html/ntqsemaphore.html b/doc/html/ntqsemaphore.html deleted file mode 100644 index b51410c9c..000000000 --- a/doc/html/ntqsemaphore.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - -TQSemaphore Class - - - - - - - -
      - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

      TQSemaphore Class Reference

      - -

      The TQSemaphore class provides a robust integer semaphore. -More... -

      All the functions in this class are thread-safe when TQt is built with thread support.

      -

      #include <ntqsemaphore.h> -

      List of all member functions. -

      Public Members

      - -

      Detailed Description

      - - - -The TQSemaphore class provides a robust integer semaphore. -

      - -

      A TQSemaphore can be used to serialize thread execution, in a -similar way to a TQMutex. A semaphore differs from a mutex, in -that a semaphore can be accessed by more than one thread at a -time. -

      For example, suppose we have an application that stores data in a -large tree structure. The application creates 10 threads -(commonly called a thread pool) to perform searches on the tree. -When the application searches the tree for some piece of data, it -uses one thread per base node to do the searching. A semaphore -could be used to make sure that two threads don't try to search -the same branch of the tree at the same time. -

      A non-computing example of a semaphore would be dining at a -restuarant. A semaphore is initialized to have a maximum count -equal to the number of chairs in the restuarant. As people -arrive, they want a seat. As seats are filled, the semaphore is -accessed, once per person. As people leave, the access is -released, allowing more people to enter. If a party of 10 people -want to be seated, but there are only 9 seats, those 10 people -will wait, but a party of 4 people would be seated (taking the -available seats to 5, making the party of 10 people wait longer). -

      When a semaphore is created it is given a number which is the -maximum number of concurrent accesses it will permit. Accesses to -the sempahore are gained using operator++() or operator+=(), and -released with operator--() or operator-=(). The number of -accesses allowed is retrieved with available(), and the total -number with total(). Note that the incrementing functions will -block if there aren't enough available accesses. Use tryAccess() -if you want to acquire accesses without blocking. -

      See also Environment Classes and Threading. - -


      Member Function Documentation

      -

      TQSemaphore::TQSemaphore ( int maxcount ) -

      -Creates a new semaphore. The semaphore can be concurrently -accessed at most maxcount times. - -

      TQSemaphore::~TQSemaphore () [virtual] -

      -Destroys the semaphore. -

      Warning: If you destroy a semaphore that has accesses in use the -resultant behavior is undefined. - -

      int TQSemaphore::available () const -

      -Returns the number of accesses currently available to the -semaphore. - -

      int TQSemaphore::operator++ ( int ) -

      -Postfix ++ operator. -

      Try to get access to the semaphore. If available() == 0, this -call will block until it can get access, i.e. until available() > -0. - -

      int TQSemaphore::operator+= ( int n ) -

      -Try to get access to the semaphore. If available() < n, this -call will block until it can get all the accesses it wants, i.e. -until available() >= n. - -

      int TQSemaphore::operator-- ( int ) -

      -Postfix -- operator. -

      Release access of the semaphore. This wakes all threads waiting -for access to the semaphore. - -

      int TQSemaphore::operator-= ( int n ) -

      -Release n accesses to the semaphore. - -

      int TQSemaphore::total () const -

      -Returns the total number of accesses to the semaphore. - -

      bool TQSemaphore::tryAccess ( int n ) -

      -Try to get access to the semaphore. If available() < n, this -function will return FALSE immediately. If available() >= n, -this function will take n accesses and return TRUE. This -function does not block. - - -

      -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


      - -
      Copyright © 2007 -TrolltechTrademarks -
      TQt 3.3.8
      -
      - diff --git a/doc/html/ntqt.html b/doc/html/ntqt.html index 0785cd686..3c4dcc93c 100644 --- a/doc/html/ntqt.html +++ b/doc/html/ntqt.html @@ -35,7 +35,7 @@ body { background: #ffffff; color: black; } that need to be global-like. More...

      #include <ntqnamespace.h> -

      Inherited by TQObject, TQPixmap, TQBrush, TQCanvasItem, TQCursor, TQPainter, TQEvent, TQIconViewItem, TQKeySequence, TQListViewItem, TQCustomMenuItem, TQPen, TQStyleSheetItem, TQSyntaxHighlighter, TQTab, TQTableItem, TQThread, TQToolTip, and TQWhatsThis. +

      Inherited by TQObject, TQPixmap, TQBrush, TQCanvasItem, TQCursor, TQPainter, TQEvent, TQIconViewItem, TQKeySequence, TQListViewItem, TQCustomMenuItem, TQPen, TQStyleSheetItem, TQSyntaxHighlighter, TQTab, TQTableItem, TQThread, TQToolTip, and TQWhatsThis.

      List of all member functions.

      Public Members

        diff --git a/doc/html/ntqthread.html b/doc/html/ntqthread.html deleted file mode 100644 index edd77b60b..000000000 --- a/doc/html/ntqthread.html +++ /dev/null @@ -1,247 +0,0 @@ - - - - - -TQThread Class - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        TQThread Class Reference

        - -

        The TQThread class provides platform-independent threads. -More... -

        All the functions in this class are thread-safe when TQt is built with thread support.

        -

        #include <ntqthread.h> -

        Inherits TQt. -

        List of all member functions. -

        Public Members

        -
          -
        • TQThread ( unsigned int stackSize = 0 )
        • -
        • virtual ~TQThread ()
        • -
        • bool wait ( unsigned long time = ULONG_MAX )
        • -
        • enum Priority { IdlePriority, LowestPriority, LowPriority, NormalPriority, HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority }
        • -
        • void start ( Priority priority = InheritPriority )
        • -
        • void terminate ()
        • -
        • bool finished () const
        • -
        • bool running () const
        • -
        -

        Static Public Members

        - -

        Protected Members

        -
          -
        • virtual void run () = 0
        • -
        -

        Static Protected Members

        -
          -
        • void sleep ( unsigned long secs )
        • -
        • void msleep ( unsigned long msecs )
        • -
        • void usleep ( unsigned long usecs )
        • -
        -

        Detailed Description

        - - - -The TQThread class provides platform-independent threads. -

        - -

        A TQThread represents a separate thread of control within the -program; it shares data with all the other threads within the -process but executes independently in the way that a separate -program does on a multitasking operating system. Instead of -starting in main(), TQThreads begin executing in run(). You inherit -run() to include your code. For example: -

        -    class MyThread : public TQThread {
        -
        -    public:
        -
        -        virtual void run();
        -
        -    };
        -
        -    void MyThread::run()
        -    {
        -        for( int count = 0; count < 20; count++ ) {
        -            sleep( 1 );
        -            tqDebug( "Ping!" );
        -        }
        -    }
        -
        -    int main()
        -    {
        -        MyThread a;
        -        MyThread b;
        -        a.start();
        -        b.start();
        -        a.wait();
        -        b.wait();
        -    }
        -    
        - -

        This will start two threads, each of which writes Ping! 20 times -to the screen and exits. The wait() calls at the end of main() are -necessary because exiting main() ends the program, unceremoniously -killing all other threads. Each MyThread stops executing when it -reaches the end of MyThread::run(), just as an application does -when it leaves main(). -

        See also Thread Support in TQt, Environment Classes, and Threading. - -


        Member Type Documentation

        -

        TQThread::Priority

        - -

        This enum type indicates how the operating system should schedule -newly created threads. -

          -
        • TQThread::IdlePriority - scheduled only when no other threads are -running. -
        • TQThread::LowestPriority - scheduled less often than LowPriority. -
        • TQThread::LowPriority - scheduled less often than NormalPriority. -
        • TQThread::NormalPriority - the default priority of the operating -system. -
        • TQThread::HighPriority - scheduled more often than NormalPriority. -
        • TQThread::HighestPriority - scheduled more often then HighPriority. -
        • TQThread::TimeCriticalPriority - scheduled as often as possible. -
        • TQThread::InheritPriority - use the same priority as the creating -thread. This is the default. -
        -

        Member Function Documentation

        -

        TQThread::TQThread ( unsigned int stackSize = 0 ) -

        -Constructs a new thread. The thread does not begin executing until -start() is called. -

        If stackSize is greater than zero, the maximum stack size is -set to stackSize bytes, otherwise the maximum stack size is -automatically determined by the operating system. -

        Warning: Most operating systems place minimum and maximum limits -on thread stack sizes. The thread will fail to start if the stack -size is outside these limits. - -

        TQThread::~TQThread () [virtual] -

        -TQThread destructor. -

        Note that deleting a TQThread object will not stop the execution of -the thread it represents. Deleting a running TQThread (i.e. -finished() returns FALSE) will probably result in a program crash. -You can wait() on a thread to make sure that it has finished. - -

        TQt::HANDLE TQThread::currentThread () [static] -

        -This returns the thread handle of the currently executing thread. -

        Warning: The handle returned by this function is used for internal -purposes and should not be used in any application code. On -Windows, the returned value is a pseudo handle for the current -thread, and it cannot be used for numerical comparison. - -

        void TQThread::exit () [static] -

        -Ends the execution of the calling thread and wakes up any threads -waiting for its termination. - -

        bool TQThread::finished () const -

        -Returns TRUE if the thread is finished; otherwise returns FALSE. - -

        void TQThread::msleep ( unsigned long msecs ) [static protected] -

        -System independent sleep. This causes the current thread to sleep -for msecs milliseconds - -

        void TQThread::run () [pure virtual protected] -

        - -

        This method is pure virtual, and must be implemented in derived -classes in order to do useful work. Returning from this method -will end the execution of the thread. -

        See also wait(). - -

        bool TQThread::running () const -

        -Returns TRUE if the thread is running; otherwise returns FALSE. - -

        void TQThread::sleep ( unsigned long secs ) [static protected] -

        -System independent sleep. This causes the current thread to sleep -for secs seconds. - -

        void TQThread::start ( Priority priority = InheritPriority ) -

        -Begins execution of the thread by calling run(), which should be -reimplemented in a TQThread subclass to contain your code. The -operating system will schedule the thread according to the priority argument. -

        If you try to start a thread that is already running, this -function will wait until the the thread has finished and then -restart the thread. -

        See also Priority. - -

        void TQThread::terminate () -

        -This function terminates the execution of the thread. The thread -may or may not be terminated immediately, depending on the -operating system's scheduling policies. Use TQThread::wait() -after terminate() for synchronous termination. -

        When the thread is terminated, all threads waiting for the -the thread to finish will be woken up. -

        Warning: This function is dangerous, and its use is discouraged. -The thread can be terminated at any point in its code path. Threads -can be terminated while modifying data. There is no chance for -the thread to cleanup after itself, unlock any held mutexes, etc. -In short, use this function only if absolutely necessary. - -

        void TQThread::usleep ( unsigned long usecs ) [static protected] -

        -System independent sleep. This causes the current thread to sleep -for usecs microseconds - -

        bool TQThread::wait ( unsigned long time = ULONG_MAX ) -

        -A thread calling this function will block until either of these -conditions is met: -

          -
        • The thread associated with this TQThread object has finished -execution (i.e. when it returns from run()). This function -will return TRUE if the thread has finished. It also returns -TRUE if the thread has not been started yet. -
        • time milliseconds has elapsed. If time is ULONG_MAX (the -default), then the wait will never timeout (the thread must -return from run()). This function will return FALSE if the -wait timed out. -
        -

        This provides similar functionality to the POSIX pthread_join() function. - - -


        -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/ntqthreadstorage.html b/doc/html/ntqthreadstorage.html deleted file mode 100644 index c18111bd1..000000000 --- a/doc/html/ntqthreadstorage.html +++ /dev/null @@ -1,189 +0,0 @@ - - - - - -TQThreadStorage Class - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        TQThreadStorage Class Reference

        - -

        The TQThreadStorage class provides per-thread data storage. -More... -

        All the functions in this class are thread-safe when TQt is built with thread support.

        -

        #include <ntqthreadstorage.h> -

        List of all member functions. -

        Public Members

        - -

        Detailed Description

        - - -The TQThreadStorage class provides per-thread data storage. -

        - - -

        TQThreadStorage is a template class that provides per-thread data -storage. -

        Note that due to compiler limitations, TQThreadStorage can only store pointers. -

        The setLocalData() function stores a single thread-specific value -for the calling thread. The data can be accessed later using the -localData() functions. TQThreadStorage takes ownership of the -data (which must be created on the heap with new) and deletes -it when the thread exits (either normally or via termination). -

        The hasLocalData() function allows the programmer to determine if -data has previously been set using the setLocalData() function. -This is useful for lazy initializiation. -

        For example, the following code uses TQThreadStorage to store a -single cache for each thread that calls the cacheObject() and -removeFromCache() functions. The cache is automatically -deleted when the calling thread exits (either normally or via -termination). -

        -    TQThreadStorage<TQCache<SomeClass> *> caches;
        -
        -    void cacheObject( const TQString &key, SomeClass *object )
        -    {
        -        if ( ! caches.hasLocalData() )
        -            caches.setLocalData( new TQCache<SomeClass> );
        -
        -        caches.localData()->insert( key, object );
        -    }
        -
        -    void removeFromCache( const TQString &key )
        -    {
        -        if ( ! caches.hasLocalData() )
        -            return; // nothing to do
        -
        -        caches.localData()->remove( key );
        -    }
        -    
        - -

        Caveats -

        -

          -

        • As noted above, TQThreadStorage can only store pointers due to -compiler limitations. Support for value-based objects will be -added when the majority of compilers are able to support partial -template specialization. -

        • The destructor does not -delete per-thread data. TQThreadStorage only deletes per-thread -data when the thread exits or when setLocalData() is called -multiple times. -

        • TQThreadStorage can only be used with threads started with -TQThread. It cannot be used with threads started with -platform-specific APIs. -

        • As a corollary to the above, platform-specific APIs cannot be -used to exit or terminate a TQThread using TQThreadStorage. Doing so -will cause all per-thread data to be leaked. See TQThread::exit() -and TQThread::terminate(). -

        • TQThreadStorage can be used to store data for the main() -thread after TQApplication has been constructed. TQThreadStorage -deletes all data set for the main() thread when TQApplication is -destroyed, regardless of whether or not the main() thread has -actually finished. -

        • The implementation of TQThreadStorage limits the total number of -TQThreadStorage objects to 256. An unlimited number of threads -can store per-thread data in each TQThreadStorage object. -

        -

        See also Environment Classes and Threading. - -


        Member Function Documentation

        -

        TQThreadStorage::TQThreadStorage () -

        - -

        Constructs a new per-thread data storage object. - -

        TQThreadStorage::~TQThreadStorage () -

        - -

        Destroys the per-thread data storage object. -

        Note: The per-thread data stored is not deleted. Any data left -in TQThreadStorage is leaked. Make sure that all threads using -TQThreadStorage have exited before deleting the TQThreadStorage. -

        See also hasLocalData(). - -

        bool TQThreadStorage::hasLocalData () const -

        - -

        Returns TRUE if the calling thread has non-zero data available; -otherwise returns FALSE. -

        See also localData(). - -

        T & TQThreadStorage::localData () -

        - -

        Returns a reference to the data that was set by the calling -thread. -

        Note: TQThreadStorage can only store pointers. This function -returns a reference to the pointer that was set by the calling -thread. The value of this reference is 0 if no data was set by -the calling thread, -

        See also hasLocalData(). - -

        T TQThreadStorage::localData () const -

        - -This is an overloaded member function, provided for convenience. It behaves essentially like the above function. -

        Returns a copy of the data that was set by the calling thread. -

        Note: TQThreadStorage can only store pointers. This function -returns a pointer to the data that was set by the calling thread. -If no data was set by the calling thread, this function returns 0. -

        See also hasLocalData(). - -

        void TQThreadStorage::setLocalData ( T data ) -

        - -

        Sets the local data for the calling thread to data. It can be -accessed later using the localData() functions. -

        If data is 0, this function deletes the previous data (if -any) and returns immediately. -

        If data is non-zero, TQThreadStorage takes ownership of the data and deletes it automatically either when the thread exits -(either normally or via termination) or when setLocalData() is -called again. -

        Note: TQThreadStorage can only store pointers. The data -argument must be either a pointer to an object created on the heap -(i.e. using new) or 0. You should not delete data -yourself; TQThreadStorage takes ownership and will delete the data itself. -

        See also localData() and hasLocalData(). - - -


        -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/ntqwaitcondition.html b/doc/html/ntqwaitcondition.html deleted file mode 100644 index c497b58a2..000000000 --- a/doc/html/ntqwaitcondition.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - -TQWaitCondition Class - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        TQWaitCondition Class Reference

        - -

        The TQWaitCondition class allows waiting/waking for conditions between threads. -More... -

        All the functions in this class are thread-safe when TQt is built with thread support.

        -

        #include <ntqwaitcondition.h> -

        List of all member functions. -

        Public Members

        - -

        Detailed Description

        - - - -The TQWaitCondition class allows waiting/waking for conditions between threads. -

        - -

        TQWaitConditions allow a thread to tell other threads that some -sort of condition has been met; one or many threads can block -waiting for a TQWaitCondition to set a condition with wakeOne() or -wakeAll(). Use wakeOne() to wake one randomly selected event or -wakeAll() to wake them all. For example, say we have three tasks -that should be performed every time the user presses a key; each -task could be split into a thread, each of which would have a -run() body like this: -

        -    TQWaitCondition key_pressed;
        -
        -    for (;;) {
        -        key_pressed.wait(); // This is a TQWaitCondition global variable
        -        // Key was pressed, do something interesting
        -        do_something();
        -    }
        -    
        - -

        A fourth thread would read key presses and wake the other three -threads up every time it receives one, like this: -

        -    TQWaitCondition key_pressed;
        -
        -    for (;;) {
        -        getchar();
        -        // Causes any thread in key_pressed.wait() to return from
        -        // that method and continue processing
        -        key_pressed.wakeAll();
        -    }
        -    
        - -

        Note that the order the three threads are woken up in is -undefined, and that if some or all of the threads are still in -do_something() when the key is pressed, they won't be woken up -(since they're not waiting on the condition variable) and so the -task will not be performed for that key press. This can be -avoided by, for example, doing something like this: -

        -    TQMutex mymutex;
        -    TQWaitCondition key_pressed;
        -    int mycount=0;
        -
        -    // Worker thread code
        -    for (;;) {
        -        key_pressed.wait(); // This is a TQWaitCondition global variable
        -        mymutex.lock();
        -        mycount++;
        -        mymutex.unlock();
        -        do_something();
        -        mymutex.lock();
        -        mycount--;
        -        mymutex.unlock();
        -    }
        -
        -    // Key reading thread code
        -    for (;;) {
        -        getchar();
        -        mymutex.lock();
        -        // Sleep until there are no busy worker threads
        -        while( mycount > 0 ) {
        -            mymutex.unlock();
        -            sleep( 1 );
        -            mymutex.lock();
        -        }
        -        mymutex.unlock();
        -        key_pressed.wakeAll();
        -    }
        -    
        - -

        The mutexes are necessary because the results of two threads -attempting to change the value of the same variable simultaneously -are unpredictable. -

        See also Environment Classes and Threading. - -


        Member Function Documentation

        -

        TQWaitCondition::TQWaitCondition () -

        -Constructs a new event signalling, i.e. wait condition, object. - -

        TQWaitCondition::~TQWaitCondition () [virtual] -

        -Deletes the event signalling, i.e. wait condition, object. - -

        bool TQWaitCondition::wait ( unsigned long time = ULONG_MAX ) -

        -Wait on the thread event object. The thread calling this will -block until either of these conditions is met: -
          -
        • Another thread signals it using wakeOne() or wakeAll(). This -function will return TRUE in this case. -
        • time milliseconds has elapsed. If time is ULONG_MAX (the -default), then the wait will never timeout (the event must be -signalled). This function will return FALSE if the wait timed -out. -
        -

        See also wakeOne() and wakeAll(). - -

        bool TQWaitCondition::wait ( TQMutex * mutex, unsigned long time = ULONG_MAX ) -

        -This is an overloaded member function, provided for convenience. It behaves essentially like the above function. -

        Release the locked mutex and wait on the thread event object. -The mutex must be initially locked by the calling thread. If mutex is not in a locked state, this function returns immediately. -If mutex is a recursive mutex, this function returns -immediately. The mutex will be unlocked, and the calling thread -will block until either of these conditions is met: -

          -
        • Another thread signals it using wakeOne() or wakeAll(). This -function will return TRUE in this case. -
        • time milliseconds has elapsed. If time is ULONG_MAX (the -default), then the wait will never timeout (the event must be -signalled). This function will return FALSE if the wait timed -out. -
        -

        The mutex will be returned to the same locked state. This function -is provided to allow the atomic transition from the locked state -to the wait state. -

        See also wakeOne() and wakeAll(). - -

        void TQWaitCondition::wakeAll () -

        -This wakes all threads waiting on the TQWaitCondition. The order in -which the threads are woken up depends on the operating system's -scheduling policies, and cannot be controlled or predicted. -

        See also wakeOne(). - -

        void TQWaitCondition::wakeOne () -

        -This wakes one thread waiting on the TQWaitCondition. The thread -that is woken up depends on the operating system's scheduling -policies, and cannot be controlled or predicted. -

        See also wakeAll(). - - -


        -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qmutex-h.html b/doc/html/qmutex-h.html deleted file mode 100644 index 8f9eba58e..000000000 --- a/doc/html/qmutex-h.html +++ /dev/null @@ -1,159 +0,0 @@ - - - - - -ntqmutex.h Include File - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        ntqmutex.h

        - -

        This is the verbatim text of the ntqmutex.h include file. It is provided only for illustration; the copyright remains with Trolltech. -


        -
        -/****************************************************************************
        -** $Id: qt/ntqmutex.h   3.3.8   edited Jan 11 14:38 $
        -**
        -** Definition of TQMutex class
        -**
        -** Created : 931107
        -**
        -** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        -**
        -** This file is part of the tools module of the TQt GUI Toolkit.
        -**
        -** This file may be used under the terms of the GNU General Public
        -** License versions 2.0 or 3.0 as published by the Free Software
        -** Foundation and appearing in the file LICENSE.GPL included in the
        -** packaging of this file. Alternatively you may (at your option) use any
        -** later version of the GNU General Public License if such license has
        -** been publicly approved by Trolltech ASA (or its successors, if any)
        -** and the KDE Free TQt Foundation.
        -**
        -** Please review the following information to ensure GNU General
        -** Public Licensing requirements will be met:
        -** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        -** If you are unsure which license is appropriate for your use, please
        -** review the following information:
        -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        -** or contact the sales department at sales@trolltech.com.
        -**
        -** This file may be used under the terms of the Q Public License as
        -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        -** included in the packaging of this file.  Licensees holding valid TQt
        -** Commercial licenses may use this file in accordance with the TQt
        -** Commercial License Agreement provided with the Software.
        -**
        -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        -** herein.
        -**
        -**********************************************************************/
        -
        -#ifndef TQMUTEX_H
        -#define TQMUTEX_H
        -
        -#ifndef QT_H
        -#include "ntqglobal.h"
        -#endif // QT_H
        -
        -#if defined(TQT_THREAD_SUPPORT)
        -
        -class TQMutexPrivate;
        -
        -const int Q_MUTEX_NORMAL = 0;
        -const int Q_MUTEX_RECURSIVE = 1;
        -
        -class TQ_EXPORT TQMutex
        -{
        -    friend class TQThread;
        -    friend class TQWaitCondition;
        -    friend class TQWaitConditionPrivate;
        -
        -public:
        -    TQMutex(bool recursive = FALSE);
        -    virtual ~TQMutex();
        -
        -    void lock();
        -    void unlock();
        -    bool locked();
        -    bool tryLock();
        -
        -private:
        -    TQMutexPrivate * d;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    TQMutex( const TQMutex & );
        -    TQMutex &operator=( const TQMutex & );
        -#endif
        -};
        -
        -class TQ_EXPORT TQMutexLocker
        -{
        -public:
        -    TQMutexLocker( TQMutex * );
        -    ~TQMutexLocker();
        -
        -    TQMutex *mutex() const;
        -
        -private:
        -    TQMutex *mtx;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    TQMutexLocker( const TQMutexLocker & );
        -    TQMutexLocker &operator=( const TQMutexLocker & );
        -#endif
        -};
        -
        -inline TQMutexLocker::TQMutexLocker( TQMutex *m )
        -    : mtx( m )
        -{
        -    if ( mtx ) mtx->lock();
        -}
        -
        -inline TQMutexLocker::~TQMutexLocker()
        -{
        -    if ( mtx ) mtx->unlock();
        -}
        -
        -inline TQMutex *TQMutexLocker::mutex() const
        -{
        -    return mtx;
        -}
        -
        -#endif
        -
        -#endif
        -
        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qmutex-members.html b/doc/html/qmutex-members.html deleted file mode 100644 index 9c7933d93..000000000 --- a/doc/html/qmutex-members.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - -TQMutex Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQMutex

        - -

        This is the complete list of member functions for -TQMutex, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qmutexlocker-members.html b/doc/html/qmutexlocker-members.html deleted file mode 100644 index 236d9586f..000000000 --- a/doc/html/qmutexlocker-members.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - -TQMutexLocker Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQMutexLocker

        - -

        This is the complete list of member functions for -TQMutexLocker, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qmutexlocker.html b/doc/html/qmutexlocker.html deleted file mode 100644 index d14309c36..000000000 --- a/doc/html/qmutexlocker.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - -TQMutexLocker Class - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        TQMutexLocker Class Reference

        - -

        The TQMutexLocker class simplifies locking and unlocking TQMutexes. -More... -

        All the functions in this class are thread-safe when TQt is built with thread support.

        -

        #include <ntqmutex.h> -

        List of all member functions. -

        Public Members

        - -

        Detailed Description

        - - -The TQMutexLocker class simplifies locking and unlocking TQMutexes. -

        -

        - -

        The purpose of TQMutexLocker is to simplify TQMutex locking and -unlocking. Locking and unlocking a TQMutex in complex functions and -statements or in exception handling code is error prone and -difficult to debug. TQMutexLocker should be used in such situations -to ensure that the state of the mutex is well defined and always -locked and unlocked properly. -

        TQMutexLocker should be created within a function where a TQMutex -needs to be locked. The mutex is locked when TQMutexLocker is -created, and unlocked when TQMutexLocker is destroyed. -

        For example, this complex function locks a TQMutex upon entering -the function and unlocks the mutex at all the exit points: -

        -    int complexFunction( int flag )
        -    {
        -        mutex.lock();
        -
        -        int return_value = 0;
        -
        -        switch ( flag ) {
        -        case 0:
        -        case 1:
        -            {
        -                mutex.unlock();
        -                return moreComplexFunction( flag );
        -            }
        -
        -        case 2:
        -            {
        -                int status = anotherFunction();
        -                if ( status < 0 ) {
        -                    mutex.unlock();
        -                    return -2;
        -                }
        -                return_value = status + flag;
        -                break;
        -            }
        -
        -        default:
        -            {
        -                if ( flag > 10 ) {
        -                    mutex.unlock();
        -                    return -1;
        -                }
        -                break;
        -            }
        -        }
        -
        -        mutex.unlock();
        -        return return_value;
        -    }
        -    
        - -

        This example function will get more complicated as it is -developed, which increases the likelihood that errors will occur. -

        Using TQMutexLocker greatly simplifies the code, and makes it more -readable: -

        -    int complexFunction( int flag )
        -    {
        -        TQMutexLocker locker( &mutex );
        -
        -        int return_value = 0;
        -
        -        switch ( flag ) {
        -        case 0:
        -        case 1:
        -            {
        -                return moreComplexFunction( flag );
        -            }
        -
        -        case 2:
        -            {
        -                int status = anotherFunction();
        -                if ( status < 0 )
        -                    return -2;
        -                return_value = status + flag;
        -                break;
        -            }
        -
        -        default:
        -            {
        -                if ( flag > 10 )
        -                    return -1;
        -                break;
        -            }
        -        }
        -
        -        return return_value;
        -    }
        -    
        - -

        Now, the mutex will always be unlocked when the TQMutexLocker -object is destroyed (when the function returns since locker is -an auto variable). Note that the mutex will be unlocked after -the call to moreComplexFunction() in this example, avoiding -possible bugs caused by unlocking the mutex too early, as in -the first example. -

        The same principle applies to code that throws and catches -exceptions. An exception that is not caught in the function that -has locked the mutex has no way of unlocking the mutex before the -exception is passed up the stack to the calling function. -

        TQMutexLocker also provides a mutex() member function that returns -the mutex on which the TQMutexLocker is operating. This is useful -for code that needs access to the mutex, such as -TQWaitCondition::wait(). For example: -

        -    class SignalWaiter
        -    {
        -    private:
        -        TQMutexLocker locker;
        -
        -    public:
        -        SignalWaiter( TQMutex *mutex )
        -            : locker( mutex )
        -        {
        -        }
        -
        -        void waitForSignal()
        -        {
        -            ...
        -            ...
        -            ...
        -
        -            while ( ! signalled )
        -                waitcondition.wait( locker.mutex() );
        -
        -            ...
        -            ...
        -            ...
        -        }
        -    };
        -    
        - -

        See also TQMutex, TQWaitCondition, Environment Classes, and Threading. - -


        Member Function Documentation

        -

        TQMutexLocker::TQMutexLocker ( TQMutex * mutex ) -

        - -

        Constructs a TQMutexLocker and locks mutex. The mutex will be -unlocked when the TQMutexLocker is destroyed. If mutex is zero, -TQMutexLocker does nothing. -

        See also TQMutex::lock(). - -

        TQMutexLocker::~TQMutexLocker () -

        - -

        Destroys the TQMutexLocker and unlocks the mutex which was locked -in the constructor. -

        See also TQMutexLocker::TQMutexLocker() and TQMutex::unlock(). - -

        TQMutex * TQMutexLocker::mutex () const -

        - -

        Returns a pointer to the mutex which was locked in the -constructor. -

        See also TQMutexLocker::TQMutexLocker(). - - -


        -This file is part of the TQt toolkit. -Copyright © 1995-2007 -Trolltech. All Rights Reserved.


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qsemaphore-h.html b/doc/html/qsemaphore-h.html deleted file mode 100644 index a80c1de15..000000000 --- a/doc/html/qsemaphore-h.html +++ /dev/null @@ -1,126 +0,0 @@ - - - - - -ntqsemaphore.h Include File - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        ntqsemaphore.h

        - -

        This is the verbatim text of the ntqsemaphore.h include file. It is provided only for illustration; the copyright remains with Trolltech. -


        -
        -/****************************************************************************
        -** $Id: qt/ntqsemaphore.h   3.3.8   edited Jan 11 14:38 $
        -**
        -** Definition of TQSemaphore class
        -**
        -** Created : 931107
        -**
        -** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        -**
        -** This file is part of the tools module of the TQt GUI Toolkit.
        -**
        -** This file may be used under the terms of the GNU General Public
        -** License versions 2.0 or 3.0 as published by the Free Software
        -** Foundation and appearing in the file LICENSE.GPL included in the
        -** packaging of this file. Alternatively you may (at your option) use any
        -** later version of the GNU General Public License if such license has
        -** been publicly approved by Trolltech ASA (or its successors, if any)
        -** and the KDE Free TQt Foundation.
        -**
        -** Please review the following information to ensure GNU General
        -** Public Licensing requirements will be met:
        -** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        -** If you are unsure which license is appropriate for your use, please
        -** review the following information:
        -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        -** or contact the sales department at sales@trolltech.com.
        -**
        -** This file may be used under the terms of the Q Public License as
        -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        -** included in the packaging of this file.  Licensees holding valid TQt
        -** Commercial licenses may use this file in accordance with the TQt
        -** Commercial License Agreement provided with the Software.
        -**
        -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        -** herein.
        -**
        -**********************************************************************/
        -
        -#ifndef TQSEMAPHORE_H
        -#define TQSEMAPHORE_H
        -
        -#ifndef QT_H
        -#include "ntqglobal.h"
        -#endif // QT_H
        -
        -#if defined(TQT_THREAD_SUPPORT)
        -
        -class TQSemaphorePrivate;
        -
        -class TQ_EXPORT TQSemaphore
        -{
        -public:
        -    TQSemaphore( int );
        -    virtual ~TQSemaphore();
        -
        -    int available() const;
        -    int total() const;
        -
        -    // postfix operators
        -    int operator++(int);
        -    int operator--(int);
        -
        -    int operator+=(int);
        -    int operator-=(int);
        -
        -    bool tryAccess(int);
        -
        -private:
        -    TQSemaphorePrivate *d;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    TQSemaphore(const TQSemaphore &);
        -    TQSemaphore &operator=(const TQSemaphore &);
        -#endif
        -};
        -
        -#endif
        -
        -#endif
        -
        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qsemaphore-members.html b/doc/html/qsemaphore-members.html deleted file mode 100644 index 107cb075b..000000000 --- a/doc/html/qsemaphore-members.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - -TQSemaphore Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQSemaphore

        - -

        This is the complete list of member functions for -TQSemaphore, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qt.dcf b/doc/html/qt.dcf index f6467727b..f46eb88b9 100644 --- a/doc/html/qt.dcf +++ b/doc/html/qt.dcf @@ -4835,22 +4835,22 @@
        -
        - QMutex - lock - locked - tryLock - unlock - ~QMutex -
        -
        -
        -
        - QMutexLocker - mutex - ~QMutexLocker -
        -
        +
        + TQMutex + lock + locked + tryLock + unlock + ~TQMutex +
        +
        +
        +
        + TQMutexLocker + mutex + ~TQMutexLocker +
        +
        QNetworkOperation @@ -6100,18 +6100,18 @@
        -
        - QSemaphore - available - operator++ - operator+= - operator-- - operator-= - total - tryAccess - ~QSemaphore -
        -
        +
        + TQSemaphore + available + operator++ + operator+= + operator-- + operator-= + total + tryAccess + ~TQSemaphore +
        +
        QServerSocket @@ -7909,32 +7909,32 @@
        -
        - QThread - Priority - currentThread - exit - finished - msleep - run - running - sleep - start - terminate - usleep - wait - ~QThread -
        -
        -
        -
        - QThreadStorage - hasLocalData - localData - setLocalData - ~QThreadStorage -
        -
        +
        + TQThread + Priority + currentThread + exit + finished + msleep + run + running + sleep + start + terminate + usleep + wait + ~TQThread +
        +
        +
        +
        + TQThreadStorage + hasLocalData + localData + setLocalData + ~TQThreadStorage +
        +
        TQTime @@ -8578,14 +8578,14 @@
        -
        - QWaitCondition - wait - wakeAll - wakeOne - ~QWaitCondition -
        -
        +
        + TQWaitCondition + wait + wakeAll + wakeOne + ~TQWaitCondition +
        +
        QWhatsThis diff --git a/doc/html/qthread-h.html b/doc/html/qthread-h.html deleted file mode 100644 index cbde3d13e..000000000 --- a/doc/html/qthread-h.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - -ntqthread.h Include File - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        ntqthread.h

        - -

        This is the verbatim text of the ntqthread.h include file. It is provided only for illustration; the copyright remains with Trolltech. -


        -
        -/****************************************************************************
        -** $Id: qt/ntqthread.h   3.3.8   edited Jan 11 14:38 $
        -**
        -** Definition of TQThread class
        -**
        -** Created : 931107
        -**
        -** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        -**
        -** This file is part of the kernel module of the TQt GUI Toolkit.
        -**
        -** This file may be used under the terms of the GNU General Public
        -** License versions 2.0 or 3.0 as published by the Free Software
        -** Foundation and appearing in the file LICENSE.GPL included in the
        -** packaging of this file. Alternatively you may (at your option) use any
        -** later version of the GNU General Public License if such license has
        -** been publicly approved by Trolltech ASA (or its successors, if any)
        -** and the KDE Free TQt Foundation.
        -**
        -** Please review the following information to ensure GNU General
        -** Public Licensing requirements will be met:
        -** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        -** If you are unsure which license is appropriate for your use, please
        -** review the following information:
        -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        -** or contact the sales department at sales@trolltech.com.
        -**
        -** This file may be used under the terms of the Q Public License as
        -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        -** included in the packaging of this file.  Licensees holding valid TQt
        -** Commercial licenses may use this file in accordance with the TQt
        -** Commercial License Agreement provided with the Software.
        -**
        -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        -** herein.
        -**
        -**********************************************************************/
        -
        -#ifndef TQTHREAD_H
        -#define TQTHREAD_H
        -
        -#if defined(TQT_THREAD_SUPPORT)
        -
        -#ifndef QT_H
        -#include "ntqwindowdefs.h"
        -#endif // QT_H
        -
        -#include <limits.h>
        -
        -class TQThreadInstance;
        -
        -class TQ_EXPORT TQThread : public TQt
        -{
        -public:
        -    static TQt::HANDLE currentThread();
        -
        -    static void initialize();
        -    static void cleanup();
        -
        -    static void exit();
        -
        -#ifdef Q_QDOC
        -    TQThread( unsigned int stackSize = 0 );
        -#else
        -    TQThread( unsigned int stackSize );
        -    TQThread();
        -#endif
        -
        -    virtual ~TQThread();
        -
        -    // default argument causes thread to block indefinately
        -    bool wait( unsigned long time = ULONG_MAX );
        -
        -    enum Priority {
        -	IdlePriority,
        -
        -	LowestPriority,
        -	LowPriority,
        -	NormalPriority,
        -	HighPriority,
        -	HighestPriority,
        -
        -	TimeCriticalPriority,
        -
        -	InheritPriority
        -    };
        -
        -#ifdef Q_QDOC
        -    void start( Priority = InheritPriority );
        -#else
        -    void start( Priority );
        -    void start();
        -#endif
        -
        -    void terminate();
        -
        -    bool finished() const;
        -    bool running() const;
        -
        -protected:
        -    virtual void run() = 0;
        -
        -    static void sleep( unsigned long );
        -    static void msleep( unsigned long );
        -    static void usleep( unsigned long );
        -
        -private:
        -    TQThreadInstance * d;
        -    friend class TQThreadInstance;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    TQThread( const TQThread & );
        -    TQThread &operator=( const TQThread & );
        -#endif // TQ_DISABLE_COPY
        -};
        -
        -#endif // TQT_THREAD_SUPPORT
        -
        -#endif // TQTHREAD_H
        -
        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qthread-members.html b/doc/html/qthread-members.html deleted file mode 100644 index 3cbfa108f..000000000 --- a/doc/html/qthread-members.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - -TQThread Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQThread

        - -

        This is the complete list of member functions for -TQThread, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qthreadstorage-h.html b/doc/html/qthreadstorage-h.html deleted file mode 100644 index 7efc05556..000000000 --- a/doc/html/qthreadstorage-h.html +++ /dev/null @@ -1,140 +0,0 @@ - - - - - -ntqthreadstorage.h Include File - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        ntqthreadstorage.h

        - -

        This is the verbatim text of the ntqthreadstorage.h include file. It is provided only for illustration; the copyright remains with Trolltech. -


        -
        -/****************************************************************************
        -** $Id: qt/ntqthreadstorage.h   3.3.8   edited Jan 11 14:46 $
        -**
        -** ...
        -**
        -** Copyright (C) 2005-2007 Trolltech ASA.  All rights reserved.
        -**
        -** This file is part of the tools module of the TQt GUI Toolkit.
        -**
        -** This file may be used under the terms of the GNU General Public
        -** License versions 2.0 or 3.0 as published by the Free Software
        -** Foundation and appearing in the file LICENSE.GPL included in the
        -** packaging of this file. Alternatively you may (at your option) use any
        -** later version of the GNU General Public License if such license has
        -** been publicly approved by Trolltech ASA (or its successors, if any)
        -** and the KDE Free TQt Foundation.
        -**
        -** Please review the following information to ensure GNU General
        -** Public Licensing requirements will be met:
        -** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        -** If you are unsure which license is appropriate for your use, please
        -** review the following information:
        -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        -** or contact the sales department at sales@trolltech.com.
        -**
        -** This file may be used under the terms of the Q Public License as
        -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        -** included in the packaging of this file.  Licensees holding valid TQt
        -** Commercial licenses may use this file in accordance with the TQt
        -** Commercial License Agreement provided with the Software.
        -**
        -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        -** herein.
        -**
        -**********************************************************************/
        -
        -#ifndef TQTHREADSTORAGE_H
        -#define TQTHREADSTORAGE_H
        -
        -#ifdef TQT_THREAD_SUPPORT
        -
        -#ifndef QT_H
        -#include "ntqglobal.h"
        -#endif // QT_H
        -
        -class TQ_EXPORT TQThreadStorageData
        -{
        -public:
        -    TQThreadStorageData( void (*func)(void *) );
        -    ~TQThreadStorageData();
        -
        -    void** get() const;
        -    void** set( void* p );
        -
        -    static void finish( void** );
        -    int id;
        -};
        -
        -
        -template <class T>
        -class TQThreadStorage
        -{
        -private:
        -    TQThreadStorageData d;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    // disable copy constructor and operator=
        -    TQThreadStorage( const TQThreadStorage & );
        -    TQThreadStorage &operator=( const TQThreadStorage & );
        -#endif // TQ_DISABLE_COPY
        -
        -    static void deleteData( void *x ) { delete (T)x; }
        -
        -public:
        -    inline TQThreadStorage() : d( deleteData ) {  }
        -    inline ~TQThreadStorage() { }
        -
        -    inline bool hasLocalData() const
        -    { return d.get() != 0; }
        -
        -    inline T& localData()
        -    { void **v = d.get(); if ( !v ) v = d.set( 0 ); return *(T*)v; }
        -
        -    inline T localData() const
        -    { void **v = d.get(); return ( v ? *(T*)v : 0 ); }
        -
        -    inline void setLocalData( T t )
        -    { (void) d.set( t ); }
        -};
        -
        -#endif // TQT_THREAD_SUPPORT
        -
        -#endif // TQTHREADSTORAGE_H
        -
        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qthreadstorage-members.html b/doc/html/qthreadstorage-members.html deleted file mode 100644 index ee0332e5e..000000000 --- a/doc/html/qthreadstorage-members.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - -TQThreadStorage Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQThreadStorage

        - -

        This is the complete list of member functions for -TQThreadStorage, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qwaitcondition-h.html b/doc/html/qwaitcondition-h.html deleted file mode 100644 index 06589092f..000000000 --- a/doc/html/qwaitcondition-h.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - -ntqwaitcondition.h Include File - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        ntqwaitcondition.h

        - -

        This is the verbatim text of the ntqwaitcondition.h include file. It is provided only for illustration; the copyright remains with Trolltech. -


        -
        -/****************************************************************************
        -** $Id: qt/ntqwaitcondition.h   3.3.8   edited Jan 11 14:38 $
        -**
        -** Definition of TQWaitCondition class
        -**
        -** Created : 931107
        -**
        -** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        -**
        -** This file is part of the tools module of the TQt GUI Toolkit.
        -**
        -** This file may be used under the terms of the GNU General Public
        -** License versions 2.0 or 3.0 as published by the Free Software
        -** Foundation and appearing in the file LICENSE.GPL included in the
        -** packaging of this file. Alternatively you may (at your option) use any
        -** later version of the GNU General Public License if such license has
        -** been publicly approved by Trolltech ASA (or its successors, if any)
        -** and the KDE Free TQt Foundation.
        -**
        -** Please review the following information to ensure GNU General
        -** Public Licensing requirements will be met:
        -** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        -** If you are unsure which license is appropriate for your use, please
        -** review the following information:
        -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        -** or contact the sales department at sales@trolltech.com.
        -**
        -** This file may be used under the terms of the Q Public License as
        -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        -** included in the packaging of this file.  Licensees holding valid TQt
        -** Commercial licenses may use this file in accordance with the TQt
        -** Commercial License Agreement provided with the Software.
        -**
        -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        -** herein.
        -**
        -**********************************************************************/
        -
        -#ifndef TQWAITCONDITION_H
        -#define TQWAITCONDITION_H
        -
        -#ifndef QT_H
        -#include "ntqglobal.h"
        -#endif // QT_H
        -
        -#if defined(TQT_THREAD_SUPPORT)
        -
        -#include <limits.h>
        -
        -class TQWaitConditionPrivate;
        -class TQMutex;
        -
        -class TQ_EXPORT TQWaitCondition
        -{
        -public:
        -    TQWaitCondition();
        -    virtual ~TQWaitCondition();
        -
        -    // default argument causes thread to block indefinately
        -    bool wait( unsigned long time = ULONG_MAX );
        -    bool wait( TQMutex *mutex, unsigned long time = ULONG_MAX );
        -
        -    void wakeOne();
        -    void wakeAll();
        -
        -private:
        -    TQWaitConditionPrivate * d;
        -
        -#if defined(TQ_DISABLE_COPY)
        -    TQWaitCondition( const TQWaitCondition & );
        -    TQWaitCondition &operator=( const TQWaitCondition & );
        -#endif
        -};
        -
        -#endif
        -
        -#endif
        -
        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/qwaitcondition-members.html b/doc/html/qwaitcondition-members.html deleted file mode 100644 index a63aa8378..000000000 --- a/doc/html/qwaitcondition-members.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - -TQWaitCondition Member List - - - - - - - -
        - -Home - | -All Classes - | -Main Classes - | -Annotated - | -Grouped Classes - | -Functions -

        Complete Member List for TQWaitCondition

        - -

        This is the complete list of member functions for -TQWaitCondition, including inherited members. - -

        - -


        - -
        Copyright © 2007 -TrolltechTrademarks -
        TQt 3.3.8
        -
        - diff --git a/doc/html/thread.html b/doc/html/thread.html index b9f435f40..b5d992c6c 100644 --- a/doc/html/thread.html +++ b/doc/html/thread.html @@ -35,12 +35,12 @@ body { background: #ffffff; color: black; }

        These classes are relevant to threaded applications.

        -
        TQMutexAccess serialization between threads -
        TQMutexLockerSimplifies locking and unlocking TQMutexes -
        TQSemaphoreRobust integer semaphore -
        TQThreadPlatform-independent threads -
        TQThreadStoragePer-thread data storage -
        TQWaitConditionAllows waiting/waking for conditions between threads +
        TQMutexAccess serialization between threads +
        TQMutexLockerSimplifies locking and unlocking TQMutexes +
        TQSemaphoreRobust integer semaphore +
        TQThreadPlatform-independent threads +
        TQThreadStoragePer-thread data storage +
        TQWaitConditionAllows waiting/waking for conditions between threads


        diff --git a/doc/html/threads.html b/doc/html/threads.html index eb3c50767..b99b2f144 100644 --- a/doc/html/threads.html +++ b/doc/html/threads.html @@ -88,19 +88,19 @@ entry in ntqconfig.h.

        These classes are built into the TQt library when thread support is enabled:

          -
        • TQThread - Provides the means to start a new thread, which begins -execution in your reimplementation of TQThread::run(). This is similar +
        • TQThread - Provides the means to start a new thread, which begins +execution in your reimplementation of TQThread::run(). This is similar to the Java thread class. -

        • TQThreadStorage - Provides per-thread data storage. This class can +

        • TQThreadStorage - Provides per-thread data storage. This class can only be used with threads started with TQThread; it cannot be used with threads started with platform-specific APIs. -

        • TQMutex - Provides a mutual exclusion lock (also know as a mutex). -
        • TQMutexLocker - A convenience class which automatically locks and +

        • TQMutex - Provides a mutual exclusion lock (also know as a mutex). +
        • TQMutexLocker - A convenience class which automatically locks and unlocks a TQMutex. TQMutexLocker is useful in complicated code, or in code which uses exceptions. See the documentation for more details. -
        • TQWaitCondition - Provides a way for threads to go to sleep until +
        • TQWaitCondition - Provides a way for threads to go to sleep until woken up by another thread. -
        • TQSemaphore - Provides a simple integer semaphore. +
        • TQSemaphore - Provides a simple integer semaphore.

        Important Definitions

        @@ -145,7 +145,7 @@ reentrant, since they only reference unique data. Only one thread at a time can call member functions on each instance of Number. However, multiple threads can call member functions on separate instances of Number. -

        Thread-safe functions usually use a mutex (e.g a TQMutex) to serialize +

        Thread-safe functions usually use a mutex (e.g a TQMutex) to serialize access to shared data. Because of this, thread-safe functions are usually slower than reentrant functions, because of the extra overhead of locking and unlocking the mutex. For example, given the class Counter below: @@ -307,7 +307,7 @@ instead, which will cause the event loop to delete the object after all pending events have been delivered to the object.

      • Don't do any blocking operations while holding the TQt library mutex. This will freeze up the event loop. -

      • Make sure you unlock a recursive TQMutex as many times as you lock +

      • Make sure you unlock a recursive TQMutex as many times as you lock it, no more and no less.

      • Don't mix the normal TQt library and the threaded TQt library in your application. This means that if your application uses the threaded TQt diff --git a/doc/html/titleindex b/doc/html/titleindex index 2cedaf9ab..7ac89b230 100644 --- a/doc/html/titleindex +++ b/doc/html/titleindex @@ -579,10 +579,10 @@ QMovie Class | ntqmovie.html QMovie Member List | qmovie-members.html QMultiLineEdit Class | ntqmultilineedit.html QMultiLineEdit Member List | qmultilineedit-members.html -QMutex Class | ntqmutex.html -QMutex Member List | qmutex-members.html -QMutexLocker Class | qmutexlocker.html -QMutexLocker Member List | qmutexlocker-members.html +TQMutex Class | tqmutex.html +TQMutex Member List | tqmutex-members.html +TQMutexLocker Class | tqmutexlocker.html +TQMutexLocker Member List | tqmutexlocker-members.html QNPInstance Class | qnpinstance.html QNPInstance Member List | qnpinstance-members.html QNPStream Class | qnpstream.html @@ -680,8 +680,8 @@ QScrollBar Class | ntqscrollbar.html QScrollBar Member List | qscrollbar-members.html QScrollView Class | ntqscrollview.html QScrollView Member List | qscrollview-members.html -QSemaphore Class | ntqsemaphore.html -QSemaphore Member List | qsemaphore-members.html +TQSemaphore Class | tqsemaphore.html +TQSemaphore Member List | tqsemaphore-members.html QServerSocket Class | ntqserversocket.html QServerSocket Member List | qserversocket-members.html QSessionManager Class | ntqsessionmanager.html @@ -822,10 +822,10 @@ TQTextStream Class | tqtextstream.html TQTextStream Member List | tqtextstream-members.html TQTextView Class | tqtextview.html TQTextView Member List | tqtextview-members.html -QThread Class | ntqthread.html -QThread Member List | qthread-members.html -QThreadStorage Class | ntqthreadstorage.html -QThreadStorage Member List | qthreadstorage-members.html +TQThread Class | tqthread.html +TQThread Member List | tqthread-members.html +TQThreadStorage Class | tqthreadstorage.html +TQThreadStorage Member List | tqthreadstorage-members.html TQTime Class | tqtime.html TQTime Member List | tqtime-members.html TQTimeEdit Class | tqtimeedit.html @@ -884,8 +884,8 @@ QVariant Class | ntqvariant.html QVariant Member List | qvariant-members.html QWMatrix Class | ntqwmatrix.html QWMatrix Member List | qwmatrix-members.html -QWaitCondition Class | ntqwaitcondition.html -QWaitCondition Member List | qwaitcondition-members.html +TQWaitCondition Class | tqwaitcondition.html +TQWaitCondition Member List | tqwaitcondition-members.html QWhatsThis Class | ntqwhatsthis.html QWhatsThis Member List | qwhatsthis-members.html QWheelEvent Class | qwheelevent.html @@ -1182,7 +1182,7 @@ ntqmotifstyle.h Include File | qmotifstyle-h.html qmotifwidget.h Include File | qmotifwidget-h.html ntqmovie.h Include File | qmovie-h.html ntqmultilineedit.h Include File | qmultilineedit-h.html -ntqmutex.h Include File | qmutex-h.html +tqmutex.h Include File | tqmutex-h.html ntqnamespace.h Include File | qnamespace-h.html ntqnetwork.h Example File | qnetwork-h.html ntqnetworkprotocol.h Include File | qnetworkprotocol-h.html @@ -1223,7 +1223,7 @@ ntqregion.h Include File | qregion-h.html ntqrtlcodec.h Include File | qrtlcodec-h.html ntqscrollbar.h Include File | qscrollbar-h.html ntqscrollview.h Include File | qscrollview-h.html -ntqsemaphore.h Include File | qsemaphore-h.html +tqsemaphore.h Include File | tqsemaphore-h.html ntqserversocket.h Include File | qserversocket-h.html ntqsessionmanager.h Include File | qsessionmanager-h.html ntqsettings.h Include File | qsettings-h.html @@ -1277,8 +1277,8 @@ tqtextcodecplugin.h Include File | tqtextcodecplugin-h.html tqtextedit.h Include File | tqtextedit-h.html tqtextstream.h Include File | tqtextstream-h.html tqtextview.h Include File | tqtextview-h.html -ntqthread.h Include File | qthread-h.html -ntqthreadstorage.h Include File | qthreadstorage-h.html +tqthread.h Include File | tqthread-h.html +tqthreadstorage.h Include File | tqthreadstorage-h.html tqtimer.h Include File | tqtimer-h.html ntqtoolbar.h Include File | qtoolbar-h.html ntqtoolbox.h Include File | qtoolbox-h.html @@ -1298,7 +1298,7 @@ ntqvariant.h Include File | qvariant-h.html ntqvbox.h Include File | qvbox-h.html ntqvbuttongroup.h Include File | qvbuttongroup-h.html ntqvgroupbox.h Include File | qvgroupbox-h.html -ntqwaitcondition.h Include File | qwaitcondition-h.html +tqwaitcondition.h Include File | tqwaitcondition-h.html ntqwhatsthis.h Include File | qwhatsthis-h.html tqwidget.h Include File | tqwidget-h.html tqwidgetfactory.h Include File | tqwidgetfactory-h.html diff --git a/doc/html/tqmap.html b/doc/html/tqmap.html index 48bf63e73..a0bb3b31e 100644 --- a/doc/html/tqmap.html +++ b/doc/html/tqmap.html @@ -244,7 +244,7 @@ the map in time O(1). If multiple TQMap instances share the same data and one is modifying the map's data, this modifying instance makes a copy and modifies its private copy: so it does not affect other instances. If a TQMap is being used in a multi-threaded -program, you must protect all access to the map. See TQMutex. +program, you must protect all access to the map. See TQMutex.

        There are a couple of ways of inserting new items into the map. One uses the insert() method; the other uses operator[]:

        diff --git a/doc/html/tqmutex-h.html b/doc/html/tqmutex-h.html
        new file mode 100644
        index 000000000..1dfe1578f
        --- /dev/null
        +++ b/doc/html/tqmutex-h.html
        @@ -0,0 +1,159 @@
        +
        +
        +
        +
        +
        +tqmutex.h Include File
        +
        +
        +
        +
        +
        +
        +
        +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        tqmutex.h

        + +

        This is the verbatim text of the tqmutex.h include file. It is provided only for illustration; the copyright remains with Trolltech. +


        +
        +/****************************************************************************
        +** $Id: qt/tqmutex.h   3.3.8   edited Jan 11 14:38 $
        +**
        +** Definition of TQMutex class
        +**
        +** Created : 931107
        +**
        +** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        +**
        +** This file is part of the tools module of the TQt GUI Toolkit.
        +**
        +** This file may be used under the terms of the GNU General Public
        +** License versions 2.0 or 3.0 as published by the Free Software
        +** Foundation and appearing in the file LICENSE.GPL included in the
        +** packaging of this file. Alternatively you may (at your option) use any
        +** later version of the GNU General Public License if such license has
        +** been publicly approved by Trolltech ASA (or its successors, if any)
        +** and the KDE Free TQt Foundation.
        +**
        +** Please review the following information to ensure GNU General
        +** Public Licensing requirements will be met:
        +** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        +** If you are unsure which license is appropriate for your use, please
        +** review the following information:
        +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        +** or contact the sales department at sales@trolltech.com.
        +**
        +** This file may be used under the terms of the Q Public License as
        +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        +** included in the packaging of this file.  Licensees holding valid TQt
        +** Commercial licenses may use this file in accordance with the TQt
        +** Commercial License Agreement provided with the Software.
        +**
        +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        +** herein.
        +**
        +**********************************************************************/
        +
        +#ifndef TQMUTEX_H
        +#define TQMUTEX_H
        +
        +#ifndef QT_H
        +#include "ntqglobal.h"
        +#endif // QT_H
        +
        +#if defined(TQT_THREAD_SUPPORT)
        +
        +class TQMutexPrivate;
        +
        +const int Q_MUTEX_NORMAL = 0;
        +const int Q_MUTEX_RECURSIVE = 1;
        +
        +class TQ_EXPORT TQMutex
        +{
        +    friend class TQThread;
        +    friend class TQWaitCondition;
        +    friend class TQWaitConditionPrivate;
        +
        +public:
        +    TQMutex(bool recursive = FALSE);
        +    virtual ~TQMutex();
        +
        +    void lock();
        +    void unlock();
        +    bool locked();
        +    bool tryLock();
        +
        +private:
        +    TQMutexPrivate * d;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    TQMutex( const TQMutex & );
        +    TQMutex &operator=( const TQMutex & );
        +#endif
        +};
        +
        +class TQ_EXPORT TQMutexLocker
        +{
        +public:
        +    TQMutexLocker( TQMutex * );
        +    ~TQMutexLocker();
        +
        +    TQMutex *mutex() const;
        +
        +private:
        +    TQMutex *mtx;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    TQMutexLocker( const TQMutexLocker & );
        +    TQMutexLocker &operator=( const TQMutexLocker & );
        +#endif
        +};
        +
        +inline TQMutexLocker::TQMutexLocker( TQMutex *m )
        +    : mtx( m )
        +{
        +    if ( mtx ) mtx->lock();
        +}
        +
        +inline TQMutexLocker::~TQMutexLocker()
        +{
        +    if ( mtx ) mtx->unlock();
        +}
        +
        +inline TQMutex *TQMutexLocker::mutex() const
        +{
        +    return mtx;
        +}
        +
        +#endif
        +
        +#endif
        +
        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqmutex-members.html b/doc/html/tqmutex-members.html new file mode 100644 index 000000000..a3857a2fa --- /dev/null +++ b/doc/html/tqmutex-members.html @@ -0,0 +1,52 @@ + + + + + +TQMutex Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQMutex

        + +

        This is the complete list of member functions for +TQMutex, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqmutex.html b/doc/html/tqmutex.html new file mode 100644 index 000000000..fa6b727ec --- /dev/null +++ b/doc/html/tqmutex.html @@ -0,0 +1,195 @@ + + + + + +TQMutex Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQMutex Class Reference

        + +

        The TQMutex class provides access serialization between threads. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqmutex.h> +

        List of all member functions. +

        Public Members

        + +

        Detailed Description

        + + + +The TQMutex class provides access serialization between threads. +

        + +

        The purpose of a TQMutex is to protect an object, data structure or +section of code so that only one thread can access it at a time +(This is similar to the Java synchronized keyword). For +example, say there is a method which prints a message to the user +on two lines: +

        +    int number = 6;
        +
        +    void method1()
        +    {
        +        number *= 5;
        +        number /= 4;
        +    }
        +
        +    void method2()
        +    {
        +        number *= 3;
        +        number /= 2;
        +    }
        +    
        + +

        If these two methods are called in succession, the following happens: +

        +    // method1()
        +    number *= 5;        // number is now 30
        +    number /= 4;        // number is now 7
        +
        +    // method2()
        +    number *= 3;        // nubmer is now 21
        +    number /= 2;        // number is now 10
        +    
        + +

        If these two methods are called simultaneously from two threads then the +following sequence could result: +

        +    // Thread 1 calls method1()
        +    number *= 5;        // number is now 30
        +
        +    // Thread 2 calls method2().
        +    //
        +    // Most likely Thread 1 has been put to sleep by the operating
        +    // system to allow Thread 2 to run.
        +    number *= 3;        // number is now 90
        +    number /= 2;        // number is now 45
        +
        +    // Thread 1 finishes executing.
        +    number /= 4;        // number is now 11, instead of 10
        +    
        + +

        If we add a mutex, we should get the result we want: +

        +    TQMutex mutex;
        +    int number = 6;
        +
        +    void method1()
        +    {
        +        mutex.lock();
        +        number *= 5;
        +        number /= 4;
        +        mutex.unlock();
        +    }
        +
        +    void method2()
        +    {
        +        mutex.lock();
        +        number *= 3;
        +        number /= 2;
        +        mutex.unlock();
        +    }
        +    
        + +

        Then only one thread can modify number at any given time and +the result is correct. This is a trivial example, of course, but +applies to any other case where things need to happen in a +particular sequence. +

        When you call lock() in a thread, other threads that try to call +lock() in the same place will block until the thread that got the +lock calls unlock(). A non-blocking alternative to lock() is +tryLock(). +

        See also Environment Classes and Threading. + +


        Member Function Documentation

        +

        TQMutex::TQMutex ( bool recursive = FALSE ) +

        +Constructs a new mutex. The mutex is created in an unlocked state. +A recursive mutex is created if recursive is TRUE; a normal +mutex is created if recursive is FALSE (the default). With a +recursive mutex, a thread can lock the same mutex multiple times +and it will not be unlocked until a corresponding number of +unlock() calls have been made. + +

        TQMutex::~TQMutex () [virtual] +

        +Destroys the mutex. +

        Warning: If you destroy a mutex that still holds a lock the +resultant behavior is undefined. + +

        void TQMutex::lock () +

        +Attempt to lock the mutex. If another thread has locked the mutex +then this call will block until that thread has unlocked it. +

        See also unlock() and locked(). + +

        bool TQMutex::locked () +

        +Returns TRUE if the mutex is locked by another thread; otherwise +returns FALSE. +

        Warning: Due to differing implementations of recursive mutexes on +various platforms, calling this function from the same thread that +previously locked the mutex will return undefined results. +

        See also lock() and unlock(). + +

        bool TQMutex::tryLock () +

        +Attempt to lock the mutex. If the lock was obtained, this function +returns TRUE. If another thread has locked the mutex, this +function returns FALSE, instead of waiting for the mutex to become +available, i.e. it does not block. +

        If the lock was obtained, the mutex must be unlocked with unlock() +before another thread can successfully lock it. +

        See also lock(), unlock(), and locked(). + +

        void TQMutex::unlock () +

        +Unlocks the mutex. Attempting to unlock a mutex in a different +thread to the one that locked it results in an error. Unlocking a +mutex that is not locked results in undefined behaviour (varies +between different Operating Systems' thread implementations). +

        See also lock() and locked(). + + +


        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqmutexlocker-members.html b/doc/html/tqmutexlocker-members.html new file mode 100644 index 000000000..c68b9c736 --- /dev/null +++ b/doc/html/tqmutexlocker-members.html @@ -0,0 +1,49 @@ + + + + + +TQMutexLocker Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQMutexLocker

        + +

        This is the complete list of member functions for +TQMutexLocker, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqmutexlocker.html b/doc/html/tqmutexlocker.html new file mode 100644 index 000000000..2ec99fc2a --- /dev/null +++ b/doc/html/tqmutexlocker.html @@ -0,0 +1,220 @@ + + + + + +TQMutexLocker Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQMutexLocker Class Reference

        + +

        The TQMutexLocker class simplifies locking and unlocking TQMutexes. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqmutex.h> +

        List of all member functions. +

        Public Members

        + +

        Detailed Description

        + + +The TQMutexLocker class simplifies locking and unlocking TQMutexes. +

        +

        + +

        The purpose of TQMutexLocker is to simplify TQMutex locking and +unlocking. Locking and unlocking a TQMutex in complex functions and +statements or in exception handling code is error prone and +difficult to debug. TQMutexLocker should be used in such situations +to ensure that the state of the mutex is well defined and always +locked and unlocked properly. +

        TQMutexLocker should be created within a function where a TQMutex +needs to be locked. The mutex is locked when TQMutexLocker is +created, and unlocked when TQMutexLocker is destroyed. +

        For example, this complex function locks a TQMutex upon entering +the function and unlocks the mutex at all the exit points: +

        +    int complexFunction( int flag )
        +    {
        +        mutex.lock();
        +
        +        int return_value = 0;
        +
        +        switch ( flag ) {
        +        case 0:
        +        case 1:
        +            {
        +                mutex.unlock();
        +                return moreComplexFunction( flag );
        +            }
        +
        +        case 2:
        +            {
        +                int status = anotherFunction();
        +                if ( status < 0 ) {
        +                    mutex.unlock();
        +                    return -2;
        +                }
        +                return_value = status + flag;
        +                break;
        +            }
        +
        +        default:
        +            {
        +                if ( flag > 10 ) {
        +                    mutex.unlock();
        +                    return -1;
        +                }
        +                break;
        +            }
        +        }
        +
        +        mutex.unlock();
        +        return return_value;
        +    }
        +    
        + +

        This example function will get more complicated as it is +developed, which increases the likelihood that errors will occur. +

        Using TQMutexLocker greatly simplifies the code, and makes it more +readable: +

        +    int complexFunction( int flag )
        +    {
        +        TQMutexLocker locker( &mutex );
        +
        +        int return_value = 0;
        +
        +        switch ( flag ) {
        +        case 0:
        +        case 1:
        +            {
        +                return moreComplexFunction( flag );
        +            }
        +
        +        case 2:
        +            {
        +                int status = anotherFunction();
        +                if ( status < 0 )
        +                    return -2;
        +                return_value = status + flag;
        +                break;
        +            }
        +
        +        default:
        +            {
        +                if ( flag > 10 )
        +                    return -1;
        +                break;
        +            }
        +        }
        +
        +        return return_value;
        +    }
        +    
        + +

        Now, the mutex will always be unlocked when the TQMutexLocker +object is destroyed (when the function returns since locker is +an auto variable). Note that the mutex will be unlocked after +the call to moreComplexFunction() in this example, avoiding +possible bugs caused by unlocking the mutex too early, as in +the first example. +

        The same principle applies to code that throws and catches +exceptions. An exception that is not caught in the function that +has locked the mutex has no way of unlocking the mutex before the +exception is passed up the stack to the calling function. +

        TQMutexLocker also provides a mutex() member function that returns +the mutex on which the TQMutexLocker is operating. This is useful +for code that needs access to the mutex, such as +TQWaitCondition::wait(). For example: +

        +    class SignalWaiter
        +    {
        +    private:
        +        TQMutexLocker locker;
        +
        +    public:
        +        SignalWaiter( TQMutex *mutex )
        +            : locker( mutex )
        +        {
        +        }
        +
        +        void waitForSignal()
        +        {
        +            ...
        +            ...
        +            ...
        +
        +            while ( ! signalled )
        +                waitcondition.wait( locker.mutex() );
        +
        +            ...
        +            ...
        +            ...
        +        }
        +    };
        +    
        + +

        See also TQMutex, TQWaitCondition, Environment Classes, and Threading. + +


        Member Function Documentation

        +

        TQMutexLocker::TQMutexLocker ( TQMutex * mutex ) +

        + +

        Constructs a TQMutexLocker and locks mutex. The mutex will be +unlocked when the TQMutexLocker is destroyed. If mutex is zero, +TQMutexLocker does nothing. +

        See also TQMutex::lock(). + +

        TQMutexLocker::~TQMutexLocker () +

        + +

        Destroys the TQMutexLocker and unlocks the mutex which was locked +in the constructor. +

        See also TQMutexLocker::TQMutexLocker() and TQMutex::unlock(). + +

        TQMutex * TQMutexLocker::mutex () const +

        + +

        Returns a pointer to the mutex which was locked in the +constructor. +

        See also TQMutexLocker::TQMutexLocker(). + + +


        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqsemaphore-h.html b/doc/html/tqsemaphore-h.html new file mode 100644 index 000000000..85e153ba8 --- /dev/null +++ b/doc/html/tqsemaphore-h.html @@ -0,0 +1,126 @@ + + + + + +tqsemaphore.h Include File + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        tqsemaphore.h

        + +

        This is the verbatim text of the tqsemaphore.h include file. It is provided only for illustration; the copyright remains with Trolltech. +


        +
        +/****************************************************************************
        +** $Id: qt/tqsemaphore.h   3.3.8   edited Jan 11 14:38 $
        +**
        +** Definition of TQSemaphore class
        +**
        +** Created : 931107
        +**
        +** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        +**
        +** This file is part of the tools module of the TQt GUI Toolkit.
        +**
        +** This file may be used under the terms of the GNU General Public
        +** License versions 2.0 or 3.0 as published by the Free Software
        +** Foundation and appearing in the file LICENSE.GPL included in the
        +** packaging of this file. Alternatively you may (at your option) use any
        +** later version of the GNU General Public License if such license has
        +** been publicly approved by Trolltech ASA (or its successors, if any)
        +** and the KDE Free TQt Foundation.
        +**
        +** Please review the following information to ensure GNU General
        +** Public Licensing requirements will be met:
        +** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        +** If you are unsure which license is appropriate for your use, please
        +** review the following information:
        +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        +** or contact the sales department at sales@trolltech.com.
        +**
        +** This file may be used under the terms of the Q Public License as
        +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        +** included in the packaging of this file.  Licensees holding valid TQt
        +** Commercial licenses may use this file in accordance with the TQt
        +** Commercial License Agreement provided with the Software.
        +**
        +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        +** herein.
        +**
        +**********************************************************************/
        +
        +#ifndef TQSEMAPHORE_H
        +#define TQSEMAPHORE_H
        +
        +#ifndef QT_H
        +#include "ntqglobal.h"
        +#endif // QT_H
        +
        +#if defined(TQT_THREAD_SUPPORT)
        +
        +class TQSemaphorePrivate;
        +
        +class TQ_EXPORT TQSemaphore
        +{
        +public:
        +    TQSemaphore( int );
        +    virtual ~TQSemaphore();
        +
        +    int available() const;
        +    int total() const;
        +
        +    // postfix operators
        +    int operator++(int);
        +    int operator--(int);
        +
        +    int operator+=(int);
        +    int operator-=(int);
        +
        +    bool tryAccess(int);
        +
        +private:
        +    TQSemaphorePrivate *d;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    TQSemaphore(const TQSemaphore &);
        +    TQSemaphore &operator=(const TQSemaphore &);
        +#endif
        +};
        +
        +#endif
        +
        +#endif
        +
        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqsemaphore-members.html b/doc/html/tqsemaphore-members.html new file mode 100644 index 000000000..7926751ed --- /dev/null +++ b/doc/html/tqsemaphore-members.html @@ -0,0 +1,55 @@ + + + + + +TQSemaphore Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQSemaphore

        + +

        This is the complete list of member functions for +TQSemaphore, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqsemaphore.html b/doc/html/tqsemaphore.html new file mode 100644 index 000000000..e50963edf --- /dev/null +++ b/doc/html/tqsemaphore.html @@ -0,0 +1,149 @@ + + + + + +TQSemaphore Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQSemaphore Class Reference

        + +

        The TQSemaphore class provides a robust integer semaphore. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqsemaphore.h> +

        List of all member functions. +

        Public Members

        + +

        Detailed Description

        + + + +The TQSemaphore class provides a robust integer semaphore. +

        + +

        A TQSemaphore can be used to serialize thread execution, in a +similar way to a TQMutex. A semaphore differs from a mutex, in +that a semaphore can be accessed by more than one thread at a +time. +

        For example, suppose we have an application that stores data in a +large tree structure. The application creates 10 threads +(commonly called a thread pool) to perform searches on the tree. +When the application searches the tree for some piece of data, it +uses one thread per base node to do the searching. A semaphore +could be used to make sure that two threads don't try to search +the same branch of the tree at the same time. +

        A non-computing example of a semaphore would be dining at a +restuarant. A semaphore is initialized to have a maximum count +equal to the number of chairs in the restuarant. As people +arrive, they want a seat. As seats are filled, the semaphore is +accessed, once per person. As people leave, the access is +released, allowing more people to enter. If a party of 10 people +want to be seated, but there are only 9 seats, those 10 people +will wait, but a party of 4 people would be seated (taking the +available seats to 5, making the party of 10 people wait longer). +

        When a semaphore is created it is given a number which is the +maximum number of concurrent accesses it will permit. Accesses to +the sempahore are gained using operator++() or operator+=(), and +released with operator--() or operator-=(). The number of +accesses allowed is retrieved with available(), and the total +number with total(). Note that the incrementing functions will +block if there aren't enough available accesses. Use tryAccess() +if you want to acquire accesses without blocking. +

        See also Environment Classes and Threading. + +


        Member Function Documentation

        +

        TQSemaphore::TQSemaphore ( int maxcount ) +

        +Creates a new semaphore. The semaphore can be concurrently +accessed at most maxcount times. + +

        TQSemaphore::~TQSemaphore () [virtual] +

        +Destroys the semaphore. +

        Warning: If you destroy a semaphore that has accesses in use the +resultant behavior is undefined. + +

        int TQSemaphore::available () const +

        +Returns the number of accesses currently available to the +semaphore. + +

        int TQSemaphore::operator++ ( int ) +

        +Postfix ++ operator. +

        Try to get access to the semaphore. If available() == 0, this +call will block until it can get access, i.e. until available() > +0. + +

        int TQSemaphore::operator+= ( int n ) +

        +Try to get access to the semaphore. If available() < n, this +call will block until it can get all the accesses it wants, i.e. +until available() >= n. + +

        int TQSemaphore::operator-- ( int ) +

        +Postfix -- operator. +

        Release access of the semaphore. This wakes all threads waiting +for access to the semaphore. + +

        int TQSemaphore::operator-= ( int n ) +

        +Release n accesses to the semaphore. + +

        int TQSemaphore::total () const +

        +Returns the total number of accesses to the semaphore. + +

        bool TQSemaphore::tryAccess ( int n ) +

        +Try to get access to the semaphore. If available() < n, this +function will return FALSE immediately. If available() >= n, +this function will take n accesses and return TRUE. This +function does not block. + + +

        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthread-h.html b/doc/html/tqthread-h.html new file mode 100644 index 000000000..a8028ef62 --- /dev/null +++ b/doc/html/tqthread-h.html @@ -0,0 +1,166 @@ + + + + + +tqthread.h Include File + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        tqthread.h

        + +

        This is the verbatim text of the tqthread.h include file. It is provided only for illustration; the copyright remains with Trolltech. +


        +
        +/****************************************************************************
        +** $Id: qt/tqthread.h   3.3.8   edited Jan 11 14:38 $
        +**
        +** Definition of TQThread class
        +**
        +** Created : 931107
        +**
        +** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        +**
        +** This file is part of the kernel module of the TQt GUI Toolkit.
        +**
        +** This file may be used under the terms of the GNU General Public
        +** License versions 2.0 or 3.0 as published by the Free Software
        +** Foundation and appearing in the file LICENSE.GPL included in the
        +** packaging of this file. Alternatively you may (at your option) use any
        +** later version of the GNU General Public License if such license has
        +** been publicly approved by Trolltech ASA (or its successors, if any)
        +** and the KDE Free TQt Foundation.
        +**
        +** Please review the following information to ensure GNU General
        +** Public Licensing requirements will be met:
        +** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        +** If you are unsure which license is appropriate for your use, please
        +** review the following information:
        +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        +** or contact the sales department at sales@trolltech.com.
        +**
        +** This file may be used under the terms of the Q Public License as
        +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        +** included in the packaging of this file.  Licensees holding valid TQt
        +** Commercial licenses may use this file in accordance with the TQt
        +** Commercial License Agreement provided with the Software.
        +**
        +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        +** herein.
        +**
        +**********************************************************************/
        +
        +#ifndef TQTHREAD_H
        +#define TQTHREAD_H
        +
        +#if defined(TQT_THREAD_SUPPORT)
        +
        +#ifndef QT_H
        +#include "ntqwindowdefs.h"
        +#endif // QT_H
        +
        +#include <limits.h>
        +
        +class TQThreadInstance;
        +
        +class TQ_EXPORT TQThread : public TQt
        +{
        +public:
        +    static TQt::HANDLE currentThread();
        +
        +    static void initialize();
        +    static void cleanup();
        +
        +    static void exit();
        +
        +#ifdef Q_QDOC
        +    TQThread( unsigned int stackSize = 0 );
        +#else
        +    TQThread( unsigned int stackSize );
        +    TQThread();
        +#endif
        +
        +    virtual ~TQThread();
        +
        +    // default argument causes thread to block indefinately
        +    bool wait( unsigned long time = ULONG_MAX );
        +
        +    enum Priority {
        +	IdlePriority,
        +
        +	LowestPriority,
        +	LowPriority,
        +	NormalPriority,
        +	HighPriority,
        +	HighestPriority,
        +
        +	TimeCriticalPriority,
        +
        +	InheritPriority
        +    };
        +
        +#ifdef Q_QDOC
        +    void start( Priority = InheritPriority );
        +#else
        +    void start( Priority );
        +    void start();
        +#endif
        +
        +    void terminate();
        +
        +    bool finished() const;
        +    bool running() const;
        +
        +protected:
        +    virtual void run() = 0;
        +
        +    static void sleep( unsigned long );
        +    static void msleep( unsigned long );
        +    static void usleep( unsigned long );
        +
        +private:
        +    TQThreadInstance * d;
        +    friend class TQThreadInstance;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    TQThread( const TQThread & );
        +    TQThread &operator=( const TQThread & );
        +#endif // TQ_DISABLE_COPY
        +};
        +
        +#endif // TQT_THREAD_SUPPORT
        +
        +#endif // TQTHREAD_H
        +
        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthread-members.html b/doc/html/tqthread-members.html new file mode 100644 index 000000000..7d5bddd54 --- /dev/null +++ b/doc/html/tqthread-members.html @@ -0,0 +1,59 @@ + + + + + +TQThread Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQThread

        + +

        This is the complete list of member functions for +TQThread, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthread.html b/doc/html/tqthread.html new file mode 100644 index 000000000..8df9c449f --- /dev/null +++ b/doc/html/tqthread.html @@ -0,0 +1,247 @@ + + + + + +TQThread Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQThread Class Reference

        + +

        The TQThread class provides platform-independent threads. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqthread.h> +

        Inherits TQt. +

        List of all member functions. +

        Public Members

        +
          +
        • TQThread ( unsigned int stackSize = 0 )
        • +
        • virtual ~TQThread ()
        • +
        • bool wait ( unsigned long time = ULONG_MAX )
        • +
        • enum Priority { IdlePriority, LowestPriority, LowPriority, NormalPriority, HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority }
        • +
        • void start ( Priority priority = InheritPriority )
        • +
        • void terminate ()
        • +
        • bool finished () const
        • +
        • bool running () const
        • +
        +

        Static Public Members

        + +

        Protected Members

        +
          +
        • virtual void run () = 0
        • +
        +

        Static Protected Members

        +
          +
        • void sleep ( unsigned long secs )
        • +
        • void msleep ( unsigned long msecs )
        • +
        • void usleep ( unsigned long usecs )
        • +
        +

        Detailed Description

        + + + +The TQThread class provides platform-independent threads. +

        + +

        A TQThread represents a separate thread of control within the +program; it shares data with all the other threads within the +process but executes independently in the way that a separate +program does on a multitasking operating system. Instead of +starting in main(), TQThreads begin executing in run(). You inherit +run() to include your code. For example: +

        +    class MyThread : public TQThread {
        +
        +    public:
        +
        +        virtual void run();
        +
        +    };
        +
        +    void MyThread::run()
        +    {
        +        for( int count = 0; count < 20; count++ ) {
        +            sleep( 1 );
        +            tqDebug( "Ping!" );
        +        }
        +    }
        +
        +    int main()
        +    {
        +        MyThread a;
        +        MyThread b;
        +        a.start();
        +        b.start();
        +        a.wait();
        +        b.wait();
        +    }
        +    
        + +

        This will start two threads, each of which writes Ping! 20 times +to the screen and exits. The wait() calls at the end of main() are +necessary because exiting main() ends the program, unceremoniously +killing all other threads. Each MyThread stops executing when it +reaches the end of MyThread::run(), just as an application does +when it leaves main(). +

        See also Thread Support in TQt, Environment Classes, and Threading. + +


        Member Type Documentation

        +

        TQThread::Priority

        + +

        This enum type indicates how the operating system should schedule +newly created threads. +

          +
        • TQThread::IdlePriority - scheduled only when no other threads are +running. +
        • TQThread::LowestPriority - scheduled less often than LowPriority. +
        • TQThread::LowPriority - scheduled less often than NormalPriority. +
        • TQThread::NormalPriority - the default priority of the operating +system. +
        • TQThread::HighPriority - scheduled more often than NormalPriority. +
        • TQThread::HighestPriority - scheduled more often then HighPriority. +
        • TQThread::TimeCriticalPriority - scheduled as often as possible. +
        • TQThread::InheritPriority - use the same priority as the creating +thread. This is the default. +
        +

        Member Function Documentation

        +

        TQThread::TQThread ( unsigned int stackSize = 0 ) +

        +Constructs a new thread. The thread does not begin executing until +start() is called. +

        If stackSize is greater than zero, the maximum stack size is +set to stackSize bytes, otherwise the maximum stack size is +automatically determined by the operating system. +

        Warning: Most operating systems place minimum and maximum limits +on thread stack sizes. The thread will fail to start if the stack +size is outside these limits. + +

        TQThread::~TQThread () [virtual] +

        +TQThread destructor. +

        Note that deleting a TQThread object will not stop the execution of +the thread it represents. Deleting a running TQThread (i.e. +finished() returns FALSE) will probably result in a program crash. +You can wait() on a thread to make sure that it has finished. + +

        TQt::HANDLE TQThread::currentThread () [static] +

        +This returns the thread handle of the currently executing thread. +

        Warning: The handle returned by this function is used for internal +purposes and should not be used in any application code. On +Windows, the returned value is a pseudo handle for the current +thread, and it cannot be used for numerical comparison. + +

        void TQThread::exit () [static] +

        +Ends the execution of the calling thread and wakes up any threads +waiting for its termination. + +

        bool TQThread::finished () const +

        +Returns TRUE if the thread is finished; otherwise returns FALSE. + +

        void TQThread::msleep ( unsigned long msecs ) [static protected] +

        +System independent sleep. This causes the current thread to sleep +for msecs milliseconds + +

        void TQThread::run () [pure virtual protected] +

        + +

        This method is pure virtual, and must be implemented in derived +classes in order to do useful work. Returning from this method +will end the execution of the thread. +

        See also wait(). + +

        bool TQThread::running () const +

        +Returns TRUE if the thread is running; otherwise returns FALSE. + +

        void TQThread::sleep ( unsigned long secs ) [static protected] +

        +System independent sleep. This causes the current thread to sleep +for secs seconds. + +

        void TQThread::start ( Priority priority = InheritPriority ) +

        +Begins execution of the thread by calling run(), which should be +reimplemented in a TQThread subclass to contain your code. The +operating system will schedule the thread according to the priority argument. +

        If you try to start a thread that is already running, this +function will wait until the the thread has finished and then +restart the thread. +

        See also Priority. + +

        void TQThread::terminate () +

        +This function terminates the execution of the thread. The thread +may or may not be terminated immediately, depending on the +operating system's scheduling policies. Use TQThread::wait() +after terminate() for synchronous termination. +

        When the thread is terminated, all threads waiting for the +the thread to finish will be woken up. +

        Warning: This function is dangerous, and its use is discouraged. +The thread can be terminated at any point in its code path. Threads +can be terminated while modifying data. There is no chance for +the thread to cleanup after itself, unlock any held mutexes, etc. +In short, use this function only if absolutely necessary. + +

        void TQThread::usleep ( unsigned long usecs ) [static protected] +

        +System independent sleep. This causes the current thread to sleep +for usecs microseconds + +

        bool TQThread::wait ( unsigned long time = ULONG_MAX ) +

        +A thread calling this function will block until either of these +conditions is met: +

          +
        • The thread associated with this TQThread object has finished +execution (i.e. when it returns from run()). This function +will return TRUE if the thread has finished. It also returns +TRUE if the thread has not been started yet. +
        • time milliseconds has elapsed. If time is ULONG_MAX (the +default), then the wait will never timeout (the thread must +return from run()). This function will return FALSE if the +wait timed out. +
        +

        This provides similar functionality to the POSIX pthread_join() function. + + +


        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthreadstorage-h.html b/doc/html/tqthreadstorage-h.html new file mode 100644 index 000000000..748578a84 --- /dev/null +++ b/doc/html/tqthreadstorage-h.html @@ -0,0 +1,140 @@ + + + + + +tqthreadstorage.h Include File + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        tqthreadstorage.h

        + +

        This is the verbatim text of the tqthreadstorage.h include file. It is provided only for illustration; the copyright remains with Trolltech. +


        +
        +/****************************************************************************
        +** $Id: qt/tqthreadstorage.h   3.3.8   edited Jan 11 14:46 $
        +**
        +** ...
        +**
        +** Copyright (C) 2005-2007 Trolltech ASA.  All rights reserved.
        +**
        +** This file is part of the tools module of the TQt GUI Toolkit.
        +**
        +** This file may be used under the terms of the GNU General Public
        +** License versions 2.0 or 3.0 as published by the Free Software
        +** Foundation and appearing in the file LICENSE.GPL included in the
        +** packaging of this file. Alternatively you may (at your option) use any
        +** later version of the GNU General Public License if such license has
        +** been publicly approved by Trolltech ASA (or its successors, if any)
        +** and the KDE Free TQt Foundation.
        +**
        +** Please review the following information to ensure GNU General
        +** Public Licensing requirements will be met:
        +** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        +** If you are unsure which license is appropriate for your use, please
        +** review the following information:
        +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        +** or contact the sales department at sales@trolltech.com.
        +**
        +** This file may be used under the terms of the Q Public License as
        +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        +** included in the packaging of this file.  Licensees holding valid TQt
        +** Commercial licenses may use this file in accordance with the TQt
        +** Commercial License Agreement provided with the Software.
        +**
        +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        +** herein.
        +**
        +**********************************************************************/
        +
        +#ifndef TQTHREADSTORAGE_H
        +#define TQTHREADSTORAGE_H
        +
        +#ifdef TQT_THREAD_SUPPORT
        +
        +#ifndef QT_H
        +#include "ntqglobal.h"
        +#endif // QT_H
        +
        +class TQ_EXPORT TQThreadStorageData
        +{
        +public:
        +    TQThreadStorageData( void (*func)(void *) );
        +    ~TQThreadStorageData();
        +
        +    void** get() const;
        +    void** set( void* p );
        +
        +    static void finish( void** );
        +    int id;
        +};
        +
        +
        +template <class T>
        +class TQThreadStorage
        +{
        +private:
        +    TQThreadStorageData d;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    // disable copy constructor and operator=
        +    TQThreadStorage( const TQThreadStorage & );
        +    TQThreadStorage &operator=( const TQThreadStorage & );
        +#endif // TQ_DISABLE_COPY
        +
        +    static void deleteData( void *x ) { delete (T)x; }
        +
        +public:
        +    inline TQThreadStorage() : d( deleteData ) {  }
        +    inline ~TQThreadStorage() { }
        +
        +    inline bool hasLocalData() const
        +    { return d.get() != 0; }
        +
        +    inline T& localData()
        +    { void **v = d.get(); if ( !v ) v = d.set( 0 ); return *(T*)v; }
        +
        +    inline T localData() const
        +    { void **v = d.get(); return ( v ? *(T*)v : 0 ); }
        +
        +    inline void setLocalData( T t )
        +    { (void) d.set( t ); }
        +};
        +
        +#endif // TQT_THREAD_SUPPORT
        +
        +#endif // TQTHREADSTORAGE_H
        +
        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthreadstorage-members.html b/doc/html/tqthreadstorage-members.html new file mode 100644 index 000000000..4fdb72507 --- /dev/null +++ b/doc/html/tqthreadstorage-members.html @@ -0,0 +1,51 @@ + + + + + +TQThreadStorage Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQThreadStorage

        + +

        This is the complete list of member functions for +TQThreadStorage, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqthreadstorage.html b/doc/html/tqthreadstorage.html new file mode 100644 index 000000000..be0fb3482 --- /dev/null +++ b/doc/html/tqthreadstorage.html @@ -0,0 +1,189 @@ + + + + + +TQThreadStorage Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQThreadStorage Class Reference

        + +

        The TQThreadStorage class provides per-thread data storage. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqthreadstorage.h> +

        List of all member functions. +

        Public Members

        + +

        Detailed Description

        + + +The TQThreadStorage class provides per-thread data storage. +

        + + +

        TQThreadStorage is a template class that provides per-thread data +storage. +

        Note that due to compiler limitations, TQThreadStorage can only store pointers. +

        The setLocalData() function stores a single thread-specific value +for the calling thread. The data can be accessed later using the +localData() functions. TQThreadStorage takes ownership of the +data (which must be created on the heap with new) and deletes +it when the thread exits (either normally or via termination). +

        The hasLocalData() function allows the programmer to determine if +data has previously been set using the setLocalData() function. +This is useful for lazy initializiation. +

        For example, the following code uses TQThreadStorage to store a +single cache for each thread that calls the cacheObject() and +removeFromCache() functions. The cache is automatically +deleted when the calling thread exits (either normally or via +termination). +

        +    TQThreadStorage<TQCache<SomeClass> *> caches;
        +
        +    void cacheObject( const TQString &key, SomeClass *object )
        +    {
        +        if ( ! caches.hasLocalData() )
        +            caches.setLocalData( new TQCache<SomeClass> );
        +
        +        caches.localData()->insert( key, object );
        +    }
        +
        +    void removeFromCache( const TQString &key )
        +    {
        +        if ( ! caches.hasLocalData() )
        +            return; // nothing to do
        +
        +        caches.localData()->remove( key );
        +    }
        +    
        + +

        Caveats +

        +

          +

        • As noted above, TQThreadStorage can only store pointers due to +compiler limitations. Support for value-based objects will be +added when the majority of compilers are able to support partial +template specialization. +

        • The destructor does not +delete per-thread data. TQThreadStorage only deletes per-thread +data when the thread exits or when setLocalData() is called +multiple times. +

        • TQThreadStorage can only be used with threads started with +TQThread. It cannot be used with threads started with +platform-specific APIs. +

        • As a corollary to the above, platform-specific APIs cannot be +used to exit or terminate a TQThread using TQThreadStorage. Doing so +will cause all per-thread data to be leaked. See TQThread::exit() +and TQThread::terminate(). +

        • TQThreadStorage can be used to store data for the main() +thread after TQApplication has been constructed. TQThreadStorage +deletes all data set for the main() thread when TQApplication is +destroyed, regardless of whether or not the main() thread has +actually finished. +

        • The implementation of TQThreadStorage limits the total number of +TQThreadStorage objects to 256. An unlimited number of threads +can store per-thread data in each TQThreadStorage object. +

        +

        See also Environment Classes and Threading. + +


        Member Function Documentation

        +

        TQThreadStorage::TQThreadStorage () +

        + +

        Constructs a new per-thread data storage object. + +

        TQThreadStorage::~TQThreadStorage () +

        + +

        Destroys the per-thread data storage object. +

        Note: The per-thread data stored is not deleted. Any data left +in TQThreadStorage is leaked. Make sure that all threads using +TQThreadStorage have exited before deleting the TQThreadStorage. +

        See also hasLocalData(). + +

        bool TQThreadStorage::hasLocalData () const +

        + +

        Returns TRUE if the calling thread has non-zero data available; +otherwise returns FALSE. +

        See also localData(). + +

        T & TQThreadStorage::localData () +

        + +

        Returns a reference to the data that was set by the calling +thread. +

        Note: TQThreadStorage can only store pointers. This function +returns a reference to the pointer that was set by the calling +thread. The value of this reference is 0 if no data was set by +the calling thread, +

        See also hasLocalData(). + +

        T TQThreadStorage::localData () const +

        + +This is an overloaded member function, provided for convenience. It behaves essentially like the above function. +

        Returns a copy of the data that was set by the calling thread. +

        Note: TQThreadStorage can only store pointers. This function +returns a pointer to the data that was set by the calling thread. +If no data was set by the calling thread, this function returns 0. +

        See also hasLocalData(). + +

        void TQThreadStorage::setLocalData ( T data ) +

        + +

        Sets the local data for the calling thread to data. It can be +accessed later using the localData() functions. +

        If data is 0, this function deletes the previous data (if +any) and returns immediately. +

        If data is non-zero, TQThreadStorage takes ownership of the data and deletes it automatically either when the thread exits +(either normally or via termination) or when setLocalData() is +called again. +

        Note: TQThreadStorage can only store pointers. The data +argument must be either a pointer to an object created on the heap +(i.e. using new) or 0. You should not delete data +yourself; TQThreadStorage takes ownership and will delete the data itself. +

        See also localData() and hasLocalData(). + + +


        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqvaluelist.html b/doc/html/tqvaluelist.html index 72bd00e8a..d9b189a47 100644 --- a/doc/html/tqvaluelist.html +++ b/doc/html/tqvaluelist.html @@ -259,7 +259,7 @@ instance makes a copy and modifies its private copy; therefore it does not affect the other instances; this takes O(n) time. This is often called "copy on write". If a TQValueList is being used in a multi-threaded program, you must protect all access to the list. -See TQMutex. +See TQMutex.

        There are several ways to insert items into the list. The prepend() and append() functions insert items at the beginning and the end of the list respectively. The insert() function comes in diff --git a/doc/html/tqvaluevector.html b/doc/html/tqvaluevector.html index 527ca3a29..6f90c2adc 100644 --- a/doc/html/tqvaluevector.html +++ b/doc/html/tqvaluevector.html @@ -296,7 +296,7 @@ data and one needs to modify its contents, this modifying instance makes a copy and modifies its private copy; it thus does not affect the other instances. This is often called "copy on write". If a TQValueVector is being used in a multi-threaded program, you -must protect all access to the vector. See TQMutex. +must protect all access to the vector. See TQMutex.

        There are several ways to insert elements into the vector. The push_back() function insert elements into the end of the vector, and is usually fastest. The insert() function can be used to add diff --git a/doc/html/tqwaitcondition-h.html b/doc/html/tqwaitcondition-h.html new file mode 100644 index 000000000..0cc7d9cfb --- /dev/null +++ b/doc/html/tqwaitcondition-h.html @@ -0,0 +1,124 @@ + + + + + +tqwaitcondition.h Include File + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        tqwaitcondition.h

        + +

        This is the verbatim text of the tqwaitcondition.h include file. It is provided only for illustration; the copyright remains with Trolltech. +


        +
        +/****************************************************************************
        +** $Id: qt/tqwaitcondition.h   3.3.8   edited Jan 11 14:38 $
        +**
        +** Definition of TQWaitCondition class
        +**
        +** Created : 931107
        +**
        +** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
        +**
        +** This file is part of the tools module of the TQt GUI Toolkit.
        +**
        +** This file may be used under the terms of the GNU General Public
        +** License versions 2.0 or 3.0 as published by the Free Software
        +** Foundation and appearing in the file LICENSE.GPL included in the
        +** packaging of this file. Alternatively you may (at your option) use any
        +** later version of the GNU General Public License if such license has
        +** been publicly approved by Trolltech ASA (or its successors, if any)
        +** and the KDE Free TQt Foundation.
        +**
        +** Please review the following information to ensure GNU General
        +** Public Licensing requirements will be met:
        +** http://trolltech.com/products/qt/licenses/licensing/opensource/.
        +** If you are unsure which license is appropriate for your use, please
        +** review the following information:
        +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
        +** or contact the sales department at sales@trolltech.com.
        +**
        +** This file may be used under the terms of the Q Public License as
        +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
        +** included in the packaging of this file.  Licensees holding valid TQt
        +** Commercial licenses may use this file in accordance with the TQt
        +** Commercial License Agreement provided with the Software.
        +**
        +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
        +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
        +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
        +** herein.
        +**
        +**********************************************************************/
        +
        +#ifndef TQWAITCONDITION_H
        +#define TQWAITCONDITION_H
        +
        +#ifndef QT_H
        +#include "ntqglobal.h"
        +#endif // QT_H
        +
        +#if defined(TQT_THREAD_SUPPORT)
        +
        +#include <limits.h>
        +
        +class TQWaitConditionPrivate;
        +class TQMutex;
        +
        +class TQ_EXPORT TQWaitCondition
        +{
        +public:
        +    TQWaitCondition();
        +    virtual ~TQWaitCondition();
        +
        +    // default argument causes thread to block indefinately
        +    bool wait( unsigned long time = ULONG_MAX );
        +    bool wait( TQMutex *mutex, unsigned long time = ULONG_MAX );
        +
        +    void wakeOne();
        +    void wakeAll();
        +
        +private:
        +    TQWaitConditionPrivate * d;
        +
        +#if defined(TQ_DISABLE_COPY)
        +    TQWaitCondition( const TQWaitCondition & );
        +    TQWaitCondition &operator=( const TQWaitCondition & );
        +#endif
        +};
        +
        +#endif
        +
        +#endif
        +
        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqwaitcondition-members.html b/doc/html/tqwaitcondition-members.html new file mode 100644 index 000000000..a3d550c62 --- /dev/null +++ b/doc/html/tqwaitcondition-members.html @@ -0,0 +1,51 @@ + + + + + +TQWaitCondition Member List + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        Complete Member List for TQWaitCondition

        + +

        This is the complete list of member functions for +TQWaitCondition, including inherited members. + +

        + +


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/tqwaitcondition.html b/doc/html/tqwaitcondition.html new file mode 100644 index 000000000..50a7b6464 --- /dev/null +++ b/doc/html/tqwaitcondition.html @@ -0,0 +1,197 @@ + + + + + +TQWaitCondition Class + + + + + + + +
        + +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

        TQWaitCondition Class Reference

        + +

        The TQWaitCondition class allows waiting/waking for conditions between threads. +More... +

        All the functions in this class are thread-safe when TQt is built with thread support.

        +

        #include <tqwaitcondition.h> +

        List of all member functions. +

        Public Members

        + +

        Detailed Description

        + + + +The TQWaitCondition class allows waiting/waking for conditions between threads. +

        + +

        TQWaitConditions allow a thread to tell other threads that some +sort of condition has been met; one or many threads can block +waiting for a TQWaitCondition to set a condition with wakeOne() or +wakeAll(). Use wakeOne() to wake one randomly selected event or +wakeAll() to wake them all. For example, say we have three tasks +that should be performed every time the user presses a key; each +task could be split into a thread, each of which would have a +run() body like this: +

        +    TQWaitCondition key_pressed;
        +
        +    for (;;) {
        +        key_pressed.wait(); // This is a TQWaitCondition global variable
        +        // Key was pressed, do something interesting
        +        do_something();
        +    }
        +    
        + +

        A fourth thread would read key presses and wake the other three +threads up every time it receives one, like this: +

        +    TQWaitCondition key_pressed;
        +
        +    for (;;) {
        +        getchar();
        +        // Causes any thread in key_pressed.wait() to return from
        +        // that method and continue processing
        +        key_pressed.wakeAll();
        +    }
        +    
        + +

        Note that the order the three threads are woken up in is +undefined, and that if some or all of the threads are still in +do_something() when the key is pressed, they won't be woken up +(since they're not waiting on the condition variable) and so the +task will not be performed for that key press. This can be +avoided by, for example, doing something like this: +

        +    TQMutex mymutex;
        +    TQWaitCondition key_pressed;
        +    int mycount=0;
        +
        +    // Worker thread code
        +    for (;;) {
        +        key_pressed.wait(); // This is a TQWaitCondition global variable
        +        mymutex.lock();
        +        mycount++;
        +        mymutex.unlock();
        +        do_something();
        +        mymutex.lock();
        +        mycount--;
        +        mymutex.unlock();
        +    }
        +
        +    // Key reading thread code
        +    for (;;) {
        +        getchar();
        +        mymutex.lock();
        +        // Sleep until there are no busy worker threads
        +        while( mycount > 0 ) {
        +            mymutex.unlock();
        +            sleep( 1 );
        +            mymutex.lock();
        +        }
        +        mymutex.unlock();
        +        key_pressed.wakeAll();
        +    }
        +    
        + +

        The mutexes are necessary because the results of two threads +attempting to change the value of the same variable simultaneously +are unpredictable. +

        See also Environment Classes and Threading. + +


        Member Function Documentation

        +

        TQWaitCondition::TQWaitCondition () +

        +Constructs a new event signalling, i.e. wait condition, object. + +

        TQWaitCondition::~TQWaitCondition () [virtual] +

        +Deletes the event signalling, i.e. wait condition, object. + +

        bool TQWaitCondition::wait ( unsigned long time = ULONG_MAX ) +

        +Wait on the thread event object. The thread calling this will +block until either of these conditions is met: +
          +
        • Another thread signals it using wakeOne() or wakeAll(). This +function will return TRUE in this case. +
        • time milliseconds has elapsed. If time is ULONG_MAX (the +default), then the wait will never timeout (the event must be +signalled). This function will return FALSE if the wait timed +out. +
        +

        See also wakeOne() and wakeAll(). + +

        bool TQWaitCondition::wait ( TQMutex * mutex, unsigned long time = ULONG_MAX ) +

        +This is an overloaded member function, provided for convenience. It behaves essentially like the above function. +

        Release the locked mutex and wait on the thread event object. +The mutex must be initially locked by the calling thread. If mutex is not in a locked state, this function returns immediately. +If mutex is a recursive mutex, this function returns +immediately. The mutex will be unlocked, and the calling thread +will block until either of these conditions is met: +

          +
        • Another thread signals it using wakeOne() or wakeAll(). This +function will return TRUE in this case. +
        • time milliseconds has elapsed. If time is ULONG_MAX (the +default), then the wait will never timeout (the event must be +signalled). This function will return FALSE if the wait timed +out. +
        +

        The mutex will be returned to the same locked state. This function +is provided to allow the atomic transition from the locked state +to the wait state. +

        See also wakeOne() and wakeAll(). + +

        void TQWaitCondition::wakeAll () +

        +This wakes all threads waiting on the TQWaitCondition. The order in +which the threads are woken up depends on the operating system's +scheduling policies, and cannot be controlled or predicted. +

        See also wakeOne(). + +

        void TQWaitCondition::wakeOne () +

        +This wakes one thread waiting on the TQWaitCondition. The thread +that is woken up depends on the operating system's scheduling +policies, and cannot be controlled or predicted. +

        See also wakeAll(). + + +


        +This file is part of the TQt toolkit. +Copyright © 1995-2007 +Trolltech. All Rights Reserved.


        + +
        Copyright © 2007 +TrolltechTrademarks +
        TQt 3.3.8
        +
        + diff --git a/doc/html/whatsthis b/doc/html/whatsthis index 0dccd7737..25fe82bc3 100644 --- a/doc/html/whatsthis +++ b/doc/html/whatsthis @@ -18,7 +18,7 @@ Abstraction of Unicode text and the classic C '\0'-terminated char array. | Abstraction of objects which provide formatted data of a certain MIME type. | QMimeSource Abstraction of the classic C zero-terminated char array (char *). | QCString Abstraction used by TQImageDecoder. | TQImageConsumer -Access serialization between threads. | QMutex +Access serialization between threads. | TQMutex Access to a selected area in a QTable. | QTableSelection Access to directory structures and their contents in a platform-independent way. | QDir Access to screen information on multi-head systems. | QDesktopWidget @@ -26,7 +26,7 @@ Access to the platform audio facilities. | QSound Access to the session manager. | QSessionManager Access to the window system clipboard. | QClipboard Acts like a union for the most common TQt data types. | QVariant -Allows waiting/waking for conditions between threads. | QWaitCondition +Allows waiting/waking for conditions between threads. | TQWaitCondition Animated canvas item on a TQCanvas. | TQCanvasSprite Application-global cache for pixmaps. | QPixmapCache Area with movable labelled icons. | TQIconView @@ -255,11 +255,11 @@ Parameters that describe a mouse event. | QMouseEvent Parameters that describe a timer event. | TQTimerEvent Parameters that describe a wheel event. | QWheelEvent Pattern matching using regular expressions. | QRegExp -Per-thread data storage. | QThreadStorage +Per-thread data storage. | TQThreadStorage Persistent platform-independent application settings. | QSettings Pixmaps for TQCanvasSprites. | TQCanvasPixmap Platform-independent low-level socket API. | QSocketDevice -Platform-independent threads. | QThread +Platform-independent threads. | TQThread Polygon on a TQCanvas. | TQCanvasPolygon Polygonal canvas item on a TQCanvas. | TQCanvasPolygonalItem Popup menu widget. | QPopupMenu @@ -286,7 +286,7 @@ Represents text data in the parsed XML document. | TQDomText Request header information for HTTP. | QHttpRequestHeader Response header information for HTTP. | QHttpResponseHeader Rich text browser with hypertext navigation. | TQTextBrowser -Robust integer semaphore. | QSemaphore +Robust integer semaphore. | TQSemaphore Rounded range control (like a speedometer or potentiometer). | QDial SGI/Irix look and feel. | QSGIStyle SQL database error information. | TQSqlError @@ -298,7 +298,7 @@ Simple convenience dialog to get a single value from the user. | QInputDialog Simple description of any widget, i.e. answering the question "What's this?". | QWhatsThis Simple geometry management of its children. | QGrid Simple stored-value drag object for arbitrary MIME data. | QStoredDrag -Simplifies locking and unlocking QMutexes. | QMutexLocker +Simplifies locking and unlocking TQMutexes. | TQMutexLocker Single item in a TQIconView. | TQIconViewItem Small displayable piece of rich text. | QSimpleRichText Spin box widget (spin button). | QSpinBox diff --git a/doc/man/man3/tqdeepcopy.3qt b/doc/man/man3/tqdeepcopy.3qt index bbfce204b..afbd32ba9 100644 --- a/doc/man/man3/tqdeepcopy.3qt +++ b/doc/man/man3/tqdeepcopy.3qt @@ -91,7 +91,7 @@ QDeepCopy can also provide safety in multithreaded applications that use shared .br QDeepCopy global_string; // global string data .br - QMutex global_mutex; // mutex to protext global_string + TQMutex global_mutex; // mutex to protext global_string .br .br ... diff --git a/doc/man/man3/tqmap.3qt b/doc/man/man3/tqmap.3qt index 6630c43a5..169d558d6 100644 --- a/doc/man/man3/tqmap.3qt +++ b/doc/man/man3/tqmap.3qt @@ -324,7 +324,7 @@ It is safe to have multiple iterators at the same time. If some member of the ma .PP Since TQMap is value-based, there is no need to be concerned about deleting items in the map. The map holds its own copies and will free them if the corresponding member or the map itself is deleted. .PP -TQMap is implicitly shared. This means you can just make copies of the map in time O(1). If multiple TQMap instances share the same data and one is modifying the map's data, this modifying instance makes a copy and modifies its private copy: so it does not affect other instances. If a TQMap is being used in a multi-threaded program, you must protect all access to the map. See QMutex. +TQMap is implicitly shared. This means you can just make copies of the map in time O(1). If multiple TQMap instances share the same data and one is modifying the map's data, this modifying instance makes a copy and modifies its private copy: so it does not affect other instances. If a TQMap is being used in a multi-threaded program, you must protect all access to the map. See TQMutex. .PP There are a couple of ways of inserting new items into the map. One uses the insert() method; the other uses operator[]: .PP diff --git a/doc/man/man3/tqmutex.3qt b/doc/man/man3/tqmutex.3qt index 7a81c98df..f685a31f4 100644 --- a/doc/man/man3/tqmutex.3qt +++ b/doc/man/man3/tqmutex.3qt @@ -1,5 +1,5 @@ '\" t -.TH QMutex 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQMutex 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,19 +7,19 @@ .ad l .nh .SH NAME -QMutex \- Access serialization between threads +TQMutex \- Access serialization between threads .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQMutex\fR ( bool recursive = FALSE )" +.BI "\fBTQMutex\fR ( bool recursive = FALSE )" .br .ti -1c -.BI "virtual \fB~QMutex\fR ()" +.BI "virtual \fB~TQMutex\fR ()" .br .ti -1c .BI "void \fBlock\fR ()" @@ -35,9 +35,9 @@ All the functions in this class are thread-safe when TQt is built with thread su .br .in -1c .SH DESCRIPTION -The QMutex class provides access serialization between threads. +The TQMutex class provides access serialization between threads. .PP -The purpose of a QMutex is to protect an object, data structure or section of code so that only one thread can access it at a time (This is similar to the Java \fCsynchronized\fR keyword). For example, say there is a method which prints a message to the user on two lines: +The purpose of a TQMutex is to protect an object, data structure or section of code so that only one thread can access it at a time (This is similar to the Java \fCsynchronized\fR keyword). For example, say there is a method which prints a message to the user on two lines: .PP .nf .br @@ -118,7 +118,7 @@ If we add a mutex, we should get the result we want: .PP .nf .br - QMutex mutex; + TQMutex mutex; .br int number = 6; .br @@ -160,35 +160,35 @@ When you call lock() in a thread, other threads that try to call lock() in the s .PP See also Environment Classes and Threading. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QMutex::QMutex ( bool recursive = FALSE )" +.SH "TQMutex::TQMutex ( bool recursive = FALSE )" Constructs a new mutex. The mutex is created in an unlocked state. A recursive mutex is created if \fIrecursive\fR is TRUE; a normal mutex is created if \fIrecursive\fR is FALSE (the default). With a recursive mutex, a thread can lock the same mutex multiple times and it will not be unlocked until a corresponding number of unlock() calls have been made. -.SH "QMutex::~QMutex ()\fC [virtual]\fR" +.SH "TQMutex::~TQMutex ()\fC [virtual]\fR" Destroys the mutex. .PP \fBWarning:\fR If you destroy a mutex that still holds a lock the resultant behavior is undefined. -.SH "void QMutex::lock ()" +.SH "void TQMutex::lock ()" Attempt to lock the mutex. If another thread has locked the mutex then this call will \fIblock\fR until that thread has unlocked it. .PP See also unlock() and locked(). -.SH "bool QMutex::locked ()" +.SH "bool TQMutex::locked ()" Returns TRUE if the mutex is locked by another thread; otherwise returns FALSE. .PP \fBWarning:\fR Due to differing implementations of recursive mutexes on various platforms, calling this function from the same thread that previously locked the mutex will return undefined results. .PP See also lock() and unlock(). -.SH "bool QMutex::tryLock ()" +.SH "bool TQMutex::tryLock ()" Attempt to lock the mutex. If the lock was obtained, this function returns TRUE. If another thread has locked the mutex, this function returns FALSE, instead of waiting for the mutex to become available, i.e. it does not block. .PP If the lock was obtained, the mutex must be unlocked with unlock() before another thread can successfully lock it. .PP See also lock(), unlock(), and locked(). -.SH "void QMutex::unlock ()" +.SH "void TQMutex::unlock ()" Unlocks the mutex. Attempting to unlock a mutex in a different thread to the one that locked it results in an error. Unlocking a mutex that is not locked results in undefined behaviour (varies between different Operating Systems' thread implementations). .PP See also lock() and locked(). .SH "SEE ALSO" -.BR http://doc.trolltech.com/ntqmutex.html +.BR http://doc.trolltech.com/tqmutex.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/man/man3/tqmutexlocker.3qt b/doc/man/man3/tqmutexlocker.3qt index 52006502e..b713c7e1a 100644 --- a/doc/man/man3/tqmutexlocker.3qt +++ b/doc/man/man3/tqmutexlocker.3qt @@ -1,5 +1,5 @@ '\" t -.TH QMutexLocker 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQMutexLocker 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,32 +7,32 @@ .ad l .nh .SH NAME -QMutexLocker \- Simplifies locking and unlocking QMutexes +TQMutexLocker \- Simplifies locking and unlocking TQMutexes .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQMutexLocker\fR ( QMutex * mutex )" +.BI "\fBTQMutexLocker\fR ( TQMutex * mutex )" .br .ti -1c -.BI "\fB~QMutexLocker\fR ()" +.BI "\fB~TQMutexLocker\fR ()" .br .ti -1c -.BI "QMutex * \fBmutex\fR () const" +.BI "TQMutex * \fBmutex\fR () const" .br .in -1c .SH DESCRIPTION -The QMutexLocker class simplifies locking and unlocking QMutexes. +The TQMutexLocker class simplifies locking and unlocking TQMutexes. .PP -The purpose of QMutexLocker is to simplify QMutex locking and unlocking. Locking and unlocking a QMutex in complex functions and statements or in exception handling code is error prone and difficult to debug. QMutexLocker should be used in such situations to ensure that the state of the mutex is well defined and always locked and unlocked properly. +The purpose of TQMutexLocker is to simplify TQMutex locking and unlocking. Locking and unlocking a TQMutex in complex functions and statements or in exception handling code is error prone and difficult to debug. TQMutexLocker should be used in such situations to ensure that the state of the mutex is well defined and always locked and unlocked properly. .PP -QMutexLocker should be created within a function where a QMutex needs to be locked. The mutex is locked when QMutexLocker is created, and unlocked when QMutexLocker is destroyed. +TQMutexLocker should be created within a function where a TQMutex needs to be locked. The mutex is locked when TQMutexLocker is created, and unlocked when TQMutexLocker is destroyed. .PP -For example, this complex function locks a QMutex upon entering the function and unlocks the mutex at all the exit points: +For example, this complex function locks a TQMutex upon entering the function and unlocks the mutex at all the exit points: .PP .nf .br @@ -111,7 +111,7 @@ For example, this complex function locks a QMutex upon entering the function and .PP This example function will get more complicated as it is developed, which increases the likelihood that errors will occur. .PP -Using QMutexLocker greatly simplifies the code, and makes it more readable: +Using TQMutexLocker greatly simplifies the code, and makes it more readable: .PP .nf .br @@ -119,7 +119,7 @@ Using QMutexLocker greatly simplifies the code, and makes it more readable: .br { .br - QMutexLocker locker( &mutex ); + TQMutexLocker locker( &mutex ); .br .br int return_value = 0; @@ -176,11 +176,11 @@ Using QMutexLocker greatly simplifies the code, and makes it more readable: .br .fi .PP -Now, the mutex will always be unlocked when the QMutexLocker object is destroyed (when the function returns since \fClocker\fR is an auto variable). Note that the mutex will be unlocked after the call to moreComplexFunction() in this example, avoiding possible bugs caused by unlocking the mutex too early, as in the first example. +Now, the mutex will always be unlocked when the TQMutexLocker object is destroyed (when the function returns since \fClocker\fR is an auto variable). Note that the mutex will be unlocked after the call to moreComplexFunction() in this example, avoiding possible bugs caused by unlocking the mutex too early, as in the first example. .PP The same principle applies to code that throws and catches exceptions. An exception that is not caught in the function that has locked the mutex has no way of unlocking the mutex before the exception is passed up the stack to the calling function. .PP -QMutexLocker also provides a mutex() member function that returns the mutex on which the QMutexLocker is operating. This is useful for code that needs access to the mutex, such as QWaitCondition::wait(). For example: +TQMutexLocker also provides a mutex() member function that returns the mutex on which the TQMutexLocker is operating. This is useful for code that needs access to the mutex, such as TQWaitCondition::wait(). For example: .PP .nf .br @@ -190,12 +190,12 @@ QMutexLocker also provides a mutex() member function that returns the mutex on w .br private: .br - QMutexLocker locker; + TQMutexLocker locker; .br .br public: .br - SignalWaiter( QMutex *mutex ) + SignalWaiter( TQMutex *mutex ) .br : locker( mutex ) .br @@ -232,23 +232,23 @@ QMutexLocker also provides a mutex() member function that returns the mutex on w .br .fi .PP -See also QMutex, QWaitCondition, Environment Classes, and Threading. +See also TQMutex, TQWaitCondition, Environment Classes, and Threading. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QMutexLocker::QMutexLocker ( QMutex * mutex )" -Constructs a QMutexLocker and locks \fImutex\fR. The mutex will be unlocked when the QMutexLocker is destroyed. If \fImutex\fR is zero, QMutexLocker does nothing. +.SH "TQMutexLocker::TQMutexLocker ( TQMutex * mutex )" +Constructs a TQMutexLocker and locks \fImutex\fR. The mutex will be unlocked when the TQMutexLocker is destroyed. If \fImutex\fR is zero, TQMutexLocker does nothing. .PP -See also QMutex::lock(). -.SH "QMutexLocker::~QMutexLocker ()" -Destroys the QMutexLocker and unlocks the mutex which was locked in the constructor. +See also TQMutex::lock(). +.SH "TQMutexLocker::~TQMutexLocker ()" +Destroys the TQMutexLocker and unlocks the mutex which was locked in the constructor. .PP -See also QMutexLocker::QMutexLocker() and QMutex::unlock(). -.SH "QMutex * QMutexLocker::mutex () const" +See also TQMutexLocker::TQMutexLocker() and TQMutex::unlock(). +.SH "TQMutex * TQMutexLocker::mutex () const" Returns a pointer to the mutex which was locked in the constructor. .PP -See also QMutexLocker::QMutexLocker(). +See also TQMutexLocker::TQMutexLocker(). .SH "SEE ALSO" -.BR http://doc.trolltech.com/qmutexlocker.html +.BR http://doc.trolltech.com/tqmutexlocker.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/man/man3/tqregexp.3qt b/doc/man/man3/tqregexp.3qt index f62f432e5..859ce0c21 100644 --- a/doc/man/man3/tqregexp.3qt +++ b/doc/man/man3/tqregexp.3qt @@ -124,7 +124,7 @@ We present a very brief introduction to regexps, a description of Qt's regexp la .PP Experienced regexp users may prefer to skip the introduction and go directly to the relevant information. .PP -In case of multi-threaded programming, note that QRegExp depends on QThreadStorage internally. For that reason, QRegExp should only be used with threads started with QThread, i.e. not with threads started with platform-specific APIs. +In case of multi-threaded programming, note that QRegExp depends on TQThreadStorage internally. For that reason, QRegExp should only be used with threads started with TQThread, i.e. not with threads started with platform-specific APIs. .PP .TP diff --git a/doc/man/man3/tqsemaphore.3qt b/doc/man/man3/tqsemaphore.3qt index 8888f065b..59e9261aa 100644 --- a/doc/man/man3/tqsemaphore.3qt +++ b/doc/man/man3/tqsemaphore.3qt @@ -1,5 +1,5 @@ '\" t -.TH QSemaphore 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQSemaphore 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,19 +7,19 @@ .ad l .nh .SH NAME -QSemaphore \- Robust integer semaphore +TQSemaphore \- Robust integer semaphore .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQSemaphore\fR ( int maxcount )" +.BI "\fBTQSemaphore\fR ( int maxcount )" .br .ti -1c -.BI "virtual \fB~QSemaphore\fR ()" +.BI "virtual \fB~TQSemaphore\fR ()" .br .ti -1c .BI "int \fBavailable\fR () const" @@ -44,9 +44,9 @@ All the functions in this class are thread-safe when TQt is built with thread su .br .in -1c .SH DESCRIPTION -The QSemaphore class provides a robust integer semaphore. +The TQSemaphore class provides a robust integer semaphore. .PP -A QSemaphore can be used to serialize thread execution, in a similar way to a QMutex. A semaphore differs from a mutex, in that a semaphore can be accessed by more than one thread at a time. +A TQSemaphore can be used to serialize thread execution, in a similar way to a TQMutex. A semaphore differs from a mutex, in that a semaphore can be accessed by more than one thread at a time. .PP For example, suppose we have an application that stores data in a large tree structure. The application creates 10 threads (commonly called a thread pool) to perform searches on the tree. When the application searches the tree for some piece of data, it uses one thread per base node to do the searching. A semaphore could be used to make sure that two threads don't try to search the same branch of the tree at the same time. .PP @@ -56,36 +56,36 @@ When a semaphore is created it is given a number which is the maximum number of .PP See also Environment Classes and Threading. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QSemaphore::QSemaphore ( int maxcount )" +.SH "TQSemaphore::TQSemaphore ( int maxcount )" Creates a new semaphore. The semaphore can be concurrently accessed at most \fImaxcount\fR times. -.SH "QSemaphore::~QSemaphore ()\fC [virtual]\fR" +.SH "TQSemaphore::~TQSemaphore ()\fC [virtual]\fR" Destroys the semaphore. .PP \fBWarning:\fR If you destroy a semaphore that has accesses in use the resultant behavior is undefined. -.SH "int QSemaphore::available () const" +.SH "int TQSemaphore::available () const" Returns the number of accesses currently available to the semaphore. -.SH "int QSemaphore::operator++ ( int )" +.SH "int TQSemaphore::operator++ ( int )" Postfix ++ operator. .PP Try to get access to the semaphore. If available() == 0, this call will block until it can get access, i.e. until available() > 0. -.SH "int QSemaphore::operator+= ( int n )" +.SH "int TQSemaphore::operator+= ( int n )" Try to get access to the semaphore. If available() < \fIn\fR, this call will block until it can get all the accesses it wants, i.e. until available() >= \fIn\fR. -.SH "int QSemaphore::operator-- ( int )" +.SH "int TQSemaphore::operator-- ( int )" Postfix -- operator. .PP Release access of the semaphore. This wakes all threads waiting for access to the semaphore. -.SH "int QSemaphore::operator-= ( int n )" +.SH "int TQSemaphore::operator-= ( int n )" Release \fIn\fR accesses to the semaphore. -.SH "int QSemaphore::total () const" +.SH "int TQSemaphore::total () const" Returns the total number of accesses to the semaphore. -.SH "bool QSemaphore::tryAccess ( int n )" +.SH "bool TQSemaphore::tryAccess ( int n )" Try to get access to the semaphore. If available() < \fIn\fR, this function will return FALSE immediately. If available() >= \fIn\fR, this function will take \fIn\fR accesses and return TRUE. This function does \fInot\fR block. .SH "SEE ALSO" -.BR http://doc.trolltech.com/ntqsemaphore.html +.BR http://doc.trolltech.com/tqsemaphore.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/man/man3/tqt.3qt b/doc/man/man3/tqt.3qt index 22a9fa065..d82f7113b 100644 --- a/doc/man/man3/tqt.3qt +++ b/doc/man/man3/tqt.3qt @@ -11,7 +11,7 @@ Qt \- Namespace for miscellaneous identifiers that need to be global-like .SH SYNOPSIS \fC#include \fR .PP -Inherited by TQObject, QPixmap, QBrush, TQCanvasItem, QCursor, QPainter, QEvent, TQIconViewItem, QKeySequence, QListViewItem, QCustomMenuItem, QPen, TQStyleSheetItem, QSyntaxHighlighter, QTab, QTableItem, QThread, QToolTip, and QWhatsThis. +Inherited by TQObject, QPixmap, QBrush, TQCanvasItem, QCursor, QPainter, QEvent, TQIconViewItem, QKeySequence, QListViewItem, QCustomMenuItem, QPen, TQStyleSheetItem, QSyntaxHighlighter, QTab, QTableItem, TQThread, QToolTip, and QWhatsThis. .PP .SS "Public Members" .in +1c diff --git a/doc/man/man3/tqthread.3qt b/doc/man/man3/tqthread.3qt index 07551b891..64cb10828 100644 --- a/doc/man/man3/tqthread.3qt +++ b/doc/man/man3/tqthread.3qt @@ -1,5 +1,5 @@ '\" t -.TH QThread 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQThread 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,21 +7,21 @@ .ad l .nh .SH NAME -QThread \- Platform-independent threads +TQThread \- Platform-independent threads .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP Inherits Qt. .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQThread\fR ( unsigned int stackSize = 0 )" +.BI "\fBTQThread\fR ( unsigned int stackSize = 0 )" .br .ti -1c -.BI "virtual \fB~QThread\fR ()" +.BI "virtual \fB~TQThread\fR ()" .br .ti -1c .BI "bool \fBwait\fR ( unsigned long time = ULONG_MAX )" @@ -70,13 +70,13 @@ Inherits Qt. .br .in -1c .SH DESCRIPTION -The QThread class provides platform-independent threads. +The TQThread class provides platform-independent threads. .PP -A QThread represents a separate thread of control within the program; it shares data with all the other threads within the process but executes independently in the way that a separate program does on a multitasking operating system. Instead of starting in main(), QThreads begin executing in run(). You inherit run() to include your code. For example: +A TQThread represents a separate thread of control within the program; it shares data with all the other threads within the process but executes independently in the way that a separate program does on a multitasking operating system. Instead of starting in main(), TQThreads begin executing in run(). You inherit run() to include your code. For example: .PP .nf .br - class MyThread : public QThread { + class MyThread : public TQThread { .br .br public: @@ -127,78 +127,78 @@ This will start two threads, each of which writes Ping! 20 times to the screen a .PP See also Thread Support in Qt, Environment Classes, and Threading. .SS "Member Type Documentation" -.SH "QThread::Priority" +.SH "TQThread::Priority" This enum type indicates how the operating system should schedule newly created threads. .TP -\fCQThread::IdlePriority\fR - scheduled only when no other threads are running. +\fCTQThread::IdlePriority\fR - scheduled only when no other threads are running. .TP -\fCQThread::LowestPriority\fR - scheduled less often than LowPriority. +\fCTQThread::LowestPriority\fR - scheduled less often than LowPriority. .TP -\fCQThread::LowPriority\fR - scheduled less often than NormalPriority. +\fCTQThread::LowPriority\fR - scheduled less often than NormalPriority. .TP -\fCQThread::NormalPriority\fR - the default priority of the operating system. +\fCTQThread::NormalPriority\fR - the default priority of the operating system. .TP -\fCQThread::HighPriority\fR - scheduled more often than NormalPriority. +\fCTQThread::HighPriority\fR - scheduled more often than NormalPriority. .TP -\fCQThread::HighestPriority\fR - scheduled more often then HighPriority. +\fCTQThread::HighestPriority\fR - scheduled more often then HighPriority. .TP -\fCQThread::TimeCriticalPriority\fR - scheduled as often as possible. +\fCTQThread::TimeCriticalPriority\fR - scheduled as often as possible. .TP -\fCQThread::InheritPriority\fR - use the same priority as the creating thread. This is the default. +\fCTQThread::InheritPriority\fR - use the same priority as the creating thread. This is the default. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QThread::QThread ( unsigned int stackSize = 0 )" +.SH "TQThread::TQThread ( unsigned int stackSize = 0 )" Constructs a new thread. The thread does not begin executing until start() is called. .PP If \fIstackSize\fR is greater than zero, the maximum stack size is set to \fIstackSize\fR bytes, otherwise the maximum stack size is automatically determined by the operating system. .PP \fBWarning:\fR Most operating systems place minimum and maximum limits on thread stack sizes. The thread will fail to start if the stack size is outside these limits. -.SH "QThread::~QThread ()\fC [virtual]\fR" -QThread destructor. +.SH "TQThread::~TQThread ()\fC [virtual]\fR" +TQThread destructor. .PP -Note that deleting a QThread object will not stop the execution of the thread it represents. Deleting a running QThread (i.e. finished() returns FALSE) will probably result in a program crash. You can wait() on a thread to make sure that it has finished. -.SH "TQt::HANDLE QThread::currentThread ()\fC [static]\fR" +Note that deleting a TQThread object will not stop the execution of the thread it represents. Deleting a running TQThread (i.e. finished() returns FALSE) will probably result in a program crash. You can wait() on a thread to make sure that it has finished. +.SH "TQt::HANDLE TQThread::currentThread ()\fC [static]\fR" This returns the thread handle of the currently executing thread. .PP \fBWarning:\fR The handle returned by this function is used for internal purposes and should \fInot\fR be used in any application code. On Windows, the returned value is a pseudo handle for the current thread, and it cannot be used for numerical comparison. -.SH "void QThread::exit ()\fC [static]\fR" +.SH "void TQThread::exit ()\fC [static]\fR" Ends the execution of the calling thread and wakes up any threads waiting for its termination. -.SH "bool QThread::finished () const" +.SH "bool TQThread::finished () const" Returns TRUE if the thread is finished; otherwise returns FALSE. -.SH "void QThread::msleep ( unsigned long msecs )\fC [static protected]\fR" +.SH "void TQThread::msleep ( unsigned long msecs )\fC [static protected]\fR" System independent sleep. This causes the current thread to sleep for \fImsecs\fR milliseconds -.SH "void QThread::run ()\fC [pure virtual protected]\fR" +.SH "void TQThread::run ()\fC [pure virtual protected]\fR" This method is pure virtual, and must be implemented in derived classes in order to do useful work. Returning from this method will end the execution of the thread. .PP See also wait(). -.SH "bool QThread::running () const" +.SH "bool TQThread::running () const" Returns TRUE if the thread is running; otherwise returns FALSE. -.SH "void QThread::sleep ( unsigned long secs )\fC [static protected]\fR" +.SH "void TQThread::sleep ( unsigned long secs )\fC [static protected]\fR" System independent sleep. This causes the current thread to sleep for \fIsecs\fR seconds. -.SH "void QThread::start ( Priority priority = InheritPriority )" -Begins execution of the thread by calling run(), which should be reimplemented in a QThread subclass to contain your code. The operating system will schedule the thread according to the \fIpriority\fR argument. +.SH "void TQThread::start ( Priority priority = InheritPriority )" +Begins execution of the thread by calling run(), which should be reimplemented in a TQThread subclass to contain your code. The operating system will schedule the thread according to the \fIpriority\fR argument. .PP If you try to start a thread that is already running, this function will wait until the the thread has finished and then restart the thread. .PP See also Priority. -.SH "void QThread::terminate ()" -This function terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating system's scheduling policies. Use QThread::wait() after terminate() for synchronous termination. +.SH "void TQThread::terminate ()" +This function terminates the execution of the thread. The thread may or may not be terminated immediately, depending on the operating system's scheduling policies. Use TQThread::wait() after terminate() for synchronous termination. .PP When the thread is terminated, all threads waiting for the the thread to finish will be woken up. .PP \fBWarning:\fR This function is dangerous, and its use is discouraged. The thread can be terminated at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to cleanup after itself, unlock any held mutexes, etc. In short, use this function only if \fIabsolutely\fR necessary. -.SH "void QThread::usleep ( unsigned long usecs )\fC [static protected]\fR" +.SH "void TQThread::usleep ( unsigned long usecs )\fC [static protected]\fR" System independent sleep. This causes the current thread to sleep for \fIusecs\fR microseconds -.SH "bool QThread::wait ( unsigned long time = ULONG_MAX )" +.SH "bool TQThread::wait ( unsigned long time = ULONG_MAX )" A thread calling this function will block until either of these conditions is met: .TP -The thread associated with this QThread object has finished execution (i.e. when it returns from run()). This function will return TRUE if the thread has finished. It also returns TRUE if the thread has not been started yet. +The thread associated with this TQThread object has finished execution (i.e. when it returns from run()). This function will return TRUE if the thread has finished. It also returns TRUE if the thread has not been started yet. .TP \fItime\fR milliseconds has elapsed. If \fItime\fR is ULONG_MAX (the default), then the wait will never timeout (the thread must return from run()). This function will return FALSE if the wait timed out. .PP This provides similar functionality to the POSIX \fCpthread_join()\fR function. .SH "SEE ALSO" -.BR http://doc.trolltech.com/ntqthread.html +.BR http://doc.trolltech.com/tqthread.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/man/man3/tqthreadstorage.3qt b/doc/man/man3/tqthreadstorage.3qt index 3ad1393f5..ed8ef3565 100644 --- a/doc/man/man3/tqthreadstorage.3qt +++ b/doc/man/man3/tqthreadstorage.3qt @@ -1,5 +1,5 @@ '\" t -.TH QThreadStorage 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQThreadStorage 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,19 +7,19 @@ .ad l .nh .SH NAME -QThreadStorage \- Per-thread data storage +TQThreadStorage \- Per-thread data storage .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQThreadStorage\fR ()" +.BI "\fBTQThreadStorage\fR ()" .br .ti -1c -.BI "\fB~QThreadStorage\fR ()" +.BI "\fB~TQThreadStorage\fR ()" .br .ti -1c .BI "bool \fBhasLocalData\fR () const" @@ -35,21 +35,21 @@ All the functions in this class are thread-safe when TQt is built with thread su .br .in -1c .SH DESCRIPTION -The QThreadStorage class provides per-thread data storage. +The TQThreadStorage class provides per-thread data storage. .PP -QThreadStorage is a template class that provides per-thread data storage. +TQThreadStorage is a template class that provides per-thread data storage. .PP -\fINote that due to compiler limitations, QThreadStorage can only store pointers.\fR +\fINote that due to compiler limitations, TQThreadStorage can only store pointers.\fR .PP -The setLocalData() function stores a single thread-specific value for the calling thread. The data can be accessed later using the localData() functions. QThreadStorage takes ownership of the data (which must be created on the heap with \fInew\fR) and deletes it when the thread exits (either normally or via termination). +The setLocalData() function stores a single thread-specific value for the calling thread. The data can be accessed later using the localData() functions. TQThreadStorage takes ownership of the data (which must be created on the heap with \fInew\fR) and deletes it when the thread exits (either normally or via termination). .PP The hasLocalData() function allows the programmer to determine if data has previously been set using the setLocalData() function. This is useful for lazy initializiation. .PP -For example, the following code uses QThreadStorage to store a single cache for each thread that calls the \fIcacheObject()\fR and \fIremoveFromCache()\fR functions. The cache is automatically deleted when the calling thread exits (either normally or via termination). +For example, the following code uses TQThreadStorage to store a single cache for each thread that calls the \fIcacheObject()\fR and \fIremoveFromCache()\fR functions. The cache is automatically deleted when the calling thread exits (either normally or via termination). .PP .nf .br - QThreadStorage *> caches; + TQThreadStorage *> caches; .br .br void cacheObject( const TQString &key, SomeClass *object ) @@ -83,65 +83,65 @@ For example, the following code uses QThreadStorage to store a single cache for .SH "Caveats" .IP .TP -As noted above, QThreadStorage can only store pointers due to compiler limitations. Support for value-based objects will be added when the majority of compilers are able to support partial template specialization. +As noted above, TQThreadStorage can only store pointers due to compiler limitations. Support for value-based objects will be added when the majority of compilers are able to support partial template specialization. .IP .TP -The destructor does \fInot\fR delete per-thread data. QThreadStorage only deletes per-thread data when the thread exits or when setLocalData() is called multiple times. +The destructor does \fInot\fR delete per-thread data. TQThreadStorage only deletes per-thread data when the thread exits or when setLocalData() is called multiple times. .IP .TP -QThreadStorage can only be used with threads started with QThread. It \fIcannot\fR be used with threads started with platform-specific APIs. +TQThreadStorage can only be used with threads started with TQThread. It \fIcannot\fR be used with threads started with platform-specific APIs. .IP .TP -As a corollary to the above, platform-specific APIs cannot be used to exit or terminate a QThread using QThreadStorage. Doing so will cause all per-thread data to be leaked. See QThread::exit() and QThread::terminate(). +As a corollary to the above, platform-specific APIs cannot be used to exit or terminate a TQThread using TQThreadStorage. Doing so will cause all per-thread data to be leaked. See TQThread::exit() and TQThread::terminate(). .IP .TP -QThreadStorage \fIcan\fR be used to store data for the \fImain()\fR thread \fIafter\fR QApplication has been constructed. QThreadStorage deletes all data set for the \fImain()\fR thread when QApplication is destroyed, regardless of whether or not the \fImain()\fR thread has actually finished. +TQThreadStorage \fIcan\fR be used to store data for the \fImain()\fR thread \fIafter\fR QApplication has been constructed. TQThreadStorage deletes all data set for the \fImain()\fR thread when QApplication is destroyed, regardless of whether or not the \fImain()\fR thread has actually finished. .IP .TP -The implementation of QThreadStorage limits the total number of QThreadStorage objects to 256. An unlimited number of threads can store per-thread data in each QThreadStorage object. +The implementation of TQThreadStorage limits the total number of TQThreadStorage objects to 256. An unlimited number of threads can store per-thread data in each TQThreadStorage object. .IP .PP See also Environment Classes and Threading. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QThreadStorage::QThreadStorage ()" +.SH "TQThreadStorage::TQThreadStorage ()" Constructs a new per-thread data storage object. -.SH "QThreadStorage::~QThreadStorage ()" +.SH "TQThreadStorage::~TQThreadStorage ()" Destroys the per-thread data storage object. .PP -Note: The per-thread data stored is \fInot\fR deleted. Any data left in QThreadStorage is leaked. Make sure that all threads using QThreadStorage have exited before deleting the QThreadStorage. +Note: The per-thread data stored is \fInot\fR deleted. Any data left in TQThreadStorage is leaked. Make sure that all threads using TQThreadStorage have exited before deleting the TQThreadStorage. .PP See also hasLocalData(). -.SH "bool QThreadStorage::hasLocalData () const" +.SH "bool TQThreadStorage::hasLocalData () const" Returns TRUE if the calling thread has non-zero data available; otherwise returns FALSE. .PP See also localData(). -.SH "T & QThreadStorage::localData ()" +.SH "T & TQThreadStorage::localData ()" Returns a reference to the data that was set by the calling thread. .PP -Note: QThreadStorage can only store pointers. This function returns a \fIreference\fR to the pointer that was set by the calling thread. The value of this reference is 0 if no data was set by the calling thread, +Note: TQThreadStorage can only store pointers. This function returns a \fIreference\fR to the pointer that was set by the calling thread. The value of this reference is 0 if no data was set by the calling thread, .PP See also hasLocalData(). -.SH "T QThreadStorage::localData () const" +.SH "T TQThreadStorage::localData () const" This is an overloaded member function, provided for convenience. It behaves essentially like the above function. .PP Returns a copy of the data that was set by the calling thread. .PP -Note: QThreadStorage can only store pointers. This function returns a pointer to the data that was set by the calling thread. If no data was set by the calling thread, this function returns 0. +Note: TQThreadStorage can only store pointers. This function returns a pointer to the data that was set by the calling thread. If no data was set by the calling thread, this function returns 0. .PP See also hasLocalData(). -.SH "void QThreadStorage::setLocalData ( T data )" +.SH "void TQThreadStorage::setLocalData ( T data )" Sets the local data for the calling thread to \fIdata\fR. It can be accessed later using the localData() functions. .PP If \fIdata\fR is 0, this function deletes the previous data (if any) and returns immediately. .PP -If \fIdata\fR is non-zero, QThreadStorage takes ownership of the \fIdata\fR and deletes it automatically either when the thread exits (either normally or via termination) or when setLocalData() is called again. +If \fIdata\fR is non-zero, TQThreadStorage takes ownership of the \fIdata\fR and deletes it automatically either when the thread exits (either normally or via termination) or when setLocalData() is called again. .PP -Note: QThreadStorage can only store pointers. The \fIdata\fR argument must be either a pointer to an object created on the heap (i.e. using \fInew\fR) or 0. You should not delete \fIdata\fR yourself; QThreadStorage takes ownership and will delete the \fIdata\fR itself. +Note: TQThreadStorage can only store pointers. The \fIdata\fR argument must be either a pointer to an object created on the heap (i.e. using \fInew\fR) or 0. You should not delete \fIdata\fR yourself; TQThreadStorage takes ownership and will delete the \fIdata\fR itself. .PP See also localData() and hasLocalData(). .SH "SEE ALSO" -.BR http://doc.trolltech.com/ntqthreadstorage.html +.BR http://doc.trolltech.com/tqthreadstorage.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/man/man3/tqvaluelist.3qt b/doc/man/man3/tqvaluelist.3qt index 040ecd815..cc7b8e5c9 100644 --- a/doc/man/man3/tqvaluelist.3qt +++ b/doc/man/man3/tqvaluelist.3qt @@ -383,7 +383,7 @@ It is safe to have multiple iterators a the list at the same time. If some membe .PP Because TQValueList is value-based there is no need to be careful about deleting items in the list. The list holds its own copies and will free them if the corresponding member or the list itself is deleted. You can force the list to free all of its items with clear(). .PP -TQValueList is shared implicitly, which means it can be copied in constant time, i.e. O(1). If multiple TQValueList instances share the same data and one needs to modify its contents, this modifying instance makes a copy and modifies its private copy; therefore it does not affect the other instances; this takes O(n) time. This is often called "copy on write". If a TQValueList is being used in a multi-threaded program, you must protect all access to the list. See QMutex. +TQValueList is shared implicitly, which means it can be copied in constant time, i.e. O(1). If multiple TQValueList instances share the same data and one needs to modify its contents, this modifying instance makes a copy and modifies its private copy; therefore it does not affect the other instances; this takes O(n) time. This is often called "copy on write". If a TQValueList is being used in a multi-threaded program, you must protect all access to the list. See TQMutex. .PP There are several ways to insert items into the list. The prepend() and append() functions insert items at the beginning and the end of the list respectively. The insert() function comes in several flavors and can be used to add one or more items at specific positions within the list. .PP diff --git a/doc/man/man3/tqvaluevector.3qt b/doc/man/man3/tqvaluevector.3qt index c2e9caefd..2c3827394 100644 --- a/doc/man/man3/tqvaluevector.3qt +++ b/doc/man/man3/tqvaluevector.3qt @@ -395,7 +395,7 @@ By creating a TQValueVector with a sufficiently large initial size, there will b .PP Because TQValueVector is value-based there is no need to be careful about deleting elements in the vector. The vector holds its own copies and will free them if the corresponding member or the vector itself is deleted. You can force the vector to free all of its items with clear(). .PP -TQValueVector is shared implicitly, which means it can be copied in constant time. If multiple TQValueVector instances share the same data and one needs to modify its contents, this modifying instance makes a copy and modifies its private copy; it thus does not affect the other instances. This is often called "copy on write". If a TQValueVector is being used in a multi-threaded program, you must protect all access to the vector. See QMutex. +TQValueVector is shared implicitly, which means it can be copied in constant time. If multiple TQValueVector instances share the same data and one needs to modify its contents, this modifying instance makes a copy and modifies its private copy; it thus does not affect the other instances. This is often called "copy on write". If a TQValueVector is being used in a multi-threaded program, you must protect all access to the vector. See TQMutex. .PP There are several ways to insert elements into the vector. The push_back() function insert elements into the end of the vector, and is usually fastest. The insert() function can be used to add elements at specific positions within the vector. .PP diff --git a/doc/man/man3/tqwaitcondition.3qt b/doc/man/man3/tqwaitcondition.3qt index 8db75baca..3dbbc3741 100644 --- a/doc/man/man3/tqwaitcondition.3qt +++ b/doc/man/man3/tqwaitcondition.3qt @@ -1,5 +1,5 @@ '\" t -.TH QWaitCondition 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.TH TQWaitCondition 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. @@ -7,25 +7,25 @@ .ad l .nh .SH NAME -QWaitCondition \- Allows waiting/waking for conditions between threads +TQWaitCondition \- Allows waiting/waking for conditions between threads .SH SYNOPSIS All the functions in this class are thread-safe when TQt is built with thread support.

        .PP -\fC#include \fR +\fC#include \fR .PP .SS "Public Members" .in +1c .ti -1c -.BI "\fBQWaitCondition\fR ()" +.BI "\fBTQWaitCondition\fR ()" .br .ti -1c -.BI "virtual \fB~QWaitCondition\fR ()" +.BI "virtual \fB~TQWaitCondition\fR ()" .br .ti -1c .BI "bool \fBwait\fR ( unsigned long time = ULONG_MAX )" .br .ti -1c -.BI "bool \fBwait\fR ( QMutex * mutex, unsigned long time = ULONG_MAX )" +.BI "bool \fBwait\fR ( TQMutex * mutex, unsigned long time = ULONG_MAX )" .br .ti -1c .BI "void \fBwakeOne\fR ()" @@ -35,18 +35,18 @@ All the functions in this class are thread-safe when TQt is built with thread su .br .in -1c .SH DESCRIPTION -The QWaitCondition class allows waiting/waking for conditions between threads. +The TQWaitCondition class allows waiting/waking for conditions between threads. .PP -QWaitConditions allow a thread to tell other threads that some sort of condition has been met; one or many threads can block waiting for a QWaitCondition to set a condition with wakeOne() or wakeAll(). Use wakeOne() to wake one randomly selected event or wakeAll() to wake them all. For example, say we have three tasks that should be performed every time the user presses a key; each task could be split into a thread, each of which would have a run() body like this: +TQWaitConditions allow a thread to tell other threads that some sort of condition has been met; one or many threads can block waiting for a TQWaitCondition to set a condition with wakeOne() or wakeAll(). Use wakeOne() to wake one randomly selected event or wakeAll() to wake them all. For example, say we have three tasks that should be performed every time the user presses a key; each task could be split into a thread, each of which would have a run() body like this: .PP .nf .br - QWaitCondition key_pressed; + TQWaitCondition key_pressed; .br .br for (;;) { .br - key_pressed.wait(); // This is a QWaitCondition global variable + key_pressed.wait(); // This is a TQWaitCondition global variable .br // Key was pressed, do something interesting .br @@ -60,7 +60,7 @@ A fourth thread would read key presses and wake the other three threads up every .PP .nf .br - QWaitCondition key_pressed; + TQWaitCondition key_pressed; .br .br for (;;) { @@ -81,9 +81,9 @@ Note that the order the three threads are woken up in is undefined, and that if .PP .nf .br - QMutex mymutex; + TQMutex mymutex; .br - QWaitCondition key_pressed; + TQWaitCondition key_pressed; .br int mycount=0; .br @@ -92,7 +92,7 @@ Note that the order the three threads are woken up in is undefined, and that if .br for (;;) { .br - key_pressed.wait(); // This is a QWaitCondition global variable + key_pressed.wait(); // This is a TQWaitCondition global variable .br mymutex.lock(); .br @@ -143,11 +143,11 @@ The mutexes are necessary because the results of two threads attempting to chang .PP See also Environment Classes and Threading. .SH MEMBER FUNCTION DOCUMENTATION -.SH "QWaitCondition::QWaitCondition ()" +.SH "TQWaitCondition::TQWaitCondition ()" Constructs a new event signalling, i.e. wait condition, object. -.SH "QWaitCondition::~QWaitCondition ()\fC [virtual]\fR" +.SH "TQWaitCondition::~TQWaitCondition ()\fC [virtual]\fR" Deletes the event signalling, i.e. wait condition, object. -.SH "bool QWaitCondition::wait ( unsigned long time = ULONG_MAX )" +.SH "bool TQWaitCondition::wait ( unsigned long time = ULONG_MAX )" Wait on the thread event object. The thread calling this will block until either of these conditions is met: .TP Another thread signals it using wakeOne() or wakeAll(). This function will return TRUE in this case. @@ -155,7 +155,7 @@ Another thread signals it using wakeOne() or wakeAll(). This function will retur \fItime\fR milliseconds has elapsed. If \fItime\fR is ULONG_MAX (the default), then the wait will never timeout (the event must be signalled). This function will return FALSE if the wait timed out. .PP See also wakeOne() and wakeAll(). -.SH "bool QWaitCondition::wait ( QMutex * mutex, unsigned long time = ULONG_MAX )" +.SH "bool TQWaitCondition::wait ( TQMutex * mutex, unsigned long time = ULONG_MAX )" This is an overloaded member function, provided for convenience. It behaves essentially like the above function. .PP Release the locked \fImutex\fR and wait on the thread event object. The \fImutex\fR must be initially locked by the calling thread. If \fImutex\fR is not in a locked state, this function returns immediately. If \fImutex\fR is a recursive mutex, this function returns immediately. The \fImutex\fR will be unlocked, and the calling thread will block until either of these conditions is met: @@ -167,17 +167,17 @@ Another thread signals it using wakeOne() or wakeAll(). This function will retur The mutex will be returned to the same locked state. This function is provided to allow the atomic transition from the locked state to the wait state. .PP See also wakeOne() and wakeAll(). -.SH "void QWaitCondition::wakeAll ()" -This wakes all threads waiting on the QWaitCondition. The order in which the threads are woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted. +.SH "void TQWaitCondition::wakeAll ()" +This wakes all threads waiting on the TQWaitCondition. The order in which the threads are woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted. .PP See also wakeOne(). -.SH "void QWaitCondition::wakeOne ()" -This wakes one thread waiting on the QWaitCondition. The thread that is woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted. +.SH "void TQWaitCondition::wakeOne ()" +This wakes one thread waiting on the TQWaitCondition. The thread that is woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted. .PP See also wakeAll(). .SH "SEE ALSO" -.BR http://doc.trolltech.com/ntqwaitcondition.html +.BR http://doc.trolltech.com/tqwaitcondition.html .BR http://www.trolltech.com/faq/tech.html .SH COPYRIGHT Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the diff --git a/doc/porting3.doc b/doc/porting3.doc index 9afb769df..a2c9656a7 100644 --- a/doc/porting3.doc +++ b/doc/porting3.doc @@ -220,7 +220,7 @@ All these functions have been removed in TQt 3.x: \i TQString::visual() \i TQStyle::set...() functions \i TQStyle::drawArrow() -\i QThread::postEvent(TQObject *receiver, TQEvent *event). Use TQApplication::postEvent() instead. +\i TQThread::postEvent(TQObject *receiver, TQEvent *event). Use TQApplication::postEvent() instead. \i QToolButton::iconSet(bool on) const \i QToolButton::offIconSet() const \i QToolButton::onIconSet() const diff --git a/doc/threads.doc b/doc/threads.doc index 79f29dbaa..dd51296f8 100644 --- a/doc/threads.doc +++ b/doc/threads.doc @@ -78,21 +78,21 @@ entry in \c{ntqconfig.h}. These classes are built into the TQt library when thread support is enabled: \list -\i QThread - Provides the means to start a new thread, which begins -execution in your reimplementation of QThread::run(). This is similar +\i TQThread - Provides the means to start a new thread, which begins +execution in your reimplementation of TQThread::run(). This is similar to the Java thread class. -\i QThreadStorage - Provides per-thread data storage. This class can -only be used with threads started with QThread; it cannot be used with +\i TQThreadStorage - Provides per-thread data storage. This class can +only be used with threads started with TQThread; it cannot be used with threads started with platform-specific APIs. -\i QMutex - Provides a mutual exclusion lock (also know as a mutex). -\i QMutexLocker - A convenience class which automatically locks and -unlocks a QMutex. QMutexLocker is useful in complicated code, or in +\i TQMutex - Provides a mutual exclusion lock (also know as a mutex). +\i TQMutexLocker - A convenience class which automatically locks and +unlocks a TQMutex. TQMutexLocker is useful in complicated code, or in code which uses exceptions. See the documentation for more details. -\i QWaitCondition - Provides a way for threads to go to sleep until +\i TQWaitCondition - Provides a way for threads to go to sleep until woken up by another thread. -\i QSemaphore - Provides a simple integer semaphore. +\i TQSemaphore - Provides a simple integer semaphore. \endlist \section1 Important Definitions @@ -147,7 +147,7 @@ a time can call member functions on each instance of \c Number. However, multiple threads can call member functions on separate instances of \c Number. -Thread-safe functions usually use a mutex (e.g a QMutex) to serialize +Thread-safe functions usually use a mutex (e.g a TQMutex) to serialize access to shared data. Because of this, thread-safe functions are usually slower than reentrant functions, because of the extra overhead of locking and unlocking the mutex. For example, given the class \c @@ -182,7 +182,7 @@ mutex must be used: ... private: - static QMutex mutex; + static TQMutex mutex; static int instances; }; \endcode @@ -337,7 +337,7 @@ all pending events have been delivered to the object. \i Don't do any blocking operations while holding the TQt library mutex. This will freeze up the event loop. -\i Make sure you unlock a recursive QMutex as many times as you lock +\i Make sure you unlock a recursive TQMutex as many times as you lock it, no more and no less. \i Don't mix the normal TQt library and the threaded TQt library in your diff --git a/doc/tqmap.doc b/doc/tqmap.doc index 5006ca271..cad832f46 100644 --- a/doc/tqmap.doc +++ b/doc/tqmap.doc @@ -210,7 +210,7 @@ data and one is modifying the map's data, this modifying instance makes a copy and modifies its private copy: so it does not affect other instances. If a TQMap is being used in a multi-threaded - program, you must protect all access to the map. See \l QMutex. + program, you must protect all access to the map. See \l TQMutex. There are a couple of ways of inserting new items into the map. One uses the insert() method; the other uses operator[]: diff --git a/doc/tqvaluelist.doc b/doc/tqvaluelist.doc index 4eba79409..7815d5acb 100644 --- a/doc/tqvaluelist.doc +++ b/doc/tqvaluelist.doc @@ -203,7 +203,7 @@ does not affect the other instances; this takes O(n) time. This is often called "copy on write". If a TQValueList is being used in a multi-threaded program, you must protect all access to the list. - See \l QMutex. + See \l TQMutex. There are several ways to insert items into the list. The prepend() and append() functions insert items at the beginning and diff --git a/doc/tqvaluevector.doc b/doc/tqvaluevector.doc index 49ed3f3ae..3be96ae2f 100644 --- a/doc/tqvaluevector.doc +++ b/doc/tqvaluevector.doc @@ -264,7 +264,7 @@ makes a copy and modifies its private copy; it thus does not affect the other instances. This is often called "copy on write". If a TQValueVector is being used in a multi-threaded program, you - must protect all access to the vector. See QMutex. + must protect all access to the vector. See TQMutex. There are several ways to insert elements into the vector. The push_back() function insert elements into the end of the vector, diff --git a/examples/thread/prodcons/prodcons.cpp b/examples/thread/prodcons/prodcons.cpp index d8cb43111..88553869e 100644 --- a/examples/thread/prodcons/prodcons.cpp +++ b/examples/thread/prodcons/prodcons.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/examples/thread/semaphores/main.cpp b/examples/thread/semaphores/main.cpp index 0e0bbb810..f6b9157dd 100644 --- a/examples/thread/semaphores/main.cpp +++ b/examples/thread/semaphores/main.cpp @@ -10,9 +10,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/include/ntqmutex.h b/include/ntqmutex.h deleted file mode 120000 index 0b2e6277c..000000000 --- a/include/ntqmutex.h +++ /dev/null @@ -1 +0,0 @@ -../src/tools/ntqmutex.h \ No newline at end of file diff --git a/include/ntqsemaphore.h b/include/ntqsemaphore.h deleted file mode 120000 index fd38d086b..000000000 --- a/include/ntqsemaphore.h +++ /dev/null @@ -1 +0,0 @@ -../src/tools/ntqsemaphore.h \ No newline at end of file diff --git a/include/ntqthread.h b/include/ntqthread.h deleted file mode 120000 index fcc097894..000000000 --- a/include/ntqthread.h +++ /dev/null @@ -1 +0,0 @@ -../src/kernel/ntqthread.h \ No newline at end of file diff --git a/include/ntqthreadstorage.h b/include/ntqthreadstorage.h deleted file mode 120000 index 8833f8a8b..000000000 --- a/include/ntqthreadstorage.h +++ /dev/null @@ -1 +0,0 @@ -../src/tools/ntqthreadstorage.h \ No newline at end of file diff --git a/include/ntqwaitcondition.h b/include/ntqwaitcondition.h deleted file mode 120000 index c767321fb..000000000 --- a/include/ntqwaitcondition.h +++ /dev/null @@ -1 +0,0 @@ -../src/tools/ntqwaitcondition.h \ No newline at end of file diff --git a/include/private/qmutex_p.h b/include/private/qmutex_p.h deleted file mode 120000 index 2dcf0d356..000000000 --- a/include/private/qmutex_p.h +++ /dev/null @@ -1 +0,0 @@ -../../src/tools/qmutex_p.h \ No newline at end of file diff --git a/include/private/qmutexpool_p.h b/include/private/qmutexpool_p.h deleted file mode 120000 index fc31eaadd..000000000 --- a/include/private/qmutexpool_p.h +++ /dev/null @@ -1 +0,0 @@ -../../src/tools/qmutexpool_p.h \ No newline at end of file diff --git a/include/private/qthreadinstance_p.h b/include/private/qthreadinstance_p.h deleted file mode 120000 index 952c83620..000000000 --- a/include/private/qthreadinstance_p.h +++ /dev/null @@ -1 +0,0 @@ -../../src/tools/qthreadinstance_p.h \ No newline at end of file diff --git a/include/private/tqmutex_p.h b/include/private/tqmutex_p.h new file mode 120000 index 000000000..af12dcdc8 --- /dev/null +++ b/include/private/tqmutex_p.h @@ -0,0 +1 @@ +../../src/tools/tqmutex_p.h \ No newline at end of file diff --git a/include/private/tqmutexpool_p.h b/include/private/tqmutexpool_p.h new file mode 120000 index 000000000..dcd445d23 --- /dev/null +++ b/include/private/tqmutexpool_p.h @@ -0,0 +1 @@ +../../src/tools/tqmutexpool_p.h \ No newline at end of file diff --git a/include/private/tqthreadinstance_p.h b/include/private/tqthreadinstance_p.h new file mode 120000 index 000000000..c6380e3f8 --- /dev/null +++ b/include/private/tqthreadinstance_p.h @@ -0,0 +1 @@ +../../src/tools/tqthreadinstance_p.h \ No newline at end of file diff --git a/include/tqmutex.h b/include/tqmutex.h new file mode 120000 index 000000000..c550c019c --- /dev/null +++ b/include/tqmutex.h @@ -0,0 +1 @@ +../src/tools/tqmutex.h \ No newline at end of file diff --git a/include/tqsemaphore.h b/include/tqsemaphore.h new file mode 120000 index 000000000..f8c39570e --- /dev/null +++ b/include/tqsemaphore.h @@ -0,0 +1 @@ +../src/tools/tqsemaphore.h \ No newline at end of file diff --git a/include/tqthread.h b/include/tqthread.h new file mode 120000 index 000000000..fb906f1e2 --- /dev/null +++ b/include/tqthread.h @@ -0,0 +1 @@ +../src/kernel/tqthread.h \ No newline at end of file diff --git a/include/tqthreadstorage.h b/include/tqthreadstorage.h new file mode 120000 index 000000000..d3804ee0d --- /dev/null +++ b/include/tqthreadstorage.h @@ -0,0 +1 @@ +../src/tools/tqthreadstorage.h \ No newline at end of file diff --git a/include/tqwaitcondition.h b/include/tqwaitcondition.h new file mode 120000 index 000000000..3734541e3 --- /dev/null +++ b/include/tqwaitcondition.h @@ -0,0 +1 @@ +../src/tools/tqwaitcondition.h \ No newline at end of file diff --git a/qmake/generators/projectgenerator.cpp b/qmake/generators/projectgenerator.cpp index 0bc44a599..1fd4bf226 100644 --- a/qmake/generators/projectgenerator.cpp +++ b/qmake/generators/projectgenerator.cpp @@ -274,7 +274,7 @@ ProjectGenerator::init() if(!h_ext.isEmpty()) { if((*dep_it).left(1).lower() == "q") { TQString qhdr = (*dep_it).lower(); - if(file_no_path == "ntqthread.h") + if(file_no_path == "tqthread.h") addConfig("thread"); } for(TQStringList::Iterator cppit = Option::cpp_ext.begin(); diff --git a/src/codecs/tqtextcodec.cpp b/src/codecs/tqtextcodec.cpp index 0609ae294..8d2c0bb17 100644 --- a/src/codecs/tqtextcodec.cpp +++ b/src/codecs/tqtextcodec.cpp @@ -76,7 +76,7 @@ #endif #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/codecs/tqtextcodecfactory.cpp b/src/codecs/tqtextcodecfactory.cpp index 24ac82a09..b98155587 100644 --- a/src/codecs/tqtextcodecfactory.cpp +++ b/src/codecs/tqtextcodecfactory.cpp @@ -49,7 +49,7 @@ #include "tqtextcodecinterface_p.h" #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/dialogs/qfiledialog.cpp b/src/dialogs/qfiledialog.cpp index 7dfc1fb2a..983c817d3 100644 --- a/src/dialogs/qfiledialog.cpp +++ b/src/dialogs/qfiledialog.cpp @@ -100,7 +100,7 @@ #ifdef TQ_WS_WIN #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #endif // TQ_WS_WIN diff --git a/src/inputmethod/qinputcontextfactory.cpp b/src/inputmethod/qinputcontextfactory.cpp index a54d2d24c..9199f8088 100644 --- a/src/inputmethod/qinputcontextfactory.cpp +++ b/src/inputmethod/qinputcontextfactory.cpp @@ -44,7 +44,7 @@ #include "ntqapplication.h" #ifdef TQT_THREAD_SUPPORT -#include +#include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 4dee12662..41b65486d 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -136,7 +136,7 @@ #include #include #include "tqptrvector.h" -#include "ntqmutex.h" +#include "tqmutex.h" #include #include #include "ntqguardedptr.h" @@ -178,7 +178,7 @@ #include #include #include -#include "ntqsemaphore.h" +#include "tqsemaphore.h" #include #include "ntqsocketdevice.h" #include @@ -236,7 +236,7 @@ #include #include "ntqtoolbar.h" #include -#include "ntqwaitcondition.h" +#include "tqwaitcondition.h" #include #include #include @@ -257,7 +257,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/ntqthread.h b/src/kernel/ntqthread.h deleted file mode 100644 index 0b38e5a33..000000000 --- a/src/kernel/ntqthread.h +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Definition of TQThread class -** -** Created : 931107 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQTHREAD_H -#define TQTHREAD_H - -#if defined(TQT_THREAD_SUPPORT) - -#ifndef QT_H -#include "ntqwindowdefs.h" -#endif // QT_H - -#include - -class TQThreadInstance; - -class TQ_EXPORT TQThread : public TQt -{ -public: - static TQt::HANDLE currentThread(); - - static void initialize(); - static void cleanup(); - - static void exit(); - -#ifdef Q_QDOC - TQThread( unsigned int stackSize = 0 ); -#else - TQThread( unsigned int stackSize ); - TQThread(); -#endif - - virtual ~TQThread(); - - // default argument causes thread to block indefinately - bool wait( unsigned long time = ULONG_MAX ); - - enum Priority { - IdlePriority, - - LowestPriority, - LowPriority, - NormalPriority, - HighPriority, - HighestPriority, - - TimeCriticalPriority, - - InheritPriority - }; - -#ifdef Q_QDOC - void start( Priority = InheritPriority ); -#else - void start( Priority ); - void start(); -#endif - - void terminate(); - - bool finished() const; - bool running() const; - - enum CleanupType { - CleanupNone, - CleanupMergeObjects - }; - - CleanupType cleanupType() const; - void setCleanupType(CleanupType); - - bool threadPostedEventsDisabled() const; - void setThreadPostedEventsDisabled(bool); - -protected: - virtual void run() = 0; - - static void sleep( unsigned long ); - static void msleep( unsigned long ); - static void usleep( unsigned long ); - -private: - TQThreadInstance * d; - friend class TQThreadInstance; - friend class TQThreadStorageData; - friend class TQCoreApplicationThread; - friend class TQApplication; - friend class TQEventLoop; - -#if defined(TQ_DISABLE_COPY) - TQThread( const TQThread & ); - TQThread &operator=( const TQThread & ); -#endif // TQ_DISABLE_COPY - -public: - static TQThread* currentThreadObject(); -}; - -class TQ_EXPORT TQEventLoopThread : public TQThread -{ - public: - TQEventLoopThread(); - ~TQEventLoopThread(); - virtual void run(); -}; - -#endif // TQT_THREAD_SUPPORT - -#endif // TQTHREAD_H diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index c6bde72a7..5297837cc 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -66,9 +66,9 @@ #include "qfontdata_p.h" #if defined(TQT_THREAD_SUPPORT) -# include "ntqmutex.h" -# include "ntqthread.h" -# include +# include "tqmutex.h" +# include "tqthread.h" +# include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index 33fa0ceca..cd65da67a 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -95,7 +95,7 @@ #include "qinternal_p.h" // shared double buffer cleanup #if defined(TQT_THREAD_SUPPORT) -# include "ntqthread.h" +# include "tqthread.h" #endif #if defined(QT_DEBUG) && defined(Q_OS_LINUX) diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp index e08a1ee1c..ce0f2bc82 100644 --- a/src/kernel/qeventloop.cpp +++ b/src/kernel/qeventloop.cpp @@ -42,8 +42,8 @@ #include "tqdatetime.h" #ifdef TQT_THREAD_SUPPORT -# include "ntqthread.h" -# include "private/qthreadinstance_p.h" +# include "tqthread.h" +# include "private/tqthreadinstance_p.h" #endif /*! diff --git a/src/kernel/qeventloop_unix.cpp b/src/kernel/qeventloop_unix.cpp index 132279314..89e31da82 100644 --- a/src/kernel/qeventloop_unix.cpp +++ b/src/kernel/qeventloop_unix.cpp @@ -40,7 +40,7 @@ #include "ntqeventloop.h" #include "ntqapplication.h" #include "ntqbitarray.h" -#include "ntqmutex.h" +#include "tqmutex.h" #include #include diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp index e65d49bb2..5d43a6efb 100644 --- a/src/kernel/qeventloop_unix_glib.cpp +++ b/src/kernel/qeventloop_unix_glib.cpp @@ -40,10 +40,10 @@ #include "ntqeventloop.h" #include "ntqapplication.h" #include "ntqbitarray.h" -#include "ntqmutex.h" +#include "tqmutex.h" #if defined(TQT_THREAD_SUPPORT) - #include "ntqthread.h" + #include "tqthread.h" #endif #include diff --git a/src/kernel/qeventloop_x11.cpp b/src/kernel/qeventloop_x11.cpp index 1ba3b21df..6905bac22 100644 --- a/src/kernel/qeventloop_x11.cpp +++ b/src/kernel/qeventloop_x11.cpp @@ -44,7 +44,7 @@ #include "qt_x11_p.h" #if defined(TQT_THREAD_SUPPORT) -# include "ntqmutex.h" +# include "tqmutex.h" #endif // TQT_THREAD_SUPPORT #include diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp index a13dbeebf..b152d6a38 100644 --- a/src/kernel/qeventloop_x11_glib.cpp +++ b/src/kernel/qeventloop_x11_glib.cpp @@ -47,8 +47,8 @@ #include "qt_x11_p.h" #if defined(TQT_THREAD_SUPPORT) -# include "ntqmutex.h" -# include "ntqthread.h" +# include "tqmutex.h" +# include "tqthread.h" #endif // TQT_THREAD_SUPPORT #include diff --git a/src/kernel/qmetaobject.cpp b/src/kernel/qmetaobject.cpp index 70ed6b5d5..624c025d8 100644 --- a/src/kernel/qmetaobject.cpp +++ b/src/kernel/qmetaobject.cpp @@ -42,7 +42,7 @@ #include "ntqasciidict.h" #ifdef TQT_THREAD_SUPPORT -#include +#include #endif // TQT_THREAD_SUPPORT /*! diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index 446019b6e..c4690a3f6 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -77,7 +77,7 @@ kernel { $$KERNEL_H/ntqsound.h \ $$KERNEL_H/tqstyle.h \ $$KERNEL_H/tqstylesheet.h \ - $$KERNEL_H/ntqthread.h \ + $$KERNEL_H/tqthread.h \ $$KERNEL_H/tqtimer.h \ $$KERNEL_H/ntqurl.h \ $$KERNEL_H/ntqlocalfs.h \ @@ -127,7 +127,7 @@ kernel { $$KERNEL_CPP/qpainter_win.cpp \ $$KERNEL_CPP/qregion_win.cpp \ $$KERNEL_CPP/qsound_win.cpp \ - $$KERNEL_CPP/qthread_win.cpp \ + $$KERNEL_CPP/tqthread_win.cpp \ $$KERNEL_CPP/tqwidget_win.cpp \ $$KERNEL_CPP/qole_win.c \ $$KERNEL_CPP/qfontengine_win.cpp @@ -191,7 +191,7 @@ kernel { } unix:SOURCES += $$KERNEL_CPP/qprocess_unix.cpp \ - $$KERNEL_CPP/qthread_unix.cpp + $$KERNEL_CPP/tqthread_unix.cpp SOURCES += $$KERNEL_CPP/qabstractlayout.cpp \ $$KERNEL_CPP/qucomextra.cpp \ @@ -248,7 +248,7 @@ kernel { $$KERNEL_CPP/qsocketnotifier.cpp \ $$KERNEL_CPP/qsound.cpp \ $$KERNEL_CPP/tqstylesheet.cpp \ - $$KERNEL_CPP/qthread.cpp \ + $$KERNEL_CPP/tqthread.cpp \ $$KERNEL_CPP/tqtimer.cpp \ $$KERNEL_CPP/qurl.cpp \ $$KERNEL_CPP/qlocalfs.cpp \ diff --git a/src/kernel/qthread.cpp b/src/kernel/qthread.cpp deleted file mode 100644 index bb51e41fc..000000000 --- a/src/kernel/qthread.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** -** -** Cross-platform TQThread implementation. -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifdef TQT_THREAD_SUPPORT - -#include "qplatformdefs.h" - -#include "ntqthread.h" -#include "ntqeventloop.h" -#include - -#ifndef QT_H -# include "ntqapplication.h" -#endif // QT_H - - -/*! - \class TQThread ntqthread.h - \threadsafe - \brief The TQThread class provides platform-independent threads. - - \ingroup thread - \ingroup environment - - A TQThread represents a separate thread of control within the - program; it shares data with all the other threads within the - process but executes independently in the way that a separate - program does on a multitasking operating system. Instead of - starting in main(), TQThreads begin executing in run(). You inherit - run() to include your code. For example: - - \code - class MyThread : public TQThread { - - public: - - virtual void run(); - - }; - - void MyThread::run() - { - for( int count = 0; count < 20; count++ ) { - sleep( 1 ); - tqDebug( "Ping!" ); - } - } - - int main() - { - MyThread a; - MyThread b; - a.start(); - b.start(); - a.wait(); - b.wait(); - } - \endcode - - This will start two threads, each of which writes Ping! 20 times - to the screen and exits. The wait() calls at the end of main() are - necessary because exiting main() ends the program, unceremoniously - killing all other threads. Each MyThread stops executing when it - reaches the end of MyThread::run(), just as an application does - when it leaves main(). - - \sa \link threads.html Thread Support in TQt\endlink. -*/ - -/*! - \enum TQThread::Priority - - This enum type indicates how the operating system should schedule - newly created threads. - - \value IdlePriority scheduled only when no other threads are - running. - - \value LowestPriority scheduled less often than LowPriority. - \value LowPriority scheduled less often than NormalPriority. - - \value NormalPriority the default priority of the operating - system. - - \value HighPriority scheduled more often than NormalPriority. - \value HighestPriority scheduled more often then HighPriority. - - \value TimeCriticalPriority scheduled as often as possible. - - \value InheritPriority use the same priority as the creating - thread. This is the default. -*/ - -TQThread::TQThread() -{ -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( TQApplication::tqt_mutex ); -#endif // TQT_THREAD_SUPPORT - - d = new TQThreadInstance; - d->init(0); -} - -/*! - Constructs a new thread. The thread does not begin executing until - start() is called. - - If \a stackSize is greater than zero, the maximum stack size is - set to \a stackSize bytes, otherwise the maximum stack size is - automatically determined by the operating system. - - \warning Most operating systems place minimum and maximum limits - on thread stack sizes. The thread will fail to start if the stack - size is outside these limits. -*/ -TQThread::TQThread( unsigned int stackSize ) -{ - d = new TQThreadInstance; - d->init(stackSize); -} - -/*! - TQThread destructor. - - Note that deleting a TQThread object will not stop the execution of - the thread it represents. Deleting a running TQThread (i.e. - finished() returns FALSE) will probably result in a program crash. - You can wait() on a thread to make sure that it has finished. -*/ -TQThread::~TQThread() -{ - TQMutexLocker locker( d->mutex() ); - if ( d->running && !d->finished ) { -#ifdef QT_CHECK_STATE - tqWarning("TQThread object destroyed while thread is still running."); -#endif - - d->orphan = TRUE; - return; - } - - d->deinit(); - delete d; -} - -/*! - This function terminates the execution of the thread. The thread - may or may not be terminated immediately, depending on the - operating system's scheduling policies. Use TQThread::wait() - after terminate() for synchronous termination. - - When the thread is terminated, all threads waiting for the - the thread to finish will be woken up. - - \warning This function is dangerous, and its use is discouraged. - The thread can be terminated at any point in its code path. Threads - can be terminated while modifying data. There is no chance for - the thread to cleanup after itself, unlock any held mutexes, etc. - In short, use this function only if \e absolutely necessary. -*/ -void TQThread::terminate() -{ - TQMutexLocker locker( d->mutex() ); - if ( d->finished || !d->running ) - return; - d->terminate(); -} - -/*! - Returns TRUE if the thread is finished; otherwise returns FALSE. -*/ -bool TQThread::finished() const -{ - TQMutexLocker locker( d->mutex() ); - return d->finished; -} - -/*! - Returns TRUE if the thread is running; otherwise returns FALSE. -*/ -bool TQThread::running() const -{ - TQMutexLocker locker( d->mutex() ); - return d->running; -} - -/*! - Changes the way cross thread signals are handled - If disable is FALSE, signals emitted from this thread will be - posted to any other connected threads' event loops (default). - - If disable is TRUE, calls to emit from this thread - will immediately execute slots in another thread. - This mode of operation is inherently unsafe and is provided - solely to support thread management by a third party application. - */ -void TQThread::setThreadPostedEventsDisabled(bool disable) -{ - d->disableThreadPostedEvents = disable; -} - -/*! - Returns TRUE if thread posted events are disabled, FALSE if not - */ -bool TQThread::threadPostedEventsDisabled() const -{ - return d->disableThreadPostedEvents; -} - -/*! - \fn void TQThread::run() - - This method is pure virtual, and must be implemented in derived - classes in order to do useful work. Returning from this method - will end the execution of the thread. - - \sa wait() -*/ - -TQEventLoopThread::TQEventLoopThread() : TQThread() -{ - // -} - -TQEventLoopThread::~TQEventLoopThread() -{ - // -} - -void TQEventLoopThread::run() -{ - TQEventLoop* eventLoop = TQApplication::eventLoop(); - if (eventLoop) eventLoop->exec(); -} - -#endif // TQT_THREAD_SUPPORT diff --git a/src/kernel/qthread_unix.cpp b/src/kernel/qthread_unix.cpp deleted file mode 100644 index be67e002d..000000000 --- a/src/kernel/qthread_unix.cpp +++ /dev/null @@ -1,569 +0,0 @@ -/**************************************************************************** -** -** TQThread class for Unix -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#if defined(TQT_THREAD_SUPPORT) - -#include "qplatformdefs.h" - -typedef pthread_mutex_t Q_MUTEX_T; - -#include "ntqthread.h" -#include -#include -#include -#include -#include - -#include -#include - -#if defined(QT_USE_GLIBMAINLOOP) -#include -#endif // QT_USE_GLIBMAINLOOP - -static TQMutexPool *qt_thread_mutexpool = 0; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -typedef void*(*TQtThreadCallback)(void*); - -static pthread_once_t storage_key_once = PTHREAD_ONCE_INIT; -static pthread_key_t storage_key; -static void create_storage_key() -{ - pthread_key_create( &storage_key, NULL ); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -/************************************************************************** - ** TQThreadInstance - *************************************************************************/ - -void TQThreadInstance::setCurrentThread(TQThread *thread) -{ - pthread_once(&storage_key_once, create_storage_key); - pthread_setspecific(storage_key, thread); -} - -TQThreadInstance *TQThreadInstance::current() -{ - TQThreadInstance *ret = NULL; - pthread_once( &storage_key_once, create_storage_key ); - TQThread *thread = (TQThread *) pthread_getspecific( storage_key ); - if (thread) { - ret = thread->d; - } - return ret; -} - -void TQThreadInstance::init(unsigned int stackSize) -{ - stacksize = stackSize; - args[0] = args[1] = 0; - thread_storage = 0; - finished = FALSE; - running = FALSE; - orphan = FALSE; - disableThreadPostedEvents = FALSE; - - pthread_cond_init(&thread_done, NULL); - thread_id = 0; - - eventLoop = 0; - cleanupType = TQThread::CleanupMergeObjects; - - // threads have not been initialized yet, do it now - if (! qt_thread_mutexpool) TQThread::initialize(); -} - -void TQThreadInstance::deinit() -{ - pthread_cond_destroy(&thread_done); -} - -void *TQThreadInstance::start( void *_arg ) -{ - void **arg = (void **) _arg; - -#if defined(QT_USE_GLIBMAINLOOP) - // This is the first time we have access to the native pthread ID of this newly created thread - ((TQThreadInstance*)arg[1])->thread_id = pthread_self(); -#endif // QT_USE_GLIBMAINLOOP - -#ifdef QT_DEBUG - tqDebug("TQThreadInstance::start: Setting thread storage to %p\n", (TQThread *) arg[0]); -#endif // QT_DEBUG - setCurrentThread( (TQThread *) arg[0] ); - - pthread_cleanup_push( TQThreadInstance::finish, arg[1] ); - pthread_testcancel(); - - ( (TQThread *) arg[0] )->run(); - - pthread_cleanup_pop( TRUE ); - return 0; -} - -void TQThreadInstance::finish( void * ) -{ - TQThreadInstance *d = current(); - - if ( ! d ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQThread: internal error: zero data for running thread." ); -#endif // QT_CHECK_STATE - return; - } - -#ifdef QT_DEBUG - tqDebug("TQThreadInstance::finish: In TQThreadInstance::finish for thread %p\n", (TQThread*)d->args[0]); -#endif // QT_DEBUG - - TQApplication::threadTerminationHandler((TQThread*)d->args[0]); - - TQMutexLocker locker( d->mutex() ); - d->running = FALSE; - d->finished = TRUE; - d->args[0] = d->args[1] = 0; - - - TQThreadStorageData::finish( d->thread_storage ); - d->thread_storage = 0; - - d->thread_id = 0; - pthread_cond_broadcast(&d->thread_done); - - if (d->orphan) { - d->deinit(); - delete d; - } -} - -void TQThreadInstance::finishGuiThread(TQThreadInstance *d) { - TQThreadStorageData::finish( d->thread_storage ); - d->thread_storage = 0; -} - -TQMutex *TQThreadInstance::mutex() const -{ - return qt_thread_mutexpool ? qt_thread_mutexpool->get( (void *) this ) : 0; -} - -void TQThreadInstance::terminate() -{ - if ( ! thread_id ) return; - pthread_cancel( thread_id ); -} - -/************************************************************************** - ** TQThread - *************************************************************************/ - -/*! - This returns the thread handle of the currently executing thread. - - \warning The handle returned by this function is used for internal - purposes and should \e not be used in any application code. On - Windows, the returned value is a pseudo handle for the current - thread, and it cannot be used for numerical comparison. -*/ -TQt::HANDLE TQThread::currentThread() -{ - return (HANDLE) pthread_self(); -} - -/*! \internal - Initializes the TQThread system. -*/ -void TQThread::initialize() -{ - if ( ! tqt_global_mutexpool ) - tqt_global_mutexpool = new TQMutexPool( TRUE, 73 ); - if ( ! qt_thread_mutexpool ) - qt_thread_mutexpool = new TQMutexPool( FALSE, 127 ); -} - -/*! \internal - Cleans up the TQThread system. -*/ -void TQThread::cleanup() -{ - delete tqt_global_mutexpool; - delete qt_thread_mutexpool; - tqt_global_mutexpool = 0; - qt_thread_mutexpool = 0; -} - -/*! - Ends the execution of the calling thread and wakes up any threads - waiting for its termination. -*/ -void TQThread::exit() -{ - pthread_exit( 0 ); -} - -/* \internal - helper function to do thread sleeps, since usleep()/nanosleep() - aren't reliable enough (in terms of behavior and availability) -*/ -static void thread_sleep( struct timespec *ti ) -{ - pthread_mutex_t mtx; - pthread_cond_t cnd; - - pthread_mutex_init(&mtx, 0); - pthread_cond_init(&cnd, 0); - - pthread_mutex_lock( &mtx ); - (void) pthread_cond_timedwait( &cnd, &mtx, ti ); - pthread_mutex_unlock( &mtx ); - - pthread_cond_destroy( &cnd ); - pthread_mutex_destroy( &mtx ); -} - -/*! - System independent sleep. This causes the current thread to sleep - for \a secs seconds. -*/ -void TQThread::sleep( unsigned long secs ) -{ - struct timeval tv; - gettimeofday( &tv, 0 ); - struct timespec ti; - ti.tv_sec = tv.tv_sec + secs; - ti.tv_nsec = ( tv.tv_usec * 1000 ); - thread_sleep( &ti ); -} - -/*! - System independent sleep. This causes the current thread to sleep - for \a msecs milliseconds -*/ -void TQThread::msleep( unsigned long msecs ) -{ - struct timeval tv; - gettimeofday( &tv, 0 ); - struct timespec ti; - - ti.tv_nsec = ( tv.tv_usec + ( msecs % 1000 ) * 1000 ) * 1000; - ti.tv_sec = tv.tv_sec + ( msecs / 1000 ) + ( ti.tv_nsec / 1000000000 ); - ti.tv_nsec %= 1000000000; - thread_sleep( &ti ); -} - -/*! - System independent sleep. This causes the current thread to sleep - for \a usecs microseconds -*/ -void TQThread::usleep( unsigned long usecs ) -{ - struct timeval tv; - gettimeofday( &tv, 0 ); - struct timespec ti; - - ti.tv_nsec = ( tv.tv_usec + ( usecs % 1000000 ) ) * 1000; - ti.tv_sec = tv.tv_sec + ( usecs / 1000000 ) + ( ti.tv_nsec / 1000000000 ); - ti.tv_nsec %= 1000000000; - thread_sleep( &ti ); -} - -/*! - Begins execution of the thread by calling run(), which should be - reimplemented in a TQThread subclass to contain your code. The - operating system will schedule the thread according to the \a - priority argument. - - If you try to start a thread that is already running, this - function will wait until the the thread has finished and then - restart the thread. - - \sa Priority -*/ -void TQThread::start(Priority priority) -{ - TQMutexLocker locker( d->mutex() ); - - if ( d->running ) - pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle); - d->running = TRUE; - d->finished = FALSE; - - int ret; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - -#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0) -#if _POSIX_THREAD_PRIORITY_SCHEDULING == 0 && defined _SC_THREAD_PRIORITY_SCHEDULING - if (sysconf(_SC_THREAD_PRIORITY_SCHEDULING) > 0) -#endif - switch (priority) { - case InheritPriority: - { - pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); - break; - } - - default: - { - int sched_policy; - if (pthread_attr_getschedpolicy(&attr, &sched_policy) != 0) { - // failed to get the scheduling policy, don't bother - // setting the priority - tqWarning("TQThread: cannot determine default scheduler policy"); - break; - } - - int prio_min = sched_get_priority_min(sched_policy); - int prio_max = sched_get_priority_max(sched_policy); - if (prio_min == -1 || prio_max == -1) { - // failed to get the scheduling parameters, don't - // bother setting the priority - tqWarning("TQThread: cannot determine scheduler priority range"); - break; - } - - int prio; - switch (priority) { - case IdlePriority: - prio = prio_min; - break; - - case HighestPriority: - prio = prio_max; - break; - - default: - // crudely scale our priority enum values to the prio_min/prio_max - prio = (((prio_max - prio_min) / TimeCriticalPriority) * - priority) + prio_min; - prio = TQMAX(prio_min, TQMIN(prio_max, prio)); - break; - } - - sched_param sp; - sp.sched_priority = prio; - - pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - pthread_attr_setschedparam(&attr, &sp); - break; - } - } -#endif // _POSIX_THREAD_PRIORITY_SCHEDULING - - if ( d->stacksize > 0 ) { -#if defined(_POSIX_THREAD_ATTR_STACKSIZE) && (_POSIX_THREAD_ATTR_STACKSIZE-0 > 0) - ret = pthread_attr_setstacksize( &attr, d->stacksize ); -#else - ret = ENOSYS; // stack size not supported, automatically fail -#endif // _POSIX_THREAD_ATTR_STACKSIZE - - if ( ret ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQThread::start: thread stack size error: %s", strerror( ret ) ) ; -#endif // QT_CHECK_STATE - - // we failed to set the stacksize, and as the documentation states, - // the thread will fail to run... - d->running = FALSE; - d->finished = FALSE; - return; - } - } - - d->args[0] = this; - d->args[1] = d; -#if defined(QT_USE_GLIBMAINLOOP) - // The correct thread_id is set in TQThreadInstance::start using the value of d->args[1] - d->thread_id = 0; - - // glib versions < 2.32.0 requires threading system initialization call - #if GLIB_CHECK_VERSION(2, 32, 0) - GThread* glib_thread_handle = g_thread_new( NULL, (GThreadFunc)TQThreadInstance::start, d->args ); - #else - if( !g_thread_get_initialized() ); - g_thread_init(NULL); - GThread* glib_thread_handle = g_thread_create((GThreadFunc)TQThreadInstance::start, d->args, false, NULL); - #endif - - if (glib_thread_handle) { - ret = 0; - } - else { - ret = -1; - } -#else // QT_USE_GLIBMAINLOOP - ret = pthread_create( &d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args ); -#if defined (Q_OS_HPUX) - if (ret == EPERM) { - pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); - ret = pthread_create(&d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args); - } -#endif - pthread_attr_destroy( &attr ); -#endif // QT_USE_GLIBMAINLOOP - - if ( ret ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQThread::start: thread creation error: %s", strerror( ret ) ); -#endif // QT_CHECK_STATE - - d->running = FALSE; - d->finished = FALSE; - d->args[0] = d->args[1] = 0; - } -} - -void TQThread::start() -{ - start(InheritPriority); -} - -/*! - A thread calling this function will block until either of these - conditions is met: - - \list - \i The thread associated with this TQThread object has finished - execution (i.e. when it returns from \l{run()}). This function - will return TRUE if the thread has finished. It also returns - TRUE if the thread has not been started yet. - \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the - default), then the wait will never timeout (the thread must - return from \l{run()}). This function will return FALSE if the - wait timed out. - \endlist - - This provides similar functionality to the POSIX \c pthread_join() function. -*/ -bool TQThread::wait( unsigned long time ) -{ - TQMutexLocker locker( d->mutex() ); - - if ( pthread_equal( d->thread_id, pthread_self() ) ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQThread::wait: thread tried to wait on itself" ); -#endif // QT_CHECK_STATE - - return FALSE; - } - - if ( d->finished || ! d->running ) { - return TRUE; - } - - int ret; - if (time != ULONG_MAX) { - struct timeval tv; - gettimeofday(&tv, 0); - - timespec ti; - ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; - ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); - ti.tv_nsec %= 1000000000; - - ret = pthread_cond_timedwait(&d->thread_done, &locker.mutex()->d->handle, &ti); - } - else { - ret = pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle); - } - -#ifdef QT_CHECK_RANGE - if (ret && ret != ETIMEDOUT) { - tqWarning("Wait condition wait failure: %s",strerror(ret)); - } -#endif - - return (ret == 0); -} - -/*! - Returns the current cleanup behaviour of the thread. - - \sa setCleanupType - \sa CleanupType -*/ - -TQThread::CleanupType TQThread::cleanupType() const { - return (TQThread::CleanupType)d->cleanupType; -} - -/*! - Sets the current cleanup behaviour of the thread. The default, - TQThread::CleanupMergeObjects, will merge any objects owned by this thread - with the main GUI thread when this thread is terminated. - - If faster thread termination performance is desired, TQThread::CleanupNone - may be specified instead. However, this is not recommended as any objects - owned by this thread on termination can then cause events to become "stuck" - in the global event queue, leading to high CPU usage and other undesirable - behavior. You have been warned! - - \sa cleanupType - \sa CleanupType -*/ - -void TQThread::setCleanupType(CleanupType type) { - d->cleanupType = type; -} - -/*! - Returns a pointer to the currently executing TQThread. If the - current thread was not started using the TQThread API, this - function returns zero. - - Note that TQApplication creates a TQThread object to represent the - main thread; calling this function from main() after creating - TQApplication will return a valid pointer. -*/ -TQThread *TQThread::currentThreadObject() -{ - pthread_once(&storage_key_once, create_storage_key); - return reinterpret_cast(pthread_getspecific(storage_key)); -} - - -#endif // TQT_THREAD_SUPPORT diff --git a/src/kernel/tqobject.cpp b/src/kernel/tqobject.cpp index d50b48e85..3923b46d0 100644 --- a/src/kernel/tqobject.cpp +++ b/src/kernel/tqobject.cpp @@ -53,9 +53,9 @@ #include "tqstyle.h" #ifdef TQT_THREAD_SUPPORT -#include "ntqmutex.h" -#include -#include "ntqthread.h" +#include "tqmutex.h" +#include +#include "tqthread.h" #endif #include diff --git a/src/kernel/tqobject.h b/src/kernel/tqobject.h index 2d72bfa25..cc67ba551 100644 --- a/src/kernel/tqobject.h +++ b/src/kernel/tqobject.h @@ -46,7 +46,7 @@ #include "ntqwindowdefs.h" #include "tqstring.h" #include "ntqevent.h" -#include "ntqmutex.h" +#include "tqmutex.h" #include "ntqnamespace.h" #endif // QT_H diff --git a/src/kernel/tqthread.cpp b/src/kernel/tqthread.cpp new file mode 100644 index 000000000..27b2071ea --- /dev/null +++ b/src/kernel/tqthread.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Cross-platform TQThread implementation. +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifdef TQT_THREAD_SUPPORT + +#include "qplatformdefs.h" + +#include "tqthread.h" +#include "ntqeventloop.h" +#include + +#ifndef QT_H +# include "ntqapplication.h" +#endif // QT_H + + +/*! + \class TQThread tqthread.h + \threadsafe + \brief The TQThread class provides platform-independent threads. + + \ingroup thread + \ingroup environment + + A TQThread represents a separate thread of control within the + program; it shares data with all the other threads within the + process but executes independently in the way that a separate + program does on a multitasking operating system. Instead of + starting in main(), TQThreads begin executing in run(). You inherit + run() to include your code. For example: + + \code + class MyThread : public TQThread { + + public: + + virtual void run(); + + }; + + void MyThread::run() + { + for( int count = 0; count < 20; count++ ) { + sleep( 1 ); + tqDebug( "Ping!" ); + } + } + + int main() + { + MyThread a; + MyThread b; + a.start(); + b.start(); + a.wait(); + b.wait(); + } + \endcode + + This will start two threads, each of which writes Ping! 20 times + to the screen and exits. The wait() calls at the end of main() are + necessary because exiting main() ends the program, unceremoniously + killing all other threads. Each MyThread stops executing when it + reaches the end of MyThread::run(), just as an application does + when it leaves main(). + + \sa \link threads.html Thread Support in TQt\endlink. +*/ + +/*! + \enum TQThread::Priority + + This enum type indicates how the operating system should schedule + newly created threads. + + \value IdlePriority scheduled only when no other threads are + running. + + \value LowestPriority scheduled less often than LowPriority. + \value LowPriority scheduled less often than NormalPriority. + + \value NormalPriority the default priority of the operating + system. + + \value HighPriority scheduled more often than NormalPriority. + \value HighestPriority scheduled more often then HighPriority. + + \value TimeCriticalPriority scheduled as often as possible. + + \value InheritPriority use the same priority as the creating + thread. This is the default. +*/ + +TQThread::TQThread() +{ +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif // TQT_THREAD_SUPPORT + + d = new TQThreadInstance; + d->init(0); +} + +/*! + Constructs a new thread. The thread does not begin executing until + start() is called. + + If \a stackSize is greater than zero, the maximum stack size is + set to \a stackSize bytes, otherwise the maximum stack size is + automatically determined by the operating system. + + \warning Most operating systems place minimum and maximum limits + on thread stack sizes. The thread will fail to start if the stack + size is outside these limits. +*/ +TQThread::TQThread( unsigned int stackSize ) +{ + d = new TQThreadInstance; + d->init(stackSize); +} + +/*! + TQThread destructor. + + Note that deleting a TQThread object will not stop the execution of + the thread it represents. Deleting a running TQThread (i.e. + finished() returns FALSE) will probably result in a program crash. + You can wait() on a thread to make sure that it has finished. +*/ +TQThread::~TQThread() +{ + TQMutexLocker locker( d->mutex() ); + if ( d->running && !d->finished ) { +#ifdef QT_CHECK_STATE + tqWarning("TQThread object destroyed while thread is still running."); +#endif + + d->orphan = TRUE; + return; + } + + d->deinit(); + delete d; +} + +/*! + This function terminates the execution of the thread. The thread + may or may not be terminated immediately, depending on the + operating system's scheduling policies. Use TQThread::wait() + after terminate() for synchronous termination. + + When the thread is terminated, all threads waiting for the + the thread to finish will be woken up. + + \warning This function is dangerous, and its use is discouraged. + The thread can be terminated at any point in its code path. Threads + can be terminated while modifying data. There is no chance for + the thread to cleanup after itself, unlock any held mutexes, etc. + In short, use this function only if \e absolutely necessary. +*/ +void TQThread::terminate() +{ + TQMutexLocker locker( d->mutex() ); + if ( d->finished || !d->running ) + return; + d->terminate(); +} + +/*! + Returns TRUE if the thread is finished; otherwise returns FALSE. +*/ +bool TQThread::finished() const +{ + TQMutexLocker locker( d->mutex() ); + return d->finished; +} + +/*! + Returns TRUE if the thread is running; otherwise returns FALSE. +*/ +bool TQThread::running() const +{ + TQMutexLocker locker( d->mutex() ); + return d->running; +} + +/*! + Changes the way cross thread signals are handled + If disable is FALSE, signals emitted from this thread will be + posted to any other connected threads' event loops (default). + + If disable is TRUE, calls to emit from this thread + will immediately execute slots in another thread. + This mode of operation is inherently unsafe and is provided + solely to support thread management by a third party application. + */ +void TQThread::setThreadPostedEventsDisabled(bool disable) +{ + d->disableThreadPostedEvents = disable; +} + +/*! + Returns TRUE if thread posted events are disabled, FALSE if not + */ +bool TQThread::threadPostedEventsDisabled() const +{ + return d->disableThreadPostedEvents; +} + +/*! + \fn void TQThread::run() + + This method is pure virtual, and must be implemented in derived + classes in order to do useful work. Returning from this method + will end the execution of the thread. + + \sa wait() +*/ + +TQEventLoopThread::TQEventLoopThread() : TQThread() +{ + // +} + +TQEventLoopThread::~TQEventLoopThread() +{ + // +} + +void TQEventLoopThread::run() +{ + TQEventLoop* eventLoop = TQApplication::eventLoop(); + if (eventLoop) eventLoop->exec(); +} + +#endif // TQT_THREAD_SUPPORT diff --git a/src/kernel/tqthread.h b/src/kernel/tqthread.h new file mode 100644 index 000000000..0b38e5a33 --- /dev/null +++ b/src/kernel/tqthread.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Definition of TQThread class +** +** Created : 931107 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQTHREAD_H +#define TQTHREAD_H + +#if defined(TQT_THREAD_SUPPORT) + +#ifndef QT_H +#include "ntqwindowdefs.h" +#endif // QT_H + +#include + +class TQThreadInstance; + +class TQ_EXPORT TQThread : public TQt +{ +public: + static TQt::HANDLE currentThread(); + + static void initialize(); + static void cleanup(); + + static void exit(); + +#ifdef Q_QDOC + TQThread( unsigned int stackSize = 0 ); +#else + TQThread( unsigned int stackSize ); + TQThread(); +#endif + + virtual ~TQThread(); + + // default argument causes thread to block indefinately + bool wait( unsigned long time = ULONG_MAX ); + + enum Priority { + IdlePriority, + + LowestPriority, + LowPriority, + NormalPriority, + HighPriority, + HighestPriority, + + TimeCriticalPriority, + + InheritPriority + }; + +#ifdef Q_QDOC + void start( Priority = InheritPriority ); +#else + void start( Priority ); + void start(); +#endif + + void terminate(); + + bool finished() const; + bool running() const; + + enum CleanupType { + CleanupNone, + CleanupMergeObjects + }; + + CleanupType cleanupType() const; + void setCleanupType(CleanupType); + + bool threadPostedEventsDisabled() const; + void setThreadPostedEventsDisabled(bool); + +protected: + virtual void run() = 0; + + static void sleep( unsigned long ); + static void msleep( unsigned long ); + static void usleep( unsigned long ); + +private: + TQThreadInstance * d; + friend class TQThreadInstance; + friend class TQThreadStorageData; + friend class TQCoreApplicationThread; + friend class TQApplication; + friend class TQEventLoop; + +#if defined(TQ_DISABLE_COPY) + TQThread( const TQThread & ); + TQThread &operator=( const TQThread & ); +#endif // TQ_DISABLE_COPY + +public: + static TQThread* currentThreadObject(); +}; + +class TQ_EXPORT TQEventLoopThread : public TQThread +{ + public: + TQEventLoopThread(); + ~TQEventLoopThread(); + virtual void run(); +}; + +#endif // TQT_THREAD_SUPPORT + +#endif // TQTHREAD_H diff --git a/src/kernel/tqthread_unix.cpp b/src/kernel/tqthread_unix.cpp new file mode 100644 index 000000000..c6662dbeb --- /dev/null +++ b/src/kernel/tqthread_unix.cpp @@ -0,0 +1,569 @@ +/**************************************************************************** +** +** TQThread class for Unix +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#if defined(TQT_THREAD_SUPPORT) + +#include "qplatformdefs.h" + +typedef pthread_mutex_t Q_MUTEX_T; + +#include "tqthread.h" +#include +#include +#include +#include +#include + +#include +#include + +#if defined(QT_USE_GLIBMAINLOOP) +#include +#endif // QT_USE_GLIBMAINLOOP + +static TQMutexPool *qt_thread_mutexpool = 0; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +typedef void*(*TQtThreadCallback)(void*); + +static pthread_once_t storage_key_once = PTHREAD_ONCE_INIT; +static pthread_key_t storage_key; +static void create_storage_key() +{ + pthread_key_create( &storage_key, NULL ); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +/************************************************************************** + ** TQThreadInstance + *************************************************************************/ + +void TQThreadInstance::setCurrentThread(TQThread *thread) +{ + pthread_once(&storage_key_once, create_storage_key); + pthread_setspecific(storage_key, thread); +} + +TQThreadInstance *TQThreadInstance::current() +{ + TQThreadInstance *ret = NULL; + pthread_once( &storage_key_once, create_storage_key ); + TQThread *thread = (TQThread *) pthread_getspecific( storage_key ); + if (thread) { + ret = thread->d; + } + return ret; +} + +void TQThreadInstance::init(unsigned int stackSize) +{ + stacksize = stackSize; + args[0] = args[1] = 0; + thread_storage = 0; + finished = FALSE; + running = FALSE; + orphan = FALSE; + disableThreadPostedEvents = FALSE; + + pthread_cond_init(&thread_done, NULL); + thread_id = 0; + + eventLoop = 0; + cleanupType = TQThread::CleanupMergeObjects; + + // threads have not been initialized yet, do it now + if (! qt_thread_mutexpool) TQThread::initialize(); +} + +void TQThreadInstance::deinit() +{ + pthread_cond_destroy(&thread_done); +} + +void *TQThreadInstance::start( void *_arg ) +{ + void **arg = (void **) _arg; + +#if defined(QT_USE_GLIBMAINLOOP) + // This is the first time we have access to the native pthread ID of this newly created thread + ((TQThreadInstance*)arg[1])->thread_id = pthread_self(); +#endif // QT_USE_GLIBMAINLOOP + +#ifdef QT_DEBUG + tqDebug("TQThreadInstance::start: Setting thread storage to %p\n", (TQThread *) arg[0]); +#endif // QT_DEBUG + setCurrentThread( (TQThread *) arg[0] ); + + pthread_cleanup_push( TQThreadInstance::finish, arg[1] ); + pthread_testcancel(); + + ( (TQThread *) arg[0] )->run(); + + pthread_cleanup_pop( TRUE ); + return 0; +} + +void TQThreadInstance::finish( void * ) +{ + TQThreadInstance *d = current(); + + if ( ! d ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQThread: internal error: zero data for running thread." ); +#endif // QT_CHECK_STATE + return; + } + +#ifdef QT_DEBUG + tqDebug("TQThreadInstance::finish: In TQThreadInstance::finish for thread %p\n", (TQThread*)d->args[0]); +#endif // QT_DEBUG + + TQApplication::threadTerminationHandler((TQThread*)d->args[0]); + + TQMutexLocker locker( d->mutex() ); + d->running = FALSE; + d->finished = TRUE; + d->args[0] = d->args[1] = 0; + + + TQThreadStorageData::finish( d->thread_storage ); + d->thread_storage = 0; + + d->thread_id = 0; + pthread_cond_broadcast(&d->thread_done); + + if (d->orphan) { + d->deinit(); + delete d; + } +} + +void TQThreadInstance::finishGuiThread(TQThreadInstance *d) { + TQThreadStorageData::finish( d->thread_storage ); + d->thread_storage = 0; +} + +TQMutex *TQThreadInstance::mutex() const +{ + return qt_thread_mutexpool ? qt_thread_mutexpool->get( (void *) this ) : 0; +} + +void TQThreadInstance::terminate() +{ + if ( ! thread_id ) return; + pthread_cancel( thread_id ); +} + +/************************************************************************** + ** TQThread + *************************************************************************/ + +/*! + This returns the thread handle of the currently executing thread. + + \warning The handle returned by this function is used for internal + purposes and should \e not be used in any application code. On + Windows, the returned value is a pseudo handle for the current + thread, and it cannot be used for numerical comparison. +*/ +TQt::HANDLE TQThread::currentThread() +{ + return (HANDLE) pthread_self(); +} + +/*! \internal + Initializes the TQThread system. +*/ +void TQThread::initialize() +{ + if ( ! tqt_global_mutexpool ) + tqt_global_mutexpool = new TQMutexPool( TRUE, 73 ); + if ( ! qt_thread_mutexpool ) + qt_thread_mutexpool = new TQMutexPool( FALSE, 127 ); +} + +/*! \internal + Cleans up the TQThread system. +*/ +void TQThread::cleanup() +{ + delete tqt_global_mutexpool; + delete qt_thread_mutexpool; + tqt_global_mutexpool = 0; + qt_thread_mutexpool = 0; +} + +/*! + Ends the execution of the calling thread and wakes up any threads + waiting for its termination. +*/ +void TQThread::exit() +{ + pthread_exit( 0 ); +} + +/* \internal + helper function to do thread sleeps, since usleep()/nanosleep() + aren't reliable enough (in terms of behavior and availability) +*/ +static void thread_sleep( struct timespec *ti ) +{ + pthread_mutex_t mtx; + pthread_cond_t cnd; + + pthread_mutex_init(&mtx, 0); + pthread_cond_init(&cnd, 0); + + pthread_mutex_lock( &mtx ); + (void) pthread_cond_timedwait( &cnd, &mtx, ti ); + pthread_mutex_unlock( &mtx ); + + pthread_cond_destroy( &cnd ); + pthread_mutex_destroy( &mtx ); +} + +/*! + System independent sleep. This causes the current thread to sleep + for \a secs seconds. +*/ +void TQThread::sleep( unsigned long secs ) +{ + struct timeval tv; + gettimeofday( &tv, 0 ); + struct timespec ti; + ti.tv_sec = tv.tv_sec + secs; + ti.tv_nsec = ( tv.tv_usec * 1000 ); + thread_sleep( &ti ); +} + +/*! + System independent sleep. This causes the current thread to sleep + for \a msecs milliseconds +*/ +void TQThread::msleep( unsigned long msecs ) +{ + struct timeval tv; + gettimeofday( &tv, 0 ); + struct timespec ti; + + ti.tv_nsec = ( tv.tv_usec + ( msecs % 1000 ) * 1000 ) * 1000; + ti.tv_sec = tv.tv_sec + ( msecs / 1000 ) + ( ti.tv_nsec / 1000000000 ); + ti.tv_nsec %= 1000000000; + thread_sleep( &ti ); +} + +/*! + System independent sleep. This causes the current thread to sleep + for \a usecs microseconds +*/ +void TQThread::usleep( unsigned long usecs ) +{ + struct timeval tv; + gettimeofday( &tv, 0 ); + struct timespec ti; + + ti.tv_nsec = ( tv.tv_usec + ( usecs % 1000000 ) ) * 1000; + ti.tv_sec = tv.tv_sec + ( usecs / 1000000 ) + ( ti.tv_nsec / 1000000000 ); + ti.tv_nsec %= 1000000000; + thread_sleep( &ti ); +} + +/*! + Begins execution of the thread by calling run(), which should be + reimplemented in a TQThread subclass to contain your code. The + operating system will schedule the thread according to the \a + priority argument. + + If you try to start a thread that is already running, this + function will wait until the the thread has finished and then + restart the thread. + + \sa Priority +*/ +void TQThread::start(Priority priority) +{ + TQMutexLocker locker( d->mutex() ); + + if ( d->running ) + pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle); + d->running = TRUE; + d->finished = FALSE; + + int ret; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + +#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0) +#if _POSIX_THREAD_PRIORITY_SCHEDULING == 0 && defined _SC_THREAD_PRIORITY_SCHEDULING + if (sysconf(_SC_THREAD_PRIORITY_SCHEDULING) > 0) +#endif + switch (priority) { + case InheritPriority: + { + pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); + break; + } + + default: + { + int sched_policy; + if (pthread_attr_getschedpolicy(&attr, &sched_policy) != 0) { + // failed to get the scheduling policy, don't bother + // setting the priority + tqWarning("TQThread: cannot determine default scheduler policy"); + break; + } + + int prio_min = sched_get_priority_min(sched_policy); + int prio_max = sched_get_priority_max(sched_policy); + if (prio_min == -1 || prio_max == -1) { + // failed to get the scheduling parameters, don't + // bother setting the priority + tqWarning("TQThread: cannot determine scheduler priority range"); + break; + } + + int prio; + switch (priority) { + case IdlePriority: + prio = prio_min; + break; + + case HighestPriority: + prio = prio_max; + break; + + default: + // crudely scale our priority enum values to the prio_min/prio_max + prio = (((prio_max - prio_min) / TimeCriticalPriority) * + priority) + prio_min; + prio = TQMAX(prio_min, TQMIN(prio_max, prio)); + break; + } + + sched_param sp; + sp.sched_priority = prio; + + pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_setschedparam(&attr, &sp); + break; + } + } +#endif // _POSIX_THREAD_PRIORITY_SCHEDULING + + if ( d->stacksize > 0 ) { +#if defined(_POSIX_THREAD_ATTR_STACKSIZE) && (_POSIX_THREAD_ATTR_STACKSIZE-0 > 0) + ret = pthread_attr_setstacksize( &attr, d->stacksize ); +#else + ret = ENOSYS; // stack size not supported, automatically fail +#endif // _POSIX_THREAD_ATTR_STACKSIZE + + if ( ret ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQThread::start: thread stack size error: %s", strerror( ret ) ) ; +#endif // QT_CHECK_STATE + + // we failed to set the stacksize, and as the documentation states, + // the thread will fail to run... + d->running = FALSE; + d->finished = FALSE; + return; + } + } + + d->args[0] = this; + d->args[1] = d; +#if defined(QT_USE_GLIBMAINLOOP) + // The correct thread_id is set in TQThreadInstance::start using the value of d->args[1] + d->thread_id = 0; + + // glib versions < 2.32.0 requires threading system initialization call + #if GLIB_CHECK_VERSION(2, 32, 0) + GThread* glib_thread_handle = g_thread_new( NULL, (GThreadFunc)TQThreadInstance::start, d->args ); + #else + if( !g_thread_get_initialized() ); + g_thread_init(NULL); + GThread* glib_thread_handle = g_thread_create((GThreadFunc)TQThreadInstance::start, d->args, false, NULL); + #endif + + if (glib_thread_handle) { + ret = 0; + } + else { + ret = -1; + } +#else // QT_USE_GLIBMAINLOOP + ret = pthread_create( &d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args ); +#if defined (Q_OS_HPUX) + if (ret == EPERM) { + pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); + ret = pthread_create(&d->thread_id, &attr, (TQtThreadCallback)TQThreadInstance::start, d->args); + } +#endif + pthread_attr_destroy( &attr ); +#endif // QT_USE_GLIBMAINLOOP + + if ( ret ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQThread::start: thread creation error: %s", strerror( ret ) ); +#endif // QT_CHECK_STATE + + d->running = FALSE; + d->finished = FALSE; + d->args[0] = d->args[1] = 0; + } +} + +void TQThread::start() +{ + start(InheritPriority); +} + +/*! + A thread calling this function will block until either of these + conditions is met: + + \list + \i The thread associated with this TQThread object has finished + execution (i.e. when it returns from \l{run()}). This function + will return TRUE if the thread has finished. It also returns + TRUE if the thread has not been started yet. + \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the + default), then the wait will never timeout (the thread must + return from \l{run()}). This function will return FALSE if the + wait timed out. + \endlist + + This provides similar functionality to the POSIX \c pthread_join() function. +*/ +bool TQThread::wait( unsigned long time ) +{ + TQMutexLocker locker( d->mutex() ); + + if ( pthread_equal( d->thread_id, pthread_self() ) ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQThread::wait: thread tried to wait on itself" ); +#endif // QT_CHECK_STATE + + return FALSE; + } + + if ( d->finished || ! d->running ) { + return TRUE; + } + + int ret; + if (time != ULONG_MAX) { + struct timeval tv; + gettimeofday(&tv, 0); + + timespec ti; + ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; + ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); + ti.tv_nsec %= 1000000000; + + ret = pthread_cond_timedwait(&d->thread_done, &locker.mutex()->d->handle, &ti); + } + else { + ret = pthread_cond_wait(&d->thread_done, &locker.mutex()->d->handle); + } + +#ifdef QT_CHECK_RANGE + if (ret && ret != ETIMEDOUT) { + tqWarning("Wait condition wait failure: %s",strerror(ret)); + } +#endif + + return (ret == 0); +} + +/*! + Returns the current cleanup behaviour of the thread. + + \sa setCleanupType + \sa CleanupType +*/ + +TQThread::CleanupType TQThread::cleanupType() const { + return (TQThread::CleanupType)d->cleanupType; +} + +/*! + Sets the current cleanup behaviour of the thread. The default, + TQThread::CleanupMergeObjects, will merge any objects owned by this thread + with the main GUI thread when this thread is terminated. + + If faster thread termination performance is desired, TQThread::CleanupNone + may be specified instead. However, this is not recommended as any objects + owned by this thread on termination can then cause events to become "stuck" + in the global event queue, leading to high CPU usage and other undesirable + behavior. You have been warned! + + \sa cleanupType + \sa CleanupType +*/ + +void TQThread::setCleanupType(CleanupType type) { + d->cleanupType = type; +} + +/*! + Returns a pointer to the currently executing TQThread. If the + current thread was not started using the TQThread API, this + function returns zero. + + Note that TQApplication creates a TQThread object to represent the + main thread; calling this function from main() after creating + TQApplication will return a valid pointer. +*/ +TQThread *TQThread::currentThreadObject() +{ + pthread_once(&storage_key_once, create_storage_key); + return reinterpret_cast(pthread_getspecific(storage_key)); +} + + +#endif // TQT_THREAD_SUPPORT diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index 8dfda823c..d5419c8d0 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -57,7 +57,7 @@ #include "ntqmetaobject.h" #include "ntqguardedptr.h" #if defined(TQT_THREAD_SUPPORT) -#include "ntqthread.h" +#include "tqthread.h" #endif #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index 3ce552ebd..9f1610620 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_STYLE -#include "ntqmutex.h" +#include "tqmutex.h" #include "ntqmenubar.h" #include "ntqapplication.h" #include "ntqpainter.h" diff --git a/src/tools/ntqmutex.h b/src/tools/ntqmutex.h deleted file mode 100644 index c517c6355..000000000 --- a/src/tools/ntqmutex.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Definition of TQMutex class -** -** Created : 931107 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMUTEX_H -#define TQMUTEX_H - -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H - -#if defined(TQT_THREAD_SUPPORT) - -class TQMutexPrivate; - -const int Q_MUTEX_NORMAL = 0; -const int Q_MUTEX_RECURSIVE = 1; - -class TQ_EXPORT TQMutex -{ - friend class TQThread; - friend class TQWaitCondition; - friend class TQWaitConditionPrivate; - -public: - TQMutex(bool recursive = FALSE); - virtual ~TQMutex(); - - void lock(); - void unlock(); - bool locked(); - bool tryLock(); - -private: - TQMutexPrivate * d; - -#if defined(TQ_DISABLE_COPY) - TQMutex( const TQMutex & ); - TQMutex &operator=( const TQMutex & ); -#endif - -public: - int level(); -}; - -class TQ_EXPORT TQMutexLocker -{ -public: - TQMutexLocker( TQMutex * ); - ~TQMutexLocker(); - - TQMutex *mutex() const; - -private: - TQMutex *mtx; - -#if defined(TQ_DISABLE_COPY) - TQMutexLocker( const TQMutexLocker & ); - TQMutexLocker &operator=( const TQMutexLocker & ); -#endif -}; - -inline TQMutexLocker::TQMutexLocker( TQMutex *m ) - : mtx( m ) -{ - if ( mtx ) mtx->lock(); -} - -inline TQMutexLocker::~TQMutexLocker() -{ - if ( mtx ) mtx->unlock(); -} - -inline TQMutex *TQMutexLocker::mutex() const -{ - return mtx; -} - -#endif - -#endif diff --git a/src/tools/ntqsemaphore.h b/src/tools/ntqsemaphore.h deleted file mode 100644 index 0dc8e81de..000000000 --- a/src/tools/ntqsemaphore.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSemaphore class -** -** Created : 931107 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQSEMAPHORE_H -#define TQSEMAPHORE_H - -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H - -#if defined(TQT_THREAD_SUPPORT) - -class TQSemaphorePrivate; - -class TQ_EXPORT TQSemaphore -{ -public: - TQSemaphore( int ); - virtual ~TQSemaphore(); - - int available() const; - int total() const; - - // postfix operators - int operator++(int); - int operator--(int); - - int operator+=(int); - int operator-=(int); - - bool tryAccess(int); - -private: - TQSemaphorePrivate *d; - -#if defined(TQ_DISABLE_COPY) - TQSemaphore(const TQSemaphore &); - TQSemaphore &operator=(const TQSemaphore &); -#endif -}; - -#endif - -#endif diff --git a/src/tools/ntqthreadstorage.h b/src/tools/ntqthreadstorage.h deleted file mode 100644 index 588621237..000000000 --- a/src/tools/ntqthreadstorage.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQTHREADSTORAGE_H -#define TQTHREADSTORAGE_H - -#ifdef TQT_THREAD_SUPPORT - -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H - -class TQ_EXPORT TQThreadStorageData -{ -public: - TQThreadStorageData( void (*func)(void *) ); - ~TQThreadStorageData(); - - void** get() const; - void** set( void* p ); - - static void finish( void** ); - int id; -}; - - -template -class TQThreadStorage -{ -private: - TQThreadStorageData d; - -#if defined(TQ_DISABLE_COPY) - // disable copy constructor and operator= - TQThreadStorage( const TQThreadStorage & ); - TQThreadStorage &operator=( const TQThreadStorage & ); -#endif // TQ_DISABLE_COPY - - static void deleteData( void *x ) { delete (T)x; } - -public: - inline TQThreadStorage() : d( deleteData ) { } - inline ~TQThreadStorage() { } - - inline bool hasLocalData() const - { return d.get() != 0; } - - inline T& localData() - { void **v = d.get(); if ( !v ) v = d.set( 0 ); return *(T*)v; } - - inline T localData() const - { void **v = d.get(); return ( v ? *(T*)v : 0 ); } - - inline void setLocalData( T t ) - { (void) d.set( t ); } -}; - -#endif // TQT_THREAD_SUPPORT - -#endif // TQTHREADSTORAGE_H diff --git a/src/tools/ntqwaitcondition.h b/src/tools/ntqwaitcondition.h deleted file mode 100644 index 503d5d6c9..000000000 --- a/src/tools/ntqwaitcondition.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Definition of TQWaitCondition class -** -** Created : 931107 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQWAITCONDITION_H -#define TQWAITCONDITION_H - -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H - -#if defined(TQT_THREAD_SUPPORT) - -#include - -class TQWaitConditionPrivate; -class TQMutex; - -class TQ_EXPORT TQWaitCondition -{ -public: - TQWaitCondition(); - virtual ~TQWaitCondition(); - - // default argument causes thread to block indefinately - bool wait( unsigned long time = ULONG_MAX ); - bool wait( TQMutex *mutex, unsigned long time = ULONG_MAX ); - - void wakeOne(); - void wakeAll(); - -private: - TQWaitConditionPrivate * d; - -#if defined(TQ_DISABLE_COPY) - TQWaitCondition( const TQWaitCondition & ); - TQWaitCondition &operator=( const TQWaitCondition & ); -#endif -}; - -#endif - -#endif diff --git a/src/tools/qcomlibrary.cpp b/src/tools/qcomlibrary.cpp index 27ffbb8ce..cc7647da9 100644 --- a/src/tools/qcomlibrary.cpp +++ b/src/tools/qcomlibrary.cpp @@ -49,7 +49,7 @@ #endif // NO_ERROR_H #ifdef TQT_THREAD_SUPPORT -# include "qmutexpool_p.h" +# include "tqmutexpool_p.h" #endif // TQT_THREAD_SUPPORT #ifndef QT_DEBUG_COMPONENT diff --git a/src/tools/qcstring.cpp b/src/tools/qcstring.cpp index 80381e8b9..d35b06e3e 100644 --- a/src/tools/qcstring.cpp +++ b/src/tools/qcstring.cpp @@ -44,7 +44,7 @@ #include "ntqdatastream.h" #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/tools/qdir_unix.cpp b/src/tools/qdir_unix.cpp index 19e03e642..8019d7b16 100644 --- a/src/tools/qdir_unix.cpp +++ b/src/tools/qdir_unix.cpp @@ -49,7 +49,7 @@ #include "tqstringlist.h" #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #include diff --git a/src/tools/qgarray.cpp b/src/tools/qgarray.cpp index ff1f7b08b..1470d100e 100644 --- a/src/tools/qgarray.cpp +++ b/src/tools/qgarray.cpp @@ -53,7 +53,7 @@ #include #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT /* diff --git a/src/tools/qglist.cpp b/src/tools/qglist.cpp index 1afa67b41..95e66b38f 100644 --- a/src/tools/qglist.cpp +++ b/src/tools/qglist.cpp @@ -44,7 +44,7 @@ #include "tqvaluelist.h" #if defined(TQT_THREAD_SUPPORT) - #include "ntqmutex.h" + #include "tqmutex.h" #endif // defined(TQT_THREAD_SUPPORT) /*! diff --git a/src/tools/qgvector.cpp b/src/tools/qgvector.cpp index 81b7a2006..1c6c8669e 100644 --- a/src/tools/qgvector.cpp +++ b/src/tools/qgvector.cpp @@ -52,7 +52,7 @@ #include #ifdef TQT_THREAD_SUPPORT -# include +# include #endif // TQT_THREAD_SUPPORT #define USE_MALLOC // comment to use new/delete diff --git a/src/tools/qlocale.cpp b/src/tools/qlocale.cpp index d7716a1a7..fc02f8ef2 100644 --- a/src/tools/qlocale.cpp +++ b/src/tools/qlocale.cpp @@ -48,8 +48,8 @@ #include "ntqnamespace.h" #ifdef QT_QLOCALE_USES_FCVT -# include -# include +# include +# include #endif #if defined (Q_OS_WIN) diff --git a/src/tools/qmutex_p.h b/src/tools/qmutex_p.h deleted file mode 100644 index 3e9de8e5c..000000000 --- a/src/tools/qmutex_p.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** TQMutex private class declarations -** -** Created : 20012507 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMUTEX_P_H -#define TQMUTEX_P_H - -#ifndef QT_H -#endif // QT_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of qmutex_unix.cpp and qmutex_win.cpp. This header file may change -// from version to version without notice, or even be removed. -// -// We mean it. -// - -class TQMutexPrivate { -public: - // Q_MUTEX_T is defined in the various *.cpp files - Q_MUTEX_T handle; - - virtual ~TQMutexPrivate(); - - virtual void lock() = 0; - virtual void unlock() = 0; - virtual bool locked() = 0; - virtual bool trylock() = 0; - virtual int type() const = 0; - virtual int level() = 0; -}; - - -#endif // TQMUTEX_P_H diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp deleted file mode 100644 index 597d3e628..000000000 --- a/src/tools/qmutex_unix.cpp +++ /dev/null @@ -1,535 +0,0 @@ -/**************************************************************************** -** -** TQMutex class for Unix -** -** Created : 20010725 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#if defined(TQT_THREAD_SUPPORT) - -#include "qplatformdefs.h" - -typedef pthread_mutex_t Q_MUTEX_T; - -#if defined(QT_CHECK_RANGE) -# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK -#else -# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT -#endif -#define Q_RECURSIVE_MUTEX_TYPE PTHREAD_MUTEX_RECURSIVE - -#include "ntqmutex.h" -#include "qmutex_p.h" - -#include -#include - -// Private class declarations - -class TQRealMutexPrivate : public TQMutexPrivate { -public: - TQRealMutexPrivate(bool = FALSE); - - void lock(); - void unlock(); - bool locked(); - bool trylock(); - int type() const; - int level(); - - bool recursive; - int count; -}; - - -// Private class implementation - -// base destructor -TQMutexPrivate::~TQMutexPrivate() -{ - int ret = pthread_mutex_destroy(&handle); - -#ifdef QT_CHECK_RANGE - if ( ret ) - tqWarning( "Mutex destroy failure: %s", strerror( ret ) ); -#endif -} - -// real mutex class -TQRealMutexPrivate::TQRealMutexPrivate(bool recurs) - : recursive(recurs), count(0) -{ - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, recursive ? Q_RECURSIVE_MUTEX_TYPE : Q_NORMAL_MUTEX_TYPE); - int ret = pthread_mutex_init(&handle, &attr); - pthread_mutexattr_destroy(&attr); - -#ifdef QT_CHECK_RANGE - if( ret ) - tqWarning( "Mutex init failure: %s", strerror( ret ) ); -#endif // QT_CHECK_RANGE -} - -void TQRealMutexPrivate::lock() -{ - int ret = pthread_mutex_lock(&handle); - - if (!ret) { - count++; - } else { -#ifdef QT_CHECK_RANGE - tqWarning("Mutex lock failure: %s", strerror(ret)); -#endif - } -} - -void TQRealMutexPrivate::unlock() -{ - count--; - int ret = pthread_mutex_unlock(&handle); - - if (ret) { - count++; -#ifdef QT_CHECK_RANGE - tqWarning("Mutex unlock failure: %s", strerror(ret)); -#endif - } -} - -bool TQRealMutexPrivate::locked() -{ - return count > 0; -} - -bool TQRealMutexPrivate::trylock() -{ - int ret = pthread_mutex_trylock(&handle); - - if (ret == EBUSY) { - return FALSE; - } else if (ret) { -#ifdef QT_CHECK_RANGE - tqWarning("Mutex trylock failure: %s", strerror(ret)); -#endif - return FALSE; - } - - return TRUE; -} - -int TQRealMutexPrivate::type() const -{ - return recursive ? Q_MUTEX_RECURSIVE : Q_MUTEX_NORMAL; -} - -int TQRealMutexPrivate::level() -{ - return count; -} - - -/*! - \class TQMutex ntqmutex.h - \threadsafe - \brief The TQMutex class provides access serialization between threads. - - \ingroup thread - \ingroup environment - - The purpose of a TQMutex is to protect an object, data structure or - section of code so that only one thread can access it at a time - (This is similar to the Java \c synchronized keyword). For - example, say there is a method which prints a message to the user - on two lines: - - \code - int number = 6; - - void method1() - { - number *= 5; - number /= 4; - } - - void method2() - { - number *= 3; - number /= 2; - } - \endcode - - If these two methods are called in succession, the following happens: - - \code - // method1() - number *= 5; // number is now 30 - number /= 4; // number is now 7 - - // method2() - number *= 3; // nubmer is now 21 - number /= 2; // number is now 10 - \endcode - - If these two methods are called simultaneously from two threads then the - following sequence could result: - - \code - // Thread 1 calls method1() - number *= 5; // number is now 30 - - // Thread 2 calls method2(). - // - // Most likely Thread 1 has been put to sleep by the operating - // system to allow Thread 2 to run. - number *= 3; // number is now 90 - number /= 2; // number is now 45 - - // Thread 1 finishes executing. - number /= 4; // number is now 11, instead of 10 - \endcode - - If we add a mutex, we should get the result we want: - - \code - TQMutex mutex; - int number = 6; - - void method1() - { - mutex.lock(); - number *= 5; - number /= 4; - mutex.unlock(); - } - - void method2() - { - mutex.lock(); - number *= 3; - number /= 2; - mutex.unlock(); - } - \endcode - - Then only one thread can modify \c number at any given time and - the result is correct. This is a trivial example, of course, but - applies to any other case where things need to happen in a - particular sequence. - - When you call lock() in a thread, other threads that try to call - lock() in the same place will block until the thread that got the - lock calls unlock(). A non-blocking alternative to lock() is - tryLock(). -*/ - -/*! - Constructs a new mutex. The mutex is created in an unlocked state. - A recursive mutex is created if \a recursive is TRUE; a normal - mutex is created if \a recursive is FALSE (the default). With a - recursive mutex, a thread can lock the same mutex multiple times - and it will not be unlocked until a corresponding number of - unlock() calls have been made. -*/ -TQMutex::TQMutex(bool recursive) -{ - d = new TQRealMutexPrivate(recursive); -} - -/*! - Destroys the mutex. - - \warning If you destroy a mutex that still holds a lock the - resultant behavior is undefined. -*/ -TQMutex::~TQMutex() -{ - delete d; -} - -/*! - Attempt to lock the mutex. If another thread has locked the mutex - then this call will \e block until that thread has unlocked it. - - \sa unlock(), locked() -*/ -void TQMutex::lock() -{ - d->lock(); -} - -/*! - Unlocks the mutex. Attempting to unlock a mutex in a different - thread to the one that locked it results in an error. Unlocking a - mutex that is not locked results in undefined behaviour (varies - between different Operating Systems' thread implementations). - - \sa lock(), locked() -*/ -void TQMutex::unlock() -{ - d->unlock(); -} - -/*! - Returns TRUE if the mutex is locked by another thread; otherwise - returns FALSE. - - \warning Due to differing implementations of recursive mutexes on - various platforms, calling this function from the same thread that - previously locked the mutex will return undefined results. - - \sa lock(), unlock() -*/ -bool TQMutex::locked() -{ - return d->locked(); -} - -/*! - Attempt to lock the mutex. If the lock was obtained, this function - returns TRUE. If another thread has locked the mutex, this - function returns FALSE, instead of waiting for the mutex to become - available, i.e. it does not block. - - If the lock was obtained, the mutex must be unlocked with unlock() - before another thread can successfully lock it. - - \sa lock(), unlock(), locked() -*/ -bool TQMutex::tryLock() -{ - return d->trylock(); -} - -/*! - Returns the current lock level of the mutex. - 0 means the mutex is unlocked - This method should only be called when the mutex has already been locked - by lock(), otherwise the lock level could change before the next line - of code is executed. - - WARNING: Non-recursive mutexes will never exceed a lock level of 1! - - \sa lock(), unlock(), locked() -*/ -int TQMutex::level() -{ - return d->level(); -} - -/*! - \class TQMutexLocker ntqmutex.h - \brief The TQMutexLocker class simplifies locking and unlocking TQMutexes. - - \threadsafe - - \ingroup thread - \ingroup environment - - The purpose of TQMutexLocker is to simplify TQMutex locking and - unlocking. Locking and unlocking a TQMutex in complex functions and - statements or in exception handling code is error prone and - difficult to debug. TQMutexLocker should be used in such situations - to ensure that the state of the mutex is well defined and always - locked and unlocked properly. - - TQMutexLocker should be created within a function where a TQMutex - needs to be locked. The mutex is locked when TQMutexLocker is - created, and unlocked when TQMutexLocker is destroyed. - - For example, this complex function locks a TQMutex upon entering - the function and unlocks the mutex at all the exit points: - - \code - int complexFunction( int flag ) - { - mutex.lock(); - - int return_value = 0; - - switch ( flag ) { - case 0: - case 1: - { - mutex.unlock(); - return moreComplexFunction( flag ); - } - - case 2: - { - int status = anotherFunction(); - if ( status < 0 ) { - mutex.unlock(); - return -2; - } - return_value = status + flag; - break; - } - - default: - { - if ( flag > 10 ) { - mutex.unlock(); - return -1; - } - break; - } - } - - mutex.unlock(); - return return_value; - } - \endcode - - This example function will get more complicated as it is - developed, which increases the likelihood that errors will occur. - - Using TQMutexLocker greatly simplifies the code, and makes it more - readable: - - \code - int complexFunction( int flag ) - { - TQMutexLocker locker( &mutex ); - - int return_value = 0; - - switch ( flag ) { - case 0: - case 1: - { - return moreComplexFunction( flag ); - } - - case 2: - { - int status = anotherFunction(); - if ( status < 0 ) - return -2; - return_value = status + flag; - break; - } - - default: - { - if ( flag > 10 ) - return -1; - break; - } - } - - return return_value; - } - \endcode - - Now, the mutex will always be unlocked when the TQMutexLocker - object is destroyed (when the function returns since \c locker is - an auto variable). Note that the mutex will be unlocked after - the call to moreComplexFunction() in this example, avoiding - possible bugs caused by unlocking the mutex too early, as in - the first example. - - The same principle applies to code that throws and catches - exceptions. An exception that is not caught in the function that - has locked the mutex has no way of unlocking the mutex before the - exception is passed up the stack to the calling function. - - TQMutexLocker also provides a mutex() member function that returns - the mutex on which the TQMutexLocker is operating. This is useful - for code that needs access to the mutex, such as - TQWaitCondition::wait(). For example: - - \code - class SignalWaiter - { - private: - TQMutexLocker locker; - - public: - SignalWaiter( TQMutex *mutex ) - : locker( mutex ) - { - } - - void waitForSignal() - { - ... - ... - ... - - while ( ! signalled ) - waitcondition.wait( locker.mutex() ); - - ... - ... - ... - } - }; - \endcode - - \sa TQMutex, TQWaitCondition -*/ - -/*! - \fn TQMutexLocker::TQMutexLocker( TQMutex *mutex ) - - Constructs a TQMutexLocker and locks \a mutex. The mutex will be - unlocked when the TQMutexLocker is destroyed. If \a mutex is zero, - TQMutexLocker does nothing. - - \sa TQMutex::lock() -*/ - -/*! - \fn TQMutexLocker::~TQMutexLocker() - - Destroys the TQMutexLocker and unlocks the mutex which was locked - in the constructor. - - \sa TQMutexLocker::TQMutexLocker(), TQMutex::unlock() -*/ - -/*! - \fn TQMutex *TQMutexLocker::mutex() const - - Returns a pointer to the mutex which was locked in the - constructor. - - \sa TQMutexLocker::TQMutexLocker() -*/ - -#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/qmutexpool.cpp b/src/tools/qmutexpool.cpp deleted file mode 100644 index 72c66c8ca..000000000 --- a/src/tools/qmutexpool.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qmutexpool_p.h" - -#ifdef TQT_THREAD_SUPPORT - -#include - -TQ_EXPORT TQMutexPool *tqt_global_mutexpool = 0; - - -/*! - \class TQMutexPool qmutexpool_p.h - \brief The TQMutexPool class provides a pool of TQMutex objects. - - \internal - - \ingroup thread - - TQMutexPool is a convenience class that provides access to a fixed - number of TQMutex objects. - - Typical use of a TQMutexPool is in situations where it is not - possible or feasible to use one TQMutex for every protected object. - The mutex pool will return a mutex based on the address of the - object that needs protection. - - For example, consider this simple class: - - \code - class Number { - public: - Number( double n ) : num ( n ) { } - - void setNumber( double n ) { num = n; } - double number() const { return num; } - - private: - double num; - }; - \endcode - - Adding a TQMutex member to the Number class does not make sense, - because it is so small. However, in order to ensure that access to - each Number is protected, you need to use a mutex. In this case, a - TQMutexPool would be ideal. - - Code to calculate the square of a number would then look something - like this: - - \code - void calcSquare( Number *num ) - { - TQMutexLocker locker( mutexpool.get( num ) ); - num.setNumber( num.number() * num.number() ); - } - \endcode - - This function will safely calculate the square of a number, since - it uses a mutex from a TQMutexPool. The mutex is locked and - unlocked automatically by the TQMutexLocker class. See the - TQMutexLocker documentation for more details. -*/ - -/*! - Constructs a TQMutexPool, reserving space for \a size TQMutexes. If - \a recursive is TRUE, all TQMutexes in the pool will be recursive - mutexes; otherwise they will all be non-recursive (the default). - - The TQMutexes are created when needed, and deleted when the - TQMutexPool is destructed. -*/ -TQMutexPool::TQMutexPool( bool recursive, int size ) - : mutex( FALSE ), count( size ), recurs( recursive ) -{ - mutexes = new TQMutex*[count]; - for ( int index = 0; index < count; ++index ) { - mutexes[index] = 0; - } -} - -/*! - Destructs a TQMutexPool. All TQMutexes that were created by the pool - are deleted. -*/ -TQMutexPool::~TQMutexPool() -{ - TQMutexLocker locker( &mutex ); - for ( int index = 0; index < count; ++index ) { - delete mutexes[index]; - mutexes[index] = 0; - } - delete [] mutexes; - mutexes = 0; -} - -/*! - Returns a TQMutex from the pool. TQMutexPool uses the value \a - address to determine which mutex is retured from the pool. -*/ -TQMutex *TQMutexPool::get( void *address ) -{ - int index = (int) ( (unsigned long) address % count ); - - if ( ! mutexes[index] ) { - // mutex not created, create one - - TQMutexLocker locker( &mutex ); - // we need to check once again that the mutex hasn't been created, since - // 2 threads could be trying to create a mutex as the same index... - if ( ! mutexes[index] ) { - mutexes[index] = new TQMutex( recurs ); - } - } - - return mutexes[index]; -} - -#endif diff --git a/src/tools/qmutexpool_p.h b/src/tools/qmutexpool_p.h deleted file mode 100644 index a0bb28562..000000000 --- a/src/tools/qmutexpool_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMUTEXPOOL_P_H -#define TQMUTEXPOOL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of TQSettings. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// -// - -#ifdef TQT_THREAD_SUPPORT - -#ifndef QT_H -#include "ntqmutex.h" -#include "ntqmemarray.h" -#endif // QT_H - -class TQ_EXPORT TQMutexPool -{ -public: - TQMutexPool( bool recursive = FALSE, int size = 17 ); - ~TQMutexPool(); - - TQMutex *get( void *address ); - -private: - TQMutex mutex; - TQMutex **mutexes; - int count; - bool recurs; -}; - -extern TQ_EXPORT TQMutexPool *tqt_global_mutexpool; - -#endif // TQT_THREAD_SUPPORT - -#endif // TQMUTEXPOOL_P_H diff --git a/src/tools/qregexp.cpp b/src/tools/qregexp.cpp index 612e31194..e6447cdf1 100644 --- a/src/tools/qregexp.cpp +++ b/src/tools/qregexp.cpp @@ -53,8 +53,8 @@ #include "ntqtl.h" #ifdef TQT_THREAD_SUPPORT -#include "ntqthreadstorage.h" -#include +#include "tqthreadstorage.h" +#include #endif // TQT_THREAD_SUPPORT #undef TQT_TRANSLATE_NOOP diff --git a/src/tools/qsemaphore.cpp b/src/tools/qsemaphore.cpp deleted file mode 100644 index 810837b4c..000000000 --- a/src/tools/qsemaphore.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** -** -** TQSemaphore class for Unix -** -** Created : 20010725 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#if defined(TQT_THREAD_SUPPORT) - -#include "ntqsemaphore.h" -#include "ntqmutex.h" -#include "ntqwaitcondition.h" - - -/*! - \class TQSemaphore ntqsemaphore.h - \threadsafe - \brief The TQSemaphore class provides a robust integer semaphore. - - \ingroup thread - \ingroup environment - - A TQSemaphore can be used to serialize thread execution, in a - similar way to a TQMutex. A semaphore differs from a mutex, in - that a semaphore can be accessed by more than one thread at a - time. - - For example, suppose we have an application that stores data in a - large tree structure. The application creates 10 threads - (commonly called a thread pool) to perform searches on the tree. - When the application searches the tree for some piece of data, it - uses one thread per base node to do the searching. A semaphore - could be used to make sure that two threads don't try to search - the same branch of the tree at the same time. - - A non-computing example of a semaphore would be dining at a - restuarant. A semaphore is initialized to have a maximum count - equal to the number of chairs in the restuarant. As people - arrive, they want a seat. As seats are filled, the semaphore is - accessed, once per person. As people leave, the access is - released, allowing more people to enter. If a party of 10 people - want to be seated, but there are only 9 seats, those 10 people - will wait, but a party of 4 people would be seated (taking the - available seats to 5, making the party of 10 people wait longer). - - When a semaphore is created it is given a number which is the - maximum number of concurrent accesses it will permit. Accesses to - the sempahore are gained using operator++() or operator+=(), and - released with operator--() or operator-=(). The number of - accesses allowed is retrieved with available(), and the total - number with total(). Note that the incrementing functions will - block if there aren't enough available accesses. Use tryAccess() - if you want to acquire accesses without blocking. -*/ - - -class TQSemaphorePrivate { -public: - TQSemaphorePrivate(int); - - TQMutex mutex; - TQWaitCondition cond; - - int value, max; -}; - - -TQSemaphorePrivate::TQSemaphorePrivate(int m) - : mutex(FALSE), value(0), max(m) -{ -} - - -/*! - Creates a new semaphore. The semaphore can be concurrently - accessed at most \a maxcount times. -*/ -TQSemaphore::TQSemaphore(int maxcount) -{ - d = new TQSemaphorePrivate(maxcount); -} - - -/*! - Destroys the semaphore. - - \warning If you destroy a semaphore that has accesses in use the - resultant behavior is undefined. -*/ -TQSemaphore::~TQSemaphore() -{ - delete d; -} - - -/*! - Postfix ++ operator. - - Try to get access to the semaphore. If \l available() == 0, this - call will block until it can get access, i.e. until available() \> - 0. -*/ -int TQSemaphore::operator++(int) -{ - TQMutexLocker locker(&d->mutex); - while (d->value >= d->max) - d->cond.wait(locker.mutex()); - - ++d->value; - if (d->value > d->max) - d->value = d->max; - - return d->value; -} - - -/*! - Postfix -- operator. - - Release access of the semaphore. This wakes all threads waiting - for access to the semaphore. -*/ -int TQSemaphore::operator--(int) -{ - TQMutexLocker locker(&d->mutex); - - --d->value; - if (d->value < 0) - d->value = 0; - - d->cond.wakeAll(); - - return d->value; -} - - -/*! - Try to get access to the semaphore. If \l available() \< \a n, this - call will block until it can get all the accesses it wants, i.e. - until available() \>= \a n. -*/ -int TQSemaphore::operator+=(int n) -{ - TQMutexLocker locker(&d->mutex); - - if ( n < 0 || n > d->max ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQSemaphore::operator+=: paramter %d out of range", n ); -#endif // QT_CHECK_RANGE - n = n < 0 ? 0 : d->max; - } - - while (d->value + n > d->max) - d->cond.wait(locker.mutex()); - - d->value += n; - - return d->value; -} - - -/*! - Release \a n accesses to the semaphore. -*/ -int TQSemaphore::operator-=(int n) -{ - TQMutexLocker locker(&d->mutex); - - if ( n < 0 || n > d->value ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQSemaphore::operator-=: paramter %d out of range", n ); -#endif // QT_CHECK_RANGE - n = n < 0 ? 0 : d->value; - } - - d->value -= n; - d->cond.wakeAll(); - - return d->value; -} - - -/*! - Returns the number of accesses currently available to the - semaphore. -*/ -int TQSemaphore::available() const -{ - TQMutexLocker locker(&d->mutex); - return d->max - d->value; -} - - -/*! - Returns the total number of accesses to the semaphore. -*/ -int TQSemaphore::total() const -{ - TQMutexLocker locker(&d->mutex); - return d->max; -} - - -/*! - Try to get access to the semaphore. If \l available() \< \a n, this - function will return FALSE immediately. If \l available() \>= \a n, - this function will take \a n accesses and return TRUE. This - function does \e not block. -*/ -bool TQSemaphore::tryAccess(int n) -{ - TQMutexLocker locker(&d->mutex); - - if (d->value + n > d->max) - return FALSE; - - d->value += n; - - return TRUE; -} - -#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/qt_tools.pri b/src/tools/qt_tools.pri index b57e00435..d52bbd339 100644 --- a/src/tools/qt_tools.pri +++ b/src/tools/qt_tools.pri @@ -38,15 +38,15 @@ tools { $$TOOLS_P/qlocale_p.h \ $$TOOLS_H/tqptrlist.h \ $$TOOLS_H/tqmap.h \ - $$TOOLS_H/ntqmutex.h \ - $$TOOLS_P/qmutex_p.h \ - $$TOOLS_P/qmutexpool_p.h \ + $$TOOLS_H/tqmutex.h \ + $$TOOLS_P/tqmutex_p.h \ + $$TOOLS_P/tqmutexpool_p.h \ $$TOOLS_P/qpluginmanager_p.h \ $$TOOLS_H/tqptrcollection.h \ $$TOOLS_H/tqptrdict.h \ $$TOOLS_H/tqptrqueue.h \ $$TOOLS_H/ntqregexp.h \ - $$TOOLS_H/ntqsemaphore.h \ + $$TOOLS_H/tqsemaphore.h \ $$TOOLS_H/ntqsettings.h \ $$TOOLS_P/qsettings_p.h \ $$TOOLS_H/ntqshared.h \ @@ -56,14 +56,14 @@ tools { $$TOOLS_H/tqstrlist.h \ $$TOOLS_H/tqstrvec.h \ $$TOOLS_H/tqtextstream.h \ - $$TOOLS_P/qthreadinstance_p.h \ - $$TOOLS_H/ntqthreadstorage.h\ + $$TOOLS_P/tqthreadinstance_p.h \ + $$TOOLS_H/tqthreadstorage.h\ $$TOOLS_P/qunicodetables_p.h \ $$TOOLS_H/tqptrvector.h \ $$TOOLS_H/tqvaluelist.h \ $$TOOLS_H/tqvaluestack.h \ $$TOOLS_H/tqvaluevector.h \ - $$TOOLS_H/ntqwaitcondition.h \ + $$TOOLS_H/tqwaitcondition.h \ $$TOOLS_P/qcom_p.h \ $$TOOLS_P/qucom_p.h \ $$TOOLS_H/ntquuid.h @@ -73,9 +73,9 @@ tools { $$TOOLS_CPP/qfileinfo_win.cpp \ $$TOOLS_CPP/qlibrary_win.cpp \ $$TOOLS_CPP/qsettings_win.cpp \ - $$TOOLS_CPP/qmutex_win.cpp \ - $$TOOLS_CPP/qwaitcondition_win.cpp \ - $$TOOLS_CPP/qthreadstorage_win.cpp \ + $$TOOLS_CPP/tqmutex_win.cpp \ + $$TOOLS_CPP/tqwaitcondition_win.cpp \ + $$TOOLS_CPP/tqthreadstorage_win.cpp \ $$TOOLS_CPP/qcriticalsection_p.cpp win32-borland:SOURCES += $$TOOLS_CPP/qwinexport.cpp @@ -95,9 +95,9 @@ tools { else:unix:SOURCES += $$TOOLS_CPP/qdir_unix.cpp \ $$TOOLS_CPP/qfile_unix.cpp \ $$TOOLS_CPP/qfileinfo_unix.cpp \ - $$TOOLS_CPP/qmutex_unix.cpp \ - $$TOOLS_CPP/qthreadstorage_unix.cpp \ - $$TOOLS_CPP/qwaitcondition_unix.cpp + $$TOOLS_CPP/tqmutex_unix.cpp \ + $$TOOLS_CPP/tqthreadstorage_unix.cpp \ + $$TOOLS_CPP/tqwaitcondition_unix.cpp mac:!x11:!embedded:SOURCES += $$TOOLS_CPP/qsettings_mac.cpp mac { @@ -128,11 +128,11 @@ tools { $$TOOLS_CPP/qlibrary.cpp \ $$TOOLS_CPP/qlocale.cpp \ $$TOOLS_CPP/tqmap.cpp \ - $$TOOLS_CPP/qmutexpool.cpp \ + $$TOOLS_CPP/tqmutexpool.cpp \ $$TOOLS_CPP/tqptrcollection.cpp \ $$TOOLS_CPP/qregexp.cpp \ $$TOOLS_CPP/tqstring.cpp \ - $$TOOLS_CPP/qsemaphore.cpp \ + $$TOOLS_CPP/tqsemaphore.cpp \ $$TOOLS_CPP/qsettings.cpp \ $$TOOLS_CPP/tqstringlist.cpp \ $$TOOLS_CPP/tqtextstream.cpp \ diff --git a/src/tools/qthreadinstance_p.h b/src/tools/qthreadinstance_p.h deleted file mode 100644 index 076c2ba19..000000000 --- a/src/tools/qthreadinstance_p.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQTHREAD_P_H -#define TQTHREAD_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of TQThread and TQThreadStorage. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// -// - -#ifdef TQT_THREAD_SUPPORT - -#ifndef QT_H -#include "ntqmutex.h" -#include "ntqwindowdefs.h" -#endif // QT_H - -#ifdef Q_OS_UNIX -#include -#endif - -class TQThread; -class TQEventLoop; - -class TQThreadInstance { -public: - static void setCurrentThread(TQThread *thread); - static TQThreadInstance *current(); - - void init(unsigned int stackSize); - void deinit(); - - TQMutex *mutex() const; - void terminate(); - - unsigned int stacksize; - void *args[2]; - void **thread_storage; - bool finished : 1; - bool running : 1; - bool orphan : 1; - -#ifdef Q_OS_UNIX - pthread_cond_t thread_done; - pthread_t thread_id; - - static void *start( void * ); - static void finish( void * ); -#endif // Q_OS_UNIX - -#ifdef Q_OS_WIN32 - TQt::HANDLE handle; - unsigned int thread_id; - int waiters; - - static unsigned int __stdcall start( void * ); - static void finish( TQThreadInstance * ); -#endif // Q_OS_WIN32 - - static void finishGuiThread( TQThreadInstance *d ); - - TQEventLoop* eventLoop; - int cleanupType; - bool disableThreadPostedEvents : 1; -}; - -#endif // TQT_THREAD_SUPPORT -#endif // TQTHREAD_P_H diff --git a/src/tools/qthreadstorage_unix.cpp b/src/tools/qthreadstorage_unix.cpp deleted file mode 100644 index 86192868e..000000000 --- a/src/tools/qthreadstorage_unix.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifdef TQT_THREAD_SUPPORT - -#include "ntqapplication.h" -#include "ntqthread.h" -#include "qplatformdefs.h" - -#include "ntqthreadstorage.h" -#include - -#include - -// #define TQTHREADSTORAGE_DEBUG - - -// keep this in sync with the implementation in qthreadstorage.cpp -static const int MAX_THREAD_STORAGE = 257; // 256 maximum + 1 used in TQRegExp - -static pthread_mutex_t thread_storage_mutex = PTHREAD_MUTEX_INITIALIZER; - -static bool thread_storage_init = FALSE; -static struct { - bool used; - void (*func)( void * ); -} thread_storage_usage[MAX_THREAD_STORAGE]; - - -TQThreadStorageData::TQThreadStorageData( void (*func)( void * ) ) - : id( 0 ) -{ - pthread_mutex_lock( &thread_storage_mutex ); - - // make sure things are initialized - if ( ! thread_storage_init ) - memset( thread_storage_usage, 0, sizeof( thread_storage_usage ) ); - thread_storage_init = TRUE; - - for ( ; id < MAX_THREAD_STORAGE; ++id ) { - if ( !thread_storage_usage[id].used ) - break; - } - - Q_ASSERT( id >= 0 && id < MAX_THREAD_STORAGE ); - thread_storage_usage[id].used = TRUE; - thread_storage_usage[id].func = func; - -#ifdef TQTHREADSTORAGE_DEBUG - tqDebug( "TQThreadStorageData: allocated id %d", id ); -#endif // TQTHREADSTORAGE_DEBUG - - pthread_mutex_unlock( &thread_storage_mutex ); -} - -TQThreadStorageData::~TQThreadStorageData() -{ - // The Gui thread has static storage duration, TQThreadStorage are almost always static (it's - // technically possible to allocate those in the heap, but it's quite unusual). It's impossible - // to predict whichever of those one gets destroyed first, but usually it's a TQThreadStorage. - // In that case we have to do the cleanup of its storage ourself as it won't be possible after - // nullifying the destructor below. - TQThread *guiThread = TQApplication::guiThread(); - if (guiThread) { - TQThreadInstance *d = guiThread->d; - TQMutexLocker locker( d->mutex() ); - if (d->thread_storage && d->thread_storage[id]) { - thread_storage_usage[id].func( d->thread_storage[id] ); - d->thread_storage[id] = nullptr; - } - } - - pthread_mutex_lock( &thread_storage_mutex ); - thread_storage_usage[id].used = FALSE; - thread_storage_usage[id].func = 0; - -#ifdef TQTHREADSTORAGE_DEBUG - tqDebug( "TQThreadStorageData: released id %d", id ); -#endif // TQTHREADSTORAGE_DEBUG - - pthread_mutex_unlock( &thread_storage_mutex ); -} - -void **TQThreadStorageData::get() const -{ - TQThreadInstance *d = TQThreadInstance::current(); - if (!d) { - tqWarning("TQThreadStorage can only be used with threads started with TQThread"); - return 0; - } - TQMutexLocker locker( d->mutex() ); - return d->thread_storage && d->thread_storage[id] ? &d->thread_storage[id] : 0; -} - -void **TQThreadStorageData::set( void *p ) -{ - TQThreadInstance *d = TQThreadInstance::current(); - if (!d) { - tqWarning("TQThreadStorage can only be used with threads started with TQThread"); - return 0; - } - TQMutexLocker locker( d->mutex() ); - if ( !d->thread_storage ) { -#ifdef TQTHREADSTORAGE_DEBUG - tqDebug( "TQThreadStorageData: allocating storage for thread %lx", - (unsigned long) pthread_self() ); -#endif // TQTHREADSTORAGE_DEBUG - - d->thread_storage = new void*[MAX_THREAD_STORAGE]; - memset( d->thread_storage, 0, sizeof( void* ) * MAX_THREAD_STORAGE ); - } - - // delete any previous data - if ( d->thread_storage[id] ) - thread_storage_usage[id].func( d->thread_storage[id] ); - - // store new data - d->thread_storage[id] = p; - return &d->thread_storage[id]; -} - -void TQThreadStorageData::finish( void **thread_storage ) -{ - if ( ! thread_storage ) return; // nothing to do - -#ifdef TQTHREADSTORAGE_DEBUG - tqDebug( "TQThreadStorageData: destroying storage for thread %lx", - (unsigned long) pthread_self() ); -#endif // TQTHREADSTORAGE_DEBUG - - for ( int i = 0; i < MAX_THREAD_STORAGE; ++i ) { - if ( ! thread_storage[i] ) continue; - if ( ! thread_storage_usage[i].used ) { -#ifdef QT_CHECK_STATE - tqWarning( "TQThreadStorage: thread %lx exited after TQThreadStorage destroyed", - (unsigned long) pthread_self() ); -#endif // QT_CHECK_STATE - continue; - } - - thread_storage_usage[i].func( thread_storage[i] ); - } - - delete [] thread_storage; -} - - -/*! - \class TQThreadStorage - \brief The TQThreadStorage class provides per-thread data storage. - - \threadsafe - \ingroup thread - \ingroup environment - - TQThreadStorage is a template class that provides per-thread data - storage. - - \e{Note that due to compiler limitations, TQThreadStorage can only - store pointers.} - - The setLocalData() function stores a single thread-specific value - for the calling thread. The data can be accessed later using the - localData() functions. TQThreadStorage takes ownership of the - data (which must be created on the heap with \e new) and deletes - it when the thread exits (either normally or via termination). - - The hasLocalData() function allows the programmer to determine if - data has previously been set using the setLocalData() function. - This is useful for lazy initializiation. - - For example, the following code uses TQThreadStorage to store a - single cache for each thread that calls the \e cacheObject() and - \e removeFromCache() functions. The cache is automatically - deleted when the calling thread exits (either normally or via - termination). - - \code - TQThreadStorage *> caches; - - void cacheObject( const TQString &key, SomeClass *object ) - { - if ( ! caches.hasLocalData() ) - caches.setLocalData( new TQCache ); - - caches.localData()->insert( key, object ); - } - - void removeFromCache( const TQString &key ) - { - if ( ! caches.hasLocalData() ) - return; // nothing to do - - caches.localData()->remove( key ); - } - \endcode - - \section1 Caveats - - \list - - \i As noted above, TQThreadStorage can only store pointers due to - compiler limitations. Support for value-based objects will be - added when the majority of compilers are able to support partial - template specialization. - - \i The \link ~TQThreadStorage() destructor\endlink does \e not - delete per-thread data. TQThreadStorage only deletes per-thread - data when the thread exits or when setLocalData() is called - multiple times. - - \i TQThreadStorage can only be used with threads started with - TQThread. It \e cannot be used with threads started with - platform-specific APIs. - - \i As a corollary to the above, platform-specific APIs cannot be - used to exit or terminate a TQThread using TQThreadStorage. Doing so - will cause all per-thread data to be leaked. See TQThread::exit() - and TQThread::terminate(). - - \i TQThreadStorage \e can be used to store data for the \e main() - thread \e after TQApplication has been constructed. TQThreadStorage - deletes all data set for the \e main() thread when TQApplication is - destroyed, regardless of whether or not the \e main() thread has - actually finished. - - \i The implementation of TQThreadStorage limits the total number of - TQThreadStorage objects to 256. An unlimited number of threads - can store per-thread data in each TQThreadStorage object. - - \endlist -*/ - -/*! - \fn TQThreadStorage::TQThreadStorage() - - Constructs a new per-thread data storage object. -*/ - -/*! - \fn TQThreadStorage::~TQThreadStorage() - - Destroys the per-thread data storage object. - - Note: The per-thread data stored is \e not deleted. Any data left - in TQThreadStorage is leaked. Make sure that all threads using - TQThreadStorage have exited before deleting the TQThreadStorage. - - \sa hasLocalData() -*/ - -/*! - \fn bool TQThreadStorage::hasLocalData() const - - Returns TRUE if the calling thread has non-zero data available; - otherwise returns FALSE. - - \sa localData() -*/ - -/*! - \fn T& TQThreadStorage::localData() - - Returns a reference to the data that was set by the calling - thread. - - Note: TQThreadStorage can only store pointers. This function - returns a \e reference to the pointer that was set by the calling - thread. The value of this reference is 0 if no data was set by - the calling thread, - - \sa hasLocalData() -*/ -/* - ### addition to the above documentation when we start supporting - ### partial template specialization, and TQThreadStorage can store - ### values *and* pointers - - When using TQThreadStorage to store values (not pointers), this - function stores an object of type \e T (created with its default - constructor) and returns a reference to that object. -*/ - -/*! - \fn const T TQThreadStorage::localData() const - \overload - - Returns a copy of the data that was set by the calling thread. - - Note: TQThreadStorage can only store pointers. This function - returns a pointer to the data that was set by the calling thread. - If no data was set by the calling thread, this function returns 0. - - \sa hasLocalData() -*/ -/* - ### addition to the above documentation when we start supporting - ### partial template specialization, and TQThreadStorage can store - ### values *and* pointers - - When using TQThreadStorage to store values (not pointers), this - function returns an object of type \e T (created with its default - constructor). Unlike the above function, this object is \e not - stored automatically. You will need to call setLocalData() to store - the object. -*/ - -/*! - \fn void TQThreadStorage::setLocalData( T data ) - - Sets the local data for the calling thread to \a data. It can be - accessed later using the localData() functions. - - If \a data is 0, this function deletes the previous data (if - any) and returns immediately. - - If \a data is non-zero, TQThreadStorage takes ownership of the \a - data and deletes it automatically either when the thread exits - (either normally or via termination) or when setLocalData() is - called again. - - Note: TQThreadStorage can only store pointers. The \a data - argument must be either a pointer to an object created on the heap - (i.e. using \e new) or 0. You should not delete \a data - yourself; TQThreadStorage takes ownership and will delete the \a - data itself. - - \sa localData() hasLocalData() -*/ - -#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/qwaitcondition_unix.cpp b/src/tools/qwaitcondition_unix.cpp deleted file mode 100644 index 62038bae5..000000000 --- a/src/tools/qwaitcondition_unix.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -** -** TQWaitCondition class for Unix -** -** Created : 20010725 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#if defined(TQT_THREAD_SUPPORT) - -#include "qplatformdefs.h" - -typedef pthread_mutex_t Q_MUTEX_T; - -#include "ntqwaitcondition.h" -#include "ntqmutex.h" -#include "qmutex_p.h" - -#include -#include - - -struct TQWaitConditionPrivate { - pthread_cond_t cond; -}; - - -/*! - \class TQWaitCondition ntqwaitcondition.h - \threadsafe - \brief The TQWaitCondition class allows waiting/waking for conditions between threads. - - \ingroup thread - \ingroup environment - - TQWaitConditions allow a thread to tell other threads that some - sort of condition has been met; one or many threads can block - waiting for a TQWaitCondition to set a condition with wakeOne() or - wakeAll(). Use wakeOne() to wake one randomly selected event or - wakeAll() to wake them all. For example, say we have three tasks - that should be performed every time the user presses a key; each - task could be split into a thread, each of which would have a - run() body like this: - - \code - TQWaitCondition key_pressed; - - for (;;) { - key_pressed.wait(); // This is a TQWaitCondition global variable - // Key was pressed, do something interesting - do_something(); - } - \endcode - - A fourth thread would read key presses and wake the other three - threads up every time it receives one, like this: - - \code - TQWaitCondition key_pressed; - - for (;;) { - getchar(); - // Causes any thread in key_pressed.wait() to return from - // that method and continue processing - key_pressed.wakeAll(); - } - \endcode - - Note that the order the three threads are woken up in is - undefined, and that if some or all of the threads are still in - do_something() when the key is pressed, they won't be woken up - (since they're not waiting on the condition variable) and so the - task will not be performed for that key press. This can be - avoided by, for example, doing something like this: - - \code - TQMutex mymutex; - TQWaitCondition key_pressed; - int mycount=0; - - // Worker thread code - for (;;) { - key_pressed.wait(); // This is a TQWaitCondition global variable - mymutex.lock(); - mycount++; - mymutex.unlock(); - do_something(); - mymutex.lock(); - mycount--; - mymutex.unlock(); - } - - // Key reading thread code - for (;;) { - getchar(); - mymutex.lock(); - // Sleep until there are no busy worker threads - while( mycount > 0 ) { - mymutex.unlock(); - sleep( 1 ); - mymutex.lock(); - } - mymutex.unlock(); - key_pressed.wakeAll(); - } - \endcode - - The mutexes are necessary because the results of two threads - attempting to change the value of the same variable simultaneously - are unpredictable. -*/ - -/*! - Constructs a new event signalling, i.e. wait condition, object. -*/ -TQWaitCondition::TQWaitCondition() -{ - d = new TQWaitConditionPrivate; - - int ret = pthread_cond_init(&d->cond, NULL); - -#ifdef QT_CHECK_RANGE - if (ret) - tqWarning( "Wait condition init failure: %s", strerror( ret ) ); -#endif -} - - -/*! - Deletes the event signalling, i.e. wait condition, object. -*/ -TQWaitCondition::~TQWaitCondition() -{ - int ret = pthread_cond_destroy(&d->cond); - - if (ret) { -#ifdef QT_CHECK_RANGE - tqWarning( "Wait condition destroy failure: %s", strerror( ret ) ); -#endif - - // seems we have threads waiting on us, lets wake them up - pthread_cond_broadcast(&d->cond); - } - - delete d; -} - -/*! - This wakes one thread waiting on the TQWaitCondition. The thread - that is woken up depends on the operating system's scheduling - policies, and cannot be controlled or predicted. - - \sa wakeAll() -*/ -void TQWaitCondition::wakeOne() -{ - int ret = pthread_cond_signal(&d->cond); - -#ifdef QT_CHECK_RANGE - if (ret) - tqWarning("Wait condition wakeOne failure: %s", strerror(ret)); -#endif -} - -/*! - This wakes all threads waiting on the TQWaitCondition. The order in - which the threads are woken up depends on the operating system's - scheduling policies, and cannot be controlled or predicted. - - \sa wakeOne() -*/ -void TQWaitCondition::wakeAll() -{ - int ret = pthread_cond_broadcast(&d->cond); - -#ifdef QT_CHECK_RANGE - if (ret) - tqWarning("Wait condition wakeAll failure: %s", strerror(ret)); -#endif -} - -/*! - Wait on the thread event object. The thread calling this will - block until either of these conditions is met: - \list - \i Another thread signals it using wakeOne() or wakeAll(). This - function will return TRUE in this case. - \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the - default), then the wait will never timeout (the event must be - signalled). This function will return FALSE if the wait timed - out. - \endlist - - \sa wakeOne(), wakeAll() -*/ -bool TQWaitCondition::wait(unsigned long time) -{ - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_mutex_lock( &mutex ); - - int ret; - if (time != ULONG_MAX) { - struct timeval tv; - gettimeofday(&tv, 0); - - timespec ti; - ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; - ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); - ti.tv_nsec %= 1000000000; - - ret = pthread_cond_timedwait(&d->cond, &mutex, &ti); - } else - ret = pthread_cond_wait(&d->cond, &mutex); - -#ifdef QT_CHECK_RANGE - if (ret && ret != ETIMEDOUT) - tqWarning("Wait condition wait failure: %s",strerror(ret)); -#endif - - pthread_mutex_unlock( &mutex ); - - return (ret == 0); -} - -/*! - \overload - - Release the locked \a mutex and wait on the thread event object. - The \a mutex must be initially locked by the calling thread. If \a - mutex is not in a locked state, this function returns immediately. - If \a mutex is a recursive mutex, this function returns - immediately. The \a mutex will be unlocked, and the calling thread - will block until either of these conditions is met: - \list - \i Another thread signals it using wakeOne() or wakeAll(). This - function will return TRUE in this case. - \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the - default), then the wait will never timeout (the event must be - signalled). This function will return FALSE if the wait timed - out. - \endlist - - The mutex will be returned to the same locked state. This function - is provided to allow the atomic transition from the locked state - to the wait state. - - \sa wakeOne(), wakeAll() -*/ -bool TQWaitCondition::wait(TQMutex *mutex, unsigned long time) -{ - if (! mutex) - return FALSE; - - if (mutex->d->type() == Q_MUTEX_RECURSIVE) { -#ifdef QT_CHECK_RANGE - tqWarning("Wait condition warning: using recursive mutexes with\n" - " wait conditions is undefined!"); -#endif - return FALSE; - } - - int ret; - if (time != ULONG_MAX) { - struct timeval tv; - gettimeofday(&tv, 0); - - timespec ti; - ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; - ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); - ti.tv_nsec %= 1000000000; - - ret = pthread_cond_timedwait(&d->cond, &mutex->d->handle, &ti); - } else - ret = pthread_cond_wait(&d->cond, &mutex->d->handle); - -#ifdef QT_CHECK_RANGE - if (ret && ret != ETIMEDOUT) - tqWarning("Wait condition wait failure: %s",strerror(ret)); -#endif - - return (ret == 0); -} - -#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/tqmutex.h b/src/tools/tqmutex.h new file mode 100644 index 000000000..c517c6355 --- /dev/null +++ b/src/tools/tqmutex.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Definition of TQMutex class +** +** Created : 931107 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMUTEX_H +#define TQMUTEX_H + +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H + +#if defined(TQT_THREAD_SUPPORT) + +class TQMutexPrivate; + +const int Q_MUTEX_NORMAL = 0; +const int Q_MUTEX_RECURSIVE = 1; + +class TQ_EXPORT TQMutex +{ + friend class TQThread; + friend class TQWaitCondition; + friend class TQWaitConditionPrivate; + +public: + TQMutex(bool recursive = FALSE); + virtual ~TQMutex(); + + void lock(); + void unlock(); + bool locked(); + bool tryLock(); + +private: + TQMutexPrivate * d; + +#if defined(TQ_DISABLE_COPY) + TQMutex( const TQMutex & ); + TQMutex &operator=( const TQMutex & ); +#endif + +public: + int level(); +}; + +class TQ_EXPORT TQMutexLocker +{ +public: + TQMutexLocker( TQMutex * ); + ~TQMutexLocker(); + + TQMutex *mutex() const; + +private: + TQMutex *mtx; + +#if defined(TQ_DISABLE_COPY) + TQMutexLocker( const TQMutexLocker & ); + TQMutexLocker &operator=( const TQMutexLocker & ); +#endif +}; + +inline TQMutexLocker::TQMutexLocker( TQMutex *m ) + : mtx( m ) +{ + if ( mtx ) mtx->lock(); +} + +inline TQMutexLocker::~TQMutexLocker() +{ + if ( mtx ) mtx->unlock(); +} + +inline TQMutex *TQMutexLocker::mutex() const +{ + return mtx; +} + +#endif + +#endif diff --git a/src/tools/tqmutex_p.h b/src/tools/tqmutex_p.h new file mode 100644 index 000000000..ee841f5e2 --- /dev/null +++ b/src/tools/tqmutex_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** TQMutex private class declarations +** +** Created : 20012507 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMUTEX_P_H +#define TQMUTEX_P_H + +#ifndef QT_H +#endif // QT_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of tqmutex_unix.cpp and tqmutex_win.cpp. This header file may change +// from version to version without notice, or even be removed. +// +// We mean it. +// + +class TQMutexPrivate { +public: + // Q_MUTEX_T is defined in the various *.cpp files + Q_MUTEX_T handle; + + virtual ~TQMutexPrivate(); + + virtual void lock() = 0; + virtual void unlock() = 0; + virtual bool locked() = 0; + virtual bool trylock() = 0; + virtual int type() const = 0; + virtual int level() = 0; +}; + + +#endif // TQMUTEX_P_H diff --git a/src/tools/tqmutex_unix.cpp b/src/tools/tqmutex_unix.cpp new file mode 100644 index 000000000..9c793a02d --- /dev/null +++ b/src/tools/tqmutex_unix.cpp @@ -0,0 +1,535 @@ +/**************************************************************************** +** +** TQMutex class for Unix +** +** Created : 20010725 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#if defined(TQT_THREAD_SUPPORT) + +#include "qplatformdefs.h" + +typedef pthread_mutex_t Q_MUTEX_T; + +#if defined(QT_CHECK_RANGE) +# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK +#else +# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT +#endif +#define Q_RECURSIVE_MUTEX_TYPE PTHREAD_MUTEX_RECURSIVE + +#include "tqmutex.h" +#include "tqmutex_p.h" + +#include +#include + +// Private class declarations + +class TQRealMutexPrivate : public TQMutexPrivate { +public: + TQRealMutexPrivate(bool = FALSE); + + void lock(); + void unlock(); + bool locked(); + bool trylock(); + int type() const; + int level(); + + bool recursive; + int count; +}; + + +// Private class implementation + +// base destructor +TQMutexPrivate::~TQMutexPrivate() +{ + int ret = pthread_mutex_destroy(&handle); + +#ifdef QT_CHECK_RANGE + if ( ret ) + tqWarning( "Mutex destroy failure: %s", strerror( ret ) ); +#endif +} + +// real mutex class +TQRealMutexPrivate::TQRealMutexPrivate(bool recurs) + : recursive(recurs), count(0) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, recursive ? Q_RECURSIVE_MUTEX_TYPE : Q_NORMAL_MUTEX_TYPE); + int ret = pthread_mutex_init(&handle, &attr); + pthread_mutexattr_destroy(&attr); + +#ifdef QT_CHECK_RANGE + if( ret ) + tqWarning( "Mutex init failure: %s", strerror( ret ) ); +#endif // QT_CHECK_RANGE +} + +void TQRealMutexPrivate::lock() +{ + int ret = pthread_mutex_lock(&handle); + + if (!ret) { + count++; + } else { +#ifdef QT_CHECK_RANGE + tqWarning("Mutex lock failure: %s", strerror(ret)); +#endif + } +} + +void TQRealMutexPrivate::unlock() +{ + count--; + int ret = pthread_mutex_unlock(&handle); + + if (ret) { + count++; +#ifdef QT_CHECK_RANGE + tqWarning("Mutex unlock failure: %s", strerror(ret)); +#endif + } +} + +bool TQRealMutexPrivate::locked() +{ + return count > 0; +} + +bool TQRealMutexPrivate::trylock() +{ + int ret = pthread_mutex_trylock(&handle); + + if (ret == EBUSY) { + return FALSE; + } else if (ret) { +#ifdef QT_CHECK_RANGE + tqWarning("Mutex trylock failure: %s", strerror(ret)); +#endif + return FALSE; + } + + return TRUE; +} + +int TQRealMutexPrivate::type() const +{ + return recursive ? Q_MUTEX_RECURSIVE : Q_MUTEX_NORMAL; +} + +int TQRealMutexPrivate::level() +{ + return count; +} + + +/*! + \class TQMutex tqmutex.h + \threadsafe + \brief The TQMutex class provides access serialization between threads. + + \ingroup thread + \ingroup environment + + The purpose of a TQMutex is to protect an object, data structure or + section of code so that only one thread can access it at a time + (This is similar to the Java \c synchronized keyword). For + example, say there is a method which prints a message to the user + on two lines: + + \code + int number = 6; + + void method1() + { + number *= 5; + number /= 4; + } + + void method2() + { + number *= 3; + number /= 2; + } + \endcode + + If these two methods are called in succession, the following happens: + + \code + // method1() + number *= 5; // number is now 30 + number /= 4; // number is now 7 + + // method2() + number *= 3; // nubmer is now 21 + number /= 2; // number is now 10 + \endcode + + If these two methods are called simultaneously from two threads then the + following sequence could result: + + \code + // Thread 1 calls method1() + number *= 5; // number is now 30 + + // Thread 2 calls method2(). + // + // Most likely Thread 1 has been put to sleep by the operating + // system to allow Thread 2 to run. + number *= 3; // number is now 90 + number /= 2; // number is now 45 + + // Thread 1 finishes executing. + number /= 4; // number is now 11, instead of 10 + \endcode + + If we add a mutex, we should get the result we want: + + \code + TQMutex mutex; + int number = 6; + + void method1() + { + mutex.lock(); + number *= 5; + number /= 4; + mutex.unlock(); + } + + void method2() + { + mutex.lock(); + number *= 3; + number /= 2; + mutex.unlock(); + } + \endcode + + Then only one thread can modify \c number at any given time and + the result is correct. This is a trivial example, of course, but + applies to any other case where things need to happen in a + particular sequence. + + When you call lock() in a thread, other threads that try to call + lock() in the same place will block until the thread that got the + lock calls unlock(). A non-blocking alternative to lock() is + tryLock(). +*/ + +/*! + Constructs a new mutex. The mutex is created in an unlocked state. + A recursive mutex is created if \a recursive is TRUE; a normal + mutex is created if \a recursive is FALSE (the default). With a + recursive mutex, a thread can lock the same mutex multiple times + and it will not be unlocked until a corresponding number of + unlock() calls have been made. +*/ +TQMutex::TQMutex(bool recursive) +{ + d = new TQRealMutexPrivate(recursive); +} + +/*! + Destroys the mutex. + + \warning If you destroy a mutex that still holds a lock the + resultant behavior is undefined. +*/ +TQMutex::~TQMutex() +{ + delete d; +} + +/*! + Attempt to lock the mutex. If another thread has locked the mutex + then this call will \e block until that thread has unlocked it. + + \sa unlock(), locked() +*/ +void TQMutex::lock() +{ + d->lock(); +} + +/*! + Unlocks the mutex. Attempting to unlock a mutex in a different + thread to the one that locked it results in an error. Unlocking a + mutex that is not locked results in undefined behaviour (varies + between different Operating Systems' thread implementations). + + \sa lock(), locked() +*/ +void TQMutex::unlock() +{ + d->unlock(); +} + +/*! + Returns TRUE if the mutex is locked by another thread; otherwise + returns FALSE. + + \warning Due to differing implementations of recursive mutexes on + various platforms, calling this function from the same thread that + previously locked the mutex will return undefined results. + + \sa lock(), unlock() +*/ +bool TQMutex::locked() +{ + return d->locked(); +} + +/*! + Attempt to lock the mutex. If the lock was obtained, this function + returns TRUE. If another thread has locked the mutex, this + function returns FALSE, instead of waiting for the mutex to become + available, i.e. it does not block. + + If the lock was obtained, the mutex must be unlocked with unlock() + before another thread can successfully lock it. + + \sa lock(), unlock(), locked() +*/ +bool TQMutex::tryLock() +{ + return d->trylock(); +} + +/*! + Returns the current lock level of the mutex. + 0 means the mutex is unlocked + This method should only be called when the mutex has already been locked + by lock(), otherwise the lock level could change before the next line + of code is executed. + + WARNING: Non-recursive mutexes will never exceed a lock level of 1! + + \sa lock(), unlock(), locked() +*/ +int TQMutex::level() +{ + return d->level(); +} + +/*! + \class TQMutexLocker tqmutex.h + \brief The TQMutexLocker class simplifies locking and unlocking TQMutexes. + + \threadsafe + + \ingroup thread + \ingroup environment + + The purpose of TQMutexLocker is to simplify TQMutex locking and + unlocking. Locking and unlocking a TQMutex in complex functions and + statements or in exception handling code is error prone and + difficult to debug. TQMutexLocker should be used in such situations + to ensure that the state of the mutex is well defined and always + locked and unlocked properly. + + TQMutexLocker should be created within a function where a TQMutex + needs to be locked. The mutex is locked when TQMutexLocker is + created, and unlocked when TQMutexLocker is destroyed. + + For example, this complex function locks a TQMutex upon entering + the function and unlocks the mutex at all the exit points: + + \code + int complexFunction( int flag ) + { + mutex.lock(); + + int return_value = 0; + + switch ( flag ) { + case 0: + case 1: + { + mutex.unlock(); + return moreComplexFunction( flag ); + } + + case 2: + { + int status = anotherFunction(); + if ( status < 0 ) { + mutex.unlock(); + return -2; + } + return_value = status + flag; + break; + } + + default: + { + if ( flag > 10 ) { + mutex.unlock(); + return -1; + } + break; + } + } + + mutex.unlock(); + return return_value; + } + \endcode + + This example function will get more complicated as it is + developed, which increases the likelihood that errors will occur. + + Using TQMutexLocker greatly simplifies the code, and makes it more + readable: + + \code + int complexFunction( int flag ) + { + TQMutexLocker locker( &mutex ); + + int return_value = 0; + + switch ( flag ) { + case 0: + case 1: + { + return moreComplexFunction( flag ); + } + + case 2: + { + int status = anotherFunction(); + if ( status < 0 ) + return -2; + return_value = status + flag; + break; + } + + default: + { + if ( flag > 10 ) + return -1; + break; + } + } + + return return_value; + } + \endcode + + Now, the mutex will always be unlocked when the TQMutexLocker + object is destroyed (when the function returns since \c locker is + an auto variable). Note that the mutex will be unlocked after + the call to moreComplexFunction() in this example, avoiding + possible bugs caused by unlocking the mutex too early, as in + the first example. + + The same principle applies to code that throws and catches + exceptions. An exception that is not caught in the function that + has locked the mutex has no way of unlocking the mutex before the + exception is passed up the stack to the calling function. + + TQMutexLocker also provides a mutex() member function that returns + the mutex on which the TQMutexLocker is operating. This is useful + for code that needs access to the mutex, such as + TQWaitCondition::wait(). For example: + + \code + class SignalWaiter + { + private: + TQMutexLocker locker; + + public: + SignalWaiter( TQMutex *mutex ) + : locker( mutex ) + { + } + + void waitForSignal() + { + ... + ... + ... + + while ( ! signalled ) + waitcondition.wait( locker.mutex() ); + + ... + ... + ... + } + }; + \endcode + + \sa TQMutex, TQWaitCondition +*/ + +/*! + \fn TQMutexLocker::TQMutexLocker( TQMutex *mutex ) + + Constructs a TQMutexLocker and locks \a mutex. The mutex will be + unlocked when the TQMutexLocker is destroyed. If \a mutex is zero, + TQMutexLocker does nothing. + + \sa TQMutex::lock() +*/ + +/*! + \fn TQMutexLocker::~TQMutexLocker() + + Destroys the TQMutexLocker and unlocks the mutex which was locked + in the constructor. + + \sa TQMutexLocker::TQMutexLocker(), TQMutex::unlock() +*/ + +/*! + \fn TQMutex *TQMutexLocker::mutex() const + + Returns a pointer to the mutex which was locked in the + constructor. + + \sa TQMutexLocker::TQMutexLocker() +*/ + +#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/tqmutexpool.cpp b/src/tools/tqmutexpool.cpp new file mode 100644 index 000000000..a7b17da3d --- /dev/null +++ b/src/tools/tqmutexpool.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqmutexpool_p.h" + +#ifdef TQT_THREAD_SUPPORT + +#include + +TQ_EXPORT TQMutexPool *tqt_global_mutexpool = 0; + + +/*! + \class TQMutexPool tqmutexpool_p.h + \brief The TQMutexPool class provides a pool of TQMutex objects. + + \internal + + \ingroup thread + + TQMutexPool is a convenience class that provides access to a fixed + number of TQMutex objects. + + Typical use of a TQMutexPool is in situations where it is not + possible or feasible to use one TQMutex for every protected object. + The mutex pool will return a mutex based on the address of the + object that needs protection. + + For example, consider this simple class: + + \code + class Number { + public: + Number( double n ) : num ( n ) { } + + void setNumber( double n ) { num = n; } + double number() const { return num; } + + private: + double num; + }; + \endcode + + Adding a TQMutex member to the Number class does not make sense, + because it is so small. However, in order to ensure that access to + each Number is protected, you need to use a mutex. In this case, a + TQMutexPool would be ideal. + + Code to calculate the square of a number would then look something + like this: + + \code + void calcSquare( Number *num ) + { + TQMutexLocker locker( mutexpool.get( num ) ); + num.setNumber( num.number() * num.number() ); + } + \endcode + + This function will safely calculate the square of a number, since + it uses a mutex from a TQMutexPool. The mutex is locked and + unlocked automatically by the TQMutexLocker class. See the + TQMutexLocker documentation for more details. +*/ + +/*! + Constructs a TQMutexPool, reserving space for \a size TQMutexes. If + \a recursive is TRUE, all TQMutexes in the pool will be recursive + mutexes; otherwise they will all be non-recursive (the default). + + The TQMutexes are created when needed, and deleted when the + TQMutexPool is destructed. +*/ +TQMutexPool::TQMutexPool( bool recursive, int size ) + : mutex( FALSE ), count( size ), recurs( recursive ) +{ + mutexes = new TQMutex*[count]; + for ( int index = 0; index < count; ++index ) { + mutexes[index] = 0; + } +} + +/*! + Destructs a TQMutexPool. All TQMutexes that were created by the pool + are deleted. +*/ +TQMutexPool::~TQMutexPool() +{ + TQMutexLocker locker( &mutex ); + for ( int index = 0; index < count; ++index ) { + delete mutexes[index]; + mutexes[index] = 0; + } + delete [] mutexes; + mutexes = 0; +} + +/*! + Returns a TQMutex from the pool. TQMutexPool uses the value \a + address to determine which mutex is retured from the pool. +*/ +TQMutex *TQMutexPool::get( void *address ) +{ + int index = (int) ( (unsigned long) address % count ); + + if ( ! mutexes[index] ) { + // mutex not created, create one + + TQMutexLocker locker( &mutex ); + // we need to check once again that the mutex hasn't been created, since + // 2 threads could be trying to create a mutex as the same index... + if ( ! mutexes[index] ) { + mutexes[index] = new TQMutex( recurs ); + } + } + + return mutexes[index]; +} + +#endif diff --git a/src/tools/tqmutexpool_p.h b/src/tools/tqmutexpool_p.h new file mode 100644 index 000000000..28a7ac63a --- /dev/null +++ b/src/tools/tqmutexpool_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMUTEXPOOL_P_H +#define TQMUTEXPOOL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of TQSettings. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// +// + +#ifdef TQT_THREAD_SUPPORT + +#ifndef QT_H +#include "tqmutex.h" +#include "ntqmemarray.h" +#endif // QT_H + +class TQ_EXPORT TQMutexPool +{ +public: + TQMutexPool( bool recursive = FALSE, int size = 17 ); + ~TQMutexPool(); + + TQMutex *get( void *address ); + +private: + TQMutex mutex; + TQMutex **mutexes; + int count; + bool recurs; +}; + +extern TQ_EXPORT TQMutexPool *tqt_global_mutexpool; + +#endif // TQT_THREAD_SUPPORT + +#endif // TQMUTEXPOOL_P_H diff --git a/src/tools/tqsemaphore.cpp b/src/tools/tqsemaphore.cpp new file mode 100644 index 000000000..a5cdfc630 --- /dev/null +++ b/src/tools/tqsemaphore.cpp @@ -0,0 +1,255 @@ +/**************************************************************************** +** +** TQSemaphore class for Unix +** +** Created : 20010725 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#if defined(TQT_THREAD_SUPPORT) + +#include "tqsemaphore.h" +#include "tqmutex.h" +#include "tqwaitcondition.h" + + +/*! + \class TQSemaphore tqsemaphore.h + \threadsafe + \brief The TQSemaphore class provides a robust integer semaphore. + + \ingroup thread + \ingroup environment + + A TQSemaphore can be used to serialize thread execution, in a + similar way to a TQMutex. A semaphore differs from a mutex, in + that a semaphore can be accessed by more than one thread at a + time. + + For example, suppose we have an application that stores data in a + large tree structure. The application creates 10 threads + (commonly called a thread pool) to perform searches on the tree. + When the application searches the tree for some piece of data, it + uses one thread per base node to do the searching. A semaphore + could be used to make sure that two threads don't try to search + the same branch of the tree at the same time. + + A non-computing example of a semaphore would be dining at a + restuarant. A semaphore is initialized to have a maximum count + equal to the number of chairs in the restuarant. As people + arrive, they want a seat. As seats are filled, the semaphore is + accessed, once per person. As people leave, the access is + released, allowing more people to enter. If a party of 10 people + want to be seated, but there are only 9 seats, those 10 people + will wait, but a party of 4 people would be seated (taking the + available seats to 5, making the party of 10 people wait longer). + + When a semaphore is created it is given a number which is the + maximum number of concurrent accesses it will permit. Accesses to + the sempahore are gained using operator++() or operator+=(), and + released with operator--() or operator-=(). The number of + accesses allowed is retrieved with available(), and the total + number with total(). Note that the incrementing functions will + block if there aren't enough available accesses. Use tryAccess() + if you want to acquire accesses without blocking. +*/ + + +class TQSemaphorePrivate { +public: + TQSemaphorePrivate(int); + + TQMutex mutex; + TQWaitCondition cond; + + int value, max; +}; + + +TQSemaphorePrivate::TQSemaphorePrivate(int m) + : mutex(FALSE), value(0), max(m) +{ +} + + +/*! + Creates a new semaphore. The semaphore can be concurrently + accessed at most \a maxcount times. +*/ +TQSemaphore::TQSemaphore(int maxcount) +{ + d = new TQSemaphorePrivate(maxcount); +} + + +/*! + Destroys the semaphore. + + \warning If you destroy a semaphore that has accesses in use the + resultant behavior is undefined. +*/ +TQSemaphore::~TQSemaphore() +{ + delete d; +} + + +/*! + Postfix ++ operator. + + Try to get access to the semaphore. If \l available() == 0, this + call will block until it can get access, i.e. until available() \> + 0. +*/ +int TQSemaphore::operator++(int) +{ + TQMutexLocker locker(&d->mutex); + while (d->value >= d->max) + d->cond.wait(locker.mutex()); + + ++d->value; + if (d->value > d->max) + d->value = d->max; + + return d->value; +} + + +/*! + Postfix -- operator. + + Release access of the semaphore. This wakes all threads waiting + for access to the semaphore. +*/ +int TQSemaphore::operator--(int) +{ + TQMutexLocker locker(&d->mutex); + + --d->value; + if (d->value < 0) + d->value = 0; + + d->cond.wakeAll(); + + return d->value; +} + + +/*! + Try to get access to the semaphore. If \l available() \< \a n, this + call will block until it can get all the accesses it wants, i.e. + until available() \>= \a n. +*/ +int TQSemaphore::operator+=(int n) +{ + TQMutexLocker locker(&d->mutex); + + if ( n < 0 || n > d->max ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQSemaphore::operator+=: paramter %d out of range", n ); +#endif // QT_CHECK_RANGE + n = n < 0 ? 0 : d->max; + } + + while (d->value + n > d->max) + d->cond.wait(locker.mutex()); + + d->value += n; + + return d->value; +} + + +/*! + Release \a n accesses to the semaphore. +*/ +int TQSemaphore::operator-=(int n) +{ + TQMutexLocker locker(&d->mutex); + + if ( n < 0 || n > d->value ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQSemaphore::operator-=: paramter %d out of range", n ); +#endif // QT_CHECK_RANGE + n = n < 0 ? 0 : d->value; + } + + d->value -= n; + d->cond.wakeAll(); + + return d->value; +} + + +/*! + Returns the number of accesses currently available to the + semaphore. +*/ +int TQSemaphore::available() const +{ + TQMutexLocker locker(&d->mutex); + return d->max - d->value; +} + + +/*! + Returns the total number of accesses to the semaphore. +*/ +int TQSemaphore::total() const +{ + TQMutexLocker locker(&d->mutex); + return d->max; +} + + +/*! + Try to get access to the semaphore. If \l available() \< \a n, this + function will return FALSE immediately. If \l available() \>= \a n, + this function will take \a n accesses and return TRUE. This + function does \e not block. +*/ +bool TQSemaphore::tryAccess(int n) +{ + TQMutexLocker locker(&d->mutex); + + if (d->value + n > d->max) + return FALSE; + + d->value += n; + + return TRUE; +} + +#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/tqsemaphore.h b/src/tools/tqsemaphore.h new file mode 100644 index 000000000..0dc8e81de --- /dev/null +++ b/src/tools/tqsemaphore.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Definition of TQSemaphore class +** +** Created : 931107 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQSEMAPHORE_H +#define TQSEMAPHORE_H + +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H + +#if defined(TQT_THREAD_SUPPORT) + +class TQSemaphorePrivate; + +class TQ_EXPORT TQSemaphore +{ +public: + TQSemaphore( int ); + virtual ~TQSemaphore(); + + int available() const; + int total() const; + + // postfix operators + int operator++(int); + int operator--(int); + + int operator+=(int); + int operator-=(int); + + bool tryAccess(int); + +private: + TQSemaphorePrivate *d; + +#if defined(TQ_DISABLE_COPY) + TQSemaphore(const TQSemaphore &); + TQSemaphore &operator=(const TQSemaphore &); +#endif +}; + +#endif + +#endif diff --git a/src/tools/tqstring.cpp b/src/tools/tqstring.cpp index dbf179404..71eced17d 100644 --- a/src/tools/tqstring.cpp +++ b/src/tools/tqstring.cpp @@ -94,7 +94,7 @@ #endif #if defined(TQT_THREAD_SUPPORT) && defined(MAKE_QSTRING_THREAD_SAFE) -#include "ntqmutex.h" +#include "tqmutex.h" #endif // TQT_THREAD_SUPPORT && MAKE_QSTRING_THREAD_SAFE extern TQMutex *tqt_sharedStringMutex; diff --git a/src/tools/tqthreadinstance_p.h b/src/tools/tqthreadinstance_p.h new file mode 100644 index 000000000..1cc0d083e --- /dev/null +++ b/src/tools/tqthreadinstance_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQTHREAD_P_H +#define TQTHREAD_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of TQThread and TQThreadStorage. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +// + +#ifdef TQT_THREAD_SUPPORT + +#ifndef QT_H +#include "tqmutex.h" +#include "ntqwindowdefs.h" +#endif // QT_H + +#ifdef Q_OS_UNIX +#include +#endif + +class TQThread; +class TQEventLoop; + +class TQThreadInstance { +public: + static void setCurrentThread(TQThread *thread); + static TQThreadInstance *current(); + + void init(unsigned int stackSize); + void deinit(); + + TQMutex *mutex() const; + void terminate(); + + unsigned int stacksize; + void *args[2]; + void **thread_storage; + bool finished : 1; + bool running : 1; + bool orphan : 1; + +#ifdef Q_OS_UNIX + pthread_cond_t thread_done; + pthread_t thread_id; + + static void *start( void * ); + static void finish( void * ); +#endif // Q_OS_UNIX + +#ifdef Q_OS_WIN32 + TQt::HANDLE handle; + unsigned int thread_id; + int waiters; + + static unsigned int __stdcall start( void * ); + static void finish( TQThreadInstance * ); +#endif // Q_OS_WIN32 + + static void finishGuiThread( TQThreadInstance *d ); + + TQEventLoop* eventLoop; + int cleanupType; + bool disableThreadPostedEvents : 1; +}; + +#endif // TQT_THREAD_SUPPORT +#endif // TQTHREAD_P_H diff --git a/src/tools/tqthreadstorage.h b/src/tools/tqthreadstorage.h new file mode 100644 index 000000000..588621237 --- /dev/null +++ b/src/tools/tqthreadstorage.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQTHREADSTORAGE_H +#define TQTHREADSTORAGE_H + +#ifdef TQT_THREAD_SUPPORT + +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H + +class TQ_EXPORT TQThreadStorageData +{ +public: + TQThreadStorageData( void (*func)(void *) ); + ~TQThreadStorageData(); + + void** get() const; + void** set( void* p ); + + static void finish( void** ); + int id; +}; + + +template +class TQThreadStorage +{ +private: + TQThreadStorageData d; + +#if defined(TQ_DISABLE_COPY) + // disable copy constructor and operator= + TQThreadStorage( const TQThreadStorage & ); + TQThreadStorage &operator=( const TQThreadStorage & ); +#endif // TQ_DISABLE_COPY + + static void deleteData( void *x ) { delete (T)x; } + +public: + inline TQThreadStorage() : d( deleteData ) { } + inline ~TQThreadStorage() { } + + inline bool hasLocalData() const + { return d.get() != 0; } + + inline T& localData() + { void **v = d.get(); if ( !v ) v = d.set( 0 ); return *(T*)v; } + + inline T localData() const + { void **v = d.get(); return ( v ? *(T*)v : 0 ); } + + inline void setLocalData( T t ) + { (void) d.set( t ); } +}; + +#endif // TQT_THREAD_SUPPORT + +#endif // TQTHREADSTORAGE_H diff --git a/src/tools/tqthreadstorage_unix.cpp b/src/tools/tqthreadstorage_unix.cpp new file mode 100644 index 000000000..9a7e179b2 --- /dev/null +++ b/src/tools/tqthreadstorage_unix.cpp @@ -0,0 +1,366 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifdef TQT_THREAD_SUPPORT + +#include "ntqapplication.h" +#include "tqthread.h" +#include "qplatformdefs.h" + +#include "tqthreadstorage.h" +#include + +#include + +// #define TQTHREADSTORAGE_DEBUG + + +// keep this in sync with the implementation in tqthreadstorage.cpp +static const int MAX_THREAD_STORAGE = 257; // 256 maximum + 1 used in TQRegExp + +static pthread_mutex_t thread_storage_mutex = PTHREAD_MUTEX_INITIALIZER; + +static bool thread_storage_init = FALSE; +static struct { + bool used; + void (*func)( void * ); +} thread_storage_usage[MAX_THREAD_STORAGE]; + + +TQThreadStorageData::TQThreadStorageData( void (*func)( void * ) ) + : id( 0 ) +{ + pthread_mutex_lock( &thread_storage_mutex ); + + // make sure things are initialized + if ( ! thread_storage_init ) + memset( thread_storage_usage, 0, sizeof( thread_storage_usage ) ); + thread_storage_init = TRUE; + + for ( ; id < MAX_THREAD_STORAGE; ++id ) { + if ( !thread_storage_usage[id].used ) + break; + } + + Q_ASSERT( id >= 0 && id < MAX_THREAD_STORAGE ); + thread_storage_usage[id].used = TRUE; + thread_storage_usage[id].func = func; + +#ifdef TQTHREADSTORAGE_DEBUG + tqDebug( "TQThreadStorageData: allocated id %d", id ); +#endif // TQTHREADSTORAGE_DEBUG + + pthread_mutex_unlock( &thread_storage_mutex ); +} + +TQThreadStorageData::~TQThreadStorageData() +{ + // The Gui thread has static storage duration, TQThreadStorage are almost always static (it's + // technically possible to allocate those in the heap, but it's quite unusual). It's impossible + // to predict whichever of those one gets destroyed first, but usually it's a TQThreadStorage. + // In that case we have to do the cleanup of its storage ourself as it won't be possible after + // nullifying the destructor below. + TQThread *guiThread = TQApplication::guiThread(); + if (guiThread) { + TQThreadInstance *d = guiThread->d; + TQMutexLocker locker( d->mutex() ); + if (d->thread_storage && d->thread_storage[id]) { + thread_storage_usage[id].func( d->thread_storage[id] ); + d->thread_storage[id] = nullptr; + } + } + + pthread_mutex_lock( &thread_storage_mutex ); + thread_storage_usage[id].used = FALSE; + thread_storage_usage[id].func = 0; + +#ifdef TQTHREADSTORAGE_DEBUG + tqDebug( "TQThreadStorageData: released id %d", id ); +#endif // TQTHREADSTORAGE_DEBUG + + pthread_mutex_unlock( &thread_storage_mutex ); +} + +void **TQThreadStorageData::get() const +{ + TQThreadInstance *d = TQThreadInstance::current(); + if (!d) { + tqWarning("TQThreadStorage can only be used with threads started with TQThread"); + return 0; + } + TQMutexLocker locker( d->mutex() ); + return d->thread_storage && d->thread_storage[id] ? &d->thread_storage[id] : 0; +} + +void **TQThreadStorageData::set( void *p ) +{ + TQThreadInstance *d = TQThreadInstance::current(); + if (!d) { + tqWarning("TQThreadStorage can only be used with threads started with TQThread"); + return 0; + } + TQMutexLocker locker( d->mutex() ); + if ( !d->thread_storage ) { +#ifdef TQTHREADSTORAGE_DEBUG + tqDebug( "TQThreadStorageData: allocating storage for thread %lx", + (unsigned long) pthread_self() ); +#endif // TQTHREADSTORAGE_DEBUG + + d->thread_storage = new void*[MAX_THREAD_STORAGE]; + memset( d->thread_storage, 0, sizeof( void* ) * MAX_THREAD_STORAGE ); + } + + // delete any previous data + if ( d->thread_storage[id] ) + thread_storage_usage[id].func( d->thread_storage[id] ); + + // store new data + d->thread_storage[id] = p; + return &d->thread_storage[id]; +} + +void TQThreadStorageData::finish( void **thread_storage ) +{ + if ( ! thread_storage ) return; // nothing to do + +#ifdef TQTHREADSTORAGE_DEBUG + tqDebug( "TQThreadStorageData: destroying storage for thread %lx", + (unsigned long) pthread_self() ); +#endif // TQTHREADSTORAGE_DEBUG + + for ( int i = 0; i < MAX_THREAD_STORAGE; ++i ) { + if ( ! thread_storage[i] ) continue; + if ( ! thread_storage_usage[i].used ) { +#ifdef QT_CHECK_STATE + tqWarning( "TQThreadStorage: thread %lx exited after TQThreadStorage destroyed", + (unsigned long) pthread_self() ); +#endif // QT_CHECK_STATE + continue; + } + + thread_storage_usage[i].func( thread_storage[i] ); + } + + delete [] thread_storage; +} + + +/*! + \class TQThreadStorage + \brief The TQThreadStorage class provides per-thread data storage. + + \threadsafe + \ingroup thread + \ingroup environment + + TQThreadStorage is a template class that provides per-thread data + storage. + + \e{Note that due to compiler limitations, TQThreadStorage can only + store pointers.} + + The setLocalData() function stores a single thread-specific value + for the calling thread. The data can be accessed later using the + localData() functions. TQThreadStorage takes ownership of the + data (which must be created on the heap with \e new) and deletes + it when the thread exits (either normally or via termination). + + The hasLocalData() function allows the programmer to determine if + data has previously been set using the setLocalData() function. + This is useful for lazy initializiation. + + For example, the following code uses TQThreadStorage to store a + single cache for each thread that calls the \e cacheObject() and + \e removeFromCache() functions. The cache is automatically + deleted when the calling thread exits (either normally or via + termination). + + \code + TQThreadStorage *> caches; + + void cacheObject( const TQString &key, SomeClass *object ) + { + if ( ! caches.hasLocalData() ) + caches.setLocalData( new TQCache ); + + caches.localData()->insert( key, object ); + } + + void removeFromCache( const TQString &key ) + { + if ( ! caches.hasLocalData() ) + return; // nothing to do + + caches.localData()->remove( key ); + } + \endcode + + \section1 Caveats + + \list + + \i As noted above, TQThreadStorage can only store pointers due to + compiler limitations. Support for value-based objects will be + added when the majority of compilers are able to support partial + template specialization. + + \i The \link ~TQThreadStorage() destructor\endlink does \e not + delete per-thread data. TQThreadStorage only deletes per-thread + data when the thread exits or when setLocalData() is called + multiple times. + + \i TQThreadStorage can only be used with threads started with + TQThread. It \e cannot be used with threads started with + platform-specific APIs. + + \i As a corollary to the above, platform-specific APIs cannot be + used to exit or terminate a TQThread using TQThreadStorage. Doing so + will cause all per-thread data to be leaked. See TQThread::exit() + and TQThread::terminate(). + + \i TQThreadStorage \e can be used to store data for the \e main() + thread \e after TQApplication has been constructed. TQThreadStorage + deletes all data set for the \e main() thread when TQApplication is + destroyed, regardless of whether or not the \e main() thread has + actually finished. + + \i The implementation of TQThreadStorage limits the total number of + TQThreadStorage objects to 256. An unlimited number of threads + can store per-thread data in each TQThreadStorage object. + + \endlist +*/ + +/*! + \fn TQThreadStorage::TQThreadStorage() + + Constructs a new per-thread data storage object. +*/ + +/*! + \fn TQThreadStorage::~TQThreadStorage() + + Destroys the per-thread data storage object. + + Note: The per-thread data stored is \e not deleted. Any data left + in TQThreadStorage is leaked. Make sure that all threads using + TQThreadStorage have exited before deleting the TQThreadStorage. + + \sa hasLocalData() +*/ + +/*! + \fn bool TQThreadStorage::hasLocalData() const + + Returns TRUE if the calling thread has non-zero data available; + otherwise returns FALSE. + + \sa localData() +*/ + +/*! + \fn T& TQThreadStorage::localData() + + Returns a reference to the data that was set by the calling + thread. + + Note: TQThreadStorage can only store pointers. This function + returns a \e reference to the pointer that was set by the calling + thread. The value of this reference is 0 if no data was set by + the calling thread, + + \sa hasLocalData() +*/ +/* + ### addition to the above documentation when we start supporting + ### partial template specialization, and TQThreadStorage can store + ### values *and* pointers + + When using TQThreadStorage to store values (not pointers), this + function stores an object of type \e T (created with its default + constructor) and returns a reference to that object. +*/ + +/*! + \fn const T TQThreadStorage::localData() const + \overload + + Returns a copy of the data that was set by the calling thread. + + Note: TQThreadStorage can only store pointers. This function + returns a pointer to the data that was set by the calling thread. + If no data was set by the calling thread, this function returns 0. + + \sa hasLocalData() +*/ +/* + ### addition to the above documentation when we start supporting + ### partial template specialization, and TQThreadStorage can store + ### values *and* pointers + + When using TQThreadStorage to store values (not pointers), this + function returns an object of type \e T (created with its default + constructor). Unlike the above function, this object is \e not + stored automatically. You will need to call setLocalData() to store + the object. +*/ + +/*! + \fn void TQThreadStorage::setLocalData( T data ) + + Sets the local data for the calling thread to \a data. It can be + accessed later using the localData() functions. + + If \a data is 0, this function deletes the previous data (if + any) and returns immediately. + + If \a data is non-zero, TQThreadStorage takes ownership of the \a + data and deletes it automatically either when the thread exits + (either normally or via termination) or when setLocalData() is + called again. + + Note: TQThreadStorage can only store pointers. The \a data + argument must be either a pointer to an object created on the heap + (i.e. using \e new) or 0. You should not delete \a data + yourself; TQThreadStorage takes ownership and will delete the \a + data itself. + + \sa localData() hasLocalData() +*/ + +#endif // TQT_THREAD_SUPPORT diff --git a/src/tools/tqwaitcondition.h b/src/tools/tqwaitcondition.h new file mode 100644 index 000000000..503d5d6c9 --- /dev/null +++ b/src/tools/tqwaitcondition.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Definition of TQWaitCondition class +** +** Created : 931107 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQWAITCONDITION_H +#define TQWAITCONDITION_H + +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H + +#if defined(TQT_THREAD_SUPPORT) + +#include + +class TQWaitConditionPrivate; +class TQMutex; + +class TQ_EXPORT TQWaitCondition +{ +public: + TQWaitCondition(); + virtual ~TQWaitCondition(); + + // default argument causes thread to block indefinately + bool wait( unsigned long time = ULONG_MAX ); + bool wait( TQMutex *mutex, unsigned long time = ULONG_MAX ); + + void wakeOne(); + void wakeAll(); + +private: + TQWaitConditionPrivate * d; + +#if defined(TQ_DISABLE_COPY) + TQWaitCondition( const TQWaitCondition & ); + TQWaitCondition &operator=( const TQWaitCondition & ); +#endif +}; + +#endif + +#endif diff --git a/src/tools/tqwaitcondition_unix.cpp b/src/tools/tqwaitcondition_unix.cpp new file mode 100644 index 000000000..78fdb16bc --- /dev/null +++ b/src/tools/tqwaitcondition_unix.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** TQWaitCondition class for Unix +** +** Created : 20010725 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#if defined(TQT_THREAD_SUPPORT) + +#include "qplatformdefs.h" + +typedef pthread_mutex_t Q_MUTEX_T; + +#include "tqwaitcondition.h" +#include "tqmutex.h" +#include "tqmutex_p.h" + +#include +#include + + +struct TQWaitConditionPrivate { + pthread_cond_t cond; +}; + + +/*! + \class TQWaitCondition tqwaitcondition.h + \threadsafe + \brief The TQWaitCondition class allows waiting/waking for conditions between threads. + + \ingroup thread + \ingroup environment + + TQWaitConditions allow a thread to tell other threads that some + sort of condition has been met; one or many threads can block + waiting for a TQWaitCondition to set a condition with wakeOne() or + wakeAll(). Use wakeOne() to wake one randomly selected event or + wakeAll() to wake them all. For example, say we have three tasks + that should be performed every time the user presses a key; each + task could be split into a thread, each of which would have a + run() body like this: + + \code + TQWaitCondition key_pressed; + + for (;;) { + key_pressed.wait(); // This is a TQWaitCondition global variable + // Key was pressed, do something interesting + do_something(); + } + \endcode + + A fourth thread would read key presses and wake the other three + threads up every time it receives one, like this: + + \code + TQWaitCondition key_pressed; + + for (;;) { + getchar(); + // Causes any thread in key_pressed.wait() to return from + // that method and continue processing + key_pressed.wakeAll(); + } + \endcode + + Note that the order the three threads are woken up in is + undefined, and that if some or all of the threads are still in + do_something() when the key is pressed, they won't be woken up + (since they're not waiting on the condition variable) and so the + task will not be performed for that key press. This can be + avoided by, for example, doing something like this: + + \code + TQMutex mymutex; + TQWaitCondition key_pressed; + int mycount=0; + + // Worker thread code + for (;;) { + key_pressed.wait(); // This is a TQWaitCondition global variable + mymutex.lock(); + mycount++; + mymutex.unlock(); + do_something(); + mymutex.lock(); + mycount--; + mymutex.unlock(); + } + + // Key reading thread code + for (;;) { + getchar(); + mymutex.lock(); + // Sleep until there are no busy worker threads + while( mycount > 0 ) { + mymutex.unlock(); + sleep( 1 ); + mymutex.lock(); + } + mymutex.unlock(); + key_pressed.wakeAll(); + } + \endcode + + The mutexes are necessary because the results of two threads + attempting to change the value of the same variable simultaneously + are unpredictable. +*/ + +/*! + Constructs a new event signalling, i.e. wait condition, object. +*/ +TQWaitCondition::TQWaitCondition() +{ + d = new TQWaitConditionPrivate; + + int ret = pthread_cond_init(&d->cond, NULL); + +#ifdef QT_CHECK_RANGE + if (ret) + tqWarning( "Wait condition init failure: %s", strerror( ret ) ); +#endif +} + + +/*! + Deletes the event signalling, i.e. wait condition, object. +*/ +TQWaitCondition::~TQWaitCondition() +{ + int ret = pthread_cond_destroy(&d->cond); + + if (ret) { +#ifdef QT_CHECK_RANGE + tqWarning( "Wait condition destroy failure: %s", strerror( ret ) ); +#endif + + // seems we have threads waiting on us, lets wake them up + pthread_cond_broadcast(&d->cond); + } + + delete d; +} + +/*! + This wakes one thread waiting on the TQWaitCondition. The thread + that is woken up depends on the operating system's scheduling + policies, and cannot be controlled or predicted. + + \sa wakeAll() +*/ +void TQWaitCondition::wakeOne() +{ + int ret = pthread_cond_signal(&d->cond); + +#ifdef QT_CHECK_RANGE + if (ret) + tqWarning("Wait condition wakeOne failure: %s", strerror(ret)); +#endif +} + +/*! + This wakes all threads waiting on the TQWaitCondition. The order in + which the threads are woken up depends on the operating system's + scheduling policies, and cannot be controlled or predicted. + + \sa wakeOne() +*/ +void TQWaitCondition::wakeAll() +{ + int ret = pthread_cond_broadcast(&d->cond); + +#ifdef QT_CHECK_RANGE + if (ret) + tqWarning("Wait condition wakeAll failure: %s", strerror(ret)); +#endif +} + +/*! + Wait on the thread event object. The thread calling this will + block until either of these conditions is met: + \list + \i Another thread signals it using wakeOne() or wakeAll(). This + function will return TRUE in this case. + \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the + default), then the wait will never timeout (the event must be + signalled). This function will return FALSE if the wait timed + out. + \endlist + + \sa wakeOne(), wakeAll() +*/ +bool TQWaitCondition::wait(unsigned long time) +{ + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock( &mutex ); + + int ret; + if (time != ULONG_MAX) { + struct timeval tv; + gettimeofday(&tv, 0); + + timespec ti; + ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; + ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); + ti.tv_nsec %= 1000000000; + + ret = pthread_cond_timedwait(&d->cond, &mutex, &ti); + } else + ret = pthread_cond_wait(&d->cond, &mutex); + +#ifdef QT_CHECK_RANGE + if (ret && ret != ETIMEDOUT) + tqWarning("Wait condition wait failure: %s",strerror(ret)); +#endif + + pthread_mutex_unlock( &mutex ); + + return (ret == 0); +} + +/*! + \overload + + Release the locked \a mutex and wait on the thread event object. + The \a mutex must be initially locked by the calling thread. If \a + mutex is not in a locked state, this function returns immediately. + If \a mutex is a recursive mutex, this function returns + immediately. The \a mutex will be unlocked, and the calling thread + will block until either of these conditions is met: + \list + \i Another thread signals it using wakeOne() or wakeAll(). This + function will return TRUE in this case. + \i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the + default), then the wait will never timeout (the event must be + signalled). This function will return FALSE if the wait timed + out. + \endlist + + The mutex will be returned to the same locked state. This function + is provided to allow the atomic transition from the locked state + to the wait state. + + \sa wakeOne(), wakeAll() +*/ +bool TQWaitCondition::wait(TQMutex *mutex, unsigned long time) +{ + if (! mutex) + return FALSE; + + if (mutex->d->type() == Q_MUTEX_RECURSIVE) { +#ifdef QT_CHECK_RANGE + tqWarning("Wait condition warning: using recursive mutexes with\n" + " wait conditions is undefined!"); +#endif + return FALSE; + } + + int ret; + if (time != ULONG_MAX) { + struct timeval tv; + gettimeofday(&tv, 0); + + timespec ti; + ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; + ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); + ti.tv_nsec %= 1000000000; + + ret = pthread_cond_timedwait(&d->cond, &mutex->d->handle, &ti); + } else + ret = pthread_cond_wait(&d->cond, &mutex->d->handle); + +#ifdef QT_CHECK_RANGE + if (ret && ret != ETIMEDOUT) + tqWarning("Wait condition wait failure: %s",strerror(ret)); +#endif + + return (ret == 0); +} + +#endif // TQT_THREAD_SUPPORT diff --git a/tutorial/t15/main.h b/tutorial/t15/main.h index ed39316be..0b3697514 100644 --- a/tutorial/t15/main.h +++ b/tutorial/t15/main.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include class MainObject; -- cgit v1.2.3