diff options
author | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1997-12-08 18:15:44 +0000 |
---|---|---|
committer | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 1997-12-08 18:15:44 +0000 |
commit | cafc12ffdd7b55c825781b0e471acd0fd28adf3f (patch) | |
tree | 28df68bd892c8e4eb74705ab722b8b34c6b7c611 | |
parent | 341eaef04b87c0c1d60dd26a22dff7ad4f67784b (diff) | |
download | guile-cafc12ffdd7b55c825781b0e471acd0fd28adf3f.tar.gz |
* 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.
-rw-r--r-- | libguile/ChangeLog | 22 | ||||
-rw-r--r-- | libguile/filesys.c | 53 | ||||
-rw-r--r-- | libguile/iselect.c | 4 |
3 files changed, 59 insertions, 20 deletions
diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 4c8aa3395..3d088ae19 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -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 diff --git a/libguile/filesys.c b/libguile/filesys.c index 60b64e8cb..9121b12bb 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -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), diff --git a/libguile/iselect.c b/libguile/iselect.c index 921fca3e5..b2977ad7c 100644 --- a/libguile/iselect.c +++ b/libguile/iselect.c @@ -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: } |