小组成员:10215300402-朱维清 & 10222140408 谷杰
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

84 linhas
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. bool Snappy_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. return true;
  45. #else
  46. return false;
  47. #endif
  48. }
  49. bool Snappy_GetUncompressedLength(const char* input, size_t length,
  50. size_t* result) {
  51. #if defined(USE_SNAPPY)
  52. return snappy::GetUncompressedLength(input_data, input_length, result);
  53. #else
  54. return false;
  55. #endif
  56. }
  57. bool Snappy_Uncompress(const char* input_data, size_t input_length,
  58. char* output) {
  59. #if defined(USE_SNAPPY)
  60. return snappy::RawUncompress(input_data, input_length, output);
  61. #else
  62. return false;
  63. #endif
  64. }
  65. }
  66. }