作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

80 rader
1.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. #include "port/port_chromium.h"
  5. #include "util/logging.h"
  6. #if defined(USE_SNAPPY)
  7. # include "third_party/snappy/src/snappy.h"
  8. #endif
  9. namespace leveldb {
  10. namespace port {
  11. Mutex::Mutex() {
  12. }
  13. Mutex::~Mutex() {
  14. }
  15. void Mutex::Lock() {
  16. mu_.Acquire();
  17. }
  18. void Mutex::Unlock() {
  19. mu_.Release();
  20. }
  21. void Mutex::AssertHeld() {
  22. mu_.AssertAcquired();
  23. }
  24. CondVar::CondVar(Mutex* mu)
  25. : cv_(&mu->mu_) {
  26. }
  27. CondVar::~CondVar() { }
  28. void CondVar::Wait() {
  29. cv_.Wait();
  30. }
  31. void CondVar::Signal(){
  32. cv_.Signal();
  33. }
  34. void CondVar::SignalAll() {
  35. cv_.Broadcast();
  36. }
  37. void Lightweight_Compress(const char* input, size_t input_length,
  38. std::string* output) {
  39. #if defined(USE_SNAPPY)
  40. output->resize(snappy::MaxCompressedLength(input_length));
  41. size_t outlen;
  42. snappy::RawCompress(input, input_length, &(*output)[0], &outlen);
  43. output->resize(outlen);
  44. #else
  45. output->assign(input, input_length);
  46. #endif
  47. }
  48. bool Lightweight_Uncompress(const char* input_data, size_t input_length,
  49. std::string* output) {
  50. #if defined(USE_SNAPPY)
  51. size_t ulength;
  52. if (!snappy::GetUncompressedLength(input_data, input_length, &ulength)) {
  53. return false;
  54. }
  55. output->resize(ulength);
  56. return snappy::RawUncompress(input_data, input_length, &(*output)[0]);
  57. #else
  58. output->assign(input_data, input_length);
  59. return true;
  60. #endif
  61. }
  62. }
  63. }