leveldb-ruby 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/ext/leveldb/extconf.rb +10 -0
- data/ext/leveldb/leveldb.cc +181 -0
- data/leveldb/Makefile +172 -0
- data/leveldb/db/builder.cc +90 -0
- data/leveldb/db/builder.h +36 -0
- data/leveldb/db/corruption_test.cc +354 -0
- data/leveldb/db/db_bench.cc +677 -0
- data/leveldb/db/db_impl.cc +1236 -0
- data/leveldb/db/db_impl.h +180 -0
- data/leveldb/db/db_iter.cc +298 -0
- data/leveldb/db/db_iter.h +26 -0
- data/leveldb/db/db_test.cc +1192 -0
- data/leveldb/db/dbformat.cc +87 -0
- data/leveldb/db/dbformat.h +165 -0
- data/leveldb/db/dbformat_test.cc +112 -0
- data/leveldb/db/filename.cc +135 -0
- data/leveldb/db/filename.h +80 -0
- data/leveldb/db/filename_test.cc +122 -0
- data/leveldb/db/log_format.h +35 -0
- data/leveldb/db/log_reader.cc +254 -0
- data/leveldb/db/log_reader.h +108 -0
- data/leveldb/db/log_test.cc +500 -0
- data/leveldb/db/log_writer.cc +103 -0
- data/leveldb/db/log_writer.h +48 -0
- data/leveldb/db/memtable.cc +108 -0
- data/leveldb/db/memtable.h +85 -0
- data/leveldb/db/repair.cc +384 -0
- data/leveldb/db/skiplist.h +378 -0
- data/leveldb/db/skiplist_test.cc +378 -0
- data/leveldb/db/snapshot.h +66 -0
- data/leveldb/db/table_cache.cc +95 -0
- data/leveldb/db/table_cache.h +50 -0
- data/leveldb/db/version_edit.cc +268 -0
- data/leveldb/db/version_edit.h +106 -0
- data/leveldb/db/version_edit_test.cc +46 -0
- data/leveldb/db/version_set.cc +1060 -0
- data/leveldb/db/version_set.h +306 -0
- data/leveldb/db/write_batch.cc +138 -0
- data/leveldb/db/write_batch_internal.h +45 -0
- data/leveldb/db/write_batch_test.cc +89 -0
- data/leveldb/include/leveldb/cache.h +99 -0
- data/leveldb/include/leveldb/comparator.h +63 -0
- data/leveldb/include/leveldb/db.h +148 -0
- data/leveldb/include/leveldb/env.h +302 -0
- data/leveldb/include/leveldb/iterator.h +100 -0
- data/leveldb/include/leveldb/options.h +198 -0
- data/leveldb/include/leveldb/slice.h +109 -0
- data/leveldb/include/leveldb/status.h +100 -0
- data/leveldb/include/leveldb/table.h +70 -0
- data/leveldb/include/leveldb/table_builder.h +91 -0
- data/leveldb/include/leveldb/write_batch.h +64 -0
- data/leveldb/port/port.h +23 -0
- data/leveldb/port/port_android.cc +64 -0
- data/leveldb/port/port_android.h +150 -0
- data/leveldb/port/port_chromium.cc +80 -0
- data/leveldb/port/port_chromium.h +97 -0
- data/leveldb/port/port_example.h +115 -0
- data/leveldb/port/port_osx.cc +50 -0
- data/leveldb/port/port_osx.h +125 -0
- data/leveldb/port/port_posix.cc +50 -0
- data/leveldb/port/port_posix.h +94 -0
- data/leveldb/port/sha1_portable.cc +298 -0
- data/leveldb/port/sha1_portable.h +25 -0
- data/leveldb/port/sha1_test.cc +39 -0
- data/leveldb/port/win/stdint.h +24 -0
- data/leveldb/table/block.cc +263 -0
- data/leveldb/table/block.h +43 -0
- data/leveldb/table/block_builder.cc +109 -0
- data/leveldb/table/block_builder.h +57 -0
- data/leveldb/table/format.cc +131 -0
- data/leveldb/table/format.h +103 -0
- data/leveldb/table/iterator.cc +67 -0
- data/leveldb/table/iterator_wrapper.h +63 -0
- data/leveldb/table/merger.cc +197 -0
- data/leveldb/table/merger.h +26 -0
- data/leveldb/table/table.cc +175 -0
- data/leveldb/table/table_builder.cc +227 -0
- data/leveldb/table/table_test.cc +845 -0
- data/leveldb/table/two_level_iterator.cc +182 -0
- data/leveldb/table/two_level_iterator.h +34 -0
- data/leveldb/util/arena.cc +68 -0
- data/leveldb/util/arena.h +68 -0
- data/leveldb/util/arena_test.cc +68 -0
- data/leveldb/util/cache.cc +255 -0
- data/leveldb/util/cache_test.cc +169 -0
- data/leveldb/util/coding.cc +194 -0
- data/leveldb/util/coding.h +104 -0
- data/leveldb/util/coding_test.cc +173 -0
- data/leveldb/util/comparator.cc +72 -0
- data/leveldb/util/crc32c.cc +332 -0
- data/leveldb/util/crc32c.h +45 -0
- data/leveldb/util/crc32c_test.cc +72 -0
- data/leveldb/util/env.cc +77 -0
- data/leveldb/util/env_chromium.cc +612 -0
- data/leveldb/util/env_posix.cc +606 -0
- data/leveldb/util/env_test.cc +102 -0
- data/leveldb/util/hash.cc +45 -0
- data/leveldb/util/hash.h +19 -0
- data/leveldb/util/histogram.cc +128 -0
- data/leveldb/util/histogram.h +41 -0
- data/leveldb/util/logging.cc +81 -0
- data/leveldb/util/logging.h +47 -0
- data/leveldb/util/mutexlock.h +39 -0
- data/leveldb/util/options.cc +28 -0
- data/leveldb/util/random.h +59 -0
- data/leveldb/util/status.cc +75 -0
- data/leveldb/util/testharness.cc +65 -0
- data/leveldb/util/testharness.h +129 -0
- data/leveldb/util/testutil.cc +51 -0
- data/leveldb/util/testutil.h +53 -0
- data/lib/leveldb.rb +36 -0
- metadata +183 -0
@@ -0,0 +1,70 @@
|
|
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.
|
4
|
+
|
5
|
+
#ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_
|
6
|
+
#define STORAGE_LEVELDB_INCLUDE_TABLE_H_
|
7
|
+
|
8
|
+
#include <stdint.h>
|
9
|
+
#include "leveldb/iterator.h"
|
10
|
+
|
11
|
+
namespace leveldb {
|
12
|
+
|
13
|
+
class Block;
|
14
|
+
class BlockHandle;
|
15
|
+
struct Options;
|
16
|
+
class RandomAccessFile;
|
17
|
+
struct ReadOptions;
|
18
|
+
|
19
|
+
// A Table is a sorted map from strings to strings. Tables are
|
20
|
+
// immutable and persistent. A Table may be safely accessed from
|
21
|
+
// multiple threads without external synchronization.
|
22
|
+
class Table {
|
23
|
+
public:
|
24
|
+
// Attempt to open the table that is stored in bytes [0..file_size)
|
25
|
+
// of "file", and read the metadata entries necessary to allow
|
26
|
+
// retrieving data from the table.
|
27
|
+
//
|
28
|
+
// If successful, returns ok and sets "*table" to the newly opened
|
29
|
+
// table. The client should delete "*table" when no longer needed.
|
30
|
+
// If there was an error while initializing the table, sets "*table"
|
31
|
+
// to NULL and returns a non-ok status. Does not take ownership of
|
32
|
+
// "*source", but the client must ensure that "source" remains live
|
33
|
+
// for the duration of the returned table's lifetime.
|
34
|
+
//
|
35
|
+
// *file must remain live while this Table is in use.
|
36
|
+
static Status Open(const Options& options,
|
37
|
+
RandomAccessFile* file,
|
38
|
+
uint64_t file_size,
|
39
|
+
Table** table);
|
40
|
+
|
41
|
+
~Table();
|
42
|
+
|
43
|
+
// Returns a new iterator over the table contents.
|
44
|
+
// The result of NewIterator() is initially invalid (caller must
|
45
|
+
// call one of the Seek methods on the iterator before using it).
|
46
|
+
Iterator* NewIterator(const ReadOptions&) const;
|
47
|
+
|
48
|
+
// Given a key, return an approximate byte offset in the file where
|
49
|
+
// the data for that key begins (or would begin if the key were
|
50
|
+
// present in the file). The returned value is in terms of file
|
51
|
+
// bytes, and so includes effects like compression of the underlying data.
|
52
|
+
// E.g., the approximate offset of the last key in the table will
|
53
|
+
// be close to the file length.
|
54
|
+
uint64_t ApproximateOffsetOf(const Slice& key) const;
|
55
|
+
|
56
|
+
private:
|
57
|
+
struct Rep;
|
58
|
+
Rep* rep_;
|
59
|
+
|
60
|
+
explicit Table(Rep* rep) { rep_ = rep; }
|
61
|
+
static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
|
62
|
+
|
63
|
+
// No copying allowed
|
64
|
+
Table(const Table&);
|
65
|
+
void operator=(const Table&);
|
66
|
+
};
|
67
|
+
|
68
|
+
}
|
69
|
+
|
70
|
+
#endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_
|
@@ -0,0 +1,91 @@
|
|
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.
|
4
|
+
//
|
5
|
+
// TableBuilder provides the interface used to build a Table
|
6
|
+
// (an immutable and sorted map from keys to values).
|
7
|
+
//
|
8
|
+
// Multiple threads can invoke const methods on a TableBuilder without
|
9
|
+
// external synchronization, but if any of the threads may call a
|
10
|
+
// non-const method, all threads accessing the same TableBuilder must use
|
11
|
+
// external synchronization.
|
12
|
+
|
13
|
+
#ifndef STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|
14
|
+
#define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|
15
|
+
|
16
|
+
#include <stdint.h>
|
17
|
+
#include "leveldb/options.h"
|
18
|
+
#include "leveldb/status.h"
|
19
|
+
|
20
|
+
namespace leveldb {
|
21
|
+
|
22
|
+
class BlockBuilder;
|
23
|
+
class BlockHandle;
|
24
|
+
class WritableFile;
|
25
|
+
|
26
|
+
class TableBuilder {
|
27
|
+
public:
|
28
|
+
// Create a builder that will store the contents of the table it is
|
29
|
+
// building in *file. Does not close the file. It is up to the
|
30
|
+
// caller to close the file after calling Finish().
|
31
|
+
TableBuilder(const Options& options, WritableFile* file);
|
32
|
+
|
33
|
+
// REQUIRES: Either Finish() or Abandon() has been called.
|
34
|
+
~TableBuilder();
|
35
|
+
|
36
|
+
// Change the options used by this builder. Note: only some of the
|
37
|
+
// option fields can be changed after construction. If a field is
|
38
|
+
// not allowed to change dynamically and its value in the structure
|
39
|
+
// passed to the constructor is different from its value in the
|
40
|
+
// structure passed to this method, this method will return an error
|
41
|
+
// without changing any fields.
|
42
|
+
Status ChangeOptions(const Options& options);
|
43
|
+
|
44
|
+
// Add key,value to the table being constructed.
|
45
|
+
// REQUIRES: key is after any previously added key according to comparator.
|
46
|
+
// REQUIRES: Finish(), Abandon() have not been called
|
47
|
+
void Add(const Slice& key, const Slice& value);
|
48
|
+
|
49
|
+
// Advanced operation: flush any buffered key/value pairs to file.
|
50
|
+
// Can be used to ensure that two adjacent entries never live in
|
51
|
+
// the same data block. Most clients should not need to use this method.
|
52
|
+
// REQUIRES: Finish(), Abandon() have not been called
|
53
|
+
void Flush();
|
54
|
+
|
55
|
+
// Return non-ok iff some error has been detected.
|
56
|
+
Status status() const;
|
57
|
+
|
58
|
+
// Finish building the table. Stops using the file passed to the
|
59
|
+
// constructor after this function returns.
|
60
|
+
// REQUIRES: Finish(), Abandon() have not been called
|
61
|
+
Status Finish();
|
62
|
+
|
63
|
+
// Indicate that the contents of this builder should be abandoned. Stops
|
64
|
+
// using the file passed to the constructor after this function returns.
|
65
|
+
// If the caller is not going to call Finish(), it must call Abandon()
|
66
|
+
// before destroying this builder.
|
67
|
+
// REQUIRES: Finish(), Abandon() have not been called
|
68
|
+
void Abandon();
|
69
|
+
|
70
|
+
// Number of calls to Add() so far.
|
71
|
+
uint64_t NumEntries() const;
|
72
|
+
|
73
|
+
// Size of the file generated so far. If invoked after a successful
|
74
|
+
// Finish() call, returns the size of the final generated file.
|
75
|
+
uint64_t FileSize() const;
|
76
|
+
|
77
|
+
private:
|
78
|
+
bool ok() const { return status().ok(); }
|
79
|
+
void WriteBlock(BlockBuilder* block, BlockHandle* handle);
|
80
|
+
|
81
|
+
struct Rep;
|
82
|
+
Rep* rep_;
|
83
|
+
|
84
|
+
// No copying allowed
|
85
|
+
TableBuilder(const TableBuilder&);
|
86
|
+
void operator=(const TableBuilder&);
|
87
|
+
};
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
#endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_
|
@@ -0,0 +1,64 @@
|
|
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.
|
4
|
+
//
|
5
|
+
// WriteBatch holds a collection of updates to apply atomically to a DB.
|
6
|
+
//
|
7
|
+
// The updates are applied in the order in which they are added
|
8
|
+
// to the WriteBatch. For example, the value of "key" will be "v3"
|
9
|
+
// after the following batch is written:
|
10
|
+
//
|
11
|
+
// batch.Put("key", "v1");
|
12
|
+
// batch.Delete("key");
|
13
|
+
// batch.Put("key", "v2");
|
14
|
+
// batch.Put("key", "v3");
|
15
|
+
//
|
16
|
+
// Multiple threads can invoke const methods on a WriteBatch without
|
17
|
+
// external synchronization, but if any of the threads may call a
|
18
|
+
// non-const method, all threads accessing the same WriteBatch must use
|
19
|
+
// external synchronization.
|
20
|
+
|
21
|
+
#ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
|
22
|
+
#define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
|
23
|
+
|
24
|
+
#include <string>
|
25
|
+
#include "leveldb/status.h"
|
26
|
+
|
27
|
+
namespace leveldb {
|
28
|
+
|
29
|
+
class Slice;
|
30
|
+
|
31
|
+
class WriteBatch {
|
32
|
+
public:
|
33
|
+
WriteBatch();
|
34
|
+
~WriteBatch();
|
35
|
+
|
36
|
+
// Store the mapping "key->value" in the database.
|
37
|
+
void Put(const Slice& key, const Slice& value);
|
38
|
+
|
39
|
+
// If the database contains a mapping for "key", erase it. Else do nothing.
|
40
|
+
void Delete(const Slice& key);
|
41
|
+
|
42
|
+
// Clear all updates buffered in this batch.
|
43
|
+
void Clear();
|
44
|
+
|
45
|
+
// Support for iterating over the contents of a batch.
|
46
|
+
class Handler {
|
47
|
+
public:
|
48
|
+
virtual ~Handler();
|
49
|
+
virtual void Put(const Slice& key, const Slice& value) = 0;
|
50
|
+
virtual void Delete(const Slice& key) = 0;
|
51
|
+
};
|
52
|
+
Status Iterate(Handler* handler) const;
|
53
|
+
|
54
|
+
private:
|
55
|
+
friend class WriteBatchInternal;
|
56
|
+
|
57
|
+
std::string rep_; // See comment in write_batch.cc for the format of rep_
|
58
|
+
|
59
|
+
// Intentionally copyable
|
60
|
+
};
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
#endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_
|
data/leveldb/port/port.h
ADDED
@@ -0,0 +1,23 @@
|
|
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.
|
4
|
+
|
5
|
+
#ifndef STORAGE_LEVELDB_PORT_PORT_H_
|
6
|
+
#define STORAGE_LEVELDB_PORT_PORT_H_
|
7
|
+
|
8
|
+
#include <string.h>
|
9
|
+
|
10
|
+
// Include the appropriate platform specific file below. If you are
|
11
|
+
// porting to a new platform, see "port_example.h" for documentation
|
12
|
+
// of what the new port_<platform>.h file must provide.
|
13
|
+
#if defined(LEVELDB_PLATFORM_POSIX)
|
14
|
+
# include "port/port_posix.h"
|
15
|
+
#elif defined(LEVELDB_PLATFORM_CHROMIUM)
|
16
|
+
# include "port/port_chromium.h"
|
17
|
+
#elif defined(LEVELDB_PLATFORM_ANDROID)
|
18
|
+
# include "port/port_android.h"
|
19
|
+
#elif defined(LEVELDB_PLATFORM_OSX)
|
20
|
+
# include "port/port_osx.h"
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#endif // STORAGE_LEVELDB_PORT_PORT_H_
|
@@ -0,0 +1,64 @@
|
|
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.
|
4
|
+
|
5
|
+
#include "port/port_android.h"
|
6
|
+
|
7
|
+
#include <cstdlib>
|
8
|
+
|
9
|
+
extern "C" {
|
10
|
+
size_t fread_unlocked(void *a, size_t b, size_t c, FILE *d) {
|
11
|
+
return fread(a, b, c, d);
|
12
|
+
}
|
13
|
+
|
14
|
+
size_t fwrite_unlocked(const void *a, size_t b, size_t c, FILE *d) {
|
15
|
+
return fwrite(a, b, c, d);
|
16
|
+
}
|
17
|
+
|
18
|
+
int fflush_unlocked(FILE *f) {
|
19
|
+
return fflush(f);
|
20
|
+
}
|
21
|
+
|
22
|
+
int fdatasync(int fd) {
|
23
|
+
return fsync(fd);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
namespace leveldb {
|
28
|
+
namespace port {
|
29
|
+
|
30
|
+
static void PthreadCall(const char* label, int result) {
|
31
|
+
if (result != 0) {
|
32
|
+
fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
|
33
|
+
abort();
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
|
38
|
+
Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
|
39
|
+
void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
|
40
|
+
void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }
|
41
|
+
|
42
|
+
CondVar::CondVar(Mutex* mu)
|
43
|
+
: mu_(mu) {
|
44
|
+
PthreadCall("init cv", pthread_cond_init(&cv_, NULL));
|
45
|
+
}
|
46
|
+
|
47
|
+
CondVar::~CondVar() {
|
48
|
+
PthreadCall("destroy cv", pthread_cond_destroy(&cv_));
|
49
|
+
}
|
50
|
+
|
51
|
+
void CondVar::Wait() {
|
52
|
+
PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
|
53
|
+
}
|
54
|
+
|
55
|
+
void CondVar::Signal(){
|
56
|
+
PthreadCall("signal", pthread_cond_signal(&cv_));
|
57
|
+
}
|
58
|
+
|
59
|
+
void CondVar::SignalAll() {
|
60
|
+
PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,150 @@
|
|
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.
|
4
|
+
//
|
5
|
+
// See port_example.h for documentation for the following types/functions.
|
6
|
+
|
7
|
+
#ifndef STORAGE_LEVELDB_PORT_PORT_ANDROID_H_
|
8
|
+
#define STORAGE_LEVELDB_PORT_PORT_ANDROID_H_
|
9
|
+
|
10
|
+
#include <endian.h>
|
11
|
+
#include <pthread.h>
|
12
|
+
#include <stdint.h>
|
13
|
+
#include <cstdatomic>
|
14
|
+
#include <string>
|
15
|
+
#include <cctype>
|
16
|
+
|
17
|
+
// Collapse the plethora of ARM flavors available to an easier to manage set
|
18
|
+
// Defs reference is at https://wiki.edubuntu.org/ARM/Thumb2PortingHowto
|
19
|
+
#if defined(__ARM_ARCH_6__) || \
|
20
|
+
defined(__ARM_ARCH_6J__) || \
|
21
|
+
defined(__ARM_ARCH_6K__) || \
|
22
|
+
defined(__ARM_ARCH_6Z__) || \
|
23
|
+
defined(__ARM_ARCH_6T2__) || \
|
24
|
+
defined(__ARM_ARCH_6ZK__) || \
|
25
|
+
defined(__ARM_ARCH_7__) || \
|
26
|
+
defined(__ARM_ARCH_7R__) || \
|
27
|
+
defined(__ARM_ARCH_7A__)
|
28
|
+
#define ARMV6_OR_7 1
|
29
|
+
#endif
|
30
|
+
|
31
|
+
extern "C" {
|
32
|
+
size_t fread_unlocked(void *a, size_t b, size_t c, FILE *d);
|
33
|
+
size_t fwrite_unlocked(const void *a, size_t b, size_t c, FILE *d);
|
34
|
+
int fflush_unlocked(FILE *f);
|
35
|
+
int fdatasync (int fd);
|
36
|
+
}
|
37
|
+
|
38
|
+
namespace leveldb {
|
39
|
+
namespace port {
|
40
|
+
|
41
|
+
static const bool kLittleEndian = __BYTE_ORDER == __LITTLE_ENDIAN;
|
42
|
+
|
43
|
+
class CondVar;
|
44
|
+
|
45
|
+
class Mutex {
|
46
|
+
public:
|
47
|
+
Mutex();
|
48
|
+
~Mutex();
|
49
|
+
|
50
|
+
void Lock();
|
51
|
+
void Unlock();
|
52
|
+
void AssertHeld() {
|
53
|
+
//TODO(gabor): How can I implement this?
|
54
|
+
}
|
55
|
+
|
56
|
+
private:
|
57
|
+
friend class CondVar;
|
58
|
+
pthread_mutex_t mu_;
|
59
|
+
|
60
|
+
// No copying
|
61
|
+
Mutex(const Mutex&);
|
62
|
+
void operator=(const Mutex&);
|
63
|
+
};
|
64
|
+
|
65
|
+
class CondVar {
|
66
|
+
public:
|
67
|
+
explicit CondVar(Mutex* mu);
|
68
|
+
~CondVar();
|
69
|
+
void Wait();
|
70
|
+
void Signal();
|
71
|
+
void SignalAll();
|
72
|
+
private:
|
73
|
+
Mutex* mu_;
|
74
|
+
pthread_cond_t cv_;
|
75
|
+
};
|
76
|
+
|
77
|
+
#ifndef ARMV6_OR_7
|
78
|
+
// On ARM chipsets <V6, 0xffff0fa0 is the hard coded address of a
|
79
|
+
// memory barrier function provided by the kernel.
|
80
|
+
typedef void (*LinuxKernelMemoryBarrierFunc)(void);
|
81
|
+
LinuxKernelMemoryBarrierFunc pLinuxKernelMemoryBarrier ATTRIBUTE_WEAK =
|
82
|
+
(LinuxKernelMemoryBarrierFunc) 0xffff0fa0;
|
83
|
+
#endif
|
84
|
+
|
85
|
+
// Storage for a lock-free pointer
|
86
|
+
class AtomicPointer {
|
87
|
+
private:
|
88
|
+
void* rep_;
|
89
|
+
|
90
|
+
inline void MemoryBarrier() const {
|
91
|
+
// TODO(gabor): This only works on Android instruction sets >= V6
|
92
|
+
#ifdef ARMV6_OR_7
|
93
|
+
__asm__ __volatile__("dmb" : : : "memory");
|
94
|
+
#else
|
95
|
+
pLinuxKernelMemoryBarrier();
|
96
|
+
#endif
|
97
|
+
}
|
98
|
+
|
99
|
+
public:
|
100
|
+
AtomicPointer() { }
|
101
|
+
explicit AtomicPointer(void* v) : rep_(v) { }
|
102
|
+
inline void* Acquire_Load() const {
|
103
|
+
void* r = rep_;
|
104
|
+
MemoryBarrier();
|
105
|
+
return r;
|
106
|
+
}
|
107
|
+
inline void Release_Store(void* v) {
|
108
|
+
MemoryBarrier();
|
109
|
+
rep_ = v;
|
110
|
+
}
|
111
|
+
inline void* NoBarrier_Load() const {
|
112
|
+
void* r = rep_;
|
113
|
+
return r;
|
114
|
+
}
|
115
|
+
inline void NoBarrier_Store(void* v) {
|
116
|
+
rep_ = v;
|
117
|
+
}
|
118
|
+
};
|
119
|
+
|
120
|
+
// TODO(gabor): Implement compress
|
121
|
+
inline bool Snappy_Compress(
|
122
|
+
const char* input,
|
123
|
+
size_t input_length,
|
124
|
+
std::string* output) {
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
|
128
|
+
// TODO(gabor): Implement uncompress
|
129
|
+
inline bool Snappy_Uncompress(
|
130
|
+
const char* input_data,
|
131
|
+
size_t input_length,
|
132
|
+
std::string* output) {
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
|
136
|
+
inline uint64_t ThreadIdentifier() {
|
137
|
+
pthread_t tid = pthread_self();
|
138
|
+
uint64_t r = 0;
|
139
|
+
memcpy(&r, &tid, sizeof(r) < sizeof(tid) ? sizeof(r) : sizeof(tid));
|
140
|
+
return r;
|
141
|
+
}
|
142
|
+
|
143
|
+
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
|
144
|
+
return false;
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
#endif // STORAGE_LEVELDB_PORT_PORT_ANDROID_H_
|