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

Diff of /linuxsampler/trunk/src/engines/InstrumentManagerThread.cpp

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

revision 2277 by persson, Sat Oct 1 08:23:02 2011 UTC revision 2349 by persson, Sun Jun 17 15:47:43 2012 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2005 - 2011 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2012 Christian Schoenebeck                       *
4   *                                                                         *   *                                                                         *
5   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
6   *   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 23  Line 23 
23  #include "../common/global_private.h"  #include "../common/global_private.h"
24  #include "EngineChannelFactory.h"  #include "EngineChannelFactory.h"
25    
26    #ifdef __APPLE__
27    #include <sys/utsname.h>
28    #endif
29    
30  namespace LinuxSampler {  namespace LinuxSampler {
31    
32      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {
# Line 46  namespace LinuxSampler { Line 50  namespace LinuxSampler {
50      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {
51          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex));          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex));
52    
53          static bool listenerRegistered = false;          // the listener only needs to be registered once in the
54          if (!listenerRegistered) {          // Sampler, but as we don't know if Sampler has been
55              pEngineChannel->GetSampler()->AddChannelCountListener(&eventHandler);          // recreated, we simply remove and add every time
56              listenerRegistered = true;          pEngineChannel->GetSampler()->RemoveChannelCountListener(&eventHandler);
57          }          pEngineChannel->GetSampler()->AddChannelCountListener(&eventHandler);
           
58                    
59          command_t cmd;          command_t cmd;
60          cmd.type           = command_t::DIRECT_LOAD;          cmd.type           = command_t::DIRECT_LOAD;
# Line 102  namespace LinuxSampler { Line 105  namespace LinuxSampler {
105              TestCancel();              TestCancel();
106              #endif              #endif
107    
108              while (!queue.empty()) {              while (true) {
109                  command_t cmd;                  command_t cmd;
110    
111                  // grab a new command from the queue                  // grab a new command from the queue
112                  mutex.Lock();                  mutex.Lock();
113                  cmd = queue.front();                  bool empty = queue.empty();
114                  queue.pop_front();                  if (!empty) {
115                        cmd = queue.front();
116                        queue.pop_front();
117    
118                        if (cmd.type == command_t::DIRECT_LOAD) {
119                            EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, false);
120                        }
121                    }
122                  mutex.Unlock();                  mutex.Unlock();
123                    if (empty) break;
124    
125                  try {                  try {
126                      switch (cmd.type) {                      switch (cmd.type) {
127                          case command_t::DIRECT_LOAD:                          case command_t::DIRECT_LOAD:
                             EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, false);  
128                              cmd.pEngineChannel->PrepareLoadInstrument(cmd.instrumentId.FileName.c_str(), cmd.instrumentId.Index);                              cmd.pEngineChannel->PrepareLoadInstrument(cmd.instrumentId.FileName.c_str(), cmd.instrumentId.Index);
129                              cmd.pEngineChannel->LoadInstrument();                              cmd.pEngineChannel->LoadInstrument();
130                              EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, true);                              EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, true);
# Line 170  namespace LinuxSampler { Line 180  namespace LinuxSampler {
180    
181  #ifdef __APPLE__  #ifdef __APPLE__
182      int InstrumentManagerThread::StopThread() {      int InstrumentManagerThread::StopThread() {
183          // This is a fix for Mac OS X, where SignalStopThread doesn't          utsname buf;
184          // wake up a thread waiting for a condition variable.          int osVersion = uname(&buf) ? 0 : atoi(buf.release);
185          SignalStopThread(); // send stop signal, but don't wait  
186          conditionJobsLeft.Set(true); // wake thread          // This is a fix for Mac OS X 10.6 and earlier, where
187            // SignalStopThread doesn't wake up a thread waiting for a
188            // condition variable.
189            if (osVersion < 11) { // darwin 11 = OS X 10.7
190                SignalStopThread(); // send stop signal, but don't wait
191                conditionJobsLeft.Set(true); // wake thread
192            }
193          return Thread::StopThread(); // then wait for it to cancel          return Thread::StopThread(); // then wait for it to cancel
194      }      }
195  #endif  #endif
196    
197    #ifdef WIN32
198        int InstrumentManagerThread::StopThread() {
199            int res = Thread::StopThread();
200            conditionJobsLeft.Reset();
201            return res;
202        }
203    #endif
204    
205  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2277  
changed lines
  Added in v.2349

  ViewVC Help
Powered by ViewVC