1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

* filesys.c (set_element): Return file descriptor.

(fill_select_type): Return the highest file descriptor.
(scm_select): Tell select about the highest file descriptor.  On
some systems the SELECT_SET_SIZE can be as much as 128 bytes.
Therefore the extra overhead for calculating the maximum fd seems
to be more than compensated.  Is this correct?  In any case,
scm_internal_select will be much faster with this info.
(scm_select, fill_select_type, set_element): Don't accept any kind
of object in the file descriptor list or vector.
This commit is contained in:
Mikael Djurfeldt 1997-12-08 18:15:44 +00:00
parent 341eaef04b
commit cafc12ffdd
3 changed files with 59 additions and 20 deletions

View file

@ -1,3 +1,25 @@
1997-12-08 Mikael Djurfeldt <mdj@mdj.nada.kth.se>
* filesys.c (set_element): Return file descriptor.
(fill_select_type): Return the highest file descriptor.
(scm_select): Tell select about the highest file descriptor. On
some systems the SELECT_SET_SIZE can be as much as 128 bytes.
Therefore the extra overhead for calculating the maximum fd seems
to be more than compensated. Is this correct? In any case,
scm_internal_select will be much faster with this info.
(scm_select, fill_select_type, set_element): Don't accept any kind
of object in the file descriptor list or vector.
1997-12-07 Mikael Djurfeldt <mdj@mdj.nada.kth.se>
* iselect.c (finalize_fd_sets): Bugfix.
1997-12-06 Mikael Djurfeldt <mdj@mdj.nada.kth.se>
* filesys.c (scm_select): Don't use SCM_DEFER_INTS/SCM_ALLOW_INTS
when using scm_internal_select (since we might switch to another
thread).
Sun Dec 7 01:43:56 1997 Gary Houston <ghouston@actrix.gen.nz>
* simpos.c (scm_system): always define: use sysmissing if not

View file

@ -820,21 +820,29 @@ scm_getcwd ()
SCM_PROC (s_select, "select", 3, 2, 0, scm_select);
static void
set_element (SELECT_TYPE *set, SCM element)
static int
set_element (SELECT_TYPE *set, SCM element, int arg)
{
int fd;
element = SCM_COERCE_OUTPORT (element);
if (SCM_NIMP (element) && SCM_TYP16 (element) == scm_tc16_fport
&& SCM_OPPORTP (element))
FD_SET (fileno ((FILE *) SCM_STREAM (element)), set);
else if (SCM_INUMP (element))
FD_SET (SCM_INUM (element), set);
fd = fileno ((FILE *) SCM_STREAM (element));
else {
SCM_ASSERT (SCM_INUMP (element), element, arg, s_select);
fd = SCM_INUM (element);
}
FD_SET (fd, set);
return fd;
}
static void
fill_select_type (SELECT_TYPE *set, SCM list)
static int
fill_select_type (SELECT_TYPE *set, SCM list, int arg)
{
int max_fd = 0, fd;
if (SCM_NIMP (list) && SCM_VECTORP (list))
{
int len = SCM_LENGTH (list);
@ -842,7 +850,9 @@ fill_select_type (SELECT_TYPE *set, SCM list)
while (len > 0)
{
set_element (set, ve[len - 1]);
fd = set_element (set, ve[len - 1], arg);
if (fd > max_fd)
max_fd = fd;
len--;
}
}
@ -850,10 +860,14 @@ fill_select_type (SELECT_TYPE *set, SCM list)
{
while (list != SCM_EOL)
{
set_element (set, SCM_CAR (list));
fd = set_element (set, SCM_CAR (list), arg);
if (fd > max_fd)
max_fd = fd;
list = SCM_CDR (list);
}
}
return max_fd;
}
static SCM
@ -905,8 +919,6 @@ retrieve_select_type (SELECT_TYPE *set, SCM list)
}
SCM_PROC (s_select, "select", 3, 2, 0, scm_select);
SCM
scm_select (reads, writes, excepts, secs, usecs)
SCM reads;
@ -921,6 +933,7 @@ scm_select (reads, writes, excepts, secs, usecs)
SELECT_TYPE read_set;
SELECT_TYPE write_set;
SELECT_TYPE except_set;
int max_fd, fd;
int sreturn;
#define assert_set(x, arg) \
@ -935,9 +948,13 @@ scm_select (reads, writes, excepts, secs, usecs)
FD_ZERO (&write_set);
FD_ZERO (&except_set);
fill_select_type (&read_set, reads);
fill_select_type (&write_set, writes);
fill_select_type (&except_set, excepts);
max_fd = fill_select_type (&read_set, reads, SCM_ARG1);
fd = fill_select_type (&write_set, writes, SCM_ARG2);
if (fd > max_fd)
max_fd = fd;
fd = fill_select_type (&except_set, excepts, SCM_ARG3);
if (fd > max_fd)
max_fd = fd;
if (SCM_UNBNDP (secs) || SCM_FALSEP (secs))
time_p = 0;
@ -969,17 +986,17 @@ scm_select (reads, writes, excepts, secs, usecs)
time_p = &timeout;
}
SCM_DEFER_INTS;
#ifdef GUILE_ISELECT
sreturn = scm_internal_select (SELECT_SET_SIZE,
sreturn = scm_internal_select (max_fd + 1,
&read_set, &write_set, &except_set, time_p);
#else
sreturn = select (SELECT_SET_SIZE,
SCM_DEFER_INTS;
sreturn = select (max_fd + 1,
&read_set, &write_set, &except_set, time_p);
SCM_ALLOW_INTS;
#endif
if (sreturn < 0)
scm_syserror (s_select);
SCM_ALLOW_INTS;
return scm_listify (retrieve_select_type (&read_set, reads),
retrieve_select_type (&write_set, writes),
retrieve_select_type (&except_set, excepts),

View file

@ -311,14 +311,14 @@ finalize_fd_sets (coop_t *t)
{
((ulongptr) t->writefds)[i] &= ((ulongptr) &rwritefds)[i];
((ulongptr) &gwritefds)[i] &= ~s;
n_ones += SCM_NLONGBITS (&((ulongptr) t->readfds)[i]);
n_ones += SCM_NLONGBITS (&((ulongptr) t->writefds)[i]);
}
cont_write:
if (t->exceptfds != NULL && (s = ((ulongptr) t->exceptfds)[i]) != 0)
{
((ulongptr) t->exceptfds)[i] &= ((ulongptr) &rexceptfds)[i];
((ulongptr) &gexceptfds)[i] &= ~s;
n_ones += SCM_NLONGBITS (&((ulongptr) t->readfds)[i]);
n_ones += SCM_NLONGBITS (&((ulongptr) t->exceptfds)[i]);
}
cont_except:
}