/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. #if QT_VERSION >= 0x040400 || defined( DOXYGEN_RUN )
  3. #include <QSharedMemory>
  4. using namespace kdtools;
  5. /*!
  6. \class KDSharedMemoryLocker
  7. \ingroup raii core
  8. \brief Exception-safe and convenient wrapper around QSharedMemory::lock()
  9. */
  10. /**
  11. * Constructor. Locks the shared memory segment \a mem.
  12. * If another process has locking the segment, this constructor blocks
  13. * until the lock is released. The memory segments needs to be properly created or attached.
  14. */
  15. KDSharedMemoryLocker::KDSharedMemoryLocker( QSharedMemory* mem )
  16. : mem( mem )
  17. {
  18. mem->lock();
  19. }
  20. /**
  21. * Destructor. Unlocks the shared memory segment associated with this
  22. * KDSharedMemoryLocker.
  23. */
  24. KDSharedMemoryLocker::~KDSharedMemoryLocker()
  25. {
  26. mem->unlock();
  27. }
  28. #ifdef KDAB_EVAL
  29. #include KDAB_EVAL
  30. static const EvalDialogChecker evalChecker( "KD Tools", false );
  31. #endif
  32. #endif