Rearrange and fixup abstraction layer

- Replace os_result by dds_retcode_t and move DDS return code defines down.
  Eliminates the need to convert between different return code types.

- Move dds_time_t down and remove os_time.
  Eliminates the need to convert between different time representations and
  reduces code duplication.

- Remove use of Microsoft source-code annotation language (SAL).
  SAL annotations are Microsoft specific and not very well documented. This
  makes it very difficult for contributers to write.

- Rearrange the abstraction layer to be feature-based. The previous layout
  falsely assumed that the operating system dictates which implementation is
  best suited. For general purpose operating systems this is mostly true, but
  embedded targets require a slightly different approach and may not even offer
  all features. The new layout makes it possible to mix-and-match feature
  implementations and allows for features to not be implemented at all.

- Replace the os prefix by ddsrt to avoid name collisions.

- Remove various portions of unused and unwanted code.

- Export thread names on all supported platforms.

- Return native thread identifier on POSIX compatible platforms.

- Add timed wait for condition variables that takes an absolute time.

- Remove system abstraction for errno. The os_getErrno and os_setErrno were
  incorrect. Functions that might fail now simply return a DDS return code
  instead.

- Remove thread-specific memory abstraction. os_threadMemGet and accompanying
  functions were a mess and their use has been eliminated by other changes in
  this commit.

- Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name
  collisions and problems with faulty __nonnull__ attributes.

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-01-18 14:10:19 +01:00
parent 318968f40f
commit cd6742ee12
439 changed files with 22117 additions and 28782 deletions

View file

@ -0,0 +1,29 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ARCH_H
#define DDSRT_ARCH_H
#if _WIN32
# if _WIN64
# define DDSRT_64BIT 1
# else
# define DDSRT_64BIT 0
# endif
#else
# if defined(_LP64)
# define DDSRT_64BIT 1
# else
# define DDSRT_64BIT 0
# endif
#endif
#endif /* DDSRT_ARCH_H */

View file

@ -0,0 +1,66 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ATOMICS_H
#define DDSRT_ATOMICS_H
#include <stddef.h>
#include "dds/export.h"
#include "dds/ddsrt/arch.h"
#include "dds/ddsrt/endian.h"
#include "dds/ddsrt/types.h"
#if defined (__cplusplus)
extern "C" {
#endif
/**
* @brief Types on which atomic operations are defined.
*
* @note 64-bit types are defined even if atomic operations on them are not
* really supported. atomic
*/
typedef struct { uint32_t v; } ddsrt_atomic_uint32_t;
typedef struct { uint64_t v; } ddsrt_atomic_uint64_t;
typedef struct { uintptr_t v; } ddsrt_atomic_uintptr_t;
typedef ddsrt_atomic_uintptr_t ddsrt_atomic_voidp_t;
#if DDSRT_64BIT
# define DDSRT_HAVE_ATOMIC64 1
#endif
/**
* @brief Initializers for the types on which atomic operations are defined.
*/
#define DDSRT_ATOMIC_UINT32_INIT(v) { (v) }
#define DDSRT_ATOMIC_UINT64_INIT(v) { (v) }
#define DDSRT_ATOMIC_UINTPTR_INIT(v) { (v) }
#define DDSRT_ATOMIC_VOIDP_INIT(v) { (uintptr_t) (v) }
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40100
#include "dds/ddsrt/atomics/gcc.h"
#elif defined(_WIN32)
#include "dds/ddsrt/atomics/msvc.h"
#elif defined(__sun)
#include "dds/ddsrt/atomics/sun.h"
#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__)
#include "dds/ddsrt/atomics/arm.h"
#else
#error "Atomic operations are not supported"
#endif
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_ATOMICS_H */

View file

@ -0,0 +1,213 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ATOMICS_ARM_H
#define DDSRT_ATOMICS_ARM_H
#if !defined(__arm__)
#define __arm__
#endif
/* IAR documentation states that __CPU_MODE__ is a predefined preprocessor
symbol reflecting the selected CPU mode and is defined to 1 for Thumb and
2 for ARM. */
#if !defined(__thumb__) && __CPU_MODE__ == 1
#define __thumb__
#endif
/* LD, ST */
inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; }
inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; }
inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); }
inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; }
inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); }
/* CAS */
inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
register int result;
asm volatile ("ldrex r0, [%1]\n\t" /*exclusive load of ptr */
"cmp r0, %2\n\t" /*compare the oldval == *ptr */
#if defined(__thumb__)
"ite eq\n\t"
#endif
"strexeq %0, %3, [%1]\n\t" /*store if eq, strex+eq*/
#if defined(__thumb__)
"clrexne"
#endif
: "=&r" (result)
: "r"(&x->v), "r"(exp),"r"(des)
: "r0");
return result == 0;
}
inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return ddsrt_atomic_cas32 ((volatile ddsrt_atomic_uint32_t *) x, exp, des);
}
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);
}
/* ADD */
inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
register unsigned int result;
asm volatile ("1: ldrex %0, [%1]\n\t"
"add %0, %0, %2\n\t"
"strex r1, %0, [%1]\n\t"
"cmp r1, #0\n\t"
"bne 1b"
: "=&r" (result)
: "r"(&x->v), "r"(v)
: "r1");
return result;
}
inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return ddsrt_atomic_add32_nv ((volatile ddsrt_atomic_uint32_t *) x, 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);
}
inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
(void) ddsrt_atomic_add32_nv (x, v);
}
inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
(void) ddsrt_atomic_addptr_nv (x, v);
}
inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
(void) ddsrt_atomic_addvoidp_nv (x, v);
}
/* SUB */
inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return ddsrt_atomic_add32_nv (x, -v);
}
inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return ddsrt_atomic_addptr_nv (x, -v);
}
inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
return ddsrt_atomic_addvoidp_nv (x, -v);
}
inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
ddsrt_atomic_add32 (x, -v);
}
inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
ddsrt_atomic_subptr (x, -v);
}
inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
ddsrt_atomic_subvoidp (x, -v);
}
/* INC */
inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) {
return ddsrt_atomic_add32_nv (x, 1);
}
inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return ddsrt_atomic_addptr_nv (x, 1);
}
inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) {
(void) ddsrt_atomic_inc32_nv (x);
}
inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) {
(void) ddsrt_atomic_incptr_nv (x);
}
/* DEC */
inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) {
return ddsrt_atomic_sub32_nv (x, 1);
}
inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return ddsrt_atomic_subptr_nv (x, 1);
}
inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) {
(void) ddsrt_atomic_dec32_nv (x);
}
inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) {
(void) ddsrt_atomic_decptr_nv (x);
}
/* AND */
inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_cas32 (x, oldval, newval));
return oldval;
}
inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_casptr (x, oldval, newval));
return oldval;
}
inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_cas32 (x, oldval, newval));
return newval;
}
inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_casptr (x, oldval, newval));
return newval;
}
inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
(void) ddsrt_atomic_and32_nv (x, v);
}
inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
(void) ddsrt_atomic_andptr_nv (x, v);
}
/* OR */
inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_cas32 (x, oldval, newval));
return oldval;
}
inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_casptr (x, oldval, newval));
return oldval;
}
inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_cas32 (x, oldval, newval));
return newval;
}
inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_casptr (x, oldval, newval));
return newval;
}
inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
(void) ddsrt_atomic_or32_nv (x, v);
}
inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
(void) ddsrt_atomic_orptr_nv (x, v);
}
/* FENCES */
inline void ddsrt_atomic_fence (void) {
__asm volatile ("dmb" : : : "memory");
}
inline void ddsrt_atomic_fence_acq (void) {
ddsrt_atomic_fence ();
}
inline void ddsrt_atomic_fence_rel (void) {
ddsrt_atomic_fence ();
}
#endif /* DDSRT_ATOMICS_ARM_H */

View file

@ -0,0 +1,291 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ATOMICS_GCC_H
#define DDSRT_ATOMICS_GCC_H
#include "dds/ddsrt/misc.h"
#if ( DDSRT_HAVE_ATOMIC64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || \
(!DDSRT_HAVE_ATOMIC64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
# define DDSRT_HAVE_ATOMIC_LIFO 1
#endif
/* LD, ST */
inline uint32_t ddsrt_atomic_ld32(const volatile ddsrt_atomic_uint32_t *x) { return x->v; }
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_ld64(const volatile ddsrt_atomic_uint64_t *x) { return x->v; }
#endif
inline uintptr_t ddsrt_atomic_ldptr(const volatile ddsrt_atomic_uintptr_t *x) { return x->v; }
inline void *ddsrt_atomic_ldvoidp(const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr(x); }
inline void ddsrt_atomic_st32(volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; }
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_st64(volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; }
#endif
inline void ddsrt_atomic_stptr(volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void ddsrt_atomic_stvoidp(volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr(x, (uintptr_t)v); }
/* INC */
inline void ddsrt_atomic_inc32(volatile ddsrt_atomic_uint32_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
#endif
inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
#endif
inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
/* DEC */
inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
#endif
inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
#endif
inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
#endif
inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
/* ADD */
inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_add (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_add (&x->v, v);
}
#endif
inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_add (&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_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_add_and_fetch (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_add_and_fetch (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_add_and_fetch (&x->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);
}
/* SUB */
inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_sub (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_sub (&x->v, v);
}
#endif
inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_sub (&x->v, v);
}
inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
ddsrt_atomic_subptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
}
inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) ddsrt_atomic_subptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
}
/* AND */
inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_and (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_and (&x->v, v);
}
#endif
inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_and (&x->v, v);
}
inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_fetch_and_and (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_fetch_and_and (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_fetch_and_and (&x->v, v);
}
inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_and_and_fetch (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_and_and_fetch (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_and_and_fetch (&x->v, v);
}
/* OR */
inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_or (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_or (&x->v, v);
}
#endif
inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_or (&x->v, v);
}
inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_fetch_and_or (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_fetch_and_or (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_fetch_and_or (&x->v, v);
}
inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return __sync_or_and_fetch (&x->v, v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return __sync_or_and_fetch (&x->v, v);
}
#endif
inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return __sync_or_and_fetch (&x->v, v);
}
/* CAS */
inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
#if DDSRT_HAVE_ATOMIC64
inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
#endif
inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) {
return ddsrt_atomic_casptr (x, (uintptr_t) exp, (uintptr_t) des);
}
#if DDSRT_HAVE_ATOMIC_LIFO
#if DDSRT_HAVE_ATOMIC64
typedef union { __int128_t x; struct { uintptr_t a, b; } s; } ddsrt_atomic_uintptr2_t;
#else
typedef union { uint64_t x; struct { uintptr_t a, b; } s; } ddsrt_atomic_uintptr2_t;
#endif
typedef struct {
ddsrt_atomic_uintptr2_t aba_head;
} ddsrt_atomic_lifo_t;
DDS_EXPORT void ddsrt_atomic_lifo_init(ddsrt_atomic_lifo_t *head);
DDS_EXPORT void ddsrt_atomic_lifo_push(ddsrt_atomic_lifo_t *head, void *elem, size_t linkoff);
DDS_EXPORT void *ddsrt_atomic_lifo_pop(ddsrt_atomic_lifo_t *head, size_t linkoff);
DDS_EXPORT void ddsrt_atomic_lifo_pushmany(ddsrt_atomic_lifo_t *head, void *first, void *last, size_t linkoff);
inline int ddsrt_atomic_casvoidp2 (volatile ddsrt_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1) {
ddsrt_atomic_uintptr2_t o, n;
o.s.a = a0; o.s.b = b0;
n.s.a = a1; n.s.b = b1;
return __sync_bool_compare_and_swap (&x->x, o.x, n.x);
}
#endif
/* FENCES */
inline void ddsrt_atomic_fence (void) {
__sync_synchronize ();
}
inline void ddsrt_atomic_fence_ldld (void) {
#if !(defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64)
__sync_synchronize ();
#endif
}
inline void ddsrt_atomic_fence_acq (void) {
ddsrt_atomic_fence ();
}
inline void ddsrt_atomic_fence_rel (void) {
ddsrt_atomic_fence ();
}
#endif /* DDSRT_ATOMICS_GCC_H */

