jack: remove unnecessary GPL include from LGPL code
[jack2.git] / common / JackThread.h
bloba61c5ab1becf2ddfb7beea9ffd42abb6c34c038e
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(); // Used when called from another thread
100 int AcquireSelfRealTime(); // Used when called from thread itself
102 int AcquireRealTime(int priority); // Used when called from another thread
103 int AcquireSelfRealTime(int priority); // Used when called from thread itself
105 int DropRealTime(); // Used when called from another thread
106 int DropSelfRealTime(); // Used when called from thread itself
108 jack_native_thread_t GetThreadID();
109 bool IsThread();
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);
121 } // end of namespace
123 bool jack_get_thread_realtime_priority_range(int * min_ptr, int * max_ptr);
125 bool jack_tls_allocate_key(jack_tls_key *key_ptr);
126 bool jack_tls_free_key(jack_tls_key key);
128 bool jack_tls_set(jack_tls_key key, void *data_ptr);
129 void *jack_tls_get(jack_tls_key key);
131 #endif