Merge branch 'master' into merge
Signed-off-by: Martin Bremmer <martin.bremmer@adlinktech.com>
This commit is contained in:
		
						commit
						919850232c
					
				
					 128 changed files with 6936 additions and 2075 deletions
				
			
		| 
						 | 
				
			
			@ -22,10 +22,12 @@ extern "C" {
 | 
			
		|||
   provide all the interlocked operations for 64-bit operands on x86
 | 
			
		||||
   platforms, but it doesn't. */
 | 
			
		||||
 | 
			
		||||
#define DDSRT_ATOMIC_OP32(name, ...) name ((volatile long *) __VA_ARGS__)
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
#define DDSRT_ATOMIC_PTROP(name) name##64
 | 
			
		||||
#define DDSRT_ATOMIC_OP64(name, ...) name##64 ((volatile int64_t *) __VA_ARGS__)
 | 
			
		||||
#define DDSRT_ATOMIC_PTROP(name, ...) name##64 ((volatile int64_t *) __VA_ARGS__)
 | 
			
		||||
#else
 | 
			
		||||
#define DDSRT_ATOMIC_PTROP(name) name
 | 
			
		||||
#define DDSRT_ATOMIC_PTROP(name, ...) name ((volatile long *) __VA_ARGS__)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* LD, ST */
 | 
			
		||||
| 
						 | 
				
			
			@ -47,15 +49,15 @@ inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { d
 | 
			
		|||
/* CAS */
 | 
			
		||||
 | 
			
		||||
inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
 | 
			
		||||
  return InterlockedCompareExchange (&x->v, des, exp) == exp;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedCompareExchange, &x->v, des, exp) == exp;
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
 | 
			
		||||
  return InterlockedCompareExchange64 (&x->v, des, exp) == exp;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedCompareExchange, &x->v, des, exp) == exp;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedCompareExchange) (&x->v, des, exp) == exp;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedCompareExchange, &x->v, des, exp) == exp;
 | 
			
		||||
}
 | 
			
		||||
inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) {
 | 
			
		||||
  return ddsrt_atomic_casptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) exp, (uintptr_t) des);
 | 
			
		||||
| 
						 | 
				
			
			@ -64,96 +66,96 @@ inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, v
 | 
			
		|||
/* INC */
 | 
			
		||||
 | 
			
		||||
inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  InterlockedIncrement (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) {
 | 
			
		||||
  InterlockedIncrement64 (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) {
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_inc32_ov (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  return InterlockedIncrement (&x->v) - 1;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedIncrement, &x->v) - 1;
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  return InterlockedIncrement (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) {
 | 
			
		||||
  return InterlockedIncrement64 (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedIncrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* DEC */
 | 
			
		||||
 | 
			
		||||
inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  InterlockedDecrement (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) {
 | 
			
		||||
  InterlockedDecrement64 (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) {
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  return InterlockedDecrement (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) {
 | 
			
		||||
  return InterlockedDecrement64 (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedDecrement, &x->v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) {
 | 
			
		||||
  return InterlockedDecrement (&x->v) + 1;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedDecrement, &x->v) + 1;
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) {
 | 
			
		||||
  return InterlockedDecrement64 (&x->v) + 1;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedDecrement, &x->v) + 1;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v) + 1;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedDecrement, &x->v) + 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* ADD */
 | 
			
		||||
 | 
			
		||||
inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  InterlockedExchangeAdd (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  InterlockedExchangeAdd64 (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedExchangeAdd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
 | 
			
		||||
  ddsrt_atomic_addptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_add32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedExchangeAdd (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedExchangeAdd (&x->v, v) + v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, v) + v;
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  return InterlockedExchangeAdd64 (&x->v, v) + v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedExchangeAdd, &x->v, v) + v;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v) + v;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd, &x->v, v) + v;
 | 
			
		||||
}
 | 
			
		||||
inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
 | 
			
		||||
  return (void *) ddsrt_atomic_addptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
 | 
			
		||||
| 
						 | 
				
			
			@ -164,21 +166,21 @@ inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff
 | 
			
		|||
inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  InterlockedExchangeAdd (&x->v, -v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, -v);
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  InterlockedExchangeAdd64 (&x->v, -v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedExchangeAdd, &x->v, -v);
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd, &x->v, -v);
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
 | 
			
		||||
| 
						 | 
				
			
			@ -187,27 +189,27 @@ inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v
 | 
			
		|||
inline uint32_t ddsrt_atomic_sub32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  return InterlockedExchangeAdd (&x->v, -v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, -v);
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  return InterlockedExchangeAdd (&x->v, -v) - v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedExchangeAdd, &x->v, -v) - v;
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  return InterlockedExchangeAdd64 (&x->v, -v) - v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedExchangeAdd, &x->v, -v) - v;
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  /* disable unary minus applied to unsigned type, result still unsigned */
 | 
			
		||||
  DDSRT_WARNING_MSVC_OFF(4146)
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v) - v;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd, &x->v, -v) - v;
 | 
			
		||||
  DDSRT_WARNING_MSVC_ON(4146)
 | 
			
		||||
}
 | 
			
		||||
inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
 | 
			
		||||
| 
						 | 
				
			
			@ -217,73 +219,73 @@ inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff
 | 
			
		|||
/* AND */
 | 
			
		||||
 | 
			
		||||
inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  InterlockedAnd (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  InterlockedAnd64 (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedAnd (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  return InterlockedAnd64 (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedAnd, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedAnd (&x->v, v) & v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedAnd, &x->v, v) & v;
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  return InterlockedAnd64 (&x->v, v) & v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedAnd, &x->v, v) & v;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v) & v;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedAnd, &x->v, v) & v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* OR */
 | 
			
		||||
 | 
			
		||||
inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  InterlockedOr (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP32 (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  InterlockedOr64 (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_OP64 (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v);
 | 
			
		||||
  DDSRT_ATOMIC_PTROP (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedOr (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  return InterlockedOr64 (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v);
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedOr, &x->v, v);
 | 
			
		||||
}
 | 
			
		||||
inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
 | 
			
		||||
  return InterlockedOr (&x->v, v) | v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP32 (InterlockedOr, &x->v, v) | v;
 | 
			
		||||
}
 | 
			
		||||
#if DDSRT_HAVE_ATOMIC64
 | 
			
		||||
inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
 | 
			
		||||
  return InterlockedOr64 (&x->v, v) | v;
 | 
			
		||||
  return DDSRT_ATOMIC_OP64 (InterlockedOr, &x->v, v) | v;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v) | v;
 | 
			
		||||
  return DDSRT_ATOMIC_PTROP (InterlockedOr, &x->v, v) | v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* FENCES */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,6 +25,8 @@ DDS_EXPORT void ddsrt_fini(void);
 | 
			
		|||
 | 
			
		||||
DDS_EXPORT ddsrt_mutex_t *ddsrt_get_singleton_mutex(void);
 | 
			
		||||
 | 
			
		||||
DDS_EXPORT ddsrt_cond_t *ddsrt_get_singleton_cond(void);
 | 
			
		||||
 | 
			
		||||
#if defined (__cplusplus)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,13 +73,16 @@ extern "C" {
 | 
			
		|||
#define DDS_LC_WHC (16384u)
 | 
			
		||||
/** Debug/trace messages related to throttling. */
 | 
			
		||||
#define DDS_LC_THROTTLE (32768u)
 | 
			
		||||
/** All common trace categories. */
 | 
			
		||||
/** Reader history cache. */
 | 
			
		||||
#define DDS_LC_RHC (65536u)
 | 
			
		||||
/** Include content in traces. */
 | 
			
		||||
#define DDS_LC_CONTENT (131072u)
 | 
			
		||||
/** All common trace categories. */
 | 
			
		||||
#define DDS_LC_ALL \
 | 
			
		||||
    (DDS_LC_FATAL | DDS_LC_ERROR | DDS_LC_WARNING | DDS_LC_INFO | \
 | 
			
		||||
     DDS_LC_CONFIG | DDS_LC_DISCOVERY | DDS_LC_DATA | DDS_LC_TRACE | \
 | 
			
		||||
     DDS_LC_TIMING | DDS_LC_TRAFFIC | DDS_LC_TCP | DDS_LC_THROTTLE)
 | 
			
		||||
     DDS_LC_TIMING | DDS_LC_TRAFFIC | DDS_LC_TCP | DDS_LC_THROTTLE | \
 | 
			
		||||
     DDS_LC_CONTENT)
 | 
			
		||||
/** @}*/
 | 
			
		||||
 | 
			
		||||
#define DDS_LOG_MASK \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@
 | 
			
		|||
#include "dds/ddsrt/attributes.h"
 | 
			
		||||
