diff options
author | Andy Wingo <wingo@pobox.com> | 2016-04-22 20:42:24 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-04-22 20:42:24 +0200 |
commit | 4934b69ddfb70d59b6ede6538b48da8ddea70a11 (patch) | |
tree | dc22e3b03e4a22c762348a14e771bc8d8725efcb /libguile | |
parent | fb577b59af2619edd78fea71ce6250a36376abdd (diff) | |
download | guile-4934b69ddfb70d59b6ede6538b48da8ddea70a11.tar.gz |
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.
Diffstat (limited to 'libguile')
-rw-r--r-- | libguile/ports.c | 27 | ||||
-rw-r--r-- | libguile/ports.h | 1 | ||||
-rw-r--r-- | libguile/read.c | 2 |
3 files changed, 10 insertions, 20 deletions
diff --git a/libguile/ports.c b/libguile/ports.c index b754e1bae..a59c8d831 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 2cd6f8be7..2b05a229f 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 144e39dc5..75f042377 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)); } |