/[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 989 by schoenebeck, Tue Dec 19 19:34:08 2006 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 49  namespace LinuxSampler { Line 47  namespace LinuxSampler {
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.989

  ViewVC Help
Powered by ViewVC