mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-02 23:50:47 +02:00
Manage pre-goops port type list using pairs
Avoids sloppy allocations. * libguile/ports-internal.h (scm_is_port_type): (scm_to_port_type, scm_from_port_type): New helpers. * libguile/goops.c (scm_make_port_classes): (create_port_classes): Use a list and be thread-safe.
This commit is contained in:
parent
9e9567b22a
commit
7d1eda149e
2 changed files with 38 additions and 21 deletions
|
@ -743,13 +743,6 @@ create_smob_classes (void)
|
|||
scm_smobs[i].apply != 0);
|
||||
}
|
||||
|
||||
struct pre_goops_port_type
|
||||
{
|
||||
scm_t_port_type *ptob;
|
||||
struct pre_goops_port_type *prev;
|
||||
};
|
||||
struct pre_goops_port_type *pre_goops_port_types;
|
||||
|
||||
static void
|
||||
make_port_classes (scm_t_port_type *ptob)
|
||||
{
|
||||
|
@ -775,6 +768,8 @@ make_port_classes (scm_t_port_type *ptob)
|
|||
scm_make_standard_class (meta, name, supers, SCM_EOL);
|
||||
}
|
||||
|
||||
static SCM pre_goops_port_types = SCM_EOL;
|
||||
|
||||
void
|
||||
scm_make_port_classes (scm_t_port_type *ptob)
|
||||
{
|
||||
|
@ -782,28 +777,30 @@ scm_make_port_classes (scm_t_port_type *ptob)
|
|||
ptob->output_class = SCM_BOOL_F;
|
||||
ptob->input_output_class = SCM_BOOL_F;
|
||||
|
||||
scm_i_pthread_mutex_lock (&scm_i_misc_mutex);
|
||||
if (!goops_loaded_p)
|
||||
{
|
||||
/* Not really a pair. */
|
||||
struct pre_goops_port_type *link;
|
||||
link = scm_gc_typed_calloc (struct pre_goops_port_type);
|
||||
link->ptob = ptob;
|
||||
link->prev = pre_goops_port_types;
|
||||
pre_goops_port_types = link;
|
||||
return;
|
||||
pre_goops_port_types = scm_cons (scm_from_port_type (ptob),
|
||||
pre_goops_port_types);
|
||||
scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
|
||||
make_port_classes (ptob);
|
||||
}
|
||||
|
||||
make_port_classes (ptob);
|
||||
}
|
||||
|
||||
static void
|
||||
create_port_classes (void)
|
||||
{
|
||||
while (pre_goops_port_types)
|
||||
{
|
||||
make_port_classes (pre_goops_port_types->ptob);
|
||||
pre_goops_port_types = pre_goops_port_types->prev;
|
||||
}
|
||||
scm_i_pthread_mutex_lock (&scm_i_misc_mutex);
|
||||
SCM ptobs = pre_goops_port_types;
|
||||
pre_goops_port_types = SCM_EOL;
|
||||
scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
|
||||
|
||||
for (; scm_is_pair (ptobs); ptobs = scm_cdr (ptobs))
|
||||
make_port_classes (scm_to_port_type (scm_car (ptobs)));
|
||||
}
|
||||
|
||||
SCM
|
||||
|
|
|
@ -72,6 +72,26 @@ struct scm_t_port_type
|
|||
SCM input_class, output_class, input_output_class;
|
||||
};
|
||||
|
||||
static inline int
|
||||
scm_is_port_type (SCM x)
|
||||
{
|
||||
return SCM_HAS_TYP7 (x, scm_tc7_port_type);
|
||||
}
|
||||
|
||||
static inline struct scm_t_port_type *
|
||||
scm_to_port_type (SCM x)
|
||||
{
|
||||
if (!scm_is_port_type (x))
|
||||
abort ();
|
||||
return (struct scm_t_port_type *) SCM_UNPACK_POINTER (x);
|
||||
}
|
||||
|
||||
static inline SCM
|
||||
scm_from_port_type (struct scm_t_port_type *x)
|
||||
{
|
||||
return SCM_PACK_POINTER (x);
|
||||
}
|
||||
|
||||
/* Port buffers.
|
||||
|
||||
It's important to avoid calling into the kernel too many times. For
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue