/[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 970 by schoenebeck, Wed Dec 6 22:28:17 2006 UTC revision 1038 by persson, Sat Feb 3 15:33:00 2007 UTC
# Line 23  Line 23 
23  namespace LinuxSampler {  namespace LinuxSampler {
24    
25      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {
         pQueue = new RingBuffer<command_t,true>(INSTRUMENT_LOADER_QUEUE_SIZE);  
26      }      }
27    
28      InstrumentManagerThread::~InstrumentManagerThread() {      InstrumentManagerThread::~InstrumentManagerThread() {
         if (pQueue) delete pQueue;  
29      }      }
30    
31      /**      /**
# Line 42  namespace LinuxSampler { Line 40  namespace LinuxSampler {
40       * @param pEngineChannel - engine channel on which the instrument should be loaded       * @param pEngineChannel - engine channel on which the instrument should be loaded
41       */       */
42      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {
43          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).",Filename.c_str(),uiInstrumentIndex));          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex));
44          // already tell the engine which instrument to load          // already tell the engine which instrument to load
45          pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex);          pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex);
46    
47          command_t cmd;          command_t cmd;
48          cmd.type           = command_t::DIRECT_LOAD;          cmd.type           = command_t::DIRECT_LOAD;
49          cmd.pEngineChannel = pEngineChannel;          cmd.pEngineChannel = pEngineChannel;
50          pQueue->push(&cmd);  
51            mutex.Lock();
52            queue.push_back(cmd);
53            mutex.Unlock();
54    
55          StartThread(); // ensure thread is running          StartThread(); // ensure thread is running
56          conditionJobsLeft.Set(true); // wake up thread          conditionJobsLeft.Set(true); // wake up thread
57      }      }
# Line 72  namespace LinuxSampler { Line 74  namespace LinuxSampler {
74          cmd.pManager     = pManager;          cmd.pManager     = pManager;
75          cmd.instrumentId = ID;          cmd.instrumentId = ID;
76          cmd.mode         = Mode;          cmd.mode         = Mode;
77          pQueue->push(&cmd);  
78            mutex.Lock();
79            queue.push_back(cmd);
80            mutex.Unlock();
81    
82          StartThread(); // ensure thread is running          StartThread(); // ensure thread is running
83          conditionJobsLeft.Set(true); // wake up thread          conditionJobsLeft.Set(true); // wake up thread
84      }      }
# Line 80  namespace LinuxSampler { Line 86  namespace LinuxSampler {
86      // Entry point for the task thread.      // Entry point for the task thread.
87      int InstrumentManagerThread::Main() {      int InstrumentManagerThread::Main() {
88          while (true) {          while (true) {
89              while (pQueue->read_space()) {              while (!queue.empty()) {
90                  command_t cmd;                  command_t cmd;
91                  pQueue->pop(&cmd);  
92                    // grab a new command from the queue
93                    mutex.Lock();
94                    cmd = queue.front();
95                    mutex.Unlock();
96    
97                  try {                  try {
98                      switch (cmd.type) {                      switch (cmd.type) {
99                          case command_t::DIRECT_LOAD:                          case command_t::DIRECT_LOAD:
# Line 98  namespace LinuxSampler { Line 109  namespace LinuxSampler {
109                  catch (Exception e) {                  catch (Exception e) {
110                      e.PrintMessage();                      e.PrintMessage();
111                  }                  }
112    
113                    // remove processed command from queue
114                    mutex.Lock();
115                    queue.pop_front();
116                    mutex.Unlock();
117              }              }
118    
119              // nothing left to do, sleep until new jobs arrive              // nothing left to do, sleep until new jobs arrive

Legend:
Removed from v.970  
changed lines
  Added in v.1038

  ViewVC Help
Powered by ViewVC