Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2001 Paul Davis 00003 Copyright (C) 2004-2008 Grame 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU Lesser General Public License as published by 00007 the Free Software Foundation; either version 2.1 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 */ 00020 00021 #ifndef __JackThread__ 00022 #define __JackThread__ 00023 00024 #include "JackCompilerDeps.h" 00025 #include "JackTypes.h" 00026 00027 namespace Jack 00028 { 00029 00034 class JackRunnableInterface 00035 { 00036 00037 protected: 00038 00039 JackRunnableInterface() 00040 {} 00041 virtual ~JackRunnableInterface() 00042 {} 00043 00044 public: 00045 00046 virtual bool Init() 00047 { 00048 return true; 00049 } 00050 virtual bool Execute() = 0; 00051 }; 00052 00053 namespace detail 00054 { 00055 00060 class SERVER_EXPORT JackThreadInterface 00061 { 00062 00063 public: 00064 00065 enum kThreadState {kIdle, kStarting, kIniting, kRunning}; 00066 00067 protected: 00068 00069 JackRunnableInterface* fRunnable; 00070 int fPriority; 00071 bool fRealTime; 00072 volatile kThreadState fStatus; 00073 int fCancellation; 00074 00075 public: 00076 00077 JackThreadInterface(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation): 00078 fRunnable(runnable), fPriority(priority), fRealTime(real_time), fStatus(kIdle), fCancellation(cancellation) 00079 {} 00080 00081 kThreadState GetStatus() 00082 { 00083 return fStatus; 00084 } 00085 void SetStatus(kThreadState status) 00086 { 00087 fStatus = status; 00088 } 00089 00090 void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX... 00091 {} 00092 00093 int Start(); 00094 int StartSync(); 00095 int Kill(); 00096 int Stop(); 00097 void Terminate(); 00098 00099 int AcquireRealTime(); // Used when called from another thread 00100 int AcquireSelfRealTime(); // Used when called from thread itself 00101 00102 int AcquireRealTime(int priority); // Used when called from another thread 00103 int AcquireSelfRealTime(int priority); // Used when called from thread itself 00104 00105 int DropRealTime(); // Used when called from another thread 00106 int DropSelfRealTime(); // Used when called from thread itself 00107 00108 pthread_t GetThreadID(); 00109 00110 static int AcquireRealTimeImp(pthread_t thread, int priority); 00111 static int AcquireRealTimeImp(pthread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint); 00112 static int DropRealTimeImp(pthread_t thread); 00113 static int StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg); 00114 static int StopImp(pthread_t thread); 00115 static int KillImp(pthread_t thread); 00116 }; 00117 00118 } 00119 00120 } // end of namespace 00121 00122 bool jack_get_thread_realtime_priority_range(int * min_ptr, int * max_ptr); 00123 00124 bool jack_tls_allocate_key(jack_tls_key *key_ptr); 00125 bool jack_tls_free_key(jack_tls_key key); 00126 00127 bool jack_tls_set(jack_tls_key key, void *data_ptr); 00128 void *jack_tls_get(jack_tls_key key); 00129 00130 #endif