Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

99 строки
2.2 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. #include <endian.h>
  9. #include <pthread.h>
  10. #include <stdint.h>
  11. #include <string>
  12. #include <cstdatomic>
  13. #include <cstring>
  14. #include "port/sha1_portable.h"
  15. namespace leveldb {
  16. namespace port {
  17. static const bool kLittleEndian = (__BYTE_ORDER == __LITTLE_ENDIAN);
  18. class CondVar;
  19. class Mutex {
  20. public:
  21. Mutex();
  22. ~Mutex();
  23. void Lock();
  24. void Unlock();
  25. void AssertHeld() { }
  26. private:
  27. friend class CondVar;
  28. pthread_mutex_t mu_;
  29. // No copying
  30. Mutex(const Mutex&);
  31. void operator=(const Mutex&);
  32. };
  33. class CondVar {
  34. public:
  35. explicit CondVar(Mutex* mu);
  36. ~CondVar();
  37. void Wait();
  38. void Signal();
  39. void SignalAll();
  40. private:
  41. pthread_cond_t cv_;
  42. Mutex* mu_;
  43. };
  44. // Storage for a lock-free pointer
  45. class AtomicPointer {
  46. private:
  47. std::atomic<void*> rep_;
  48. public:
  49. AtomicPointer() { }
  50. explicit AtomicPointer(void* v) : rep_(v) { }
  51. inline void* Acquire_Load() const {
  52. return rep_.load(std::memory_order_acquire);
  53. }
  54. inline void Release_Store(void* v) {
  55. rep_.store(v, std::memory_order_release);
  56. }
  57. inline void* NoBarrier_Load() const {
  58. return rep_.load(std::memory_order_relaxed);
  59. }
  60. inline void NoBarrier_Store(void* v) {
  61. rep_.store(v, std::memory_order_relaxed);
  62. }
  63. };
  64. inline void SHA1_Hash(const char* data, size_t len, char* hash_array) {
  65. SHA1_Hash_Portable(data, len, hash_array);
  66. }
  67. // TODO(gabor): Implement actual compress
  68. inline bool Snappy_Compress(const char* input, size_t input_length,
  69. std::string* output) {
  70. return false;
  71. }
  72. // TODO(gabor): Implement actual uncompress
  73. inline bool Snappy_Uncompress(const char* input_data, size_t input_length,
  74. std::string* output) {
  75. return false;
  76. }
  77. inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
  78. return false;
  79. }
  80. }
  81. }
  82. #endif // STORAGE_LEVELDB_PORT_PORT_POSIX_H_