--- linuxsampler/trunk/src/engines/gig/DiskThread.cpp 2004/04/27 09:21:58 56 +++ linuxsampler/trunk/src/engines/gig/DiskThread.cpp 2005/02/19 02:40:24 392 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -109,13 +110,17 @@ return -1; } + const Stream::OrderID_t newOrder = CreateOrderID(); + if (!newOrder) { + dmsg(1,("DiskThread: there was no free slot\n")); + return -1; // there was no free slot + } + pStreamRef->State = Stream::state_active; - pStreamRef->OrderID = CreateOrderID(); + pStreamRef->OrderID = newOrder; pStreamRef->hStream = CreateHandle(); pStreamRef->pStream = NULL; // a stream has to be activated by the disk thread first - if (!pStreamRef->OrderID) return -1; // there was no free slot - create_command_t cmd; cmd.OrderID = pStreamRef->OrderID; cmd.hStream = pStreamRef->hStream; @@ -180,14 +185,15 @@ // # (following code should only be executed by the disk thread) - DiskThread::DiskThread(uint BufferWrapElements) : Thread(false, 1, -2) { + DiskThread::DiskThread(uint BufferWrapElements) : Thread(true, false, 1, -2) { + DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(MAX_REFILL_SIZE); CreationQueue = new RingBuffer(1024); DeletionQueue = new RingBuffer(1024); GhostQueue = new RingBuffer(MAX_INPUT_STREAMS); Streams = MAX_INPUT_STREAMS; RefillStreamsPerRun = REFILL_STREAMS_PER_RUN; for (int i = 0; i < MAX_INPUT_STREAMS; i++) { - pStreams[i] = new Stream(STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words + pStreams[i] = new Stream(&DecompressionBuffer, STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words } for (int i = 1; i <= MAX_INPUT_STREAMS; i++) { pCreatedStreams[i] = NULL; @@ -201,11 +207,13 @@ if (CreationQueue) delete CreationQueue; if (DeletionQueue) delete DeletionQueue; if (GhostQueue) delete GhostQueue; + ::gig::Sample::DestroyDecompressionBuffer(DecompressionBuffer); } int DiskThread::Main() { dmsg(3,("Disk thread running\n")); while (true) { + pthread_testcancel(); // mandatory for OSX IsIdle = true; // will be set to false if a stream got filled // if there are ghost streams, delete them @@ -231,7 +239,7 @@ } // if there are deletion commands, delete those streams - while (Stream::UnusedStreams < Streams && DeletionQueue->read_space() > 0) { + while (Stream::UnusedStreams < Stream::TotalStreams && DeletionQueue->read_space() > 0) { delete_command_t command; DeletionQueue->pop(&command); DeleteStream(command); @@ -335,7 +343,7 @@ /// order ID Generator Stream::OrderID_t DiskThread::CreateOrderID() { - static uint32_t counter = 0; + static Stream::OrderID_t counter(0); for (int i = 0; i < MAX_INPUT_STREAMS; i++) { if (counter == MAX_INPUT_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0 else counter++;