Skip to content

Commit 89796d0

Browse files
mcollinaBethGriggs
authored andcommitted
deps: bump HdrHistogram_C to 0.11.2
Release tag: https://github.com/HdrHistogram/HdrHistogram_c/releases/tag/0.11.2Fixes: #39450 PR-URL: #39462 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 72ad6d3 commit 89796d0

3 files changed

Lines changed: 379 additions & 54 deletions

File tree

‎deps/histogram/src/hdr_atomic.h‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* hdr_atomic.h
3+
* Written by Philip Orwig and released to the public domain,
4+
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
5+
*/
6+
7+
#ifndefHDR_ATOMIC_H__
8+
#defineHDR_ATOMIC_H__
9+
10+
11+
#if defined(_MSC_VER)
12+
13+
#include<stdint.h>
14+
#include<intrin.h>
15+
#include<stdbool.h>
16+
17+
staticvoid __inline *hdr_atomic_load_pointer(void**pointer)
18+
{
19+
_ReadBarrier();
20+
return*pointer;
21+
}
22+
23+
staticvoidhdr_atomic_store_pointer(void**pointer, void*value)
24+
{
25+
_WriteBarrier();
26+
*pointer=value;
27+
}
28+
29+
staticint64_t __inline hdr_atomic_load_64(int64_t*field)
30+
{
31+
_ReadBarrier();
32+
return*field;
33+
}
34+
35+
staticvoid __inline hdr_atomic_store_64(int64_t*field, int64_tvalue)
36+
{
37+
_WriteBarrier();
38+
*field=value;
39+
}
40+
41+
staticint64_t __inline hdr_atomic_exchange_64(volatileint64_t*field, int64_tvalue)
42+
{
43+
#if defined(_WIN64)
44+
return_InterlockedExchange64(field, value);
45+
#else
46+
int64_tcomparand;
47+
int64_tinitial_value=*field;
48+
do
49+
{
50+
comparand=initial_value;
51+
initial_value=_InterlockedCompareExchange64(field, value, comparand);
52+
}
53+
while (comparand!=initial_value);
54+
55+
returninitial_value;
56+
#endif
57+
}
58+
59+
staticint64_t __inline hdr_atomic_add_fetch_64(volatileint64_t*field, int64_tvalue)
60+
{
61+
#if defined(_WIN64)
62+
return_InterlockedExchangeAdd64(field, value) +value;
63+
#else
64+
int64_tcomparand;
65+
int64_tinitial_value=*field;
66+
do
67+
{
68+
comparand=initial_value;
69+
initial_value=_InterlockedCompareExchange64(field, comparand+value, comparand);
70+
}
71+
while (comparand!=initial_value);
72+
73+
returninitial_value+value;
74+
#endif
75+
}
76+
77+
staticbool __inline hdr_atomic_compare_exchange_64(volatileint64_t*field, int64_t*expected, int64_tdesired)
78+
{
79+
return*expected==_InterlockedCompareExchange64(field, desired, *expected);
80+
}
81+
82+
#elif defined(__ATOMIC_SEQ_CST)
83+
84+
#definehdr_atomic_load_pointer(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
85+
#definehdr_atomic_store_pointer(f,v) __atomic_store_n(f,v, __ATOMIC_SEQ_CST)
86+
#definehdr_atomic_load_64(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
87+
#definehdr_atomic_store_64(f,v) __atomic_store_n(f,v, __ATOMIC_SEQ_CST)
88+
#definehdr_atomic_exchange_64(f,i) __atomic_exchange_n(f,i, __ATOMIC_SEQ_CST)
89+
#definehdr_atomic_add_fetch_64(field, value) __atomic_add_fetch(field, value, __ATOMIC_SEQ_CST)
90+
#definehdr_atomic_compare_exchange_64(field, expected, desired) __atomic_compare_exchange_n(field, expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
91+
92+
#elif defined(__x86_64__)
93+
94+
#include<stdint.h>
95+
#include<stdbool.h>
96+
97+
staticinlinevoid*hdr_atomic_load_pointer(void**pointer)
98+
{
99+
void*p=*pointer;
100+
asm volatile ("" ::: "memory");
101+
returnp;
102+
}
103+
104+
staticinlinevoidhdr_atomic_store_pointer(void**pointer, void*value)
105+
{
106+
asm volatile ("lock; xchgq %0, %1" : "+q" (value), "+m" (*pointer));
107+
}
108+
109+
staticinlineint64_thdr_atomic_load_64(int64_t*field)
110+
{
111+
int64_ti=*field;
112+
asm volatile ("" ::: "memory");
113+
returni;
114+
}
115+
116+
staticinlinevoidhdr_atomic_store_64(int64_t*field, int64_tvalue)
117+
{
118+
asm volatile ("lock; xchgq %0, %1" : "+q" (value), "+m" (*field));
119+
}
120+
121+
staticinlineint64_thdr_atomic_exchange_64(volatileint64_t*field, int64_tvalue)
122+
{
123+
int64_tresult=0;
124+
asm volatile ("lock; xchgq %1, %2" : "=r" (result), "+q" (value), "+m" (*field));
125+
returnresult;
126+
}
127+
128+
staticinlineint64_thdr_atomic_add_fetch_64(volatileint64_t*field, int64_tvalue)
129+
{
130+
return__sync_add_and_fetch(field, value);
131+
}
132+
133+
staticinlineboolhdr_atomic_compare_exchange_64(volatileint64_t*field, int64_t*expected, int64_tdesired)
134+
{
135+
int64_toriginal;
136+
asm volatile( "lock; cmpxchgq %2, %1" : "=a"(original), "+m"(*field) : "q"(desired), "0"(*expected));
137+
returnoriginal==*expected;
138+
}
139+
140+
#else
141+
142+
#error "Unable to determine atomic operations for your platform"
143+
144+
#endif
145+
146+
#endif/* HDR_ATOMIC_H__ */

0 commit comments

Comments
 (0)