~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/leveldb/port/port_android.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-08 15:54:37 UTC
  • mfrom: (1.1.8) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120608155437-gy3j9k6wzv7w4gn9
Tags: 0.44.1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - d/control: Switch from libcryptopp to libnss as libcryptopp
    is not seeded.
  - d/control,d/rules: Move from python-support to dh_python2.
  - d/patches/manpage_updates*.patch: cherry picked upstream manpage
    updates warning about lack of encryption, per MIR review.
  - d/rules,d/control: Drop radosgw since libfcgi is not in main and
    the code may not be suitable for LTS.
  - d/rules,d/control: Drop tcmalloc since google perftools is not
    in main yet.
  - d/rules,d/control: Drop ceph-fuse entirely per MIR review
    recommendation.
* d/patches/fix-radosgw-tests.patch: Cherry picked patch from upstream
  VCS to fixup tests to conditionally use radosgw if enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_GetUncompressedLength(const char* input, size_t length,
 
130
                                         size_t* result) {
 
131
  return false;
 
132
}
 
133
 
 
134
// TODO(gabor): Implement uncompress
 
135
inline bool Snappy_Uncompress(
 
136
    const char* input_data,
 
137
    size_t input_length,
 
138
    char* output) {
 
139
  return false;
 
140
}
 
141
 
 
142
inline uint64_t ThreadIdentifier() {
 
143
  pthread_t tid = pthread_self();
 
144
  uint64_t r = 0;
 
145
  memcpy(&r, &tid, sizeof(r) < sizeof(tid) ? sizeof(r) : sizeof(tid));
 
146
  return r;
 
147
}
 
148
 
 
149
inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
 
150
  return false;
 
151
}
 
152
 
 
153
}  // namespace port
 
154
}  // namespace leveldb
 
155
 
 
156
#endif  // STORAGE_LEVELDB_PORT_PORT_ANDROID_H_