Include c++11 threading
This commit is contained in:
+84
-10
@@ -1,7 +1,7 @@
|
|||||||
#ifndef THREADING_H
|
#ifndef THREADING_H
|
||||||
#define THREADING_H
|
#define THREADING_H
|
||||||
|
|
||||||
#if !defined(PSP) && !defined(QT_CONFIG)
|
#if !defined(PSP) && !defined(QT_CONFIG) && !(__cplusplus > 199711L)
|
||||||
#include <boost/date_time.hpp>
|
#include <boost/date_time.hpp>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#elif !defined(QT_CONFIG)
|
#elif defined(PSP)
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
@@ -212,13 +212,13 @@ namespace boost
|
|||||||
**
|
**
|
||||||
** The intent of its usage is this form only:
|
** The intent of its usage is this form only:
|
||||||
** mWorkerThread = boost::thread(ThreadProc, this);
|
** mWorkerThread = boost::thread(ThreadProc, this);
|
||||||
** where ThreadProc is a static member function of the 'this' class,eg:
|
** where ThreadProc is a static member function of the 'this' class,eg:
|
||||||
** static void FOO::ThreadProc(void* inParam)
|
** static void FOO::ThreadProc(void* inParam)
|
||||||
** {
|
** {
|
||||||
** FOO* instance = reinterpret_cast<FOO*>(inParam);
|
** FOO* instance = reinterpret_cast<FOO*>(inParam);
|
||||||
** // now you have class instance data available...
|
** // now you have class instance data available...
|
||||||
** }
|
** }
|
||||||
**
|
**
|
||||||
** Any other variant of a thread proc with more than one param is unimplemented.
|
** Any other variant of a thread proc with more than one param is unimplemented.
|
||||||
*/
|
*/
|
||||||
class thread
|
class thread
|
||||||
@@ -307,7 +307,7 @@ namespace boost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(QT_CONFIG)
|
#elif defined(QT_CONFIG) && (__cplusplus <= 199711L)
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -537,6 +537,80 @@ namespace boost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif (__cplusplus > 199711L)
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
typedef std::thread thread;
|
||||||
|
|
||||||
|
template <class Mutex>
|
||||||
|
struct unique_lock
|
||||||
|
{
|
||||||
|
unique_lock(Mutex& inMutex) : mMutex(&inMutex)
|
||||||
|
{
|
||||||
|
mMutex->lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~unique_lock()
|
||||||
|
{
|
||||||
|
mMutex->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex* mMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
class mutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef unique_lock<mutex> scoped_lock;
|
||||||
|
|
||||||
|
mutex()
|
||||||
|
: mQMutex()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~mutex()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void lock()
|
||||||
|
{
|
||||||
|
mQMutex.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock()
|
||||||
|
{
|
||||||
|
mQMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex mQMutex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutex(mutex const&);
|
||||||
|
mutex& operator=(mutex const&);
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace posix_time
|
||||||
|
{
|
||||||
|
typedef unsigned int milliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
** boost's platform neutral sleep call.
|
||||||
|
*/
|
||||||
|
namespace this_thread
|
||||||
|
{
|
||||||
|
inline void sleep(boost::posix_time::milliseconds const& time)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // THREADING_H
|
#endif // THREADING_H
|
||||||
|
|||||||
Reference in New Issue
Block a user