]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/thread.cpp
treectrl -> treetest
[wxWidgets.git] / src / msw / thread.cpp
index ab8030e5840c1c0e0ed557f4ebf8783b3b465e90..b654353bfce9748f5248201b11732b31b2737a8e 100644 (file)
@@ -351,8 +351,8 @@ wxCriticalSection::wxCriticalSection()
 #ifdef __WXDEBUG__
     // Done this way to stop warnings during compilation about statement
     // always being false
 #ifdef __WXDEBUG__
     // Done this way to stop warnings during compilation about statement
     // always being false
-        int csSize = sizeof(CRITICAL_SECTION);
-        int bSize  = sizeof(m_buffer);
+    int csSize = sizeof(CRITICAL_SECTION);
+    int bSize  = sizeof(m_buffer);
     wxASSERT_MSG( csSize <= bSize,
                   _T("must increase buffer size in wx/thread.h") );
 #endif
     wxASSERT_MSG( csSize <= bSize,
                   _T("must increase buffer size in wx/thread.h") );
 #endif
@@ -411,7 +411,7 @@ public:
     }
 
     // create a new (suspended) thread (for the given thread object)
     }
 
     // create a new (suspended) thread (for the given thread object)
-    bool Create(wxThread *thread);
+    bool Create(wxThread *thread, unsigned int stackSize);
 
     // suspend/resume/terminate
     bool Suspend();
 
     // suspend/resume/terminate
     bool Suspend();
@@ -514,30 +514,34 @@ void wxThreadInternal::SetPriority(unsigned int priority)
     }
 }
 
     }
 }
 
-bool wxThreadInternal::Create(wxThread *thread)
+bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize)
 {
     // for compilers which have it, we should use C RTL function for thread
     // creation instead of Win32 API one because otherwise we will have memory
     // leaks if the thread uses C RTL (and most threads do)
 #ifdef wxUSE_BEGIN_THREAD
 {
     // for compilers which have it, we should use C RTL function for thread
     // creation instead of Win32 API one because otherwise we will have memory
     // leaks if the thread uses C RTL (and most threads do)
 #ifdef wxUSE_BEGIN_THREAD
+
+    // Watcom is reported to not like 0 stack size (which means "use default"
+    // for the other compilers and is also the default value for stackSize)
+#ifdef __WATCOMC__
+    if ( !stackSize )
+        stackSize = 10240;
+#endif // __WATCOMC__
+
     m_hThread = (HANDLE)_beginthreadex
                         (
     m_hThread = (HANDLE)_beginthreadex
                         (
-                            NULL,   // default security
-#ifdef __WATCOMC__
-                            10240,  // stack size can't be NULL in Watcom
-#else
-                            0,      // default stack size
-#endif
-                            wxThreadInternal::WinThreadStart, // entry point
-                            thread,
-                            CREATE_SUSPENDED,
-                            (unsigned int *)&m_tid
+                          NULL,                             // default security
+                          stackSize,
+                          wxThreadInternal::WinThreadStart, // entry point
+                          thread,
+                          CREATE_SUSPENDED,
+                          (unsigned int *)&m_tid
                         );
 #else // compiler doesn't have _beginthreadex
     m_hThread = ::CreateThread
                   (
                     NULL,                               // default security
                         );
 #else // compiler doesn't have _beginthreadex
     m_hThread = ::CreateThread
                   (
                     NULL,                               // default security
-                    0,                                  // default stack size
+                    stackSize,                          // stack size
                     wxThreadInternal::WinThreadStart,   // thread entry point
                     (LPVOID)thread,                     // parameter
                     CREATE_SUSPENDED,                   // flags
                     wxThreadInternal::WinThreadStart,   // thread entry point
                     (LPVOID)thread,                     // parameter
                     CREATE_SUSPENDED,                   // flags
@@ -643,6 +647,11 @@ int wxThread::GetCPUCount()
     return si.dwNumberOfProcessors;
 }
 
     return si.dwNumberOfProcessors;
 }
 
+unsigned long wxThread::GetCurrentId()
+{
+    return (unsigned long)::GetCurrentThreadId();
+}
+
 bool wxThread::SetConcurrency(size_t level)
 {
     wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
 bool wxThread::SetConcurrency(size_t level)
 {
     wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
@@ -756,11 +765,11 @@ wxThread::~wxThread()
 // create/start thread
 // -------------------
 
 // create/start thread
 // -------------------
 
-wxThreadError wxThread::Create()
+wxThreadError wxThread::Create(unsigned int stackSize)
 {
     wxCriticalSectionLocker lock(m_critsect);
 
 {
     wxCriticalSectionLocker lock(m_critsect);
 
-    if ( !m_internal->Create(this) )
+    if ( !m_internal->Create(this, stackSize) )
         return wxTHREAD_NO_RESOURCE;
 
     return wxTHREAD_NO_ERROR;
         return wxTHREAD_NO_RESOURCE;
 
     return wxTHREAD_NO_ERROR;
@@ -1244,3 +1253,5 @@ bool WXDLLEXPORT wxIsWaitingForThread()
 }
 
 #endif // wxUSE_THREADS
 }
 
 #endif // wxUSE_THREADS
+
+// vi:sts=4:sw=4:et