Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: ollydbg on June 23, 2013, 10:05:45 am

Title: build C::B using GCC lower than 3.4?
Post by: ollydbg on June 23, 2013, 10:05:45 am
Here, in include\cbthreadpool.h
Code
// -------------------------------------------------------------------
//  Determine if a GNU compiler with version less than 3.4 is being used
// -------------------------------------------------------------------
#ifdef __GNUC__
    #if ( (__GNUC__ < 3) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ < 4) ) )
        #define GCC_LT_34
    #endif
#endif // __GNUC__

#ifdef GCC_LT_34
class cbThreadPool;
#include "cbthreadpool_extras.h"
#define QUALIFY_IF_GCC_GE_34(x)
#else
#define QUALIFY_IF_GCC_GE_34(x) x
#endif

Later in cbthreadpool.cpp

Code
void QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Abort()
{
  m_abort = true;
  AbortTask();
}

bool QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Aborted() const
{
  return m_abort;
}

void QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::AbortTask()
{
  wxMutexLocker lock(m_taskMutex);

  if (m_pTask)
    m_pTask->Abort();
}

Do we still support GCC which version is lower than 3.4?
Title: Re: build C::B using GCC lower than 3.4?
Post by: oBFusCATed on June 23, 2013, 10:27:48 am
I don't think anything below 4.0 will work.
We use std::tr1::shared_ptr and std::tr1::unordered_map which I don't think are available in <4.0.
Title: Re: build C::B using GCC lower than 3.4?
Post by: ollydbg on June 23, 2013, 10:31:23 am
Ok, so we are going to remove these dirty macros. :)
Title: Re: build C::B using GCC lower than 3.4?
Post by: ollydbg on July 06, 2013, 05:40:16 pm
Code
 src/CodeBlocks.cbp         |  3 --
 src/include/cbthreadpool.h | 93 ++++++++++++++++++++++++++++++++--------------
 src/sdk/cbthreadpool.cpp   | 10 ++---
 3 files changed, 71 insertions(+), 35 deletions(-)

diff --git a/src/CodeBlocks.cbp b/src/CodeBlocks.cbp
index a646cfb..a0671a2 100644
--- a/src/CodeBlocks.cbp
+++ b/src/CodeBlocks.cbp
@@ -808,9 +808,6 @@
  <Unit filename="include/cbthreadpool.h">
  <Option target="sdk" />
  </Unit>
- <Unit filename="include/cbthreadpool_extras.h">
- <Option target="sdk" />
- </Unit>
  <Unit filename="include/cbtool.h">
  <Option target="sdk" />
  </Unit>
diff --git a/src/include/cbthreadpool.h b/src/include/cbthreadpool.h
index e52f767..f463d42 100644
--- a/src/include/cbthreadpool.h
+++ b/src/include/cbthreadpool.h
@@ -14,23 +14,6 @@
 #include "cbthreadedtask.h"
 #include "settings.h"
 
