port/port_posix.h

filter: Statementstmt 100% 1 / 1 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 1 / 1 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« port/atomic_pointer.h ↑ Summary table/block.h »
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_POSIX_H_
8 #define STORAGE_LEVELDB_PORT_PORT_POSIX_H_
9  
10 #if defined(OS_MACOSX) || defined(OS_FREEBSD)
11 #include <machine/endian.h>
12 #elif defined(OS_SOLARIS)
13 #include <sys/isa_defs.h>
14 #ifdef _LITTLE_ENDIAN
15 #define LITTLE_ENDIAN
16 #else
17 #define BIG_ENDIAN
18 #endif
19 #else
20 #include <endian.h>
21 #endif
22 #include <pthread.h>
23 #ifdef SNAPPY
24 #include <snappy.h>
25 #endif
26 #include <stdint.h>
27 #include <string>
28 #include "port/atomic_pointer.h"
29  
30 #ifdef LITTLE_ENDIAN
31 #define IS_LITTLE_ENDIAN true
32 #else
33 #define IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
34 #endif
35  
36 #if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD)
37 #define fread_unlocked fread
38 #define fwrite_unlocked fwrite
39 #define fflush_unlocked fflush
40 #endif
41  
42 #if defined(OS_MACOSX) || defined(OS_FREEBSD)
43 #define fdatasync fsync
44 #endif
45  
46 namespace leveldb {
47 namespace port {
48  
49 static const bool kLittleEndian = IS_LITTLE_ENDIAN;
50  
51 class CondVar;
52  
53 class Mutex {
54 public:
55 Mutex();
56 ~Mutex();
57  
58 void Lock();
59 void Unlock();
60 27 void AssertHeld() { }
61  
62 private:
63 friend class CondVar;
64 pthread_mutex_t mu_;
65  
66 // No copying
67 Mutex(const Mutex&);
68 void operator=(const Mutex&);
69 };
70  
71 class CondVar {
72 public:
73 explicit CondVar(Mutex* mu);
74 ~CondVar();
75 void Wait();
76 void Signal();
77 void SignalAll();
78 private:
79 pthread_cond_t cv_;
80 Mutex* mu_;
81 };
82  
83 inline bool Snappy_Compress(const char* input, size_t length,
84 ::std::string* output) {
85 #ifdef SNAPPY
86 output->resize(snappy::MaxCompressedLength(length));
87 size_t outlen;
88 snappy::RawCompress(input, length, &(*output)[0], &outlen);
89 output->resize(outlen);
90 return true;
91 #endif
92  
93 return false;
94 }
95  
96 inline bool Snappy_GetUncompressedLength(const char* input, size_t length,
97 size_t* result) {
98 #ifdef SNAPPY
99 return snappy::GetUncompressedLength(input, length, result);
100 #else
101 return false;
102 #endif
103 }
104  
105 inline bool Snappy_Uncompress(const char* input, size_t length,
106 char* output) {
107 #ifdef SNAPPY
108 return snappy::RawUncompress(input, length, output);
109 #else
110 return false;
111 #endif
112 }
113  
114 inline bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg) {
115 return false;
116 }
117  
118 } // namespace port
119 } // namespace leveldb
120  
121 #endif // STORAGE_LEVELDB_PORT_PORT_POSIX_H_
« port/atomic_pointer.h ↑ Summary table/block.h »