select.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * include/bits/select.h -- fd_set operations
  3. *
  4. * Copyright (C) 2001 NEC Corporation
  5. * Copyright (C) 2001 Miles Bader <miles@gnu.org>
  6. * Copyright (C) 1997, 1998 Free Software Foundation, Inc.
  7. *
  8. * This file is subject to the terms and conditions of the GNU Lesser
  9. * General Public License. See the file COPYING.LIB in the main
  10. * directory of this archive for more details.
  11. */
  12. #ifndef _SYS_SELECT_H
  13. # error "Never use <bits/select.h> directly; include <sys/select.h> instead."
  14. #endif
  15. #ifdef __GNUC__
  16. /* We don't use `memset' because this would require a prototype and
  17. the array isn't too big. */
  18. #define __FD_ZERO(s) \
  19. do { \
  20. unsigned int __i; \
  21. fd_set *__arr = (s); \
  22. for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \
  23. __FDS_BITS (__arr)[__i] = 0; \
  24. } while (0)
  25. #define __FD_SET(fd, s) \
  26. do { \
  27. int __fd = (fd); \
  28. void *__addr = (void *)&__FDS_BITS (s); \
  29. __asm__ __volatile__ ("set1 %0, [%1]" \
  30. : /*nothing*/ \
  31. : "r" (__fd & 0x7), "r" (__addr + (__fd >> 3)));\
  32. } while (0)
  33. #define __FD_CLR(fd, s) \
  34. do { \
  35. int __fd = (fd); \
  36. void *__addr = (void *)&__FDS_BITS (s); \
  37. __asm__ __volatile__ ("clr1 %0, [%1]" \
  38. : /*nothing*/ \
  39. : "r" (__fd & 0x7), "r" (__addr + (__fd >> 3)));\
  40. } while (0)
  41. #define __FD_ISSET(fd, s) \
  42. ({ \
  43. int __fd = (fd); \
  44. void *__addr = (void *)&__FDS_BITS (s); \
  45. int res; \
  46. __asm__ ("tst1 %1, [%2]; setf nz, %0" \
  47. : "=r" (res) \
  48. : "r" (__fd & 0x7), "r" (__addr + (__fd >> 3))); \
  49. res; \
  50. })
  51. #else /* !__GNUC__ */
  52. #define __FD_SET(d, s) (__FDS_BITS (s)[__FDELT(d)] |= __FDMASK(d))
  53. #define __FD_CLR(d, s) (__FDS_BITS (s)[__FDELT(d)] &= ~__FDMASK(d))
  54. #define __FD_ISSET(d, s) ((__FDS_BITS (s)[__FDELT(d)] & __FDMASK(d)) != 0)
  55. #endif /* __GNUC__ */