OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "port/port_chromium.h" |
| 6 |
| 7 #include "util/logging.h" |
| 8 |
| 9 #if defined(USE_SNAPPY) |
| 10 # include "third_party/snappy/src/snappy.h" |
| 11 #endif |
| 12 |
| 13 namespace leveldb { |
| 14 namespace port { |
| 15 |
| 16 Mutex::Mutex() { |
| 17 } |
| 18 |
| 19 Mutex::~Mutex() { |
| 20 } |
| 21 |
| 22 void Mutex::Lock() { |
| 23 mu_.Acquire(); |
| 24 } |
| 25 |
| 26 void Mutex::Unlock() { |
| 27 mu_.Release(); |
| 28 } |
| 29 |
| 30 void Mutex::AssertHeld() { |
| 31 mu_.AssertAcquired(); |
| 32 } |
| 33 |
| 34 CondVar::CondVar(Mutex* mu) |
| 35 : cv_(&mu->mu_) { |
| 36 } |
| 37 |
| 38 CondVar::~CondVar() { } |
| 39 |
| 40 void CondVar::Wait() { |
| 41 cv_.Wait(); |
| 42 } |
| 43 |
| 44 void CondVar::Signal(){ |
| 45 cv_.Signal(); |
| 46 } |
| 47 |
| 48 void CondVar::SignalAll() { |
| 49 cv_.Broadcast(); |
| 50 } |
| 51 |
| 52 bool Snappy_Compress(const char* input, size_t input_length, |
| 53 std::string* output) { |
| 54 #if defined(USE_SNAPPY) |
| 55 output->resize(snappy::MaxCompressedLength(input_length)); |
| 56 size_t outlen; |
| 57 snappy::RawCompress(input, input_length, &(*output)[0], &outlen); |
| 58 output->resize(outlen); |
| 59 return true; |
| 60 #else |
| 61 return false; |
| 62 #endif |
| 63 } |
| 64 |
| 65 bool Snappy_GetUncompressedLength(const char* input, size_t length, |
| 66 size_t* result) { |
| 67 #if defined(USE_SNAPPY) |
| 68 return snappy::GetUncompressedLength(input_data, input_length, result); |
| 69 #else |
| 70 return false; |
| 71 #endif |
| 72 } |
| 73 |
| 74 bool Snappy_Uncompress(const char* input_data, size_t input_length, |
| 75 char* output) { |
| 76 #if defined(USE_SNAPPY) |
| 77 return snappy::RawUncompress(input_data, input_length, output); |
| 78 #else |
| 79 return false; |
| 80 #endif |
| 81 } |
| 82 |
| 83 } |
| 84 } |
OLD | NEW |