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 |
/** |
/** |
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 |
} |
} |
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 |
} |
} |
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: |
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 |