In JackCoreAudioDriver, improve management of input/output channels: -1 is now used...
[jack2.git] / common / JackThread.h
blob56c624194e5a0d6aa3f791262b3e96045c8ecb9c
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
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.
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.
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.
21 #ifndef __JackThread__
22 #define __JackThread__
24 #include "JackCompilerDeps.h"
25 #include "JackTypes.h"
27 namespace Jack
30 /*!
31 \brief The base class for runnable objects, that have an <B> Init </B> and <B> Execute </B> method to be called in a thread.
34 class JackRunnableInterface
37 protected:
39 JackRunnableInterface()
41 virtual ~JackRunnableInterface()
44 public:
46 virtual bool Init() /*! Called once when the thread is started */
48 return true;
50 virtual bool Execute() = 0; /*! Must be implemented by subclasses */
53 namespace detail
56 /*!
57 \brief The thread base class.
60 class SERVER_EXPORT JackThreadInterface
63 public:
65 enum kThreadState {kIdle, kStarting, kIniting, kRunning};
67 protected:
69 JackRunnableInterface* fRunnable;
70 int fPriority;
71 bool fRealTime;
72 volatile kThreadState fStatus;
73 int fCancellation;
75 public:
77 JackThreadInterface(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
78 fRunnable(runnable), fPriority(priority), fRealTime(real_time), fStatus(kIdle), fCancellation(cancellation)
81 kThreadState GetStatus()
83 return fStatus;
85 void SetStatus(kThreadState status)
87 fStatus = status;
90 void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
93 int Start();
94 int StartSync();
95 int Kill();
96 int Stop();
97 void Terminate();
99 int AcquireRealTime();
100 int AcquireRealTime(int priority);
101 int DropRealTime();
103 pthread_t GetThreadID();
105 static int AcquireRealTimeImp(pthread_t thread, int priority);
106 static int AcquireRealTimeImp(pthread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint);
107 static int DropRealTimeImp(pthread_t thread);
108 static int StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
109 static int StopImp(pthread_t thread);
110 static int KillImp(pthread_t thread);
115 } // end of namespace
117 bool jack_get_thread_realtime_priority_range(int * min_ptr, int * max_ptr);
119 bool jack_tls_allocate_key(jack_tls_key *key_ptr);
120 bool jack_tls_free_key(jack_tls_key key);
122 bool jack_tls_set(jack_tls_key key, void *data_ptr);
123 void *jack_tls_get(jack_tls_key key);
125 #endif