r283 - trunk/libfetch
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri May 18 12:31:04 EDT 2007
Author: icculus
Date: 2007-05-18 12:31:04 -0400 (Fri, 18 May 2007)
New Revision: 283
Modified:
trunk/libfetch/common.c
Log:
Whoops, race condition in my thread code.
Modified: trunk/libfetch/common.c
===================================================================
--- trunk/libfetch/common.c 2007-05-18 15:27:50 UTC (rev 282)
+++ trunk/libfetch/common.c 2007-05-18 16:31:04 UTC (rev 283)
@@ -990,6 +990,13 @@
uint32 avail = 0;
while (!io->ready(io))
MojoPlatform_sleep(100);
+
+ if (pthread_mutex_lock(&info->mutex) != 0)
+ {
+ info->stop = info->error = true; // oh well.
+ return -1;
+ } // if
+
avail = MojoRing_availableForGet(info->ring);
if (avail > 0)
{
@@ -997,9 +1004,13 @@
avail = bufsize;
MojoRing_get(info->ring, (uint8 *) buf, avail);
info->bytes_read += avail;
- return avail;
} // if
+ pthread_mutex_unlock(&info->mutex);
+
+ if (avail > 0)
+ return avail;
+
if (info->error)
return -1;
More information about the mojosetup-commits
mailing list