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"
27 void Mutex::Unlock() {
31 void Mutex::AssertHeld() {
35 CondVar::CondVar(Mutex
* mu
)
39 CondVar::~CondVar() { }
41 void CondVar::Wait() {
45 void CondVar::Signal(){
49 void CondVar::SignalAll() {
53 void InitOnceImpl(OnceType
* once
, void (*initializer
)()) {
54 OnceType state
= ::base::subtle::Acquire_Load(once
);
55 if (state
== ONCE_STATE_DONE
)
58 state
= ::base::subtle::NoBarrier_CompareAndSwap(
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.
66 ::base::subtle::Release_Store(once
, ONCE_STATE_DONE
);
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
));
81 snappy::RawCompress(input
, input_length
, &(*output
)[0], &outlen
);
82 output
->resize(outlen
);
89 bool Snappy_GetUncompressedLength(const char* input_data
,
92 #if defined(USE_SNAPPY)
93 return snappy::GetUncompressedLength(input_data
, input_length
, result
);
99 bool Snappy_Uncompress(const char* input_data
, size_t input_length
,
101 #if defined(USE_SNAPPY)
102 return snappy::RawUncompress(input_data
, input_length
, output
);