+// This class is used by wxThreadInternal to support Delete() on
+// a detached thread
+class wxRefCountedCondition
+{
+public:
+ // start with a initial reference count of 1
+ wxRefCountedCondition()
+ {
+ m_refCount = 1;
+ m_signaled = FALSE;
+
+ m_mutex = new wxMutex();
+ m_cond = new wxCondition( *m_mutex );
+ }
+
+ // increment the reference count
+ void AddRef()
+ {
+ wxMutexLocker locker( *m_mutex );
+
+ m_refCount++;
+ }
+
+ // decrement the reference count if reference count is zero then delete the
+ // object
+ void DeleteRef()
+ {
+ bool shouldDelete = FALSE;
+
+ m_mutex->Lock();
+
+ if ( --m_refCount == 0 )
+ {
+ shouldDelete = TRUE;
+ }
+
+ m_mutex->Unlock();
+
+ if ( shouldDelete )
+ {
+ delete this;
+ }
+ }
+
+
+ // sets the object to signaled this signal will be a persistent signal all
+ // further Wait()s on the object will return without blocking
+ void SetSignaled()
+ {
+ wxMutexLocker locker( *m_mutex );
+
+ m_signaled = TRUE;
+
+ m_cond->Broadcast();
+ }
+
+ // wait till the object is signaled if the object was already signaled then
+ // return immediately
+ void Wait()
+ {
+ wxMutexLocker locker( *m_mutex );
+
+ if ( !m_signaled )
+ {
+ m_cond->Wait();
+ }
+ }
+
+private:
+ int m_refCount;
+
+ wxMutex *m_mutex;
+ wxCondition *m_cond;
+
+ bool m_signaled;
+
+ // Cannot delete this object directly, call DeleteRef() instead
+ ~wxRefCountedCondition()
+ {
+ delete m_cond;
+ delete m_mutex;
+ }
+
+ // suppress gcc warning about the class having private dtor and not having
+ // friend (so what??)
+ friend class wxDummyFriend;
+};
+
+// ===========================================================================
+// wxThread implementation
+// ===========================================================================
+
+// the thread callback functions must have the C linkage
+extern "C"
+{
+
+#if HAVE_THREAD_CLEANUP_FUNCTIONS
+ // thread exit function
+ void wxPthreadCleanup(void *ptr);
+#endif // HAVE_THREAD_CLEANUP_FUNCTIONS
+
+void *wxPthreadStart(void *ptr);
+
+} // extern "C"
+
+// ----------------------------------------------------------------------------
+// wxThreadInternal
+// ----------------------------------------------------------------------------