JACK API headers
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.

138 lines
4.5KB

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