Jack2: JackThread.h Source File

Jack2 1.9.12

JackThread.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 __JackThread__
22 #define __JackThread__
23
24 #include "JackCompilerDeps.h"
25 #include "JackTypes.h"
26
27 namespace Jack
28 {
29
34 class JackRunnableInterface
35 {
36
37 protected:
38
39 JackRunnableInterface()
40 {}
41 virtual ~JackRunnableInterface()
42 {}
43
44 public:
45
46 virtual bool Init()
47 {
48 return true;
49 }
50 virtual bool Execute() = 0;
51 };
52
53 namespace detail
54 {
55
60 class SERVER_EXPORT JackThreadInterface
61 {
62
63 public:
64
65 enum kThreadState {kIdle, kStarting, kIniting, kRunning};
66
67 protected:
68
69 JackRunnableInterface* fRunnable;
70 int fPriority;
71 bool fRealTime;
72 volatile kThreadState fStatus;
73 int fCancellation;
74
75 public:
76
77 JackThreadInterface(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
78 fRunnable(runnable), fPriority(priority), fRealTime(real_time), fStatus(kIdle), fCancellation(cancellation)
79 {}
80
81 kThreadState GetStatus()
82 {
83 return fStatus;
84 }
85 void SetStatus(kThreadState status)
86 {
87 fStatus = status;
88 }
89
90 void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
91 {}
92
93 int Start();
94 int StartSync();
95 int Kill();
96 int Stop();
97 void Terminate();
98
99 int AcquireRealTime(); // Used when called from another thread
100 int AcquireSelfRealTime(); // Used when called from thread itself
101
102 int AcquireRealTime(int priority); // Used when called from another thread
103 int AcquireSelfRealTime(int priority); // Used when called from thread itself
104
105 int DropRealTime(); // Used when called from another thread
106 int DropSelfRealTime(); // Used when called from thread itself
107
108 jack_native_thread_t GetThreadID();
109 bool IsThread();
110
111 static int AcquireRealTimeImp(jack_native_thread_t thread, int priority);
112 static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint);
113 static int DropRealTimeImp(jack_native_thread_t thread);
114 static int StartImp(jack_native_thread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
115 static int StopImp(jack_native_thread_t thread);
116 static int KillImp(jack_native_thread_t thread);
117 };
118
119 }
120
121 } // end of namespace
122
123 bool jack_get_thread_realtime_priority_range(int * min_ptr, int * max_ptr);
124
125 bool jack_tls_allocate_key(jack_tls_key *key_ptr);
126 bool jack_tls_free_key(jack_tls_key key);
127
128 bool jack_tls_set(jack_tls_key key, void *data_ptr);
129 void *jack_tls_get(jack_tls_key key);
130
131 #endif
Jack::detail::JackThreadInterface
The thread base class.
Definition: JackThread.h:60
Jack::JackRunnableInterface::Init
virtual bool Init()
Definition: JackThread.h:46
Jack
Definition: JackAC3Encoder.cpp:30
Jack::JackRunnableInterface
The base class for runnable objects, that have an Init and Execute method to be called in a threa...
Definition: JackThread.h:34