1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2005 - 2012 Christian Schoenebeck * |
* Copyright (C) 2005 - 2013 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 * |
23 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
24 |
#include "EngineChannelFactory.h" |
#include "EngineChannelFactory.h" |
25 |
|
|
|
#ifdef __APPLE__ |
|
|
#include <sys/utsname.h> |
|
|
#endif |
|
|
|
|
26 |
namespace LinuxSampler { |
namespace LinuxSampler { |
27 |
|
|
28 |
InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) { |
InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) { |
58 |
cmd.instrumentId.Index = uiInstrumentIndex; |
cmd.instrumentId.Index = uiInstrumentIndex; |
59 |
cmd.instrumentId.FileName = Filename; |
cmd.instrumentId.FileName = Filename; |
60 |
|
|
61 |
mutex.Lock(); |
{ |
62 |
queue.push_back(cmd); |
LockGuard lock(mutex); |
63 |
mutex.Unlock(); |
queue.push_back(cmd); |
64 |
|
} |
65 |
|
|
66 |
StartThread(); // ensure thread is running |
StartThread(); // ensure thread is running |
67 |
conditionJobsLeft.Set(true); // wake up thread |
conditionJobsLeft.Set(true); // wake up thread |
86 |
cmd.instrumentId = ID; |
cmd.instrumentId = ID; |
87 |
cmd.mode = Mode; |
cmd.mode = Mode; |
88 |
|
|
89 |
mutex.Lock(); |
{ |
90 |
queue.push_back(cmd); |
LockGuard lock(mutex); |
91 |
mutex.Unlock(); |
queue.push_back(cmd); |
92 |
|
} |
93 |
|
|
94 |
StartThread(); // ensure thread is running |
StartThread(); // ensure thread is running |
95 |
conditionJobsLeft.Set(true); // wake up thread |
conditionJobsLeft.Set(true); // wake up thread |
107 |
command_t cmd; |
command_t cmd; |
108 |
|
|
109 |
// grab a new command from the queue |
// grab a new command from the queue |
110 |
mutex.Lock(); |
{ |
111 |
bool empty = queue.empty(); |
LockGuard lock(mutex); |
112 |
if (!empty) { |
if (queue.empty()) break; |
113 |
|
|
114 |
cmd = queue.front(); |
cmd = queue.front(); |
115 |
queue.pop_front(); |
queue.pop_front(); |
116 |
|
|
118 |
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, false); |
EngineChannelFactory::SetDeleteEnabled(cmd.pEngineChannel, false); |
119 |
} |
} |
120 |
} |
} |
|
mutex.Unlock(); |
|
|
if (empty) break; |
|
121 |
|
|
122 |
try { |
try { |
123 |
switch (cmd.type) { |
switch (cmd.type) { |
160 |
Removing from the queue an eventual scheduled loading of an instrument |
Removing from the queue an eventual scheduled loading of an instrument |
161 |
to a sampler channel which is going to be removed. |
to a sampler channel which is going to be removed. |
162 |
*/ |
*/ |
163 |
pThread->mutex.Lock(); |
LockGuard lock(pThread->mutex); |
164 |
std::list<command_t>::iterator it; |
std::list<command_t>::iterator it; |
165 |
for (it = pThread->queue.begin(); it != pThread->queue.end();){ |
for (it = pThread->queue.begin(); it != pThread->queue.end();){ |
166 |
if ((*it).type != command_t::DIRECT_LOAD) { ++it; continue; } |
if ((*it).type != command_t::DIRECT_LOAD) { ++it; continue; } |
172 |
++it; |
++it; |
173 |
} |
} |
174 |
} |
} |
|
pThread->mutex.Unlock(); |
|
175 |
} |
} |
176 |
|
|
177 |
#ifdef __APPLE__ |
#if defined(__APPLE__) && !defined(__x86_64__) |
178 |
int InstrumentManagerThread::StopThread() { |
int InstrumentManagerThread::StopThread() { |
179 |
utsname buf; |
// This is a fix for Mac OS X 32 bit, where SignalStopThread |
180 |
int osVersion = uname(&buf) ? 0 : atoi(buf.release); |
// doesn't wake up a thread waiting for a condition variable. |
181 |
|
SignalStopThread(); // send stop signal, but don't wait |
182 |
// This is a fix for Mac OS X 10.6 and earlier, where |
conditionJobsLeft.Set(true); // wake thread |
|
// SignalStopThread doesn't wake up a thread waiting for a |
|
|
// condition variable. |
|
|
if (osVersion < 11) { // darwin 11 = OS X 10.7 |
|
|
SignalStopThread(); // send stop signal, but don't wait |
|
|
conditionJobsLeft.Set(true); // wake thread |
|
|
} |
|
183 |
return Thread::StopThread(); // then wait for it to cancel |
return Thread::StopThread(); // then wait for it to cancel |
184 |
} |
} |
185 |
#endif |
#endif |