1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 12_thread_cond_wait by <hubert@uhoreg.ca>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Switch to conditional wait instead of just unlocking a mutex. More
## DP: portable.
## DP: taken from alsaplayer CVS (committed on 2004-02-15)
@DPATCH@
--- alsaplayer-0.99.76/alsaplayer/CorePlayer.h 2 Nov 2003 00:22:43 -0000 1.27
+++ alsaplayer-cvs/alsaplayer/CorePlayer.h 15 Feb 2004 18:39:58 -0000 1.28
@@ -104,6 +104,7 @@
pthread_t producer_thread;
pthread_mutex_t player_mutex;
pthread_mutex_t counter_mutex;
+ pthread_cond_t producer_ready;
pthread_mutex_t thread_mutex;
pthread_mutex_t notifier_mutex;
#if !defined(EMBEDDED)
--- alsaplayer-0.99.76/app/CorePlayer.cpp 10 Nov 2003 19:57:45 -0000 1.73
+++ alsaplayer-cvs/app/CorePlayer.cpp 15 Feb 2004 18:39:52 -0000 1.74
@@ -206,6 +206,7 @@
pthread_mutex_init(&counter_mutex, NULL);
pthread_mutex_init(&player_mutex, NULL);
pthread_mutex_init(¬ifier_mutex, NULL);
+ pthread_cond_init(&producer_ready, NULL);
producer_thread = 0;
total_frames = 0;
@@ -651,11 +652,8 @@
}
producing = false;
streaming = false;
-
- /* We don't know locked it or not */
- pthread_mutex_trylock (&counter_mutex);
- pthread_mutex_unlock (&counter_mutex);
-
+ //alsaplayer_error("Signalling 6...");
+ pthread_cond_signal(&producer_ready);
#ifdef DEBUG
alsaplayer_error("Waiting for producer_thread to finish...");
#endif
@@ -663,7 +661,7 @@
if (pthread_join(producer_thread, NULL)) {
alsaplayer_error("producer_thread not running...");
}
- }
+ }
pthread_mutex_destroy(&counter_mutex);
pthread_mutex_init(&counter_mutex, NULL);
@@ -918,7 +916,8 @@
new_frame_number = new_write_buf->start;
write_buf_changed = 1;
read_direction = direction;
- pthread_mutex_unlock(&counter_mutex);
+ //alsaplayer_error("Signalling...1");
+ pthread_cond_signal(&producer_ready);
}
return 0;
@@ -1013,7 +1012,8 @@
new_write_buf->start = jump_point;
new_frame_number = jump_point;
write_buf_changed = 1;
- pthread_mutex_unlock(&counter_mutex);
+ //alsaplayer_error("Signalling 2...");
+ pthread_cond_signal(&producer_ready);
}
#ifdef EMBEDDED
// provide a fast path implementation for the common case (no pitch)
@@ -1040,7 +1040,8 @@
// get next block
read_buf = read_buf->next;
- pthread_mutex_unlock(&counter_mutex);
+ //alsaplayer_error("Signalling 3...");
+ pthread_cond_signal(&producer_ready);
read_buf->buf->SetReadDirection(DIR_FORWARD);
read_buf->buf->ResetRead();
in_buf = (int *)read_buf->buf->buffer_data;
@@ -1073,7 +1074,8 @@
read_buf->start);
}
read_buf = read_buf->next;
- pthread_mutex_unlock(&counter_mutex);
+ //alsaplayer_error("Signalling 4...");
+ pthread_cond_signal(&producer_ready);
read_buf->buf->SetReadDirection(DIR_FORWARD);
read_buf->buf->ResetRead();
in_buf = (int *)read_buf->buf->buffer_data;
@@ -1100,7 +1102,8 @@
return samples;
}
read_buf = read_buf->prev;
- pthread_mutex_unlock(&counter_mutex);
+ //alsaplayer_error("Signalling 5...");
+ pthread_cond_signal(&producer_ready);
read_buf->buf->SetReadDirection(DIR_BACK);
read_buf->buf->ResetRead();
int buf_size = read_buf->buf->write_index;
@@ -1217,6 +1220,10 @@
} else {
//alsaplayer_error("producer: waiting for free buffer");
pthread_mutex_lock(&obj->counter_mutex);
+ //alsaplayer_error("Waiting for a signal...");
+ pthread_cond_wait(&obj->producer_ready, &obj->counter_mutex);
+ //alsaplayer_error("Got signalled...");
+ pthread_mutex_unlock(&obj->counter_mutex);
//alsaplayer_error("producer: unblocked");
}
}
|