- wxThreadInternal()
- {
- m_tid = 0;
- m_state = STATE_NEW;
- m_priority = WXTHREAD_DEFAULT_PRIORITY;
- m_notifyQueueId = 0;
- }
-
- ~wxThreadInternal()
- {
- if ( m_notifyQueueId)
- MPDeleteQueue( m_notifyQueueId);
- }
-
- void Free()
- {
- }
-
- // create a new (suspended) thread (for the given thread object)
- // stacksize == 0 will give the default stack size of 4 KB.
- bool Create(wxThread *thread, unsigned int stackSize);
-
- void Run();
-
- // suspend/resume/terminate
- bool Suspend();
- bool Resume();
- void Cancel()
- {
- wxCriticalSectionLocker lock( m_critical);
- m_state = STATE_CANCELED;
- }
-
- wxThread::ExitCode Wait();
-
- // thread state
- void SetState(wxThreadState state)
- {
- wxCriticalSectionLocker lock( m_critical);
- m_state = state;
- }
-
- wxThreadState GetState() const
- {
- wxCriticalSectionLocker lock( m_critical);
- return m_state;
- }
-
- // thread priority
- void SetPriority(unsigned int priority);
- unsigned int GetPriority() const
- {
- wxCriticalSectionLocker lock( m_critical);
- return m_priority;
- }
-
- void SetResult( void *res )
- {
- wxCriticalSectionLocker lock( m_critical);
- m_result = res ;
- }
-
- void *GetResult()
- {
- wxCriticalSectionLocker lock( m_critical);
- return m_result ;
- }
-
- // Get the ID of this thread's underlying MP Services task.
- MPTaskID GetId() const
- {
- wxCriticalSectionLocker lock( m_critical);
- return m_tid;
- }
-
- // thread function
- static OSStatus MacThreadStart(void* arg);
-
-private:
-
- wxThreadState m_state; // state, see wxThreadState enum
- unsigned int m_priority; // thread priority in "wx" units
- MPTaskID m_tid; // thread id
- void* m_result;
-
- mutable wxCriticalSection m_critical;
- MPQueueID m_notifyQueueId;
- unsigned int m_stackSize;
- wxThread* m_thread;
-};
-
-static wxArrayPtrVoid s_threads ;
-
-OSStatus wxThreadInternal::MacThreadStart(void *parameter)
-{
- wxThread* thread = (wxThread*) parameter ;
- // first of all, check whether we hadn't been cancelled already
- if ( thread->m_internal->GetState() == STATE_EXITED )