/* Call scm_fill_input until we have all the bytes that we need,
or we hit EOF. */
- while (pt->read_buf_size && (scm_fill_input (port) != EOF))
+ while (pt->read_buf_size && (scm_fill_input_unlocked (port) != EOF))
{
pt->read_buf_size -= (pt->read_end - pt->read_pos);
pt->read_pos = pt->read_buf = pt->read_end;
that a custom port implementation's entry points (in
particular, fill_input) can rely on the buffer always being
the same as they first set up. */
- while (size && (scm_fill_input (port) != EOF))
+ while (size && (scm_fill_input_unlocked (port) != EOF))
{
n_available = min (size, pt->read_end - pt->read_pos);
memcpy (buffer, pt->read_pos, n_available);
/* Manipulating the buffers. */
+/* This routine does not take any locks, as it is usually called as part
+ of a port implementation. */
void
scm_port_non_buffer (scm_t_port *pt)
{
tries to refill the read buffer. it returns the first char from
the port, which is either EOF or *(pt->read_pos). */
int
-scm_fill_input (SCM port)
+scm_fill_input_unlocked (SCM port)
{
scm_t_port *pt = SCM_PTAB_ENTRY (port);
return SCM_PORT_DESCRIPTOR (port)->fill_input (port);
}
+int
+scm_fill_input (SCM port)
+{
+ int ret;
+
+ scm_c_lock_port (port);
+ ret = scm_fill_input_unlocked (port);
+ scm_c_unlock_port (port);
+
+ return ret;
+}
+
/* move up to read_len chars from port's putback and/or read buffers
into memory starting at dest. returns the number of chars moved. */
size_t
#undef FUNC_NAME
void
-scm_end_input (SCM port)
+scm_end_input_unlocked (SCM port)
{
long offset;
scm_t_port *pt = SCM_PTAB_ENTRY (port);
SCM_PORT_DESCRIPTOR (port)->end_input (port, offset);
}
+void
+scm_end_input (SCM port)
+{
+ scm_c_lock_port (port);
+ scm_end_input_unlocked (port);
+ scm_c_unlock_port (port);
+}
+
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"
port = SCM_COERCE_OUTPORT (port);
SCM_VALIDATE_OPOUTPORT (1, port);
}
- scm_flush (port);
+ scm_flush_unlocked (port);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
void
-scm_flush (SCM port)
+scm_flush_unlocked (SCM port)
{
SCM_PORT_DESCRIPTOR (port)->flush (port);
}
+void
+scm_flush (SCM port)
+{
+ scm_c_lock_port (port);
+ scm_flush_unlocked (port);
+ scm_c_unlock_port (port);
+}
+
\f
ptob = SCM_PORT_DESCRIPTOR (port);
if (pt->rw_active == SCM_PORT_READ)
- scm_end_input (port);
+ scm_end_input_unlocked (port);
ptob->write (port, ptr, size);
scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (port);
if (pt->rw_active == SCM_PORT_READ)
- scm_end_input (port);
+ scm_end_input_unlocked (port);
ptob->write (port, ptr, size);
scm_t_port *pt = SCM_PTAB_ENTRY (port);
if (pt->rw_active == SCM_PORT_READ)
- scm_end_input (port);
+ scm_end_input_unlocked (port);
if (end == (size_t) -1)
end = scm_i_string_length (str);
if (!ptob->truncate)
SCM_MISC_ERROR ("port is not truncatable", SCM_EOL);
if (pt->rw_active == SCM_PORT_READ)
- scm_end_input (object);
+ scm_end_input_unlocked (object);
else if (pt->rw_active == SCM_PORT_WRITE)
ptob->flush (object);
flush_output_port (void *closure, SCM port)
{
if (SCM_OPOUTPORTP (port))
- scm_flush (port);
+ scm_flush_unlocked (port);
}
SCM_DEFINE (scm_flush_all_ports, "flush-all-ports", 0, 0, 0,
/* Manipulating the buffers. */
SCM_API void scm_port_non_buffer (scm_t_port *pt);
SCM_API int scm_fill_input (SCM port);
+SCM_API int 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);
/* Output. */
SCM_INLINE void scm_putc (char c, SCM port);
if (pt->read_pos >= pt->read_end)
{
- if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
+ if (SCM_UNLIKELY (scm_fill_input_unlocked (port) == EOF))
return EOF;
}
if (pt->read_pos >= pt->read_end)
{
- if (SCM_UNLIKELY (scm_fill_input (port) == EOF))
+ if (SCM_UNLIKELY (scm_fill_input_unlocked (port) == EOF))
return EOF;
}