aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2023-01-10 16:15:58 +0100
committerAndrea Corallo2023-01-10 16:18:35 +0100
commit718c56194ddd9d25d0ddd6f22f6b91310b4876ec (patch)
treef3e80935c4e1f96b51fa0e696388ee5598019494
parent60240f54e5fed16a0522fb766ffef073db596f1f (diff)
downloademacs-718c56194ddd9d25d0ddd6f22f6b91310b4876ec.tar.gz
emacs-718c56194ddd9d25d0ddd6f22f6b91310b4876ec.zip
Block atimers while loading native codescratch/native-timers-blocked
-rw-r--r--src/atimer.c5
-rw-r--r--src/atimer.h3
-rw-r--r--src/comp.c25
3 files changed, 26 insertions, 7 deletions
diff --git a/src/atimer.c b/src/atimer.c
index d07cdb82b7a..cefe8bf87b3 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -24,7 +24,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
24 24
25#include "lisp.h" 25#include "lisp.h"
26#include "keyboard.h" 26#include "keyboard.h"
27#include "syssignal.h"
28#include "systime.h" 27#include "systime.h"
29#include "atimer.h" 28#include "atimer.h"
30#include <unistd.h> 29#include <unistd.h>
@@ -71,7 +70,7 @@ enum { timerfd = -1 };
71 70
72/* Block/unblock SIGALRM. */ 71/* Block/unblock SIGALRM. */
73 72
74static void 73void
75block_atimers (sigset_t *oldset) 74block_atimers (sigset_t *oldset)
76{ 75{
77 sigset_t blocked; 76 sigset_t blocked;
@@ -80,7 +79,7 @@ block_atimers (sigset_t *oldset)
80 sigaddset (&blocked, SIGINT); 79 sigaddset (&blocked, SIGINT);
81 pthread_sigmask (SIG_BLOCK, &blocked, oldset); 80 pthread_sigmask (SIG_BLOCK, &blocked, oldset);
82} 81}
83static void 82void
84unblock_atimers (sigset_t const *oldset) 83unblock_atimers (sigset_t const *oldset)
85{ 84{
86 pthread_sigmask (SIG_SETMASK, oldset, 0); 85 pthread_sigmask (SIG_SETMASK, oldset, 0);
diff --git a/src/atimer.h b/src/atimer.h
index 551c186d24e..54d163c93fa 100644
--- a/src/atimer.h
+++ b/src/atimer.h
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20#define EMACS_ATIMER_H 20#define EMACS_ATIMER_H
21 21
22#include <time.h> 22#include <time.h>
23#include "syssignal.h"
23 24
24/* Forward declaration. */ 25/* Forward declaration. */
25 26
@@ -69,6 +70,8 @@ struct atimer
69 70
70/* Function prototypes. */ 71/* Function prototypes. */
71 72
73void block_atimers (sigset_t *);
74void unblock_atimers (sigset_t const *);
72struct atimer *start_atimer (enum atimer_type, struct timespec, 75struct atimer *start_atimer (enum atimer_type, struct timespec,
73 atimer_callback, void *); 76 atimer_callback, void *);
74void cancel_atimer (struct atimer *); 77void cancel_atimer (struct atimer *);
diff --git a/src/comp.c b/src/comp.c
index bd7ecfffc23..3cc5506f989 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -40,6 +40,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
40#include "md5.h" 40#include "md5.h"
41#include "sysstdio.h" 41#include "sysstdio.h"
42#include "zlib.h" 42#include "zlib.h"
43#include "atimer.h"
43 44
44 45
45/********************************/ 46/********************************/
@@ -5296,10 +5297,29 @@ unset_cu_load_ongoing (Lisp_Object comp_u)
5296 XNATIVE_COMP_UNIT (comp_u)->load_ongoing = false; 5297 XNATIVE_COMP_UNIT (comp_u)->load_ongoing = false;
5297} 5298}
5298 5299
5300/* Number of native loads going on. */
5301unsigned loads;
5302
5303sigset_t oldset;
5304
5305static void
5306maybe_unblock_atimers (Lisp_Object obj)
5307{
5308 --loads;
5309 if (!loads)
5310 unblock_atimers (&oldset);
5311}
5312
5299Lisp_Object 5313Lisp_Object
5300load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump, 5314load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump,
5301 bool late_load) 5315 bool late_load)
5302{ 5316{
5317 specpdl_ref count = SPECPDL_INDEX ();
5318 if (!loads)
5319 block_atimers (&oldset);
5320 ++loads;
5321 record_unwind_protect (maybe_unblock_atimers, Qnil);
5322
5303 Lisp_Object res = Qnil; 5323 Lisp_Object res = Qnil;
5304 dynlib_handle_ptr handle = comp_u->handle; 5324 dynlib_handle_ptr handle = comp_u->handle;
5305 Lisp_Object comp_u_lisp_obj; 5325 Lisp_Object comp_u_lisp_obj;
@@ -5336,7 +5356,6 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump,
5336 identify is we have at least another load active on it. */ 5356 identify is we have at least another load active on it. */
5337 bool recursive_load = comp_u->load_ongoing; 5357 bool recursive_load = comp_u->load_ongoing;
5338 comp_u->load_ongoing = true; 5358 comp_u->load_ongoing = true;
5339 specpdl_ref count = SPECPDL_INDEX ();
5340 if (!recursive_load) 5359 if (!recursive_load)
5341 record_unwind_protect (unset_cu_load_ongoing, comp_u_lisp_obj); 5360 record_unwind_protect (unset_cu_load_ongoing, comp_u_lisp_obj);
5342 5361
@@ -5437,9 +5456,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump,
5437 eassert (check_comp_unit_relocs (comp_u)); 5456 eassert (check_comp_unit_relocs (comp_u));
5438 } 5457 }
5439 5458
5440 if (!recursive_load) 5459 unbind_to (count, Qnil);
5441 /* Clean-up the load ongoing flag in case. */
5442 unbind_to (count, Qnil);
5443 5460
5444 register_native_comp_unit (comp_u_lisp_obj); 5461 register_native_comp_unit (comp_u_lisp_obj);
5445 5462