From 9f5934d95bac6436ccc9a6dadc57e1e062505a79 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Jan 2009 18:12:00 +0100 Subject: main_notify: renamed source to event_pipe.c We are going to migrate away from the concept of notifying the main thread. There should be events sent to it instead. This patch starts a series to implement that. --- src/Makefile.am | 4 +-- src/client.c | 2 +- src/database.c | 2 +- src/event_pipe.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/event_pipe.h | 39 ++++++++++++++++++++++++ src/idle.c | 2 +- src/main.c | 2 +- src/main_notify.c | 85 ---------------------------------------------------- src/main_notify.h | 39 ------------------------ src/player_control.c | 2 +- src/player_thread.c | 2 +- src/update.c | 2 +- 12 files changed, 133 insertions(+), 133 deletions(-) create mode 100644 src/event_pipe.c create mode 100644 src/event_pipe.h delete mode 100644 src/main_notify.c delete mode 100644 src/main_notify.h diff --git a/src/Makefile.am b/src/Makefile.am index 1c18bc4a..501bfe4e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,7 +44,7 @@ mpd_headers = \ log.h \ ls.h \ main.h \ - main_notify.h \ + event_pipe.h \ daemon.h \ normalize.h \ compress.h \ @@ -125,7 +125,7 @@ mpd_SOURCES = \ log.c \ ls.c \ main.c \ - main_notify.c \ + event_pipe.c \ daemon.c \ normalize.c \ compress.c \ diff --git a/src/client.c b/src/client.c index 9a251d3d..02d35cc4 100644 --- a/src/client.c +++ b/src/client.c @@ -22,7 +22,7 @@ #include "listen.h" #include "permission.h" #include "utils.h" -#include "main_notify.h" +#include "event_pipe.h" #include "dlist.h" #include "idle.h" #include "main.h" diff --git a/src/database.c b/src/database.c index 1472b712..8b66bc07 100644 --- a/src/database.c +++ b/src/database.c @@ -28,7 +28,7 @@ #include "utils.h" #include "dbUtils.h" #include "update.h" -#include "main_notify.h" +#include "event_pipe.h" #include "config.h" #include diff --git a/src/event_pipe.c b/src/event_pipe.c new file mode 100644 index 00000000..ac76209d --- /dev/null +++ b/src/event_pipe.c @@ -0,0 +1,85 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 Warren Dukes + * Copyright (C) 2008 Eric Wong + * + * This project's homepage is: http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "event_pipe.h" +#include "utils.h" +#include "log.h" + +#include +#include +#include + +static int main_pipe[2]; +GThread *main_task; + +static void consume_pipe(void) +{ + char buffer[256]; + ssize_t r = read(main_pipe[0], buffer, sizeof(buffer)); + + if (r < 0 && errno != EAGAIN && errno != EINTR) + FATAL("error reading from pipe: %s\n", strerror(errno)); +} + +static gboolean +main_notify_event(G_GNUC_UNUSED GIOChannel *source, + G_GNUC_UNUSED GIOCondition condition, + G_GNUC_UNUSED gpointer data) +{ + consume_pipe(); + main_notify_triggered(); + return true; +} + +void init_main_notify(void) +{ + GIOChannel *channel; + + main_task = g_thread_self(); + + if (pipe(main_pipe) < 0) + g_error("Couldn't open pipe: %s", strerror(errno)); + if (set_nonblocking(main_pipe[1]) < 0) + g_error("Couldn't set non-blocking I/O: %s", strerror(errno)); + + channel = g_io_channel_unix_new(main_pipe[0]); + g_io_add_watch(channel, G_IO_IN, main_notify_event, NULL); + g_io_channel_unref(channel); + + main_task = g_thread_self(); +} + +void deinit_main_notify(void) +{ + xclose(main_pipe[0]); + xclose(main_pipe[1]); +} + +void wakeup_main_task(void) +{ + ssize_t w = write(main_pipe[1], "", 1); + if (w < 0 && errno != EAGAIN && errno != EINTR) + g_error("error writing to pipe: %s", strerror(errno)); +} + +void wait_main_task(void) +{ + consume_pipe(); +} diff --git a/src/event_pipe.h b/src/event_pipe.h new file mode 100644 index 00000000..ddcc420b --- /dev/null +++ b/src/event_pipe.h @@ -0,0 +1,39 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 Warren Dukes + * Copyright (C) 2008 Eric Wong + * + * This project's homepage is: http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EVENT_PIPE_H +#define EVENT_PIPE_H + +#include + +extern GThread *main_task; + +void init_main_notify(void); + +void deinit_main_notify(void); + +void wakeup_main_task(void); + +void wait_main_task(void); + +void +main_notify_triggered(void); + +#endif /* MAIN_NOTIFY_H */ diff --git a/src/idle.c b/src/idle.c index 4de252ad..f7c3aadd 100644 --- a/src/idle.c +++ b/src/idle.c @@ -22,7 +22,7 @@ */ #include "idle.h" -#include "main_notify.h" +#include "event_pipe.h" #include #include diff --git a/src/main.c b/src/main.c index 8ab0b363..98aeb789 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,7 @@ #include "../config.h" #include "normalize.h" #include "zeroconf.h" -#include "main_notify.h" +#include "event_pipe.h" #include "dirvec.h" #include "songvec.h" #include "tag_pool.h" diff --git a/src/main_notify.c b/src/main_notify.c deleted file mode 100644 index 6a5ff484..00000000 --- a/src/main_notify.c +++ /dev/null @@ -1,85 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 Warren Dukes - * Copyright (C) 2008 Eric Wong - * - * This project's homepage is: http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "main_notify.h" -#include "utils.h" -#include "log.h" - -#include -#include -#include - -static int main_pipe[2]; -GThread *main_task; - -static void consume_pipe(void) -{ - char buffer[256]; - ssize_t r = read(main_pipe[0], buffer, sizeof(buffer)); - - if (r < 0 && errno != EAGAIN && errno != EINTR) - FATAL("error reading from pipe: %s\n", strerror(errno)); -} - -static gboolean -main_notify_event(G_GNUC_UNUSED GIOChannel *source, - G_GNUC_UNUSED GIOCondition condition, - G_GNUC_UNUSED gpointer data) -{ - consume_pipe(); - main_notify_triggered(); - return true; -} - -void init_main_notify(void) -{ - GIOChannel *channel; - - main_task = g_thread_self(); - - if (pipe(main_pipe) < 0) - g_error("Couldn't open pipe: %s", strerror(errno)); - if (set_nonblocking(main_pipe[1]) < 0) - g_error("Couldn't set non-blocking I/O: %s", strerror(errno)); - - channel = g_io_channel_unix_new(main_pipe[0]); - g_io_add_watch(channel, G_IO_IN, main_notify_event, NULL); - g_io_channel_unref(channel); - - main_task = g_thread_self(); -} - -void deinit_main_notify(void) -{ - xclose(main_pipe[0]); - xclose(main_pipe[1]); -} - -void wakeup_main_task(void) -{ - ssize_t w = write(main_pipe[1], "", 1); - if (w < 0 && errno != EAGAIN && errno != EINTR) - g_error("error writing to pipe: %s", strerror(errno)); -} - -void wait_main_task(void) -{ - consume_pipe(); -} diff --git a/src/main_notify.h b/src/main_notify.h deleted file mode 100644 index a02564cc..00000000 --- a/src/main_notify.h +++ /dev/null @@ -1,39 +0,0 @@ -/* the Music Player Daemon (MPD) - * Copyright (C) 2003-2007 Warren Dukes - * Copyright (C) 2008 Eric Wong - * - * This project's homepage is: http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef MPD_MAIN_NOTIFY_H -#define MPD_MAIN_NOTIFY_H - -#include - -extern GThread *main_task; - -void init_main_notify(void); - -void deinit_main_notify(void); - -void wakeup_main_task(void); - -void wait_main_task(void); - -void -main_notify_triggered(void); - -#endif /* MAIN_NOTIFY_H */ diff --git a/src/player_control.c b/src/player_control.c index 049207ae..4560dec8 100644 --- a/src/player_control.c +++ b/src/player_control.c @@ -23,7 +23,7 @@ #include "song.h" #include "idle.h" #include "pcm_utils.h" -#include "main_notify.h" +#include "event_pipe.h" #include #include diff --git a/src/player_thread.c b/src/player_thread.c index bbbb5e61..c8352555 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -22,7 +22,7 @@ #include "audio.h" #include "pcm_utils.h" #include "path.h" -#include "main_notify.h" +#include "event_pipe.h" #include "crossfade.h" #include "song.h" #include "pipe.h" diff --git a/src/update.c b/src/update.c index 67d19723..4d0ed511 100644 --- a/src/update.c +++ b/src/update.c @@ -26,7 +26,7 @@ #include "path.h" #include "playlist.h" #include "utils.h" -#include "main_notify.h" +#include "event_pipe.h" #include "condition.h" #include "update.h" #include "idle.h" -- cgit v1.2.3