-// -------------------------------------------------------------------
-//  Determine if a GNU compiler with version less than 3.4 is being used
-// -------------------------------------------------------------------
-#ifdef __GNUC__
-    #if ( (__GNUC__ < 3) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ < 4) ) )
-        #define GCC_LT_34
-    #endif
-#endif // __GNUC__
-
-#ifdef GCC_LT_34
-class cbThreadPool;
-#include "cbthreadpool_extras.h"
-#define QUALIFY_IF_GCC_GE_34(x)
-#else
-#define QUALIFY_IF_GCC_GE_34(x) x
-#endif
-
 /// A Thread Pool implementation
 class DLLIMPORT cbThreadPool
 {
@@ -99,9 +82,65 @@ class DLLIMPORT cbThreadPool
     void BatchEnd();
 
   private:
-    #ifndef GCC_LT_34
-    #include "cbthreadpool_extras.h"
-    #endif
+
+    /// Josuttis' implementation of CountedPtr
+    template <typename T>
+    class CountedPtr
+    {
+      private:
+        T *ptr;
+        long *count;
+
+      public:
+        explicit CountedPtr(T *p = 0);
+        CountedPtr(const CountedPtr<T> &p) throw();
+        ~CountedPtr() throw();
+        CountedPtr<T> &operator = (const CountedPtr<T> &p) throw();
+        T &operator * () const throw();
+        T *operator -> () const throw();
+
+      private:
+        void dispose();
+    };
+
+    /** A Worker Thread class.
+      *
+      * These are the ones that execute the tasks.
+      * You shouldn't worry about it since it's for "private" purposes of the Pool.
+      */
+    class cbWorkerThread : public wxThread
+    {
+      public:
+        /** cbWorkerThread ctor
+          *
+          * @param pool Thread Pool this Worker Thread belongs to
+          * @param semaphore Used to synchronise the Worker Threads
+          */
+        cbWorkerThread(cbThreadPool *pool, CountedPtr<wxSemaphore> &semaphore);
+
+        /// Entry point of this thread. The magic happens here.
+        ExitCode Entry();
+
+        /// Tell the thread to abort. It will also tell the task to abort (if any)
+        void Abort();
+
+        /** Tells whether we should abort or not
+          *
+          * @return true if we should abort
+          */
+        bool Aborted() const;
+
+        /// Aborts the running task (if any)
+        void AbortTask();
+
+      private:
+        bool m_abort;
+        cbThreadPool *m_pPool;
+        CountedPtr<wxSemaphore> m_semaphore;
+        cbThreadedTask *m_pTask;
+        wxMutex m_taskMutex;
+    };
+
     typedef std::vector<cbWorkerThread *> WorkerThreadsArray;
 
     /// All tasks are added to one of these. It'll also save the autodelete value
@@ -233,7 +272,7 @@ inline void cbThreadPool::AwakeNeeded()
 /* *** Josuttis' CountedPtr *** */
 
 template <typename T>
-inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::CountedPtr(T *p)
+inline cbThreadPool::CountedPtr<T>::CountedPtr(T *p)
 : ptr(p),
   count(new long(1))
 {
@@ -241,7 +280,7 @@ inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::CountedPtr(T *p)
 }
 
 template <typename T>
-inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::CountedPtr(const CountedPtr<T> &p) throw()
+inline cbThreadPool::CountedPtr<T>::CountedPtr(const CountedPtr<T> &p) throw()
 : ptr(p.ptr),
   count(p.count)
 {
@@ -249,13 +288,13 @@ inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::CountedPtr(const Count
 }
 
 template <typename T>
-inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::~CountedPtr() throw()
+inline cbThreadPool::CountedPtr<T>::~CountedPtr() throw()
 {
   dispose();
 }
 
 template <typename T>
-inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T> &QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::operator = (const CountedPtr<T> &p) throw()
+inline cbThreadPool::CountedPtr<T> &cbThreadPool::CountedPtr<T>::operator = (const CountedPtr<T> &p) throw()
 {
   if (this != &p)
   {
@@ -269,19 +308,19 @@ inline QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T> &QUALIFY_IF_GCC_GE_34(c
 }
 
 template <typename T>
-inline T &QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::operator * () const throw()
+inline T &cbThreadPool::CountedPtr<T>::operator * () const throw()
 {
   return *ptr;
 }
 
 template <typename T>
-inline T *QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::operator -> () const throw()
+inline T *cbThreadPool::CountedPtr<T>::operator -> () const throw()
 {
   return ptr;
 }
 
 template <typename T>
-inline void QUALIFY_IF_GCC_GE_34(cbThreadPool::)CountedPtr<T>::dispose()
+inline void cbThreadPool::CountedPtr<T>::dispose()
 {
   if (--*count == 0)
   {
diff --git a/src/sdk/cbthreadpool.cpp b/src/sdk/cbthreadpool.cpp
index dacc5fe..75332ce 100644
--- a/src/sdk/cbthreadpool.cpp
+++ b/src/sdk/cbthreadpool.cpp
@@ -165,7 +165,7 @@ void cbThreadPool::TaskDone(cb_unused cbWorkerThread* thread)
 /* ******** cbWorkerThread IMPLEMENTATION ******** */
 /* *********************************************** */
 
-QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::cbWorkerThread(cbThreadPool *pool, CountedPtr<wxSemaphore> &semaphore)
+cbThreadPool::cbWorkerThread::cbWorkerThread(cbThreadPool *pool, CountedPtr<wxSemaphore> &semaphore)
 : m_abort(false),
   m_pPool(pool),
   m_semaphore(semaphore),
@@ -174,7 +174,7 @@ QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::cbWorkerThread(cbThreadPool
   // empty
 }
 
-wxThread::ExitCode QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Entry()
+wxThread::ExitCode cbThreadPool::cbWorkerThread::Entry()
 {
   bool workingThread = false; // keeps the state of the thread so it knows better what to do
 
@@ -231,18 +231,18 @@ wxThread::ExitCode QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Entry()
   return 0;
 }
 
-void QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Abort()
+void cbThreadPool::cbWorkerThread::Abort()
 {
   m_abort = true;
   AbortTask();
 }
 
-bool QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::Aborted() const
+bool cbThreadPool::cbWorkerThread::Aborted() const
 {
   return m_abort;
 }
 
-void QUALIFY_IF_GCC_GE_34(cbThreadPool::)cbWorkerThread::AbortTask()
+void cbThreadPool::cbWorkerThread::AbortTask()
 {
   wxMutexLocker lock(m_taskMutex);
 
Git patch is here(only tested on Windows), will put in SVN trunk if there is no issue for days. :)
Title: Re: build C::B using GCC lower than 3.4?
Post by: ollydbg on July 15, 2013, 08:20:15 am
I'm commit to trunk now, please help me to synchonize on Linux build system (either unix.cbp files and auto-tools build).
Thanks.