Remove const from _Atomic vars to make Clang happy
Clang does not allow using C11's atomic_load on const _Atomic variables. Previously it just disabled use of C11 atomics if atomic_load didn't work on a const _Atomic variable, but I think I'd prefer to have Clang use C11 atomics for the added features (more explicit memory ordering) even if it means a few instances of breaking const.
This commit is contained in:
parent
d85177cd3e
commit
a0a41921fc
@ -1276,7 +1276,7 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop
|
||||
|
||||
static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean force)
|
||||
{
|
||||
const ALbufferlistitem *BufferListItem;
|
||||
ALbufferlistitem *BufferListItem;
|
||||
struct ALvoiceProps *props;
|
||||
|
||||
props = ATOMIC_EXCHANGE_PTR(&voice->Update, NULL, almemory_order_acq_rel);
|
||||
|
@ -103,16 +103,16 @@ void ll_ringbuffer_reset(ll_ringbuffer_t *rb)
|
||||
* elements in front of the read pointer and behind the write pointer. */
|
||||
size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb)
|
||||
{
|
||||
size_t w = ATOMIC_LOAD(&rb->write_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
size_t r = ATOMIC_LOAD(&rb->read_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
size_t w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
|
||||
size_t r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
|
||||
return (w-r) & rb->size_mask;
|
||||
}
|
||||
/* Return the number of elements available for writing. This is the number of
|
||||
* elements in front of the write pointer and behind the read pointer. */
|
||||
size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb)
|
||||
{
|
||||
size_t w = ATOMIC_LOAD(&rb->write_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
size_t r = ATOMIC_LOAD(&rb->read_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
size_t w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
|
||||
size_t r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
|
||||
return (r-w-1) & rb->size_mask;
|
||||
}
|
||||
|
||||
@ -256,8 +256,10 @@ void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data
|
||||
size_t cnt2;
|
||||
size_t w, r;
|
||||
|
||||
w = ATOMIC_LOAD(&rb->write_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
r = ATOMIC_LOAD(&rb->read_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
|
||||
r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
|
||||
w &= rb->size_mask;
|
||||
r &= rb->size_mask;
|
||||
free_cnt = (w-r) & rb->size_mask;
|
||||
|
||||
cnt2 = r + free_cnt;
|
||||
@ -289,8 +291,10 @@ void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_dat
|
||||
size_t cnt2;
|
||||
size_t w, r;
|
||||
|
||||
w = ATOMIC_LOAD(&rb->write_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
r = ATOMIC_LOAD(&rb->read_ptr, almemory_order_acquire) & rb->size_mask;
|
||||
w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
|
||||
r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
|
||||
w &= rb->size_mask;
|
||||
r &= rb->size_mask;
|
||||
free_cnt = (r-w-1) & rb->size_mask;
|
||||
|
||||
cnt2 = w + free_cnt;
|
||||
|
@ -264,12 +264,11 @@ HAVE_C11_ALIGNAS)
|
||||
# Check if we have C11 _Atomic
|
||||
CHECK_C_SOURCE_COMPILES(
|
||||
"#include <stdatomic.h>
|
||||
const int _Atomic foo = ATOMIC_VAR_INIT(~0);
|
||||
int _Atomic bar = ATOMIC_VAR_INIT(0);
|
||||
int _Atomic foo = ATOMIC_VAR_INIT(0);
|
||||
int main()
|
||||
{
|
||||
atomic_fetch_add(&bar, 2);
|
||||
return atomic_load(&foo);
|
||||
atomic_fetch_add(&foo, 2);
|
||||
return 0;
|
||||
}"
|
||||
HAVE_C11_ATOMIC)
|
||||
|
||||
|
@ -204,6 +204,20 @@ AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* This helps cast away the const-ness of a pointer without accidentally
|
||||
* changing the pointer type. This is necessary due to Clang's inability to use
|
||||
* atomic_load on a const _Atomic variable.
|
||||
*/
|
||||
#define CONST_CAST(T, V) __extension__({ \
|
||||
const T _tmp = (V); \
|
||||
(T)_tmp; \
|
||||
})
|
||||
#else
|
||||
#define CONST_CAST(T, V) ((T)(V))
|
||||
#endif
|
||||
|
||||
|
||||
typedef ALint64SOFT ALint64;
|
||||
typedef ALuint64SOFT ALuint64;
|
||||
|
||||
|
@ -1407,7 +1407,8 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
|
||||
while(BufferList && BufferList != Current)
|
||||
{
|
||||
played++;
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
*values = played;
|
||||
}
|
||||
@ -3177,7 +3178,8 @@ static ALint64 GetSourceSampleOffset(ALsource *Source, ALCcontext *context, ALui
|
||||
{
|
||||
if(BufferList->buffer)
|
||||
readPos += (ALuint64)BufferList->buffer->SampleLen << 32;
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
readPos = minu64(readPos, U64(0x7fffffffffffffff));
|
||||
}
|
||||
@ -3233,13 +3235,15 @@ static ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, ALuint
|
||||
if(!BufferFmt) BufferFmt = buffer;
|
||||
readPos += (ALuint64)buffer->SampleLen << FRACTIONBITS;
|
||||
}
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
|
||||
while(BufferList && !BufferFmt)
|
||||
{
|
||||
BufferFmt = BufferList->buffer;
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
assert(BufferFmt != NULL);
|
||||
|
||||
@ -3302,7 +3306,8 @@ static ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *conte
|
||||
totalBufferLen += buffer->SampleLen;
|
||||
if(!readFin) readPos += buffer->SampleLen;
|
||||
}
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
assert(BufferFmt != NULL);
|
||||
|
||||
@ -3421,7 +3426,8 @@ static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac
|
||||
{
|
||||
if((BufferFmt=BufferList->buffer) != NULL)
|
||||
break;
|
||||
BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
|
||||
BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
|
||||
almemory_order_relaxed);
|
||||
}
|
||||
if(!BufferFmt)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user