#include "dds/ddsrt/retcode.h"
 | 
			
		||||
#include "dds/ddsrt/time.h"
 | 
			
		||||
#include "dds/ddsrt/misc.h"
 | 
			
		||||
#if _WIN32
 | 
			
		||||
#include "dds/ddsrt/sockets/windows.h"
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -237,10 +238,12 @@ ddsrt_sockaddrtostr(
 | 
			
		|||
  const void *sa, char *buf, size_t size);
 | 
			
		||||
 | 
			
		||||
#if DDSRT_HAVE_DNS
 | 
			
		||||
DDSRT_WARNING_MSVC_OFF(4200)
 | 
			
		||||
typedef struct {
 | 
			
		||||
  size_t naddrs;
 | 
			
		||||
  struct sockaddr_storage addrs[];
 | 
			
		||||
} ddsrt_hostent_t;
 | 
			
		||||
DDSRT_WARNING_MSVC_ON(4200)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Lookup addresses for given host name.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ extern void ddsrt_time_fini(void);
 | 
			
		|||
#define INIT_STATUS_OK 0x80000000u
 | 
			
		||||
static ddsrt_atomic_uint32_t init_status = DDSRT_ATOMIC_UINT32_INIT(0);
 | 
			
		||||
static ddsrt_mutex_t init_mutex;
 | 
			
		||||
static ddsrt_cond_t init_cond;
 | 
			
		||||
 | 
			
		||||
