[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 05/15: Remove scm_flush_unlocked / scm_end_input_unlocke
From: |
Andy Wingo |
Subject: |
[Guile-commits] 05/15: Remove scm_flush_unlocked / scm_end_input_unlocked |
Date: |
Tue, 26 Apr 2016 21:38:53 +0000 |
wingo pushed a commit to branch wip-port-refactor
in repository guile.
commit 99899b7c9c360cc382ba3fbb05bae5265313b9ac
Author: Andy Wingo <address@hidden>
Date: Fri Apr 22 21:32:05 2016 +0200
Remove scm_flush_unlocked / scm_end_input_unlocked
* libguile/ports.h (scm_flush_unlocked, scm_end_input_unlocked):
Remove.
* libguile/ports.c (scm_c_read_bytes_unlocked):
(scm_i_unget_bytes_unlocked, scm_setvbuf, scm_force_output)
(scm_fill_input_unlocked, scm_c_write_bytes_unlocked)
(scm_c_write_unlocked, scm_lfwrite_unlocked, scm_seek)
(scm_truncate_file, flush_output_port): Call scm_flush / scm_end_input
instead of the _unlocked variants.
(scm_end_input): Lock while discarding the input buffer but not while
calling out to the seek function.
* libguile/filesys.c (scm_fsync):
* libguile/ioext.c (scm_redirect_port):
* libguile/read.c (scm_i_scan_for_encoding):
* libguile/rw.c (scm_write_string_partial): Use scm_flush, not
scm_flush_unlocked.
---
libguile/filesys.c | 2 +-
libguile/ioext.c | 12 +++++------
libguile/ports.c | 57 ++++++++++++++++++----------------------------------
libguile/ports.h | 2 --
libguile/read.c | 2 +-
libguile/rw.c | 2 +-
6 files changed, 28 insertions(+), 49 deletions(-)
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 5e0a232..167d444 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -980,7 +980,7 @@ SCM_DEFINE (scm_fsync, "fsync", 1, 0, 0,
if (SCM_OPFPORTP (object))
{
- scm_flush_unlocked (object);
+ scm_flush (object);
fdes = SCM_FPORT_FDES (object);
}
else
diff --git a/libguile/ioext.c b/libguile/ioext.c
index 3f0a53f..f39771e 100644
--- a/libguile/ioext.c
+++ b/libguile/ioext.c
@@ -89,14 +89,14 @@ SCM_DEFINE (scm_redirect_port, "redirect-port", 2, 0, 0,
/* Ensure there is nothing in either port's input or output
buffers. */
if (SCM_OUTPUT_PORT_P (old))
- scm_flush_unlocked (old);
- if (SCM_INPUT_PORT_P (old))
- scm_end_input_unlocked (old);
+ scm_flush (old);
+ if (SCM_INPUT_PORT_P (old) && SCM_PTAB_ENTRY (old)->rw_random)
+ scm_end_input (old);
if (SCM_OUTPUT_PORT_P (new))
- scm_flush_unlocked (new);
- if (SCM_INPUT_PORT_P (new))
- scm_end_input_unlocked (new);
+ scm_flush (new);
+ if (SCM_INPUT_PORT_P (new) && SCM_PTAB_ENTRY (new)->rw_random)
+ scm_end_input (new);
ans = dup2 (oldfd, newfd);
if (ans == -1)
diff --git a/libguile/ports.c b/libguile/ports.c
index 8181056..b466ed8 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1501,7 +1501,7 @@ scm_c_read_bytes_unlocked (SCM port, SCM dst, size_t
start, size_t count)
read_buf = pt->read_buf;
if (pt->rw_random)
- scm_flush_unlocked (port);
+ scm_flush (port);
/* Take bytes first from the port's read buffer. */
{
@@ -2019,7 +2019,7 @@ scm_i_unget_bytes_unlocked (const scm_t_uint8 *buf,
size_t len, SCM port)
SCM read_buf = pt->read_buf;
if (pt->rw_random)
- scm_flush_unlocked (port);
+ scm_flush (port);
if (scm_port_buffer_can_putback (read_buf) < len)
{
@@ -2368,7 +2368,7 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
write_buf_size = 1;
if (SCM_OUTPUT_PORT_P (port))
- scm_flush_unlocked (port);
+ scm_flush (port);
saved_read_buf = pt->read_buf;
@@ -2456,32 +2456,23 @@ SCM_DEFINE (scm_drain_input, "drain-input", 1, 0, 0,
#undef FUNC_NAME
void
-scm_end_input_unlocked (SCM port)
+scm_end_input (SCM port)
{
scm_t_port *pt;
SCM buf;
size_t discarded;
pt = SCM_PTAB_ENTRY (port);
+
+ scm_i_pthread_mutex_lock (pt->lock);
buf = SCM_PTAB_ENTRY (port)->read_buf;
discarded = scm_port_buffer_take (buf, NULL, (size_t) -1);
-
- assert (pt->rw_random);
+ scm_i_pthread_mutex_unlock (pt->lock);
if (discarded != 0)
SCM_PORT_DESCRIPTOR (port)->seek (port, -discarded, SEEK_CUR);
}
-void
-scm_end_input (SCM port)
-{
- scm_i_pthread_mutex_t *lock;
- scm_c_lock_port (port, &lock);
- scm_end_input_unlocked (port);
- if (lock)
- scm_i_pthread_mutex_unlock (lock);
-}
-
SCM_DEFINE (scm_force_output, "force-output", 0, 1, 0,
(SCM port),
"Flush the specified output port, or the current output port if
@var{port}\n"
@@ -2499,7 +2490,7 @@ SCM_DEFINE (scm_force_output, "force-output", 0, 1, 0,
port = SCM_COERCE_OUTPORT (port);
SCM_VALIDATE_OPOUTPORT (1, port);
}
- scm_flush_unlocked (port);
+ scm_flush (port);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
@@ -2507,23 +2498,13 @@ SCM_DEFINE (scm_force_output, "force-output", 0, 1, 0,
static void scm_i_write_unlocked (SCM port, SCM buf);
void
-scm_flush_unlocked (SCM port)
+scm_flush (SCM port)
{
SCM buf = SCM_PTAB_ENTRY (port)->write_buf;
if (scm_port_buffer_can_take (buf))
scm_i_write_unlocked (port, buf);
}
-void
-scm_flush (SCM port)
-{
- scm_i_pthread_mutex_t *lock;
- scm_c_lock_port (port, &lock);
- scm_flush_unlocked (port);
- if (lock)
- scm_i_pthread_mutex_unlock (lock);
-}
-
SCM
scm_fill_input_unlocked (SCM port)
{
@@ -2535,7 +2516,7 @@ scm_fill_input_unlocked (SCM port)
return read_buf;
if (pt->rw_random)
- scm_flush_unlocked (pt->port);
+ scm_flush (pt->port);
/* It could be that putback caused us to enlarge the buffer; now that
we've read all the bytes we need to shrink it again. */
@@ -2666,7 +2647,7 @@ scm_c_write_bytes_unlocked (SCM port, SCM src, size_t
start, size_t count)
write_buf = pt->write_buf;
if (pt->rw_random)
- scm_end_input_unlocked (port);
+ scm_end_input (port);
if (count < scm_port_buffer_size (write_buf))
{
@@ -2723,7 +2704,7 @@ scm_c_write_unlocked (SCM port, const void *ptr, size_t
size)
write_buf = pt->write_buf;
if (pt->rw_random)
- scm_end_input_unlocked (port);
+ scm_end_input (port);
while (written < size)
{
@@ -2773,7 +2754,7 @@ scm_lfwrite_unlocked (const char *ptr, size_t size, SCM
port)
/* Handle line buffering. */
if ((SCM_CELL_WORD_0 (port) & SCM_BUFLINE) && saved_line != SCM_LINUM (port))
- scm_flush_unlocked (port);
+ scm_flush (port);
}
void
@@ -2897,8 +2878,8 @@ SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
/* FIXME: Avoid flushing buffers for SEEK_CUR with an offset of
0. */
- scm_end_input_unlocked (pt->port);
- scm_flush_unlocked (pt->port);
+ scm_end_input (pt->port);
+ scm_flush (pt->port);
rv = ptob->seek (fd_port, off, how);
@@ -3001,9 +2982,9 @@ SCM_DEFINE (scm_truncate_file, "truncate-file", 1, 1, 0,
scm_i_clear_pending_eof (object);
- if (SCM_INPUT_PORT_P (object))
- scm_end_input_unlocked (object);
- scm_flush_unlocked (object);
+ if (SCM_INPUT_PORT_P (object) && SCM_PTAB_ENTRY (object)->rw_random)
+ scm_end_input (object);
+ scm_flush (object);
ptob->truncate (object, c_length);
rv = 0;
@@ -3208,7 +3189,7 @@ static void
flush_output_port (void *closure, SCM port)
{
if (SCM_OPOUTPORTP (port))
- scm_flush_unlocked (port);
+ scm_flush (port);
}
SCM_DEFINE (scm_flush_all_ports, "flush-all-ports", 0, 0, 0,
diff --git a/libguile/ports.h b/libguile/ports.h
index 816005d..4b5242e 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -323,10 +323,8 @@ SCM_API SCM scm_fill_input_unlocked (SCM port);
SCM_INTERNAL size_t scm_take_from_input_buffers (SCM port, char *dest, size_t
read_len);
SCM_API SCM scm_drain_input (SCM port);
SCM_API void scm_end_input (SCM port);
-SCM_API void scm_end_input_unlocked (SCM port);
SCM_API SCM scm_force_output (SCM port);
SCM_API void scm_flush (SCM port);
-SCM_API void scm_flush_unlocked (SCM port);
SCM_INTERNAL SCM scm_port_read_buffer (SCM port);
SCM_INTERNAL SCM scm_port_write_buffer (SCM port);
diff --git a/libguile/read.c b/libguile/read.c
index c7ba4e7..9e072ad 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -2068,7 +2068,7 @@ scm_i_scan_for_encoding (SCM port)
buf = pt->read_buf;
if (pt->rw_random)
- scm_flush_unlocked (port);
+ scm_flush (port);
if (scm_port_buffer_can_take (buf) == 0)
{
diff --git a/libguile/rw.c b/libguile/rw.c
index bf4a1f5..b2f8f3a 100644
--- a/libguile/rw.c
+++ b/libguile/rw.c
@@ -246,7 +246,7 @@ SCM_DEFINE (scm_write_string_partial,
"write-string/partial", 1, 3, 0,
return scm_from_long (write_len);
}
- scm_flush_unlocked (port);
+ scm_flush (port);
fdes = SCM_FPORT_FDES (port);
}
{
- [Guile-commits] branch wip-port-refactor updated (5a342f6 -> 15d5304), Andy Wingo, 2016/04/26
- [Guile-commits] 01/15: Refactor thread safety for %port-property, Andy Wingo, 2016/04/26
- [Guile-commits] 03/15: scm_c_read instead of scm_c_read_unlock, Andy Wingo, 2016/04/26
- [Guile-commits] 02/15: Refactor to internal get/peek-byte functions, Andy Wingo, 2016/04/26
- [Guile-commits] 04/15: Remove port rw_active field, Andy Wingo, 2016/04/26
- [Guile-commits] 08/15: Remove scm_unget_{byte,bytes}_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 06/15: Remove scm_c_read_bytes_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 10/15: Remove locking in scm_end_input, Andy Wingo, 2016/04/26
- [Guile-commits] 05/15: Remove scm_flush_unlocked / scm_end_input_unlocked,
Andy Wingo <=
- [Guile-commits] 11/15: Remove scm_fill_input_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 09/15: scm_ungetc, scm_ungets instead of _unlocked variants, Andy Wingo, 2016/04/26
- [Guile-commits] 07/15: Replace scm_getc with scm_getc_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 14/15: Remove scm_c_write_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 15/15: scm_lfwrite, not scm_lfwrite_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 12/15: Remove scm_putc_unlocked., Andy Wingo, 2016/04/26
- [Guile-commits] 13/15: Remove scm_puts_unlocked., Andy Wingo, 2016/04/26