NvBlastTkGUID.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTTKGUID_H
30 #define NVBLASTTKGUID_H
31 
32 #include "NvPreprocessor.h"
33 
34 #if NV_WINDOWS_FAMILY
35 #include <rpc.h>
36 #else
37 //#include <uuid/uuid.h>
38 #include "NvBlastTime.h"
39 #endif
40 
41 #include "PsHash.h"
42 
43 namespace Nv
44 {
45 namespace Blast
46 {
47 
48 #if NV_WINDOWS_FAMILY
49 
51 {
52  NV_UNUSED(ptr);
53 
54  NV_COMPILE_TIME_ASSERT(sizeof(UUID) == sizeof(NvBlastID));
55 
56  NvBlastID guid;
57  UuidCreate(reinterpret_cast<UUID*>(&guid));
58 
59  return guid;
60 }
61 
62 #else
63 
65 {
66 // NV_COMPILE_TIME_ASSERT(sizeof(uuid_t) == sizeof(NvBlastID));
67  Time time;
68 
69  NvBlastID guid;
70  // uuid_generate_random(reinterpret_cast<uuid_t&>(guid));
71 
72  *reinterpret_cast<uint64_t*>(guid.data) = reinterpret_cast<uintptr_t>(ptr);
73  *reinterpret_cast<int64_t*>(guid.data + 8) = time.getLastTickCount();
74 
75  return guid;
76 }
77 
78 #endif
79 
80 
89 NV_INLINE bool TkGUIDsEqual(const NvBlastID* id1, const NvBlastID* id2)
90 {
91  return !memcmp(id1, id2, sizeof(NvBlastID));
92 }
93 
94 
101 {
102  memset(id, 0, sizeof(NvBlastID));
103 }
104 
105 
113 {
114  return *reinterpret_cast<const uint64_t*>(&id->data[0]) == 0 && *reinterpret_cast<const uint64_t*>(&id->data[8]) == 0;
115 }
116 
117 } // namespace Blast
118 } // namespace Nv
119 
120 
121 namespace physx
122 {
123 namespace shdfnd
124 {
125 
126 // hash specialization for NvBlastID
127 template <>
128 struct Hash<NvBlastID>
129 {
130  uint32_t operator()(const NvBlastID& k) const
131  {
132  // "DJB" string hash
133  uint32_t h = 5381;
134  for (uint32_t i = 0; i < sizeof(k.data) / sizeof(k.data[0]); ++i)
135  h = ((h << 5) + h) ^ uint32_t(k.data[i]);
136  return h;
137  }
138  bool equal(const NvBlastID& k0, const NvBlastID& k1) const
139  {
140  return Nv::Blast::TkGUIDsEqual(&k0, &k1);
141  }
142 };
143 
144 } // namespace shdfnd
145 } // namespace physx
146 
147 
148 #endif // #ifndef NVBLASTTKGUID_H
Definition: NvBlastExtApexSharedParts.h:34
#define NV_COMPILE_TIME_ASSERT(exp)
Definition: NvPreprocessor.h:444
int64_t getLastTickCount() const
Definition: NvBlastTime.h:57
NV_CUDA_CALLABLE NV_INLINE void NV_UNUSED(T const &)
Definition: NvPreprocessor.h:476
NV_INLINE void TkGUIDReset(NvBlastID *id)
Definition: NvBlastTkGUID.h:100
char data[16]
Definition: NvBlastTypes.h:71
NV_INLINE bool TkGUIDIsZero(const NvBlastID *id)
Definition: NvBlastTkGUID.h:112
bool equal(const NvBlastID &k0, const NvBlastID &k1) const
Definition: NvBlastTkGUID.h:138
uint32_t operator()(const NvBlastID &k) const
Definition: NvBlastTkGUID.h:130
NV_INLINE NvBlastID TkGenerateGUID(void *ptr)
Definition: NvBlastTkGUID.h:64
#define NV_INLINE
Definition: NvPreprocessor.h:350
Definition: NvBlastTypes.h:69
Definition: NvBlastTime.h:40
NV_INLINE bool TkGUIDsEqual(const NvBlastID *id1, const NvBlastID *id2)
Definition: NvBlastTkGUID.h:89
Definition: NvBlastArray.h:37