select.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _SYS_SELECT_H
  15. # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
  16. #endif
  17. #if defined __GNUC__ && __GNUC__ >= 2
  18. # define __FD_ZERO(fdsp) \
  19. do { \
  20. int __d0, __d1; \
  21. __asm__ __volatile__ ("cld; rep; stosl" \
  22. : "=c" (__d0), "=D" (__d1) \
  23. : "a" (0), "0" (sizeof (fd_set) \
  24. / sizeof (__fd_mask)), \
  25. "1" (&__FDS_BITS (fdsp)[0]) \
  26. : "memory"); \
  27. } while (0)
  28. # define __FD_SET(fd, fdsp) \
  29. __asm__ __volatile__ ("btsl %1,%0" \
  30. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  31. : "r" (((int) (fd)) % __NFDBITS) \
  32. : "cc","memory")
  33. # define __FD_CLR(fd, fdsp) \
  34. __asm__ __volatile__ ("btrl %1,%0" \
  35. : "=m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  36. : "r" (((int) (fd)) % __NFDBITS) \
  37. : "cc","memory")
  38. # define __FD_ISSET(fd, fdsp) \
  39. (__extension__ \
  40. ({register char __result; \
  41. __asm__ __volatile__ ("btl %1,%2 ; setcb %b0" \
  42. : "=q" (__result) \
  43. : "r" (((int) (fd)) % __NFDBITS), \
  44. "m" (__FDS_BITS (fdsp)[__FDELT (fd)]) \
  45. : "cc"); \
  46. __result; }))
  47. #else /* ! GNU CC */
  48. /* We don't use `memset' because this would require a prototype and
  49. the array isn't too big. */
  50. # define __FD_ZERO(set) \
  51. do { \
  52. unsigned int __i; \
  53. fd_set *__arr = (set); \
  54. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  55. __FDS_BITS (__arr)[__i] = 0; \
  56. } while (0)
  57. # define __FD_SET(d, set) (__FDS_BITS (set)[__FDELT (d)] |= __FDMASK (d))
  58. # define __FD_CLR(d, set) (__FDS_BITS (set)[__FDELT (d)] &= ~__FDMASK (d))
  59. # define __FD_ISSET(d, set) (__FDS_BITS (set)[__FDELT (d)] & __FDMASK (d))
  60. #endif /* GNU CC */