leveldb-ruby 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/leveldb/extconf.rb +2 -6
- data/ext/leveldb/leveldb.cc +377 -33
- data/ext/leveldb/platform.rb +83 -0
- data/leveldb/Makefile +29 -28
- data/leveldb/build_detect_platform +23 -4
- data/leveldb/db/builder.cc +1 -1
- data/leveldb/db/builder.h +1 -1
- data/leveldb/db/corruption_test.cc +1 -1
- data/leveldb/db/db_bench.cc +2 -2
- data/leveldb/db/db_impl.cc +8 -16
- data/leveldb/db/db_impl.h +1 -1
- data/leveldb/db/db_iter.cc +1 -1
- data/leveldb/db/db_iter.h +1 -1
- data/leveldb/db/db_test.cc +180 -9
- data/leveldb/db/dbformat.cc +9 -7
- data/leveldb/db/dbformat.h +2 -2
- data/leveldb/db/dbformat_test.cc +1 -1
- data/leveldb/db/filename.cc +6 -2
- data/leveldb/db/filename.h +1 -1
- data/leveldb/db/filename_test.cc +1 -1
- data/leveldb/db/log_format.h +2 -2
- data/leveldb/db/log_reader.cc +2 -2
- data/leveldb/db/log_reader.h +2 -2
- data/leveldb/db/log_test.cc +2 -2
- data/leveldb/db/log_writer.cc +2 -2
- data/leveldb/db/log_writer.h +2 -2
- data/leveldb/db/memtable.cc +1 -1
- data/leveldb/db/memtable.h +1 -1
- data/leveldb/db/repair.cc +2 -2
- data/leveldb/db/skiplist.h +1 -1
- data/leveldb/db/skiplist_test.cc +1 -1
- data/leveldb/db/snapshot.h +1 -1
- data/leveldb/db/table_cache.cc +1 -1
- data/leveldb/db/table_cache.h +1 -1
- data/leveldb/db/version_edit.cc +1 -1
- data/leveldb/db/version_edit.h +1 -1
- data/leveldb/db/version_edit_test.cc +1 -1
- data/leveldb/db/version_set.cc +39 -14
- data/leveldb/db/version_set.h +1 -1
- data/leveldb/db/version_set_test.cc +1 -1
- data/leveldb/db/write_batch.cc +2 -2
- data/leveldb/db/write_batch_internal.h +1 -1
- data/leveldb/db/write_batch_test.cc +1 -1
- data/leveldb/helpers/memenv/memenv.cc +374 -0
- data/leveldb/helpers/memenv/memenv.h +20 -0
- data/leveldb/helpers/memenv/memenv_test.cc +232 -0
- data/leveldb/include/leveldb/cache.h +1 -1
- data/leveldb/include/leveldb/comparator.h +1 -1
- data/leveldb/include/leveldb/db.h +1 -1
- data/leveldb/include/leveldb/env.h +1 -1
- data/leveldb/include/leveldb/iterator.h +1 -1
- data/leveldb/include/leveldb/options.h +1 -1
- data/leveldb/include/leveldb/slice.h +1 -1
- data/leveldb/include/leveldb/status.h +1 -1
- data/leveldb/include/leveldb/table.h +1 -1
- data/leveldb/include/leveldb/table_builder.h +1 -1
- data/leveldb/include/leveldb/write_batch.h +1 -1
- data/leveldb/port/atomic_pointer.h +2 -2
- data/leveldb/port/port_android.cc +2 -2
- data/leveldb/port/port_android.h +2 -2
- data/leveldb/port/port_example.h +2 -2
- data/leveldb/port/port_posix.cc +2 -2
- data/leveldb/port/port_posix.h +11 -3
- data/leveldb/table/block.cc +1 -1
- data/leveldb/table/block.h +1 -1
- data/leveldb/table/block_builder.cc +1 -1
- data/leveldb/table/block_builder.h +1 -1
- data/leveldb/table/format.cc +1 -1
- data/leveldb/table/format.h +1 -1
- data/leveldb/table/iterator.cc +2 -2
- data/leveldb/table/merger.cc +2 -2
- data/leveldb/table/merger.h +1 -1
- data/leveldb/table/table.cc +1 -1
- data/leveldb/table/table_builder.cc +1 -1
- data/leveldb/table/table_test.cc +3 -3
- data/leveldb/table/two_level_iterator.cc +2 -2
- data/leveldb/table/two_level_iterator.h +1 -1
- data/leveldb/util/arena.cc +1 -1
- data/leveldb/util/arena.h +1 -1
- data/leveldb/util/arena_test.cc +1 -1
- data/leveldb/util/cache.cc +1 -1
- data/leveldb/util/cache_test.cc +1 -1
- data/leveldb/util/coding.cc +1 -1
- data/leveldb/util/coding.h +1 -1
- data/leveldb/util/coding_test.cc +1 -1
- data/leveldb/util/comparator.cc +7 -4
- data/leveldb/util/crc32c.cc +2 -2
- data/leveldb/util/crc32c.h +2 -2
- data/leveldb/util/crc32c_test.cc +2 -2
- data/leveldb/util/env.cc +17 -3
- data/leveldb/util/env_posix.cc +2 -2
- data/leveldb/util/env_test.cc +13 -11
- data/leveldb/util/hash.cc +1 -1
- data/leveldb/util/histogram.cc +1 -1
- data/leveldb/util/histogram.h +1 -1
- data/leveldb/util/logging.cc +1 -1
- data/leveldb/util/logging.h +1 -1
- data/leveldb/util/mutexlock.h +1 -1
- data/leveldb/util/options.cc +1 -1
- data/leveldb/util/posix_logger.h +1 -1
- data/leveldb/util/random.h +1 -1
- data/leveldb/util/status.cc +1 -1
- data/leveldb/util/testharness.cc +2 -2
- data/leveldb/util/testharness.h +2 -2
- data/leveldb/util/testutil.cc +2 -2
- data/leveldb/util/testutil.h +2 -2
- data/lib/leveldb.rb +34 -2
- metadata +7 -13
- data/leveldb/port/port_chromium.cc +0 -80
- data/leveldb/port/port_chromium.h +0 -97
- data/leveldb/port/port_osx.cc +0 -50
- data/leveldb/port/port_osx.h +0 -125
- data/leveldb/port/sha1_portable.cc +0 -298
- data/leveldb/port/sha1_portable.h +0 -25
- data/leveldb/port/sha1_test.cc +0 -39
- data/leveldb/util/env_chromium.cc +0 -612
data/leveldb/util/random.h
CHANGED
data/leveldb/util/status.cc
CHANGED
data/leveldb/util/testharness.cc
CHANGED
data/leveldb/util/testharness.h
CHANGED
data/leveldb/util/testutil.cc
CHANGED
data/leveldb/util/testutil.h
CHANGED
data/lib/leveldb.rb
CHANGED
@@ -4,7 +4,6 @@ module LevelDB
|
|
4
4
|
class DB
|
5
5
|
include Enumerable
|
6
6
|
class << self
|
7
|
-
|
8
7
|
## Loads or creates a LevelDB database as necessary, stored on disk at
|
9
8
|
## +pathname+.
|
10
9
|
def new pathname
|
@@ -29,16 +28,49 @@ class DB
|
|
29
28
|
def path_string pathname
|
30
29
|
File.respond_to?(:path) ? File.path(pathname) : pathname.to_str
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
|
33
|
+
attr_reader :pathname
|
34
|
+
|
35
35
|
alias :includes? :exists?
|
36
36
|
alias :contains? :exists?
|
37
37
|
alias :member? :exists?
|
38
38
|
alias :[] :get
|
39
39
|
alias :[]= :put
|
40
40
|
|
41
|
+
def each(*args, &block)
|
42
|
+
i = iterator(*args)
|
43
|
+
i.each(&block) if block
|
44
|
+
i
|
45
|
+
end
|
46
|
+
|
47
|
+
def iterator(*args); Iterator.new self, *args end
|
41
48
|
def keys; map { |k, v| k } end
|
42
49
|
def values; map { |k, v| v } end
|
50
|
+
|
51
|
+
def inspect
|
52
|
+
%(<#{self.class} #{@pathname.inspect}>)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Iterator
|
57
|
+
include Enumerable
|
58
|
+
|
59
|
+
attr_reader :db, :from, :to
|
60
|
+
|
61
|
+
def self.new(db, opts={})
|
62
|
+
make db, opts
|
63
|
+
end
|
64
|
+
|
65
|
+
def reversed?; @reversed end
|
66
|
+
def inspect
|
67
|
+
%(<#{self.class} #{@db.inspect} @from=#{@from.inspect} @to=#{@to.inspect}#{' (reversed)' if @reversed}>)
|
68
|
+
end
|
43
69
|
end
|
70
|
+
|
71
|
+
class WriteBatch
|
72
|
+
class << self
|
73
|
+
private :new
|
74
|
+
end
|
44
75
|
end
|
76
|
+
end # module LevelDB
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leveldb-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-03-07 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: LevelDB-Ruby is a Ruby binding to LevelDB.
|
16
15
|
email: wmorgan-leveldb-ruby-gemspec@masanjin.net
|
@@ -23,6 +22,7 @@ extra_rdoc_files:
|
|
23
22
|
files:
|
24
23
|
- README
|
25
24
|
- ext/leveldb/extconf.rb
|
25
|
+
- ext/leveldb/platform.rb
|
26
26
|
- lib/leveldb.rb
|
27
27
|
- ext/leveldb/leveldb.cc
|
28
28
|
- leveldb/Makefile
|
@@ -66,6 +66,9 @@ files:
|
|
66
66
|
- leveldb/db/write_batch.cc
|
67
67
|
- leveldb/db/write_batch_internal.h
|
68
68
|
- leveldb/db/write_batch_test.cc
|
69
|
+
- leveldb/helpers/memenv/memenv.cc
|
70
|
+
- leveldb/helpers/memenv/memenv.h
|
71
|
+
- leveldb/helpers/memenv/memenv_test.cc
|
69
72
|
- leveldb/include/leveldb/c.h
|
70
73
|
- leveldb/include/leveldb/cache.h
|
71
74
|
- leveldb/include/leveldb/comparator.h
|
@@ -82,16 +85,9 @@ files:
|
|
82
85
|
- leveldb/port/port.h
|
83
86
|
- leveldb/port/port_android.cc
|
84
87
|
- leveldb/port/port_android.h
|
85
|
-
- leveldb/port/port_chromium.cc
|
86
|
-
- leveldb/port/port_chromium.h
|
87
88
|
- leveldb/port/port_example.h
|
88
|
-
- leveldb/port/port_osx.cc
|
89
|
-
- leveldb/port/port_osx.h
|
90
89
|
- leveldb/port/port_posix.cc
|
91
90
|
- leveldb/port/port_posix.h
|
92
|
-
- leveldb/port/sha1_portable.cc
|
93
|
-
- leveldb/port/sha1_portable.h
|
94
|
-
- leveldb/port/sha1_test.cc
|
95
91
|
- leveldb/port/win/stdint.h
|
96
92
|
- leveldb/table/block.cc
|
97
93
|
- leveldb/table/block.h
|
@@ -121,7 +117,6 @@ files:
|
|
121
117
|
- leveldb/util/crc32c.h
|
122
118
|
- leveldb/util/crc32c_test.cc
|
123
119
|
- leveldb/util/env.cc
|
124
|
-
- leveldb/util/env_chromium.cc
|
125
120
|
- leveldb/util/env_posix.cc
|
126
121
|
- leveldb/util/env_test.cc
|
127
122
|
- leveldb/util/hash.cc
|
@@ -139,7 +134,6 @@ files:
|
|
139
134
|
- leveldb/util/testharness.h
|
140
135
|
- leveldb/util/testutil.cc
|
141
136
|
- leveldb/util/testutil.h
|
142
|
-
has_rdoc: true
|
143
137
|
homepage: http://github.com/wmorgan/leveldb-ruby
|
144
138
|
licenses: []
|
145
139
|
post_install_message:
|
@@ -166,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
160
|
version: '0'
|
167
161
|
requirements: []
|
168
162
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.
|
163
|
+
rubygems_version: 1.8.11
|
170
164
|
signing_key:
|
171
165
|
specification_version: 3
|
172
166
|
summary: a Ruby binding to LevelDB
|
@@ -1,80 +0,0 @@
|
|
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_chromium.h"
|
6
|
-
|
7
|
-
#include "util/logging.h"
|
8
|
-
|
9
|
-
#if defined(USE_SNAPPY)
|
10
|
-
# include "third_party/snappy/src/snappy.h"
|
11
|
-
#endif
|
12
|
-
|
13
|
-
namespace leveldb {
|
14
|
-
namespace port {
|
15
|
-
|
16
|
-
Mutex::Mutex() {
|
17
|
-
}
|
18
|
-
|
19
|
-
Mutex::~Mutex() {
|
20
|
-
}
|
21
|
-
|
22
|
-
void Mutex::Lock() {
|
23
|
-
mu_.Acquire();
|
24
|
-
}
|
25
|
-
|
26
|
-
void Mutex::Unlock() {
|
27
|
-
mu_.Release();
|
28
|
-
}
|
29
|
-
|
30
|
-
void Mutex::AssertHeld() {
|
31
|
-
mu_.AssertAcquired();
|
32
|
-
}
|
33
|
-
|
34
|
-
CondVar::CondVar(Mutex* mu)
|
35
|
-
: cv_(&mu->mu_) {
|
36
|
-
}
|
37
|
-
|
38
|
-
CondVar::~CondVar() { }
|
39
|
-
|
40
|
-
void CondVar::Wait() {
|
41
|
-
cv_.Wait();
|
42
|
-
}
|
43
|
-
|
44
|
-
void CondVar::Signal(){
|
45
|
-
cv_.Signal();
|
46
|
-
}
|
47
|
-
|
48
|
-
void CondVar::SignalAll() {
|
49
|
-
cv_.Broadcast();
|
50
|
-
}
|
51
|
-
|
52
|
-
bool Snappy_Compress(const char* input, size_t input_length,
|
53
|
-
std::string* output) {
|
54
|
-
#if defined(USE_SNAPPY)
|
55
|
-
output->resize(snappy::MaxCompressedLength(input_length));
|
56
|
-
size_t outlen;
|
57
|
-
snappy::RawCompress(input, input_length, &(*output)[0], &outlen);
|
58
|
-
output->resize(outlen);
|
59
|
-
return true;
|
60
|
-
#else
|
61
|
-
return false;
|
62
|
-
#endif
|
63
|
-
}
|
64
|
-
|
65
|
-
bool Snappy_Uncompress(const char* input_data, size_t input_length,
|
66
|
-
std::string* output) {
|
67
|
-
#if defined(USE_SNAPPY)
|
68
|
-
size_t ulength;
|
69
|
-
if (!snappy::GetUncompressedLength(input_data, input_length, &ulength)) {
|
70
|
-
return false;
|
71
|
-
}
|
72
|
-
output->resize(ulength);
|
73
|
-
return snappy::RawUncompress(input_data, input_length, &(*output)[0]);
|
74
|
-
#else
|
75
|
-
return false;
|
76
|
-
#endif
|
77
|
-
}
|
78
|
-
|
79
|
-
}
|
80
|
-
}
|
@@ -1,97 +0,0 @@
|
|
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_CHROMIUM_H_
|
8
|
-
#define STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
|
9
|
-
|
10
|
-
#include <stdint.h>
|
11
|
-
#include <string>
|
12
|
-
#include <cstring>
|
13
|
-
#include "base/atomicops.h"
|
14
|
-
#include "base/basictypes.h"
|
15
|
-
#include "base/logging.h"
|
16
|
-
#include "base/synchronization/condition_variable.h"
|
17
|
-
#include "base/synchronization/lock.h"
|
18
|
-
|
19
|
-
// Linux's ThreadIdentifier() needs this.
|
20
|
-
#if defined(OS_LINUX)
|
21
|
-
# include <linux/unistd.h>
|
22
|
-
#endif
|
23
|
-
|
24
|
-
#if defined(OS_WIN)
|
25
|
-
#define snprintf _snprintf
|
26
|
-
#define va_copy(a, b) do { (a) = (b); } while (0)
|
27
|
-
#endif
|
28
|
-
|
29
|
-
namespace leveldb {
|
30
|
-
namespace port {
|
31
|
-
|
32
|
-
// Chromium only supports little endian.
|
33
|
-
static const bool kLittleEndian = true;
|
34
|
-
|
35
|
-
class Mutex {
|
36
|
-
public:
|
37
|
-
Mutex();
|
38
|
-
~Mutex();
|
39
|
-
void Lock();
|
40
|
-
void Unlock();
|
41
|
-
void AssertHeld();
|
42
|
-
|
43
|
-
private:
|
44
|
-
base::Lock mu_;
|
45
|
-
|
46
|
-
friend class CondVar;
|
47
|
-
DISALLOW_COPY_AND_ASSIGN(Mutex);
|
48
|
-
};
|
49
|
-
|
50
|
-
class CondVar {
|
51
|
-
public:
|
52
|
-
explicit CondVar(Mutex* mu);
|
53
|
-
~CondVar();
|
54
|
-
void Wait();
|
55
|
-
void Signal();
|
56
|
-
void SignalAll();
|
57
|
-
|
58
|
-
private:
|
59
|
-
base::ConditionVariable cv_;
|
60
|
-
|
61
|
-
DISALLOW_COPY_AND_ASSIGN(CondVar);
|
62
|
-
};
|
63
|
-
|
64
|
-
class AtomicPointer {
|
65
|
-
private:
|
66
|
-
typedef base::subtle::AtomicWord Rep;
|
67
|
-
Rep rep_;
|
68
|
-
public:
|
69
|
-
AtomicPointer() { }
|
70
|
-
explicit AtomicPointer(void* p) : rep_(reinterpret_cast<Rep>(p)) {}
|
71
|
-
inline void* Acquire_Load() const {
|
72
|
-
return reinterpret_cast<void*>(::base::subtle::Acquire_Load(&rep_));
|
73
|
-
}
|
74
|
-
inline void Release_Store(void* v) {
|
75
|
-
::base::subtle::Release_Store(&rep_, reinterpret_cast<Rep>(v));
|
76
|
-
}
|
77
|
-
inline void* NoBarrier_Load() const {
|
78
|
-
return reinterpret_cast<void*>(::base::subtle::NoBarrier_Load(&rep_));
|
79
|
-
}
|
80
|
-
inline void NoBarrier_Store(void* v) {
|
81
|
-
::base::subtle::NoBarrier_Store(&rep_, reinterpret_cast<Rep>(v));
|
82
|
-
}
|
83
|
-
};
|
84
|
-
|
85
|
-
bool Snappy_Compress(const char* input, size_t input_length,
|
86
|
-
std::string* output);
|
87
|
-
bool Snappy_Uncompress(const char* input_data, size_t input_length,
|
88
|
-
std::string* output);
|
89
|
-
|
90
|
-
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
|
91
|
-
return false;
|
92
|
-
}
|
93
|
-
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
#endif // STORAGE_LEVELDB_PORT_PORT_CHROMIUM_H_
|
data/leveldb/port/port_osx.cc
DELETED
@@ -1,50 +0,0 @@
|
|
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_osx.h"
|
6
|
-
|
7
|
-
#include <cstdlib>
|
8
|
-
#include <stdio.h>
|
9
|
-
#include <string.h>
|
10
|
-
#include "util/logging.h"
|
11
|
-
|
12
|
-
namespace leveldb {
|
13
|
-
namespace port {
|
14
|
-
|
15
|
-
static void PthreadCall(const char* label, int result) {
|
16
|
-
if (result != 0) {
|
17
|
-
fprintf(stderr, "pthread %s: %s\n", label, strerror(result));
|
18
|
-
abort();
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
|
23
|
-
|
24
|
-
Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }
|
25
|
-
|
26
|
-
void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }
|
27
|
-
|
28
|
-
void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }
|
29
|
-
|
30
|
-
CondVar::CondVar(Mutex* mu)
|
31
|
-
: mu_(mu) {
|
32
|
-
PthreadCall("init cv", pthread_cond_init(&cv_, NULL));
|
33
|
-
}
|
34
|
-
|
35
|
-
CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); }
|
36
|
-
|
37
|
-
void CondVar::Wait() {
|
38
|
-
PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_));
|
39
|
-
}
|
40
|
-
|
41
|
-
void CondVar::Signal() {
|
42
|
-
PthreadCall("signal", pthread_cond_signal(&cv_));
|
43
|
-
}
|
44
|
-
|
45
|
-
void CondVar::SignalAll() {
|
46
|
-
PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
|
47
|
-
}
|
48
|
-
|
49
|
-
}
|
50
|
-
}
|
data/leveldb/port/port_osx.h
DELETED
@@ -1,125 +0,0 @@
|
|
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_OSX_H_
|
8
|
-
#define STORAGE_LEVELDB_PORT_PORT_OSX_H_
|
9
|
-
|
10
|
-
#include <libkern/OSAtomic.h>
|
11
|
-
#include <machine/endian.h>
|
12
|
-
#include <pthread.h>
|
13
|
-
#include <stdint.h>
|
14
|
-
|
15
|
-
#include <string>
|
16
|
-
|
17
|
-
namespace leveldb {
|
18
|
-
|
19
|
-
// The following 4 methods implemented here for the benefit of env_posix.cc.
|
20
|
-
inline size_t fread_unlocked(void *a, size_t b, size_t c, FILE *d) {
|
21
|
-
return fread(a, b, c, d);
|
22
|
-
}
|
23
|
-
|
24
|
-
inline size_t fwrite_unlocked(const void *a, size_t b, size_t c, FILE *d) {
|
25
|
-
return fwrite(a, b, c, d);
|
26
|
-
}
|
27
|
-
|
28
|
-
inline int fflush_unlocked(FILE *f) {
|
29
|
-
return fflush(f);
|
30
|
-
}
|
31
|
-
|
32
|
-
inline int fdatasync(int fd) {
|
33
|
-
return fsync(fd);
|
34
|
-
}
|
35
|
-
|
36
|
-
namespace port {
|
37
|
-
|
38
|
-
static const bool kLittleEndian = (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN);
|
39
|
-
|
40
|
-
// ------------------ Threading -------------------
|
41
|
-
|
42
|
-
// A Mutex represents an exclusive lock.
|
43
|
-
class Mutex {
|
44
|
-
public:
|
45
|
-
Mutex();
|
46
|
-
~Mutex();
|
47
|
-
|
48
|
-
void Lock();
|
49
|
-
void Unlock();
|
50
|
-
void AssertHeld() { }
|
51
|
-
|
52
|
-
private:
|
53
|
-
friend class CondVar;
|
54
|
-
pthread_mutex_t mu_;
|
55
|
-
|
56
|
-
// No copying
|
57
|
-
Mutex(const Mutex&);
|
58
|
-
void operator=(const Mutex&);
|
59
|
-
};
|
60
|
-
|
61
|
-
class CondVar {
|
62
|
-
public:
|
63
|
-
explicit CondVar(Mutex* mu);
|
64
|
-
~CondVar();
|
65
|
-
|
66
|
-
void Wait();
|
67
|
-
void Signal();
|
68
|
-
void SignalAll();
|
69
|
-
|
70
|
-
private:
|
71
|
-
pthread_cond_t cv_;
|
72
|
-
Mutex* mu_;
|
73
|
-
};
|
74
|
-
|
75
|
-
inline void MemoryBarrier() {
|
76
|
-
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
77
|
-
// See http://gcc.gnu.org/ml/gcc/2003-04/msg01180.html for a discussion on
|
78
|
-
// this idiom. Also see http://en.wikipedia.org/wiki/Memory_ordering.
|
79
|
-
__asm__ __volatile__("" : : : "memory");
|
80
|
-
#else
|
81
|
-
OSMemoryBarrier();
|
82
|
-
#endif
|
83
|
-
}
|
84
|
-
|
85
|
-
class AtomicPointer {
|
86
|
-
private:
|
87
|
-
void* ptr_;
|
88
|
-
public:
|
89
|
-
AtomicPointer() { }
|
90
|
-
explicit AtomicPointer(void* p) : ptr_(p) {}
|
91
|
-
inline void* Acquire_Load() const {
|
92
|
-
void* ptr = ptr_;
|
93
|
-
MemoryBarrier();
|
94
|
-
return ptr;
|
95
|
-
}
|
96
|
-
inline void Release_Store(void* v) {
|
97
|
-
MemoryBarrier();
|
98
|
-
ptr_ = v;
|
99
|
-
}
|
100
|
-
inline void* NoBarrier_Load() const {
|
101
|
-
return ptr_;
|
102
|
-
}
|
103
|
-
inline void NoBarrier_Store(void* v) {
|
104
|
-
ptr_ = v;
|
105
|
-
}
|
106
|
-
};
|
107
|
-
|
108
|
-
inline bool Snappy_Compress(const char* input, size_t input_length,
|
109
|
-
std::string* output) {
|
110
|
-
return false;
|
111
|
-
}
|
112
|
-
|
113
|
-
inline bool Snappy_Uncompress(const char* input_data, size_t input_length,
|
114
|
-
std::string* output) {
|
115
|
-
return false;
|
116
|
-
}
|
117
|
-
|
118
|
-
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
|
119
|
-
return false;
|
120
|
-
}
|
121
|
-
|
122
|
-
}
|
123
|
-
}
|
124
|
-
|
125
|
-
#endif // STORAGE_LEVELDB_PORT_PORT_OSX_H_
|