Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

d_sleep.hpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DISTRHO_SLEEP_HPP_INCLUDED
  17. #define DISTRHO_SLEEP_HPP_INCLUDED
  18. #include "../DistrhoUtils.hpp"
  19. #ifdef DISTRHO_OS_WINDOWS
  20. # include <winsock2.h>
  21. # include <windows.h>
  22. #else
  23. # include <unistd.h>
  24. #endif
  25. // -----------------------------------------------------------------------
  26. // d_*sleep
  27. static inline
  28. void d_sleep(const uint secs) noexcept
  29. {
  30. DISTRHO_SAFE_ASSERT_RETURN(secs > 0,);
  31. try {
  32. #ifdef DISTRHO_OS_WINDOWS
  33. ::Sleep(secs * 1000);
  34. #else
  35. ::sleep(secs);
  36. #endif
  37. } DISTRHO_SAFE_EXCEPTION("d_sleep");
  38. }
  39. static inline
  40. void d_msleep(const uint msecs) noexcept
  41. {
  42. DISTRHO_SAFE_ASSERT_RETURN(msecs > 0,);
  43. try {
  44. #ifdef DISTRHO_OS_WINDOWS
  45. ::Sleep(msecs);
  46. #else
  47. ::usleep(msecs * 1000);
  48. #endif
  49. } DISTRHO_SAFE_EXCEPTION("d_msleep");
  50. }
  51. // -----------------------------------------------------------------------
  52. #endif // DISTRHO_SLEEP_HPP_INCLUDED