void ddsrt_init (void)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +39,7 @@ retry:
 | 
			
		|||
    return;
 | 
			
		||||
  else if (v == 1) {
 | 
			
		||||
    ddsrt_mutex_init(&init_mutex);
 | 
			
		||||
    ddsrt_cond_init(&init_cond);
 | 
			
		||||
#if _WIN32
 | 
			
		||||
    ddsrt_winsock_init();
 | 
			
		||||
    ddsrt_time_init();
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +49,13 @@ retry:
 | 
			
		|||
    ddsrt_atomic_or32(&init_status, INIT_STATUS_OK);
 | 
			
		||||
  } else {
 | 
			
		||||
    while (v > 1 && !(v & INIT_STATUS_OK)) {
 | 
			
		||||
#ifndef __COVERITY__
 | 
			
		||||
      /* This sleep makes Coverity warn about possibly sleeping while holding in a lock
 | 
			
		||||
         in many places, all because just-in-time creation of a thread descriptor ends
 | 
			
		||||
         up here.  Since sleeping is merely meant as a better alternative to spinning,
 | 
			
		||||
         skip the sleep when being analyzed. */
 | 
			
		||||
      dds_sleepfor(10000000);
 | 
			
		||||
#endif
 | 
			
		||||
      v = ddsrt_atomic_ld32(&init_status);
 | 
			
		||||
    }
 | 
			
		||||
    goto retry;
 | 
			
		||||
| 
						 | 
				
			
			@ -67,6 +75,7 @@ void ddsrt_fini (void)
 | 
			
		|||
  } while (!ddsrt_atomic_cas32(&init_status, v, nv));
 | 
			
		||||
  if (nv == 1)
 | 
			
		||||
  {
 | 
			
		||||
    ddsrt_cond_destroy(&init_cond);
 | 
			
		||||
    ddsrt_mutex_destroy(&init_mutex);
 | 
			
		||||
    ddsrt_random_fini();
 | 
			
		||||
    ddsrt_atomics_fini();
 | 
			
		||||
| 
						 | 
				
			
			@ -83,6 +92,11 @@ ddsrt_mutex_t *ddsrt_get_singleton_mutex(void)
 | 
			
		|||
  return &init_mutex;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ddsrt_cond_t *ddsrt_get_singleton_cond(void)
 | 
			
		||||
{
 | 
			
		||||
  return &init_cond;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#include "dds/ddsrt/threads.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -199,7 +199,7 @@ static size_t print_header (char *str, uint32_t id)
 | 
			
		|||
  }
 | 
			
		||||
  assert (off + cnt == (HDR_LEN - 1));
 | 
			
		||||
  str[off + cnt] = ' '; /* Replace snprintf null byte by space. */
 | 
			
		||||
  return (size_t) cnt;
 | 
			
		||||
  return (size_t) (cnt + 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void vlog1 (const struct ddsrt_log_cfg_impl *cfg, uint32_t cat, uint32_t domid, const char *file, uint32_t line, const char *func, const char *fmt, va_list ap)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,6 +61,7 @@
 | 
			
		|||
#include "dds/ddsrt/sync.h"
 | 
			
		||||
#include "dds/ddsrt/time.h"
 | 
			
		||||
#include "dds/ddsrt/process.h"
 | 
			
		||||
#include "dds/ddsrt/atomics.h"
 | 
			
		||||
#include "dds/ddsrt/static_assert.h"
 | 
			
		||||
 | 
			
		||||
#define N DDSRT_MT19937_N
 | 
			
		||||
| 
						 | 
				
			
			@ -186,13 +187,15 @@ void ddsrt_random_init (void)
 | 
			
		|||
  ddsrt_prng_seed_t seed;
 | 
			
		||||
  if (!ddsrt_prng_makeseed (&seed))
 | 
			
		||||
  {
 | 
			
		||||
    static ddsrt_atomic_uint32_t counter = DDSRT_ATOMIC_UINT32_INIT (0);
 | 
			
		||||
    /* Poor man's initialisation */
 | 
			
		||||
    DDSRT_STATIC_ASSERT (sizeof (seed.key) / sizeof (seed.key[0]) >= 3);
 | 
			
		||||
    DDSRT_STATIC_ASSERT (sizeof (seed.key) / sizeof (seed.key[0]) >= 4);
 | 
			
		||||
    memset (&seed, 0, sizeof (seed));
 | 
			
		||||
    dds_time_t now = dds_time ();
 | 
			
		||||
    seed.key[0] = (uint32_t) ddsrt_getpid ();
 | 
			
		||||
    seed.key[1] = (uint32_t) ((uint64_t) now >> 32);
 | 
			
		||||
    seed.key[2] = (uint32_t) now;
 | 
			
		||||
    seed.key[3] = ddsrt_atomic_inc32_ov (&counter);
 | 
			
		||||
  }
 | 
			
		||||
  ddsrt_prng_init (&default_prng, &seed);
 | 
			
		||||
  ddsrt_mutex_init (&default_prng_lock);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include "dds/ddsrt/retcode.h"
 | 
			
		||||
#include "dds/ddsrt/static_assert.h"
 | 
			
		||||
 | 
			
		||||
static const char *retcodes[] = {
 | 
			
		||||
  "Success",
 | 
			
		||||
| 
						 | 
				
			
			@ -45,6 +46,7 @@ const char *dds_strretcode (dds_return_t rc)
 | 
			
		|||
{
 | 
			
		||||
  const dds_return_t nretcodes = (dds_return_t) (sizeof (retcodes) / sizeof (retcodes[0]));
 | 
			
		||||
  const dds_return_t nxretcodes = (dds_return_t) (sizeof (xretcodes) / sizeof (xretcodes[0]));
 | 
			
		||||
  DDSRT_STATIC_ASSERT (DDS_XRETCODE_BASE < 0);
 | 
			
		||||
  /* Retcodes used to be positive, but return values from the API would be a negative
 | 
			
		||||
     and so there are/were/may be places outside the core library where dds_strretcode
 | 
			
		||||
     is called with a -N for N a API return value, so ... play it safe and use the
 | 
			
		||||
| 
						 | 
				
			
			@ -53,8 +55,8 @@ const char *dds_strretcode (dds_return_t rc)
 | 
			
		|||
    rc = -rc;
 | 
			
		||||
  if (rc >= 0 && rc < nretcodes)
 | 
			
		||||
    return retcodes[rc];
 | 
			
		||||
  else if (rc >= DDS_XRETCODE_BASE && rc < DDS_XRETCODE_BASE + nxretcodes)
 | 
			
		||||
    return xretcodes[rc - DDS_XRETCODE_BASE];
 | 
			
		||||
  else if (rc >= (-DDS_XRETCODE_BASE) && rc < (-DDS_XRETCODE_BASE) + nxretcodes)
 | 
			
		||||
    return xretcodes[rc - (-DDS_XRETCODE_BASE)];
 | 
			
		||||
  else
 | 
			
		||||
    return "Unknown return code";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
#include "dds/ddsrt/environ.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -49,11 +50,13 @@ CU_Test(ddsrt_environ, setenv)
 | 
			
		|||
  CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
 | 
			
		||||
  ptr = getenv(name);
 | 
			
		||||
  CU_ASSERT_PTR_NOT_NULL(ptr);
 | 
			
		||||
  assert (ptr != NULL); /* for the benefit of clang's static analyzer */
 | 
			
		||||
  CU_ASSERT_STRING_EQUAL(ptr, "bar");
 | 
			
		||||
  /* Ensure value is copied into the environment. */
 | 
			
		||||
  value[2] = 'z';
 | 
			
		||||
  ptr = getenv(name);
 | 
			
		||||
  CU_ASSERT_PTR_NOT_NULL(ptr);
 | 
			
		||||
  assert (ptr != NULL); /* for the benefit of clang's static analyzer */
 | 
			
		||||
  CU_ASSERT_STRING_EQUAL(ptr, "bar");
 | 
			
		||||
  rc = ddsrt_setenv(name, "");
 | 
			
		||||
  CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,7 @@
 | 
			
		|||
 *
 | 
			
		||||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include "dds/ddsrt/cdtors.h"
 | 
			
		||||
#include "dds/ddsrt/ifaddrs.h"
 | 
			
		||||
#include "dds/ddsrt/retcode.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +74,7 @@ CU_Test(ddsrt_getifaddrs, ipv4)
 | 
			
		|||
  CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
 | 
			
		||||
  for (ifa = ifa_root; ifa; ifa = ifa->next) {
 | 
			
		||||
    CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
 | 
			
		||||
    assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
 | 
			
		||||
    CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET);
 | 
			
		||||
    if (ifa->addr->sa_family == AF_INET) {
 | 
			
		||||
      if (ifa->flags & IFF_LOOPBACK) {
 | 
			
		||||
| 
						 | 
				
			
			@ -130,6 +132,7 @@ CU_Test(ddsrt_getifaddrs, ipv6)
 | 
			
		|||
    CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
 | 
			
		||||
    for (ifa = ifa_root; ifa; ifa = ifa->next) {
 | 
			
		||||
      CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
 | 
			
		||||
      assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
 | 
			
		||||
      CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6);
 | 
			
		||||
      if (ifa->addr->sa_family == AF_INET6) {
 | 
			
		||||
        have_ipv6 = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -170,6 +173,7 @@ CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6)
 | 
			
		|||
    CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
 | 
			
		||||
    for (ifa = ifa_root; ifa; ifa = ifa->next) {
 | 
			
		||||
      CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL);
 | 
			
		||||
      assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */
 | 
			
		||||
      CU_ASSERT(ifa->addr->sa_family == AF_INET ||
 | 
			
		||||
                ifa->addr->sa_family == AF_INET6);
 | 
			
		||||
      if (ifa->addr->sa_family == AF_INET) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -254,11 +254,8 @@ CU_Test(dds_log, no_sink, .init=setup, .fini=teardown)
 | 
			
		|||
  ptr = NULL;
 | 
			
		||||
  DDS_ERROR("foobaz\n");
 | 
			
		||||
  ret = fseek(fh, 0, SEEK_SET);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  CU_ASSERT_PTR_NULL(ptr);
 | 
			
		||||
  if (ptr != NULL) {
 | 
			
		||||
    ddsrt_free(ptr);
 | 
			
		||||
    ptr = NULL;
 | 
			
		||||
  }
 | 
			
		||||
  buf[0]= '\0';
 | 
			
		||||
  cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh);
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,9 +29,13 @@ static int test_sleep(int argi, int argc, char **argv)
 | 
			
		|||
  argi++;
 | 
			
		||||
  if (argi < argc) {
 | 
			
		||||
    long long dorment;
 | 
			
		||||
    ddsrt_strtoll(argv[argi], NULL, 0, &dorment);
 | 
			
		||||
    printf(" Process: sleep %d seconds.\n", (int)dorment);
 | 
			
		||||
    dds_sleepfor(DDS_SECS((int64_t)dorment));
 | 
			
		||||
    if (ddsrt_strtoll(argv[argi], NULL, 0, &dorment) != DDS_RETCODE_OK || dorment < 0 || dorment > INT32_MAX) {
 | 
			
		||||
      printf(" Process: invalid --sleep argument.\n");
 | 
			
		||||
      return TEST_EXIT_WRONG_ARGS;
 | 
			
		||||
    } else {
 | 
			
		||||
      printf(" Process: sleep %d seconds.\n", (int)dorment);
 | 
			
		||||
      dds_sleepfor(DDS_SECS((int64_t)dorment));
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    printf(" Process: no --sleep value.\n");
 | 
			
		||||
    return TEST_EXIT_WRONG_ARGS;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue