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)); }