comparison base/StorageAdviser.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents e802e550a1f2
children 329ddaf7415d
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
22 22
23 #include <iostream> 23 #include <iostream>
24 24
25 //#define DEBUG_STORAGE_ADVISER 1 25 //#define DEBUG_STORAGE_ADVISER 1
26 26
27 long StorageAdviser::m_discPlanned = 0; 27 size_t StorageAdviser::m_discPlanned = 0;
28 long StorageAdviser::m_memoryPlanned = 0; 28 size_t StorageAdviser::m_memoryPlanned = 0;
29 29
30 StorageAdviser::Recommendation 30 StorageAdviser::Recommendation
31 StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation; 31 StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation;
32 32
33 StorageAdviser::Recommendation 33 StorageAdviser::Recommendation
34 StorageAdviser::recommend(Criteria criteria, 34 StorageAdviser::recommend(Criteria criteria,
35 int minimumSize, 35 size_t minimumSize,
36 int maximumSize) 36 size_t maximumSize)
37 { 37 {
38 #ifdef DEBUG_STORAGE_ADVISER 38 #ifdef DEBUG_STORAGE_ADVISER
39 SVDEBUG << "StorageAdviser::recommend: Criteria " << criteria 39 SVDEBUG << "StorageAdviser::recommend: Criteria " << criteria
40 << ", minimumSize " << minimumSize 40 << ", minimumSize " << minimumSize
41 << ", maximumSize " << maximumSize << endl; 41 << ", maximumSize " << maximumSize << endl;
50 path = TempDirectory::getInstance()->getPath(); 50 path = TempDirectory::getInstance()->getPath();
51 } catch (std::exception e) { 51 } catch (std::exception e) {
52 cerr << "StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl; 52 cerr << "StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl;
53 return Recommendation(UseMemory | ConserveSpace); 53 return Recommendation(UseMemory | ConserveSpace);
54 } 54 }
55 int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit()); 55 ssize_t discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit());
56 int memoryFree, memoryTotal; 56 ssize_t memoryFree, memoryTotal;
57 GetRealMemoryMBAvailable(memoryFree, memoryTotal); 57 GetRealMemoryMBAvailable(memoryFree, memoryTotal);
58 58
59 if (discFree > m_discPlanned / 1024 + 1) { 59 if (discFree > ssize_t(m_discPlanned / 1024 + 1)) {
60 discFree -= m_discPlanned / 1024 + 1; 60 discFree -= m_discPlanned / 1024 + 1;
61 } else if (discFree > 0) { // can also be -1 for unknown 61 } else if (discFree > 0) { // can also be -1 for unknown
62 discFree = 0; 62 discFree = 0;
63 } 63 }
64 64
65 if (memoryFree > m_memoryPlanned / 1024 + 1) { 65 if (memoryFree > ssize_t(m_memoryPlanned / 1024 + 1)) {
66 memoryFree -= m_memoryPlanned / 1024 + 1; 66 memoryFree -= m_memoryPlanned / 1024 + 1;
67 } else if (memoryFree > 0) { // can also be -1 for unknown 67 } else if (memoryFree > 0) { // can also be -1 for unknown
68 memoryFree = 0; 68 memoryFree = 0;
69 } 69 }
70 70
85 }; 85 };
86 86
87 StorageStatus memoryStatus = Unknown; 87 StorageStatus memoryStatus = Unknown;
88 StorageStatus discStatus = Unknown; 88 StorageStatus discStatus = Unknown;
89 89
90 int minmb = minimumSize / 1024 + 1; 90 ssize_t minmb = ssize_t(minimumSize / 1024 + 1);
91 int maxmb = maximumSize / 1024 + 1; 91 ssize_t maxmb = ssize_t(maximumSize / 1024 + 1);
92 92
93 if (memoryFree == -1) memoryStatus = Unknown; 93 if (memoryFree == -1) memoryStatus = Unknown;
94 else if (memoryFree < memoryTotal / 3) memoryStatus = Insufficient; 94 else if (memoryFree < memoryTotal / 3) memoryStatus = Insufficient;
95 else if (minmb > (memoryFree * 3) / 4) memoryStatus = Insufficient; 95 else if (minmb > (memoryFree * 3) / 4) memoryStatus = Insufficient;
96 else if (maxmb > (memoryFree * 3) / 4) memoryStatus = Marginal; 96 else if (maxmb > (memoryFree * 3) / 4) memoryStatus = Marginal;
183 183
184 return Recommendation(recommendation); 184 return Recommendation(recommendation);
185 } 185 }
186 186
187 void 187 void
188 StorageAdviser::notifyPlannedAllocation(AllocationArea area, int size) 188 StorageAdviser::notifyPlannedAllocation(AllocationArea area, size_t size)
189 { 189 {
190 if (area == MemoryAllocation) m_memoryPlanned += size; 190 if (area == MemoryAllocation) m_memoryPlanned += size;
191 else if (area == DiscAllocation) m_discPlanned += size; 191 else if (area == DiscAllocation) m_discPlanned += size;
192 // cerr << "storage planned up: memory: " << m_memoryPlanned << ", disc " 192 // cerr << "storage planned up: memory: " << m_memoryPlanned << ", disc "
193 // << m_discPlanned << endl; 193 // << m_discPlanned << endl;
194 } 194 }
195 195
196 void 196 void
197 StorageAdviser::notifyDoneAllocation(AllocationArea area, int size) 197 StorageAdviser::notifyDoneAllocation(AllocationArea area, size_t size)
198 { 198 {
199 if (area == MemoryAllocation) { 199 if (area == MemoryAllocation) {
200 if (m_memoryPlanned > size) m_memoryPlanned -= size; 200 if (m_memoryPlanned > size) m_memoryPlanned -= size;
201 else m_memoryPlanned = 0; 201 else m_memoryPlanned = 0;
202 } else if (area == DiscAllocation) { 202 } else if (area == DiscAllocation) {