mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-23 14:52:24 +00:00
More opt stuff
This commit is contained in:
parent
8e87319925
commit
b727e2a67a
@ -370,14 +370,14 @@ public:
|
||||
|
||||
private:
|
||||
template<typename O>
|
||||
static inline unsigned long _hc(const O &obj) { return (unsigned long)obj.hashCode(); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const O &obj) { return (unsigned long)obj.hashCode(); }
|
||||
|
||||
static inline unsigned long _hc(const uint64_t i) { return (unsigned long)(i ^ (i >> 32)); }
|
||||
static inline unsigned long _hc(const uint32_t i) { return ((unsigned long)i * (unsigned long)0x9e3779b1); }
|
||||
static inline unsigned long _hc(const uint16_t i) { return ((unsigned long)i * (unsigned long)0x9e3779b1); }
|
||||
static inline unsigned long _hc(const int i) { return ((unsigned long)i * (unsigned long)0x9e3379b1); }
|
||||
static inline unsigned long _hc(void *p) { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); }
|
||||
static inline unsigned long _hc(const void *p) { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const uint64_t i) { return (unsigned long)(i ^ (i >> 32)); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const uint32_t i) { return ((unsigned long)i * (unsigned long)0x9e3779b1); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const uint16_t i) { return ((unsigned long)i * (unsigned long)0x9e3779b1); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const int i) { return ((unsigned long)i * (unsigned long)0x9e3379b1); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(void *p) { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); }
|
||||
static ZT_ALWAYS_INLINE unsigned long _hc(const void *p) { return ((unsigned long)((uintptr_t)p) * (unsigned long)0x9e3779b1); }
|
||||
|
||||
inline void _grow()
|
||||
{
|
||||
|
@ -30,13 +30,13 @@ namespace ZeroTier {
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
inline Mutex() :
|
||||
ZT_ALWAYS_INLINE Mutex() :
|
||||
nextTicket(0),
|
||||
nowServing(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline void lock() const
|
||||
ZT_ALWAYS_INLINE void lock() const
|
||||
{
|
||||
const uint16_t myTicket = __sync_fetch_and_add(&(const_cast<Mutex *>(this)->nextTicket),1);
|
||||
while (nowServing != myTicket) {
|
||||
@ -45,7 +45,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
inline void unlock() const { ++(const_cast<Mutex *>(this)->nowServing); }
|
||||
ZT_ALWAYS_INLINE void unlock() const { ++(const_cast<Mutex *>(this)->nowServing); }
|
||||
|
||||
/**
|
||||
* Uses C++ contexts and constructor/destructor to lock/unlock automatically
|
||||
@ -53,9 +53,9 @@ public:
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
inline Lock(Mutex &m) : _m(&m) { m.lock(); }
|
||||
inline Lock(const Mutex &m) : _m(const_cast<Mutex *>(&m)) { _m->lock(); }
|
||||
inline ~Lock() { _m->unlock(); }
|
||||
ZT_ALWAYS_INLINE Lock(Mutex &m) : _m(&m) { m.lock(); }
|
||||
ZT_ALWAYS_INLINE Lock(const Mutex &m) : _m(const_cast<Mutex *>(&m)) { _m->lock(); }
|
||||
ZT_ALWAYS_INLINE ~Lock() { _m->unlock(); }
|
||||
private:
|
||||
Mutex *const _m;
|
||||
};
|
||||
@ -74,22 +74,22 @@ private:
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
inline Mutex()
|
||||
ZT_ALWAYS_INLINE Mutex()
|
||||
{
|
||||
pthread_mutex_init(&_mh,(const pthread_mutexattr_t *)0);
|
||||
}
|
||||
|
||||
inline ~Mutex()
|
||||
ZT_ALWAYS_INLINE ~Mutex()
|
||||
{
|
||||
pthread_mutex_destroy(&_mh);
|
||||
}
|
||||
|
||||
inline void lock() const
|
||||
ZT_ALWAYS_INLINE void lock() const
|
||||
{
|
||||
pthread_mutex_lock(&((const_cast <Mutex *> (this))->_mh));
|
||||
}
|
||||
|
||||
inline void unlock() const
|
||||
ZT_ALWAYS_INLINE void unlock() const
|
||||
{
|
||||
pthread_mutex_unlock(&((const_cast <Mutex *> (this))->_mh));
|
||||
}
|
||||
@ -97,19 +97,19 @@ public:
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
inline Lock(Mutex &m) :
|
||||
ZT_ALWAYS_INLINE Lock(Mutex &m) :
|
||||
_m(&m)
|
||||
{
|
||||
m.lock();
|
||||
}
|
||||
|
||||
inline Lock(const Mutex &m) :
|
||||
ZT_ALWAYS_INLINE Lock(const Mutex &m) :
|
||||
_m(const_cast<Mutex *>(&m))
|
||||
{
|
||||
_m->lock();
|
||||
}
|
||||
|
||||
inline ~Lock()
|
||||
ZT_ALWAYS_INLINE ~Lock()
|
||||
{
|
||||
_m->unlock();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user