|
@@ -28,7 +28,6 @@
|
|
#define ZT_MUTEX_HPP
|
|
#define ZT_MUTEX_HPP
|
|
|
|
|
|
#include "Constants.hpp"
|
|
#include "Constants.hpp"
|
|
-#include "NonCopyable.hpp"
|
|
|
|
|
|
|
|
#ifdef __UNIX_LIKE__
|
|
#ifdef __UNIX_LIKE__
|
|
|
|
|
|
@@ -41,7 +40,7 @@ namespace ZeroTier {
|
|
#if defined(__GNUC__) && (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64))
|
|
#if defined(__GNUC__) && (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64))
|
|
|
|
|
|
// Inline ticket lock on x64 systems with GCC and CLANG (Mac, Linux) -- this is really fast as long as locking durations are very short
|
|
// Inline ticket lock on x64 systems with GCC and CLANG (Mac, Linux) -- this is really fast as long as locking durations are very short
|
|
-class Mutex : NonCopyable
|
|
|
|
|
|
+class Mutex
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Mutex() :
|
|
Mutex() :
|
|
@@ -67,7 +66,7 @@ public:
|
|
/**
|
|
/**
|
|
* Uses C++ contexts and constructor/destructor to lock/unlock automatically
|
|
* Uses C++ contexts and constructor/destructor to lock/unlock automatically
|
|
*/
|
|
*/
|
|
- class Lock : NonCopyable
|
|
|
|
|
|
+ class Lock
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Lock(Mutex &m) :
|
|
Lock(Mutex &m) :
|
|
@@ -92,6 +91,9 @@ public:
|
|
};
|
|
};
|
|
|
|
|
|
private:
|
|
private:
|
|
|
|
+ Mutex(const Mutex &) {}
|
|
|
|
+ const Mutex &operator=(const Mutex &) { return *this; }
|
|
|
|
+
|
|
uint16_t nextTicket;
|
|
uint16_t nextTicket;
|
|
uint16_t nowServing;
|
|
uint16_t nowServing;
|
|
};
|
|
};
|
|
@@ -99,7 +101,7 @@ private:
|
|
#else
|
|
#else
|
|
|
|
|
|
// libpthread based mutex lock
|
|
// libpthread based mutex lock
|
|
-class Mutex : NonCopyable
|
|
|
|
|
|
+class Mutex
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Mutex()
|
|
Mutex()
|
|
@@ -122,7 +124,7 @@ public:
|
|
pthread_mutex_unlock(&((const_cast <Mutex *> (this))->_mh));
|
|
pthread_mutex_unlock(&((const_cast <Mutex *> (this))->_mh));
|
|
}
|
|
}
|
|
|
|
|
|
- class Lock : NonCopyable
|
|
|
|
|
|
+ class Lock
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Lock(Mutex &m) :
|
|
Lock(Mutex &m) :
|
|
@@ -147,6 +149,9 @@ public:
|
|
};
|
|
};
|
|
|
|
|
|
private:
|
|
private:
|
|
|
|
+ Mutex(const Mutex &) {}
|
|
|
|
+ const Mutex &operator=(const Mutex &) { return *this; }
|
|
|
|
+
|
|
pthread_mutex_t _mh;
|
|
pthread_mutex_t _mh;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -164,7 +169,7 @@ private:
|
|
namespace ZeroTier {
|
|
namespace ZeroTier {
|
|
|
|
|
|
// Windows critical section based lock
|
|
// Windows critical section based lock
|
|
-class Mutex : NonCopyable
|
|
|
|
|
|
+class Mutex
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Mutex()
|
|
Mutex()
|
|
@@ -197,7 +202,7 @@ public:
|
|
(const_cast <Mutex *> (this))->unlock();
|
|
(const_cast <Mutex *> (this))->unlock();
|
|
}
|
|
}
|
|
|
|
|
|
- class Lock : NonCopyable
|
|
|
|
|
|
+ class Lock
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
Lock(Mutex &m) :
|
|
Lock(Mutex &m) :
|
|
@@ -222,6 +227,9 @@ public:
|
|
};
|
|
};
|
|
|
|
|
|
private:
|
|
private:
|
|
|
|
+ Mutex(const Mutex &) {}
|
|
|
|
+ const Mutex &operator=(const Mutex &) { return *this; }
|
|
|
|
+
|
|
CRITICAL_SECTION _cs;
|
|
CRITICAL_SECTION _cs;
|
|
};
|
|
};
|
|
|
|
|