[atomic] Add compiler memory_r_barrier

https://github.com/harfbuzz/harfbuzz/issues/3728
This commit is contained in:
Behdad Esfahbod 2022-07-17 16:47:16 -06:00
parent f3151b6582
commit f0707e2348
2 changed files with 21 additions and 14 deletions

View File

@ -111,6 +111,13 @@ _hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N)
#endif
/* This we always use std::atomic for; and should never be disabled. */
#include <atomic>
#ifndef _hb_compiler_memory_r_barrier
#define _hb_compiler_memory_r_barrier() std::atomic_signal_fence (std::memory_order_acquire)
#endif
#ifndef _hb_memory_r_barrier
#define _hb_memory_r_barrier() _hb_memory_barrier ()
#endif

View File

@ -459,7 +459,7 @@ struct UnsizedArrayOf
unsigned int i = (unsigned int) i_;
const Type *p = &arrayZ[i];
if (unlikely (p < arrayZ)) return Null (Type); /* Overflowed. */
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return *p;
}
Type& operator [] (int i_)
@ -467,7 +467,7 @@ struct UnsizedArrayOf
unsigned int i = (unsigned int) i_;
Type *p = &arrayZ[i];
if (unlikely (p < arrayZ)) return Crap (Type); /* Overflowed. */
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return *p;
}
@ -561,7 +561,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo<Type, OffsetType, has_
unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return this+*p;
}
Type& operator [] (int i_)
@ -569,7 +569,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo<Type, OffsetType, has_
unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return this+*p;
}
@ -620,14 +620,14 @@ struct ArrayOf
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= len)) return Null (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i];
}
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= len)) return Crap (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i];
}
@ -760,14 +760,14 @@ struct List16OfOffsetTo : ArrayOf<OffsetTo<Type, OffsetType>, HBUINT16>
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= this->len)) return Null (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return this+this->arrayZ[i];
}
const Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= this->len)) return Crap (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return this+this->arrayZ[i];
}
@ -805,14 +805,14 @@ struct HeadlessArrayOf
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= lenP1 || !i)) return Null (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i-1];
}
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= lenP1 || !i)) return Crap (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i-1];
}
unsigned int get_size () const
@ -891,14 +891,14 @@ struct ArrayOfM1
{
unsigned int i = (unsigned int) i_;
if (unlikely (i > lenM1)) return Null (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i];
}
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i > lenM1)) return Crap (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return arrayZ[i];
}
unsigned int get_size () const
@ -1078,14 +1078,14 @@ struct VarSizedBinSearchArrayOf
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= get_length ())) return Null (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
}
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= get_length ())) return Crap (Type);
_hb_memory_r_barrier ();
_hb_compiler_memory_r_barrier ();
return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
}
unsigned int get_length () const