From 388def5aa1c27e6278ab088ded40ad46ec7e40b5 Mon Sep 17 00:00:00 2001 From: Kamala Narasimhan Date: Tue, 3 Feb 2009 11:13:18 -0500 Subject: [PATCH] xenpmd workaround for uClibc pthread issue. 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 | 3 ++- tools/xenpmd/xenpmd.c | 41 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c index 54b546b..56204e2 100644 --- a/tools/xenpmd/acpi-events.c +++ b/tools/xenpmd/acpi-events.c @@ -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(); } diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c index 2d29c0c..507f8f0 100644 --- a/tools/xenpmd/xenpmd.c +++ b/tools/xenpmd/xenpmd.c @@ -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; +} + -- 2.39.5