View file

@ -0,0 +1,299 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ATOMICS_MSVC_H
#define DDSRT_ATOMICS_MSVC_H
#include "dds/ddsrt/misc.h"
/* x86 has supported 64-bit CAS for a long time, so Windows ought to
provide all the interlocked operations for 64-bit operands on x86
platforms, but it doesn't. */
#if DDSRT_HAVE_ATOMIC64
#define DDSRT_ATOMIC_PTROP(name) name##64
#else
#define DDSRT_ATOMIC_PTROP(name) name
#endif
/* LD, ST */
inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; }
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_ld64 (const volatile ddsrt_atomic_uint64_t *x) { return x->v; }
#endif
inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; }
inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); }
inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; }
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_st64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; }
#endif
inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); }
/* 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;
}
#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;
}
#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;
}
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);
}
/* INC */
inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) {
InterlockedIncrement (&x->v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) {
InterlockedIncrement64 (&x->v);
}
#endif
inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) {
DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
}
inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) {
return InterlockedIncrement (&x->v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) {
return InterlockedIncrement64 (&x->v);
}
#endif
inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
}
/* DEC */
inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) {
InterlockedDecrement (&x->v);
}
#if DDSRT_HAVE_ATOMIC64
inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) {
InterlockedDecrement64 (&x->v);
}
#endif
inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) {
DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
}
inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) {
return InterlockedDecrement (&x->v);
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) {
return InterlockedDecrement64 (&x->v);
}
#endif
inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
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;
}
#if DDSRT_HAVE_ATOMIC64
inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) {
return InterlockedDecrement64 (&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;
}
/* ADD */
inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
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);
}
#endif
inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t 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_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return 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;
}
#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;
}
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);
}
/* SUB */
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_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_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_WARNING_MSVC_ON(4146)
}
inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
ddsrt_atomic_subptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
}
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;
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;
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;
DDSRT_WARNING_MSVC_ON(4146)
}
inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) ddsrt_atomic_subptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v);
}
/* AND */
inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
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);
}
#endif
inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t 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);
}
#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);
}
#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);
}
inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return 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;
}
#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;
}
/* OR */
inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
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);
}
#endif
inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t 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);
}
#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);
}
#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);
}
inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return 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;
}
#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;
}
/* FENCES */
inline void ddsrt_atomic_fence (void) {
/* 28113: accessing a local variable tmp via an Interlocked
function: This is an unusual usage which could be reconsidered.
It is too heavyweight, true, but it does the trick. */
DDSRT_WARNING_MSVC_OFF(28113)
volatile LONG tmp = 0;
InterlockedExchange (&tmp, 0);
DDSRT_WARNING_MSVC_ON(28113)
}
inline void ddsrt_atomic_fence_ldld (void) {
#if !(defined _M_IX86 || defined _M_X64)
ddsrt_atomic_fence ();
#endif
}
inline void ddsrt_atomic_fence_acq (void) {
ddsrt_atomic_fence ();
}
inline void ddsrt_atomic_fence_rel (void) {
ddsrt_atomic_fence ();
}
#undef DDSRT_ATOMIC_PTROP
#endif /* DDSRT_ATOMICS_MSVC_H */

View file

@ -0,0 +1,241 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#include <atomic.h>
#define DDSRT_ATOMIC64_SUPPORT 1
/* LD, ST */
inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; }
inline uint64_t ddsrt_atomic_ld64 (const volatile ddsrt_atomic_uint64_t *x) { return x->v; }
inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; }
inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); }
inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; }
inline void ddsrt_atomic_st64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; }
inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); }
/* INC */
inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) {
atomic_inc_32 (&x->v);
}
inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) {
atomic_inc_64 (&x->v);
}
inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) {
atomic_inc_ulong (&x->v);
}
inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) {
return atomic_inc_32_nv (&x->v);
}
inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) {
return atomic_inc_64_nv (&x->v);
}
inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return atomic_inc_ulong_nv (&x->v);
}
/* DEC */
inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) {
atomic_dec_32 (&x->v);
}
inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) {
atomic_dec_64 (&x->v);
}
inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) {
atomic_dec_ulong (&x->v);
}
inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) {
return atomic_dec_32_nv (&x->v);
}
inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) {
return atomic_dec_64_nv (&x->v);
}
inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) {
return atomic_dec_ulong_nv (&x->v);
}
inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
return oldval;
}
/* ADD */
inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
atomic_add_32 (&x->v, v);
}
inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
atomic_add_64 (&x->v, v);
}
inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
atomic_add_long (&x->v, v);
}
inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
atomic_add_ptr (&x->v, v);
}
inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return atomic_add_32_nv (&x->v, v);
}
inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return atomic_add_64_nv (&x->v, v);
}
inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return atomic_add_long_nv (&x->v, v);
}
inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
return atomic_add_ptr_nv (&x->v, v);
}
/* SUB */
inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
atomic_add_32 (&x->v, -v);
}
inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
atomic_add_64 (&x->v, -v);
}
inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
atomic_add_long (&x->v, -v);
}
inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
atomic_add_ptr (&x->v, -v);
}
inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return atomic_add_32_nv (&x->v, -v);
}
inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return atomic_add_64_nv (&x->v, -v);
}
inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return atomic_add_long_nv (&x->v, -v);
}
inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) {
return atomic_add_ptr_nv (&x->v, -v);
}
/* AND */
inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
atomic_and_32 (&x->v, v);
}
inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
atomic_and_64 (&x->v, v);
}
inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
atomic_and_ulong (&x->v, v);
}
inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return atomic_and_32_nv (&x->v, v);
}
inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return atomic_and_64_nv (&x->v, v);
}
inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return atomic_and_ulong_nv (&x->v, v);
}
/* OR */
inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
atomic_or_32 (&x->v, v);
}
inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
atomic_or_64 (&x->v, v);
}
inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
atomic_or_ulong (&x->v, v);
}
inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval);
return oldval;
}
inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) {
return atomic_or_32_nv (&x->v, v);
}
inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) {
return atomic_or_64_nv (&x->v, v);
}
inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) {
return atomic_or_ulong_nv (&x->v, v);
}
/* CAS */
inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
return atomic_cas_32 (&x->v, exp, des) == exp;
}
inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
return atomic_cas_64 (&x->v, exp, des) == exp;
}
inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return atomic_cas_ulong (&x->v, exp, des) == exp;
}
inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) {
return atomic_cas_ptr (&x->v, exp, des) == exp;
}
/* FENCES */
inline void ddsrt_atomic_fence (void) {
membar_exit ();
membar_enter ();
}
inline void ddsrt_atomic_fence_ldld (void) {
membar_enter ();
}
inline void ddsrt_atomic_fence_acq (void) {
membar_enter ();
}
inline void ddsrt_atomic_fence_rel (void) {
membar_exit ();
}

View file

@ -0,0 +1,104 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ATTRIBUTES_H
#define DDSRT_ATTRIBUTES_H
#if __clang__
# define ddsrt_gnuc (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
# define ddsrt_gnuc (0)
#endif
#if __GNUC__
# define ddsrt_clang (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#else
# define ddsrt_clang (0)
#endif
#if defined(__has_attribute)
# define ddsrt_has_attribute(params) __has_attribute(params)
#elif ddsrt_gnuc
# define ddsrt_has_attribute(params) (1) /* GCC < 5 */
#else
# define ddsrt_has_attribute(params) (0)
#endif
#if ddsrt_has_attribute(malloc)
# define ddsrt_attribute_malloc __attribute__ ((__malloc__))
#else
# define ddsrt_attribute_malloc
#endif
#if ddsrt_has_attribute(unused)
# define ddsrt_attribute_unused __attribute__((__unused__))
#else
# define ddsrt_attribute_unused
#endif
#if ddsrt_has_attribute(noreturn)
# define ddsrt_attribute_noreturn __attribute__ ((__noreturn__))
#else
# define ddsrt_attribute_noreturn
#endif
#if ddsrt_has_attribute(nonnull)
# define ddsrt_nonnull(params) __attribute__ ((__nonnull__ params))
# define ddsrt_nonnull_all __attribute__ ((__nonnull__))
#else
# define ddsrt_nonnull(params)
# define ddsrt_nonnull_all
#endif
#if ddsrt_has_attribute(returns_nonnull) && (ddsrt_clang || ddsrt_gnuc >= 40900)
# define ddsrt_attribute_returns_nonnull __attribute__ ((__returns_nonnull__))
#else
# define ddsrt_attribute_returns_nonnull
#endif
/* GCC <= 4.2.4 has the attribute, but warns that it ignores it. */
#if !ddsrt_has_attribute(alloc_size) || (ddsrt_gnuc <= 40204)
# define ddsrt_attribute_alloc_size(params)
#else
# define ddsrt_attribute_alloc_size(params) __attribute__ ((__alloc_size__ params))
#endif
#if ddsrt_has_attribute(const)
# define ddsrt_attribute_const __attribute__ ((__const__))
#else
# define ddsrt_attribute_const
#endif
#if ddsrt_has_attribute(pure)
# define ddsrt_attribute_pure __attribute__ ((__pure__))
#else
# define ddsrt_attribute_pure
#endif
#if ddsrt_has_attribute(format)
# define ddsrt_attribute_format(params) __attribute__ ((__format__ params))
#else
# define ddsrt_attribute_format(params)
#endif
#if ddsrt_has_attribute(warn_unused_result)
# define ddsrt_attribute_warn_unused_result __attribute__ ((__warn_unused_result__))
#else
# define ddsrt_attribute_warn_unused_result
#endif
#if ddsrt_has_attribute(assume_aligned)
# define ddsrt_attribute_assume_aligned(params) __attribute__ ((__assume_aligned__ params))
#else
# define ddsrt_attribute_assume_aligned(params)
#endif
#endif /* DDSRT_ATTRIBUTES_H */

View file

@ -0,0 +1,24 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_CDTORS_H
#define DDSRT_CDTORS_H
#include "dds/export.h"
#include "dds/ddsrt/sync.h"
DDS_EXPORT void ddsrt_init(void);
DDS_EXPORT void ddsrt_fini(void);
DDS_EXPORT ddsrt_mutex_t *ddsrt_get_singleton_mutex(void);
#endif /* DDSRT_CDTORS_H */

View file

