小组成员: 曹可心-10223903406 朴祉燕-10224602413
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.

104 lines
2.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_CHROMIUM_H_
  7. #define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
  8. #include <stdint.h>
  9. #include <string>
  10. #include <cstring>
  11. #include "base/atomicops.h"
  12. #include "base/basictypes.h"
  13. #include "base/logging.h"
  14. #include "base/sha1.h"
  15. #include "base/synchronization/condition_variable.h"
  16. #include "base/synchronization/lock.h"
  17. // Linux's ThreadIdentifier() needs this.
  18. #if defined(OS_LINUX)
  19. # include <linux/unistd.h>
  20. #endif
  21. #if defined(OS_WIN)
  22. #define snprintf _snprintf
  23. #define va_copy(a, b) do { (a) = (b); } while (0)
  24. #endif
  25. namespace leveldb {
  26. namespace port {
  27. // Chromium only supports little endian.
  28. static const bool kLittleEndian = true;
  29. class Mutex {
  30. public:
  31. Mutex();
  32. ~Mutex();
  33. void Lock();
  34. void Unlock();
  35. void AssertHeld();
  36. private:
  37. base::Lock mu_;
  38. friend class CondVar;
  39. DISALLOW_COPY_AND_ASSIGN(Mutex);
  40. };
  41. class CondVar {
  42. public:
  43. explicit CondVar(Mutex* mu);
  44. ~CondVar();
  45. void Wait();
  46. void Signal();
  47. void SignalAll();
  48. private:
  49. base::ConditionVariable cv_;
  50. DISALLOW_COPY_AND_ASSIGN(CondVar);
  51. };
  52. class AtomicPointer {
  53. private:
  54. typedef base::subtle::AtomicWord Rep;
  55. Rep rep_;
  56. public:
  57. AtomicPointer() { }
  58. explicit AtomicPointer(void* p) : rep_(reinterpret_cast<Rep>(p)) {}
  59. inline void* Acquire_Load() const {
  60. return reinterpret_cast<void*>(::base::subtle::Acquire_Load(&rep_));
  61. }
  62. inline void Release_Store(void* v) {
  63. ::base::subtle::Release_Store(&rep_, reinterpret_cast<Rep>(v));
  64. }
  65. inline void* NoBarrier_Load() const {
  66. return reinterpret_cast<void*>(::base::subtle::NoBarrier_Load(&rep_));
  67. }
  68. inline void NoBarrier_Store(void* v) {
  69. ::base::subtle::NoBarrier_Store(&rep_, reinterpret_cast<Rep>(v));
  70. }
  71. };
  72. inline void SHA1_Hash(const char* data, size_t len, char* hash_array) {
  73. return ::base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(data),
  74. len,
  75. reinterpret_cast<unsigned char*>(hash_array));
  76. }
  77. bool Snappy_Compress(const char* input, size_t input_length,
  78. std::string* output);
  79. bool Snappy_Uncompress(const char* input_data, size_t input_length,
  80. std::string* output);
  81. inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
  82. return false;
  83. }
  84. }
  85. }
  86. #endif // STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_