Chris@297: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@297: Chris@297: /* Chris@297: Sonic Visualiser Chris@297: An audio file viewer and annotation editor. Chris@297: Centre for Digital Music, Queen Mary, University of London. Chris@297: This file copyright 2007 QMUL. Chris@297: Chris@297: This program is free software; you can redistribute it and/or Chris@297: modify it under the terms of the GNU General Public License as Chris@297: published by the Free Software Foundation; either version 2 of the Chris@297: License, or (at your option) any later version. See the file Chris@297: COPYING included with this distribution for more information. Chris@297: */ Chris@297: Chris@1581: #ifndef SV_SERIALISER_H Chris@1581: #define SV_SERIALISER_H Chris@297: Chris@297: #include Chris@297: #include Chris@297: Chris@297: #include Chris@1857: #include Chris@297: Chris@297: class Serialiser Chris@297: { Chris@297: public: Chris@1857: /** Chris@1857: * Construct a serialiser that takes the lock associated with the Chris@1857: * given id. That is, the constructor will only complete after all Chris@1857: * existing serialisers with the given id have been deleted. Chris@1857: */ Chris@297: Serialiser(QString id); Chris@1857: Chris@1857: /** Chris@1857: * Construct a cancellable serialiser that takes the lock Chris@1857: * associated with the given id. That is, the constructor will Chris@1857: * only complete when all existing serialisers with the given id Chris@1857: * have been deleted, or when the (occasionally polled) bool flag Chris@1857: * pointed to by cancelled has been found to be true. Chris@1857: */ Chris@1857: Serialiser(QString id, const std::atomic *cancelled); Chris@1857: Chris@1857: /** Chris@1857: * Release the lock associated with the given id (if taken, rather Chris@1857: * than cancelled). Chris@1857: */ Chris@297: ~Serialiser(); Chris@297: Chris@406: QString getId() const { return m_id; } Chris@406: Chris@297: protected: Chris@297: QString m_id; Chris@1857: const std::atomic *m_cancelled; Chris@1857: bool m_locked; Chris@297: static QMutex m_mapMutex; Chris@297: static std::map m_mutexMap; Chris@297: }; Chris@297: Chris@297: #endif