summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-04-15 16:32:37 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-04-15 16:32:37 +0200
commita30db969bd25ad4641d5fd3974513b37f9b01e0e (patch)
tree0edc5652aa85bb57ffbdb5188b7862079b01289d
parent553b93dc32abe13564e3c92b08cc4a24adac5091 (diff)
Make Player thread behave nicely on shutdown.
-rw-r--r--dgedit/player.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/dgedit/player.cc b/dgedit/player.cc
index b916920..5f5c344 100644
--- a/dgedit/player.cc
+++ b/dgedit/player.cc
@@ -46,8 +46,8 @@ Player::Player()
Player::~Player()
{
- ao_close(dev);
- ao_shutdown();
+ running = false; // Signal player thread to stop
+ wait(); // Wait for player thread to stop.
}
void Player::run()
@@ -62,8 +62,10 @@ void Player::run()
dev = ao_open_live(ao_default_driver_id(), &sf, 0);
+ running = true;
+
short s[BUFSZ];
- while(true) {
+ while(running) {
if(playing) {
for(size_t i = 0; i < BUFSZ; i++) {
double sample = 0.0;
@@ -84,6 +86,9 @@ void Player::run()
msleep(22);
}
}
+
+ ao_close(dev);
+ ao_shutdown();
}
void Player::setGainScalar(double g)