Blender  V2.93
session_uuid.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_session_uuid.h"
22 
23 #include "BLI_utildefines.h"
24 
25 #include "atomic_ops.h"
26 
27 /* Special value which indicates the UUID has not been assigned yet. */
28 #define BLI_SESSION_UUID_NONE 0
29 
31 
32 /* Denotes last used UUID.
33  * It might eventually overflow, and easiest is to add more bits to it. */
35 
37 {
41  /* Happens when the UUID overflows.
42  *
43  * Just request the UUID once again, hoping that there are not a lot of high-priority threads
44  * which will overflow the counter once again between the previous call and this one.
45  *
46  * NOTE: It is possible to have collisions after such overflow. */
48  }
49  return result;
50 }
51 
53 {
55 }
56 
58 {
59  return lhs->uuid_ == rhs->uuid_;
60 }
61 
63 {
64  return uuid->uuid_;
65 }
66 
67 uint BLI_session_uuid_ghash_hash(const void *uuid_v)
68 {
69  const SessionUUID *uuid = (const SessionUUID *)uuid_v;
70  return uuid->uuid_ & 0xffffffff;
71 }
72 
73 bool BLI_session_uuid_ghash_compare(const void *lhs_v, const void *rhs_v)
74 {
75  const SessionUUID *lhs = (const SessionUUID *)lhs_v;
76  const SessionUUID *rhs = (const SessionUUID *)rhs_v;
77  return BLI_session_uuid_is_equal(lhs, rhs);
78 }
unsigned int uint
Definition: BLI_sys_types.h:83
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE uint64_t atomic_add_and_fetch_uint64(uint64_t *p, uint64_t x)
uint64_t BLI_session_uuid_hash_uint64(const SessionUUID *uuid)
Definition: session_uuid.c:62
bool BLI_session_uuid_ghash_compare(const void *lhs_v, const void *rhs_v)
Definition: session_uuid.c:73
SessionUUID BLI_session_uuid_generate(void)
Definition: session_uuid.c:36
uint BLI_session_uuid_ghash_hash(const void *uuid_v)
Definition: session_uuid.c:67
bool BLI_session_uuid_is_equal(const SessionUUID *lhs, const SessionUUID *rhs)
Definition: session_uuid.c:57
static SessionUUID global_session_uuid
Definition: session_uuid.c:34
#define BLI_SESSION_UUID_NONE
Definition: session_uuid.c:28
static const SessionUUID global_session_uuid_none
Definition: session_uuid.c:30
bool BLI_session_uuid_is_generated(const SessionUUID *uuid)
Definition: session_uuid.c:52
unsigned __int64 uint64_t
Definition: stdint.h:93