]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/random.cc
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.
7 #include "util/random.h"
14 #include "port/likely.h"
15 #include "util/thread_local.h"
17 #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
18 #define STORAGE_DECL static __thread
20 #define STORAGE_DECL static
25 Random
* Random::GetTLSInstance() {
26 STORAGE_DECL Random
* tls_instance
;
27 STORAGE_DECL
std::aligned_storage
<sizeof(Random
)>::type tls_instance_bytes
;
29 auto rv
= tls_instance
;
30 if (UNLIKELY(rv
== nullptr)) {
31 size_t seed
= std::hash
<std::thread::id
>()(std::this_thread::get_id());
32 rv
= new (&tls_instance_bytes
) Random((uint32_t)seed
);
38 } // namespace rocksdb