svcore  1.9
Serialiser.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "Serialiser.h"
17 
18 #include <iostream>
19 
20 QMutex
22 
23 std::map<QString, QMutex *>
25 
27  m_id(id)
28 {
29  m_mapMutex.lock();
30 
31  if (m_mutexMap.find(m_id) == m_mutexMap.end()) {
32  m_mutexMap[m_id] = new QMutex;
33  }
34 
35  // The id mutexes are never deleted, so once we have a reference
36  // to the one we need, we can hold on to it while we release the
37  // map mutex. We need to release the map mutex, otherwise if the
38  // id mutex is currently held, it will never be released (because
39  // the destructor needs to hold the map mutex to release the id
40  // mutex).
41 
42  QMutex *idMutex = m_mutexMap[m_id];
43 
44  m_mapMutex.unlock();
45 
46  idMutex->lock();
47 }
48 
50 {
51  m_mapMutex.lock();
52 
53  m_mutexMap[m_id]->unlock();
54 
55  m_mapMutex.unlock();
56 }
57 
58 
59 
static QMutex m_mapMutex
Definition: Serialiser.h:34
QString m_id
Definition: Serialiser.h:33
static std::map< QString, QMutex * > m_mutexMap
Definition: Serialiser.h:35
Serialiser(QString id)
Definition: Serialiser.cpp:26