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 "third_party/snappy/src/snappy.h"
9 #include "util/logging.h"
24 void Mutex::Unlock() {
28 void Mutex::AssertHeld() {
32 CondVar::CondVar(Mutex
* mu
)
36 CondVar::~CondVar() { }
38 void CondVar::Wait() {
42 void CondVar::Signal(){
46 void CondVar::SignalAll() {
50 void InitOnceImpl(OnceType
* once
, void (*initializer
)()) {
51 OnceType state
= base::subtle::Acquire_Load(once
);
52 if (state
== ONCE_STATE_DONE
)
55 state
= base::subtle::NoBarrier_CompareAndSwap(once
, ONCE_STATE_UNINITIALIZED
,
56 ONCE_STATE_EXECUTING_CLOSURE
);
58 if (state
== ONCE_STATE_UNINITIALIZED
) {
59 // We are the first thread, we have to call the closure.
61 base::subtle::Release_Store(once
, ONCE_STATE_DONE
);
63 // Another thread is running the closure, wait until completion.
64 while (state
== ONCE_STATE_EXECUTING_CLOSURE
) {
65 base::PlatformThread::YieldCurrentThread();
66 state
= base::subtle::Acquire_Load(once
);
71 bool Snappy_Compress(const char* input
,
73 std::string
* output
) {
74 output
->resize(snappy::MaxCompressedLength(input_length
));
76 snappy::RawCompress(input
, input_length
, &(*output
)[0], &outlen
);
77 output
->resize(outlen
);
81 bool Snappy_GetUncompressedLength(const char* input_data
,
84 return snappy::GetUncompressedLength(input_data
, input_length
, result
);
87 bool Snappy_Uncompress(const char* input_data
,
90 return snappy::RawUncompress(input_data
, input_length
, output
);
94 } // namespace leveldb