From b727e2a67ac10c03f98cb80bdaf34b2a008fedf5 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 23 Aug 2019 12:34:45 -0700 Subject: [PATCH] More opt stuff --- node/Hashtable.hpp | 14 +++++++------- node/Mutex.hpp | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/node/Hashtable.hpp b/node/Hashtable.hpp index 8bb3e3f7..909232a6 100644 --- a/node/Hashtable.hpp +++ b/node/Hashtable.hpp @@ -370,14 +370,14 @@ public: private: template - 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() { diff --git a/node/Mutex.hpp b/node/Mutex.hpp index 25b06f4f..50858687 100644 --- a/node/Mutex.hpp +++ b/node/Mutex.hpp @@ -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(this)->nextTicket),1); while (nowServing != myTicket) { @@ -45,7 +45,7 @@ public: } } - inline void unlock() const { ++(const_cast(this)->nowServing); } + ZT_ALWAYS_INLINE void unlock() const { ++(const_cast(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(&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(&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 (this))->_mh)); } - inline void unlock() const + ZT_ALWAYS_INLINE void unlock() const { pthread_mutex_unlock(&((const_cast (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(&m)) { _m->lock(); } - inline ~Lock() + ZT_ALWAYS_INLINE ~Lock() { _m->unlock(); }