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.

76 lines
2.3KB

  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. #include "JackProcessSync.h"
  16. #include "JackError.h"
  17. namespace Jack
  18. {
  19. bool JackProcessSync::TimedWait(long usec)
  20. {
  21. struct timeval T0, T1;
  22. timespec time;
  23. struct timeval now;
  24. int res;
  25. pthread_mutex_lock(&fLock);
  26. jack_log("JackProcessSync::TimedWait time out = %ld", usec);
  27. gettimeofday(&T0, 0);
  28. gettimeofday(&now, 0);
  29. unsigned int next_date_usec = now.tv_usec + usec;
  30. time.tv_sec = now.tv_sec + (next_date_usec / 1000000);
  31. time.tv_nsec = (next_date_usec % 1000000) * 1000;
  32. res = pthread_cond_timedwait(&fCond, &fLock, &time);
  33. if (res != 0)
  34. jack_error("pthread_cond_timedwait error usec = %ld err = %s", usec, strerror(res));
  35. gettimeofday(&T1, 0);
  36. pthread_mutex_unlock(&fLock);
  37. jack_log("JackProcessSync::TimedWait finished delta = %5.1lf",
  38. (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));
  39. return (res == 0);
  40. }
  41. void JackProcessSync::Wait()
  42. {
  43. int res;
  44. pthread_mutex_lock(&fLock);
  45. //jack_log("JackProcessSync::Wait...");
  46. if ((res = pthread_cond_wait(&fCond, &fLock)) != 0)
  47. jack_error("pthread_cond_wait error err = %s", strerror(errno));
  48. pthread_mutex_unlock(&fLock);
  49. //jack_log("JackProcessSync::Wait finished");
  50. }
  51. bool JackInterProcessSync::TimedWait(long usec)
  52. {
  53. struct timeval T0, T1;
  54. //jack_log("JackInterProcessSync::TimedWait...");
  55. gettimeofday(&T0, 0);
  56. bool res = fSynchro->TimedWait(usec);
  57. gettimeofday(&T1, 0);
  58. //jack_log("JackInterProcessSync::TimedWait finished delta = %5.1lf", (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));
  59. return res;
  60. }
  61. } // end of namespace