diff options
author | Albert Astals Cid <aacid@kde.org> | 2013-03-03 19:07:32 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2013-03-03 19:07:32 +0100 |
commit | 677e5b265a0d39a988f65d642a4f964a279fad28 (patch) | |
tree | 21d6abb9fde21ce27ee03c81a9d60116630dda10 /goo | |
parent | d5c929fc253c2748bb8fa3642d9b5383c5fe96f8 (diff) |
Small improvements over locker class
* Remove the namespace (we don't use much/any namespaces in poppler core)
* Rename the class and defines from lock to locker since lock and be either the action "to lock" or the "thing that locks", with locker it is more clear (i think) that is "the thing" than "the action"
* Make Annot::decRefCnt use gLockMutex since we the object itself is being deleted in the if and not sure the locker would be happy with that
* change the getNumPages() param to be DoNotLockMutex since previously it was a gFalse (i guess Thomas made a c&p typo here)
* Have only one constructor like Adam suggested.
Diffstat (limited to 'goo')
-rw-r--r-- | goo/GooMutex.h | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/goo/GooMutex.h b/goo/GooMutex.h index fbef476b..591a7d44 100644 --- a/goo/GooMutex.h +++ b/goo/GooMutex.h @@ -16,6 +16,8 @@ // under GPL version 2 or later // // Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net> +// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> +// Copyright (C) 2013 Albert Astals Cid <aacid@kde.org> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -60,20 +62,19 @@ typedef pthread_mutex_t GooMutex; #endif -namespace Poppler { - enum LockMode { - DoNotLock, // for conditional locks: do not lock - DoLock // for conditional locks: do lock - }; - - class Lock { - public: - Lock(GooMutex *mutexA) : mutex(mutexA) { mode = DoLock; gLockMutex(mutex); } - Lock(GooMutex *mutexA, LockMode modeA) : mutex(mutexA) { mode = modeA; if (mode == DoLock) gLockMutex(mutex); } - ~Lock() { if (mode == DoLock) gUnlockMutex(mutex); } - private: - GooMutex *mutex; - LockMode mode; - }; -} +enum MutexLockMode { + DoNotLockMutex, // for conditional locks: do not lock + DoLockMutex // for conditional locks: do lock +}; + +class MutexLocker { +public: + MutexLocker(GooMutex *mutexA, MutexLockMode modeA = DoLockMutex) : mutex(mutexA), mode(modeA) { if (mode == DoLockMutex) gLockMutex(mutex); } + ~MutexLocker() { if (mode == DoLockMutex) gUnlockMutex(mutex); } + +private: + GooMutex *mutex; + const MutexLockMode mode; +}; + #endif |