-------- Original Message --------
From: - Tue Mar 03 13:25:20 2009
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00800000
X-Mozilla-Keys: Message-ID: <[email protected]>
Date: Tue, 03 Mar 2009 13:24:55 +0100
From: michael <[email protected]>
User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)
MIME-Version: 1.0
To: [email protected],  Android on Freerunner Development 
<[email protected]>
Subject: [RFC patch] GPS stopping and code clean up
Content-Type: multipart/mixed; boundary="------------000703040504060707070204"


>From b151a44e10814828c4cb4313e3cc4323d99f9825 Mon Sep 17 00:00:00 2001
From: Michael Trimarchi <[email protected]>
Date: Tue, 3 Mar 2009 11:32:26 +0100
Subject: [PATCH] Adjust the gps code and semplify it. Remove the mutex. This fix
 seem to resolve the deadlock during shutdown. If the engine is set
 on the Navigation is active and the EventThread can't be stopped

---
 gps_freerunner.c |   60 +++++++++--------------------------------------------
 1 files changed, 11 insertions(+), 49 deletions(-)

diff --git a/gps_freerunner.c b/gps_freerunner.c
index a43b141..540a6e3 100644
--- a/gps_freerunner.c
+++ b/gps_freerunner.c
@@ -19,12 +19,12 @@
 
 #define  GPS_DEBUG  0
 
-#define  DFR(...)   LOGD(__VA_ARGS__)
-
 #if GPS_DEBUG
-#  define  D(...)   LOGD(__VA_ARGS__)
+# define  DFR(...)   LOGD(__VA_ARGS__)
+# define  D(...)   LOGD(__VA_ARGS__)
 #else
-#  define  D(...)   ((void)0)
+# define  D(...)   ((void)0)
+# define  DFR(...)   ((void)0)
 #endif
 
 #define GPS_STATUS_CB(_cb, _s)    \
@@ -919,8 +919,6 @@ gps_state_thread( void*  arg )
 
     gps_dev_init(gps_fd);
 
-    GPS_STATUS_CB(state->callbacks, GPS_STATUS_ENGINE_ON); 
-
     // now loop
     for (;;) {
         struct epoll_event   events[2];
@@ -993,24 +991,13 @@ gps_state_thread( void*  arg )
                 }
                 else if (fd == gps_fd)
                 {
-                    char  buff[32];
-                    D("gps fd event");
-                    for (;;) {
-                        int  nn, ret;
-
-                        ret = read( fd, buff, sizeof(buff) );
-                        if (ret < 0) {
-                            if (errno == EINTR)
-                                continue;
-                            if (errno != EWOULDBLOCK)
-                                LOGE("error while reading from gps daemon socket: %s:", strerror(errno));
-                            break;
-                        }
-                        D("received %d bytes: %.*s", ret, ret, buff);
+                    char  buff[512];
+                    int  nn, ret;
+
+                    ret = read( fd, buff, sizeof(buff) );
+                    if (ret > 0)
                         for (nn = 0; nn < ret; nn++)
                             nmea_reader_addc( reader, buff[nn] );
-                    }
-                    D("gps fd event end");
                 }
                 else
                 {
@@ -1023,8 +1010,6 @@ Exit:
 
     gps_dev_deinit(gps_fd);
 
-    GPS_STATUS_CB(state->callbacks, GPS_STATUS_ENGINE_OFF);
-
     return NULL;
 }
 
@@ -1033,30 +1018,11 @@ gps_timer_thread( void*  arg )
 {
 
   GpsState *state = (GpsState *)arg;
-  pthread_mutex_t timer_mtx;
-  pthread_cond_t  timer_cond;
-  struct timespec to;
 
   DFR("gps entered timer thread");
 
-  pthread_mutex_init(&timer_mtx, NULL);
-  pthread_cond_init(&timer_cond, NULL);
-
   do {
 
-    clock_gettime(CLOCK_MONOTONIC, &to);
-
-    if (state->fix_freq > 0) {
-      to.tv_sec += state->fix_freq;
-    } else {
-      to.tv_sec++;
-    }
-
-    pthread_mutex_lock(&timer_mtx);
-
-    // binoic specific function - non POSIX */
-    pthread_cond_timedwait_monotonic(&timer_cond, &timer_mtx, &to);
-
     DFR ("gps timer exp");
 
     GPS_STATE_LOCK_FIX(state);
@@ -1089,14 +1055,10 @@ gps_timer_thread( void*  arg )
     }
 
     GPS_STATE_UNLOCK_FIX(state);
-
-    pthread_mutex_unlock(&timer_mtx);
+    sleep(state->fix_freq);
 
   } while(state->init == STATE_START);
 
-  pthread_mutex_destroy(&timer_mtx);
-  pthread_cond_destroy(&timer_cond);
-
   DFR("gps timer thread destroyed");
 
   return NULL;
@@ -1257,7 +1219,7 @@ freerunner_gps_set_fix_frequency(int freq)
 
     DFR("%s: called", __FUNCTION__);
 
-    s->fix_freq = freq;
+    s->fix_freq = (freq <= 0) ? 1 : freq;
 
     DFR("gps fix frquency set to %d secs", freq);
 }
-- 
1.5.6.5


_______________________________________________
android-freerunner mailing list
[email protected]
http://android.koolu.org/listinfo.cgi/android-freerunner-koolu.org

Reply via email to