sleep_ms.cpp 643 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/thread.h>
  5. #include<__vic/posix/time.h>
  6. #include<__vic/throw_errno.h>
  7. #include<cerrno>
  8. namespace __vic {
  9. //----------------------------------------------------------------------------
  10. void this_thread::sleep_ms(unsigned msec)
  11. {
  12. posix::time_spec req(msec, posix::time_spec::msec), res;
  13. errno = 0;
  14. while(nanosleep(&req, &res))
  15. {
  16. int err = errno;
  17. if(err != EINTR
  18. #ifdef _AIX
  19. && err
  20. #endif
  21. ) throw_errno("nanosleep", err);
  22. errno = 0;
  23. req = res;
  24. }
  25. }
  26. //----------------------------------------------------------------------------
  27. } // namespace