cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / third_party / leveldatabase / port / port_chromium.cc
blobc76b4ef96154e0e2ad131e3e4af92041f1eae086
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.
5 #include "port/port_chromium.h"
7 #include "base/threading/platform_thread.h"
8 #include "util/logging.h"
10 #if defined(USE_SNAPPY)
11 # include "third_party/snappy/src/snappy.h"
12 #endif
14 namespace leveldb {
15 namespace port {
17 Mutex::Mutex() {
20 Mutex::~Mutex() {
23 void Mutex::Lock() {
24 mu_.Acquire();
27 void Mutex::Unlock() {
28 mu_.Release();
31 void Mutex::AssertHeld() {
32 mu_.AssertAcquired();
35 CondVar::CondVar(Mutex* mu)
36 : cv_(&mu->mu_) {
39 CondVar::~CondVar() { }
41 void CondVar::Wait() {
42 cv_.Wait();
45 void CondVar::Signal(){
46 cv_.Signal();
49 void CondVar::SignalAll() {
50 cv_.Broadcast();
53 void InitOnceImpl(OnceType* once, void (*initializer)()) {
54 OnceType state = ::base::subtle::Acquire_Load(once);
55 if (state == ONCE_STATE_DONE)
56 return;
58 state = ::base::subtle::NoBarrier_CompareAndSwap(
59 once,
60 ONCE_STATE_UNINITIALIZED,
61 ONCE_STATE_EXECUTING_CLOSURE);
63 if (state == ONCE_STATE_UNINITIALIZED) {
64 // We are the first thread, we have to call the closure.
65 (*initializer)();
66 ::base::subtle::Release_Store(once, ONCE_STATE_DONE);
67 } else {
68 // Another thread is running the closure, wait until completion.
69 while (state == ONCE_STATE_EXECUTING_CLOSURE) {
70 ::base::PlatformThread::YieldCurrentThread();
71 state = ::base::subtle::Acquire_Load(once);
76 bool Snappy_Compress(const char* input, size_t input_length,
77 std::string* output) {
78 #if defined(USE_SNAPPY)
79 output->resize(snappy::MaxCompressedLength(input_length));
80 size_t outlen;
81 snappy::RawCompress(input, input_length, &(*output)[0], &outlen);
82 output->resize(outlen);
83 return true;
84 #else
85 return false;
86 #endif
89 bool Snappy_GetUncompressedLength(const char* input_data,
90 size_t input_length,
91 size_t* result) {
92 #if defined(USE_SNAPPY)
93 return snappy::GetUncompressedLength(input_data, input_length, result);
94 #else
95 return false;
96 #endif
99 bool Snappy_Uncompress(const char* input_data, size_t input_length,
100 char* output) {
101 #if defined(USE_SNAPPY)
102 return snappy::RawUncompress(input_data, input_length, output);
103 #else
104 return false;
105 #endif