select.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _SYS_SELECT_H
  16. # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
  17. #endif
  18. #undef __FD_ZERO
  19. #undef __FD_SET
  20. #undef __FD_CLR
  21. #undef __FD_ISSET
  22. #if defined __GNUC__ && __GNUC__ >= 2
  23. # define __FD_ZERO(fdsp) \
  24. do { \
  25. int __d0, __d1; \
  26. __asm__ __volatile__ ("cld; rep; stosl" \
  27. : "=c" (__d0), "=D" (__d1) \
  28. : "a" (0), "0" (sizeof (fd_set) \
  29. / sizeof (__fd_mask)), \
  30. "1" (&__FDS_BITS (fdsp)[0]) \
  31. : "memory"); \
  32. } while (0)
  33. # define __FD_SET(fd, fdsp) \
  34. __asm__ __volatile__ ("btsl %1,%0" \
  35. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  36. : "r" (((int) (fd)) % __NFDBITS) \
  37. : "cc","memory")
  38. # define __FD_CLR(fd, fdsp) \
  39. __asm__ __volatile__ ("btrl %1,%0" \
  40. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  41. : "r" (((int) (fd)) % __NFDBITS) \
  42. : "cc","memory")
  43. # define __FD_ISSET(fd, fdsp) \
  44. (__extension__ \
  45. ({register char __result; \
  46. __asm__ __volatile__ ("btl %1,%2 ; setcb %b0" \
  47. : "=q" (__result) \
  48. : "r" (((int) (fd)) % __NFDBITS), \
  49. "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  50. : "cc"); \
  51. __result; }))
  52. #else /* ! GNU CC */
  53. /* We don't use `memset' because this would require a prototype and
  54. the array isn't too big. */
  55. # define __FD_ZERO(set) \
  56. do { \
  57. unsigned int __i; \
  58. fd_set *__arr = (set); \
  59. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  60. __FDS_BITS (__arr)[__i] = 0; \
  61. } while (0)
  62. # define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
  63. # define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
  64. # define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
  65. #endif /* GNU CC */