summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-08-28 21:32:52 +0200
committerGravatar Alexey Yakovenko <waker@users.sourceforge.net>2013-08-28 21:32:52 +0200
commitd48b231a9f258688fbe87cb6a07934d72e16b855 (patch)
tree773794cebfe275c8d7df64e31011632c6dfe2441
parent92882b86653d874778cd02cda72e9ed3b9df7f20 (diff)
osx: fixed termination
-rw-r--r--main.c184
-rw-r--r--plugins/gtkui/gtkui.c20
2 files changed, 98 insertions, 106 deletions
diff --git a/main.c b/main.c
index 95375d34..38492360 100644
--- a/main.c
+++ b/main.c
@@ -704,93 +704,24 @@ typedef struct {
int size;
} main_args_t;
-uintptr_t gui_cond, gui_mutex;
-void
-plugloader (void *ctx) {
+//uintptr_t gui_cond, gui_mutex;
+uintptr_t mainloop_tid;
+
+static void
+mainloop_thread (void *ctx) {
main_args_t *args = ctx;
int argc = args->argc;
char **argv = args->argv;
char *cmdline = args->cmdline;
int size = args->size;
- pl_load_all ();
- plt_set_curr_idx (conf_get_int ("playlist.current", 0));
-
- // execute server commands in local context
- int noloadpl = 0;
- if (argc > 1) {
- int res = server_exec_command_line (cmdline, size, NULL, 0);
- // some of the server commands ran on 1st instance should terminate it
- if (res == 2) {
- noloadpl = 1;
- }
- else if (res > 0) {
- exit (0);
- }
- else if (res < 0) {
- exit (-1);
- }
- }
-
- free (cmdline);
-
-#if 0
- signal (SIGTERM, sigterm_handler);
- atexit (atexit_handler); // helps to save in simple cases
-#endif
-
- // start all subsystems
- messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
-
- streamer_init ();
-
- plug_connect_all ();
- //messagepump_push (DB_EV_PLUGINSLOADED, 0, 0, 0);
- cond_signal (gui_cond);
-
-
- if (!noloadpl) {
- restore_resume_state ();
- }
- server_tid = thread_start (server_loop, NULL);
- // this runs in main thread (blocks right here)
+ // this runs until DB_EV_TERMINATE is sent (blocks right here)
player_mainloop ();
- // terminate server and wait for completion
- if (server_tid) {
- server_terminate = 1;
- thread_join (server_tid);
- server_tid = 0;
- }
-
- // save config
- pl_save_all ();
- conf_save ();
-
- // delete legacy session file
- {
- char sessfile[1024]; // $HOME/.config/deadbeef/session
- if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) {
- unlink (sessfile);
- }
- }
-
- // stop receiving messages from outside
- server_close ();
-
- // plugins might still hold references to playitems,
- // and query configuration in background
- // so unload everything 1st before final cleanup
- plug_disconnect_all ();
- plug_unload_all ();
-
- // at this point we can simply do exit(0), but let's clean up for debugging
- pl_free (); // may access conf_*
- conf_free ();
- messagepump_free ();
- plug_cleanup ();
-
- fprintf (stderr, "hej-hej!\n");
+ // tell the gui thread to finish
+ DB_plugin_t *gui = plug_get_for_id ("gtkui3_1");
+ gui->stop ();
+ //cond_signal (gui_cond);
return;
}
@@ -1042,19 +973,100 @@ main (int argc, char *argv[]) {
if (plug_load_all ()) { // required to add files to playlist from commandline
exit (-1);
}
+ pl_load_all ();
+ plt_set_curr_idx (conf_get_int ("playlist.current", 0));
+
+ // execute server commands in local context
+ int noloadpl = 0;
+ if (argc > 1) {
+ int res = server_exec_command_line (cmdline, size, NULL, 0);
+ // some of the server commands ran on 1st instance should terminate it
+ if (res == 2) {
+ noloadpl = 1;
+ }
+ else if (res > 0) {
+ exit (0);
+ }
+ else if (res < 0) {
+ exit (-1);
+ }
+ }
-
+ free (cmdline);
- gui_cond = cond_create ();
- gui_mutex = mutex_create ();
+#if 0
+ signal (SIGTERM, sigterm_handler);
+ atexit (atexit_handler); // helps to save in simple cases
+#endif
+
+ // start all subsystems
+ messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0);
+
+ streamer_init ();
+
+ plug_connect_all ();
+ //messagepump_push (DB_EV_PLUGINSLOADED, 0, 0, 0);
+ //cond_signal (gui_cond);
+
+ if (!noloadpl) {
+ restore_resume_state ();
+ }
+
+ server_tid = thread_start (server_loop, NULL);
+
+ //gui_cond = cond_create ();
+ //gui_mutex = mutex_create ();
main_args_t args = {argc,argv,cmdline,size};
- thread_start (plugloader, &args);
- printf ("waiting for GUI\n");
- cond_wait (gui_cond, gui_mutex);
-
+ mainloop_tid = thread_start (mainloop_thread, &args);
+// fprintf (stderr, "waiting for GUI\n");
+// cond_wait (gui_cond, gui_mutex);
+// mutex_unlock (gui_mutex);
+
DB_plugin_t *gui = plug_get_for_id ("gtkui3_1");
gui->command (10, 0);
+ fprintf (stderr, "gui plugin has quit; waiting for mainloop thread to finish\n");
+ thread_join (mainloop_tid);
+
+ // terminate server and wait for completion
+ if (server_tid) {
+ server_terminate = 1;
+ thread_join (server_tid);
+ server_tid = 0;
+ }
+
+ // save config
+ pl_save_all ();
+ conf_save ();
+
+ // delete legacy session file
+ {
+ char sessfile[1024]; // $HOME/.config/deadbeef/session
+ if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) {
+ unlink (sessfile);
+ }
+ }
+
+ // stop receiving messages from outside
+ server_close ();
+
+ // plugins might still hold references to playitems,
+ // and query configuration in background
+ // so unload everything 1st before final cleanup
+ plug_disconnect_all ();
+ plug_unload_all ();
+
+ // at this point we can simply do exit(0), but let's clean up for debugging
+ pl_free (); // may access conf_*
+ conf_free ();
+
+ fprintf (stderr, "messagepump_free\n");
+ messagepump_free ();
+ fprintf (stderr, "plug_cleanup\n");
+ plug_cleanup ();
+
+ fprintf (stderr, "hej-hej!\n");
+
return 0;
}
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 13ec7e68..e932915b 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -66,8 +66,6 @@
static ddb_gtkui_t plugin;
DB_functions_t *deadbeef;
-static intptr_t gtk_tid;
-
// cover art loading plugin
DB_artwork_plugin_t *coverart_plugin = NULL;
@@ -761,7 +759,6 @@ volumebar_redraw (void) {
// ddb_tabstrip_refresh (DDB_TABSTRIP (ts));
//}
-static int gtk_initialized = 0;
static gint refresh_timeout = 0;
void
@@ -831,17 +828,6 @@ gtkui_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
send_messages_to_widgets (rootwidget, id, ctx, p1, p2);
}
switch (id) {
- case DB_EV_PLUGINSLOADED:
- break;
- // gtk must be running in separate thread
- gtk_initialized = 0;
- gtk_tid = deadbeef->thread_start (gtkui_thread, NULL);
- // wait until gtk finishes initializing
- while (!gtk_initialized) {
- usleep (10000);
- }
-
- break;
case DB_EV_ACTIVATED:
g_idle_add (activate_cb, NULL);
break;
@@ -1102,7 +1088,6 @@ gtkui_thread (void *ctx) {
deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V", fmt, sizeof (fmt));
deadbeef->pl_format_title (NULL, -1, str, sizeof (str), -1, fmt);
gtk_window_set_title (GTK_WINDOW (mainwin), str);
- gtk_initialized = 1;
g_idle_add (unlock_playlist_columns_cb, NULL);
@@ -1364,11 +1349,6 @@ gtkui_stop (void) {
}
trace ("quitting gtk\n");
g_idle_add (quit_gtk_cb, NULL);
- trace ("waiting for gtk thread to finish\n");
- deadbeef->thread_join (gtk_tid);
- trace ("gtk thread finished\n");
- gtk_tid = 0;
- //main_playlist_free ();
trace ("gtkui_stop completed\n");
return 0;
}