Jack2  1.9.8
JackPosixThread.h
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 __JackPosixThread__
00022 #define __JackPosixThread__
00023 
00024 #include "JackThread.h"
00025 #include <pthread.h>
00026 
00027 namespace Jack
00028 {
00029 
00030 /* use 512KB stack per thread - the default is way too high to be feasible
00031  * with mlockall() on many systems */
00032 #define THREAD_STACK 524288
00033 
00038 class SERVER_EXPORT JackPosixThread : public detail::JackThreadInterface
00039 {
00040 
00041     protected:
00042 
00043         jack_native_thread_t fThread;
00044         static void* ThreadHandler(void* arg);
00045 
00046     public:
00047 
00048         JackPosixThread(JackRunnableInterface* runnable, bool real_time, int priority, int cancellation)
00049                 : JackThreadInterface(runnable, priority, real_time, cancellation), fThread((jack_native_thread_t)NULL)
00050         {}
00051         JackPosixThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
00052                 : JackThreadInterface(runnable, 0, false, cancellation), fThread((jack_native_thread_t)NULL)
00053         {}
00054 
00055         int Start();
00056         int StartSync();
00057         int Kill();
00058         int Stop();
00059         void Terminate();
00060 
00061         int AcquireRealTime();                  // Used when called from another thread
00062         int AcquireSelfRealTime();              // Used when called from thread itself
00063 
00064         int AcquireRealTime(int priority);      // Used when called from another thread
00065         int AcquireSelfRealTime(int priority);  // Used when called from thread itself
00066 
00067         int DropRealTime();                     // Used when called from another thread
00068         int DropSelfRealTime();                 // Used when called from thread itself
00069 
00070         jack_native_thread_t GetThreadID();
00071         bool IsThread();
00072 
00073         static int AcquireRealTimeImp(jack_native_thread_t thread, int priority);
00074         static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
00075         {
00076             return JackPosixThread::AcquireRealTimeImp(thread, priority);
00077         }
00078         static int DropRealTimeImp(jack_native_thread_t thread);
00079         static int StartImp(jack_native_thread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
00080         static int StopImp(jack_native_thread_t thread);
00081         static int KillImp(jack_native_thread_t thread);
00082 };
00083 
00084 SERVER_EXPORT void ThreadExit();
00085 
00086 } // end of namespace
00087 
00088 
00089 #endif