feat fix mutux

This commit is contained in:
tqcq
2024-02-24 10:31:28 +08:00
parent 46976d53f9
commit b1a9a8a17f
8 changed files with 141 additions and 11 deletions

View File

@@ -1,5 +1,30 @@
#include <arpa/inet.h>
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#endif
inline uint16_t
HostToNetwork16(uint16_t n)
{

View File

@@ -13,13 +13,13 @@ enum class RefCountReleaseStatus { kDroppedLastRef, kOtherRefsRemained };
class RefCountInterface {
public:
virtual void AddRef() const = 0;
virtual RefCountReleaseStatus Release() const = 0;
virtual void AddRef() const = 0;
virtual RefCountReleaseStatus Release() const = 0;
protected:
virtual ~RefCountInterface() = default;
virtual ~RefCountInterface() = default;
};
} // namespace sled
}// namespace sled
#endif // REF_COUNT_H
#endif// REF_COUNT_H

View File

@@ -17,13 +17,15 @@ namespace sled {
namespace internal {
template<typename T>
struct HasLockAndUnlock {
template<typename TClass,
decltype(std::declval<TClass>().Lock()) * = nullptr,
decltype(std::declval<TClass>().Unlock()) * = nullptr>
static int Test(T);
template<typename U,
decltype(std::declval<U>().Lock()) * = nullptr,
decltype(std::declval<U>().Unlock()) * = nullptr>
static int Test(int);
template<typename>
static char Test(...);
static constexpr bool value =
static constexpr bool value =
std::is_same<decltype(Test<T>(0)), int>::value;
};
}// namespace internal
@@ -69,6 +71,7 @@ template<typename TLock,
typename std::enable_if<internal::HasLockAndUnlock<TLock>::value,
TLock>::type * = nullptr>
class LockGuard final {
public:
LockGuard(const LockGuard &) = delete;
LockGuard &operator=(const LockGuard &) = delete;

View File

@@ -77,7 +77,10 @@ public:
return ToFractionOr<1000>(fallback_value);
}
constexpr int64_t us_or(int64_t fallback_value) const { return ToValueOr(fallback_value); }
constexpr int64_t us_or(int64_t fallback_value) const
{
return ToValueOr(fallback_value);
}
Timestamp operator+(const TimeDelta delta) const
{