#include <Threads.h>
#include "wx/mac/uma.h"
#include "wx/mac/macnotfy.h"
+#include "Timer.h"
#endif
#define INFINITE 0xFFFFFFFF
static ThreadID gs_idMainThread = kNoThreadID ;
static bool gs_waitingForThread = FALSE ;
+size_t g_numberOfThreads = 0;
// ============================================================================
// MacOS implementation of thread classes
void wxThread::Sleep(unsigned long milliseconds)
{
- clock_t start = clock();
+ UnsignedWide start, now;
+
+ Microseconds(&start);
+
+ double mssleep = milliseconds * 1000 ;
+ double msstart, msnow ;
+ msstart = (start.hi * 4294967296.0 + start.lo) ;
+
do
{
YieldToAnyThread();
- } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ;
+ Microseconds(&now);
+ msnow = (now.hi * 4294967296.0 + now.lo) ;
+ } while( msstart - msnow < mssleep );
}
int wxThread::GetCPUCount()
wxThread::wxThread(wxThreadKind kind)
{
+ g_numberOfThreads++;
m_internal = new wxThreadInternal();
m_isDetached = kind == wxTHREAD_DETACHED;
wxThread::~wxThread()
{
+ if (g_numberOfThreads>0)
+ {
+ g_numberOfThreads--;
+ }
+#ifdef __WXDEBUG__
+ else
+ {
+ wxFAIL_MSG(wxT("More threads deleted than created."));
+ }
+#endif
+
s_threads.Remove( (void*) this ) ;
if (m_internal != NULL) {
delete m_internal;