提供基本的ttl测试用例
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.6 KiB

  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. //
  5. // See port_example.h for documentation for the following types/functions.
  6. #ifndef STORAGE_LEVELDB_PORT_PORT_POSIX_H_
  7. #define STORAGE_LEVELDB_PORT_PORT_POSIX_H_
  8. #undef PLATFORM_IS_LITTLE_ENDIAN
  9. #if defined(OS_MACOSX)
  10. #include <machine/endian.h>
  11. #if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER)
  12. #define PLATFORM_IS_LITTLE_ENDIAN \
  13. (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
  14. #endif
  15. #elif defined(OS_SOLARIS)
  16. #include <sys/isa_defs.h>
  17. #ifdef _LITTLE_ENDIAN
  18. #define PLATFORM_IS_LITTLE_ENDIAN true
  19. #else
  20. #define PLATFORM_IS_LITTLE_ENDIAN false
  21. #endif
  22. #elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
  23. defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID)
  24. #include <sys/types.h>
  25. #include <sys/endian.h>
  26. #else
  27. #include <endian.h>
  28. #endif
  29. #include <pthread.h>
  30. #ifdef SNAPPY
  31. #include <snappy.h>
  32. #endif
  33. #include <stdint.h>
  34. #include <string>
  35. #include "port/atomic_pointer.h"
  36. #ifndef PLATFORM_IS_LITTLE_ENDIAN
  37. #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
  38. #endif
  39. #if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
  40. defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) ||\
  41. defined(OS_ANDROID)
  42. // Use fread/fwrite/fflush on platforms without _unlocked variants
  43. #define fread_unlocked fread
  44. #define fwrite_unlocked fwrite
  45. #define fflush_unlocked fflush
  46. #endif
  47. #if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\
  48. defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
  49. // Use fsync() on platforms without fdatasync()
  50. #define fdatasync fsync
  51. #endif
  52. #if defined(OS_ANDROID) && __ANDROID_API__ < 9
  53. // fdatasync() was only introduced in API level 9 on Android. Use fsync()
  54. // when targetting older platforms.
  55. #define fdatasync fsync
  56. #endif
  57. namespace leveldb {
  58. namespace port {
  59. static const bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN;
  60. #undef PLATFORM_IS_LITTLE_ENDIAN
  61. class CondVar;
  62. class Mutex {
  63. public:
  64. Mutex();
  65. ~Mutex();
  66. void Lock();
  67. void Unlock();
  68. void AssertHeld() { }
  69. private:
  70. friend class CondVar;
  71. pthread_mutex_t mu_;
  72. // No copying
  73. Mutex(const Mutex&);
  74. void operator=(const Mutex&);
  75. };
  76. class CondVar {
  77. public:
  78. explicit CondVar(Mutex* mu);
  79. ~CondVar();
  80. void Wait();
  81. void Signal();
  82. void SignalAll();
  83. private:
  84. pthread_cond_t cv_;
  85. Mutex* mu_;
  86. };
  87. typedef pthread_once_t OnceType;
  88. #define LEVELDB_ONCE_INIT PTHREAD_ONCE_INIT
  89. extern void InitOnce(OnceType* once, void (*initializer)());
  90. inline bool Snappy_Compress(const char* input, size_t length,
  91. ::std::string* output) {
  92. #ifdef SNAPPY
  93. output->resize(snappy::MaxCompressedLength(length));
  94. size_t outlen;
  95. snappy::RawCompress(input, length, &(*output)[0], &outlen);
  96. output->resize(outlen);
  97. return true;
  98. #endif
  99. return false;
  100. }
  101. inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
  102. size_t* result) {
  103. #ifdef SNAPPY
  104. return snappy::GetUncompressedLength(input, length, result);
  105. #else
  106. return false;
  107. #endif
  108. }
  109. inline bool Snappy_Uncompress(const char* input, size_t length,
  110. char* output) {
  111. #ifdef SNAPPY
  112. return snappy::RawUncompress(input, length, output);
  113. #else
  114. return false;
  115. #endif
  116. }
  117. inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
  118. return false;
  119. }
  120. } // namespace port
  121. } // namespace leveldb
  122. #endif // STORAGE_LEVELDB_PORT_PORT_POSIX_H_