[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 03/15: scm_c_read instead of scm_c_read_unlock
From: |
Andy Wingo |
Subject: |
[Guile-commits] 03/15: scm_c_read instead of scm_c_read_unlock |
Date: |
Tue, 26 Apr 2016 21:38:52 +0000 |
wingo pushed a commit to branch wip-port-refactor
in repository guile.
commit 4934b69ddfb70d59b6ede6538b48da8ddea70a11
Author: Andy Wingo <address@hidden>
Date: Fri Apr 22 20:42:24 2016 +0200
scm_c_read instead of scm_c_read_unlock
* libguile/ports.h (scm_c_read_unlocked): Remove.
* libguile/ports.c (scm_c_read): Rename from scm_c_read_unlocked.
Remove old scm_c_read. Lock around access to the rw_active flag, and
call scm_flush instead of scm_flush_unlocked, and scm_fill_input
instead of scm_fill_input_unlocked.
* libguile/read.c (scm_i_scan_for_encoding): Use scm_c_read instead of
the _unlocked function.
---
libguile/ports.c | 27 +++++++++------------------
libguile/ports.h | 1 -
libguile/read.c | 2 +-
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/libguile/ports.c b/libguile/ports.c
index b754e1b..a59c8d8 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1555,7 +1555,7 @@ scm_c_read_bytes_unlocked (SCM port, SCM dst, size_t
start, size_t count)
read buffer. Used by an application when it wants to read into a
memory chunk that's not owned by Guile's GC. */
size_t
-scm_c_read_unlocked (SCM port, void *buffer, size_t size)
+scm_c_read (SCM port, void *buffer, size_t size)
#define FUNC_NAME "scm_c_read"
{
size_t copied = 0;
@@ -1570,15 +1570,20 @@ scm_c_read_unlocked (SCM port, void *buffer, size_t
size)
if (pt->rw_random)
{
- if (pt->rw_active == SCM_PORT_WRITE)
- scm_flush_unlocked (port);
+ int needs_flush;
+ scm_i_pthread_mutex_lock (pt->lock);
+ needs_flush = pt->rw_active == SCM_PORT_WRITE;
pt->rw_active = SCM_PORT_READ;
+ scm_i_pthread_mutex_unlock (pt->lock);
+
+ if (needs_flush)
+ scm_flush (port);
}
while (copied < size)
{
size_t count;
- read_buf = scm_fill_input_unlocked (port);
+ read_buf = scm_fill_input (port);
count = scm_port_buffer_take (read_buf, dst + copied, size - copied);
copied += count;
if (count == 0)
@@ -1607,20 +1612,6 @@ scm_c_read_bytes (SCM port, SCM dst, size_t start,
size_t count)
return ret;
}
-size_t
-scm_c_read (SCM port, void *buffer, size_t size)
-{
- scm_i_pthread_mutex_t *lock;
- size_t ret;
-
- scm_c_lock_port (port, &lock);
- ret = scm_c_read_unlocked (port, buffer, size);
- if (lock)
- scm_i_pthread_mutex_unlock (lock);
-
- return ret;
-}
-
/* Update the line and column number of PORT after consumption of C. */
static inline void
update_port_lf (scm_t_wchar c, SCM port)
diff --git a/libguile/ports.h b/libguile/ports.h
index 2cd6f8b..2b05a22 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -310,7 +310,6 @@ SCM_INLINE int scm_c_try_lock_port (SCM port,
scm_i_pthread_mutex_t **lock);
SCM_API int scm_get_byte_or_eof (SCM port);
SCM_API int scm_peek_byte_or_eof (SCM port);
SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size);
-SCM_API size_t scm_c_read_unlocked (SCM port, void *buffer, size_t size);
SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t
count);
SCM_API scm_t_wchar scm_getc (SCM port);
SCM_API scm_t_wchar scm_getc_unlocked (SCM port);
diff --git a/libguile/read.c b/libguile/read.c
index 144e39d..75f0423 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -2100,7 +2100,7 @@ scm_i_scan_for_encoding (SCM port)
if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port)))
return NULL;
- bytes_read = scm_c_read_unlocked (port, header,
SCM_ENCODING_SEARCH_SIZE);
+ bytes_read = scm_c_read (port, header, SCM_ENCODING_SEARCH_SIZE);
header[bytes_read] = '\0';
scm_seek (port, scm_from_int (0), scm_from_int (SEEK_SET));
}
- [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 <=
- [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, 2016/04/26
- [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