PageRenderTime 132ms CodeModel.GetById 50ms app.highlight 8ms RepoModel.GetById 43ms app.codeStats 0ms

/src/libtomahawk/thirdparty/kdsingleapplicationguard/kdsharedmemorylocker.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 40 lines | 18 code | 8 blank | 14 comment | 1 complexity | a29347d5841b320fbd47b91270fa0a94 MD5 | raw file
 1#include "kdsharedmemorylocker.h"
 2
 3#if QT_VERSION >= 0x040400 || defined( DOXYGEN_RUN )
 4
 5#include <QSharedMemory>
 6
 7using namespace kdtools;
 8
 9/*!
10  \class KDSharedMemoryLocker
11  \ingroup raii core
12  \brief Exception-safe and convenient wrapper around QSharedMemory::lock()
13*/
14
15/**
16 * Constructor. Locks the shared memory segment \a mem.
17 * If another process has locking the segment, this constructor blocks
18 * until the lock is released. The memory segments needs to be properly created or attached.
19 */
20KDSharedMemoryLocker::KDSharedMemoryLocker( QSharedMemory* mem )
21    : mem( mem )
22{
23    mem->lock();
24}
25
26/**
27 * Destructor. Unlocks the shared memory segment associated with this
28 * KDSharedMemoryLocker.
29 */
30KDSharedMemoryLocker::~KDSharedMemoryLocker()
31{
32    mem->unlock();
33}
34
35#ifdef KDAB_EVAL
36#include KDAB_EVAL
37static const EvalDialogChecker evalChecker( "KD Tools", false );
38#endif
39
40#endif