+ // calculate the process mask: it's a bit vector with one bit per
+ // processor; we want to schedule the process to run on first level
+ // CPUs
+ DWORD bit = 1;
+ while ( bit )
+ {
+ if ( dwSysMask & bit )
+ {
+ // ok, we can set this bit
+ dwProcMask |= bit;
+
+ // another process added
+ if ( --level == 0 )
+ {
+ // and that's enough
+ break;
+ }
+ }
+
+ // next bit
+ bit <<= 1;
+ }
+
+ // could we set all bits?
+ if ( level != 0 )
+ {
+ wxLogDebug(wxT("bad level %u in wxThread::SetConcurrency()"), level);
+
+ return false;
+ }
+
+ // set it: we can't link to SetProcessAffinityMask() because it doesn't
+ // exist in Win9x, use RT binding instead
+
+ typedef BOOL (WINAPI *SETPROCESSAFFINITYMASK)(HANDLE, DWORD_PTR);
+
+ // can use static var because we're always in the main thread here
+ static SETPROCESSAFFINITYMASK pfnSetProcessAffinityMask = NULL;
+
+ if ( !pfnSetProcessAffinityMask )
+ {
+ HMODULE hModKernel = ::LoadLibrary(wxT("kernel32"));
+ if ( hModKernel )
+ {
+ pfnSetProcessAffinityMask = (SETPROCESSAFFINITYMASK)
+ ::GetProcAddress(hModKernel, "SetProcessAffinityMask");
+ }
+
+ // we've discovered a MT version of Win9x!
+ wxASSERT_MSG( pfnSetProcessAffinityMask,
+ wxT("this system has several CPUs but no SetProcessAffinityMask function?") );
+ }
+
+ if ( !pfnSetProcessAffinityMask )
+ {
+ // msg given above - do it only once
+ return false;
+ }
+
+ if ( pfnSetProcessAffinityMask(hProcess, dwProcMask) == 0 )
+ {
+ wxLogLastError(wxT("SetProcessAffinityMask"));
+
+ return false;
+ }
+
+ return true;
+#endif // __WXWINCE__/!__WXWINCE__
+}
+
+// ctor and dtor
+// -------------
+
+wxThread::wxThread(wxThreadKind kind)
+{
+ m_internal = new wxThreadInternal(this);
+
+ m_isDetached = kind == wxTHREAD_DETACHED;
+}
+
+wxThread::~wxThread()
+{
+ delete m_internal;
+}
+
+// create/start thread
+// -------------------
+
+wxThreadError wxThread::Create(unsigned int stackSize)
+{
+ wxCriticalSectionLocker lock(m_critsect);
+
+ if ( !m_internal->Create(this, stackSize) )
+ return wxTHREAD_NO_RESOURCE;