[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/native-timers-blocked 718c56194d: Block atimers while loading na
From: |
Andrea Corallo |
Subject: |
scratch/native-timers-blocked 718c56194d: Block atimers while loading native code |
Date: |
Tue, 10 Jan 2023 10:20:22 -0500 (EST) |
branch: scratch/native-timers-blocked
commit 718c56194ddd9d25d0ddd6f22f6b91310b4876ec
Author: Andrea Corallo <andrea.corallo@arm.com>
Commit: Andrea Corallo <andrea.corallo@arm.com>
Block atimers while loading native code
---
src/atimer.c | 5 ++---
src/atimer.h | 3 +++
src/comp.c | 25 +++++++++++++++++++++----
3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/src/atimer.c b/src/atimer.c
index d07cdb82b7..cefe8bf87b 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/>. */
#include "lisp.h"
#include "keyboard.h"
-#include "syssignal.h"
#include "systime.h"
#include "atimer.h"
#include <unistd.h>
@@ -71,7 +70,7 @@ enum { timerfd = -1 };
/* Block/unblock SIGALRM. */
-static void
+void
block_atimers (sigset_t *oldset)
{
sigset_t blocked;
@@ -80,7 +79,7 @@ block_atimers (sigset_t *oldset)
sigaddset (&blocked, SIGINT);
pthread_sigmask (SIG_BLOCK, &blocked, oldset);
}
-static void
+void
unblock_atimers (sigset_t const *oldset)
{
pthread_sigmask (SIG_SETMASK, oldset, 0);
diff --git a/src/atimer.h b/src/atimer.h
index 551c186d24..54d163c93f 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/>. */
#define EMACS_ATIMER_H
#include <time.h>
+#include "syssignal.h"
/* Forward declaration. */
@@ -69,6 +70,8 @@ struct atimer
/* Function prototypes. */
+void block_atimers (sigset_t *);
+void unblock_atimers (sigset_t const *);
struct atimer *start_atimer (enum atimer_type, struct timespec,
atimer_callback, void *);
void cancel_atimer (struct atimer *);
diff --git a/src/comp.c b/src/comp.c
index bd7ecfffc2..3cc5506f98 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/>. */
#include "md5.h"
#include "sysstdio.h"
#include "zlib.h"
+#include "atimer.h"
/********************************/
@@ -5296,10 +5297,29 @@ unset_cu_load_ongoing (Lisp_Object comp_u)
XNATIVE_COMP_UNIT (comp_u)->load_ongoing = false;
}
+/* Number of native loads going on. */
+unsigned loads;
+
+sigset_t oldset;
+
+static void
+maybe_unblock_atimers (Lisp_Object obj)
+{
+ --loads;
+ if (!loads)
+ unblock_atimers (&oldset);
+}
+
Lisp_Object
load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u, bool loading_dump,
bool late_load)
{
+ specpdl_ref count = SPECPDL_INDEX ();
+ if (!loads)
+ block_atimers (&oldset);
+ ++loads;
+ record_unwind_protect (maybe_unblock_atimers, Qnil);
+
Lisp_Object res = Qnil;
dynlib_handle_ptr handle = comp_u->handle;
Lisp_Object comp_u_lisp_obj;
@@ -5336,7 +5356,6 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
identify is we have at least another load active on it. */
bool recursive_load = comp_u->load_ongoing;
comp_u->load_ongoing = true;
- specpdl_ref count = SPECPDL_INDEX ();
if (!recursive_load)
record_unwind_protect (unset_cu_load_ongoing, comp_u_lisp_obj);
@@ -5437,9 +5456,7 @@ load_comp_unit (struct Lisp_Native_Comp_Unit *comp_u,
bool loading_dump,
eassert (check_comp_unit_relocs (comp_u));
}
- if (!recursive_load)
- /* Clean-up the load ongoing flag in case. */
- unbind_to (count, Qnil);
+ unbind_to (count, Qnil);
register_native_comp_unit (comp_u_lisp_obj);