]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/port/port_example.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
10 // This file contains the specification, but not the implementations,
11 // of the types/operations/etc. that should be defined by a platform
12 // specific port_<platform>.h file. Use this file as a reference for
13 // how to port this package to a new platform.
17 namespace ROCKSDB_NAMESPACE
{
20 // TODO(jorlow): Many of these belong more in the environment class rather than
21 // here. We should try moving them and see if it affects perf.
23 // The following boolean constant must be true on a little-endian machine
24 // and false otherwise.
25 static const bool kLittleEndian
= true /* or some other expression */;
27 // ------------------ Threading -------------------
29 // A Mutex represents an exclusive lock.
35 // Lock the mutex. Waits until other lockers have exited.
36 // Will deadlock if the mutex is already locked by this thread.
40 // REQUIRES: This mutex was locked by this thread.
43 // Optionally crash if this thread does not hold this mutex.
44 // The implementation must be fast, especially if NDEBUG is
45 // defined. The implementation is allowed to skip all checks.
51 explicit CondVar(Mutex
* mu
);
54 // Atomically release *mu and block on this condition variable until
55 // either a call to SignalAll(), or a call to Signal() that picks
56 // this thread to wakeup.
57 // REQUIRES: this thread holds *mu
60 // If there are some threads waiting, wake up at least one of them.
63 // Wake up all waiting threads.
67 // Thread-safe initialization.
69 // static port::OnceType init_control = LEVELDB_ONCE_INIT;
70 // static void Initializer() { ... do something ...; }
72 // port::InitOnce(&init_control, &Initializer);
73 typedef intptr_t OnceType
;
74 #define LEVELDB_ONCE_INIT 0
75 extern void InitOnce(port::OnceType
*, void (*initializer
)());
77 // ------------------ Compression -------------------
79 // Store the snappy compression of "input[0,input_length-1]" in *output.
80 // Returns false if snappy is not supported by this port.
81 extern bool Snappy_Compress(const char* input
, size_t input_length
,
84 // If input[0,input_length-1] looks like a valid snappy compressed
85 // buffer, store the size of the uncompressed data in *result and
86 // return true. Else return false.
87 extern bool Snappy_GetUncompressedLength(const char* input
, size_t length
,
90 // Attempt to snappy uncompress input[0,input_length-1] into *output.
91 // Returns true if successful, false if the input is invalid lightweight
94 // REQUIRES: at least the first "n" bytes of output[] must be writable
95 // where "n" is the result of a successful call to
96 // Snappy_GetUncompressedLength.
97 extern bool Snappy_Uncompress(const char* input_data
, size_t input_length
,
101 } // namespace ROCKSDB_NAMESPACE