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 // See port_example.h for documentation for the following types/functions.
7 #ifndef STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
8 #define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
13 #include "base/atomicops.h"
14 #include "base/basictypes.h"
15 #include "base/synchronization/condition_variable.h"
16 #include "base/synchronization/lock.h"
18 // Linux's ThreadIdentifier() needs this.
20 # include <linux/unistd.h>
24 #define snprintf _snprintf
25 typedef SSIZE_T ssize_t
;
31 // Chromium only supports little endian.
32 static const bool kLittleEndian
= true;
46 DISALLOW_COPY_AND_ASSIGN(Mutex
);
51 explicit CondVar(Mutex
* mu
);
58 base::ConditionVariable cv_
;
60 DISALLOW_COPY_AND_ASSIGN(CondVar
);
65 typedef base::subtle::AtomicWord Rep
;
69 explicit AtomicPointer(void* p
) : rep_(reinterpret_cast<Rep
>(p
)) {}
70 inline void* Acquire_Load() const {
71 return reinterpret_cast<void*>(base::subtle::Acquire_Load(&rep_
));
73 inline void Release_Store(void* v
) {
74 base::subtle::Release_Store(&rep_
, reinterpret_cast<Rep
>(v
));
76 inline void* NoBarrier_Load() const {
77 return reinterpret_cast<void*>(base::subtle::NoBarrier_Load(&rep_
));
79 inline void NoBarrier_Store(void* v
) {
80 base::subtle::NoBarrier_Store(&rep_
, reinterpret_cast<Rep
>(v
));
84 // Implementation of OnceType and InitOnce() pair, this is equivalent to
85 // pthread_once_t and pthread_once().
86 typedef base::subtle::Atomic32 OnceType
;
89 ONCE_STATE_UNINITIALIZED
= 0,
90 ONCE_STATE_EXECUTING_CLOSURE
= 1,
94 #define LEVELDB_ONCE_INIT leveldb::port::ONCE_STATE_UNINITIALIZED
97 void InitOnceImpl(OnceType
* once
, void (*initializer
)());
99 static inline void InitOnce(OnceType
* once
, void (*initializer
)()) {
100 if (base::subtle::Acquire_Load(once
) != ONCE_STATE_DONE
)
101 InitOnceImpl(once
, initializer
);
104 bool Snappy_Compress(const char* input
, size_t input_length
,
105 std::string
* output
);
106 bool Snappy_GetUncompressedLength(const char* input
, size_t length
,
108 bool Snappy_Uncompress(const char* input_data
, size_t input_length
,
111 inline bool GetHeapProfile(void (*func
)(void*, const char*, int), void* arg
) {
118 #endif // STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_