10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
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.

223 lines
6.6 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. #endif
  22. #ifdef OS_WIN
  23. #include <windows.h>
  24. #endif
  25. #ifdef OS_MACOSX
  26. #include <libkern/OSAtomic.h>
  27. #endif
  28. #if defined(_M_X64) || defined(__x86_64__)
  29. #define ARCH_CPU_X86_FAMILY 1
  30. #elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
  31. #define ARCH_CPU_X86_FAMILY 1
  32. #elif defined(__ARMEL__)
  33. #define ARCH_CPU_ARM_FAMILY 1
  34. #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
  35. #define ARCH_CPU_PPC_FAMILY 1
  36. #endif
  37. namespace leveldb {
  38. namespace port {
  39. // Define MemoryBarrier() if available
  40. // Windows on x86
  41. #if defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
  42. // windows.h already provides a MemoryBarrier(void) macro
  43. // http://msdn.microsoft.com/en-us/library/ms684208(v=vs.85).aspx
  44. #define LEVELDB_HAVE_MEMORY_BARRIER
  45. // Mac OS
  46. #elif defined(OS_MACOSX)
  47. inline void MemoryBarrier() {
  48. OSMemoryBarrier();
  49. }
  50. #define LEVELDB_HAVE_MEMORY_BARRIER
  51. // Gcc on x86
  52. #elif defined(ARCH_CPU_X86_FAMILY) && defined(__GNUC__)
  53. inline void MemoryBarrier() {
  54. // See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
  55. // this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
  56. __asm__ __volatile__("" : : : "memory");
  57. }
  58. #define LEVELDB_HAVE_MEMORY_BARRIER
  59. // Sun Studio
  60. #elif defined(ARCH_CPU_X86_FAMILY) && defined(__SUNPRO_CC)
  61. inline void MemoryBarrier() {
  62. // See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
  63. // this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
  64. asm volatile("" : : : "memory");
  65. }
  66. #define LEVELDB_HAVE_MEMORY_BARRIER
  67. // ARM Linux
  68. #elif defined(ARCH_CPU_ARM_FAMILY) && defined(__linux__)
  69. typedef void (*LinuxKernelMemoryBarrierFunc)(void);
  70. // The Linux ARM kernel provides a highly optimized device-specific memory
  71. // barrier function at a fixed memory address that is mapped in every
  72. // user-level process.
  73. //
  74. // This beats using CPU-specific instructions which are, on single-core
  75. // devices, un-necessary and very costly (e.g. ARMv7-A "dmb" takes more
  76. // than 180ns on a Cortex-A8 like the one on a Nexus One). Benchmarking
  77. // shows that the extra function call cost is completely negligible on
  78. // multi-core devices.
  79. //
  80. inline void MemoryBarrier() {
  81. (*(LinuxKernelMemoryBarrierFunc)0xffff0fa0)();
  82. }
  83. #define LEVELDB_HAVE_MEMORY_BARRIER
  84. // PPC
  85. #elif defined(ARCH_CPU_PPC_FAMILY) && defined(__GNUC__)
  86. inline void MemoryBarrier() {
  87. // TODO for some powerpc expert: is there a cheaper suitable variant?
  88. // Perhaps by having separate barriers for acquire and release ops.
  89. asm volatile("sync" : : : "memory");
  90. }
  91. #define LEVELDB_HAVE_MEMORY_BARRIER
  92. #endif
  93. // AtomicPointer built using platform-specific MemoryBarrier()
  94. #if defined(LEVELDB_HAVE_MEMORY_BARRIER)
  95. class AtomicPointer {
  96. private:
  97. void* rep_;
  98. public:
  99. AtomicPointer() { }
  100. explicit AtomicPointer(void* p) : rep_(p) {}
  101. inline void* NoBarrier_Load() const { return rep_; }
  102. inline void NoBarrier_Store(void* v) { rep_ = v; }
  103. inline void* Acquire_Load() const {
  104. void* result = rep_;
  105. MemoryBarrier();
  106. return result;
  107. }
  108. inline void Release_Store(void* v) {
  109. MemoryBarrier();
  110. rep_ = v;
  111. }
  112. };
  113. // AtomicPointer based on <cstdatomic>
  114. #elif defined(LEVELDB_ATOMIC_PRESENT)
  115. class AtomicPointer {
  116. private:
  117. std::atomic<void*> rep_;
  118. public:
  119. AtomicPointer() { }
  120. explicit AtomicPointer(void* v) : rep_(v) { }
  121. inline void* Acquire_Load() const {
  122. return rep_.load(std::memory_order_acquire);
  123. }
  124. inline void Release_Store(void* v) {
  125. rep_.store(v, std::memory_order_release);
  126. }
  127. inline void* NoBarrier_Load() const {
  128. return rep_.load(std::memory_order_relaxed);
  129. }
  130. inline void NoBarrier_Store(void* v) {
  131. rep_.store(v, std::memory_order_relaxed);
  132. }
  133. };
  134. // Atomic pointer based on sparc memory barriers
  135. #elif defined(__sparcv9) && defined(__GNUC__)
  136. class AtomicPointer {
  137. private:
  138. void* rep_;
  139. public:
  140. AtomicPointer() { }
  141. explicit AtomicPointer(void* v) : rep_(v) { }
  142. inline void* Acquire_Load() const {
  143. void* val;
  144. __asm__ __volatile__ (
  145. "ldx [%[rep_]], %[val] \n\t"
  146. "membar #LoadLoad|#LoadStore \n\t"
  147. : [val] "=r" (val)
  148. : [rep_] "r" (&rep_)
  149. : "memory");
  150. return val;
  151. }
  152. inline void Release_Store(void* v) {
  153. __asm__ __volatile__ (
  154. "membar #LoadStore|#StoreStore \n\t"
  155. "stx %[v], [%[rep_]] \n\t"
  156. :
  157. : [rep_] "r" (&rep_), [v] "r" (v)
  158. : "memory");
  159. }
  160. inline void* NoBarrier_Load() const { return rep_; }
  161. inline void NoBarrier_Store(void* v) { rep_ = v; }
  162. };
  163. // Atomic pointer based on ia64 acq/rel
  164. #elif defined(__ia64) && defined(__GNUC__)
  165. class AtomicPointer {
  166. private:
  167. void* rep_;
  168. public:
  169. AtomicPointer() { }
  170. explicit AtomicPointer(void* v) : rep_(v) { }
  171. inline void* Acquire_Load() const {
  172. void* val ;
  173. __asm__ __volatile__ (
  174. "ld8.acq %[val] = [%[rep_]] \n\t"
  175. : [val] "=r" (val)
  176. : [rep_] "r" (&rep_)
  177. : "memory"
  178. );
  179. return val;
  180. }
  181. inline void Release_Store(void* v) {
  182. __asm__ __volatile__ (
  183. "st8.rel [%[rep_]] = %[v] \n\t"
  184. :
  185. : [rep_] "r" (&rep_), [v] "r" (v)
  186. : "memory"
  187. );
  188. }
  189. inline void* NoBarrier_Load() const { return rep_; }
  190. inline void NoBarrier_Store(void* v) { rep_ = v; }
  191. };
  192. // We have neither MemoryBarrier(), nor <atomic>
  193. #else
  194. #error Please implement AtomicPointer for this platform.
  195. #endif
  196. #undef LEVELDB_HAVE_MEMORY_BARRIER
  197. #undef ARCH_CPU_X86_FAMILY
  198. #undef ARCH_CPU_ARM_FAMILY
  199. #undef ARCH_CPU_PPC_FAMILY
  200. } // namespace port
  201. } // namespace leveldb
  202. #endif // PORT_ATOMIC_POINTER_H_