@ -0,0 +1,47 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ENDIAN_H
#define DDSRT_ENDIAN_H
#if defined(__cplusplus)
extern "C" {
#endif
#define DDSRT_LITTLE_ENDIAN 1
#define DDSRT_BIG_ENDIAN 2
#if _WIN32
# if defined(__BIG_ENDIAN)
# define DDSRT_ENDIAN DDSRT_BIG_ENDIAN
# else
# define DDSRT_ENDIAN DDSRT_LITTLE_ENDIAN
# endif
#else /* _WIN32 */
# if defined(__BYTE_ORDER__)
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define DDSRT_ENDIAN DDSRT_BIG_ENDIAN
# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define DDSRT_ENDIAN DDSRT_LITTLE_ENDIAN
# endif
# endif
#endif /* _WIN32 */
#if (DDSRT_ENDIAN != DDSRT_LITTLE_ENDIAN) && \
(DDSRT_ENDIAN != DDSRT_BIG_ENDIAN)
# error "Endianness cannot be determined"
#endif
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_ENDIAN_H */

View file

@ -0,0 +1,103 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_ENVIRON_H
#define DDSRT_ENVIRON_H
#include "dds/export.h"
#include "dds/ddsrt/attributes.h"
#include "dds/ddsrt/retcode.h"
#if defined(__cplusplus)
extern "C" {
#endif
/**
* @brief Get value for environment variable.
*
* @param[in] name Environment variable name.
* @param[in] buf Buffer to write value to.
* @param[in] sz Size of buffer.
* @param[out] reqsz Number of bytes written (excluding the terminating null
* byte), or would have been written would @buf have been
* sufficiently large enough.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Environment variable written to @buf.
* @retval DDS_RETCODE_NOT_FOUND
* Environment variable not found.
* @retval DDS_RETCODE_BAD_PARAMETER
* FIXME: document
* @retval DDS_RETCODE_OUT_OF_RESOURCES
* FIXME: document
* @retval DDS_RETCODE_ERROR
* Unspecified error.
*/
DDS_EXPORT dds_retcode_t
ddsrt_getenv(
const char *name,
char **value)
ddsrt_nonnull_all;
/**
* @brief Set environment variable value.
*
* Sets the environment variable to the value specified in value, or
* alternatively, unsets the environment variable if value is an empty string.
*
* @param[in] name Environment variable name.
* @param[in] value Value to set environment variable to.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Environment variable successfully set to @value.
* @retval DDS_RETCODE_BAD_PARAMETER
* Invalid environment variable name.
* @retval DDS_RETCODE_OUT_OF_RESOURCES
* Not enough system resources to set environment variable.
* @retval DDS_RETCODE_ERROR
* Unspecified system error.
*/
DDS_EXPORT dds_retcode_t
ddsrt_setenv(
const char *name,
const char *value)
ddsrt_nonnull_all;
/**
* @brief Unset environment variable value.
*
* @param[in] name Environment variable name.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Environment variable successfully unset.
* @retval DDS_RETCODE_BAD_PARAMETER
* Invalid environment variable name.
* @retval DDS_RETCODE_OUT_OF_RESOURCES
* Not enough system resources to unset environment variable.
* @retval DDS_RETCODE_ERROR
* Unspecified system error.
*/
DDS_EXPORT dds_retcode_t
ddsrt_unsetenv(
const char *name)
ddsrt_nonnull_all;
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_ENVIRON_H */

View file

@ -0,0 +1,155 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
/**
* @file heap.h
* @brief Heap memory management.
*
* Platform independent interface to heap memory management.
*/
#ifndef DDSRT_HEAP_H
#define DDSRT_HEAP_H
#include <stddef.h>
#include "dds/export.h"
#include "dds/ddsrt/attributes.h"
#if defined (__cplusplus)
extern "C" {
#endif
/**
* @brief Allocate memory from heap.
*
* The allocated block of memory must be freed by calling @ddsrt_free when no
* longer used.
*
* @param[in] size The size, in bytes, of the block of memory to allocate.
*
* @returns A pointer to the allocated block of memory. abort() is called if
* not enough free memory was available.
*/
DDS_EXPORT void *
ddsrt_malloc(
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((1));
/**
* @brief Allocate memory from heap.
*
* Allocate a block of memory from heap with the given size. The allocated
* block of memory must be freed by calling @ddsrt_free when no longer used.
*
* @param[in] size The size, in bytes, of memory to allocate.
*
* @returns A pointer to the allocated block of memory, NULL if not enough
* memory was available.
*/
DDS_EXPORT void *
ddsrt_malloc_s(
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((1));
/**
* @brief Allocate memory from heap for an array of @count elements of @size
* bytes.
*
* The allocated memory is initialized to zero. The allocated memory must be
* freed by calling @ddsrt_free when no longer used.
*
* A non-NULL pointer, that must be freed is always returned, even if the sum
* @count and @size equals zero.
*
* @returns A pointer to the allocated memory. abort() is called if not enough
* free memory was available.
*/
DDS_EXPORT void *
ddsrt_calloc(
size_t count,
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((1,2));
/**
* @brief Allocate memory from heap for an array of @count elements of @size
* bytes.
*
* The allocated memory is initialized to zero. The allocated memory must be
* freed by calling @ddsrt_free when no longer used.
*
* A non-NULL pointer, that must be freed is always returned, even if the sum
* @count and @size equals zero.
*
* @returns A pointer to the allocated memory, or NULL if not enough memory was
* available.
*/
DDS_EXPORT void *
ddsrt_calloc_s(
size_t count,
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((1,2));
/**
* @brief Reallocate memory from heap.
*
* Reallocate memory from heap. If memblk is NULL the function returns
* ddsrt_malloc_s(size). If size is 0, ddsrt_realloc_s free's the memory
* pointed to by memblk and returns a pointer as if ddsrt_malloc_s(0) was
* invoked. The returned pointer must be free'd with ddsrt_free.
*
* @returns A pointer to reallocated memory. Calls abort() if not enough free
* memory was available.
*/
DDS_EXPORT void *
ddsrt_realloc(
void *memblk,
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((2));
/**
* @brief Reallocate memory from heap.
*
* Reallocate memory from heap. If memblk is NULL the function returns
* ddsrt_malloc_s(size). If size is 0, ddsrt_realloc_s free's the memory
* pointed to by memblk and returns a pointer as if ddsrt_malloc_s(0) was
* invoked. The returned pointer must be free'd with ddsrt_free.
*
* @returns A pointer to reallocated memory, or NULL if not enough free memory
* was available.
*/
DDS_EXPORT void *
ddsrt_realloc_s(
void *memblk,
size_t size)
ddsrt_attribute_malloc
ddsrt_attribute_alloc_size((2));
/**
* @brief Free a previously allocated block of memory and return it to heap.
*
* Free the allocated memory pointed to by @ptr and release it to the heap. No
* action will be taken if @ptr is NULL.
*
* @param[in] ptr Pointer to previously allocated block of memory.
*/
DDS_EXPORT void
ddsrt_free(void *ptr);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_HEAP_H */

View file

@ -0,0 +1,46 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_IFADDRS_H
#define DDSRT_IFADDRS_H
#include "dds/ddsrt/sockets.h"
#if defined (__cplusplus)
extern "C" {
#endif
struct ddsrt_ifaddrs {
struct ddsrt_ifaddrs *next;
char *name;
uint32_t index;
uint32_t flags;
struct sockaddr *addr;
struct sockaddr *netmask;
struct sockaddr *broadaddr;
};
typedef struct ddsrt_ifaddrs ddsrt_ifaddrs_t;
DDS_EXPORT dds_retcode_t
ddsrt_getifaddrs(
ddsrt_ifaddrs_t **ifap,
const int *afs);
DDS_EXPORT void
ddsrt_freeifaddrs(
ddsrt_ifaddrs_t *ifa);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_IFADDRS_H */

View file

@ -0,0 +1,41 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_IO_H
#define DDSRT_IO_H
#include <stdarg.h>
#include <stdio.h>
#include "dds/export.h"
#if defined(__cplusplus)
extern "C" {
#endif
/**
* @brief Write a formatted string to a newly allocated buffer.
*/
DDS_EXPORT int
ddsrt_asprintf(
char **strp,
const char *fmt,
...);
#if defined(_MSC_VER) && (_MSC_VER < 1900)
extern int snprintf(char *s, size_t n, const char *format, ...);
#endif
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_IO_H */

View file

@ -0,0 +1,302 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
/** @file
*
* @brief DDS C Logging API
*
* This header file defines the public API for logging and controlling logging
* in the DDS C language binding.
*/
#ifndef DDS_LOG_H
#define DDS_LOG_H
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include "dds/export.h"
#if defined (__cplusplus)
extern "C" {
#endif
/** @defgroup log_categories Convenience log category definitions.
*
* These defines expand into numeric values that can be ORed together to
* specify messages of which categories must be passed to the respective sinks.
*
* Every category other than DDS_LC_FATAL, DDS_LC_ERROR, DDS_LC_WARNING and
* DDS_LC_INFO automatically falls into the trace category.
*
* @{
*/
/** Fatal error condition. Immediate abort on sink return. */
#define DDS_LC_FATAL (1u)
/** Error condition. */
#define DDS_LC_ERROR (2u)
/** Warning condition. */
#define DDS_LC_WARNING (4u)
/** Informational message. */
#define DDS_LC_INFO (8u)
/** Debug/trace messages related to configuration settings. */
#define DDS_LC_CONFIG (16u)
/** Debug/trace messages related to node discovery. */
#define DDS_LC_DISCOVERY (32u)
/** Currently unused. */
#define DDS_LC_DATA (64u)
/** Debug/trace messages for which no specialized category exists (yet). */
#define DDS_LC_TRACE (128u)
/** Debug/trace messages related to receive administration. */
#define DDS_LC_RADMIN (256u)
/** Debug/trace messages related to timing. */
#define DDS_LC_TIMING (512u)
/** Debug/trace messages related to send administration. */
#define DDS_LC_TRAFFIC (1024u)
/** Currently unused. */
#define DDS_LC_TOPIC (2048u)
/** Debug/trace messages related to TCP communication. */
#define DDS_LC_TCP (4096u)
/** Debug/trace messages related to parameter list processing. */
#define DDS_LC_PLIST (8192u)
/** Debug/trace messages related to the writer history cache. */
#define DDS_LC_WHC (16384u)
/** Debug/trace messages related to throttling. */
#define DDS_LC_THROTTLE (32768u)
/** All common trace categories. */
#define DDS_LC_RHC (65536u)
/** 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)
/** @}*/
#define DDS_LOG_MASK \
(DDS_LC_FATAL | DDS_LC_ERROR | DDS_LC_WARNING | DDS_LC_INFO)
#define DDS_TRACE_MASK \
(~DDS_LOG_MASK)
/** Structure with log message and meta data passed to callbacks. */
typedef struct {
/** Log category the message falls into. */
uint32_t priority;
/** Filename where message was generated. */
const char *file;
/** Line number in file where message was generated. */
uint32_t line;
/** Name of function message where message was generated. */
const char *function;
/** Log message. */
const char *message;
/** Size of log message. */
size_t size;
} dds_log_data_t;
/** Function signature that log and trace callbacks must adhere too. */
typedef void(*dds_log_write_fn_t)(void *, const dds_log_data_t *);
extern uint32_t *const dds_log_mask;
/**
* @brief Get currently enabled log and trace categories.
*
* @returns A uint32_t with enabled categories set.
*/
inline uint32_t
dds_get_log_mask(void)
{
return *dds_log_mask;
}
/**
* @brief Set enabled log and trace categories.
*
* @param[in] cats Log and trace categories to enable.
*/
DDS_EXPORT void
dds_set_log_mask(
uint32_t cats);
/**
* @private
*/
DDS_EXPORT void
dds_set_log_file(
FILE *file);
/**
* @private
*/
DDS_EXPORT void
dds_set_trace_file(
FILE *file);
/**
* @brief Register callback to receive log messages
*
* Callbacks registered to handle log messages will receive messages of type
* info, warning, error and fatal. Messages that fall into the trace category
* will never be delivered to the callback.
*
* This operation is synchronous and only returns once the operation is
* registered with all threads. Meaning that neither callback or userdata will
* be referenced by the DDS stack on return.
*
* @param[in] callback Function pointer matching dds_log_write_fn signature
* or a null pointer to restore the default sink.
* @param[in] userdata User specified data passed along with each invocation
* of callback.
*/
DDS_EXPORT void
dds_set_log_sink(
dds_log_write_fn_t callback,
void *userdata);
/**
* @brief Register callback to receive trace messages
*
* Callbacks registered to handle trace messages will receive messages of type
* info, warning, error and fatal as well as all message types that fall into
* the trace category depending on the log mask.
*
* This operation is synchronous and only returns once the operation is
* registered with all threads. Meaning that neither callback or
* userdata will be referenced by the DDS stack on return.
*
* @param[in] callback Function pointer matching dds_log_write_fn_t signature
* or a null pointer to restore the default sink.
* @param[in] userdata User specified data passed along with each invocation
* of callback.
*/
DDS_EXPORT void
dds_set_trace_sink(
dds_log_write_fn_t callback,
void *userdata);
/**
* @brief Write a log or trace message.
*
* Write a log or trace message to one (or both) of the currently active sinks.
*
* Direct use of #dds_log is discouraged. Use #DDS_INFO, #DDS_WARNING,
* #DDS_ERROR, #DDS_FATAL or #DDS_LOG instead.
*/
DDS_EXPORT int
dds_log(
uint32_t prio,
const char *file,
uint32_t line,
const char *func,
const char *fmt,
...);
/**
* @brief Undecorated function name of the current function.
*
* Behavior of DDS_FUNCTION outside a function is undefined. Note that
* implementations differ across compilers and compiler versions. It might be
* implemented as either a string literal or a constant variable.
*/
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
# define DDS_FUNCTION __func__
#elif defined(__cplusplus) && (__cplusplus >= 201103)
# define DDS_FUNCTION __func__
#elif defined(__GNUC__)
# define DDS_FUNCTION __FUNCTION__
#elif defined(__clang__)
# define DDS_FUNCTION __FUNCTION__
#elif defined(__ghs__)
# define DDS_FUNCTION __FUNCTION__
#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
/* Solaris Studio had support for __func__ before it supported __FUNCTION__.
Compiler flag -features=extensions is required on older versions. */
# define DDS_FUNCTION __func__
#elif defined(__FUNCTION__)
/* Visual Studio */
# define DDS_FUNCTION __FUNCTION__
#elif defined(__vxworks)
/* At least versions 2.9.6 and 3.3.4 of the GNU C Preprocessor only define
__GNUC__ if the entire GNU C compiler is in use. VxWorks 5.5 targets invoke
the preprocessor separately resulting in __GNUC__ not being defined. */
# define DDS_FUNCTION __FUNCTION__
#else
# warning "DDS_FUNCTION is not supported"
# define DDS_FUNCTION ""
#endif
/**
* @brief Function signature of the current function.
*
* See comments on DDS_FUNCTION for details.
*/
#if defined(__GNUC__)
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif defined(__clang__)
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif defined(__ghs__)
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif (defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100)
/* Solaris Studio supports __PRETTY_FUNCTION__ in C since version 12.1 */
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5120)
/* Solaris Studio supports __PRETTY_FUNCTION__ in C++ since version 12.3 */
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif defined(__FUNCSIG__)
/* Visual Studio */
# define DDS_PRETTY_FUNCTION __FUNCSIG__
#elif defined(__vxworks)
/* See comments on __vxworks macro above. */
# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
/* Fall back to DDS_FUNCTION. */
# define DDS_PRETTY_FUNCTION DDS_FUNCTION
#endif
/**
* @brief Write a log message.
*
* Write a log or trace message to the currently active log and/or trace sinks
* if the log category is enabled. Whether or not the category is enabled is
* checked before any dds_log-related activities to save a couple of % CPU.
*
* Only messages that fall into one of the log categories are passed onto
* dds_log. While messages that fall into a trace category could have been
* passed just as easily, they are rejected so that tracing is kept entirely
* separate from logging, if only cosmetic.
*/
#define DDS_LOG(cat, ...) \
((dds_get_log_mask() & (cat)) ? \
dds_log(cat, __FILE__, __LINE__, DDS_FUNCTION, __VA_ARGS__) : 0)
/** Write a log message of type #DDS_LC_INFO. */
#define DDS_INFO(...) \
DDS_LOG(DDS_LC_INFO, __VA_ARGS__)
/** Write a log message of type #DDS_LC_WARNING. */
#define DDS_WARNING(...) \
DDS_LOG(DDS_LC_WARNING, __VA_ARGS__)
/** Write a log message of type #DDS_LC_ERROR. */
#define DDS_ERROR(...) \
DDS_LOG(DDS_LC_ERROR, __VA_ARGS__)
/** Write a log message of type #DDS_LC_ERROR and abort. */
#define DDS_FATAL(...) \
dds_log(DDS_LC_FATAL, __FILE__, __LINE__, DDS_FUNCTION, __VA_ARGS__)
/** Write a #DDS_LC_TRACE message. */
#define DDS_TRACE(...) \
DDS_LOG(DDS_LC_TRACE, __VA_ARGS__)
#if defined (__cplusplus)
}
#endif
#endif /* DDS_LOG_H */

View file

@ -0,0 +1,81 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_MISC_H
#define DDSRT_MISC_H
#include <limits.h>
#if defined (__cplusplus)
extern "C" {
#endif
#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
# define DDSRT_GNUC_STR(s) #s
# define DDSRT_GNUC_JOINSTR(x,y) DDSRT_GNUC_DIAG_STR(x ## y)
# define DDSRT_GNUC_DO_PRAGMA(x) _Pragma (#x)
# define DDSRT_GNUC_PRAGMA(x) DDSRT_GNUC_DO_PRAGMA(GCC diagnostic x)
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
# define DDSRT_WARNING_GNUC_OFF(x) \
DDSRT_GNUC_PRAGMA(push) \
DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x))
# define DDSRT_WARNING_GNUC_ON(x) \
DDSRT_GNUC_PRAGMA(pop)
# else
# define DDSRT_WARNING_GNUC_OFF(x) \
DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x))
# define DDSRT_WARNING_GNUC_ON(x) \
DDSRT_GNUC_PRAGMA(warning DDSRT_GNUC_JOINSTR(-W,x))
# endif
#else
# define DDSRT_WARNING_GNUC_OFF(x)
# define DDSRT_WARNING_GNUC_ON(x)
#endif
#if defined(_MSC_VER)
# define DDSRT_WARNING_MSVC_OFF(x) \
__pragma (warning(push)) \
__pragma (warning(disable: ## x))
# define DDSRT_WARNING_MSVC_ON(x) \
__pragma (warning(pop))
#else
# define DDSRT_WARNING_MSVC_OFF(x)
# define DDSRT_WARNING_MSVC_ON(x)
#endif
/**
* @brief Calculate maximum value of an integer type
*
* A somewhat complex, but efficient way to calculate the maximum value of an
* integer type at compile time.
*
* For unsigned numerical types the first part up to XOR is enough. The second
* part is to make up for signed numerical types.
*/
#define DDSRT_MAX_INTEGER(T) \
((T)(((T)~0) ^ ((T)!((T)~0 > 0) << (CHAR_BIT * sizeof(T) - 1))))
/**
* @brief Calculate minimum value of an integer type
*/
#define DDSRT_MIN_INTEGER(T) \
((-DDSRT_MAX_INTEGER(T)) - 1)
/**
* @brief Macro to disable unused argument warnings
*/
#define DDSRT_UNUSED_ARG(a) (void)(a)
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_MISC_H */

View file

@ -0,0 +1,48 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_PROCESS_H
#define DDSRT_PROCESS_H
#include "dds/export.h"
#include "dds/ddsrt/types.h"
#if defined (__cplusplus)
extern "C" {
#endif
#if defined(_WIN32)
typedef DWORD ddsrt_pid_t;
#define PRIdPID "u"
#else /* _WIN32 */
#include <unistd.h>
#if defined(_WRS_KERNEL)
typedef RTP_ID ddsrt_pid_t; /* typedef struct wind_rtp *RTP_ID */
#define PRIdPID PRIuPTR
#else
typedef pid_t ddsrt_pid_t;
#define PRIdPID "d"
#endif
#endif /* _WIN32 */
/**
* @brief Return process ID (PID) of the calling process.
*
* @returns The process ID of the calling process.
*/
DDS_EXPORT ddsrt_pid_t
ddsrt_getpid(void);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_PROCESS_H */

View file

@ -0,0 +1,27 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_RANDOM_H
#define DDSRT_RANDOM_H
#include "dds/export.h"
#if defined (__cplusplus)
extern "C" {
#endif
DDS_EXPORT long ddsrt_random(void);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_RANDOM_H */

View file

@ -0,0 +1,89 @@
#ifndef DDS_RETCODE_H
#define DDS_RETCODE_H
#include <stdint.h>
#include "dds/export.h"
typedef int32_t dds_retcode_t;
/*
State is unchanged following a function call returning an error
other than UNSPECIFIED, OUT_OF_RESOURCES and ALREADY_DELETED.
Error handling functions. Three components to returned int status value.
1 - The DDS_ERR_xxx error number
2 - The file identifier
3 - The line number
All functions return >= 0 on success, < 0 on error
*/
/**
* @name DDS_Error_Type
* @{
*/
#define DDS_RETCODE_OK 0 /**< Success */
#define DDS_RETCODE_ERROR 1 /**< Non specific error */
#define DDS_RETCODE_UNSUPPORTED 2 /**< Feature unsupported */
#define DDS_RETCODE_BAD_PARAMETER 3 /**< Bad parameter value */
#define DDS_RETCODE_PRECONDITION_NOT_MET 4 /**< Precondition for operation not met */
#define DDS_RETCODE_OUT_OF_RESOURCES 5 /**< When an operation fails because of a lack of resources */
#define DDS_RETCODE_NOT_ENABLED 6 /**< When a configurable feature is not enabled */
#define DDS_RETCODE_IMMUTABLE_POLICY 7 /**< When an attempt is made to modify an immutable policy */
#define DDS_RETCODE_INCONSISTENT_POLICY 8 /**< When a policy is used with inconsistent values */
#define DDS_RETCODE_ALREADY_DELETED 9 /**< When an attempt is made to delete something more than once */
#define DDS_RETCODE_TIMEOUT 10 /**< When a timeout has occurred */
#define DDS_RETCODE_NO_DATA 11 /**< When expected data is not provided */
#define DDS_RETCODE_ILLEGAL_OPERATION 12 /**< When a function is called when it should not be */
#define DDS_RETCODE_NOT_ALLOWED_BY_SECURITY 13 /**< When credentials are not enough to use the function */
/* Extended return codes are not in the DDS specification and are meant
exclusively for internal use and must not be returned by the C API. */
#define DDS_XRETCODE_BASE (50)
#define DDS_XRETCODE(x) (DDS_XRETCODE_BASE + (x))
/** Requested resource is busy */
#define DDS_RETCODE_IN_PROGRESS DDS_XRETCODE(1)
/** Resource unavailable, try again */
#define DDS_RETCODE_TRY_AGAIN DDS_XRETCODE(2)
/** Operation was interrupted */
#define DDS_RETCODE_INTERRUPTED DDS_XRETCODE(3)
/** Permission denied */
#define DDS_RETCODE_NOT_ALLOWED DDS_XRETCODE(4)
/** Host not found */
#define DDS_RETCODE_HOST_NOT_FOUND DDS_XRETCODE(5)
/** Network is not available */
#define DDS_RETCODE_NO_NETWORK DDS_XRETCODE(6)
/** Connection is not available */
#define DDS_RETCODE_NO_CONNECTION DDS_XRETCODE(7)
/* Host not reachable is used to indicate that a connection was refused
(ECONNREFUSED), reset by peer (ECONNRESET) or that a host or network cannot
be reached (EHOSTUNREACH, ENETUNREACH). Generally all system errors that
indicate a connection cannot be made or that a message cannot be delivered,
map onto host not reachable. */
/** Not enough space available */
#define DDS_RETCODE_NOT_ENOUGH_SPACE DDS_XRETCODE(8)
/* Not enough space is used to indicate there is not enough buffer space to
read a message from the network (i.e. EMSGSIZE), but is also used to
indicate there is not enough space left on a device, etc. */
/** Result too large */
#define DDS_RETCODE_OUT_OF_RANGE DDS_XRETCODE(9)
/** Not found */
#define DDS_RETCODE_NOT_FOUND DDS_XRETCODE(10)
/**
* @}
*/
/**
* @brief Takes the error value and outputs a string corresponding to it.
*
* @param[in] err Error value to be converted to a string
*
* @returns String corresponding to the error value
*/
DDS_EXPORT const char *dds_strretcode(dds_retcode_t ret);
#endif /* DDS_RETCODE_H */

View file

@ -0,0 +1,50 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_RUSAGE_H
#define DDSRT_RUSAGE_H
#include <stddef.h>
#include "dds/ddsrt/time.h"
#include "dds/ddsrt/retcode.h"
typedef struct {
dds_time_t utime; /* User CPU time used. */
dds_time_t stime; /* System CPU time used. */
size_t maxrss; /* Maximum resident set size in bytes. */
size_t idrss; /* Integral unshared data size. Not maintained on (at least)
Linux and Windows. */
size_t nvcsw; /* Voluntary context switches. Not maintained on Windows. */
size_t nivcsw; /* Involuntary context switches. Not maintained on Windows. */
} ddsrt_rusage_t;
#define DDSRT_RUSAGE_SELF (0)
#define DDSRT_RUSAGE_THREAD (1)
/**
* @brief Get resource usage for the current thread or process.
*
* @param[in] who DDSRT_RUSAGE_SELF or DDSRT_RUSAGE_THREAD.
* @param[in] usage Structure where resource usage is returned.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Resource usage successfully returned in @usage.
* @retval DDS_RETCODE_OUT_OF_RESOURCES
* There were not enough resources to get resource usage.
* @retval DDS_RETCODE_ERROR
* An unidentified error occurred.
*/
DDS_EXPORT dds_retcode_t ddsrt_getrusage(int who, ddsrt_rusage_t *usage);
#endif /* DDSRT_RUSAGE_H */

View file

@ -0,0 +1,262 @@
#ifndef DDSRT_SOCKETS_H
#define DDSRT_SOCKETS_H
#include <stdbool.h>
#include "dds/export.h"
#include "dds/ddsrt/types.h"
#include "dds/ddsrt/attributes.h"
#include "dds/ddsrt/retcode.h"
#include "dds/ddsrt/time.h"
#if !defined(_WIN32)
#include "dds/ddsrt/sockets/posix.h"
#else
#include "dds/ddsrt/sockets/windows.h"
#endif
#if DDSRT_HAVE_IPV6
#define INET6_ADDRSTRLEN_EXTENDED (INET6_ADDRSTRLEN + 8) /* "[]:12345" */
extern const struct in6_addr ddsrt_in6addr_any;
extern const struct in6_addr ddsrt_in6addr_loopback;
#endif /* DDSRT_HAVE_IPV6 */
#define DDSRT_AF_TERM (-1)
DDS_EXPORT dds_retcode_t
ddsrt_gethostname(
char *hostname,
size_t buffersize);
DDS_EXPORT dds_retcode_t
ddsrt_socket(
ddsrt_socket_t *sockptr,
int domain,
int type,
int protocol);
DDS_EXPORT dds_retcode_t
ddsrt_close(
ddsrt_socket_t sock);
DDS_EXPORT dds_retcode_t
ddsrt_connect(
ddsrt_socket_t sock,
const struct sockaddr *addr,
socklen_t addrlen);
DDS_EXPORT dds_retcode_t
ddsrt_accept(
ddsrt_socket_t sock,
struct sockaddr *addr,
socklen_t *addrlen,
ddsrt_socket_t *connptr);
DDS_EXPORT dds_retcode_t
ddsrt_listen(
ddsrt_socket_t sock,
int backlog);
DDS_EXPORT dds_retcode_t
ddsrt_bind(
ddsrt_socket_t sock,
const struct sockaddr *addr,
socklen_t addrlen);
DDS_EXPORT dds_retcode_t
ddsrt_getsockname(
ddsrt_socket_t sock,
struct sockaddr *addr,
socklen_t *addrlen);
DDS_EXPORT dds_retcode_t
ddsrt_send(
ddsrt_socket_t sock,
const void *buf,
size_t len,
int flags,
ssize_t *sent);
DDS_EXPORT dds_retcode_t
ddsrt_sendmsg(
ddsrt_socket_t sock,
const ddsrt_msghdr_t *msg,
int flags,
ssize_t *sent);
DDS_EXPORT dds_retcode_t
ddsrt_recv(
ddsrt_socket_t sock,
void *buf,
size_t len,
int flags,
ssize_t *rcvd);
DDS_EXPORT dds_retcode_t
ddsrt_recvmsg(
ddsrt_socket_t sock,
ddsrt_msghdr_t *msg,
int flags,
ssize_t *rcvd);
DDS_EXPORT dds_retcode_t
ddsrt_getsockopt(
ddsrt_socket_t sock,
int32_t level, /* SOL_SOCKET */
int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */
void *optval,
socklen_t *optlen);
DDS_EXPORT dds_retcode_t
ddsrt_setsockopt(
ddsrt_socket_t sock,
int32_t level, /* SOL_SOCKET */
int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */
const void *optval,
socklen_t optlen);
/**
* @brief Set the I/O on the socket to blocking or non-nonblocking.
*
* @param[in] sock Socket to set I/O mode for.
* @param[in] nonblock true for nonblocking, or false for blocking I/O.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* I/O mode successfully set to (non)blocking.
* @retval DDS_RETCODE_TRY_AGAIN
* A blocking call is in progress.
* @retval DDS_RETCODE_BAD_PARAMETER
* @sock is not a valid socket.
* @retval DDS_RETCODE_ERROR
* An unknown error error occurred.
*/
DDS_EXPORT dds_retcode_t
ddsrt_setsocknonblocking(
ddsrt_socket_t sock,
bool nonblock);
DDS_EXPORT int32_t
ddsrt_select(
int32_t nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *errorfds,
dds_duration_t reltime,
int32_t *ready);
#if _WIN32
/* SOCKETs on Windows are NOT integers. The nfds parameter is only there for
compatibility, the implementation ignores it. Implicit casts will generate
warnings though, therefore ddsrt_select is redefined to discard the
parameter on Windows. */
#define ddsrt_select(nfds, readfds, writefds, errorfds, timeout, ready) \
ddsrt_select(-1, readfds, writefds, errorfds, timeout, ready)
#endif /* _WIN32 */
/**
* @brief Get the size of a socket address.
*
* @param[in] sa Socket address to return the size for.
*
* @returns Size of the socket address based on the address family, or 0 if
* the address family is unknown.
*/
DDS_EXPORT socklen_t
ddsrt_sockaddr_get_size(
const struct sockaddr *const sa) ddsrt_nonnull_all;
/**
* @brief Get the port number from a socket address.
*
* @param[in] sa Socket address to retrieve the port from.
*
* @return Port number in host order.
*/
DDS_EXPORT uint16_t
ddsrt_sockaddr_get_port(
const struct sockaddr *const sa) ddsrt_nonnull_all;
/**
* @brief Check if the given address is unspecified.
*
* @param[in] sa Socket address to check.
*
* @return true if the address is unspecified, false otherwise.
*/
DDS_EXPORT bool
ddsrt_sockaddr_isunspecified(
const struct sockaddr *__restrict sa) ddsrt_nonnull_all;
/**
* @brief Check if the given address is a loopback address.
*
* @param[in] sa Socket address to check.
*
* @return true if the address is a loopback address, false otherwise.
*/
DDS_EXPORT bool
ddsrt_sockaddr_isloopback(
const struct sockaddr *__restrict sa) ddsrt_nonnull_all;
/**
* @brief Check if given socket IP addresses reside in the same subnet.
*
* Checks if two socket IP addresses reside in the same subnet, considering the
* given subnetmask. IPv6 mapped IPv4 addresses are not taken in account.
*
* @param[in] sa1 First address
* @param[in] sa2 Second address.
* @param[in] mask Subnetmask.
*
* @returns true if both addresses reside in the same subnet, false otherwise.
*/
DDS_EXPORT bool
ddsrt_sockaddr_insamesubnet(
const struct sockaddr *sa1,
const struct sockaddr *sa2,
const struct sockaddr *mask)
ddsrt_nonnull_all;
DDS_EXPORT dds_retcode_t
ddsrt_sockaddrfromstr(
int af, const char *str, void *sa);
DDS_EXPORT dds_retcode_t
ddsrt_sockaddrtostr(
const void *sa, char *buf, size_t size);
#if DDSRT_HAVE_DNS
typedef struct {
size_t naddrs;
struct sockaddr_storage addrs[];
} ddsrt_hostent_t;
/**
* @brief Lookup addresses for given host name.
*
* @param[in] name Host name to resolve.
* @param[in] af Address family, either AF_INET, AF_INET6 or AF_UNSPEC.
* @param[out] hent Structure of type ddsrt_hostent_t.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Host name successfully resolved to address(es).
* @retval DDS_RETCODE_HOST_NOT_FOUND
* Host not found.
* @retval DDS_RETCODE_NO_DATA
* Valid name, no data record of requested type.
* @retval DDS_RETCODE_ERROR
* Nonrecoverable error.
* @retval DDS_RETCODE_TRY_AGAIN
* Nonauthoratitative host not found.
*/
DDS_EXPORT dds_retcode_t
ddsrt_gethostbyname(
const char *name,
int af,
ddsrt_hostent_t **hentp);
#endif
#endif /* DDSRT_SOCKETS_H */

View file

@ -0,0 +1,54 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_SOCKETS_POSIX_H
#define DDSRT_SOCKETS_POSIX_H
#include <net/if.h>
#include <netinet/in.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#if defined(__cplusplus)
extern "C" {
#endif
typedef int ddsrt_socket_t;
#define DDSRT_INVALID_SOCKET (-1)
#define PRIdSOCK "d"
#define DDSRT_HAVE_IPV6 1
#define DDSRT_HAVE_DNS 1
#define DDSRT_HAVE_SSM 1
typedef struct iovec ddsrt_iovec_t;
typedef size_t ddsrt_iov_len_t;
#if defined(__linux)
typedef size_t ddsrt_msg_iovlen_t;
#else /* POSIX says int (which macOS, FreeBSD, Solaris do) */
typedef int ddsrt_msg_iovlen_t;
#endif
typedef struct msghdr ddsrt_msghdr_t;
#if defined(__sun) && !defined(_XPG4_2)
# define DDSRT_MSGHDR_FLAGS 0
#else
# define DDSRT_MSGHDR_FLAGS 1
#endif
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_SOCKETS_POSIX_H */

View file

@ -0,0 +1,52 @@
#ifndef DDSRT_WINDOWS_SOCKET_H
#define DDSRT_WINDOWS_SOCKET_H
#include <winsock2.h>
#include <ws2tcpip.h>
#if defined(__cplusplus)
extern "C" {
#endif
typedef SOCKET ddsrt_socket_t;
#define DDSRT_INVALID_SOCKET (INVALID_SOCKET)
#define PRIdSOCK PRIuPTR
#define DDSRT_HAVE_IPV6 1
#define DDSRT_HAVE_DNS 1
#if defined(NTDDI_VERSION) && \
defined(_WIN32_WINNT_WS03) && \
(NTDDI_VERSION >= _WIN32_WINNT_WS03)
#define DDSRT_HAVE_SSM 1
#else
#define DDSRT_HAVE_SSM 0
#endif
#define IFF_POINTOPOINT IFF_POINTTOPOINT
typedef unsigned ddsrt_iov_len_t;
typedef struct ddsrt_iovec {
ddsrt_iov_len_t iov_len;
void *iov_base;
} ddsrt_iovec_t;
typedef DWORD ddsrt_msg_iovlen_t;
typedef struct ddsrt_msghdr {
void *msg_name;
socklen_t msg_namelen;
ddsrt_iovec_t *msg_iov;
ddsrt_msg_iovlen_t msg_iovlen;
void *msg_control;
size_t msg_controllen;
int msg_flags;
} ddsrt_msghdr_t;
#define DDSRT_MSGHDR_FLAGS 1
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_WINDOWS_SOCKET_H */

View file

@ -0,0 +1,198 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_STRING_H
#define DDSRT_STRING_H
#include "dds/export.h"
#include "dds/ddsrt/attributes.h"
#include "dds/ddsrt/retcode.h"
#if defined (__cplusplus)
extern "C" {
#endif
/**
* @brief Compare two strings ignoring case.
*
* @param[in] s1 String to compare.
* @param[in] s2 String to compare.
*
* @returns Zero if @s1 and @s2 match, a negative integer if @s1 is less than
* @s2 or a positive integer if @s1 is greater than @s2.
*/
DDS_EXPORT int
ddsrt_strcasecmp(
const char *s1,
const char *s2)
ddsrt_nonnull_all;
/**
* @brief Compare two strings ignoring case, but no more than @n bytes.
*
* @param[in] s1 String to compare.
* @param[in] s2 String to compare.
* @param[in] n Maximum number of bytes to compare.
*
* @returns Zero if @s1 and @s2 match, a negative integer if @s1 is less than
* @s2 or a positive integer if @s1 is greater than @s2.
*/
DDS_EXPORT int
ddsrt_strncasecmp(
const char *s1,
const char *s2,
size_t n)
ddsrt_nonnull((1,2));
/**
* @brief Split string into tokens.
*
* @param[in] str String to split into tokens.
* @param[in] delim Characters that delimit a token.
* @param[inout] saveptr Pointer to a char * used internally.
*
* @returns The next token or NULL if there are no more tokens.
*/
DDS_EXPORT char *
ddsrt_strtok_r(
char *str,
const char *delim,
char **saveptr);
/**
* @brief Extract token from string.
*
* Finds the first token in @stringp delimited by one of the characters in
* @delim. The delimiter is overwritten with a null byte, terminating the
* token and @stringp is updated to point past the delimiter.
*
* @param[inout] stringp String to extract token from.
* @param[in] delim Characters that delimit a token.
*
* @returns The original value of @stringp.
*/
DDS_EXPORT char *
ddsrt_strsep(
char **stringp,
const char *delim);
/**
* @brief Duplicate block of memory.
*
* Copy a block of memory into a newly allocated block of memory. The memory
* is obtained with @ddsrt_malloc and must be freed with @ddsrt_free when it
* is no longer used.
*
* @param[in] ptr Pointer to block of memory to duplicate.
* @param[in] len Number of bytes to copy into newly allocated buffer.
*
* @returns A new block of memory that is a duplicate of the block pointed to
* by @ptr or NULL if not enough memory was available.
*/
DDS_EXPORT void *
ddsrt_memdup(
const void *ptr,
size_t len)
ddsrt_nonnull((1))
ddsrt_attribute_malloc;
/**
* @brief Duplicate string.
*
* Copy string into a newly allocated block of memory. The memory is obtained
* with @ddsrt_malloc and must freed with @ddsrt_free when it is no longer
* used.
*
* @param[in] str String to duplicate.
*
* @returns A new string that is a duplicate of @str or NULL if not enough
* memory was available.
*/
DDS_EXPORT char *
ddsrt_strdup(
const char *str)
ddsrt_nonnull_all
ddsrt_attribute_malloc;
/**
* @brief Copy string.
*
* Copy string to buffer with specified size. The string is truncated if there
* is not enough space. The resulting string is guaranteed to be null
* terminated if there is space.
*
* @param[out] dest Destination buffer.
* @param[in] src Null terminated string to copy to dest.
* @param[in] size Number of bytes available in dest.
*
* @returns Number of characters copied to dest (excluding the null byte), or
* the number of characters that would have been copied if dest is not
* sufficiently large enough.
*/
DDS_EXPORT
size_t
ddsrt_strlcpy(
char * __restrict dest,
const char * __restrict src,
size_t size)
ddsrt_nonnull((1,2));
/**
* @brief Concatenate strings.
*
* Append the string specified by src to the string specified by dest. The
* terminating null byte at the end of dest is overwritten. The resulting
* string is truncated if there is not enough space. The resulting string
* guaranteed to be null terminated if there is space.
*
* @param[inout] dest Destination buffer.
* @param[in] src Null terminated string to append to dest.
* @param[in] size Number of bytes available in dest.
*
* @returns Number of characters copied to dest (excluding the null byte), or
* the number of characters that would have been copied if dest is not
* sufficiently large enough.
*/
DDS_EXPORT
size_t
ddsrt_strlcat(
char * __restrict dest,
const char * __restrict src,
size_t size)
ddsrt_nonnull((1,2));
/**
* @brief Get description for specified system error number.
*
* @param[in] errnum System error number.
* @param[in] buf Buffer where description is copied to.
* @param[in] buflen Number of bytes available in @buf.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Description for @errnum was successfully copied to @buf.
* @retval DDS_RETCODE_BAD_PARAMETER
* Unknown error number.
* @retval DDS_RETCODE_NOT_ENOUGH_SPACE
* Buffer was not large enough to hold the description.
*/
DDS_EXPORT dds_retcode_t
ddsrt_strerror_r(
int errnum,
char *buf,
size_t buflen);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_STRING_H */

View file

@ -0,0 +1,75 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
/**
* @file strtod.h
* @brief Floating-point number to/from string conversion functions.
*
* Locale independent versions of the floating-point number conversion
* functions found in the standard library.
*/
#ifndef DDSRT_STRTOD_H
#define DDSRT_STRTOD_H
#include "dds/export.h"
#include "dds/ddsrt/retcode.h"
/**
* @brief Convert a string to a double precision floating point number.
*
* @param[in] nptr A string to convert into a double.
* @param[out] endptr If not NULL, a char* where the address of first invalid
* character is stored.
* @param[out] dblptr A double where the result is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*/
DDS_EXPORT dds_retcode_t
ddsrt_strtod(const char *nptr, char **endptr, double *dblptr);
/**
* @brief Convert a string to a floating point number.
*
* @param[in] nptr A string to convert into a float.
* @param[in] endptr If not NULL, a char* where the address of first invalid
* character is stored.
* @param[out] fltptr A float where the floating-point number is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*/
DDS_EXPORT dds_retcode_t
ddsrt_strtof(const char *nptr, char **endptr, float *fltptr);
/**
* @brief Convert a double-precision floating-point number to a string.
*
* @param[in] src Double-precision floating-point number to convert.
* @param[in] str Buffer where string representation is written.
* @param[in] size Number of bytes available in @str.
*
* @returns The number of bytes written (excluding the null terminating byte).
*/
DDS_EXPORT int
ddsrt_dtostr(double src, char *str, size_t size);
/**
* @brief convert a floating-point number to a string.
*
* @param[in] src Floating-point number to conver.
* @param[in] str Buffer where string representation is written.
* @param[in] size Number of bytes available in @str.
*
* @returns The number of bytes written (exluding the null terminating byte).
*/
DDS_EXPORT int
ddsrt_ftostr(float src, char *str, size_t size);
#endif /* DDSRT_STRTOD_H */

View file

@ -0,0 +1,168 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_STRTOL_H
#define DDSRT_STRTOL_H
#include <stdint.h>
#include "dds/export.h"
#include "dds/ddsrt/retcode.h"
#if defined(__cplusplus)
extern "C" {
#endif
/**
* @brief Convert a string to a long long integer.
*
* Translate @str to a long long integer considering base, and sign. If @base
* is 0, base is determined from @str. A prefix of "0x" or "0X" will cause the
* number be read in base 16 (hexadecimal), otherwise base 10 (decimal) is
* used, unless the first character is '0', in which case the number will be
* read in base 8 (octal).
*
* @param[in] str String to convert into a number.
* @param[out] endptr If not NULL, a char* where the address of first invalid
* character is stored.
* @param[in] base Base to use. Must be a base between 2 and 36, or 0 to
* determine from @str.
* @param[out] llng A long long integer where the number is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* String successfully converted to an integer.
* @retval DDS_RETCODE_BAD_PARAMETER
* Base is invalid.
* @retval DDS_RETCODE_OUT_OF_RANGE
* String converted to an integer, but was out of range.
*/
DDS_EXPORT dds_retcode_t
ddsrt_strtoll(
const char *str,
char **endptr,
int32_t base,
long long *llng);
/**
* @brief Convert a string to an unsigned long long integer.
*
* Translate @str to an unsigned long long integer considering base, and sign.
* If @base is 0, base is determined from @str. A prefix of "0x" or "0X" will
* cause the number be read in base 16 (hexadecimal), otherwise base 10
* (decimal) is used, unless the first character is '0', in which case the
* number will be read in base 8 (octal).
*
* @param[in] str String to convert into a number.
* @param[out] endptr If not NULL, a char* where the address of first invalid
* character is stored.
* @param[in] base Base to use. Must be a base between 2 and 36, or 0 to
* determine from @str.
* @param[out] ullng A long long integer where the number is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* String successfully converted to an integer.
* @retval DDS_RETCODE_BAD_PARAMETER
* Base is invalid.
* @retval DDS_RETCODE_OUT_OF_RANGE
* String converted to an integer, but was out of range.
*/
DDS_EXPORT dds_retcode_t
ddsrt_strtoull(
const char *str,
char **endptr,
int32_t base,
unsigned long long *ullng);
/**
* @brief Convert a string to a long long integer.
*
* @param[in] str String to convert into a long long integer.
* @param[in] llng A long long integer where the number is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* String successfully converted to an integer.
* @retval DDS_RETCODE_BAD_PARAMETER
* Base is invalid.
* @retval DDS_RETCODE_OUT_OF_RANGE
* String converted to an integer, but was out of range.
*/
DDS_EXPORT dds_retcode_t
ddsrt_atoll(
const char *str,
long long *llng);
/**
* @brief Convert a string to an unsigned long long integer.
*
* @param[in] str String to conver into an unsigned long long integer.
* @param[out] ullng An unsigned long long integer where the number is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* String successfully converted to an integer.
* @retval DDS_RETCODE_BAD_PARAMETER
* Base is invalid.
* @retval DDS_RETCODE_OUT_OF_RANGE
* String converted to an integer, but was out of range.
*/
DDS_EXPORT dds_retcode_t
ddsrt_atoull(
const char *str,
unsigned long long *ullng);
/**
* @brief Convert a long long integer into a string.
*
* @param[in] num Long long integer to convert into a string.
* @param[in] str Buffer where string representation is written.
* @param[in] len Number of bytes available in buffer.
* @param[out] endptr A char* where the address of the null terminating byte
* is stored.
*
* @returns The value of @str on success, otherwise NULL.
*/
DDS_EXPORT char *
ddsrt_lltostr(
long long num,
char *str,
size_t len,
char **endptr);
/**
* @brief Convert an unsigned long long integer into a string.
*
* @param[in] num Unsigned long long integer to covert into a string.
* @param[in] str Buffer where string representation is stored.
* @param[in] len Number of bytes available in buffer.
* @param[out] endptr A char* where the adress of the null terminating byte
* is stored.
*
* @returns The value of @str on success, otherwise NULL.
*/
DDS_EXPORT char *
ddsrt_ulltostr(
unsigned long long num,
char *str,
size_t len,
char **endptr);
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_STRTOL_H */

View file

@ -0,0 +1,298 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_SYNC_H
#define DDSRT_SYNC_H
#include <stdbool.h>
#include "dds/ddsrt/time.h"
#include "dds/ddsrt/retcode.h"
#include "dds/ddsrt/attributes.h"
#if _WIN32
#include "dds/ddsrt/sync/windows.h"
#else
#include "dds/ddsrt/sync/posix.h"
#endif
#if defined (__cplusplus)
extern "C" {
#endif
/**
* @brief Initialize a mutex.
*
* @param[in] mutex Mutex to itialize.
*/
DDS_EXPORT void
ddsrt_mutex_init(
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all;
/**
* @brief Destroy a mutex.
*
* @param[in] mutex Mutex to destroy.
*/
DDS_EXPORT void
ddsrt_mutex_destroy(
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all;
/**
* @brief Acquire a mutex.
*
* @param[in] mutex Mutex to acquire.
*/
DDS_EXPORT void
ddsrt_mutex_lock(
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all;
/**
* @brief Acquire a mutex if it is not already acquired.
*
* @param[in] mutex Mutex to acquire.
*
* @returns true if the mutex was acquired, false otherwise.
*/
DDS_EXPORT bool
ddsrt_mutex_trylock(
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all
ddsrt_attribute_warn_unused_result;
/**
* @brief Release an acquired mutex.
*
* @param[in] mutex Mutex to release.
*/
DDS_EXPORT void
ddsrt_mutex_unlock (
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all;
/**
* @brief Initialize a condition variable.
*
* @param[in] cond Condition variable to initialize.
*/
DDS_EXPORT void
ddsrt_cond_init(
ddsrt_cond_t *cond)
ddsrt_nonnull_all;
/**
* @brief Destroy a condition variable.
*
* @param[in] cond Condition variable to destroy.
*/
DDS_EXPORT void
ddsrt_cond_destroy(
ddsrt_cond_t *cond)
ddsrt_nonnull_all;
/**
* @brief Wait for a condition variable to be signalled.
*
* @param[in] cond Condition variable to block on.
* @param[in] mutex Mutex to associate with condition variable.
*
* @pre The calling thread must hold the mutex specified by @mutex.
*
* @post The calling thread will hold the mutex specified by @mutex.
*/
DDS_EXPORT void
ddsrt_cond_wait(
ddsrt_cond_t *cond,
ddsrt_mutex_t *mutex)
ddsrt_nonnull_all;
/**
* @brief Wait until @abstime for a condition variable to be signalled.
*
* @param[in] cond Condition variable to block on.
* @param[in] mutex Mutex to associate with condition variable.
* @param[in] abstime Time in nanoseconds since UNIX Epoch.
*
* @pre The calling thread must hold the mutex specified by @mutex.
*
* @post The calling thread will hold the mutex specified by @mutex.
*
* @returns false if the condition variable was not signalled before the
* absolute time specified by @abstime passed, otherwise true.
*/
DDS_EXPORT bool
ddsrt_cond_waituntil(
ddsrt_cond_t *cond,
ddsrt_mutex_t *mutex,
dds_time_t abstime)
ddsrt_nonnull((1,2));
/**
* @brief Wait for @reltime for a condition variable to be signalled.
*
* @param[in] cond Condition variable to block on.
* @param[in] mutex Mutex to associate with condition variable.
* @param[in] reltime Time in nanoseconds since UNIX Epoch.
*
* @pre The calling thread must hold the mutex specified by @mutex.
*
* @post The calling thread will hold the mutex specified by @mutex.
*
* @returns false if the condition variable was not signalled before the
* relative time specified by @reltime passed, otherwise true.
*/
DDS_EXPORT bool
ddsrt_cond_waitfor(
ddsrt_cond_t *cond,
ddsrt_mutex_t *mutex,
dds_duration_t reltime)
ddsrt_nonnull((1,2));
/**
* @brief Signal a condition variable and unblock at least one thread.
*
* @param[in] cond Condition variable to signal.
*
* @pre The mutex associated with the condition in general should be acquired
* by the calling thread before setting the condition state and
* signalling.
*/
DDS_EXPORT void
ddsrt_cond_signal(
ddsrt_cond_t *cond)
ddsrt_nonnull_all;
/**
* @brief Signal a condition variable and unblock all threads.
*
* @param[in] cond Condition variable to signal.
*
* @pre The mutex associated with the condition in general should be acquired
* by the calling thread before setting the condition state and
* signalling
*/
DDS_EXPORT void
ddsrt_cond_broadcast(
ddsrt_cond_t *cond)
ddsrt_nonnull_all;
/**
* @brief Initialize a read-write lock.
*
* @param[in] rwlock Read-write lock to initialize.
*/
DDS_EXPORT void
ddsrt_rwlock_init(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all;
/**
* @brief Destroy a read-write lock.
*
* @param[in] rwlock Read-write lock to destroy.
*/
DDS_EXPORT void
ddsrt_rwlock_destroy(
ddsrt_rwlock_t *rwlock);
/**
* @brief Acquire a read-write lock for reading.
*
* @param[in] rwlock Read-write lock to acquire.
*
* @post Data related to the critical section must not be changed by the
* calling thread.
*/
DDS_EXPORT void
ddsrt_rwlock_read(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all;
/**
* @brief Acquire a read-write lock for writing.
*
* @param[in] rwlock Read-write lock to acquire.
*/
DDS_EXPORT void
ddsrt_rwlock_write(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all;
/**
* @brief Try to acquire a read-write lock for reading.
*
* Try to acquire a read-write lock while for reading, immediately return if
* the lock is already exclusively acquired by another thread.
*
* @param[in] rwlock Read-write lock to aqcuire.
*
* @post Data related to the critical section must not changed by the
* calling thread.
*
* @returns true if the lock was acquired, otherwise false.
*/
DDS_EXPORT bool
ddsrt_rwlock_tryread(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all
ddsrt_attribute_warn_unused_result;
/**
* @brief Try to acquire a read-write lock for writing.
*
* Try to acquire a read-write lock for writing, immediately return if the
* lock is already acquired, either for reading or writing, by another thread.
*
* @param[in] rwlock Read-write lock to acquire.
*
* @returns true if the lock was acquired, otherwise false.
*/
DDS_EXPORT bool
ddsrt_rwlock_trywrite(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all
ddsrt_attribute_warn_unused_result;
/**
* @brief Release a previously acquired read-write lock.
*
* @param[in] rwlock Read-write lock to release.
*/
DDS_EXPORT void
ddsrt_rwlock_unlock(
ddsrt_rwlock_t *rwlock)
ddsrt_nonnull_all;
/* Initialization callback used by ddsrt_once */
typedef void (*ddsrt_once_fn)(void);
/**
* @brief Invoke init_fn exactly once for a given control.
*
* The first thread to call this function with a given control will call the
* function specified by @init_fn with no arguments. All following calls with
* the same control will not call the specified function.
*
* @pre The control parameter is properly initialized with DDSRT_ONCE_INIT.
*/
DDS_EXPORT void
ddsrt_once(
ddsrt_once_t *control,
ddsrt_once_fn init_fn);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_SYNC_H */

View file

@ -0,0 +1,44 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_POSIX_SYNC_H
#define DDSRT_POSIX_SYNC_H
#include <stdint.h>
#include <pthread.h>
#if HAVE_LKST
#include "lkst.h"
#endif
#if defined (__cplusplus)
extern "C" {
#endif
typedef struct {
pthread_cond_t cond;
} ddsrt_cond_t;
typedef struct {
pthread_mutex_t mutex;
} ddsrt_mutex_t;
typedef struct {
pthread_rwlock_t rwlock;
} ddsrt_rwlock_t;
typedef pthread_once_t ddsrt_once_t;
#define DDSRT_ONCE_INIT PTHREAD_ONCE_INIT
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_POSIX_SYNC_H */

View file

@ -0,0 +1,39 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_WINDOWS_SYNC_H
#define DDSRT_WINDOWS_SYNC_H
#if defined (__cplusplus)
extern "C" {
#endif
typedef struct {
CONDITION_VARIABLE cond;
} ddsrt_cond_t;
typedef struct {
SRWLOCK lock;
} ddsrt_mutex_t;
typedef struct os_rwlock {
SRWLOCK lock;
int state; /* -1: exclusive, 0: free, 1: shared */
} ddsrt_rwlock_t;
typedef INIT_ONCE ddsrt_once_t;
#define DDSRT_ONCE_INIT INIT_ONCE_STATIC_INIT
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_WINDOWS_SYNC_H */

View file

@ -0,0 +1,262 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
/**
* @file threads.h
* @brief Thread management and creation.
*
* Platform independent interface for managing and creating execution threads.
*/
#ifndef DDSRT_THREADS_H
#define DDSRT_THREADS_H
#include <stdbool.h>
#include <stdint.h>
#include "dds/export.h"
#include "dds/ddsrt/attributes.h"
#include "dds/ddsrt/retcode.h"
#if _WIN32
#include "dds/ddsrt/threads/windows.h"
#else
#include "dds/ddsrt/threads/posix.h"
#endif
#if defined (__cplusplus)
extern "C" {
#endif
#if defined(_MSC_VER)
/* Thread-local storage using __declspec(thread) on Windows versions before
Vista and Server 2008 works in DLLs if they are bound to the executable,
it does not work if the library is loaded using LoadLibrary. */
#define ddsrt_thread_local __declspec(thread)
#elif defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 2)
/* GCC supports Thread-local storage for x86 since version 3.3. Clang
supports Thread-local storage since version 2.0. */
/* VxWorks 7 supports __thread for both GCC and DIAB, older versions may
support it as well, but that is not verified. */
#define ddsrt_thread_local __thread
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#define ddsrt_thread_local __thread
#else
#error "Thread-local storage is not supported"
#endif
/**
* @brief Definition for a thread routine invoked on thread create.
*/
typedef uint32_t (*ddsrt_thread_routine_t)(void*);
/**
* @brief Thread scheduling classes
* @{
*/
typedef enum {
/** Schedule processes and threads according a platform default.
* DDSRT_SCHED_REALTIME for timesharing platforms and
* DDSRT_SCHED_TIMESHARE for realtime platforms
*/
DDSRT_SCHED_DEFAULT,
/** Schedule processes and threads on realtime basis,
* on most platforms implying:
* - Fixed Priority
* - Preemption
* - Either "First In First Out" or "Round Robin"
*/
DDSRT_SCHED_REALTIME,
/** Schedule processes and threads on timesharing basis,
* on most platforms implying:
* - Dynamic Priority to guarantee fair share
* - Preemption
*/
DDSRT_SCHED_TIMESHARE
} ddsrt_sched_t;
/** @} */
/**
* @brief Definition of the thread attributes
*/
typedef struct {
/** Specifies the scheduling class */
ddsrt_sched_t schedClass;
/** Specifies the thread priority */
int32_t schedPriority;
/** Specifies the thread stack size */
uint32_t stackSize;
} ddsrt_threadattr_t;
/**
* @brief Initialize thread attributes to platform defaults.
*/
DDS_EXPORT void
ddsrt_threadattr_init(
ddsrt_threadattr_t *attr)
ddsrt_nonnull_all;
/**
* @brief Create a new thread.
*
* Creates a new thread of control that executes concurrently with
* the calling thread. The new thread applies the function start_routine
* passing it arg as first argument.
*
* The new thread terminates by returning from the start_routine function.
* The created thread is identified by the returned threadId.
*
* @param[out] thread Location where thread id is stored.
* @param[in] name Name assigned to created thread.
* @param[in] attr Attributes to create thread with.
* @param[in] start_routine Function to execute in created thread.
* @param[in] arg Argument passed to @start_routine.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Thread successfully created.
* @retval DDS_RETCODE_ERROR
* Thread could not be created.
*/
DDS_EXPORT dds_retcode_t
ddsrt_thread_create(
ddsrt_thread_t *thread,
const char *name,
const ddsrt_threadattr_t *attr,
ddsrt_thread_routine_t start_routine,
void *arg)
ddsrt_nonnull((1,2,3,4));
/**
* @brief Retrieve integer representation of the given thread id.
*
* @returns The integer representation of the given thread.
*/
DDS_EXPORT ddsrt_tid_t
ddsrt_gettid(void);
/**
* @brief Return thread ID of the calling thread.
*
* @returns Thread ID of the calling thread.
*/
DDS_EXPORT ddsrt_thread_t
ddsrt_thread_self(void);
/**
* @brief Compare thread identifiers.
*
* @returns true if thread ids match, otherwise false.
*/
DDS_EXPORT bool
ddsrt_thread_equal(ddsrt_thread_t t1, ddsrt_thread_t t2);
/**
* @brief Wait for termination of the specified thread.
*
* If the specified thread is still running, wait for its termination
* else return immediately. In thread_result it returns the exit status
* of the thread. If NULL is passed for @thread_result, no exit status is
* returned, but ddsrt_thread_join still waits for the thread to terminate.
*
* @param[in] thread Id of thread to wait for.
* @param[out] thread_result Location where thread result is stored.
*
* @returns A dds_retcode_t indicating success or failure.
*
* @retval DDS_RETCODE_OK
* Target thread terminated.
* @retval DDS_RETCODE_ERROR
* An error occurred while waiting for the thread to terminate.
*/
DDS_EXPORT dds_retcode_t
ddsrt_thread_join(
ddsrt_thread_t thread,
uint32_t *thread_result);
/**
* @brief Get name of current thread.
*
* @param[in] name Buffer where the name is copied to.
* @param[in] size Number of bytes available in the buffer.
*
* @returns The number of bytes (excluding the null terminating bytes) that
* are written. If the buffer is not sufficiently large enough, the
* name is truncated and the number of bytes that would have been
* written is returned.
*/
DDS_EXPORT size_t
ddsrt_thread_getname(
char *__restrict name,
size_t size);
/**
* @brief Set name of current thread.
*
* Set name of the current thread to @name. If the name is longer than the
* platform maximum, it is silently truncated.
*
* @param[in] name Name for current thread.
*/
DDS_EXPORT void
ddsrt_thread_setname(
const char *__restrict name);
/**
* @brief Push cleanup handler onto the cleanup stack
*
* Push a cleanup handler onto the top of the calling thread's cleanup
* stack. The cleanup handler will be popped of the thread's cleanup stack
* and invoked with the specified argument when the thread exits.
*
* @param[in] routine Cleanup handler to push onto the thread cleanup stack.
* @param[in] arg Argument that will be passed to the cleanup handler.
*/
DDS_EXPORT dds_retcode_t
ddsrt_thread_cleanup_push(
void (*routine)(void*),
void *arg);
/**
* @brief Pop cleanup handler from the top of the cleanup stack
*
* Remove routine at the top of the calling thread's cleanup stack and
* optionally invoke it (if execute is non-zero).
*/
DDS_EXPORT dds_retcode_t
ddsrt_thread_cleanup_pop(
int execute);
/**
* @brief Initialize thread internals.
*
* Initialize internals for threads not created with @ddsrt_create_thread. By
* default initialization is done automatically.
*/
DDS_EXPORT void
ddsrt_thread_init(void);
/**
* @brief Free thread resources and execute cleanup handlers.
*
* Platforms that support it, automatically free resources claimed by the
* current thread and call any registered cleanup routines. This function only
* needs to be called on platforms that do not support thread destructors and
* only for threads that were not created with @ddsrt_thread_create.
*/
DDS_EXPORT void
ddsrt_thread_fini(void);
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_THREADS_H */

View file

@ -0,0 +1,59 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_POSIX_THREAD_H
#define DDSRT_POSIX_THREAD_H
#include <pthread.h>
#if defined (__cplusplus)
extern "C" {
#endif
#if defined(__linux)
typedef long int ddsrt_tid_t;
#define PRIdTID "ld"
/* __linux */
#elif defined(__FreeBSD__) && (__FreeBSD_version >= 900031)
/* FreeBSD >= 9.0 */
typedef int ddsrt_tid_t;
#define PRIdTID "d"
/* __FreeBSD__ */
#elif defined(__APPLE__) && !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
__MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
/* macOS X >= 10.6 */
typedef uint64_t ddsrt_tid_t;
#define PRIdTID PRIu64
/* __APPLE__ */
#elif defined(__VXWORKS__)
/* TODO: Verify taskIdSelf is the right function to use on VxWorks */
typedef TASK_ID ddsrt_tid_t;
# if defined(_WRS_CONFIG_LP64)
# define PRIdPID PRIuPTR /* typedef struct windTcb *TASK_ID */
# else
# define PRIdPID "d" /* typedef int TASK_ID */
# endif
/* __VXWORKS__ */
#else
typedef uintmax_t ddsrt_tid_t;
#define PRIdTID PRIuPTR
#endif
/* Wrapped in a struct to force conformation to abstraction. */
typedef struct {
pthread_t v;
} ddsrt_thread_t;
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_POSIX_THREAD_H */

View file

@ -0,0 +1,33 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_WINDOWS_THREADS_H
#define DDSRT_WINDOWS_THREADS_H
#include "dds/ddsrt/types.h"
#if defined (__cplusplus)
extern "C" {
#endif
typedef struct {
DWORD tid;
HANDLE handle;
} ddsrt_thread_t;
typedef DWORD ddsrt_tid_t;
#define PRIdTID "u"
#if defined (__cplusplus)
}
#endif
#endif /* DDSRT_WINDOWS_THREADS_H */

View file

@ -0,0 +1,149 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
/**
* @file
* @brief DDS C Time support API
*
* This header file defines the public API of the in the
* CycloneDDS C language binding.
*/
#ifndef DDS_TIME_H
#define DDS_TIME_H
#include <stdint.h>
#include "dds/export.h"
#include "dds/ddsrt/types.h"
#if defined (__cplusplus)
extern "C" {
#endif
/*
Times are represented using a 64-bit signed integer, encoding
nanoseconds since the epoch. Considering the nature of these
systems, one would best use TAI, International Atomic Time, rather
than something UTC, but availability may be limited.
Valid times are non-negative and times up to 2**63-2 can be
represented. 2**63-1 is defined to represent, essentially, "never".
This is good enough for a couple of centuries.
*/
/** Absolute Time definition */
typedef int64_t dds_time_t;
/** Relative Time definition */
typedef int64_t dds_duration_t;
/** @name Macro definition for time units in nanoseconds.
@{**/
#define DDS_NSECS_IN_SEC INT64_C(1000000000)
#define DDS_NSECS_IN_MSEC INT64_C(1000000)
#define DDS_NSECS_IN_USEC INT64_C(1000)
/** @}*/
/** @name Infinite timeout for indicate absolute time */
#define DDS_NEVER ((dds_time_t) INT64_MAX)
/** @name Infinite timeout for relative time */
#define DDS_INFINITY ((dds_duration_t) INT64_MAX)
/** @name Macro definition for time conversion to nanoseconds
@{**/
#define DDS_SECS(n) ((n) * DDS_NSECS_IN_SEC)
#define DDS_MSECS(n) ((n) * DDS_NSECS_IN_MSEC)
#define DDS_USECS(n) ((n) * DDS_NSECS_IN_USEC)
/** @}*/
/**
* @brief Get the current time in nanoseconds since the UNIX Epoch.
*
* @returns Current time.
*/
DDS_EXPORT dds_time_t dds_time(void);
/**
* @brief Suspend execution of calling thread until relative time n elapsed.
*
* Execution is suspended for n nanoseconds. Should the call be interrupted,
* the call is re-entered with the remaining time.
*
* @param[in] reltime Relative time in nanoseconds.
*/
DDS_EXPORT void dds_sleepfor (dds_duration_t reltime);
/**
* @brief Suspend execution of calling thread until absolute time n elapsed.
*
* Execution is suspended until the given absolute time elapsed. Should the
* call be interrupted, it is re-entered with the remaining time.
*
* @param[in] abstime Absolute time in nanoseconds since UNIX Epoch.
*/
DDS_EXPORT void dds_sleepuntil (dds_time_t abstime);
/**
* @brief Get high resolution, monotonic time.
*
* The monotonic clock is a clock with near real-time progression and can be
* used when a high-resolution time is needed without the need for it to be
* related to the wall-clock. The resolution of the clock is typically the
* highest available on the platform.
*
* The clock is not guaranteed to be strictly monotonic, but on most common
* platforms it will be (based on performance-counters or HPET's).
*
* @returns Monotonic time if available, otherwise real time.
*/
DDS_EXPORT dds_time_t ddsrt_time_monotonic(void);
/**
* @brief Get high resolution, elapsed (and thus monotonic) time since some
* fixed unspecified past time.
*
* The elapsed time clock is a clock with near real-time progression and can be
* used when a high-resolution suspend-aware monotonic clock is needed, without
* having to deal with the complications of discontinuities if for example the
* time is changed. The fixed point from which the elapsed time is returned is
* not guaranteed to be fixed over reboots of the system.
*
* @returns Elapsed time if available, otherwise return monotonic time.
*/
DDS_EXPORT dds_time_t ddsrt_time_elapsed(void);
/**
* @brief Convert time into a human readable string in RFC 3339 format.
*
* Converts the calender time into a null-terminated string in RFC 3339 format.
* e.g. "2014-10-24 15:32:27-04:00".
*
* UTC offset is omitted if time-zone information is unknown.
*
* @param[in] abstime Time in nanoseconds since UNIX Epoch.
* @param[in] str String to write human readable timestamp to.
* @param[in] size Number of bytes available in @str.
*
* @returns Number of bytes written (excluding terminating null byte). The
* string is truncated if str is not sufficiently large enough. Thus,
* a return value of size or more means the output was truncated.
*/
#define DDSRT_RFC3339STRLEN (25)
DDS_EXPORT size_t ddsrt_ctime(dds_time_t abstime, char *str, size_t size);
#if defined(__cplusplus)
}
#endif
#endif /* DDSRT_TIME_H */

View file

@ -0,0 +1,30 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_TYPES_H
#define DDSRT_TYPES_H
#include <stdbool.h>
#include <stdint.h>
#if _WIN32
# include "dds/ddsrt/types/windows.h"
#elif __VXWORKS__
# include "dds/ddsrt/types/vxworks.h"
#else
# include "dds/ddsrt/types/posix.h"
#endif
#define PRIdSIZE "zd"
#define PRIuSIZE "zu"
#define PRIxSIZE "zx"
#endif /* DDSRT_TYPES_H */

View file

@ -0,0 +1,19 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_TYPES_POSIX_H
#define DDSRT_TYPES_POSIX_H
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
#endif /* DDSRT_TYPES_POSIX_H */

View file

@ -0,0 +1,74 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_TYPES_VXWORKS_H
#define DDSRT_TYPES_VXWORKS_H
#if defined(_WRS_KERNEL)
/* inttypes.h does not exist in VxWorks DKM. */
#include <st_inttypes.h>
#include <cafe/inttypes.h>
/* The above inttypes includes don't seem to define uintmax_t &c. */
#ifdef _WRS_CONFIG_LP64 /* Used in cafe/inttypes.h too. */
#define _PFX_64 "l"
typedef unsigned long int uintmax_t;
#else
#define _PFX_64 "ll"
typedef unsigned long long int uintmax_t;
#endif
/* Not a complete replacement for inttypes.h (yet); No SCN/PRI?LEAST/FAST/etc. */
#define PRId8 "d"
#define PRId16 "d"
#define PRId32 "d"
#define PRId64 _PFX_64 "d"
#define PRIi8 "i"
#define PRIi16 "i"
#define PRIi32 "i"
#define PRIi64 _PFX_64 "i"
#define PRIo8 "o"
#define PRIo16 "o"
#define PRIo32 "o"
#define PRIo64 _PFX_64 "o"
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "u"
#define PRIu64 _PFX_64 "u"
#define PRIx8 "x"
#define PRIx16 "x"
#define PRIx32 "x"
#define PRIX8 "X"
#define PRIX16 "X"
#define PRIX32 "X"
#define PRIX64 _PFX_64 "X"
#define PRIdMAX _PFX_64 "d"
#define PRIiMAX _PFX_64 "i"
#define PRIoMAX _PFX_64 "o"
#define PRIuMAX _PFX_64 "u"
#define PRIxMAX _PFX_64 "x"
#define PRIXMAX _PFX_64 "X"
#define PRIdPTR _PFX_64 "d"
#define PRIiPTR _PFX_64 "i"
#define PRIoPTR _PFX_64 "o"
#define PRIXPTR _PFX_64 "X"
#else /* _WRS_KERNEL */
#include <inttypes.h>
#endif /* _WRS_KERNEL */
#endif /* DDSRT_TYPES_VXWORKS_H */

View file

@ -0,0 +1,27 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDSRT_TYPES_WINDOWS_H
#define DDSRT_TYPES_WINDOWS_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <VersionHelpers.h>
#include <stdint.h>
#include <inttypes.h>
#include <wchar.h>
typedef SSIZE_T ssize_t;
#endif /* DDSRT_TYPES_WINDOWS_H */

View file

@ -0,0 +1,28 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef DDS_VERSION_H
#define DDS_VERSION_H
#define DDS_VERSION "@CycloneDDS_VERSION@"
#define DDS_VERSION_MAJOR @CycloneDDS_VERSION_MAJOR@
#define DDS_VERSION_MINOR @CycloneDDS_VERSION_MINOR@
#define DDS_VERSION_PATCH @CycloneDDS_VERSION_PATCH@
#define DDS_VERSION_TWEAK @CycloneDDS_VERSION_TWEAK@
#define DDS_PROJECT_NAME_NOSPACE_CAPS "@CMAKE_PROJECT_NAME_CAPS@"
#define DDS_PROJECT_NAME_NOSPACE_SMALL "@CMAKE_PROJECT_NAME_SMALL@"
#define DDS_PROJECT_NAME_NOSPACE "@CMAKE_PROJECT_NAME@"
#define DDS_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
#define DDS_HOST_NAME "@CMAKE_HOST_SYSTEM_NAME@"
#define DDS_TARGET_NAME "@CMAKE_SYSTEM_NAME@"
#endif /* DDS_VERSION_H */

View file

@ -0,0 +1,24 @@
/*
* Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef GETOPT_H
#define GETOPT_H
#include "dds/export.h"
DDS_EXPORT extern int opterr;
DDS_EXPORT extern int optind;
DDS_EXPORT extern int optopt;
DDS_EXPORT extern char *optarg;
DDS_EXPORT int getopt(int argc, char **argv, const char *opts);
#endif /* GETOPT_H */