]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/thread.h
OpenGl works now under GTK
[wxWidgets.git] / include / wx / thread.h
index d5cd919400a81e900e887161f6bf9c2c900e4fbf..906a4eb5170e0466f3873b0d4ea153e40a6aa806 100644 (file)
@@ -64,25 +64,29 @@ class WXDLLEXPORT wxMutexInternal;
 class WXDLLEXPORT wxMutex 
 {
 public:
-  // constructor & destructor 
-  wxMutex();
-  ~wxMutex();
+    // constructor & destructor 
+    wxMutex();
+    ~wxMutex();
 
-  // Lock the mutex.
-  wxMutexError Lock();
-  // Try to lock the mutex: if it can't, returns immediately with an error.
-  wxMutexError TryLock();
-  // Unlock the mutex.
-  wxMutexError Unlock();
+    // Lock the mutex.
+    wxMutexError Lock();
+    // Try to lock the mutex: if it can't, returns immediately with an error.
+    wxMutexError TryLock();
+    // Unlock the mutex.
+    wxMutexError Unlock();
 
-  // Returns true if the mutex is locked.
-  bool IsLocked() const { return (m_locked > 0); }
+    // Returns true if the mutex is locked.
+    bool IsLocked() const { return (m_locked > 0); }
 
 protected:
-  friend class wxCondition;
+    friend class wxCondition;
 
-  int m_locked;
-  wxMutexInternal *p_internal;
+    // no assignment operator nor copy ctor
+    wxMutex(const wxMutex&);
+    wxMutex& operator=(const wxMutex&);
+
+    int m_locked;
+    wxMutexInternal *p_internal;
 };
 
 // a helper class which locks the mutex in the ctor and unlocks it in the dtor:
@@ -102,6 +106,10 @@ public:
     ~wxMutexLocker() { if ( IsOk() ) m_mutex->Unlock(); }
 
 private:
+    // no assignment operator nor copy ctor
+    wxMutexLocker(const wxMutexLocker&);
+    wxMutexLocker& operator=(const wxMutexLocker&);
+
     bool     m_isOk;
     wxMutex *m_mutex;
 };
@@ -131,6 +139,10 @@ public:
     void Leave();
 
 private:
+    // no assignment operator nor copy ctor
+    wxCriticalSection(const wxCriticalSection&);
+    wxCriticalSection& operator=(const wxCriticalSection&);
+
     wxCriticalSectionInternal *m_critsect;
 };
 
@@ -139,13 +151,17 @@ private:
 class WXDLLEXPORT wxCriticalSectionLocker
 {
 public:
-    wxCriticalSectionLocker(wxCriticalSection *critsect)
-        { (m_critsect = critsect)->Enter(); }
+    wxCriticalSectionLocker(wxCriticalSection& critsect) : m_critsect(critsect)
+        { m_critsect.Enter(); }
     ~wxCriticalSectionLocker()
-        { m_critsect->Leave(); }
+        { m_critsect.Leave(); }
 
 private:
-    wxCriticalSection *m_critsect;
+    // no assignment operator nor copy ctor
+    wxCriticalSectionLocker(const wxCriticalSectionLocker&);
+    wxCriticalSectionLocker& operator=(const wxCriticalSectionLocker&);
+
+    wxCriticalSection& m_critsect;
 };
 
 #endif
@@ -253,6 +269,20 @@ private:
 void WXDLLEXPORT wxMutexGuiEnter();
 void WXDLLEXPORT wxMutexGuiLeave();
 
+// implementation only
+#ifdef __WXMSW__
+    // unlock GUI if there are threads waiting for and lock it back when
+    // there are no more of them - should be called periodically by the main
+    // thread
+    void WXDLLEXPORT wxMutexGuiLeaveOrEnter();
+
+    // returns TRUE if the main thread has GUI lock
+    inline bool WXDLLEXPORT wxGuiOwnedByMainThread();
+
+    // wakes up the main thread if it's sleeping inside ::GetMessage()
+    inline void WXDLLEXPORT wxWakeUpMainThread();
+#endif // MSW
+
 #else // !wxUSE_THREADS
 
 // no thread support
@@ -261,4 +291,12 @@ inline void WXDLLEXPORT wxMutexGuiLeave() { }
 
 #endif // wxUSE_THREADS
 
+// automatically unlock GUI mutex in dtor
+class WXDLLEXPORT wxMutexGuiLocker
+{
+public:
+    wxMutexGuiLocker() { wxMutexGuiEnter(); }
+   ~wxMutexGuiLocker() { wxMutexGuiLeave(); }
+};
+
 #endif // __THREADH__