oops, paul should remember to try an OSX build before releasing a tarball; fixed...
[jack.git] / jack / thread.h
blob26e506530e378638ec78802aaf7002075052cae7
1 /*
2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __jack_thread_h__
21 #define __jack_thread_h__
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 #include <pthread.h>
29 /* use 512KB stack per thread - the default is way too high to be feasible
30 * with mlockall() on many systems */
31 #define THREAD_STACK 524288
33 /** @file thread.h
35 * Library functions to standardize thread creation for JACK and its
36 * clients. These interfaces hide some system variations in the
37 * handling of realtime scheduling and associated privileges.
40 /**
41 * @returns if JACK is running with realtime scheduling, this returns
42 * the priority that any JACK-created client threads will run at.
43 * Otherwise returns -1.
46 int jack_client_real_time_priority (jack_client_t*);
48 /**
49 * @returns if JACK is running with realtime scheduling, this returns
50 * the maximum priority that a JACK client thread should use if the thread
51 * is subject to realtime scheduling. Otherwise returns -1.
54 int jack_client_max_real_time_priority (jack_client_t*);
56 /**
57 * Attempt to enable realtime scheduling for a thread. On some
58 * systems that may require special privileges.
60 * @param thread POSIX thread ID.
61 * @param priority requested thread priority.
63 * @returns 0, if successful; EPERM, if the calling process lacks
64 * required realtime privileges; otherwise some other error number.
66 int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
68 /**
69 * Create a thread for JACK or one of its clients. The thread is
70 * created executing @a start_routine with @a arg as its sole
71 * argument.
73 * @param client the JACK client for whom the thread is being created. May be
74 * NULL if the client is being created within the JACK server.
75 * @param thread place to return POSIX thread ID.
76 * @param priority thread priority, if realtime.
77 * @param realtime true for the thread to use realtime scheduling. On
78 * some systems that may require special privileges.
79 * @param start_routine function the thread calls when it starts.
80 * @param arg parameter passed to the @a start_routine.
82 * @returns 0, if successful; otherwise some error number.
84 int jack_client_create_thread (jack_client_t* client,
85 pthread_t *thread,
86 int priority,
87 int realtime, /* boolean */
88 void *(*start_routine)(void*),
89 void *arg);
91 /**
92 * Drop realtime scheduling for a thread.
94 * @param thread POSIX thread ID.
96 * @returns 0, if successful; otherwise an error number.
98 int jack_drop_real_time_scheduling (pthread_t thread);
100 #ifdef __cplusplus
102 #endif
104 #endif /* __jack_thread_h__ */