| OLD | NEW |
| 1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 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 | 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. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
| 4 | 4 |
| 5 #include "port/port_chromium.h" | 5 #include "port/port_chromium.h" |
| 6 | 6 |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "util/logging.h" | 8 #include "util/logging.h" |
| 9 | 9 |
| 10 #if defined(USE_SNAPPY) | 10 #if defined(USE_SNAPPY) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 void CondVar::Signal(){ | 45 void CondVar::Signal(){ |
| 46 cv_.Signal(); | 46 cv_.Signal(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void CondVar::SignalAll() { | 49 void CondVar::SignalAll() { |
| 50 cv_.Broadcast(); | 50 cv_.Broadcast(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void InitOnceImpl(OnceType* once, void (*initializer)()) { | 53 void InitOnceImpl(OnceType* once, void (*initializer)()) { |
| 54 OnceType state = ::base::subtle::Acquire_Load(once); | 54 OnceType state = base::subtle::Acquire_Load(once); |
| 55 if (state == ONCE_STATE_DONE) | 55 if (state == ONCE_STATE_DONE) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 state = ::base::subtle::NoBarrier_CompareAndSwap( | 58 state = base::subtle::NoBarrier_CompareAndSwap(once, ONCE_STATE_UNINITIALIZED, |
| 59 once, | 59 ONCE_STATE_EXECUTING_CLOSURE); |
| 60 ONCE_STATE_UNINITIALIZED, | |
| 61 ONCE_STATE_EXECUTING_CLOSURE); | |
| 62 | 60 |
| 63 if (state == ONCE_STATE_UNINITIALIZED) { | 61 if (state == ONCE_STATE_UNINITIALIZED) { |
| 64 // We are the first thread, we have to call the closure. | 62 // We are the first thread, we have to call the closure. |
| 65 (*initializer)(); | 63 (*initializer)(); |
| 66 ::base::subtle::Release_Store(once, ONCE_STATE_DONE); | 64 base::subtle::Release_Store(once, ONCE_STATE_DONE); |
| 67 } else { | 65 } else { |
| 68 // Another thread is running the closure, wait until completion. | 66 // Another thread is running the closure, wait until completion. |
| 69 while (state == ONCE_STATE_EXECUTING_CLOSURE) { | 67 while (state == ONCE_STATE_EXECUTING_CLOSURE) { |
| 70 ::base::PlatformThread::YieldCurrentThread(); | 68 base::PlatformThread::YieldCurrentThread(); |
| 71 state = ::base::subtle::Acquire_Load(once); | 69 state = base::subtle::Acquire_Load(once); |
| 72 } | 70 } |
| 73 } | 71 } |
| 74 } | 72 } |
| 75 | 73 |
| 76 bool Snappy_Compress(const char* input, size_t input_length, | 74 bool Snappy_Compress(const char* input, size_t input_length, |
| 77 std::string* output) { | 75 std::string* output) { |
| 78 #if defined(USE_SNAPPY) | 76 #if defined(USE_SNAPPY) |
| 79 output->resize(snappy::MaxCompressedLength(input_length)); | 77 output->resize(snappy::MaxCompressedLength(input_length)); |
| 80 size_t outlen; | 78 size_t outlen; |
| 81 snappy::RawCompress(input, input_length, &(*output)[0], &outlen); | 79 snappy::RawCompress(input, input_length, &(*output)[0], &outlen); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 100 char* output) { | 98 char* output) { |
| 101 #if defined(USE_SNAPPY) | 99 #if defined(USE_SNAPPY) |
| 102 return snappy::RawUncompress(input_data, input_length, output); | 100 return snappy::RawUncompress(input_data, input_length, output); |
| 103 #else | 101 #else |
| 104 return false; | 102 return false; |
| 105 #endif | 103 #endif |
| 106 } | 104 } |
| 107 | 105 |
| 108 } | 106 } |
| 109 } | 107 } |
| OLD | NEW |