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.

81 lines
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. # include "snappy-stubs-public.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(input, input_length, &(*output)[0], &outlen);
  44. output->resize(outlen);
  45. #else
  46. output->assign(input, input_length);
  47. #endif
  48. }
  49. bool Lightweight_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. output->assign(input_data, input_length);
  60. return true;
  61. #endif
  62. }
  63. }
  64. }