jack2 codebase
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.

80 lines
2.4KB

  1. /*
  2. Copyright (C) 2004-2006 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program 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
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #if defined(HAVE_CONFIG_H)
  16. #include "config.h"
  17. #endif
  18. #include "JackProcessSync.h"
  19. #include "JackError.h"
  20. namespace Jack
  21. {
  22. bool JackProcessSync::TimedWait(long usec)
  23. {
  24. struct timeval T0, T1;
  25. timespec time;
  26. struct timeval now;
  27. int res;
  28. pthread_mutex_lock(&fLock);
  29. jack_log("JackProcessSync::TimedWait time out = %ld", usec);
  30. gettimeofday(&T0, 0);
  31. gettimeofday(&now, 0);
  32. unsigned int next_date_usec = now.tv_usec + usec;
  33. time.tv_sec = now.tv_sec + (next_date_usec / 1000000);
  34. time.tv_nsec = (next_date_usec % 1000000) * 1000;
  35. res = pthread_cond_timedwait(&fCond, &fLock, &time);
  36. if (res != 0)
  37. jack_error("pthread_cond_timedwait error usec = %ld err = %s", usec, strerror(res));
  38. gettimeofday(&T1, 0);
  39. pthread_mutex_unlock(&fLock);
  40. jack_log("JackProcessSync::TimedWait finished delta = %5.1lf",
  41. (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));
  42. return (res == 0);
  43. }
  44. void JackProcessSync::Wait()
  45. {
  46. int res;
  47. pthread_mutex_lock(&fLock);
  48. //jack_log("JackProcessSync::Wait...");
  49. if ((res = pthread_cond_wait(&fCond, &fLock)) != 0)
  50. jack_error("pthread_cond_wait error err = %s", strerror(errno));
  51. pthread_mutex_unlock(&fLock);
  52. //jack_log("JackProcessSync::Wait finished");
  53. }
  54. bool JackInterProcessSync::TimedWait(long usec)
  55. {
  56. struct timeval T0, T1;
  57. //jack_log("JackInterProcessSync::TimedWait...");
  58. gettimeofday(&T0, 0);
  59. bool res = fSynchro->TimedWait(usec);
  60. gettimeofday(&T1, 0);
  61. //jack_log("JackInterProcessSync::TimedWait finished delta = %5.1lf", (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));
  62. return res;
  63. }
  64. } // end of namespace