Skip to content

Commit

Permalink
Check whether the thread is still running
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Jul 12, 2024
1 parent 59886a5 commit 8266c64
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/tlTimeline/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace tl
}
#endif
p.log(context);
p.thread.running = true;
p.running = true;
p.thread.thread = std::thread(
[this]
{
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace tl

p.thread.cacheTimer = std::chrono::steady_clock::now();
p.thread.logTimer = std::chrono::steady_clock::now();
while (p.thread.running)
while (p.running)
{
const auto t0 = std::chrono::steady_clock::now();

Expand Down Expand Up @@ -325,7 +325,7 @@ namespace tl
Player::~Player()
{
TLRENDER_P();
p.thread.running = false;
p.running = false;
if (p.thread.thread.joinable())
{
p.thread.thread.join();
Expand Down
3 changes: 2 additions & 1 deletion lib/tlTimeline/PlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ namespace tl
p->audioThread.info.sampleRate).rescaled_to(p->ioInfo.audio.sampleRate).value();
int64_t seconds = p->ioInfo.audio.sampleRate > 0 ? (frame / p->ioInfo.audio.sampleRate) : 0;
int64_t offset = frame - seconds * p->ioInfo.audio.sampleRate;
while (audio::getSampleCount(p->audioThread.buffer) < nFrames)
while (audio::getSampleCount(p->audioThread.buffer) < nFrames &&
p->running)
{
//std::cout << "frame: " << frame << std::endl;
//std::cout << "seconds: " << seconds << std::endl;
Expand Down
3 changes: 2 additions & 1 deletion lib/tlTimeline/PlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace tl
std::shared_ptr<observer::Value<PlayerCacheInfo> > cacheInfo;
std::shared_ptr<observer::ValueObserver<bool> > timelineObserver;

std::atomic<bool> running;

struct Mutex
{
Playback playback = Playback::Stop;
Expand Down Expand Up @@ -128,7 +130,6 @@ namespace tl
std::map<int64_t, AudioRequest> audioDataRequests;
std::chrono::steady_clock::time_point cacheTimer;
std::chrono::steady_clock::time_point logTimer;
std::atomic<bool> running;
std::thread thread;
};
Thread thread;
Expand Down

0 comments on commit 8266c64

Please sign in to comment.