mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
openal-soft updates
This commit is contained in:
parent
d6f6bc65a5
commit
925d8b27cf
149 changed files with 22293 additions and 16887 deletions
|
|
@ -97,6 +97,31 @@ extern "C" {
|
|||
|
||||
#ifndef AL_EXT_MCFORMATS
|
||||
#define AL_EXT_MCFORMATS 1
|
||||
/* Provides support for surround sound buffer formats with 8, 16, and 32-bit
|
||||
* samples.
|
||||
*
|
||||
* QUAD8: Unsigned 8-bit, Quadraphonic (Front Left, Front Right, Rear Left,
|
||||
* Rear Right).
|
||||
* QUAD16: Signed 16-bit, Quadraphonic.
|
||||
* QUAD32: 32-bit float, Quadraphonic.
|
||||
* REAR8: Unsigned 8-bit, Rear Stereo (Rear Left, Rear Right).
|
||||
* REAR16: Signed 16-bit, Rear Stereo.
|
||||
* REAR32: 32-bit float, Rear Stereo.
|
||||
* 51CHN8: Unsigned 8-bit, 5.1 Surround (Front Left, Front Right, Front Center,
|
||||
* LFE, Side Left, Side Right). Note that some audio systems may label
|
||||
* 5.1's Side channels as Rear or Surround; they are equivalent for the
|
||||
* purposes of this extension.
|
||||
* 51CHN16: Signed 16-bit, 5.1 Surround.
|
||||
* 51CHN32: 32-bit float, 5.1 Surround.
|
||||
* 61CHN8: Unsigned 8-bit, 6.1 Surround (Front Left, Front Right, Front Center,
|
||||
* LFE, Rear Center, Side Left, Side Right).
|
||||
* 61CHN16: Signed 16-bit, 6.1 Surround.
|
||||
* 61CHN32: 32-bit float, 6.1 Surround.
|
||||
* 71CHN8: Unsigned 8-bit, 7.1 Surround (Front Left, Front Right, Front Center,
|
||||
* LFE, Rear Left, Rear Right, Side Left, Side Right).
|
||||
* 71CHN16: Signed 16-bit, 7.1 Surround.
|
||||
* 71CHN32: 32-bit float, 7.1 Surround.
|
||||
*/
|
||||
#define AL_FORMAT_QUAD8 0x1204
|
||||
#define AL_FORMAT_QUAD16 0x1205
|
||||
#define AL_FORMAT_QUAD32 0x1206
|
||||
|
|
@ -395,6 +420,16 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device);
|
|||
|
||||
#ifndef AL_EXT_BFORMAT
|
||||
#define AL_EXT_BFORMAT 1
|
||||
/* Provides support for B-Format ambisonic buffers (first-order, FuMa scaling
|
||||
* and layout).
|
||||
*
|
||||
* BFORMAT2D_8: Unsigned 8-bit, 3-channel non-periphonic (WXY).
|
||||
* BFORMAT2D_16: Signed 16-bit, 3-channel non-periphonic (WXY).
|
||||
* BFORMAT2D_FLOAT32: 32-bit float, 3-channel non-periphonic (WXY).
|
||||
* BFORMAT3D_8: Unsigned 8-bit, 4-channel periphonic (WXYZ).
|
||||
* BFORMAT3D_16: Signed 16-bit, 4-channel periphonic (WXYZ).
|
||||
* BFORMAT3D_FLOAT32: 32-bit float, 4-channel periphonic (WXYZ).
|
||||
*/
|
||||
#define AL_FORMAT_BFORMAT2D_8 0x20021
|
||||
#define AL_FORMAT_BFORMAT2D_16 0x20022
|
||||
#define AL_FORMAT_BFORMAT2D_FLOAT32 0x20023
|
||||
|
|
@ -436,6 +471,44 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi
|
|||
#define AL_GAIN_LIMIT_SOFT 0x200E
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_source_resampler
|
||||
#define AL_SOFT_source_resampler
|
||||
#define AL_NUM_RESAMPLERS_SOFT 0x1210
|
||||
#define AL_DEFAULT_RESAMPLER_SOFT 0x1211
|
||||
#define AL_SOURCE_RESAMPLER_SOFT 0x1212
|
||||
#define AL_RESAMPLER_NAME_SOFT 0x1213
|
||||
typedef const ALchar* (AL_APIENTRY*LPALGETSTRINGISOFT)(ALenum pname, ALsizei index);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_source_spatialize
|
||||
#define AL_SOFT_source_spatialize
|
||||
#define AL_SOURCE_SPATIALIZE_SOFT 0x1214
|
||||
#define AL_AUTO_SOFT 0x0002
|
||||
#endif
|
||||
|
||||
#ifndef ALC_SOFT_output_limiter
|
||||
#define ALC_SOFT_output_limiter
|
||||
#define ALC_OUTPUT_LIMITER_SOFT 0x199A
|
||||
#endif
|
||||
|
||||
#ifndef ALC_SOFT_device_clock
|
||||
#define ALC_SOFT_device_clock 1
|
||||
typedef int64_t ALCint64SOFT;
|
||||
typedef uint64_t ALCuint64SOFT;
|
||||
#define ALC_DEVICE_CLOCK_SOFT 0x1600
|
||||
#define ALC_DEVICE_LATENCY_SOFT 0x1601
|
||||
#define ALC_DEVICE_CLOCK_LATENCY_SOFT 0x1602
|
||||
#define AL_SAMPLE_OFFSET_CLOCK_SOFT 0x1202
|
||||
#define AL_SEC_OFFSET_CLOCK_SOFT 0x1203
|
||||
typedef void (ALC_APIENTRY*LPALCGETINTEGER64VSOFT)(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef AL_ALIGN_H
|
||||
#define AL_ALIGN_H
|
||||
|
||||
#if defined(HAVE_STDALIGN_H) && defined(HAVE_C11_ALIGNAS)
|
||||
#include <stdalign.h>
|
||||
#endif
|
||||
|
||||
#ifndef alignas
|
||||
#if defined(IN_IDE_PARSER)
|
||||
/* KDevelop has problems with our align macro, so just use nothing for parsing. */
|
||||
#define alignas(x)
|
||||
#elif defined(HAVE_C11_ALIGNAS)
|
||||
#define alignas _Alignas
|
||||
#else
|
||||
/* NOTE: Our custom ALIGN macro can't take a type name like alignas can. For
|
||||
* maximum compatibility, only provide constant integer values to alignas. */
|
||||
#define alignas(_x) ALIGN(_x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* AL_ALIGN_H */
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef AL_MALLOC_H
|
||||
#define AL_MALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *al_malloc(size_t alignment, size_t size);
|
||||
void *al_calloc(size_t alignment, size_t size);
|
||||
void al_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_MALLOC_H */
|
||||
|
|
@ -1,317 +0,0 @@
|
|||
#ifndef AL_ATOMIC_H
|
||||
#define AL_ATOMIC_H
|
||||
|
||||
#include "static_assert.h"
|
||||
#include "bool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Atomics using C11 */
|
||||
#ifdef HAVE_C11_ATOMIC
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
#define almemory_order memory_order
|
||||
#define almemory_order_relaxed memory_order_relaxed
|
||||
#define almemory_order_consume memory_order_consume
|
||||
#define almemory_order_acquire memory_order_acquire
|
||||
#define almemory_order_release memory_order_release
|
||||
#define almemory_order_acq_rel memory_order_acq_rel
|
||||
#define almemory_order_seq_cst memory_order_seq_cst
|
||||
|
||||
#define ATOMIC(T) T _Atomic
|
||||
|
||||
#define ATOMIC_INIT(_val, _newval) atomic_init((_val), (_newval))
|
||||
#define ATOMIC_INIT_STATIC(_newval) ATOMIC_VAR_INIT(_newval)
|
||||
|
||||
#define PARAM2(f, a, b, ...) (f((a), (b)))
|
||||
#define PARAM3(f, a, b, c, ...) (f((a), (b), (c)))
|
||||
#define PARAM5(f, a, b, c, d, e, ...) (f((a), (b), (c), (d), (e)))
|
||||
|
||||
#define ATOMIC_LOAD(...) PARAM2(atomic_load_explicit, __VA_ARGS__, memory_order_seq_cst)
|
||||
#define ATOMIC_STORE(...) PARAM3(atomic_store_explicit, __VA_ARGS__, memory_order_seq_cst)
|
||||
|
||||
#define ATOMIC_ADD(T, ...) PARAM3(atomic_fetch_add_explicit, __VA_ARGS__, memory_order_seq_cst)
|
||||
#define ATOMIC_SUB(T, ...) PARAM3(atomic_fetch_sub_explicit, __VA_ARGS__, memory_order_seq_cst)
|
||||
|
||||
#define ATOMIC_EXCHANGE(T, ...) PARAM3(atomic_exchange_explicit, __VA_ARGS__, memory_order_seq_cst)
|
||||
#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, ...) \
|
||||
PARAM5(atomic_compare_exchange_strong_explicit, __VA_ARGS__, memory_order_seq_cst, memory_order_seq_cst)
|
||||
#define ATOMIC_COMPARE_EXCHANGE_WEAK(T, ...) \
|
||||
PARAM5(atomic_compare_exchange_weak_explicit, __VA_ARGS__, memory_order_seq_cst, memory_order_seq_cst)
|
||||
|
||||
/* Atomics using GCC intrinsics */
|
||||
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__QNXNTO__)
|
||||
|
||||
enum almemory_order {
|
||||
almemory_order_relaxed,
|
||||
almemory_order_consume,
|
||||
almemory_order_acquire,
|
||||
almemory_order_release,
|
||||
almemory_order_acq_rel,
|
||||
almemory_order_seq_cst
|
||||
};
|
||||
|
||||
#define ATOMIC(T) struct { T volatile value; }
|
||||
|
||||
#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
|
||||
#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
|
||||
|
||||
#define ATOMIC_LOAD(_val, ...) __extension__({ \
|
||||
__typeof((_val)->value) _r = (_val)->value; \
|
||||
__asm__ __volatile__("" ::: "memory"); \
|
||||
_r; \
|
||||
})
|
||||
#define ATOMIC_STORE(_val, _newval, ...) do { \
|
||||
__asm__ __volatile__("" ::: "memory"); \
|
||||
(_val)->value = (_newval); \
|
||||
} while(0)
|
||||
|
||||
#define ATOMIC_ADD(T, _val, _incr, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
__sync_fetch_and_add(&(_val)->value, (_incr)); \
|
||||
})
|
||||
#define ATOMIC_SUB(T, _val, _decr, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
__sync_fetch_and_sub(&(_val)->value, (_decr)); \
|
||||
})
|
||||
|
||||
#define ATOMIC_EXCHANGE(T, _val, _newval, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
__sync_lock_test_and_set(&(_val)->value, (_newval)); \
|
||||
})
|
||||
#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
T _o = *(_oldval); \
|
||||
*(_oldval) = __sync_val_compare_and_swap(&(_val)->value, _o, (_newval)); \
|
||||
*(_oldval) == _o; \
|
||||
})
|
||||
|
||||
/* Atomics using x86/x86-64 GCC inline assembly */
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
|
||||
#define WRAP_ADD(ret, dest, incr) __asm__ __volatile__( \
|
||||
"lock; xaddl %0,(%1)" \
|
||||
: "=r" (ret) \
|
||||
: "r" (dest), "0" (incr) \
|
||||
: "memory" \
|
||||
)
|
||||
#define WRAP_SUB(ret, dest, decr) __asm__ __volatile__( \
|
||||
"lock; xaddl %0,(%1)" \
|
||||
: "=r" (ret) \
|
||||
: "r" (dest), "0" (-(decr)) \
|
||||
: "memory" \
|
||||
)
|
||||
|
||||
#define WRAP_XCHG(S, ret, dest, newval) __asm__ __volatile__( \
|
||||
"lock; xchg"S" %0,(%1)" \
|
||||
: "=r" (ret) \
|
||||
: "r" (dest), "0" (newval) \
|
||||
: "memory" \
|
||||
)
|
||||
#define WRAP_CMPXCHG(S, ret, dest, oldval, newval) __asm__ __volatile__( \
|
||||
"lock; cmpxchg"S" %2,(%1)" \
|
||||
: "=a" (ret) \
|
||||
: "r" (dest), "r" (newval), "0" (oldval) \
|
||||
: "memory" \
|
||||
)
|
||||
|
||||
|
||||
enum almemory_order {
|
||||
almemory_order_relaxed,
|
||||
almemory_order_consume,
|
||||
almemory_order_acquire,
|
||||
almemory_order_release,
|
||||
almemory_order_acq_rel,
|
||||
almemory_order_seq_cst
|
||||
};
|
||||
|
||||
#define ATOMIC(T) struct { T volatile value; }
|
||||
|
||||
#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
|
||||
#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
|
||||
|
||||
#define ATOMIC_LOAD(_val, ...) __extension__({ \
|
||||
__typeof((_val)->value) _r = (_val)->value; \
|
||||
__asm__ __volatile__("" ::: "memory"); \
|
||||
_r; \
|
||||
})
|
||||
#define ATOMIC_STORE(_val, _newval, ...) do { \
|
||||
__asm__ __volatile__("" ::: "memory"); \
|
||||
(_val)->value = (_newval); \
|
||||
} while(0)
|
||||
|
||||
#define ATOMIC_ADD(T, _val, _incr, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==4, "Type "#T" has incorrect size!"); \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
T _r; \
|
||||
WRAP_ADD(_r, &(_val)->value, (T)(_incr)); \
|
||||
_r; \
|
||||
})
|
||||
#define ATOMIC_SUB(T, _val, _decr, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==4, "Type "#T" has incorrect size!"); \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
T _r; \
|
||||
WRAP_SUB(_r, &(_val)->value, (T)(_decr)); \
|
||||
_r; \
|
||||
})
|
||||
|
||||
#define ATOMIC_EXCHANGE(T, _val, _newval, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==4 || sizeof(T)==8, "Type "#T" has incorrect size!"); \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
T _r; \
|
||||
if(sizeof(T) == 4) WRAP_XCHG("l", _r, &(_val)->value, (T)(_newval)); \
|
||||
else if(sizeof(T) == 8) WRAP_XCHG("q", _r, &(_val)->value, (T)(_newval)); \
|
||||
_r; \
|
||||
})
|
||||
#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) __extension__({ \
|
||||
static_assert(sizeof(T)==4 || sizeof(T)==8, "Type "#T" has incorrect size!"); \
|
||||
static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
|
||||
T _old = *(_oldval); \
|
||||
if(sizeof(T) == 4) WRAP_CMPXCHG("l", *(_oldval), &(_val)->value, _old, (T)(_newval)); \
|
||||
else if(sizeof(T) == 8) WRAP_CMPXCHG("q", *(_oldval), &(_val)->value, _old, (T)(_newval)); \
|
||||
*(_oldval) == _old; \
|
||||
})
|
||||
|
||||
/* Atomics using Windows methods */
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
/* NOTE: This mess is *extremely* noisy, at least on GCC. It works by wrapping
|
||||
* Windows' 32-bit and 64-bit atomic methods, which are then casted to use the
|
||||
* given type based on its size (e.g. int and float use 32-bit atomics). This
|
||||
* is fine for the swap and compare-and-swap methods, although the add and
|
||||
* subtract methods only work properly for integer types.
|
||||
*
|
||||
* Despite how noisy it is, it's unfortunately the only way that doesn't rely
|
||||
* on C99 (damn MSVC).
|
||||
*/
|
||||
|
||||
inline LONG AtomicAdd32(volatile LONG *dest, LONG incr)
|
||||
{
|
||||
return InterlockedExchangeAdd(dest, incr);
|
||||
}
|
||||
inline LONG AtomicSub32(volatile LONG *dest, LONG decr)
|
||||
{
|
||||
return InterlockedExchangeAdd(dest, -decr);
|
||||
}
|
||||
|
||||
inline LONG AtomicSwap32(volatile LONG *dest, LONG newval)
|
||||
{
|
||||
return InterlockedExchange(dest, newval);
|
||||
}
|
||||
inline LONGLONG AtomicSwap64(volatile LONGLONG *dest, LONGLONG newval)
|
||||
{
|
||||
return InterlockedExchange64(dest, newval);
|
||||
}
|
||||
|
||||
inline bool CompareAndSwap32(volatile LONG *dest, LONG newval, LONG *oldval)
|
||||
{
|
||||
LONG old = *oldval;
|
||||
*oldval = InterlockedCompareExchange(dest, newval, *oldval);
|
||||
return old == *oldval;
|
||||
}
|
||||
inline bool CompareAndSwap64(volatile LONGLONG *dest, LONGLONG newval, LONGLONG *oldval)
|
||||
{
|
||||
LONGLONG old = *oldval;
|
||||
*oldval = InterlockedCompareExchange64(dest, newval, *oldval);
|
||||
return old == *oldval;
|
||||
}
|
||||
|
||||
#define WRAP_ADDSUB(T, _func, _ptr, _amnt) ((T(*)(T volatile*,T))_func)((_ptr), (_amnt))
|
||||
#define WRAP_XCHG(T, _func, _ptr, _newval) ((T(*)(T volatile*,T))_func)((_ptr), (_newval))
|
||||
#define WRAP_CMPXCHG(T, _func, _ptr, _newval, _oldval) ((bool(*)(T volatile*,T,T*))_func)((_ptr), (_newval), (_oldval))
|
||||
|
||||
|
||||
enum almemory_order {
|
||||
almemory_order_relaxed,
|
||||
almemory_order_consume,
|
||||
almemory_order_acquire,
|
||||
almemory_order_release,
|
||||
almemory_order_acq_rel,
|
||||
almemory_order_seq_cst
|
||||
};
|
||||
|
||||
#define ATOMIC(T) struct { T volatile value; }
|
||||
|
||||
#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
|
||||
#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
|
||||
|
||||
#define ATOMIC_LOAD(_val, ...) ((_val)->value)
|
||||
#define ATOMIC_STORE(_val, _newval, ...) do { \
|
||||
(_val)->value = (_newval); \
|
||||
} while(0)
|
||||
|
||||
int _al_invalid_atomic_size(); /* not defined */
|
||||
|
||||
#define ATOMIC_ADD(T, _val, _incr, ...) \
|
||||
((sizeof(T)==4) ? WRAP_ADDSUB(T, AtomicAdd32, &(_val)->value, (_incr)) : \
|
||||
(T)_al_invalid_atomic_size())
|
||||
#define ATOMIC_SUB(T, _val, _decr, ...) \
|
||||
((sizeof(T)==4) ? WRAP_ADDSUB(T, AtomicSub32, &(_val)->value, (_decr)) : \
|
||||
(T)_al_invalid_atomic_size())
|
||||
|
||||
#define ATOMIC_EXCHANGE(T, _val, _newval, ...) \
|
||||
((sizeof(T)==4) ? WRAP_XCHG(T, AtomicSwap32, &(_val)->value, (_newval)) : \
|
||||
(sizeof(T)==8) ? WRAP_XCHG(T, AtomicSwap64, &(_val)->value, (_newval)) : \
|
||||
(T)_al_invalid_atomic_size())
|
||||
#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) \
|
||||
((sizeof(T)==4) ? WRAP_CMPXCHG(T, CompareAndSwap32, &(_val)->value, (_newval), (_oldval)) : \
|
||||
(sizeof(T)==8) ? WRAP_CMPXCHG(T, CompareAndSwap64, &(_val)->value, (_newval), (_oldval)) : \
|
||||
(bool)_al_invalid_atomic_size())
|
||||
|
||||
#else
|
||||
|
||||
#error "No atomic functions available on this platform!"
|
||||
|
||||
#define ATOMIC(T) T
|
||||
|
||||
#define ATOMIC_INIT_STATIC(_newval) (0)
|
||||
|
||||
#define ATOMIC_LOAD_UNSAFE(_val) (0)
|
||||
#define ATOMIC_STORE_UNSAFE(_val, _newval) ((void)0)
|
||||
|
||||
#define ATOMIC_LOAD(_val, ...) (0)
|
||||
#define ATOMIC_STORE(_val, _newval, ...) ((void)0)
|
||||
|
||||
#define ATOMIC_ADD(T, _val, _incr, ...) (0)
|
||||
#define ATOMIC_SUB(T, _val, _decr, ...) (0)
|
||||
|
||||
#define ATOMIC_EXCHANGE(T, _val, _newval, ...) (0)
|
||||
#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) (0)
|
||||
#endif
|
||||
|
||||
/* If no weak cmpxchg is provided (not all systems will have one), substitute a
|
||||
* strong cmpxchg. */
|
||||
#ifndef ATOMIC_COMPARE_EXCHANGE_WEAK
|
||||
#define ATOMIC_COMPARE_EXCHANGE_WEAK ATOMIC_COMPARE_EXCHANGE_STRONG
|
||||
#endif
|
||||
|
||||
|
||||
typedef unsigned int uint;
|
||||
typedef ATOMIC(uint) RefCount;
|
||||
|
||||
inline void InitRef(RefCount *ptr, uint value)
|
||||
{ ATOMIC_INIT(ptr, value); }
|
||||
inline uint ReadRef(RefCount *ptr)
|
||||
{ return ATOMIC_LOAD(ptr); }
|
||||
inline uint IncrementRef(RefCount *ptr)
|
||||
{ return ATOMIC_ADD(uint, ptr, 1)+1; }
|
||||
inline uint DecrementRef(RefCount *ptr)
|
||||
{ return ATOMIC_SUB(uint, ptr, 1)-1; }
|
||||
|
||||
|
||||
/* This is *NOT* atomic, but is a handy utility macro to compare-and-swap non-
|
||||
* atomic variables. */
|
||||
#define COMPARE_EXCHANGE(_val, _oldval, _newval) ((*(_val) == *(_oldval)) ? ((*(_val)=(_newval)),true) : ((*(_oldval)=*(_val)),false))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_ATOMIC_H */
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef AL_BOOL_H
|
||||
#define AL_BOOL_H
|
||||
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifndef bool
|
||||
#ifdef HAVE_C99_BOOL
|
||||
#define bool _Bool
|
||||
#else
|
||||
#define bool int
|
||||
#endif
|
||||
#define false 0
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#endif /* AL_BOOL_H */
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#ifndef AL_MATH_DEFS_H
|
||||
#define AL_MATH_DEFS_H
|
||||
|
||||
#ifdef HAVE_FLOAT_H
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#define F_PI (3.14159265358979323846f)
|
||||
#define F_PI_2 (1.57079632679489661923f)
|
||||
#define F_TAU (6.28318530717958647692f)
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
#define FLT_EPSILON (1.19209290e-07f)
|
||||
#endif
|
||||
|
||||
#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
|
||||
#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
|
||||
|
||||
#endif /* AL_MATH_DEFS_H */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef AL_RWLOCK_H
|
||||
#define AL_RWLOCK_H
|
||||
|
||||
#include "bool.h"
|
||||
#include "atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
RefCount read_count;
|
||||
RefCount write_count;
|
||||
ATOMIC(int) read_lock;
|
||||
ATOMIC(int) read_entry_lock;
|
||||
ATOMIC(int) write_lock;
|
||||
} RWLock;
|
||||
#define RWLOCK_STATIC_INITIALIZE { ATOMIC_INIT_STATIC(0), ATOMIC_INIT_STATIC(0), \
|
||||
ATOMIC_INIT_STATIC(false), ATOMIC_INIT_STATIC(false), \
|
||||
ATOMIC_INIT_STATIC(false) }
|
||||
|
||||
void RWLockInit(RWLock *lock);
|
||||
void ReadLock(RWLock *lock);
|
||||
void ReadUnlock(RWLock *lock);
|
||||
void WriteLock(RWLock *lock);
|
||||
void WriteUnlock(RWLock *lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_RWLOCK_H */
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef AL_STATIC_ASSERT_H
|
||||
#define AL_STATIC_ASSERT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#ifndef static_assert
|
||||
#ifdef HAVE_C11_STATIC_ASSERT
|
||||
#define static_assert _Static_assert
|
||||
#else
|
||||
#define CTASTR2(_pre,_post) _pre##_post
|
||||
#define CTASTR(_pre,_post) CTASTR2(_pre,_post)
|
||||
#if defined(__COUNTER__)
|
||||
#define static_assert(_cond, _msg) typedef struct { int CTASTR(static_assert_failed_at_line_,__LINE__) : !!(_cond); } CTASTR(static_assertion_,__COUNTER__)
|
||||
#else
|
||||
#define static_assert(_cond, _msg) struct { int CTASTR(static_assert_failed_at_line_,__LINE__) : !!(_cond); }
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* AL_STATIC_ASSERT_H */
|
||||
|
|
@ -1,237 +0,0 @@
|
|||
#ifndef AL_THREADS_H
|
||||
#define AL_THREADS_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
althrd_success = 0,
|
||||
althrd_error,
|
||||
althrd_nomem,
|
||||
althrd_timedout,
|
||||
althrd_busy
|
||||
};
|
||||
|
||||
enum {
|
||||
almtx_plain = 0,
|
||||
almtx_recursive = 1,
|
||||
almtx_timed = 2
|
||||
};
|
||||
|
||||
typedef int (*althrd_start_t)(void*);
|
||||
typedef void (*altss_dtor_t)(void*);
|
||||
|
||||
|
||||
#define AL_TIME_UTC 1
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#ifndef HAVE_STRUCT_TIMESPEC
|
||||
struct timespec {
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef DWORD althrd_t;
|
||||
typedef CRITICAL_SECTION almtx_t;
|
||||
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
|
||||
typedef CONDITION_VARIABLE alcnd_t;
|
||||
#else
|
||||
typedef struct { void *Ptr; } alcnd_t;
|
||||
#endif
|
||||
typedef DWORD altss_t;
|
||||
typedef LONG alonce_flag;
|
||||
|
||||
#define AL_ONCE_FLAG_INIT 0
|
||||
|
||||
int althrd_sleep(const struct timespec *ts, struct timespec *rem);
|
||||
void alcall_once(alonce_flag *once, void (*callback)(void));
|
||||
|
||||
|
||||
inline althrd_t althrd_current(void)
|
||||
{
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
|
||||
inline int althrd_equal(althrd_t thr0, althrd_t thr1)
|
||||
{
|
||||
return thr0 == thr1;
|
||||
}
|
||||
|
||||
inline void althrd_exit(int res)
|
||||
{
|
||||
ExitThread(res);
|
||||
}
|
||||
|
||||
inline void althrd_yield(void)
|
||||
{
|
||||
SwitchToThread();
|
||||
}
|
||||
|
||||
|
||||
inline int almtx_lock(almtx_t *mtx)
|
||||
{
|
||||
if(!mtx) return althrd_error;
|
||||
EnterCriticalSection(mtx);
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
inline int almtx_unlock(almtx_t *mtx)
|
||||
{
|
||||
if(!mtx) return althrd_error;
|
||||
LeaveCriticalSection(mtx);
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
inline int almtx_trylock(almtx_t *mtx)
|
||||
{
|
||||
if(!mtx) return althrd_error;
|
||||
if(!TryEnterCriticalSection(mtx))
|
||||
return althrd_busy;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
|
||||
inline void *altss_get(altss_t tss_id)
|
||||
{
|
||||
return TlsGetValue(tss_id);
|
||||
}
|
||||
|
||||
inline int altss_set(altss_t tss_id, void *val)
|
||||
{
|
||||
if(TlsSetValue(tss_id, val) == 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
typedef pthread_t althrd_t;
|
||||
typedef pthread_mutex_t almtx_t;
|
||||
typedef pthread_cond_t alcnd_t;
|
||||
typedef pthread_key_t altss_t;
|
||||
typedef pthread_once_t alonce_flag;
|
||||
|
||||
#define AL_ONCE_FLAG_INIT PTHREAD_ONCE_INIT
|
||||
|
||||
|
||||
inline althrd_t althrd_current(void)
|
||||
{
|
||||
return pthread_self();
|
||||
}
|
||||
|
||||
inline int althrd_equal(althrd_t thr0, althrd_t thr1)
|
||||
{
|
||||
return pthread_equal(thr0, thr1);
|
||||
}
|
||||
|
||||
inline void althrd_exit(int res)
|
||||
{
|
||||
pthread_exit((void*)(intptr_t)res);
|
||||
}
|
||||
|
||||
inline void althrd_yield(void)
|
||||
{
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
inline int althrd_sleep(const struct timespec *ts, struct timespec *rem)
|
||||
{
|
||||
int ret = nanosleep(ts, rem);
|
||||
if(ret != 0)
|
||||
{
|
||||
ret = ((errno==EINTR) ? -1 : -2);
|
||||
errno = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
inline int almtx_lock(almtx_t *mtx)
|
||||
{
|
||||
if(pthread_mutex_lock(mtx) != 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
inline int almtx_unlock(almtx_t *mtx)
|
||||
{
|
||||
if(pthread_mutex_unlock(mtx) != 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
inline int almtx_trylock(almtx_t *mtx)
|
||||
{
|
||||
int ret = pthread_mutex_trylock(mtx);
|
||||
switch(ret)
|
||||
{
|
||||
case 0: return althrd_success;
|
||||
case EBUSY: return althrd_busy;
|
||||
}
|
||||
return althrd_error;
|
||||
}
|
||||
|
||||
|
||||
inline void *altss_get(altss_t tss_id)
|
||||
{
|
||||
return pthread_getspecific(tss_id);
|
||||
}
|
||||
|
||||
inline int altss_set(altss_t tss_id, void *val)
|
||||
{
|
||||
if(pthread_setspecific(tss_id, val) != 0)
|
||||
return althrd_error;
|
||||
return althrd_success;
|
||||
}
|
||||
|
||||
|
||||
inline void alcall_once(alonce_flag *once, void (*callback)(void))
|
||||
{
|
||||
pthread_once(once, callback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int althrd_create(althrd_t *thr, althrd_start_t func, void *arg);
|
||||
int althrd_detach(althrd_t thr);
|
||||
int althrd_join(althrd_t thr, int *res);
|
||||
void althrd_setname(althrd_t thr, const char *name);
|
||||
|
||||
int almtx_init(almtx_t *mtx, int type);
|
||||
void almtx_destroy(almtx_t *mtx);
|
||||
int almtx_timedlock(almtx_t *mtx, const struct timespec *ts);
|
||||
|
||||
int alcnd_init(alcnd_t *cond);
|
||||
int alcnd_signal(alcnd_t *cond);
|
||||
int alcnd_broadcast(alcnd_t *cond);
|
||||
int alcnd_wait(alcnd_t *cond, almtx_t *mtx);
|
||||
int alcnd_timedwait(alcnd_t *cond, almtx_t *mtx, const struct timespec *time_point);
|
||||
void alcnd_destroy(alcnd_t *cond);
|
||||
|
||||
int altss_create(altss_t *tss_id, altss_dtor_t callback);
|
||||
void altss_delete(altss_t tss_id);
|
||||
|
||||
int altimespec_get(struct timespec *ts, int base);
|
||||
|
||||
void al_nssleep(unsigned long nsec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_THREADS_H */
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#ifndef AL_UINTMAP_H
|
||||
#define AL_UINTMAP_H
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "rwlock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct UIntMap {
|
||||
ALuint *keys;
|
||||
/* Shares memory with keys. */
|
||||
ALvoid **values;
|
||||
|
||||
ALsizei size;
|
||||
ALsizei capacity;
|
||||
ALsizei limit;
|
||||
RWLock lock;
|
||||
} UIntMap;
|
||||
#define UINTMAP_STATIC_INITIALIZE_N(_n) { NULL, NULL, 0, 0, (_n), RWLOCK_STATIC_INITIALIZE }
|
||||
#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(~0)
|
||||
|
||||
void InitUIntMap(UIntMap *map, ALsizei limit);
|
||||
void ResetUIntMap(UIntMap *map);
|
||||
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value);
|
||||
ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key);
|
||||
ALvoid *RemoveUIntMapKeyNoLock(UIntMap *map, ALuint key);
|
||||
ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key);
|
||||
ALvoid *LookupUIntMapKeyNoLock(UIntMap *map, ALuint key);
|
||||
|
||||
inline void LockUIntMapRead(UIntMap *map)
|
||||
{ ReadLock(&map->lock); }
|
||||
inline void UnlockUIntMapRead(UIntMap *map)
|
||||
{ ReadUnlock(&map->lock); }
|
||||
inline void LockUIntMapWrite(UIntMap *map)
|
||||
{ WriteLock(&map->lock); }
|
||||
inline void UnlockUIntMapWrite(UIntMap *map)
|
||||
{ WriteUnlock(&map->lock); }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_UINTMAP_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue