Jack2  1.9.9
JackPosixThread.h
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 #ifndef __JackPosixThread__
22 #define __JackPosixThread__
23 
24 #include "JackThread.h"
25 #include <pthread.h>
26 
27 namespace Jack
28 {
29 
30 /* use 512KB stack per thread - the default is way too high to be feasible
31  * with mlockall() on many systems */
32 #define THREAD_STACK 524288
33 
38 class SERVER_EXPORT JackPosixThread : public detail::JackThreadInterface
39 {
40 
41  protected:
42 
43  jack_native_thread_t fThread;
44  static void* ThreadHandler(void* arg);
45 
46  public:
47 
48  JackPosixThread(JackRunnableInterface* runnable, bool real_time, int priority, int cancellation)
49  : JackThreadInterface(runnable, priority, real_time, cancellation), fThread((jack_native_thread_t)NULL)
50  {}
51  JackPosixThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
52  : JackThreadInterface(runnable, 0, false, cancellation), fThread((jack_native_thread_t)NULL)
53  {}
54 
55  int Start();
56  int StartSync();
57  int Kill();
58  int Stop();
59  void Terminate();
60 
61  int AcquireRealTime(); // Used when called from another thread
62  int AcquireSelfRealTime(); // Used when called from thread itself
63 
64  int AcquireRealTime(int priority); // Used when called from another thread
65  int AcquireSelfRealTime(int priority); // Used when called from thread itself
66 
67  int DropRealTime(); // Used when called from another thread
68  int DropSelfRealTime(); // Used when called from thread itself
69 
70  jack_native_thread_t GetThreadID();
71  bool IsThread();
72 
73  static int AcquireRealTimeImp(jack_native_thread_t thread, int priority);
74  static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
75  {
76  return JackPosixThread::AcquireRealTimeImp(thread, priority);
77  }
78  static int DropRealTimeImp(jack_native_thread_t thread);
79  static int StartImp(jack_native_thread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
80  static int StopImp(jack_native_thread_t thread);
81  static int KillImp(jack_native_thread_t thread);
82 };
83 
84 SERVER_EXPORT void ThreadExit();
85 
86 } // end of namespace
87 
88 
89 #endif
The thread base class.
Definition: JackThread.h:60
The POSIX thread base class.
The base class for runnable objects, that have an Init and Execute method to be called in a threa...
Definition: JackThread.h:34