]> xenbits.xen.org Git - xenclient/xen.git/commitdiff
xenpmd workaround for uClibc pthread issue.
authorKamala Narasimhan <kamala.narasimhan@citrix.com>
Tue, 3 Feb 2009 16:13:18 +0000 (11:13 -0500)
committerKamala Narasimhan <kamala.narasimhan@citrix.com>
Tue, 3 Feb 2009 16:13:18 +0000 (11:13 -0500)
This check-in creates an additional worker thread to workaround
uClibc pthread issue.  Plus a minor tweak to acpid power button event
string.

tools/xenpmd/acpi-events.c
tools/xenpmd/xenpmd.c

index 54b546bd7bfe2d579d83277487cabc095a9fb858..56204e2586b0d314d6c95c6930f5f8f42ea112ce 100644 (file)
@@ -105,7 +105,8 @@ void process_acpi_message(char *acpi_buffer)
         return;
     }
 
-    if ( strstr(acpi_buffer, "PBTN") )
+    if ( (strstr(acpi_buffer, "PBTN")) ||
+         (strstr(acpi_buffer, "PWRF")) )
         handle_pbtn_pressed_event();
 }
 
index 2d29c0cc5b20ffc04479714dad91b3fb020a9343..507f8f022b8e31850ed01e6ae4eacbfa24662d35 100644 (file)
@@ -85,6 +85,8 @@ struct battery_status {
 };
 
 struct xs_handle *xs;
+static pthread_t worker_thread;
+
 extern void initialize_system_state_info(void);
 extern void monitor_acpi_events(void);
 extern void acpi_events_cleanup(void);
@@ -504,21 +506,28 @@ static void daemonize(void)
 }
 #endif /* RUN_STANDALONE */
 
-int main(int argc, char *argv[])
+/*
+ * IMPORTANT: From the child process, we create a new thread
+ * to monitor acpid events.  However, due to a bug in uClibc,
+ * the child process main thread does not get time slice
+ * after spawning a new thread.  To work around this, we create
+ * a worker thread and then create an acpid monitor thread from
+ * this worker thread.  This way both the worker thread and acpid
+ * thread will get time slices.  This workaround will be removed
+ * once uClibc bug is fixed.
+ */
+static void *worker_thread_routine(void *arg)
 {
-#ifndef RUN_STANDALONE
-    daemonize();
-#endif
     xs = (struct xs_handle *)xs_daemon_open();
-    if ( xs == NULL ) 
-        return -1;
+    if ( xs == NULL )
+        return 0;
 
     initialize_system_state_info();
     monitor_acpi_events();
-    if ( write_one_time_battery_info() == 0 ) 
+    if ( write_one_time_battery_info() == 0 )
     {
         xs_daemon_close(xs);
-        return -1;
+        return 0;
     }
 
     wait_for_and_update_battery_status_request();
@@ -527,3 +536,19 @@ int main(int argc, char *argv[])
     return 0;
 }
 
+int main(int argc, char *argv[])
+{
+#ifndef RUN_STANDALONE
+    daemonize();
+#endif
+
+    /* Refer to worker_thread_routine for why we create additional thread */
+    pthread_create(&worker_thread, NULL, &worker_thread_routine, NULL);
+
+    /* below won't get a time slice because of uClibc bug. */
+    while ( 1 ) 
+        sleep(60);
+
+    return 0;
+}
+