作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.5 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_Uncompress(const char* input_data, size_t input_length,
  50. std::string* output) {
  51. #if defined(USE_SNAPPY)
  52. size_t ulength;
  53. if (!snappy::GetUncompressedLength(input_data, input_length, &ulength)) {
  54. return false;
  55. }
  56. output->resize(ulength);
  57. return snappy::RawUncompress(input_data, input_length, &(*output)[0]);
  58. #else
  59. return false;
  60. #endif
  61. }
  62. }
  63. }