thread.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. {$I systemdeps.inc}
  23. //#include <jack/weakmacros.h>
  24. {$I weakmacros.inc}
  25. (* use 512KB stack per thread - the default is way too high to be feasible
  26. * with mlockall() on many systems *)
  27. const
  28. THREAD_STACK = 524288;
  29. (** @file thread.h
  30. *
  31. * Library functions to standardize thread creation for JACK and its
  32. * clients. These interfaces hide some system variations in the
  33. * handling of realtime scheduling and associated privileges.
  34. *)
  35. (**
  36. * @defgroup ClientThreads Creating and managing client threads
  37. * @{
  38. *)
  39. (**
  40. * @returns if JACK is running with realtime scheduling, this returns
  41. * the priority that any JACK-created client threads will run at.
  42. * Otherwise returns -1.
  43. *)
  44. function jack_client_real_time_priority (client: Pjack_client_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  45. (**
  46. * @returns if JACK is running with realtime scheduling, this returns
  47. * the maximum priority that a JACK client thread should use if the thread
  48. * is subject to realtime scheduling. Otherwise returns -1.
  49. *)
  50. function jack_client_max_real_time_priority (client: Pjack_client_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  51. (**
  52. * Attempt to enable realtime scheduling for a thread. On some
  53. * systems that may require special privileges.
  54. *
  55. * @param thread POSIX thread ID.
  56. * @param priority requested thread priority.
  57. *
  58. * @returns 0, if successful; EPERM, if the calling process lacks
  59. * required realtime privileges; otherwise some other error number.
  60. *)
  61. function jack_acquire_real_time_scheduling (thread: jack_native_thread_t; priority: cint): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  62. (**
  63. * Create a thread for JACK or one of its clients. The thread is
  64. * created executing @a start_routine with @a arg as its sole
  65. * argument.
  66. *
  67. * @param client the JACK client for whom the thread is being created. May be
  68. * NULL if the client is being created within the JACK server.
  69. * @param thread place to return POSIX thread ID.
  70. * @param priority thread priority, if realtime.
  71. * @param realtime true for the thread to use realtime scheduling. On
  72. * some systems that may require special privileges.
  73. * @param start_routine function the thread calls when it starts.
  74. * @param arg parameter passed to the @a start_routine.
  75. *
  76. * @returns 0, if successful; otherwise some error number.
  77. *)
  78. type
  79. TJackThreadStartRoutine = function(arg: Pointer): Pointer; cdecl;
  80. function jack_client_create_thread (client: Pjack_client_t;
  81. thread: Pjack_native_thread_t;
  82. priority: cint;
  83. realtime: cint; { boolean }
  84. start_routine: TJackThreadStartRoutine;
  85. arg: Pointer): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  86. (**
  87. * Drop realtime scheduling for a thread.
  88. *
  89. * @param thread POSIX thread ID.
  90. *
  91. * @returns 0, if successful; otherwise an error number.
  92. *)
  93. function jack_drop_real_time_scheduling (thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  94. (**
  95. * Stop the thread, waiting for the thread handler to terminate.
  96. *
  97. * @param thread POSIX thread ID.
  98. *
  99. * @returns 0, if successful; otherwise an error number.
  100. *)
  101. function jack_client_stop_thread(client: Pjack_client_t; thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  102. (**
  103. * Kill the thread.
  104. *
  105. * @param thread POSIX thread ID.
  106. *
  107. * @returns 0, if successful; otherwise an error number.
  108. *)
  109. function jack_client_kill_thread(client: Pjack_client_t; thread: jack_native_thread_t): cint; cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  110. {$ifndef MSWINDOWS}
  111. type
  112. jack_thread_creator_t = function(thread: {pthread_t*}Pointer;
  113. const attr: {pthread_attr_t*}Pointer;
  114. start_routine: TJackThreadStartRoutine;
  115. arg: Pointer): cint; cdecl;
  116. (**
  117. * This function can be used in very very specialized cases
  118. * where it is necessary that client threads created by JACK
  119. * are created by something other than pthread_create(). After
  120. * it is used, any threads that JACK needs for the client will
  121. * will be created by calling the function passed to this
  122. * function.
  123. *
  124. * No normal application/client should consider calling this.
  125. * The specific case for which it was created involves running
  126. * win32/x86 plugins under Wine on Linux, where it is necessary
  127. * that all threads that might call win32 functions are known
  128. * to Wine.
  129. *
  130. * Set it to NULL to restore thread creation function.
  131. *
  132. * @param creator a function that creates a new thread
  133. *
  134. *)
  135. procedure jack_set_thread_creator (creator: jack_thread_creator_t); cdecl; JACK_OPTIONAL_WEAK_EXPORT;
  136. {$endif}
  137. ///**@}*/
  138. //#ifdef __cplusplus
  139. //}
  140. //#endif
  141. {$endif __jack_thread_h__}