No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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