diff options
author | Andy Wingo <wingo@pobox.com> | 2016-04-28 08:34:08 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-04-28 08:34:08 +0200 |
commit | 2b47043052565eb780ef5600e4968fc333643b0c (patch) | |
tree | 435e3a0e2d8edde84822e30d4508a6934f930f05 | |
parent | 8b46a4af446d2015976b1d9c09888a75260ebc2b (diff) | |
download | guile-2b47043052565eb780ef5600e4968fc333643b0c.tar.gz |
Remove port locks
* libguile/ports.h (scm_t_port): Remove lock field.
(scm_dynwind_lock_port, scm_c_lock_port, scm_c_try_lock_port):
Remove.
* libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x):
Remove locking.
* libguile/ports.c (scm_c_make_port_with_encoding): Remove lock.
(scm_i_read_bytes, scm_i_read, scm_i_write_bytes, scm_i_write): Remove
"_unlocked" from names and adapt callers.
-rw-r--r-- | libguile/ports.c | 83 | ||||
-rw-r--r-- | libguile/ports.h | 38 |
2 files changed, 22 insertions, 99 deletions
diff --git a/libguile/ports.c b/libguile/ports.c index 394d632e7..75bd1dd81 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -327,9 +327,7 @@ SCM_DEFINE (scm_i_port_property, "%port-property", 2, 0, 0, SCM_VALIDATE_OPPORT (1, port); pt = SCM_PTAB_ENTRY (port); - scm_i_pthread_mutex_lock (pt->lock); result = scm_assq_ref (pt->internal->alist, key); - scm_i_pthread_mutex_unlock (pt->lock); return result; } @@ -345,9 +343,7 @@ SCM_DEFINE (scm_i_set_port_property_x, "%set-port-property!", 3, 0, 0, SCM_VALIDATE_OPPORT (1, port); pt = SCM_PTAB_ENTRY (port); - scm_i_pthread_mutex_lock (pt->lock); pt->internal->alist = scm_assq_set_x (pt->internal->alist, key, value); - scm_i_pthread_mutex_unlock (pt->lock); return SCM_UNSPECIFIED; } @@ -690,9 +686,6 @@ scm_c_make_port_with_encoding (scm_t_bits tag, unsigned long mode_bits, SCM_SET_CELL_WORD_1 (ret, (scm_t_bits) entry); SCM_SET_CELL_WORD_2 (ret, (scm_t_bits) ptob); - entry->lock = scm_gc_malloc_pointerless (sizeof (*entry->lock), "port lock"); - scm_i_pthread_mutex_init (entry->lock, scm_i_pthread_mutexattr_recursive); - entry->internal = pti; entry->file_name = SCM_BOOL_F; /* By default, any port type with a seek function has random-access @@ -1326,38 +1319,6 @@ SCM_DEFINE (scm_set_port_conversion_strategy_x, "set-port-conversion-strategy!", -/* The port lock. */ - -static void -lock_port (void *mutex) -{ - scm_i_pthread_mutex_lock ((scm_i_pthread_mutex_t *) mutex); -} - -static void -unlock_port (void *mutex) -{ - scm_i_pthread_mutex_unlock ((scm_i_pthread_mutex_t *) mutex); -} - -void -scm_dynwind_lock_port (SCM port) -#define FUNC_NAME "dynwind-lock-port" -{ - scm_i_pthread_mutex_t *lock; - SCM_VALIDATE_OPPORT (SCM_ARG1, port); - scm_c_lock_port (port, &lock); - if (lock) - { - scm_dynwind_unwind_handler (unlock_port, lock, SCM_F_WIND_EXPLICITLY); - scm_dynwind_rewind_handler (lock_port, lock, 0); - } -} -#undef FUNC_NAME - - - - /* Input. */ static int @@ -1448,7 +1409,7 @@ scm_peek_byte_or_eof (SCM port) } static size_t -scm_i_read_bytes_unlocked (SCM port, SCM dst, size_t start, size_t count) +scm_i_read_bytes (SCM port, SCM dst, size_t start, size_t count) { size_t filled; scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (port); @@ -1463,17 +1424,17 @@ scm_i_read_bytes_unlocked (SCM port, SCM dst, size_t start, size_t count) return filled; } -/* scm_i_read_unlocked is used internally to add bytes to the given port +/* scm_i_read is used internally to add bytes to the given port buffer. If the number of available bytes in the buffer does not - increase after a call to scm_i_read_unlocked, that indicates EOF. */ + increase after a call to scm_i_read, that indicates EOF. */ static void -scm_i_read_unlocked (SCM port, SCM buf) +scm_i_read (SCM port, SCM buf) { size_t count; - count = scm_i_read_bytes_unlocked (port, scm_port_buffer_bytevector (buf), - scm_to_size_t (scm_port_buffer_end (buf)), - scm_port_buffer_can_put (buf)); + count = scm_i_read_bytes (port, scm_port_buffer_bytevector (buf), + scm_to_size_t (scm_port_buffer_end (buf)), + scm_port_buffer_can_put (buf)); scm_port_buffer_did_put (buf, count); scm_port_buffer_set_has_eof_p (buf, scm_from_bool (count == 0)); } @@ -1529,9 +1490,9 @@ scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count) } else { - did_read = scm_i_read_bytes_unlocked (port, dst, - start + count - to_read, - to_read); + did_read = scm_i_read_bytes (port, dst, + start + count - to_read, + to_read); to_read -= did_read; dst_ptr += did_read; if (did_read == 0) @@ -2408,14 +2369,14 @@ SCM_DEFINE (scm_force_output, "force-output", 0, 1, 0, } #undef FUNC_NAME -static void scm_i_write_unlocked (SCM port, SCM buf); +static void scm_i_write (SCM port, SCM buf); void 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); + scm_i_write (port, buf); } SCM @@ -2438,7 +2399,7 @@ scm_fill_input (SCM port) else scm_port_buffer_reset (read_buf); - scm_i_read_unlocked (port, read_buf); + scm_i_read (port, read_buf); return read_buf; } @@ -2503,7 +2464,7 @@ scm_puts (const char *s, SCM port) } static void -scm_i_write_bytes_unlocked (SCM port, SCM src, size_t start, size_t count) +scm_i_write_bytes (SCM port, SCM src, size_t start, size_t count) { size_t written = 0; scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (port); @@ -2519,7 +2480,7 @@ scm_i_write_bytes_unlocked (SCM port, SCM src, size_t start, size_t count) } static void -scm_i_write_unlocked (SCM port, SCM buf) +scm_i_write (SCM port, SCM buf) { size_t start, count; @@ -2532,8 +2493,8 @@ scm_i_write_unlocked (SCM port, SCM buf) start = scm_to_size_t (scm_port_buffer_cur (buf)); count = scm_port_buffer_can_take (buf); scm_port_buffer_reset (buf); - scm_i_write_bytes_unlocked (port, scm_port_buffer_bytevector (buf), start, - count); + scm_i_write_bytes (port, scm_port_buffer_bytevector (buf), start, + count); } /* Used by an application to write arbitrary number of bytes to an SCM @@ -2569,7 +2530,7 @@ scm_c_write_bytes (SCM port, SCM src, size_t start, size_t count) full after filling it with the new data; if that's the case, we flush then instead. */ if (scm_port_buffer_can_put (write_buf) < count) - scm_i_write_unlocked (port, write_buf); + scm_i_write (port, write_buf); { signed char *src_ptr = SCM_BYTEVECTOR_CONTENTS (src) + start; @@ -2577,16 +2538,16 @@ scm_c_write_bytes (SCM port, SCM src, size_t start, size_t count) } if (scm_port_buffer_can_put (write_buf) == 0) - scm_i_write_unlocked (port, write_buf); + scm_i_write (port, write_buf); } else { /* Our write would overflow the buffer. Flush buffered bytes (if needed), then write our bytes with just one syscall. */ if (scm_port_buffer_can_take (write_buf)) - scm_i_write_unlocked (port, write_buf); + scm_i_write (port, write_buf); - scm_i_write_bytes_unlocked (port, src, start, count); + scm_i_write_bytes (port, src, start, count); } } #undef FUNC_NAME @@ -2617,7 +2578,7 @@ scm_c_write (SCM port, const void *ptr, size_t size) written += did_put; src += did_put; if (scm_port_buffer_can_put (write_buf) == 0) - scm_i_write_unlocked (port, write_buf); + scm_i_write (port, write_buf); } } #undef FUNC_NAME diff --git a/libguile/ports.h b/libguile/ports.h index d88fb21bd..230137f68 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -84,9 +84,6 @@ typedef struct /* Link back to the port object. */ SCM port; - /* A recursive lock for this port. */ - scm_i_pthread_mutex_t *lock; - /* Pointer to internal-only port structure. */ struct scm_port_internal *internal; @@ -289,11 +286,6 @@ SCM_API SCM scm_set_port_encoding_x (SCM port, SCM encoding); SCM_API SCM scm_port_conversion_strategy (SCM port); SCM_API SCM scm_set_port_conversion_strategy_x (SCM port, SCM behavior); -/* Acquiring and releasing the port lock. */ -SCM_API void scm_dynwind_lock_port (SCM port); -SCM_INLINE int scm_c_lock_port (SCM port, scm_i_pthread_mutex_t **lock); -SCM_INLINE int scm_c_try_lock_port (SCM port, scm_i_pthread_mutex_t **lock); - /* Input. */ SCM_API int scm_get_byte_or_eof (SCM port); SCM_API int scm_peek_byte_or_eof (SCM port); @@ -363,36 +355,6 @@ SCM_API SCM scm_sys_make_void_port (SCM mode); SCM_INTERNAL void scm_init_ports (void); -/* Inline function implementations. */ - -#if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES -SCM_INLINE_IMPLEMENTATION int -scm_c_lock_port (SCM port, scm_i_pthread_mutex_t **lock) -{ - *lock = SCM_PTAB_ENTRY (port)->lock; - - if (*lock) - return scm_i_pthread_mutex_lock (*lock); - else - return 0; -} - -SCM_INLINE_IMPLEMENTATION int -scm_c_try_lock_port (SCM port, scm_i_pthread_mutex_t **lock) -{ - *lock = SCM_PTAB_ENTRY (port)->lock; - if (*lock) - { - int ret = scm_i_pthread_mutex_trylock (*lock); - if (ret != 0) - *lock = NULL; - return ret; - } - else - return 0; -} -#endif /* SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES */ - #endif /* SCM_PORTS_H */ /* |