/[svn]/linuxsampler/trunk/src/engines/gig/DiskThread.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/DiskThread.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1320 by persson, Sat Feb 3 15:33:00 2007 UTC revision 1321 by schoenebeck, Tue Sep 4 01:12:49 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 58  namespace LinuxSampler { namespace gig { Line 58  namespace LinuxSampler { namespace gig {
58          GhostQueue->init();          GhostQueue->init();
59          CreationQueue->init();          CreationQueue->init();
60          DeletionQueue->init();          DeletionQueue->init();
61            DeletionNotificationQueue.init();
62          DeleteDimregQueue->init();          DeleteDimregQueue->init();
63          ActiveStreamCount = 0;          ActiveStreamCount = 0;
64          ActiveStreamCountMax = 0;          ActiveStreamCountMax = 0;
# Line 135  namespace LinuxSampler { namespace gig { Line 136  namespace LinuxSampler { namespace gig {
136      }      }
137    
138      /**      /**
139       * Returns -1 if command queue is full, 0 on success (will be called by audio       * Request the disk thread to delete the given disk stream. This method
140       * thread within the voice class).       * will return immediately, thus it won't block until the respective voice
141         * was actually deleted. (Called by audio thread within the Voice class).
142         *
143         * @param pStreamRef           - stream that shall be deleted
144         * @param bRequestNotification - set to true in case you want to receive a
145         *                               notification once the stream has actually
146         *                               been deleted
147         * @returns 0 on success, -1 if command queue is full
148         * @see AskForDeletedStream()
149       */       */
150      int DiskThread::OrderDeletionOfStream(Stream::reference_t* pStreamRef) {      int DiskThread::OrderDeletionOfStream(Stream::reference_t* pStreamRef, bool bRequestNotification) {
151          dmsg(4,("Disk Thread: stream deletion ordered\n"));          dmsg(4,("Disk Thread: stream deletion ordered\n"));
152          if (DeletionQueue->write_space() < 1) {          if (DeletionQueue->write_space() < 1) {
153              dmsg(1,("DiskThread: Deletion queue full!\n"));              dmsg(1,("DiskThread: Deletion queue full!\n"));
# Line 149  namespace LinuxSampler { namespace gig { Line 158  namespace LinuxSampler { namespace gig {
158          cmd.pStream = pStreamRef->pStream;          cmd.pStream = pStreamRef->pStream;
159          cmd.hStream = pStreamRef->hStream;          cmd.hStream = pStreamRef->hStream;
160          cmd.OrderID = pStreamRef->OrderID;          cmd.OrderID = pStreamRef->OrderID;
161            cmd.bNotify = bRequestNotification;
162    
163          DeletionQueue->push(&cmd);          DeletionQueue->push(&cmd);
164          return 0;          return 0;
165      }      }
166    
167      /**      /**
168       * Tell the disk thread to release a dimension region that belong       * Tell the disk thread to release a dimension region that belongs
169       * to an instrument which isn't loaded anymore. The disk thread       * to an instrument which isn't loaded anymore. The disk thread
170       * will hand back the dimension region to the instrument resource       * will hand back the dimension region to the instrument resource
171       * manager. (OrderDeletionOfDimreg is called from the audio thread       * manager. (OrderDeletionOfDimreg is called from the audio thread
# Line 196  namespace LinuxSampler { namespace gig { Line 206  namespace LinuxSampler { namespace gig {
206          return NULL;          return NULL;
207      }      }
208    
209        /**
210         * In case the original sender requested a notification with his stream
211         * deletion order, he can use this method to poll if the respective stream
212         * has actually been deleted.
213         *
214         * @returns handle / identifier of the deleted stream, or
215         *          Stream::INVALID_HANDLE if no notification present
216         */
217        Stream::Handle DiskThread::AskForDeletedStream() {
218            if (DeletionNotificationQueue.read_space()) {
219                Stream::Handle hStream;
220                DeletionNotificationQueue.pop(&hStream);
221                return hStream;
222            } else return Stream::INVALID_HANDLE; // no notification received yet
223        }
224    
225    
226    
227      // #########################################################################      // #########################################################################
# Line 205  namespace LinuxSampler { namespace gig { Line 231  namespace LinuxSampler { namespace gig {
231    
232      DiskThread::DiskThread(uint BufferWrapElements, InstrumentResourceManager* pInstruments) :      DiskThread::DiskThread(uint BufferWrapElements, InstrumentResourceManager* pInstruments) :
233          Thread(true, false, 1, -2),          Thread(true, false, 1, -2),
234          pInstruments(pInstruments) {          pInstruments(pInstruments),
235            DeletionNotificationQueue(4*CONFIG_MAX_STREAMS)
236        {
237          DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(CONFIG_STREAM_MAX_REFILL_SIZE);          DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(CONFIG_STREAM_MAX_REFILL_SIZE);
238          CreationQueue       = new RingBuffer<create_command_t,false>(1024);          CreationQueue       = new RingBuffer<create_command_t,false>(4*CONFIG_MAX_STREAMS);
239          DeletionQueue       = new RingBuffer<delete_command_t,false>(1024);          DeletionQueue       = new RingBuffer<delete_command_t,false>(4*CONFIG_MAX_STREAMS);
240          GhostQueue          = new RingBuffer<Stream::Handle,false>(CONFIG_MAX_STREAMS);          GhostQueue          = new RingBuffer<delete_command_t,false>(CONFIG_MAX_STREAMS);
241          DeleteDimregQueue   = new RingBuffer< ::gig::DimensionRegion*,false>(1024);          DeleteDimregQueue   = new RingBuffer< ::gig::DimensionRegion*,false>(4*CONFIG_MAX_STREAMS);
242          Streams             = CONFIG_MAX_STREAMS;          Streams             = CONFIG_MAX_STREAMS;
243          RefillStreamsPerRun = CONFIG_REFILL_STREAMS_PER_RUN;          RefillStreamsPerRun = CONFIG_REFILL_STREAMS_PER_RUN;
244          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {
# Line 241  namespace LinuxSampler { namespace gig { Line 269  namespace LinuxSampler { namespace gig {
269    
270              // if there are ghost streams, delete them              // if there are ghost streams, delete them
271              for (int i = 0; i < GhostQueue->read_space(); i++) { //FIXME: unefficient              for (int i = 0; i < GhostQueue->read_space(); i++) { //FIXME: unefficient
272                  Stream::Handle hGhostStream;                  delete_command_t ghostStream;
273                  GhostQueue->pop(&hGhostStream);                  GhostQueue->pop(&ghostStream);
274                  bool found = false;                  bool found = false;
275                  for (int i = 0; i < this->Streams; i++) {                  for (int i = 0; i < this->Streams; i++) {
276                      if (pStreams[i]->GetHandle() == hGhostStream) {                      if (pStreams[i]->GetHandle() == ghostStream.hStream) {
277                          pStreams[i]->Kill();                          pStreams[i]->Kill();
278                          found = true;                          found = true;
279                            // if original sender requested a notification, let him know now
280                            if (ghostStream.bNotify)
281                                DeletionNotificationQueue.push(&ghostStream.hStream);
282                          break;                          break;
283                      }                      }
284                  }                  }
285                  if (!found) GhostQueue->push(&hGhostStream); // put ghost stream handle back to the queue                  if (!found) GhostQueue->push(&ghostStream); // put ghost stream handle back to the queue
286              }              }
287    
288              // if there are creation commands, create new streams              // if there are creation commands, create new streams
# Line 325  namespace LinuxSampler { namespace gig { Line 356  namespace LinuxSampler { namespace gig {
356              if (pStream && pStream != SLOT_RESERVED) {              if (pStream && pStream != SLOT_RESERVED) {
357                  pStream->Kill();                  pStream->Kill();
358                  pCreatedStreams[Command.OrderID] = NULL; // free slot for new order                  pCreatedStreams[Command.OrderID] = NULL; // free slot for new order
359                    // if original sender requested a notification, let him know now
360                    if (Command.bNotify)
361                        DeletionNotificationQueue.push(&Command.hStream);
362                  return;                  return;
363              }              }
364    
365              // the stream was not created yet              // the stream was not created yet
366              if (GhostQueue->write_space() > 0) {              if (GhostQueue->write_space() > 0) {
367                  GhostQueue->push(&Command.hStream);                  GhostQueue->push(&Command);
368                } else { // error, queue full
369                    if (Command.bNotify) {
370                        dmsg(1,("DiskThread: GhostQueue full! (might lead to dead lock with instrument editor!)\n"));
371                    } else {
372                        dmsg(1,("DiskThread: GhostQueue full!\n"));
373                    }
374              }              }
             else dmsg(1,("DiskThread: GhostQueue full!\n"));  
375          }          }
376      }      }
377    

Legend:
Removed from v.1320  
changed lines
  Added in v.1321

  ViewVC Help
Powered by ViewVC