Adam Ierymenko 6 years ago
parent
commit
f12370c348
4 changed files with 85 additions and 85 deletions
  1. 31 31
      node/Address.hpp
  2. 4 4
      node/AtomicCounter.hpp
  3. 30 30
      node/MAC.hpp
  4. 20 20
      node/SharedPtr.hpp

+ 31 - 31
node/Address.hpp

@@ -33,24 +33,24 @@ namespace ZeroTier {
 class Address
 {
 public:
-	inline Address() : _a(0) {}
-	inline Address(const Address &a) : _a(a._a) {}
-	inline Address(uint64_t a) : _a(a & 0xffffffffffULL) {}
+	ZT_ALWAYS_INLINE Address() : _a(0) {}
+	ZT_ALWAYS_INLINE Address(const Address &a) : _a(a._a) {}
+	ZT_ALWAYS_INLINE Address(uint64_t a) : _a(a & 0xffffffffffULL) {}
 
 	/**
 	 * @param bits Raw address -- 5 bytes, big-endian byte order
 	 * @param len Length of array
 	 */
-	inline Address(const void *bits,unsigned int len) { setTo(bits,len); }
+	ZT_ALWAYS_INLINE Address(const void *bits,unsigned int len) { setTo(bits,len); }
 
-	inline Address &operator=(const Address &a) { _a = a._a; return *this; }
-	inline Address &operator=(const uint64_t a) { _a = (a & 0xffffffffffULL); return *this; }
+	ZT_ALWAYS_INLINE Address &operator=(const Address &a) { _a = a._a; return *this; }
+	ZT_ALWAYS_INLINE Address &operator=(const uint64_t a) { _a = (a & 0xffffffffffULL); return *this; }
 
 	/**
 	 * @param bits Raw address -- 5 bytes, big-endian byte order
 	 * @param len Length of array
 	 */
-	inline void setTo(const void *bits,const unsigned int len)
+	ZT_ALWAYS_INLINE void setTo(const void *bits,const unsigned int len)
 	{
 		if (len < ZT_ADDRESS_LENGTH) {
 			_a = 0;
@@ -69,7 +69,7 @@ public:
 	 * @param bits Buffer to hold 5-byte address in big-endian byte order
 	 * @param len Length of array
 	 */
-	inline void copyTo(void *const bits,const unsigned int len) const
+	ZT_ALWAYS_INLINE void copyTo(void *const bits,const unsigned int len) const
 	{
 		if (len < ZT_ADDRESS_LENGTH)
 			return;
@@ -87,7 +87,7 @@ public:
 	 * @param b Buffer to append to
 	 */
 	template<unsigned int C>
-	inline void appendTo(Buffer<C> &b) const
+	ZT_ALWAYS_INLINE void appendTo(Buffer<C> &b) const
 	{
 		unsigned char *p = (unsigned char *)b.appendField(ZT_ADDRESS_LENGTH);
 		*(p++) = (unsigned char)((_a >> 32) & 0xff);
@@ -100,22 +100,22 @@ public:
 	/**
 	 * @return Integer containing address (0 to 2^40)
 	 */
-	inline uint64_t toInt() const { return _a; }
+	ZT_ALWAYS_INLINE uint64_t toInt() const { return _a; }
 
 	/**
 	 * @return Hash code for use with Hashtable
 	 */
-	inline unsigned long hashCode() const { return (unsigned long)_a; }
+	ZT_ALWAYS_INLINE unsigned long hashCode() const { return (unsigned long)_a; }
 
 	/**
 	 * @return Hexadecimal string
 	 */
-	inline char *toString(char buf[11]) const { return Utils::hex10(_a,buf); }
+	ZT_ALWAYS_INLINE char *toString(char buf[11]) const { return Utils::hex10(_a,buf); }
 
 	/**
 	 * @return True if this address is not zero
 	 */
-	inline operator bool() const { return (_a != 0); }
+	ZT_ALWAYS_INLINE operator bool() const { return (_a != 0); }
 
 	/**
 	 * Check if this address is reserved
@@ -126,29 +126,29 @@ public:
 	 *
 	 * @return True if address is reserved and may not be used
 	 */
-	inline bool isReserved() const { return ((!_a)||((_a >> 32) == ZT_ADDRESS_RESERVED_PREFIX)); }
+	ZT_ALWAYS_INLINE bool isReserved() const { return ((!_a)||((_a >> 32) == ZT_ADDRESS_RESERVED_PREFIX)); }
 
 	/**
 	 * @param i Value from 0 to 4 (inclusive)
 	 * @return Byte at said position (address interpreted in big-endian order)
 	 */
-	inline uint8_t operator[](unsigned int i) const { return (uint8_t)(_a >> (32 - (i * 8))); }
-
-	inline void zero() { _a = 0; }
-
-	inline bool operator==(const uint64_t &a) const { return (_a == (a & 0xffffffffffULL)); }
-	inline bool operator!=(const uint64_t &a) const { return (_a != (a & 0xffffffffffULL)); }
-	inline bool operator>(const uint64_t &a) const { return (_a > (a & 0xffffffffffULL)); }
-	inline bool operator<(const uint64_t &a) const { return (_a < (a & 0xffffffffffULL)); }
-	inline bool operator>=(const uint64_t &a) const { return (_a >= (a & 0xffffffffffULL)); }
-	inline bool operator<=(const uint64_t &a) const { return (_a <= (a & 0xffffffffffULL)); }
-
-	inline bool operator==(const Address &a) const { return (_a == a._a); }
-	inline bool operator!=(const Address &a) const { return (_a != a._a); }
-	inline bool operator>(const Address &a) const { return (_a > a._a); }
-	inline bool operator<(const Address &a) const { return (_a < a._a); }
-	inline bool operator>=(const Address &a) const { return (_a >= a._a); }
-	inline bool operator<=(const Address &a) const { return (_a <= a._a); }
+	ZT_ALWAYS_INLINE uint8_t operator[](unsigned int i) const { return (uint8_t)(_a >> (32 - (i * 8))); }
+
+	ZT_ALWAYS_INLINE void zero() { _a = 0; }
+
+	ZT_ALWAYS_INLINE bool operator==(const uint64_t &a) const { return (_a == (a & 0xffffffffffULL)); }
+	ZT_ALWAYS_INLINE bool operator!=(const uint64_t &a) const { return (_a != (a & 0xffffffffffULL)); }
+	ZT_ALWAYS_INLINE bool operator>(const uint64_t &a) const { return (_a > (a & 0xffffffffffULL)); }
+	ZT_ALWAYS_INLINE bool operator<(const uint64_t &a) const { return (_a < (a & 0xffffffffffULL)); }
+	ZT_ALWAYS_INLINE bool operator>=(const uint64_t &a) const { return (_a >= (a & 0xffffffffffULL)); }
+	ZT_ALWAYS_INLINE bool operator<=(const uint64_t &a) const { return (_a <= (a & 0xffffffffffULL)); }
+
+	ZT_ALWAYS_INLINE bool operator==(const Address &a) const { return (_a == a._a); }
+	ZT_ALWAYS_INLINE bool operator!=(const Address &a) const { return (_a != a._a); }
+	ZT_ALWAYS_INLINE bool operator>(const Address &a) const { return (_a > a._a); }
+	ZT_ALWAYS_INLINE bool operator<(const Address &a) const { return (_a < a._a); }
+	ZT_ALWAYS_INLINE bool operator>=(const Address &a) const { return (_a >= a._a); }
+	ZT_ALWAYS_INLINE bool operator<=(const Address &a) const { return (_a <= a._a); }
 
 private:
 	uint64_t _a;

+ 4 - 4
node/AtomicCounter.hpp

@@ -28,9 +28,9 @@ namespace ZeroTier {
 class AtomicCounter
 {
 public:
-	inline AtomicCounter() { _v = 0; }
+	ZT_ALWAYS_INLINE AtomicCounter() { _v = 0; }
 
-	inline int load() const
+	ZT_ALWAYS_INLINE int load() const
 	{
 #ifdef __GNUC__
 		return __sync_or_and_fetch(const_cast<int *>(&_v),0);
@@ -39,7 +39,7 @@ public:
 #endif
 	}
 
-	inline int operator++()
+	ZT_ALWAYS_INLINE int operator++()
 	{
 #ifdef __GNUC__
 		return __sync_add_and_fetch(&_v,1);
@@ -48,7 +48,7 @@ public:
 #endif
 	}
 
-	inline int operator--()
+	ZT_ALWAYS_INLINE int operator--()
 	{
 #ifdef __GNUC__
 		return __sync_sub_and_fetch(&_v,1);

+ 30 - 30
node/MAC.hpp

@@ -31,40 +31,40 @@ namespace ZeroTier {
 class MAC
 {
 public:
-	inline MAC() : _m(0ULL) {}
-	inline MAC(const MAC &m) : _m(m._m) {}
+	ZT_ALWAYS_INLINE MAC() : _m(0ULL) {}
+	ZT_ALWAYS_INLINE MAC(const MAC &m) : _m(m._m) {}
 
-	inline MAC(const unsigned char a,const unsigned char b,const unsigned char c,const unsigned char d,const unsigned char e,const unsigned char f) :
+	ZT_ALWAYS_INLINE MAC(const unsigned char a,const unsigned char b,const unsigned char c,const unsigned char d,const unsigned char e,const unsigned char f) :
 		_m( ((((uint64_t)a) & 0xffULL) << 40) |
 		    ((((uint64_t)b) & 0xffULL) << 32) |
 		    ((((uint64_t)c) & 0xffULL) << 24) |
 		    ((((uint64_t)d) & 0xffULL) << 16) |
 		    ((((uint64_t)e) & 0xffULL) << 8) |
 		    (((uint64_t)f) & 0xffULL) ) {}
-	inline MAC(const void *bits,unsigned int len) { setTo(bits,len); }
-	inline MAC(const Address &ztaddr,uint64_t nwid) { fromAddress(ztaddr,nwid); }
-	inline MAC(const uint64_t m) : _m(m & 0xffffffffffffULL) {}
+				ZT_ALWAYS_INLINE MAC(const void *bits,unsigned int len) { setTo(bits,len); }
+				ZT_ALWAYS_INLINE MAC(const Address &ztaddr,uint64_t nwid) { fromAddress(ztaddr,nwid); }
+	ZT_ALWAYS_INLINE MAC(const uint64_t m) : _m(m & 0xffffffffffffULL) {}
 
 	/**
 	 * @return MAC in 64-bit integer
 	 */
-	inline uint64_t toInt() const { return _m; }
+	ZT_ALWAYS_INLINE uint64_t toInt() const { return _m; }
 
 	/**
 	 * Set MAC to zero
 	 */
-	inline void zero() { _m = 0ULL; }
+	ZT_ALWAYS_INLINE void zero() { _m = 0ULL; }
 
 	/**
 	 * @return True if MAC is non-zero
 	 */
-	inline operator bool() const { return (_m != 0ULL); }
+	ZT_ALWAYS_INLINE operator bool() const { return (_m != 0ULL); }
 
 	/**
 	 * @param bits Raw MAC in big-endian byte order
 	 * @param len Length, must be >= 6 or result is zero
 	 */
-	inline void setTo(const void *bits,unsigned int len)
+	ZT_ALWAYS_INLINE void setTo(const void *bits,unsigned int len)
 	{
 		if (len < 6) {
 			_m = 0ULL;
@@ -83,7 +83,7 @@ public:
 	 * @param buf Destination buffer for MAC in big-endian byte order
 	 * @param len Length of buffer, must be >= 6 or nothing is copied
 	 */
-	inline void copyTo(void *buf,unsigned int len) const
+	ZT_ALWAYS_INLINE void copyTo(void *buf,unsigned int len) const
 	{
 		if (len < 6)
 			return;
@@ -102,7 +102,7 @@ public:
 	 * @param b Buffer to append to
 	 */
 	template<unsigned int C>
-	inline void appendTo(Buffer<C> &b) const
+	ZT_ALWAYS_INLINE void appendTo(Buffer<C> &b) const
 	{
 		unsigned char *p = (unsigned char *)b.appendField(6);
 		*(p++) = (unsigned char)((_m >> 40) & 0xff);
@@ -116,17 +116,17 @@ public:
 	/**
 	 * @return True if this is broadcast (all 0xff)
 	 */
-	inline bool isBroadcast() const { return (_m == 0xffffffffffffULL); }
+	ZT_ALWAYS_INLINE bool isBroadcast() const { return (_m == 0xffffffffffffULL); }
 
 	/**
 	 * @return True if this is a multicast MAC
 	 */
-	inline bool isMulticast() const { return ((_m & 0x010000000000ULL) != 0ULL); }
+	ZT_ALWAYS_INLINE bool isMulticast() const { return ((_m & 0x010000000000ULL) != 0ULL); }
 
 	/**
 	 * @param True if this is a locally-administered MAC
 	 */
-	inline bool isLocallyAdministered() const { return ((_m & 0x020000000000ULL) != 0ULL); }
+	ZT_ALWAYS_INLINE bool isLocallyAdministered() const { return ((_m & 0x020000000000ULL) != 0ULL); }
 
 	/**
 	 * Set this MAC to a MAC derived from an address and a network ID
@@ -134,7 +134,7 @@ public:
 	 * @param ztaddr ZeroTier address
 	 * @param nwid 64-bit network ID
 	 */
-	inline void fromAddress(const Address &ztaddr,uint64_t nwid)
+	ZT_ALWAYS_INLINE void fromAddress(const Address &ztaddr,uint64_t nwid)
 	{
 		uint64_t m = ((uint64_t)firstOctetForNetwork(nwid)) << 40;
 		m |= ztaddr.toInt(); // a is 40 bits
@@ -153,7 +153,7 @@ public:
 	 *
 	 * @param nwid Network ID
 	 */
-	inline Address toAddress(uint64_t nwid) const
+	ZT_ALWAYS_INLINE Address toAddress(uint64_t nwid) const
 	{
 		uint64_t a = _m & 0xffffffffffULL; // least significant 40 bits of MAC are formed from address
 		a ^= ((nwid >> 8) & 0xff) << 32; // ... XORed with bits 8-48 of the nwid in little-endian byte order, so unmask it
@@ -168,7 +168,7 @@ public:
 	 * @param nwid Network ID
 	 * @return First octet of MAC for this network
 	 */
-	static inline unsigned char firstOctetForNetwork(uint64_t nwid)
+	static ZT_ALWAYS_INLINE unsigned char firstOctetForNetwork(uint64_t nwid)
 	{
 		unsigned char a = ((unsigned char)(nwid & 0xfe) | 0x02); // locally administered, not multicast, from LSB of network ID
 		return ((a == 0x52) ? 0x32 : a); // blacklist 0x52 since it's used by KVM, libvirt, and other popular virtualization engines... seems de-facto standard on Linux
@@ -178,16 +178,16 @@ public:
 	 * @param i Value from 0 to 5 (inclusive)
 	 * @return Byte at said position (address interpreted in big-endian order)
 	 */
-	inline uint8_t operator[](unsigned int i) const { return (uint8_t)(_m >> (40 - (i * 8))); }
+	ZT_ALWAYS_INLINE uint8_t operator[](unsigned int i) const { return (uint8_t)(_m >> (40 - (i * 8))); }
 
 	/**
 	 * @return 6, which is the number of bytes in a MAC, for container compliance
 	 */
-	inline unsigned int size() const { return 6; }
+	ZT_ALWAYS_INLINE unsigned int size() const { return 6; }
 
-	inline unsigned long hashCode() const { return (unsigned long)_m; }
+	ZT_ALWAYS_INLINE unsigned long hashCode() const { return (unsigned long)_m; }
 
-	inline char *toString(char buf[18]) const
+	ZT_ALWAYS_INLINE char *toString(char buf[18]) const
 	{
 		buf[0] = Utils::HEXCHARS[(_m >> 44) & 0xf];
 		buf[1] = Utils::HEXCHARS[(_m >> 40) & 0xf];
@@ -210,23 +210,23 @@ public:
 		return buf;
 	}
 
-	inline MAC &operator=(const MAC &m)
+	ZT_ALWAYS_INLINE MAC &operator=(const MAC &m)
 	{
 		_m = m._m;
 		return *this;
 	}
-	inline MAC &operator=(const uint64_t m)
+	ZT_ALWAYS_INLINE MAC &operator=(const uint64_t m)
 	{
 		_m = m & 0xffffffffffffULL;
 		return *this;
 	}
 
-	inline bool operator==(const MAC &m) const { return (_m == m._m); }
-	inline bool operator!=(const MAC &m) const { return (_m != m._m); }
-	inline bool operator<(const MAC &m) const { return (_m < m._m); }
-	inline bool operator<=(const MAC &m) const { return (_m <= m._m); }
-	inline bool operator>(const MAC &m) const { return (_m > m._m); }
-	inline bool operator>=(const MAC &m) const { return (_m >= m._m); }
+	ZT_ALWAYS_INLINE bool operator==(const MAC &m) const { return (_m == m._m); }
+	ZT_ALWAYS_INLINE bool operator!=(const MAC &m) const { return (_m != m._m); }
+	ZT_ALWAYS_INLINE bool operator<(const MAC &m) const { return (_m < m._m); }
+	ZT_ALWAYS_INLINE bool operator<=(const MAC &m) const { return (_m <= m._m); }
+	ZT_ALWAYS_INLINE bool operator>(const MAC &m) const { return (_m > m._m); }
+	ZT_ALWAYS_INLINE bool operator>=(const MAC &m) const { return (_m >= m._m); }
 
 private:
 	uint64_t _m;

+ 20 - 20
node/SharedPtr.hpp

@@ -30,11 +30,11 @@ template<typename T>
 class SharedPtr
 {
 public:
-	inline SharedPtr() : _ptr((T *)0) {}
-	inline SharedPtr(T *obj) : _ptr(obj) { ++obj->__refCount; }
-	inline SharedPtr(const SharedPtr &sp) : _ptr(sp._getAndInc()) {}
+	ZT_ALWAYS_INLINE SharedPtr() : _ptr((T *)0) {}
+	ZT_ALWAYS_INLINE SharedPtr(T *obj) : _ptr(obj) { ++obj->__refCount; }
+	ZT_ALWAYS_INLINE SharedPtr(const SharedPtr &sp) : _ptr(sp._getAndInc()) {}
 
-	inline ~SharedPtr()
+	ZT_ALWAYS_INLINE ~SharedPtr()
 	{
 		if (_ptr) {
 			if (--_ptr->__refCount <= 0)
@@ -42,7 +42,7 @@ public:
 		}
 	}
 
-	inline SharedPtr &operator=(const SharedPtr &sp)
+	ZT_ALWAYS_INLINE SharedPtr &operator=(const SharedPtr &sp)
 	{
 		if (_ptr != sp._ptr) {
 			T *p = sp._getAndInc();
@@ -63,7 +63,7 @@ public:
 	 *
 	 * @param ptr Naked pointer to assign
 	 */
-	inline void set(T *ptr)
+	ZT_ALWAYS_INLINE void set(T *ptr)
 	{
 		zero();
 		++ptr->__refCount;
@@ -75,26 +75,26 @@ public:
 	 *
 	 * @param with Pointer to swap with
 	 */
-	inline void swap(SharedPtr &with)
+	ZT_ALWAYS_INLINE void swap(SharedPtr &with)
 	{
 		T *tmp = _ptr;
 		_ptr = with._ptr;
 		with._ptr = tmp;
 	}
 
-	inline operator bool() const { return (_ptr != (T *)0); }
-	inline T &operator*() const { return *_ptr; }
-	inline T *operator->() const { return _ptr; }
+	ZT_ALWAYS_INLINE operator bool() const { return (_ptr != (T *)0); }
+	ZT_ALWAYS_INLINE T &operator*() const { return *_ptr; }
+	ZT_ALWAYS_INLINE T *operator->() const { return _ptr; }
 
 	/**
 	 * @return Raw pointer to held object
 	 */
-	inline T *ptr() const { return _ptr; }
+	ZT_ALWAYS_INLINE T *ptr() const { return _ptr; }
 
 	/**
 	 * Set this pointer to NULL
 	 */
-	inline void zero()
+	ZT_ALWAYS_INLINE void zero()
 	{
 		if (_ptr) {
 			if (--_ptr->__refCount <= 0)
@@ -106,22 +106,22 @@ public:
 	/**
 	 * @return Number of references according to this object's ref count or 0 if NULL
 	 */
-	inline int references()
+	ZT_ALWAYS_INLINE int references()
 	{
 		if (_ptr)
 			return _ptr->__refCount.load();
 		return 0;
 	}
 
-	inline bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
-	inline bool operator!=(const SharedPtr &sp) const { return (_ptr != sp._ptr); }
-	inline bool operator>(const SharedPtr &sp) const { return (_ptr > sp._ptr); }
-	inline bool operator<(const SharedPtr &sp) const { return (_ptr < sp._ptr); }
-	inline bool operator>=(const SharedPtr &sp) const { return (_ptr >= sp._ptr); }
-	inline bool operator<=(const SharedPtr &sp) const { return (_ptr <= sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator==(const SharedPtr &sp) const { return (_ptr == sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator!=(const SharedPtr &sp) const { return (_ptr != sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator>(const SharedPtr &sp) const { return (_ptr > sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator<(const SharedPtr &sp) const { return (_ptr < sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator>=(const SharedPtr &sp) const { return (_ptr >= sp._ptr); }
+	ZT_ALWAYS_INLINE bool operator<=(const SharedPtr &sp) const { return (_ptr <= sp._ptr); }
 
 private:
-	inline T *_getAndInc() const
+	ZT_ALWAYS_INLINE T *_getAndInc() const
 	{
 		if (_ptr)
 			++_ptr->__refCount;