summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-11-07 20:00:39 +0100
committerAndy Wingo <wingo@pobox.com>2011-11-08 00:54:52 +0100
commitb262d3065c03cbde552cdfbce5819544f2e2dfea (patch)
tree907c673b2968837c688a2ab79c0ff11deda426af
parent285ac79b1ae6c502841bd2d175445ec5c599aa1e (diff)
downloadguile-b262d3065c03cbde552cdfbce5819544f2e2dfea.tar.gz
threadsafe port revealed counts
* libguile/ports.h: * libguile/ports.c (scm_revealed_count, scm_set_port_revealed_x): Make threadsafe. (scm_adjust_port_revealed_x): New function, to adjust a port's revealed count in a threadsafe way.
-rw-r--r--libguile/ports.c32
-rw-r--r--libguile/ports.h1
2 files changed, 31 insertions, 2 deletions
diff --git a/libguile/ports.c b/libguile/ports.c
index ea38133d0..c89ae1732 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1106,7 +1106,13 @@ SCM_DEFINE (scm_set_port_conversion_strategy_x, "set-port-conversion-strategy!",
int
scm_revealed_count (SCM port)
{
- return SCM_REVEALED (port);
+ int ret;
+
+ scm_c_lock_port (port);
+ ret = SCM_REVEALED (port);
+ scm_c_unlock_port (port);
+
+ return ret;
}
SCM_DEFINE (scm_port_revealed, "port-revealed", 1, 0, 0,
@@ -1127,9 +1133,31 @@ SCM_DEFINE (scm_set_port_revealed_x, "set-port-revealed!", 2, 0, 0,
"The return value is unspecified.")
#define FUNC_NAME s_scm_set_port_revealed_x
{
+ int r;
+ port = SCM_COERCE_OUTPORT (port);
+ SCM_VALIDATE_OPENPORT (1, port);
+ r = scm_to_int (rcount);
+ scm_c_lock_port (port);
+ SCM_REVEALED (port) = r;
+ scm_c_unlock_port (port);
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+/* Set the revealed count for a port. */
+SCM_DEFINE (scm_adjust_port_revealed_x, "adjust-port-revealed!", 2, 0, 0,
+ (SCM port, SCM addend),
+ "Add @var{addend} to the revealed count of @var{port}.\n"
+ "The return value is unspecified.")
+#define FUNC_NAME s_scm_set_port_revealed_x
+{
+ int a;
port = SCM_COERCE_OUTPORT (port);
SCM_VALIDATE_OPENPORT (1, port);
- SCM_REVEALED (port) = scm_to_int (rcount);
+ a = scm_to_int (addend);
+ scm_c_lock_port (port);
+ SCM_REVEALED (port) += a;
+ scm_c_unlock_port (port);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
diff --git a/libguile/ports.h b/libguile/ports.h
index 88a050abc..d9493e54c 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -302,6 +302,7 @@ SCM_INLINE int scm_c_unlock_port (SCM port);
SCM_API int scm_revealed_count (SCM port);
SCM_API SCM scm_port_revealed (SCM port);
SCM_API SCM scm_set_port_revealed_x (SCM port, SCM rcount);
+SCM_API SCM scm_adjust_port_revealed_x (SCM port, SCM addend);
/* Input. */
SCM_INLINE int scm_get_byte_or_eof (SCM port);