ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / third_party / leveldatabase / port / port_chromium.cc
blobef1e93abd17bf405385a96e78a75b07bfbfe27e4
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(once, ONCE_STATE_UNINITIALIZED,
59 ONCE_STATE_EXECUTING_CLOSURE);
61 if (state == ONCE_STATE_UNINITIALIZED) {
62 // We are the first thread, we have to call the closure.
63 (*initializer)();
64 base::subtle::Release_Store(once, ONCE_STATE_DONE);
65 } else {
66 // Another thread is running the closure, wait until completion.
67 while (state == ONCE_STATE_EXECUTING_CLOSURE) {
68 base::PlatformThread::YieldCurrentThread();
69 state = base::subtle::Acquire_Load(once);
74 bool Snappy_Compress(const char* input, size_t input_length,
75 std::string* output) {
76 #if defined(USE_SNAPPY)
77 output->resize(snappy::MaxCompressedLength(input_length));
78 size_t outlen;
79 snappy::RawCompress(input, input_length, &(*output)[0], &outlen);
80 output->resize(outlen);
81 return true;
82 #else
83 return false;
84 #endif
87 bool Snappy_GetUncompressedLength(const char* input_data,
88 size_t input_length,
89 size_t* result) {
90 #if defined(USE_SNAPPY)
91 return snappy::GetUncompressedLength(input_data, input_length, result);
92 #else
93 return false;
94 #endif
97 bool Snappy_Uncompress(const char* input_data, size_t input_length,
98 char* output) {
99 #if defined(USE_SNAPPY)
100 return snappy::RawUncompress(input_data, input_length, output);
101 #else
102 return false;
103 #endif