作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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