emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6c4559d138: Properly wait for app thread exit on Haiku


From: Po Lu
Subject: master 6c4559d138: Properly wait for app thread exit on Haiku
Date: Thu, 14 Apr 2022 21:23:48 -0400 (EDT)

branch: master
commit 6c4559d13865cb5761071ac59f395718b85eb41c
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Properly wait for app thread exit on Haiku
    
    * src/haiku_support.cc (MessageReceived): Handle
    QUIT_APPLICATION.
    (start_running_application): Clean up code a little.
    (wait_for_exit_of_app_thread): New function.
    (BApplication_setup): Add atexit handler to clean up app thread.
    (be_app_quit): Delete function.
    * src/haikuterm.c (haiku_delete_terminal): Un-implement
    function.
    * src/haikuterm.h: Update prototypes.
---
 src/haiku_support.cc | 46 ++++++++++++++++++++++++++++++----------------
 src/haikuterm.c      | 39 +--------------------------------------
 src/haikuterm.h      |  2 --
 3 files changed, 31 insertions(+), 56 deletions(-)

diff --git a/src/haiku_support.cc b/src/haiku_support.cc
index f0db852e26..0642dbacff 100644
--- a/src/haiku_support.cc
+++ b/src/haiku_support.cc
@@ -89,6 +89,7 @@ enum
     CANCEL_DROP                = 3003,
     SHOW_MENU_BAR      = 3004,
     BE_MENU_BAR_OPEN   = 3005,
+    QUIT_APPLICATION   = 3006,
   };
 
 static color_space dpy_color_space = B_NO_COLOR_SPACE;
@@ -418,6 +419,15 @@ public:
     haiku_write (APP_QUIT_REQUESTED_EVENT, &rq);
     return 0;
   }
+
+  void
+  MessageReceived (BMessage *msg)
+  {
+    if (msg->what == QUIT_APPLICATION)
+      Quit ();
+    else
+      BApplication::MessageReceived (msg);
+  }
 };
 
 class EmacsWindow : public BWindow
@@ -2328,13 +2338,15 @@ public:
 static int32
 start_running_application (void *data)
 {
+  Emacs *app = (Emacs *) data;
+
   haiku_io_init_in_app_thread ();
 
-  if (!((Emacs *) data)->Lock ())
+  if (!app->Lock ())
     gui_abort ("Failed to lock application");
 
-  ((Emacs *) data)->Run ();
-  ((Emacs *) data)->Unlock ();
+  app->Run ();
+  app->Unlock ();
   return 0;
 }
 
@@ -2404,25 +2416,37 @@ BBitmap_dimensions (void *bitmap, int *left, int *top,
   *mono_p = (((BBitmap *) bitmap)->ColorSpace () == B_GRAY1);
 }
 
+static void
+wait_for_exit_of_app_thread (void)
+{
+  status_t ret;
+
+  be_app->PostMessage (QUIT_APPLICATION);
+  wait_for_thread (app_thread, &ret);
+}
+
 /* Set up an application and return it.  If starting the application
    thread fails, abort Emacs.  */
 void *
 BApplication_setup (void)
 {
-  if (be_app)
-    return be_app;
   thread_id id;
   Emacs *app;
 
+  if (be_app)
+    return be_app;
+
   app = new Emacs;
   app->Unlock ();
+
   if ((id = spawn_thread (start_running_application, "Emacs app thread",
                          B_DEFAULT_MEDIA_PRIORITY, app)) < 0)
     gui_abort ("spawn_thread failed");
 
   resume_thread (id);
-
   app_thread = id;
+
+  atexit (wait_for_exit_of_app_thread);
   return app;
 }
 
@@ -3772,16 +3796,6 @@ be_popup_file_dialog (int open_p, const char 
*default_dir, int must_match_p, int
     }
 }
 
-void
-be_app_quit (void)
-{
-  if (be_app)
-    {
-      while (!be_app->Lock ());
-      be_app->Quit ();
-    }
-}
-
 /* Zoom WINDOW.  */
 void
 BWindow_zoom (void *window)
diff --git a/src/haikuterm.c b/src/haikuterm.c
index bc21276437..6137e985b4 100644
--- a/src/haikuterm.c
+++ b/src/haikuterm.c
@@ -115,44 +115,7 @@ haiku_toolkit_position (struct frame *f, int x, int y,
 static void
 haiku_delete_terminal (struct terminal *terminal)
 {
-  struct haiku_display_info *dpyinfo = terminal->display_info.haiku;
-  struct terminal *t;
-
-  if (!terminal->name)
-    return;
-
-  block_input ();
-
-  be_app_quit ();
-  delete_port (port_application_to_emacs);
-
-  BCursor_delete (dpyinfo->text_cursor);
-  BCursor_delete (dpyinfo->nontext_cursor);
-  BCursor_delete (dpyinfo->modeline_cursor);
-  BCursor_delete (dpyinfo->hand_cursor);
-  BCursor_delete (dpyinfo->hourglass_cursor);
-  BCursor_delete (dpyinfo->horizontal_drag_cursor);
-  BCursor_delete (dpyinfo->vertical_drag_cursor);
-  BCursor_delete (dpyinfo->left_edge_cursor);
-  BCursor_delete (dpyinfo->top_left_corner_cursor);
-  BCursor_delete (dpyinfo->top_edge_cursor);
-  BCursor_delete (dpyinfo->top_right_corner_cursor);
-  BCursor_delete (dpyinfo->right_edge_cursor);
-  BCursor_delete (dpyinfo->bottom_right_corner_cursor);
-  BCursor_delete (dpyinfo->bottom_edge_cursor);
-  BCursor_delete (dpyinfo->bottom_left_corner_cursor);
-  BCursor_delete (dpyinfo->no_cursor);
-
-  /* Close all frames and delete the generic struct terminal.  */
-  for (t = terminal_list; t; t = t->next_terminal)
-    {
-      if (t->type == output_haiku && t->display_info.haiku == dpyinfo)
-       {
-         delete_terminal (t);
-         break;
-       }
-    }
-  unblock_input ();
+  error ("The Haiku terminal cannot be deleted");
 }
 
 static const char *
diff --git a/src/haikuterm.h b/src/haikuterm.h
index 5f905ab400..7022ea77de 100644
--- a/src/haikuterm.h
+++ b/src/haikuterm.h
@@ -260,8 +260,6 @@ extern void syms_of_haikufont (void);
 extern void syms_of_haikuselect (void);
 extern void init_haiku_select (void);
 
-extern void be_app_quit (void);
-
 extern void haiku_iconify_frame (struct frame *);
 extern void haiku_visualize_frame (struct frame *);
 extern void haiku_unvisualize_frame (struct frame *);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]