summaryrefslogtreecommitdiff
path: root/qmake/tools/qmutex_unix.cpp
Unidiff
Diffstat (limited to 'qmake/tools/qmutex_unix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qmutex_unix.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/qmake/tools/qmutex_unix.cpp b/qmake/tools/qmutex_unix.cpp
index c861b2d..3eb59cf 100644
--- a/qmake/tools/qmutex_unix.cpp
+++ b/qmake/tools/qmutex_unix.cpp
@@ -1,95 +1,96 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** QMutex class for Unix 4** QMutex class for Unix
5** 5**
6** Created : 20010725 6** Created : 20010725
7** 7**
8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the tools module of the Qt GUI Toolkit. 10** This file is part of the tools module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#if defined(QT_THREAD_SUPPORT) 38#if defined(QT_THREAD_SUPPORT)
39 39
40#include "qplatformdefs.h" 40#include "qplatformdefs.h"
41 41
42typedef pthread_mutex_t Q_MUTEX_T; 42typedef pthread_mutex_t Q_MUTEX_T;
43 43
44// POSIX threads mutex types 44// POSIX threads mutex types
45#if ((defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_DEFAULT)) || \ 45#if ((defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_DEFAULT)) || \
46 defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS) 46 defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS) && \
47 // POSIX 1003.1c-1995 - We love this OS 47 !defined(Q_OS_MAC)
48// POSIX 1003.1c-1995 - We love this OS
48# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_settype((a), (b)) 49# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_settype((a), (b))
49# if defined(QT_CHECK_RANGE) 50# if defined(QT_CHECK_RANGE)
50# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK 51# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK
51# else 52# else
52# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT 53# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT
53# endif 54# endif
54# define Q_RECURSIVE_MUTEX_TYPE PTHREAD_MUTEX_RECURSIVE 55# define Q_RECURSIVE_MUTEX_TYPE PTHREAD_MUTEX_RECURSIVE
55#elif defined(MUTEX_NONRECURSIVE_NP) && defined(MUTEX_RECURSIVE_NP) 56#elif defined(MUTEX_NONRECURSIVE_NP) && defined(MUTEX_RECURSIVE_NP)
56// POSIX 1003.4a pthreads draft extensions 57// POSIX 1003.4a pthreads draft extensions
57# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_setkind_np((a), (b)); 58# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_setkind_np((a), (b));
58# define Q_NORMAL_MUTEX_TYPE MUTEX_NONRECURSIVE_NP 59# define Q_NORMAL_MUTEX_TYPE MUTEX_NONRECURSIVE_NP
59# define Q_RECURSIVE_MUTEX_TYPE MUTEX_RECURSIVE_NP 60# define Q_RECURSIVE_MUTEX_TYPE MUTEX_RECURSIVE_NP
60#else 61#else
61// Unknown mutex types - skip them 62// Unknown mutex types - skip them
62# define Q_MUTEX_SET_TYPE(a, b) 63# define Q_MUTEX_SET_TYPE(a, b)
63# undef Q_NORMAL_MUTEX_TYPE 64# undef Q_NORMAL_MUTEX_TYPE
64# undef Q_RECURSIVE_MUTEX_TYPE 65# undef Q_RECURSIVE_MUTEX_TYPE
65#endif 66#endif
66 67
67#include "qmutex.h" 68#include "qmutex.h"
68#include "qmutex_p.h" 69#include "qmutex_p.h"
69 70
70#include <errno.h> 71#include <errno.h>
71#include <string.h> 72#include <string.h>
72 73
73 74
74// Private class declarations 75// Private class declarations
75 76
76class QRealMutexPrivate : public QMutexPrivate { 77class QRealMutexPrivate : public QMutexPrivate {
77public: 78public:
78 QRealMutexPrivate(bool = FALSE); 79 QRealMutexPrivate(bool = FALSE);
79 80
80 void lock(); 81 void lock();
81 void unlock(); 82 void unlock();
82 bool locked(); 83 bool locked();
83 bool trylock(); 84 bool trylock();
84 int type() const; 85 int type() const;
85 86
86 bool recursive; 87 bool recursive;
87}; 88};
88 89
89#ifndef Q_RECURSIVE_MUTEX_TYPE 90#ifndef Q_RECURSIVE_MUTEX_TYPE
90class QRecursiveMutexPrivate : public QMutexPrivate 91class QRecursiveMutexPrivate : public QMutexPrivate
91{ 92{
92public: 93public:
93 QRecursiveMutexPrivate(); 94 QRecursiveMutexPrivate();
94 ~QRecursiveMutexPrivate(); 95 ~QRecursiveMutexPrivate();
95 96
@@ -616,72 +617,73 @@ bool QMutex::tryLock()
616 object is destroyed (when the function returns since \c locker is 617 object is destroyed (when the function returns since \c locker is
617 an auto variable). 618 an auto variable).
618 619
619 The same principle applies to code that throws and catches 620 The same principle applies to code that throws and catches
620 exceptions. An exception that is not caught in the function that 621 exceptions. An exception that is not caught in the function that
621 has locked the mutex has no way of unlocking the mutex before the 622 has locked the mutex has no way of unlocking the mutex before the
622 exception is passed up the stack to the calling function. 623 exception is passed up the stack to the calling function.
623 624
624 QMutexLocker also provides a mutex() member function that returns 625 QMutexLocker also provides a mutex() member function that returns
625 the mutex on which the QMutexLocker is operating. This is useful 626 the mutex on which the QMutexLocker is operating. This is useful
626 for code that needs access to the mutex, such as 627 for code that needs access to the mutex, such as
627 QWaitCondition::wait(). For example: 628 QWaitCondition::wait(). For example:
628 629
629 \code 630 \code
630 class SignalWaiter 631 class SignalWaiter
631 { 632 {
632 private: 633 private:
633 QMutexLocker locker; 634 QMutexLocker locker;
634 635
635 public: 636 public:
636 SignalWaiter( QMutex *mutex ) 637 SignalWaiter( QMutex *mutex )
637 : locker( mutex ) 638 : locker( mutex )
638 { 639 {
639 } 640 }
640 641
641 void waitForSignal() 642 void waitForSignal()
642 { 643 {
643 ... 644 ...
644 ... 645 ...
645 ... 646 ...
646 647
647 while ( ! signalled ) 648 while ( ! signalled )
648 waitcondition.wait( locker.mutex() ); 649 waitcondition.wait( locker.mutex() );
649 650
650 ... 651 ...
651 ... 652 ...
652 ... 653 ...
653 } 654 }
654 }; 655 };
655 \endcode 656 \endcode
656 657
657 \sa QMutex, QWaitCondition 658 \sa QMutex, QWaitCondition
658*/ 659*/
659 660
660/*! 661/*!
661 \fn QMutexLocker::QMutexLocker( QMutex *mutex ) 662 \fn QMutexLocker::QMutexLocker( QMutex *mutex )
662 663
663 Constructs a QMutexLocker and locks \a mutex. The mutex will be 664 Constructs a QMutexLocker and locks \a mutex. The mutex will be
664 unlocked when the QMutexLocker is destroyed. 665 unlocked when the QMutexLocker is destroyed. If \a mutex is zero,
666 QMutexLocker does nothing.
665 667
666 \sa QMutex::lock() 668 \sa QMutex::lock()
667*/ 669*/
668 670
669/*! 671/*!
670 \fn QMutexLocker::~QMutexLocker() 672 \fn QMutexLocker::~QMutexLocker()
671 673
672 Destroys the QMutexLocker and unlocks the mutex which was locked 674 Destroys the QMutexLocker and unlocks the mutex which was locked
673 in the constructor. 675 in the constructor.
674 676
675 \sa QMutexLocker::QMutexLocker(), QMutex::unlock() 677 \sa QMutexLocker::QMutexLocker(), QMutex::unlock()
676*/ 678*/
677 679
678/*! 680/*!
679 \fn QMutex *QMutexLocker::mutex() const 681 \fn QMutex *QMutexLocker::mutex() const
680 682
681 Returns a pointer to the mutex which was locked in the 683 Returns a pointer to the mutex which was locked in the
682 constructor. 684 constructor.
683 685
684 \sa QMutexLocker::QMutexLocker() 686 \sa QMutexLocker::QMutexLocker()
685*/ 687*/
686 688
687#endif // QT_THREAD_SUPPORT 689#endif // QT_THREAD_SUPPORT