]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/port/win/port_win.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same 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 // See port_example.h for documentation for the following types/functions.
12 #ifndef STORAGE_LEVELDB_PORT_PORT_WIN_H_
13 #define STORAGE_LEVELDB_PORT_PORT_WIN_H_
15 // Always want minimum headers
16 #ifndef WIN32_LEAN_AND_MEAN
17 #define WIN32_LEAN_AND_MEAN
20 // Assume that for everywhere
21 #undef PLATFORM_IS_LITTLE_ENDIAN
22 #define PLATFORM_IS_LITTLE_ENDIAN true
29 #include <condition_variable>
33 #include "port/win/win_thread.h"
35 #include "rocksdb/options.h"
44 #define strcasecmp _stricmp
50 #ifndef _SSIZE_T_DEFINED
51 typedef SSIZE_T ssize_t
;
54 // size_t printf formatting named in the manner of C99 standard formatting
55 // strings such as PRIu64
56 // in fact, we could use that one
57 #ifndef ROCKSDB_PRIszt
58 #define ROCKSDB_PRIszt "Iu"
62 #define __attribute__(A)
64 // Thread local storage on Linux
65 // There is thread_local in C++11
67 #define __thread __declspec(thread)
72 #ifndef PLATFORM_IS_LITTLE_ENDIAN
73 #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
78 #define PREFETCH(addr, rw, locality)
83 #if (defined _MSC_VER) && (_MSC_VER >= 1900)
85 #define ROCKSDB_NOEXCEPT noexcept
87 // For use at db/file_indexer.h kLevelMaxIndex
88 const int kMaxInt32
= std::numeric_limits
<int>::max();
89 const uint64_t kMaxUint64
= std::numeric_limits
<uint64_t>::max();
90 const int64_t kMaxInt64
= std::numeric_limits
<int64_t>::max();
92 const size_t kMaxSizet
= std::numeric_limits
<size_t>::max();
97 #define snprintf _snprintf
99 #define ROCKSDB_NOEXCEPT
100 // std::numeric_limits<size_t>::max() is not constexpr just yet
101 // therefore, use the same limits
103 // For use at db/file_indexer.h kLevelMaxIndex
104 const int kMaxInt32
= INT32_MAX
;
105 const int64_t kMaxInt64
= INT64_MAX
;
106 const uint64_t kMaxUint64
= UINT64_MAX
;
109 const size_t kMaxSizet
= UINT64_MAX
;
111 const size_t kMaxSizet
= UINT_MAX
;
116 const bool kLittleEndian
= true;
123 /* implicit */ Mutex(bool adaptive
= false)
145 // this will assert if the mutex is not locked
146 // it does NOT verify that mutex is held by a calling thread
153 // Mutex is move only with lock ownership transfer
154 Mutex(const Mutex
&) = delete;
155 void operator=(const Mutex
&) = delete;
159 friend class CondVar
;
161 std::mutex
& getLock() {
173 RWMutex() { InitializeSRWLock(&srwLock_
); }
175 void ReadLock() { AcquireSRWLockShared(&srwLock_
); }
177 void WriteLock() { AcquireSRWLockExclusive(&srwLock_
); }
179 void ReadUnlock() { ReleaseSRWLockShared(&srwLock_
); }
181 void WriteUnlock() { ReleaseSRWLockExclusive(&srwLock_
); }
188 // No copying allowed
189 RWMutex(const RWMutex
&);
190 void operator=(const RWMutex
&);
195 explicit CondVar(Mutex
* mu
) : mu_(mu
) {
200 bool TimedWait(uint64_t expiration_time
);
204 // Condition var is not copy/move constructible
205 CondVar(const CondVar
&) = delete;
206 CondVar
& operator=(const CondVar
&) = delete;
208 CondVar(CondVar
&&) = delete;
209 CondVar
& operator=(CondVar
&&) = delete;
212 std::condition_variable cv_
;
216 // Wrapper around the platform efficient
217 // or otherwise preferrable implementation
218 using Thread
= WindowsThread
;
220 // OnceInit type helps emulate
221 // Posix semantics with initialization
222 // adopted in the project
228 OnceType(const Init
&) {}
229 OnceType(const OnceType
&) = delete;
230 OnceType
& operator=(const OnceType
&) = delete;
232 std::once_flag flag_
;
235 #define LEVELDB_ONCE_INIT port::OnceType::Init()
236 extern void InitOnce(OnceType
* once
, void (*initializer
)());
238 #define CACHE_LINE_SIZE 64U
240 static inline void AsmVolatilePause() {
241 #if defined(_M_IX86) || defined(_M_X64)
244 // it would be nice to get "wfe" on ARM here
247 extern int PhysicalCoreID();
249 // For Thread Local Storage abstraction
250 typedef DWORD pthread_key_t
;
252 inline int pthread_key_create(pthread_key_t
* key
, void (*destructor
)(void*)) {
256 pthread_key_t k
= TlsAlloc();
257 if (TLS_OUT_OF_INDEXES
== k
) {
265 inline int pthread_key_delete(pthread_key_t key
) {
272 inline int pthread_setspecific(pthread_key_t key
, const void* value
) {
273 if (!TlsSetValue(key
, const_cast<void*>(value
))) {
279 inline void* pthread_getspecific(pthread_key_t key
) {
280 void* result
= TlsGetValue(key
);
282 if (GetLastError() != ERROR_SUCCESS
) {
291 // UNIX equiv although errno numbers will be off
292 // using C-runtime to implement. Note, this does not
293 // feel space with zeros in case the file is extended.
294 int truncate(const char* path
, int64_t length
);
295 void Crash(const std::string
& srcfile
, int srcline
);
296 extern int GetMaxOpenFiles();
300 using port::pthread_key_t
;
301 using port::pthread_key_create
;
302 using port::pthread_key_delete
;
303 using port::pthread_setspecific
;
304 using port::pthread_getspecific
;
305 using port::truncate
;
307 } // namespace rocksdb
309 #endif // STORAGE_LEVELDB_PORT_PORT_WIN_H_