commit ddc8769bfa305d593c7948d4ea49cb6c0bdc9a41
parent e62e6178dc94edd27e5841888758db6becb94419
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date: Thu, 8 Jul 2010 14:06:40 +1000
Properly quit the reader thread
Diffstat:
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/spek-pipeline.vala b/src/spek-pipeline.vala
@@ -42,7 +42,7 @@ namespace Spek {
private float[] input;
private float[] output;
- private unowned Thread thread = null;
+ private unowned Thread reader_thread = null;
private bool quit = false;
public Pipeline (string file_name, int bands, int samples, int threshold, Callback cb) {
@@ -96,23 +96,24 @@ namespace Spek {
stop ();
try {
- thread = Thread.create (thread_func, true);
- thread.set_priority (ThreadPriority.LOW);
+ reader_thread = Thread.create (reader_func, true);
} catch (ThreadError e) {
- assert_not_reached ();
+ stop ();
}
}
public void stop () {
- if (thread != null) {
- quit = true;
- thread.join ();
+ if (reader_thread != null) {
+ lock (quit) {
+ quit = true;
+ }
+ reader_thread.join ();
quit = false;
- thread = null;
+ reader_thread = null;
}
}
- private void * thread_func () {
+ private void * reader_func () {
int pos = 0;
int sample = 0;
int64 frames = 0;
@@ -124,12 +125,15 @@ namespace Spek {
Posix.memset (output, 0, sizeof (float) * bands);
while ((size = cx.read (this.buffer)) > 0) {
- uint8 *buffer = (uint8 *) this.buffer;
- var block_size = cx.width * cx.channels / 8;
- while (size >= block_size) {
+ lock (quit) {
if (quit) {
return null;
}
+ }
+
+ uint8 *buffer = (uint8 *) this.buffer;
+ var block_size = cx.width * cx.channels / 8;
+ while (size >= block_size) {
input[pos] = average_input (buffer);
buffer += block_size;
size -= block_size;