comparison data/model/EditableDenseThreeDimensionalModel.cpp @ 536:beb51f558e9c

* Change QMutex in Editable DTDM to a read/write lock
author Chris Cannam
date Mon, 26 Jan 2009 15:18:32 +0000
parents 3ccf48fb81d6
children 3cc4b7cd2aa5
comparison
equal deleted inserted replaced
535:3ccf48fb81d6 536:beb51f558e9c
17 17
18 #include "base/LogRange.h" 18 #include "base/LogRange.h"
19 19
20 #include <QTextStream> 20 #include <QTextStream>
21 #include <QStringList> 21 #include <QStringList>
22 #include <QReadLocker>
23 #include <QWriteLocker>
22 24
23 #include <iostream> 25 #include <iostream>
24 26
25 #include <cmath> 27 #include <cmath>
26 #include <cassert> 28 #include <cassert>
69 } 71 }
70 72
71 Model * 73 Model *
72 EditableDenseThreeDimensionalModel::clone() const 74 EditableDenseThreeDimensionalModel::clone() const
73 { 75 {
74 QMutexLocker locker(&m_mutex); 76 QReadLocker locker(&m_lock);
75 77
76 EditableDenseThreeDimensionalModel *model = 78 EditableDenseThreeDimensionalModel *model =
77 new EditableDenseThreeDimensionalModel 79 new EditableDenseThreeDimensionalModel
78 (m_sampleRate, m_resolution, m_yBinCount, m_compression); 80 (m_sampleRate, m_resolution, m_yBinCount, m_compression);
79 81
143 } 145 }
144 146
145 EditableDenseThreeDimensionalModel::Column 147 EditableDenseThreeDimensionalModel::Column
146 EditableDenseThreeDimensionalModel::getColumn(size_t index) const 148 EditableDenseThreeDimensionalModel::getColumn(size_t index) const
147 { 149 {
148 QMutexLocker locker(&m_mutex); 150 QReadLocker locker(&m_lock);
149 if (index >= m_data.size()) return Column(); 151 if (index >= m_data.size()) return Column();
150 return expandAndRetrieve(index); 152 return expandAndRetrieve(index);
151 } 153 }
152 154
153 float 155 float
306 308
307 void 309 void
308 EditableDenseThreeDimensionalModel::setColumn(size_t index, 310 EditableDenseThreeDimensionalModel::setColumn(size_t index,
309 const Column &values) 311 const Column &values)
310 { 312 {
311 QMutexLocker locker(&m_mutex); 313 QWriteLocker locker(&m_lock);
312 314
313 while (index >= m_data.size()) { 315 while (index >= m_data.size()) {
314 m_data.push_back(Column()); 316 m_data.push_back(Column());
315 m_trunc.push_back(0); 317 m_trunc.push_back(0);
316 } 318 }
389 } 391 }
390 392
391 bool 393 bool
392 EditableDenseThreeDimensionalModel::shouldUseLogValueScale() const 394 EditableDenseThreeDimensionalModel::shouldUseLogValueScale() const
393 { 395 {
394 QMutexLocker locker(&m_mutex); 396 QReadLocker locker(&m_lock);
395 397
396 QVector<float> sample; 398 QVector<float> sample;
397 QVector<int> n; 399 QVector<int> n;
398 400
399 for (int i = 0; i < 10; ++i) { 401 for (int i = 0; i < 10; ++i) {
448 } 450 }
449 451
450 QString 452 QString
451 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const 453 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const
452 { 454 {
453 QMutexLocker locker(&m_mutex); 455 QReadLocker locker(&m_lock);
454 QString s; 456 QString s;
455 for (size_t i = 0; i < m_data.size(); ++i) { 457 for (size_t i = 0; i < m_data.size(); ++i) {
456 QStringList list; 458 QStringList list;
457 for (size_t j = 0; j < m_data.at(i).size(); ++j) { 459 for (size_t j = 0; j < m_data.at(i).size(); ++j) {
458 list << QString("%1").arg(m_data.at(i).at(j)); 460 list << QString("%1").arg(m_data.at(i).at(j));
465 void 467 void
466 EditableDenseThreeDimensionalModel::toXml(QTextStream &out, 468 EditableDenseThreeDimensionalModel::toXml(QTextStream &out,
467 QString indent, 469 QString indent,
468 QString extraAttributes) const 470 QString extraAttributes) const
469 { 471 {
470 QMutexLocker locker(&m_mutex); 472 QReadLocker locker(&m_lock);
471 473
472 // For historical reasons we read and write "resolution" as "windowSize" 474 // For historical reasons we read and write "resolution" as "windowSize"
473 475
474 std::cerr << "EditableDenseThreeDimensionalModel::toXml" << std::endl; 476 std::cerr << "EditableDenseThreeDimensionalModel::toXml" << std::endl;
475 477