Jack2  1.9.8
JackWinThread.h
00001 /*
00002  Copyright (C) 2004-2008 Grame
00003 
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU Lesser General Public License as published by
00006  the Free Software Foundation; either version 2.1 of the License, or
00007  (at your option) any later version.
00008 
00009  This program is distributed in the hope that it will be useful,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU Lesser General Public License for more details.
00013 
00014  You should have received a copy of the GNU Lesser General Public License
00015  along with this program; if not, write to the Free Software
00016  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018  */
00019 
00020 #ifndef __JackWinThread__
00021 #define __JackWinThread__
00022 
00023 #include "JackThread.h"
00024 #include "JackMMCSS.h"
00025 #include "JackCompilerDeps.h"
00026 #include "JackSystemDeps.h"
00027 #include <windows.h>
00028 
00029 namespace Jack
00030 {
00031 
00032 typedef DWORD (WINAPI *ThreadCallback)(void *arg);
00033 
00038 class SERVER_EXPORT JackWinThread : public JackMMCSS, public detail::JackThreadInterface
00039 {
00040 
00041     private:
00042 
00043         HANDLE fThread;
00044         HANDLE fEvent;
00045 
00046         static DWORD WINAPI ThreadHandler(void* arg);
00047 
00048     public:
00049 
00050         JackWinThread(JackRunnableInterface* runnable);
00051         ~JackWinThread();
00052 
00053         int Start();
00054         int StartSync();
00055         int Kill();
00056         int Stop();
00057         void Terminate();
00058 
00059         int AcquireRealTime();                  // Used when called from another thread
00060         int AcquireSelfRealTime();              // Used when called from thread itself
00061 
00062         int AcquireRealTime(int priority);      // Used when called from another thread
00063         int AcquireSelfRealTime(int priority);  // Used when called from thread itself
00064 
00065         int DropRealTime();                     // Used when called from another thread
00066         int DropSelfRealTime();                 // Used when called from thread itself
00067 
00068         jack_native_thread_t GetThreadID();
00069         bool IsThread();
00070 
00071         static int AcquireRealTimeImp(jack_native_thread_t thread, int priority);
00072         static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
00073         {
00074             return JackWinThread::AcquireRealTimeImp(thread, priority);
00075         }
00076         static int DropRealTimeImp(jack_native_thread_t thread);
00077         static int StartImp(jack_native_thread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg)
00078         {
00079             return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback) start_routine, arg);
00080         }
00081         static int StartImp(jack_native_thread_t* thread, int priority, int realtime, ThreadCallback start_routine, void* arg);
00082         static int StopImp(jack_native_thread_t thread);
00083         static int KillImp(jack_native_thread_t thread);
00084 
00085 };
00086 
00087 SERVER_EXPORT void ThreadExit();
00088 
00089 } // end of namespace
00090 
00091 #endif
00092