Replace OS_INLINE by inline
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
parent
c86bda7aa4
commit
62b9b8d9dc
17 changed files with 488 additions and 766 deletions
|
@ -84,9 +84,7 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
|
|||
q_addrset.h
|
||||
q_align.h
|
||||
q_bitset.h
|
||||
q_bitset_template.h
|
||||
q_bswap.h
|
||||
q_bswap_template.h
|
||||
q_config.h
|
||||
q_ddsi_discovery.h
|
||||
q_debmon.h
|
||||
|
@ -116,7 +114,6 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
|
|||
q_sockwaitset.h
|
||||
q_static_assert.h
|
||||
q_thread.h
|
||||
q_thread_template.h
|
||||
q_time.h
|
||||
q_transmit.h
|
||||
q_inverse_uint32_set.h
|
||||
|
|
|
@ -15,22 +15,40 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "os/os_inline.h"
|
||||
#include "ddsi/q_unused.h"
|
||||
|
||||
#if OS_HAVE_INLINE && !defined SUPPRESS_BITSET_INLINES
|
||||
#include "q_bitset_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx);
|
||||
void nn_bitset_set (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
void nn_bitset_clear (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
void nn_bitset_zero (unsigned numbits, unsigned *bits);
|
||||
void nn_bitset_one (unsigned numbits, unsigned *bits);
|
||||
#if defined (__cplusplus)
|
||||
inline int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx)
|
||||
{
|
||||
return idx < numbits && (bits[idx/32] & (1u << (31 - (idx%32))));
|
||||
}
|
||||
|
||||
inline void nn_bitset_set (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] |= 1u << (31 - (idx%32));
|
||||
}
|
||||
|
||||
inline void nn_bitset_clear (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] &= ~(1u << (31 - (idx%32)));
|
||||
}
|
||||
|
||||
inline void nn_bitset_zero (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0, 4 * ((numbits + 31) / 32));
|
||||
}
|
||||
|
||||
inline void nn_bitset_one (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0xff, 4 * ((numbits + 31) / 32));
|
||||
|
||||
/* clear bits "accidentally" set */
|
||||
{
|
||||
const unsigned k = numbits / 32;
|
||||
const unsigned n = numbits % 32;
|
||||
bits[k] &= ~(~0u >> n);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* NN_BITSET_H */
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "ddsi/q_unused.h"
|
||||
|
||||
#if defined SUPPRESS_BITSET_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx)
|
||||
{
|
||||
return idx < numbits && (bits[idx/32] & (1u << (31 - (idx%32))));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_set (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] |= 1u << (31 - (idx%32));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_clear (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
|
||||
{
|
||||
assert (idx < numbits);
|
||||
bits[idx/32] &= ~(1u << (31 - (idx%32)));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_zero (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0, 4 * ((numbits + 31) / 32));
|
||||
}
|
||||
|
||||
OS_INLINE void nn_bitset_one (unsigned numbits, unsigned *bits)
|
||||
{
|
||||
memset (bits, 0xff, 4 * ((numbits + 31) / 32));
|
||||
|
||||
/* clear bits "accidentally" set */
|
||||
{
|
||||
const unsigned k = numbits / 32;
|
||||
const unsigned n = numbits % 32;
|
||||
bits[k] &= ~(~0u >> n);
|
||||
}
|
||||
}
|
|
@ -21,20 +21,28 @@
|
|||
#define bswap4(x) ((int32_t) bswap4u ((uint32_t) (x)))
|
||||
#define bswap8(x) ((int64_t) bswap8u ((uint64_t) (x)))
|
||||
|
||||
#if NN_HAVE_C99_INLINE && !defined SUPPRESS_BSWAP_INLINES
|
||||
#include "q_bswap_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
uint16_t bswap2u (uint16_t x);
|
||||
uint32_t bswap4u (uint32_t x);
|
||||
uint64_t bswap8u (uint64_t x);
|
||||
void bswapSN (nn_sequence_number_t *sn);
|
||||
#if defined (__cplusplus)
|
||||
inline uint16_t bswap2u (uint16_t x)
|
||||
{
|
||||
return (unsigned short) ((x >> 8) | (x << 8));
|
||||
}
|
||||
|
||||
inline uint32_t bswap4u (uint32_t x)
|
||||
{
|
||||
return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
|
||||
}
|
||||
|
||||
inline uint64_t bswap8u (uint64_t x)
|
||||
{
|
||||
const uint32_t newhi = bswap4u ((uint32_t) x);
|
||||
const uint32_t newlo = bswap4u ((uint32_t) (x >> 32));
|
||||
return ((uint64_t) newhi << 32) | (uint64_t) newlo;
|
||||
}
|
||||
|
||||
inline void bswapSN (nn_sequence_number_t *sn)
|
||||
{
|
||||
sn->high = bswap4 (sn->high);
|
||||
sn->low = bswap4u (sn->low);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if OS_ENDIANNESS == OS_LITTLE_ENDIAN
|
||||
#define toBE2(x) bswap2 (x)
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#if defined SUPPRESS_BSWAP_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE uint16_t bswap2u (uint16_t x)
|
||||
{
|
||||
return (unsigned short) ((x >> 8) | (x << 8));
|
||||
}
|
||||
|
||||
OS_INLINE uint32_t bswap4u (uint32_t x)
|
||||
{
|
||||
return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
|
||||
}
|
||||
|
||||
OS_INLINE uint64_t bswap8u (uint64_t x)
|
||||
{
|
||||
const uint32_t newhi = bswap4u ((uint32_t) x);
|
||||
const uint32_t newlo = bswap4u ((uint32_t) (x >> 32));
|
||||
return ((uint64_t) newhi << 32) | (uint64_t) newlo;
|
||||
}
|
||||
|
||||
OS_INLINE void bswapSN (nn_sequence_number_t *sn)
|
||||
{
|
||||
sn->high = bswap4 (sn->high);
|
||||
sn->low = bswap4u (sn->low);
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
#define Q_THREAD_H
|
||||
|
||||
#include "os/os.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
|
@ -100,27 +101,88 @@ struct thread_state1 * init_thread_state (_In_z_ const char *tname);
|
|||
void reset_thread_state (_Inout_opt_ struct thread_state1 *ts1);
|
||||
int thread_exists (_In_z_ const char *name);
|
||||
|
||||
inline int vtime_awake_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 0;
|
||||
}
|
||||
|
||||
inline int vtime_asleep_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 1;
|
||||
}
|
||||
|
||||
inline int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0)
|
||||
{
|
||||
Q_STATIC_ASSERT_CODE (sizeof (vtime_t) == sizeof (svtime_t));
|
||||
return (svtime_t) (vtime1 - vtime0) > 0;
|
||||
}
|
||||
|
||||
inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_awake_p (vt))
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
os_atomic_fence_acq ();
|
||||
}
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void thread_state_awake (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_asleep_p (vt))
|
||||
ts1->vtime = vt + 1;
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
}
|
||||
os_atomic_fence_acq ();
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void thread_state_unblocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NN_HAVE_C99_INLINE && !defined SUPPRESS_THREAD_INLINES
|
||||
#include "q_thread_template.h"
|
||||
#else
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
int vtime_awake_p (_In_ vtime_t vtime);
|
||||
int vtime_asleep_p (_In_ vtime_t vtime);
|
||||
int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0);
|
||||
|
||||
void thread_state_asleep (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_awake (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_blocked (_Inout_ struct thread_state1 *ts1);
|
||||
void thread_state_unblocked (_Inout_ struct thread_state1 *ts1);
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* Q_THREAD_H */
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "os/os_atomics.h"
|
||||
#include "ddsi/q_static_assert.h"
|
||||
|
||||
#if defined SUPPRESS_THREAD_INLINES && defined OS_INLINE
|
||||
#undef OS_INLINE
|
||||
#define OS_INLINE
|
||||
#endif
|
||||
|
||||
OS_INLINE int vtime_awake_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 0;
|
||||
}
|
||||
|
||||
OS_INLINE int vtime_asleep_p (_In_ vtime_t vtime)
|
||||
{
|
||||
return (vtime % 2) == 1;
|
||||
}
|
||||
|
||||
OS_INLINE int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0)
|
||||
{
|
||||
Q_STATIC_ASSERT_CODE (sizeof (vtime_t) == sizeof (svtime_t));
|
||||
return (svtime_t) (vtime1 - vtime0) > 0;
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_asleep (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_awake_p (vt))
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
os_atomic_fence_acq ();
|
||||
}
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_awake (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t vt = ts1->vtime;
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if (vtime_asleep_p (vt))
|
||||
ts1->vtime = vt + 1;
|
||||
else
|
||||
{
|
||||
os_atomic_fence_rel ();
|
||||
ts1->vtime = vt + 2;
|
||||
}
|
||||
os_atomic_fence_acq ();
|
||||
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_blocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 2;
|
||||
} else {
|
||||
ts1->watchdog = wd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
OS_INLINE void thread_state_unblocked (_Inout_ struct thread_state1 *ts1)
|
||||
{
|
||||
vtime_t wd = ts1->watchdog;
|
||||
if ( wd % 2 ){
|
||||
ts1->watchdog = wd + 1;
|
||||
} else {
|
||||
ts1->watchdog = wd + 2;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,11 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_BITSET_INLINES
|
||||
|
||||
#include "ddsi/q_bitset.h"
|
||||
#include "ddsi/q_bitset_template.h"
|
||||
|
||||
extern inline int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_set (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_clear (unsigned numbits, unsigned *bits, unsigned idx);
|
||||
extern inline void nn_bitset_zero (unsigned numbits, unsigned *bits);
|
||||
extern inline void nn_bitset_one (unsigned numbits, unsigned *bits);
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_BSWAP_INLINES
|
||||
|
||||
#include "ddsi/q_bswap.h"
|
||||
#include "ddsi/q_bswap_template.h"
|
||||
|
||||
extern inline uint16_t bswap2u (uint16_t x);
|
||||
extern inline uint32_t bswap4u (uint32_t x);
|
||||
extern inline uint64_t bswap8u (uint64_t x);
|
||||
extern inline void bswapSN (nn_sequence_number_t *sn);
|
||||
|
||||
|
|
|
@ -9,7 +9,14 @@
|
|||
*
|
||||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
*/
|
||||
#define SUPPRESS_THREAD_INLINES
|
||||
|
||||
#include "ddsi/q_thread.h"
|
||||
#include "ddsi/q_thread_template.h"
|
||||
|
||||
extern inline int vtime_awake_p (_In_ vtime_t vtime);
|
||||
extern inline int vtime_asleep_p (_In_ vtime_t vtime);
|
||||
extern inline int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0);
|
||||
|
||||
extern inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_awake (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1);
|
||||
extern inline void thread_state_unblocked (_Inout_ struct thread_state1 *ts1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue