Merge "Merge "Fix emulator GPS support"" into tools_r7
diff --git a/emulator/gps/gps_qemu.c b/emulator/gps/gps_qemu.c
index ce14fcb..a4699d3 100644
--- a/emulator/gps/gps_qemu.c
+++ b/emulator/gps/gps_qemu.c
@@ -660,7 +660,7 @@
  * when started, messages from the QEMU GPS daemon. these are simple NMEA sentences
  * that must be parsed to be converted into GPS fixes sent to the framework
  */
-static void*
+static void
 gps_state_thread( void*  arg )
 {
     GpsState*   state = (GpsState*) arg;
@@ -693,7 +693,7 @@
         for (ne = 0; ne < nevents; ne++) {
             if ((events[ne].events & (EPOLLERR|EPOLLHUP)) != 0) {
                 LOGE("EPOLLERR or EPOLLHUP after epoll_wait() !?");
-                goto Exit;
+                return;
             }
             if ((events[ne].events & EPOLLIN) != 0) {
                 int  fd = events[ne].data.fd;
@@ -709,7 +709,7 @@
 
                     if (cmd == CMD_QUIT) {
                         D("gps thread quitting on demand");
-                        goto Exit;
+                        return;
                     }
                     else if (cmd == CMD_START) {
                         if (!started) {
@@ -754,13 +754,11 @@
             }
         }
     }
-Exit:
-    return NULL;
 }
 
 
 static void
-gps_state_init( GpsState*  state )
+gps_state_init( GpsState*  state, GpsCallbacks* callbacks )
 {
     state->init       = 1;
     state->control[0] = -1;
@@ -781,11 +779,15 @@
         goto Fail;
     }
 
-    if ( pthread_create( &state->thread, NULL, gps_state_thread, state ) != 0 ) {
+    state->thread = callbacks->create_thread_cb( "gps_state_thread", gps_state_thread, state );
+
+    if ( !state->thread ) {
         LOGE("could not create gps thread: %s", strerror(errno));
         goto Fail;
     }
 
+    state->callbacks = *callbacks;
+
     D("gps state initialized");
     return;
 
@@ -809,13 +811,11 @@
     GpsState*  s = _gps_state;
 
     if (!s->init)
-        gps_state_init(s);
+        gps_state_init(s, callbacks);
 
     if (s->fd < 0)
         return -1;
 
-    s->callbacks = *callbacks;
-
     return 0;
 }