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.

156 lines
4.7KB

  1. /*
  2. Copyright (C) 2004 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __jack_thread_h__
  16. #define __jack_thread_h__
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. #include <jack/systemdeps.h>
  22. /** @file thread.h
  23. *
  24. * Library functions to standardize thread creation for JACK and its
  25. * clients. These interfaces hide some system variations in the
  26. * handling of realtime scheduling and associated privileges.
  27. */
  28. /**
  29. * @defgroup ClientThreads Creating and managing client threads
  30. * @{
  31. */
  32. /**
  33. * @returns if JACK is running with realtime scheduling, this returns
  34. * the priority that any JACK-created client threads will run at.
  35. * Otherwise returns -1.
  36. */
  37. int jack_client_real_time_priority (jack_client_t*);
  38. /**
  39. * @returns if JACK is running with realtime scheduling, this returns
  40. * the maximum priority that a JACK client thread should use if the thread
  41. * is subject to realtime scheduling. Otherwise returns -1.
  42. */
  43. int jack_client_max_real_time_priority (jack_client_t*);
  44. /**
  45. * Attempt to enable realtime scheduling for a thread. On some
  46. * systems that may require special privileges.
  47. *
  48. * @param thread POSIX thread ID.
  49. * @param priority requested thread priority.
  50. *
  51. * @returns 0, if successful; EPERM, if the calling process lacks
  52. * required realtime privileges; otherwise some other error number.
  53. */
  54. int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  55. /**
  56. * Create a thread for JACK or one of its clients. The thread is
  57. * created executing @a start_routine with @a arg as its sole
  58. * argument.
  59. *
  60. * @param client the JACK client for whom the thread is being created. May be
  61. * NULL if the client is being created within the JACK server.
  62. * @param thread place to return POSIX thread ID.
  63. * @param priority thread priority, if realtime.
  64. * @param realtime true for the thread to use realtime scheduling. On
  65. * some systems that may require special privileges.
  66. * @param start_routine function the thread calls when it starts.
  67. * @param arg parameter passed to the @a start_routine.
  68. *
  69. * @returns 0, if successful; otherwise some error number.
  70. */
  71. int jack_client_create_thread (jack_client_t* client,
  72. pthread_t *thread,
  73. int priority,
  74. int realtime, /* boolean */
  75. void *(*start_routine)(void*),
  76. void *arg);
  77. /**
  78. * Drop realtime scheduling for a thread.
  79. *
  80. * @param thread POSIX thread ID.
  81. *
  82. * @returns 0, if successful; otherwise an error number.
  83. */
  84. int jack_drop_real_time_scheduling (pthread_t thread);
  85. /**
  86. * Stop the thread, waiting for the thread handler to terminate.
  87. *
  88. * @param thread POSIX thread ID.
  89. *
  90. * @returns 0, if successful; otherwise an error number.
  91. */
  92. int jack_client_stop_thread(jack_client_t* client, pthread_t thread);
  93. /**
  94. * Cancel the thread then waits for the thread handler to terminate.
  95. *
  96. * @param thread POSIX thread ID.
  97. *
  98. * @returns 0, if successful; otherwise an error number.
  99. */
  100. int jack_client_kill_thread(jack_client_t* client, pthread_t thread);
  101. #ifndef WIN32
  102. typedef int (*jack_thread_creator_t)(pthread_t*,
  103. const pthread_attr_t*,
  104. void* (*function)(void*),
  105. void* arg);
  106. /**
  107. * This function can be used in very very specialized cases
  108. * where it is necessary that client threads created by JACK
  109. * are created by something other than pthread_create(). After
  110. * it is used, any threads that JACK needs for the client will
  111. * will be created by calling the function passed to this
  112. * function.
  113. *
  114. * No normal application/client should consider calling this.
  115. * The specific case for which it was created involves running
  116. * win32/x86 plugins under Wine on Linux, where it is necessary
  117. * that all threads that might call win32 functions are known
  118. * to Wine.
  119. *
  120. * Set it to NULL to restore thread creation function.
  121. *
  122. * @param creator a function that creates a new thread
  123. *
  124. */
  125. void jack_set_thread_creator (jack_thread_creator_t creator);
  126. #endif
  127. /* @} */
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /* __jack_thread_h__ */