Bug 92511 - Review: utilities/cameragui/mtqueue.h use bad locking style
Summary: Review: utilities/cameragui/mtqueue.h use bad locking style
Status: RESOLVED INTENTIONAL
Alias: None
Product: digikam
Classification: Applications
Component: Import-MainView (show other bugs)
Version: 0.7.0
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-01 11:14 UTC by lan
Modified: 2017-07-19 09:34 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Better locking style (1.52 KB, patch)
2004-11-01 11:14 UTC, lan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description lan 2004-11-01 11:14:19 UTC
Version:           0.7-beta1 (using KDE 3.2.1, SuSE)
Compiler:          gcc version 3.3.3 (SuSE Linux)
OS:                Linux (i686) release 2.6.5-7.111-default

It use something like this:
{
  mutex.lock();
  do_something();
  mutex.unloack();
}

in case of exception or other error lock will not be unlocked.
Qt suggest better style by using QMutexLocker:
{
  QMutexLocker locker(&mutex);
  do_something();
}

locker lock mutex in constructor and unlock it in the destructor
and as far as it created on the stack it WILL be unlocked.
Patch attached.
Comment 1 lan 2004-11-01 11:14:56 UTC
Created attachment 8121 [details]
Better locking style
Comment 2 lan 2004-11-01 11:17:11 UTC
Forgot to add:
this patch also remove lock() and unlock() methods in mtqueue
and aslo make method head() without argument. These methods are not 
used at now.
Comment 3 Renchi Raju 2004-11-01 18:00:50 UTC
can you give me an example of a case where the mutex will not be unlocked? And digikam doesn't use exceptions. QMutexLocker is just a convenience function for locking and unlocking mutex, so that the programmer doesn't have to remember to unlock the mutex for each scenario.
Comment 4 lan 2004-11-02 03:55:59 UTC
You are right, where are can be any exceptions. That is why original code is working right. I just thought it would be better to make code nicer.
Comment 5 Renchi Raju 2004-11-04 02:41:29 UTC
not using qmutexlocker is not a sin :)