作者: 韩晨旭 10225101440 李畅 10225102463
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.

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