Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/bin/apps/rv/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
#include <sched.h>
#include <sstream>
#include <stdlib.h>
#include <stl_ext/thread_group.h>
#include <signal.h>
#include <string.h>
#include <vector>
Expand Down Expand Up @@ -122,7 +121,7 @@ extern void rvThirdPartyCustomization(TwkApp::Bundle& bundle, char* licarg);
// #error ********* NO VERSION INFORMATION ***********
#else
#ifndef _MSC_VER
#warning********* NO VERSION INFORMATION ***********
#warning ********* NO VERSION INFORMATION ***********
#endif
#endif
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/bin/apps/rvpkg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <sched.h>
#include <sstream>
#include <stdlib.h>
#include <stl_ext/thread_group.h>
#include <string.h>
#include <vector>
#include <set>
Expand Down Expand Up @@ -71,7 +70,7 @@
// #error ********* NO VERSION INFORMATION ***********
#else
#ifndef _MSC_VER
#warning********* NO VERSION INFORMATION ***********
#warning ********* NO VERSION INFORMATION ***********
#endif
#endif
#endif
Expand Down
1 change: 0 additions & 1 deletion src/bin/imgtools/rvio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
#include <iostream>
#include <sched.h>
#include <cstdlib>
#include <stl_ext/thread_group.h>
#include <stl_ext/string_algo.h>
#include <cstring>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion src/bin/imgtools/rvls/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <iostream>
#include <iterator>
#include <numeric>
#include <stl_ext/thread_group.h>
#include <boost/algorithm/string.hpp>
#include <ImfHeader.h>
#include <yaml-cpp/yaml.h>
Expand Down
3 changes: 1 addition & 2 deletions src/bin/nsapps/RV/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <thread>
#include <signal.h>
#include <stdlib.h>
#include <stl_ext/thread_group.h>
#include <string.h>
#include <errno.h>
#include <vector>
Expand Down Expand Up @@ -83,7 +82,7 @@ extern void rvThirdPartyCustomization(TwkApp::Bundle& bundle, char* licarg);
#if NDEBUG
// #error ********* NO VERSION INFORMATION ***********
#else
#warning********* NO VERSION INFORMATION ***********
#warning ********* NO VERSION INFORMATION ***********
#endif
#endif

Expand Down
1 change: 1 addition & 0 deletions src/lib/app/RvApp/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <fstream>
#include <iostream>
#include <stl_ext/string_algo.h>
#include <stl_ext/thread_group.h>

extern void TwkMovie_GenericIO_setDebug(bool);
extern void TwkFB_GenericIO_setDebug(bool);
Expand Down
1 change: 1 addition & 0 deletions src/lib/app/RvCommon/RvConsoleApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Rv
, m_pyLibrary(INTERNAL_APPLICATION_NAME)
{
m_pyLibrary.setName("py-media-library");
m_pyLibrary.start();
}

} // namespace Rv
9 changes: 5 additions & 4 deletions src/lib/app/TwkMediaLibrary/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ namespace TwkMediaLibrary
, m_appName(appName)
, m_name(typeName)
, m_taskStop(false)
, m_taskThread(threadTrampoline, this)
{
// globalLibraryMap[typeName] = this;
}
Expand All @@ -359,8 +358,10 @@ namespace TwkMediaLibrary
m_taskCond.notify_one();
}

m_taskThread.join();

if (m_taskThread.joinable())
{
m_taskThread.join();
}
//
// willDeleteSignal() should be sent by derived classes. Its sent
// here as a stop-gap but if this is used is almost certain going
Expand Down Expand Up @@ -636,7 +637,7 @@ namespace TwkMediaLibrary

const Task* Library::referencesToNodeASync(const Node*, PropertyQueryResultFunction) const { return 0; }

void Library::threadTrampoline(Library* library) { library->threadMain(); }
void Library::start() { m_taskThread = Thread(&Library::threadMain, this); }

void Library::addTask(Task* item) const
{
Expand Down
3 changes: 1 addition & 2 deletions src/lib/app/TwkMediaLibrary/TwkMediaLibrary/Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,8 @@ namespace TwkMediaLibrary
// ASync/Parallel Task API
//

static void threadTrampoline(Library*);
void threadMain();

void start();
void addTask(Task*) const;
void cancelTask(const Task*) const;
void cancelTasks(const TaskVector&) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <TwkUtil/Timer.h>

#include <alsa/asoundlib.h>
#include <mutex>

namespace IPCore
{
Expand Down Expand Up @@ -92,7 +93,7 @@ namespace IPCore
snd_pcm_uframes_t m_bufferSize;
pthread_t m_audioThread;
bool m_audioThreadRunning;
pthread_mutex_t m_runningLock;
std::mutex m_runningLock;
};

} // namespace IPCore
Expand Down
35 changes: 19 additions & 16 deletions src/lib/audio/ALSAAudioModule/ALSAAudioRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ namespace IPCore
, m_audioThreadRunning(false)
{
snd_lib_error_set_handler(alsaErrorHandler);
pthread_mutex_init(&m_runningLock, 0);

if (m_parameters.rate == 0)
m_parameters.rate = TWEAK_AUDIO_DEFAULT_SAMPLE_RATE;
Expand Down Expand Up @@ -263,7 +262,6 @@ namespace IPCore
{
AudioRenderer::stop();
shutdown();
pthread_mutex_destroy(&m_runningLock);
}

void ALSAAudioRenderer::createDeviceList()
Expand Down Expand Up @@ -629,7 +627,7 @@ namespace IPCore

snd_pcm_hw_params_set_periods(pcm, params, periods, 0);
snd_pcm_hw_params_set_buffer_size(pcm, params, (period_size * periods) >> 2);

if (snd_pcm_hw_params(pcm, params) >= 0 && rrate == rate)
{
rates.push_back((unsigned int)rate);
Expand Down Expand Up @@ -882,10 +880,11 @@ namespace IPCore
if (!m_pcm)
return;

m_threadGroup.lock(m_runningLock);
m_audioThreadRunning = true;
m_audioThread = pthread_self();
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
m_audioThreadRunning = true;
m_audioThread = pthread_self();
}

//
// Get the current state. (yeah, I know it was just set above)
Expand Down Expand Up @@ -1123,9 +1122,10 @@ namespace IPCore
if (pcmState == SND_PCM_STATE_RUNNING)
snd_pcm_drop(m_pcm);

m_threadGroup.lock(m_runningLock);
m_audioThreadRunning = false;
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
m_audioThreadRunning = false;
}

