[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 16/18: Load (ice-9 binary-ports) from C in thread-safe w
From: |
Andy Wingo |
Subject: |
[Guile-commits] 16/18: Load (ice-9 binary-ports) from C in thread-safe way |
Date: |
Thu, 8 Jun 2023 04:26:43 -0400 (EDT) |
wingo pushed a commit to branch main
in repository guile.
commit 00e48eb16dfda825789a66f18e86a27652f61037
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Fri Jun 2 22:28:13 2023 +0200
Load (ice-9 binary-ports) from C in thread-safe way
* libguile/r6rs-ports.c: Do the usual dance to load
make-custom-binary-input-port et al just once.
---
libguile/r6rs-ports.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c
index 2e4fc9452..7c51bf617 100644
--- a/libguile/r6rs-ports.c
+++ b/libguile/r6rs-ports.c
@@ -40,7 +40,9 @@
#include "strings.h"
#include "symbols.h"
#include "syscalls.h"
+#include "threads.h"
#include "values.h"
+#include "variable.h"
#include "vectors.h"
#include "version.h"
@@ -771,11 +773,32 @@ initialize_bytevector_output_ports (void)
/* Custom ports. */
+static SCM make_custom_binary_input_port_var;
+static SCM make_custom_binary_output_port_var;
+static SCM make_custom_binary_input_output_port_var;
+
+static scm_i_pthread_once_t make_custom_binary_port_vars =
+ SCM_I_PTHREAD_ONCE_INIT;
+
+static void
+init_make_custom_binary_port_vars (void)
+{
+ SCM mod = scm_c_resolve_module ("ice-9 binary-ports");
+ SCM iface = scm_module_public_interface (mod);
+ make_custom_binary_input_port_var =
+ scm_c_module_lookup (iface, "make-custom-binary-input-port");
+ make_custom_binary_output_port_var =
+ scm_c_module_lookup (iface, "make-custom-binary-output-port");
+ make_custom_binary_input_output_port_var =
+ scm_c_module_lookup (iface, "make-custom-binary-input/output-port");
+}
+
SCM scm_make_custom_binary_input_port (SCM id, SCM read_proc,
SCM get_position_proc,
SCM set_position_proc, SCM close_proc) {
- return scm_call_5 (scm_c_public_ref ("ice-9 binary-ports",
- "make-custom-binary-input-port"),
+ scm_i_pthread_once (&make_custom_binary_port_vars,
+ init_make_custom_binary_port_vars);
+ return scm_call_5 (scm_variable_ref (make_custom_binary_input_port_var),
id, read_proc, get_position_proc, set_position_proc,
close_proc);
}
@@ -783,8 +806,9 @@ SCM scm_make_custom_binary_input_port (SCM id, SCM
read_proc,
SCM scm_make_custom_binary_output_port (SCM id, SCM write_proc,
SCM get_position_proc,
SCM set_position_proc, SCM close_proc) {
- return scm_call_5 (scm_c_public_ref ("ice-9 binary-ports",
- "make-custom-binary-output-port"),
+ scm_i_pthread_once (&make_custom_binary_port_vars,
+ init_make_custom_binary_port_vars);
+ return scm_call_5 (scm_variable_ref (make_custom_binary_output_port_var),
id, write_proc, get_position_proc, set_position_proc,
close_proc);
}
@@ -794,8 +818,9 @@ SCM scm_make_custom_binary_input_output_port (SCM id, SCM
read_proc,
SCM get_position_proc,
SCM set_position_proc,
SCM close_proc) {
- return scm_call_6 (scm_c_public_ref ("ice-9 binary-ports",
- "make-custom-binary-input/output-port"),
+ scm_i_pthread_once (&make_custom_binary_port_vars,
+ init_make_custom_binary_port_vars);
+ return scm_call_6 (scm_variable_ref
(make_custom_binary_input_output_port_var),
id, read_proc, write_proc, get_position_proc,
set_position_proc, close_proc);
}
- [Guile-commits] branch main updated (cd57379b3 -> 02dfb6e77), Andy Wingo, 2023/06/08
- [Guile-commits] 03/18: pretty-print: inline some handling of read macros, Andy Wingo, 2023/06/08
- [Guile-commits] 05/18: Add "custom ports", Andy Wingo, 2023/06/08
- [Guile-commits] 06/18: Rewrite custom binary ports in Scheme, in terms of custom ports, Andy Wingo, 2023/06/08
- [Guile-commits] 08/18: Rewrite soft ports in Scheme, Andy Wingo, 2023/06/08
- [Guile-commits] 04/18: bytevector-slice: optimize trivial case, Andy Wingo, 2023/06/08
- [Guile-commits] 16/18: Load (ice-9 binary-ports) from C in thread-safe way,
Andy Wingo <=
- [Guile-commits] 07/18: Use custom binary output ports for make-chunked-output-port, Andy Wingo, 2023/06/08
- [Guile-commits] 13/18: Inline generic-write into pretty-print, Andy Wingo, 2023/06/08
- [Guile-commits] 10/18: Modernize soft ports, Andy Wingo, 2023/06/08
- [Guile-commits] 01/18: pretty-print: Use string-concatenate-reverse, Andy Wingo, 2023/06/08
- [Guile-commits] 17/18: Deprecate (ice-9 lineio), Andy Wingo, 2023/06/08
- [Guile-commits] 18/18: Fix exn dispatch for exns within pre-unwind handlers, Andy Wingo, 2023/06/08
- [Guile-commits] 09/18: Implement R6RS custom textual ports, Andy Wingo, 2023/06/08
- [Guile-commits] 11/18: Rewrite pretty-print to rely on port-column, abort early, Andy Wingo, 2023/06/08
- [Guile-commits] 14/18: truncated-print: use call-with-truncating-output-string, Andy Wingo, 2023/06/08
- [Guile-commits] 12/18: pretty-print: width arg is never false, Andy Wingo, 2023/06/08