hmulti_audio.media_addon: Removed superfluous semaphore.
* The semaphore wasn't really needed to do what it did; using
atomic_{get|set}() as suggested by jua is much faster, anyway.
* Thanks to Dario for the initial work on this.
This commit is contained in:
@@ -175,6 +175,7 @@ MultiAudioNode::MultiAudioNode(BMediaAddOn* addon, const char* name,
|
|||||||
BBufferProducer(B_MEDIA_RAW_AUDIO),
|
BBufferProducer(B_MEDIA_RAW_AUDIO),
|
||||||
BMediaEventLooper(),
|
BMediaEventLooper(),
|
||||||
fBufferLock("multi audio buffers"),
|
fBufferLock("multi audio buffers"),
|
||||||
|
fQuitThread(0),
|
||||||
fThread(-1),
|
fThread(-1),
|
||||||
fDevice(device),
|
fDevice(device),
|
||||||
fTimeSourceStarted(false),
|
fTimeSourceStarted(false),
|
||||||
@@ -1821,13 +1822,7 @@ MultiAudioNode::_OutputThread()
|
|||||||
system_time());
|
system_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (atomic_get(&fQuitThread) == 0) {
|
||||||
// TODO: why this semaphore??
|
|
||||||
if (acquire_sem_etc(fBufferFreeSem, 1, B_RELATIVE_TIMEOUT, 0)
|
|
||||||
== B_BAD_SEM_ID) {
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
BAutolock locker(fBufferLock);
|
BAutolock locker(fBufferLock);
|
||||||
// make sure the buffers don't change while we're playing with them
|
// make sure the buffers don't change while we're playing with them
|
||||||
|
|
||||||
@@ -1875,9 +1870,6 @@ MultiAudioNode::_OutputThread()
|
|||||||
_WriteZeros(*input, input->fBufferCycle);
|
_WriteZeros(*input, input->fBufferCycle);
|
||||||
//PRINT(("MultiAudioNode::Runthread WriteZeros\n"));
|
//PRINT(("MultiAudioNode::Runthread WriteZeros\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark buffer free
|
|
||||||
release_sem(fBufferFreeSem);
|
|
||||||
} else {
|
} else {
|
||||||
//PRINT(("playback_buffer_cycle non ok input: %i\n", i));
|
//PRINT(("playback_buffer_cycle non ok input: %i\n", i));
|
||||||
}
|
}
|
||||||
@@ -2088,21 +2080,12 @@ MultiAudioNode::_StartOutputThreadIfNeeded()
|
|||||||
if (fThread >= 0)
|
if (fThread >= 0)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
// allocate buffer free semaphore
|
|
||||||
fBufferFreeSem = create_sem(
|
|
||||||
fDevice->BufferList().return_playback_buffers - 1,
|
|
||||||
"multi_audio out buffer free");
|
|
||||||
if (fBufferFreeSem < B_OK)
|
|
||||||
return fBufferFreeSem;
|
|
||||||
|
|
||||||
PublishTime(-50, 0, 0);
|
PublishTime(-50, 0, 0);
|
||||||
|
|
||||||
fThread = spawn_thread(_OutputThreadEntry, "multi_audio audio output",
|
fThread = spawn_thread(_OutputThreadEntry, "multi_audio audio output",
|
||||||
B_REAL_TIME_PRIORITY, this);
|
B_REAL_TIME_PRIORITY, this);
|
||||||
if (fThread < B_OK) {
|
if (fThread < 0)
|
||||||
delete_sem(fBufferFreeSem);
|
|
||||||
return fThread;
|
return fThread;
|
||||||
}
|
|
||||||
|
|
||||||
resume_thread(fThread);
|
resume_thread(fThread);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -2113,10 +2096,9 @@ status_t
|
|||||||
MultiAudioNode::_StopOutputThread()
|
MultiAudioNode::_StopOutputThread()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
delete_sem(fBufferFreeSem);
|
atomic_set(&fQuitThread, 1);
|
||||||
|
|
||||||
status_t exitValue;
|
wait_for_thread(fThread, NULL);
|
||||||
wait_for_thread(fThread, &exitValue);
|
|
||||||
fThread = -1;
|
fThread = -1;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ private:
|
|||||||
// not the defaults that are in the parameters
|
// not the defaults that are in the parameters
|
||||||
bigtime_t fBufferPeriod;
|
bigtime_t fBufferPeriod;
|
||||||
|
|
||||||
sem_id fBufferFreeSem;
|
int32 fQuitThread;
|
||||||
thread_id fThread;
|
thread_id fThread;
|
||||||
MultiAudioDevice* fDevice;
|
MultiAudioDevice* fDevice;
|
||||||
bool fTimeSourceStarted;
|
bool fTimeSourceStarted;
|
||||||
|
|||||||
Reference in New Issue
Block a user