diff recpt1/recpt1.c @ 125:a910b49dfbee

work in progress improvement: - fix bugs around cond_timedwait - try to avoid sticking in PMT analysis
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 21 Feb 2012 15:46:04 +0900
parents d89f0da0a7e4
children 8e0f7191b92e
line wrap: on
line diff
--- a/recpt1/recpt1.c	Thu Feb 16 13:11:38 2012 +0900
+++ b/recpt1/recpt1.c	Tue Feb 21 15:46:04 2012 +0900
@@ -209,18 +209,24 @@
 {
     struct timeval now;
     struct timespec spec;
-
-    gettimeofday(&now, NULL);
-    spec.tv_sec = now.tv_sec + 1;
-    spec.tv_nsec = now.tv_usec * 1000;
+    int retry_count = 0;
 
     pthread_mutex_lock(&p_queue->mutex);
     /* entered critical section */
 
     /* wait while queue is full */
     while(p_queue->num_avail == 0) {
+
+        gettimeofday(&now, NULL);
+        spec.tv_sec = now.tv_sec + 1;
+        spec.tv_nsec = now.tv_usec * 1000;
+
         pthread_cond_timedwait(&p_queue->cond_avail,
                                &p_queue->mutex, &spec);
+        retry_count++;
+        if(retry_count > 60) {
+            f_exit = TRUE;
+        }
         if(f_exit) {
             pthread_mutex_unlock(&p_queue->mutex);
             return;
@@ -249,18 +255,24 @@
     struct timeval now;
     struct timespec spec;
     BUFSZ *buffer;
-
-    gettimeofday(&now, NULL);
-    spec.tv_sec = now.tv_sec + 1;
-    spec.tv_nsec = now.tv_usec * 1000;
+    int retry_count = 0;
 
     pthread_mutex_lock(&p_queue->mutex);
     /* entered the critical section*/
 
     /* wait while queue is empty */
     while(p_queue->num_used == 0) {
+
+        gettimeofday(&now, NULL);
+        spec.tv_sec = now.tv_sec + 1;
+        spec.tv_nsec = now.tv_usec * 1000;
+
         pthread_cond_timedwait(&p_queue->cond_used,
                                &p_queue->mutex, &spec);
+        retry_count++;
+        if(retry_count > 60) {
+            f_exit = TRUE;
+        }
         if(f_exit) {
             pthread_mutex_unlock(&p_queue->mutex);
             return NULL;