+wxCriticalSection::wxCriticalSection()
+{
+ m_critsect = new wxCriticalSectionInternal;
+}
+
+wxCriticalSection::~wxCriticalSection()
+{
+ delete m_critsect;
+}
+
+void wxCriticalSection::Enter()
+{
+// ::EnterCriticalSection(*m_critsect);
+}
+
+void wxCriticalSection::Leave()
+{
+// ::LeaveCriticalSection(*m_critsect);
+}
+
+// ----------------------------------------------------------------------------
+// wxThread implementation
+// ----------------------------------------------------------------------------
+
+// wxThreadInternal class
+// ----------------------
+
+/*
+class wxThreadInternal
+{
+public:
+ wxThreadInternal()
+ {
+ m_hThread = 0;
+ m_state = STATE_NEW;
+ m_priority = WXTHREAD_DEFAULT_PRIORITY;
+ }
+
+ // create a new (suspended) thread (for the given thread object)
+ bool Create(wxThread *thread);
+
+ // suspend/resume/terminate
+ bool Suspend();
+ bool Resume();
+ void Cancel() { m_state = STATE_CANCELED; }
+
+ // thread state
+ void SetState(wxThreadState state) { m_state = state; }
+ wxThreadState GetState() const { return m_state; }
+
+ // thread priority
+ void SetPriority(unsigned int priority) { m_priority = priority; }
+ unsigned int GetPriority() const { return m_priority; }
+
+ // thread handle and id
+ HANDLE GetHandle() const { return m_hThread; }
+ DWORD GetId() const { return m_tid; }
+
+ // thread function
+ static DWORD WinThreadStart(wxThread *thread);
+
+private:
+ Handle m_hThread; // handle of the thread
+ wxThreadState m_state; // state, see wxThreadState enum
+ unsigned int m_priority; // thread priority in "wx" units
+ ThreadId m_tid; // thread id
+};
+
+DWORD wxThreadInternal::WinThreadStart(wxThread *thread)
+{
+ // store the thread object in the TLS
+ if ( !::TlsSetValue(s_tlsThisThread, thread) )
+ {
+ wxLogSysError(_("Can not start thread: error writing TLS."));
+
+ return (DWORD)-1;
+ }
+
+ DWORD ret = (DWORD)thread->Entry();
+ thread->p_internal->SetState(STATE_EXITED);
+ thread->OnExit();
+
+ delete thread;
+
+ return ret;
+}
+
+bool wxThreadInternal::Create(wxThread *thread)
+{
+ m_hThread = ::CreateThread
+ (
+ NULL, // default security
+ 0, // default stack size
+ (LPTHREAD_START_ROUTINE) // thread entry point
+ wxThreadInternal::WinThreadStart, //
+ (LPVOID)thread, // parameter
+ CREATE_SUSPENDED, // flags
+ &m_tid // [out] thread id
+ );
+
+ if ( m_hThread == NULL )
+ {
+ wxLogSysError(_("Can't create thread"));
+
+ return FALSE;
+ }
+
+ // translate wxWindows priority to the Windows one
+ int win_priority;
+ if (m_priority <= 20)
+ win_priority = THREAD_PRIORITY_LOWEST;
+ else if (m_priority <= 40)
+ win_priority = THREAD_PRIORITY_BELOW_NORMAL;
+ else if (m_priority <= 60)
+ win_priority = THREAD_PRIORITY_NORMAL;
+ else if (m_priority <= 80)
+ win_priority = THREAD_PRIORITY_ABOVE_NORMAL;
+ else if (m_priority <= 100)
+ win_priority = THREAD_PRIORITY_HIGHEST;
+ else
+ {
+ wxFAIL_MSG(wxT("invalid value of thread priority parameter"));
+ win_priority = THREAD_PRIORITY_NORMAL;
+ }
+
+ if ( ::SetThreadPriority(m_hThread, win_priority) == 0 )
+ {
+ wxLogSysError(_("Can't set thread priority"));
+ }
+
+ return TRUE;
+}
+
+bool wxThreadInternal::Suspend()
+{
+ DWORD nSuspendCount = ::SuspendThread(m_hThread);
+ if ( nSuspendCount == (DWORD)-1 )
+ {
+ wxLogSysError(_("Can not suspend thread %x"), m_hThread);
+
+ return FALSE;
+ }
+
+ m_state = STATE_PAUSED;
+
+ return TRUE;
+}
+
+bool wxThreadInternal::Resume()
+{
+ DWORD nSuspendCount = ::ResumeThread(m_hThread);
+ if ( nSuspendCount == (DWORD)-1 )
+ {
+ wxLogSysError(_("Can not resume thread %x"), m_hThread);
+
+ return FALSE;
+ }
+
+ m_state = STATE_RUNNING;
+
+ return TRUE;
+}
+
+// static functions
+// ----------------
+
+wxThread *wxThread::This()
+{
+ wxThread *thread = (wxThread *)::TlsGetValue(s_tlsThisThread);
+
+ // be careful, 0 may be a valid return value as well
+ if ( !thread && (::GetLastError() != NO_ERROR) )
+ {
+ wxLogSysError(_("Couldn't get the current thread pointer"));
+
+ // return NULL...
+ }
+
+ return thread;
+}
+
+bool wxThread::IsMain()
+{
+ return ::GetCurrentThreadId() == s_idMainThread;
+}
+
+#ifdef Yield
+ #undef Yield
+#endif
+
+void wxThread::Yield()
+{
+ // 0 argument to Sleep() is special
+ ::Sleep(0);
+}
+
+void wxThread::Sleep(unsigned long milliseconds)
+{
+ ::Sleep(milliseconds);
+}
+
+// create/start thread
+// -------------------
+