Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95869

Consider introducing a QTryMutexLocker in addition to QMutexLocker

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 5.15
    • Core: Threads
    • None
    • All multithread could use that.

    • All

    Description

      Would be nice to have the QTryMutexLocker along the QMutexLocker.

       

      Something like this:

      class QTryMutexLocker
      {
      public:  
        QTryMutexLocker(QMutex &m, int timeout = 0);  ~TryMutexLocker();
        bool isLocked() const;
      private:  
        QMutex &m_mutex;  bool m_locked;
      };
      
      QTryMutexLocker::QTryMutexLocker(QMutex &m, int timeout)
          : m_mutex(m)
          , m_locked(m.tryLock(timeout))
      {
      }
      
      QTryMutexLocker::~QTryMutexLocker()
      {
          if(m_locked)
              m_mutex.unlock();
      }
      
      bool QTryMutexLocker::isLocked() const
      {
          return m_locked;
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sonakur Sona Kurazyan
            jeromegodboutamotus Jerome Godbout
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes