小组成员:姚凯文(kevinyao0901),姜嘉琪
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.

245 lines
7.2 KiB

Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 years ago
Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 years ago
Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 years ago
Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 years ago
Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
10 years ago
  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. // AtomicPointer provides storage for a lock-free pointer.
  5. // Platform-dependent implementation of AtomicPointer:
  6. // - If the platform provides a cheap barrier, we use it with raw pointers
  7. // - If <atomic> is present (on newer versions of gcc, it is), we use
  8. // a <atomic>-based AtomicPointer. However we prefer the memory
  9. // barrier based version, because at least on a gcc 4.4 32-bit build
  10. // on linux, we have encountered a buggy <atomic> implementation.
  11. // Also, some <atomic> implementations are much slower than a memory-barrier
  12. // based implementation (~16ns for <atomic> based acquire-load vs. ~1ns for
  13. // a barrier based acquire-load).
  14. // This code is based on atomicops-internals-* in Google's perftools:
  15. // http://code.google.com/p/google-perftools/source/browse/#svn%2Ftrunk%2Fsrc%2Fbase
  16. #ifndef PORT_ATOMIC_POINTER_H_
  17. #define PORT_ATOMIC_POINTER_H_
  18. #include <stdint.h>
  19. #ifdef LEVELDB_ATOMIC_PRESENT
  20. #include <atomic>
  21. #elif defined(__APPLE__)
  22. #include <libkern/OSAtomic.h>
  23. #endif
  24. #ifdef OS_WIN
  25. #include <windows.h>
  26. #endif
  27. #if defined(_M_X64) || defined(__x86_64__)
  28. #define ARCH_CPU_X86_FAMILY 1
  29. #elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
  30. #define ARCH_CPU_X86_FAMILY 1
  31. #elif defined(__ARMEL__)
  32. #define ARCH_CPU_ARM_FAMILY 1
  33. #elif defined(__aarch64__)
  34. #define ARCH_CPU_ARM64_FAMILY 1
  35. #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
  36. #define ARCH_CPU_PPC_FAMILY 1
  37. #elif defined(__mips__)
  38. #define ARCH_CPU_MIPS_FAMILY 1
  39. #endif
  40. namespace leveldb {
  41. namespace port {
  42. // Define MemoryBarrier() if available
  43. // Windows on x86
  44. #if defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
  45. // windows.h already provides a MemoryBarrier(void) macro
  46. // http://msdn.microsoft.com/en-us/library/ms684208(v=vs.85).aspx
  47. #define LEVELDB_HAVE_MEMORY_BARRIER
  48. // Mac OS
  49. #elif defined(__APPLE__)
  50. inline void MemoryBarrier() {
  51. #if defined(LEVELDB_ATOMIC_PRESENT)
  52. std::atomic_thread_fence(std::memory_order_seq_cst);
  53. #else
  54. OSMemoryBarrier();
  55. #endif // defined(LEVELDB_ATOMIC_PRESENT)
  56. }
  57. #define LEVELDB_HAVE_MEMORY_BARRIER
  58. // Gcc on x86
  59. #elif defined(ARCH_CPU_X86_FAMILY) && defined(__GNUC__)
  60. inline void MemoryBarrier() {
  61. // See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
  62. // this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
  63. __asm__ __volatile__("" : : : "memory");
  64. }
  65. #define LEVELDB_HAVE_MEMORY_BARRIER
  66. // Sun Studio
  67. #elif defined(ARCH_CPU_X86_FAMILY) && defined(__SUNPRO_CC)
  68. inline void MemoryBarrier() {
  69. // See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
  70. // this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
  71. asm volatile("" : : : "memory");
  72. }
  73. #define LEVELDB_HAVE_MEMORY_BARRIER
  74. // ARM Linux
  75. #elif defined(ARCH_CPU_ARM_FAMILY) && defined(__linux__)
  76. typedef void (*LinuxKernelMemoryBarrierFunc)(void);
  77. // The Linux ARM kernel provides a highly optimized device-specific memory
  78. // barrier function at a fixed memory address that is mapped in every
  79. // user-level process.
  80. //
  81. // This beats using CPU-specific instructions which are, on single-core
  82. // devices, un-necessary and very costly (e.g. ARMv7-A "dmb" takes more
  83. // than 180ns on a Cortex-A8 like the one on a Nexus One). Benchmarking
  84. // shows that the extra function call cost is completely negligible on
  85. // multi-core devices.
  86. //
  87. inline void MemoryBarrier() {
  88. (*(LinuxKernelMemoryBarrierFunc)0xffff0fa0)();
  89. }
  90. #define LEVELDB_HAVE_MEMORY_BARRIER
  91. // ARM64
  92. #elif defined(ARCH_CPU_ARM64_FAMILY)
  93. inline void MemoryBarrier() {
  94. asm volatile("dmb sy" : : : "memory");
  95. }
  96. #define LEVELDB_HAVE_MEMORY_BARRIER
  97. // PPC
  98. #elif defined(ARCH_CPU_PPC_FAMILY) && defined(__GNUC__)
  99. inline void MemoryBarrier() {
  100. // TODO for some powerpc expert: is there a cheaper suitable variant?
  101. // Perhaps by having separate barriers for acquire and release ops.
  102. asm volatile("sync" : : : "memory");
  103. }
  104. #define LEVELDB_HAVE_MEMORY_BARRIER
  105. // MIPS
  106. #elif defined(ARCH_CPU_MIPS_FAMILY) && defined(__GNUC__)
  107. inline void MemoryBarrier() {
  108. __asm__ __volatile__("sync" : : : "memory");
  109. }
  110. #define LEVELDB_HAVE_MEMORY_BARRIER
  111. #endif
  112. // AtomicPointer built using platform-specific MemoryBarrier()
  113. #if defined(LEVELDB_HAVE_MEMORY_BARRIER)
  114. class AtomicPointer {
  115. private:
  116. void* rep_;
  117. public:
  118. AtomicPointer() { }
  119. explicit AtomicPointer(void* p) : rep_(p) {}
  120. inline void* NoBarrier_Load() const { return rep_; }
  121. inline void NoBarrier_Store(void* v) { rep_ = v; }
  122. inline void* Acquire_Load() const {
  123. void* result = rep_;
  124. MemoryBarrier();
  125. return result;
  126. }
  127. inline void Release_Store(void* v) {
  128. MemoryBarrier();
  129. rep_ = v;
  130. }
  131. };
  132. // AtomicPointer based on <cstdatomic>
  133. #elif defined(LEVELDB_ATOMIC_PRESENT)
  134. class AtomicPointer {
  135. private:
  136. std::atomic<void*> rep_;
  137. public:
  138. AtomicPointer() { }
  139. explicit AtomicPointer(void* v) : rep_(v) { }
  140. inline void* Acquire_Load() const {
  141. return rep_.load(std::memory_order_acquire);
  142. }
  143. inline void Release_Store(void* v) {
  144. rep_.store(v, std::memory_order_release);
  145. }
  146. inline void* NoBarrier_Load() const {
  147. return rep_.load(std::memory_order_relaxed);
  148. }
  149. inline void NoBarrier_Store(void* v) {
  150. rep_.store(v, std::memory_order_relaxed);
  151. }
  152. };
  153. // Atomic pointer based on sparc memory barriers
  154. #elif defined(__sparcv9) && defined(__GNUC__)
  155. class AtomicPointer {
  156. private:
  157. void* rep_;
  158. public:
  159. AtomicPointer() { }
  160. explicit AtomicPointer(void* v) : rep_(v) { }
  161. inline void* Acquire_Load() const {
  162. void* val;
  163. __asm__ __volatile__ (
  164. "ldx [%[rep_]], %[val] \n\t"
  165. "membar #LoadLoad|#LoadStore \n\t"
  166. : [val] "=r" (val)
  167. : [rep_] "r" (&rep_)
  168. : "memory");
  169. return val;
  170. }
  171. inline void Release_Store(void* v) {
  172. __asm__ __volatile__ (
  173. "membar #LoadStore|#StoreStore \n\t"
  174. "stx %[v], [%[rep_]] \n\t"
  175. :
  176. : [rep_] "r" (&rep_), [v] "r" (v)
  177. : "memory");
  178. }
  179. inline void* NoBarrier_Load() const { return rep_; }
  180. inline void NoBarrier_Store(void* v) { rep_ = v; }
  181. };
  182. // Atomic pointer based on ia64 acq/rel
  183. #elif defined(__ia64) && defined(__GNUC__)
  184. class AtomicPointer {
  185. private:
  186. void* rep_;
  187. public:
  188. AtomicPointer() { }
  189. explicit AtomicPointer(void* v) : rep_(v) { }
  190. inline void* Acquire_Load() const {
  191. void* val ;
  192. __asm__ __volatile__ (
  193. "ld8.acq %[val] = [%[rep_]] \n\t"
  194. : [val] "=r" (val)
  195. : [rep_] "r" (&rep_)
  196. : "memory"
  197. );
  198. return val;
  199. }
  200. inline void Release_Store(void* v) {
  201. __asm__ __volatile__ (
  202. "st8.rel [%[rep_]] = %[v] \n\t"
  203. :
  204. : [rep_] "r" (&rep_), [v] "r" (v)
  205. : "memory"
  206. );
  207. }
  208. inline void* NoBarrier_Load() const { return rep_; }
  209. inline void NoBarrier_Store(void* v) { rep_ = v; }
  210. };
  211. // We have neither MemoryBarrier(), nor <atomic>
  212. #else
  213. #error Please implement AtomicPointer for this platform.
  214. #endif
  215. #undef LEVELDB_HAVE_MEMORY_BARRIER
  216. #undef ARCH_CPU_X86_FAMILY
  217. #undef ARCH_CPU_ARM_FAMILY
  218. #undef ARCH_CPU_ARM64_FAMILY
  219. #undef ARCH_CPU_PPC_FAMILY
  220. } // namespace port
  221. } // namespace leveldb
  222. #endif // PORT_ATOMIC_POINTER_H_