summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2015-04-10 18:03:54 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:22:08 +0100
commit867c42996ec1ff3cd9eb9ec9347f049edceffea9 (patch)
tree8866b59a881d9ab5026310fbbac8dc0e8b30259e
parentabb00f5e7fea020e9f55840784753002b8dd2d8a (diff)
Added handling of cache calling when no free ids is available.
-rw-r--r--src/cachemanager.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/cachemanager.cc b/src/cachemanager.cc
index 9b18882..2c0315d 100644
--- a/src/cachemanager.cc
+++ b/src/cachemanager.cc
@@ -30,8 +30,13 @@
#define CHUNKSIZE 256
+sample_t nodata[CHUNKSIZE];
+
CacheManager::CacheManager()
{
+ for(int i = 0; i < CHUNKSIZE; i++) {
+ nodata[i] = 0;
+ }
}
CacheManager::~CacheManager()
@@ -62,11 +67,17 @@ sample_t *CacheManager::open(AudioFile *file, size_t initial_samples_needed, int
{
// What if no free ids is available?
m_ids.lock();
- id = availableids.front();
- availableids.pop_front();
+ if(availableids.empty()) {
+ id = CACHEMANAGER_NOID;
+ }
+ else {
+ id = availableids.front();
+ availableids.pop_front();
+ }
m_ids.unlock();
- if(initial_samples_needed < file->size) {
+ if(id != CACHEMANAGER_NOID &&
+ initial_samples_needed < file->size) {
cache_t c;
c.file = file;
c.channel = channel;
@@ -81,11 +92,17 @@ sample_t *CacheManager::open(AudioFile *file, size_t initial_samples_needed, int
pushEvent(e);
}
+ if(id == CACHEMANAGER_NOID) {
+ return nodata;
+ }
+
return file->data;
}
void CacheManager::close(cacheid_t id)
{
+ if(CACHEMANAGER_NOID) return;
+
{
event_t e = createEvent(id, CLEAN);
MutexAutolock l(m_events);
@@ -103,6 +120,11 @@ void CacheManager::close(cacheid_t id)
sample_t *CacheManager::next(cacheid_t id, size_t &size)
{
size = CHUNKSIZE;
+
+ if(id == CACHEMANAGER_NOID) {
+ return nodata;
+ }
+
m_caches.lock();
cache_t c = id2cache[id];
c.pos += size;