[pulseaudio-commits] r1671 - /branches/lennart/src/pulsecore/protocol-native.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Wed Aug 15 15:48:01 PDT 2007
Author: lennart
Date: Thu Aug 16 00:47:59 2007
New Revision: 1671
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1671&root=3Dpulseaudio&vi=
ew=3Drev
Log:
fix an awful race condition when handling data requests
Modified:
branches/lennart/src/pulsecore/protocol-native.c
Modified: branches/lennart/src/pulsecore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
protocol-native.c?rev=3D1671&root=3Dpulseaudio&r1=3D1670&r2=3D1671&view=3Dd=
iff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/protocol-native.c (original)
+++ branches/lennart/src/pulsecore/protocol-native.c Thu Aug 16 00:47:59 20=
07
@@ -537,12 +537,22 @@
switch (code) {
case PLAYBACK_STREAM_MESSAGE_REQUEST_DATA: {
pa_tagstruct *t;
- int32_t l;
-
- if ((l =3D pa_atomic_load(&s->missing)) <=3D 0)
+ int32_t l =3D 0;
+
+ for (;;) {
+ int32_t k;
+ =
+ if ((k =3D pa_atomic_load(&s->missing)) <=3D 0)
+ break;
+
+ l +=3D k;
+ =
+ if (pa_atomic_sub(&s->missing, k) <=3D k)
+ break;
+ }
+
+ if (l <=3D 0)
break;
- =
- pa_assert_se(pa_atomic_sub(&s->missing, l) >=3D l);
=
t =3D pa_tagstruct_new(NULL, 0);
pa_tagstruct_putu32(t, PA_COMMAND_REQUEST);
@@ -551,7 +561,7 @@
pa_tagstruct_putu32(t, l);
pa_pstream_send_tagstruct(s->connection->pstream, t);
=
-/* pa_log("Requesting %u bytes", l); */
+/* pa_log("Requesting %u bytes", l); */
break;
}
=
@@ -770,24 +780,22 @@
/* Called from thread context */
static void request_bytes(playback_stream *s) {
size_t new_missing, delta, previous_missing;
-
-/* pa_log("request_bytes()"); */
+ size_t minreq;
+
playback_stream_assert_ref(s);
=
new_missing =3D pa_memblockq_missing(s->memblockq);
- =
- if (new_missing <=3D s->last_missing) {
- s->last_missing =3D new_missing;
- return;
- }
-
- delta =3D new_missing - s->last_missing;
+ delta =3D new_missing > s->last_missing ? new_missing - s->last_missin=
g : 0;
s->last_missing =3D new_missing;
=
+ if (delta <=3D 0)
+ return;
+
/* pa_log("request_bytes(%u)", delta); */
+ minreq =3D pa_memblockq_get_minreq(s->memblockq);
=
previous_missing =3D pa_atomic_add(&s->missing, delta);
- if (previous_missing < pa_memblockq_get_minreq(s->memblockq) && previo=
us_missing+delta >=3D pa_memblockq_get_minreq(s->memblockq))
+ if (previous_missing < minreq && previous_missing+delta >=3D minreq)
pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(s), PLAYB=
ACK_STREAM_MESSAGE_REQUEST_DATA, NULL, 0, NULL, NULL);
}
=
More information about the pulseaudio-commits
mailing list