if (debug)
cout << "DEBUG: audio thread exiting" << endl;
Expand Down Expand Up @@ -1180,12 +1180,14 @@ namespace IPCore

const bool holdOpen = m_parameters.holdOpen;
m_parameters.holdOpen = false;
bool isrunning = false;

AudioRenderer::stop();

m_threadGroup.lock(m_runningLock);
bool isrunning = m_audioThreadRunning;
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
isrunning = m_audioThreadRunning;
}

if (isrunning)
m_threadGroup.control_wait(true, 1.0);
Expand All @@ -1199,9 +1201,10 @@ namespace IPCore
// the audio device until after m_pcm has been zeroed.
//
snd_pcm_t* tmp = m_pcm;
m_threadGroup.lock(m_runningLock);
m_pcm = 0;
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
m_pcm = 0;
}
snd_pcm_close(tmp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <TwkUtil/Timer.h>

#include <alsa/asoundlib.h>
#include <mutex>

namespace IPCore
{
Expand Down Expand Up @@ -92,7 +93,7 @@ namespace IPCore
snd_pcm_uframes_t m_bufferSize;
pthread_t m_audioThread;
bool m_audioThreadRunning;
pthread_mutex_t m_runningLock;
std::mutex m_runningLock;
};

} // namespace IPCore
Expand Down
38 changes: 21 additions & 17 deletions src/lib/audio/ALSASafeAudioModule/ALSASafeAudioRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ namespace IPCore
, m_audioThreadRunning(false)
{
snd_lib_error_set_handler(alsaErrorHandler);
pthread_mutex_init(&m_runningLock, 0);

if (m_parameters.rate == 0)
m_parameters.rate = TWEAK_AUDIO_DEFAULT_SAMPLE_RATE;
Expand Down Expand Up @@ -264,7 +263,6 @@ namespace IPCore
{
AudioRenderer::stop();
shutdown();
pthread_mutex_destroy(&m_runningLock);
}

void ALSASafeAudioRenderer::createDeviceList()
Expand Down Expand Up @@ -639,7 +637,7 @@ namespace IPCore

snd_pcm_hw_params_set_periods(pcm, params, periods, 0);
snd_pcm_hw_params_set_buffer_size(pcm, params, (period_size * periods) >> 2);

if (snd_pcm_hw_params(pcm, params) >= 0 && rrate == rate)
{
rates.push_back((unsigned int)rate);
Expand Down Expand Up @@ -890,10 +888,11 @@ namespace IPCore
if (!m_pcm)
return;

m_threadGroup.lock(m_runningLock);
m_audioThreadRunning = true;
m_audioThread = pthread_self();
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
m_audioThreadRunning = true;
m_audioThread = pthread_self();
}

//
// Get the current state. (yeah, I know it was just set above)
Expand Down Expand Up @@ -1130,10 +1129,10 @@ namespace IPCore
return;
if (pcmState == SND_PCM_STATE_RUNNING)
snd_pcm_drop(m_pcm);

m_threadGroup.lock(m_runningLock);
m_audioThreadRunning = false;
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
m_audioThreadRunning = false;
}

if (debug)
cout << "DEBUG: audio thread exiting" << endl;
Expand Down Expand Up @@ -1188,12 +1187,14 @@ namespace IPCore

const bool holdOpen = m_parameters.holdOpen;
m_parameters.holdOpen = false;
bool isrunning = false;

AudioRenderer::stop();

m_threadGroup.lock(m_runningLock);
bool isrunning = m_audioThreadRunning;
m_threadGroup.unlock(m_runningLock);
{
std::lock_guard<std::mutex> guard(m_runningLock);
isrunning = m_audioThreadRunning;
}

if (isrunning)
m_threadGroup.control_wait(true, 1.0);
Expand All @@ -1207,9 +1208,12 @@ namespace IPCore
// the audio device until after m_pcm has been zeroed.
//
snd_pcm_t* tmp = m_pcm;
m_threadGroup.lock(m_runningLock);
m_pcm = 0;
m_threadGroup.unlock(m_runningLock);

{
std::lock_guard<std::mutex> guard(m_runningLock);
m_pcm = 0;
}

snd_pcm_close(tmp);
}

Expand Down
Loading
Loading