41 #if !defined(__CAPThread_h__)
42 #define __CAPThread_h__
49 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
50 #include <CoreFoundation/CFBase.h>
61 #error Unsupported operating system
76 typedef void* (*ThreadRoutine)(
void* inParameter);
83 kMinThreadPriority = 1,
84 kMaxThreadPriority = 63,
85 kDefaultThreadPriority = 31
87 kMinThreadPriority = 1,
88 kMaxThreadPriority = 31,
89 kDefaultThreadPriority = THREAD_PRIORITY_NORMAL
95 CAPThread(ThreadRoutine inThreadRoutine,
void* inParameter, UInt32 inPriority = kDefaultThreadPriority,
bool inFixedPriority=
false,
bool inAutoDelete=
false);
96 CAPThread(ThreadRoutine inThreadRoutine,
void* inParameter, UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint,
bool inIsPreemptible,
bool inAutoDelete=
false);
102 typedef pthread_t NativeThread;
104 NativeThread GetNativeThread() {
return mPThread; }
105 static NativeThread GetCurrentThread() {
return pthread_self(); }
106 static bool IsNativeThreadsEqual(NativeThread a, NativeThread b) {
return (a==b); }
108 bool operator==(NativeThread b) {
return pthread_equal(mPThread,b); }
110 pthread_t GetPThread()
const {
return mPThread; }
111 bool IsCurrentThread()
const {
return (0 != mPThread) && (pthread_self() == mPThread); }
112 bool IsRunning()
const {
return 0 != mPThread; }
113 #elif TARGET_OS_WIN32
114 typedef unsigned long NativeThread;
116 NativeThread GetNativeThread() {
return mThreadID; }
117 static NativeThread GetCurrentThread() {
return GetCurrentThreadId(); }
118 static bool IsNativeThreadsEqual(NativeThread a, NativeThread b) {
return (a==b); }
120 bool operator ==(NativeThread b) {
return (mThreadID==b); }
122 HANDLE GetThreadHandle()
const {
return mThreadHandle; }
123 UInt32 GetThreadID()
const {
return mThreadID; }
124 bool IsCurrentThread()
const {
return (0 != mThreadID) && (GetCurrentThreadId() == mThreadID); }
125 bool IsRunning()
const {
return 0 != mThreadID; }
128 bool IsTimeShareThread()
const {
return !mTimeConstraintSet; }
129 bool IsTimeConstraintThread()
const {
return mTimeConstraintSet; }
131 UInt32 GetPriority()
const {
return mPriority; }
132 UInt32 GetScheduledPriority();
133 void SetPriority(UInt32 inPriority,
bool inFixedPriority=
false);
135 void GetTimeConstraints(UInt32& outPeriod, UInt32& outComputation, UInt32& outConstraint,
bool& outIsPreemptible)
const { outPeriod = mPeriod; outComputation = mComputation; outConstraint = mConstraint; outIsPreemptible = mIsPreemptible; }
136 void SetTimeConstraints(UInt32 inPeriod, UInt32 inComputation, UInt32 inConstraint,
bool inIsPreemptible);
137 void ClearTimeConstraints() { SetPriority(mPriority); }
139 bool WillAutoDelete()
const {
return mAutoDelete; }
140 void SetAutoDelete(
bool b) { mAutoDelete = b; }
143 void DebugPriority(
const char *label);
148 virtual void Start();
153 static void* Entry(CAPThread* inCAPThread);
154 static UInt32 getScheduledPriority(pthread_t inThread,
int inPriorityKind);
155 #elif TARGET_OS_WIN32
156 static UInt32 WINAPI Entry(CAPThread* inCAPThread);
161 UInt32 mSpawningThreadPriority;
162 #elif TARGET_OS_WIN32
163 HANDLE mThreadHandle;
164 unsigned long mThreadID;
166 ThreadRoutine mThreadRoutine;
167 void* mThreadParameter;
173 bool mTimeConstraintSet;
bool TTFOUNDATION_EXPORT operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.