Fix C++11 compilability

Previous commits broke it... :(
master
est31 2016-01-23 05:45:00 +01:00
parent 0459eca8eb
commit e50c784e2c
7 changed files with 43 additions and 5 deletions

View File

@ -68,7 +68,7 @@ public:
*/ */
ScriptApiBase::ScriptApiBase() : ScriptApiBase::ScriptApiBase() :
m_luastackmutex(true) m_luastackmutex()
{ {
#ifdef SCRIPTAPI_LOCK_DEBUG #ifdef SCRIPTAPI_LOCK_DEBUG
m_lock_recursion_count = 0; m_lock_recursion_count = 0;

View File

@ -108,7 +108,7 @@ protected:
void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj); void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj);
void objectrefGet(lua_State *L, u16 id); void objectrefGet(lua_State *L, u16 id);
Mutex m_luastackmutex; RecursiveMutex m_luastackmutex;
std::string m_last_run_mod; std::string m_last_run_mod;
bool m_secure; bool m_secure;
#ifdef SCRIPTAPI_LOCK_DEBUG #ifdef SCRIPTAPI_LOCK_DEBUG

View File

@ -75,7 +75,7 @@ private:
#endif #endif
#define SCRIPTAPI_PRECHECKHEADER \ #define SCRIPTAPI_PRECHECKHEADER \
MutexAutoLock scriptlock(this->m_luastackmutex); \ RecursiveMutexAutoLock scriptlock(this->m_luastackmutex); \
SCRIPTAPI_LOCK_CHECK; \ SCRIPTAPI_LOCK_CHECK; \
realityCheck(); \ realityCheck(); \
lua_State *L = getStack(); \ lua_State *L = getStack(); \

View File

@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#include <condition_variable> #include <condition_variable>
#include "threading/mutex.h" #include "threading/mutex.h"
#include "threading/mutex_auto_lock.h"
#elif defined(_WIN32) #elif defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN

View File

@ -34,7 +34,18 @@ DEALINGS IN THE SOFTWARE.
#define UNUSED(expr) do { (void)(expr); } while (0) #define UNUSED(expr) do { (void)(expr); } while (0)
Mutex::Mutex()
{
init_mutex(false);
}
Mutex::Mutex(bool recursive) Mutex::Mutex(bool recursive)
{
init_mutex(recursive);
}
void Mutex::init_mutex(bool recursive)
{ {
#ifdef _WIN32 #ifdef _WIN32
// Windows critical sections are recursive by default // Windows critical sections are recursive by default
@ -89,5 +100,9 @@ void Mutex::unlock()
#endif #endif
} }
RecursiveMutex::RecursiveMutex()
: Mutex(true)
{}
#endif #endif

View File

@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L && !defined(_WIN32) #if __cplusplus >= 201103L && !defined(_WIN32)
#include <mutex> #include <mutex>
using Mutex = std::mutex; using Mutex = std::mutex;
using RecursiveMutex = std::recursive_mutex;
#else #else
#ifdef _WIN32 #ifdef _WIN32
@ -49,11 +50,14 @@ DEALINGS IN THE SOFTWARE.
class Mutex class Mutex
{ {
public: public:
Mutex(bool recursive=false); Mutex();
~Mutex(); ~Mutex();
void lock(); void lock();
void unlock(); void unlock();
protected:
Mutex(bool recursive);
void init_mutex(bool recursive);
private: private:
#ifdef _WIN32 #ifdef _WIN32
CRITICAL_SECTION mutex; CRITICAL_SECTION mutex;
@ -64,6 +68,14 @@ private:
DISABLE_CLASS_COPY(Mutex); DISABLE_CLASS_COPY(Mutex);
}; };
class RecursiveMutex : public Mutex
{
public:
RecursiveMutex();
DISABLE_CLASS_COPY(RecursiveMutex);
};
#endif // C++11 #endif // C++11
#endif #endif

View File

@ -28,7 +28,8 @@ DEALINGS IN THE SOFTWARE.
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#include <mutex> #include <mutex>
using MutexAutoLock = std::lock_guard<std::mutex>; using MutexAutoLock = std::unique_lock<std::mutex>;
using RecursiveMutexAutoLock = std::unique_lock<std::recursive_mutex>;
#else #else
#include "threading/mutex.h" #include "threading/mutex.h"
@ -44,6 +45,15 @@ private:
Mutex &mutex; Mutex &mutex;
}; };
class RecursiveMutexAutoLock
{
public:
RecursiveMutexAutoLock(RecursiveMutex &m) : mutex(m) { mutex.lock(); }
~RecursiveMutexAutoLock() { mutex.unlock(); }
private:
RecursiveMutex &mutex;
};
#endif #endif
#endif #endif