Mercurial > hg > svcore
comparison data/fft/FFTDataServer.cpp @ 1081:027d8b943be5
Do not attempt to switch from read-only to read-write mode if an error is pending (may cause mutex deadlock)
author | Chris Cannam |
---|---|
date | Wed, 10 Jun 2015 13:12:29 +0100 |
parents | 1a73618b0b67 |
children | e4d40c185c72 |
comparison
equal
deleted
inserted
replaced
1080:f35c1f9bfaa2 | 1081:027d8b943be5 |
---|---|
900 int col; | 900 int col; |
901 FFTCacheReader *cache = getCacheReader(x, col); | 901 FFTCacheReader *cache = getCacheReader(x, col); |
902 if (!cache) return 0; | 902 if (!cache) return 0; |
903 | 903 |
904 if (!cache->haveSetColumnAt(col)) { | 904 if (!cache->haveSetColumnAt(col)) { |
905 if (getError() != "") return false; | |
905 Profiler profiler("FFTDataServer::getMagnitudeAt: filling"); | 906 Profiler profiler("FFTDataServer::getMagnitudeAt: filling"); |
906 #ifdef DEBUG_FFT_SERVER | 907 #ifdef DEBUG_FFT_SERVER |
907 std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn(" | 908 std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn(" |
908 << x << ")" << std::endl; | 909 << x << ")" << std::endl; |
909 #endif | 910 #endif |
936 int col; | 937 int col; |
937 FFTCacheReader *cache = getCacheReader(x, col); | 938 FFTCacheReader *cache = getCacheReader(x, col); |
938 if (!cache) return false; | 939 if (!cache) return false; |
939 | 940 |
940 if (!cache->haveSetColumnAt(col)) { | 941 if (!cache->haveSetColumnAt(col)) { |
942 if (getError() != "") return false; | |
941 Profiler profiler("FFTDataServer::getMagnitudesAt: filling"); | 943 Profiler profiler("FFTDataServer::getMagnitudesAt: filling"); |
942 fillColumn(x); | 944 fillColumn(x); |
943 } | 945 } |
944 | 946 |
945 cache->getMagnitudesAt(col, values, minbin, count, step); | 947 cache->getMagnitudesAt(col, values, minbin, count, step); |
966 int col; | 968 int col; |
967 FFTCacheReader *cache = getCacheReader(x, col); | 969 FFTCacheReader *cache = getCacheReader(x, col); |
968 if (!cache) return 0; | 970 if (!cache) return 0; |
969 | 971 |
970 if (!cache->haveSetColumnAt(col)) { | 972 if (!cache->haveSetColumnAt(col)) { |
973 if (getError() != "") return false; | |
971 Profiler profiler("FFTDataServer::getNormalizedMagnitudeAt: filling"); | 974 Profiler profiler("FFTDataServer::getNormalizedMagnitudeAt: filling"); |
972 fillColumn(x); | 975 fillColumn(x); |
973 } | 976 } |
974 val = cache->getNormalizedMagnitudeAt(col, y); | 977 val = cache->getNormalizedMagnitudeAt(col, y); |
975 | 978 |
998 int col; | 1001 int col; |
999 FFTCacheReader *cache = getCacheReader(x, col); | 1002 FFTCacheReader *cache = getCacheReader(x, col); |
1000 if (!cache) return false; | 1003 if (!cache) return false; |
1001 | 1004 |
1002 if (!cache->haveSetColumnAt(col)) { | 1005 if (!cache->haveSetColumnAt(col)) { |
1006 if (getError() != "") return false; | |
1003 Profiler profiler("FFTDataServer::getNormalizedMagnitudesAt: filling"); | 1007 Profiler profiler("FFTDataServer::getNormalizedMagnitudesAt: filling"); |
1004 fillColumn(x); | 1008 fillColumn(x); |
1005 } | 1009 } |
1006 | 1010 |
1007 for (int i = 0; i < count; ++i) { | 1011 for (int i = 0; i < count; ++i) { |
1030 int col; | 1034 int col; |
1031 FFTCacheReader *cache = getCacheReader(x, col); | 1035 FFTCacheReader *cache = getCacheReader(x, col); |
1032 if (!cache) return 0; | 1036 if (!cache) return 0; |
1033 | 1037 |
1034 if (!cache->haveSetColumnAt(col)) { | 1038 if (!cache->haveSetColumnAt(col)) { |
1039 if (getError() != "") return false; | |
1035 Profiler profiler("FFTDataServer::getMaximumMagnitudeAt: filling"); | 1040 Profiler profiler("FFTDataServer::getMaximumMagnitudeAt: filling"); |
1036 fillColumn(x); | 1041 fillColumn(x); |
1037 } | 1042 } |
1038 val = cache->getMaximumMagnitudeAt(col); | 1043 val = cache->getMaximumMagnitudeAt(col); |
1039 | 1044 |
1058 int col; | 1063 int col; |
1059 FFTCacheReader *cache = getCacheReader(x, col); | 1064 FFTCacheReader *cache = getCacheReader(x, col); |
1060 if (!cache) return 0; | 1065 if (!cache) return 0; |
1061 | 1066 |
1062 if (!cache->haveSetColumnAt(col)) { | 1067 if (!cache->haveSetColumnAt(col)) { |
1068 if (getError() != "") return false; | |
1063 Profiler profiler("FFTDataServer::getPhaseAt: filling"); | 1069 Profiler profiler("FFTDataServer::getPhaseAt: filling"); |
1064 fillColumn(x); | 1070 fillColumn(x); |
1065 } | 1071 } |
1066 val = cache->getPhaseAt(col, y); | 1072 val = cache->getPhaseAt(col, y); |
1067 | 1073 |
1090 int col; | 1096 int col; |
1091 FFTCacheReader *cache = getCacheReader(x, col); | 1097 FFTCacheReader *cache = getCacheReader(x, col); |
1092 if (!cache) return false; | 1098 if (!cache) return false; |
1093 | 1099 |
1094 if (!cache->haveSetColumnAt(col)) { | 1100 if (!cache->haveSetColumnAt(col)) { |
1101 if (getError() != "") return false; | |
1095 Profiler profiler("FFTDataServer::getPhasesAt: filling"); | 1102 Profiler profiler("FFTDataServer::getPhasesAt: filling"); |
1096 fillColumn(x); | 1103 fillColumn(x); |
1097 } | 1104 } |
1098 | 1105 |
1099 for (int i = 0; i < count; ++i) { | 1106 for (int i = 0; i < count; ++i) { |
1129 imaginary = 0; | 1136 imaginary = 0; |
1130 return; | 1137 return; |
1131 } | 1138 } |
1132 | 1139 |
1133 if (!cache->haveSetColumnAt(col)) { | 1140 if (!cache->haveSetColumnAt(col)) { |
1141 if (getError() != "") { | |
1142 real = 0; | |
1143 imaginary = 0; | |
1144 return; | |
1145 } | |
1134 Profiler profiler("FFTDataServer::getValuesAt: filling"); | 1146 Profiler profiler("FFTDataServer::getValuesAt: filling"); |
1135 #ifdef DEBUG_FFT_SERVER | 1147 #ifdef DEBUG_FFT_SERVER |
1136 std::cerr << "FFTDataServer::getValuesAt(" << x << ", " << y << "): filling" << std::endl; | 1148 std::cerr << "FFTDataServer::getValuesAt(" << x << ", " << y << "): filling" << std::endl; |
1137 #endif | 1149 #endif |
1138 fillColumn(x); | 1150 fillColumn(x); |
1163 int col; | 1175 int col; |
1164 FFTCacheReader *cache = getCacheReader(x, col); | 1176 FFTCacheReader *cache = getCacheReader(x, col); |
1165 if (!cache) return false; | 1177 if (!cache) return false; |
1166 | 1178 |
1167 if (!cache->haveSetColumnAt(col)) { | 1179 if (!cache->haveSetColumnAt(col)) { |
1180 if (getError() != "") return false; | |
1168 Profiler profiler("FFTDataServer::getValuesAt: filling"); | 1181 Profiler profiler("FFTDataServer::getValuesAt: filling"); |
1169 fillColumn(x); | 1182 fillColumn(x); |
1170 } | 1183 } |
1171 | 1184 |
1172 for (int i = 0; i < count; ++i) { | 1185 for (int i = 0; i < count; ++i) { |
1393 } | 1406 } |
1394 | 1407 |
1395 QString | 1408 QString |
1396 FFTDataServer::getError() const | 1409 FFTDataServer::getError() const |
1397 { | 1410 { |
1398 if (m_error != "") return m_error; | 1411 QString err; |
1399 else if (m_fillThread) return m_fillThread->getError(); | 1412 if (m_error != "") { |
1400 else return ""; | 1413 err = m_error; |
1414 cerr << "FFTDataServer::getError: err (server " << this << ") = " << err << endl; | |
1415 } else { | |
1416 MutexLocker locker(&m_fftBuffersLock, "FFTDataServer::getError"); | |
1417 if (m_fillThread) { | |
1418 err = m_fillThread->getError(); | |
1419 cerr << "FFTDataServer::getError: err (server " << this << ", from thread " << m_fillThread | |
1420 << ") = " << err << endl; | |
1421 } | |
1422 } | |
1423 return err; | |
1401 } | 1424 } |
1402 | 1425 |
1403 int | 1426 int |
1404 FFTDataServer::getFillCompletion() const | 1427 FFTDataServer::getFillCompletion() const |
1405 { | 1428 { |
1473 for (sv_frame_t f = m_fillFrom; f < end; f += m_server.m_windowIncrement) { | 1496 for (sv_frame_t f = m_fillFrom; f < end; f += m_server.m_windowIncrement) { |
1474 | 1497 |
1475 try { | 1498 try { |
1476 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); | 1499 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); |
1477 } catch (std::exception &e) { | 1500 } catch (std::exception &e) { |
1478 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl; | 1501 MutexLocker locker(&m_server.m_fftBuffersLock, |
1479 m_error = e.what(); | 1502 "FFTDataServer::run::m_fftBuffersLock [err]"); |
1503 m_threadError = e.what(); | |
1504 std::cerr << "FFTDataServer::FillThread::run: exception: " << m_threadError << " (thread = " << this << " from server " << &m_server << ")" << std::endl; | |
1480 m_server.fillComplete(); | 1505 m_server.fillComplete(); |
1481 m_completion = 100; | 1506 m_completion = 100; |
1482 m_extent = end; | 1507 m_extent = end; |
1483 return; | 1508 return; |
1484 } | 1509 } |
1522 for (sv_frame_t f = start; f < remainingEnd; f += m_server.m_windowIncrement) { | 1547 for (sv_frame_t f = start; f < remainingEnd; f += m_server.m_windowIncrement) { |
1523 | 1548 |
1524 try { | 1549 try { |
1525 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); | 1550 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); |
1526 } catch (std::exception &e) { | 1551 } catch (std::exception &e) { |
1527 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl; | 1552 MutexLocker locker(&m_server.m_fftBuffersLock, |
1528 m_error = e.what(); | 1553 "FFTDataServer::run::m_fftBuffersLock [err]"); |
1554 m_threadError = e.what(); | |
1555 std::cerr << "FFTDataServer::FillThread::run: exception: " << m_threadError << " (thread = " << this << " from server " << &m_server << ")" << std::endl; | |
1529 m_server.fillComplete(); | 1556 m_server.fillComplete(); |
1530 m_completion = 100; | 1557 m_completion = 100; |
1531 m_extent = end; | 1558 m_extent = end; |
1532 return; | 1559 return; |
1533 } | 1560 } |