Merge pull request #80 from k0ekk0ek/gethostbyname

Cleanups of abstraction, layer, cmake, windows warnings and addition of os_gethostbyname
This commit is contained in:
eboasson 2019-01-09 08:22:23 +01:00 committed by GitHub
commit e518f9d0e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
151 changed files with 2182 additions and 2889 deletions

View file

@ -42,8 +42,6 @@ set(CMAKE_PROJECT_NAME_FULL "Cyclone DDS")
string(REPLACE " " "" PROJECT_NAME "${CMAKE_PROJECT_NAME_FULL}")
project(${PROJECT_NAME} VERSION 0.1.0)
find_package(Abstraction REQUIRED)
# Set some convenience variants of the project-name
string(REPLACE " " "-" CMAKE_PROJECT_NAME_DASHED "${CMAKE_PROJECT_NAME_FULL}")
string(TOUPPER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_CAPS)

View file

@ -1,42 +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
#
if (NOT TARGET Abstraction)
add_library(Abstraction INTERFACE)
endif()
# Link with the platform-specific threads library that find_package provides us
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
target_link_libraries(Abstraction INTERFACE Threads::Threads)
if(WIN32)
# Link with WIN32 core-libraries
target_link_libraries(Abstraction INTERFACE wsock32 ws2_32 iphlpapi)
# Many of the secure versions provided by Microsoft have failure modes
# which are not supported by our abstraction layer, so efforts trying
# to use the _s versions aren't typically the proper solution and C11
# (which contains most of the secure versions) is 'too new'. So we rely
# on static detection of misuse instead of runtime detection, so all
# these warnings can be disabled on Windows.
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) #Disabled warnings for deprecated Winsock 2 API calls in general
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) #Disabled warnings for deprecated POSIX names
elseif(UNIX AND NOT APPLE)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
# Shared libs will have this by default. Static libs need it too on x86_64.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
find_package(GetTime REQUIRED)
target_link_libraries(Abstraction INTERFACE GetTime)
endif()

View file

@ -1,28 +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
#
if (NOT TARGET GetTime)
add_library(GetTime INTERFACE)
endif()
include(CheckLibraryExists)
# First check whether libc has clock_gettime
check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME_IN_C)
if(NOT HAVE_CLOCK_GETTIME_IN_C)
# Before glibc 2.17, clock_gettime was in librt
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_IN_RT)
if (HAVE_CLOCK_GETTIME_IN_RT)
target_link_libraries(GetTime INTERFACE rt)
endif()
endif()

View file

@ -9,8 +9,6 @@
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#
find_package(Abstraction REQUIRED)
include (GenerateExportHeader)
FUNCTION(PREPEND var prefix)

View file

@ -537,8 +537,8 @@ dds_get_status_mask(
_Out_ uint32_t *mask);
_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK)
DDS_EXPORT _Check_return_ dds_return_t
DDS_DEPRECATED_EXPORT dds_get_enabled_status(
DDS_DEPRECATED_EXPORT _Check_return_ dds_return_t
dds_get_enabled_status(
_In_ dds_entity_t entity,
_Out_ uint32_t *mask);
@ -568,8 +568,7 @@ dds_set_status_mask(
_In_ uint32_t mask);
_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK)
DDS_EXPORT dds_return_t
DDS_DEPRECATED_EXPORT
DDS_DEPRECATED_EXPORT dds_return_t
dds_set_enabled_status(
_In_ dds_entity_t entity,
_In_ uint32_t mask);
@ -1115,8 +1114,7 @@ dds_set_topic_filter(
dds_topic_filter_fn filter);
_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC)
DDS_EXPORT void
DDS_DEPRECATED_EXPORT
DDS_DEPRECATED_EXPORT void
dds_topic_set_filter(
dds_entity_t topic,
dds_topic_filter_fn filter);
@ -1134,8 +1132,7 @@ dds_get_topic_filter(
dds_entity_t topic);
_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC)
DDS_EXPORT dds_topic_filter_fn
DDS_DEPRECATED_EXPORT
DDS_DEPRECATED_EXPORT dds_topic_filter_fn
dds_topic_get_filter(
dds_entity_t topic);
@ -3145,8 +3142,7 @@ dds_lookup_instance(
const void *data);
_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK)
DDS_EXPORT dds_instance_handle_t
DDS_DEPRECATED_EXPORT
DDS_DEPRECATED_EXPORT dds_instance_handle_t
dds_instance_lookup (
dds_entity_t entity,
const void *data);

View file

@ -149,17 +149,10 @@ dds_init(dds_domainid_t domain)
/* Set additional default participant properties */
gv.default_plist_pp.process_id = (unsigned)os_procIdSelf();
gv.default_plist_pp.process_id = (unsigned)os_getpid();
gv.default_plist_pp.present |= PP_PRISMTECH_PROCESS_ID;
if (os_procName(progname, sizeof(progname)) > 0)
{
gv.default_plist_pp.exec_name = dds_string_dup(progname);
}
else
{
gv.default_plist_pp.exec_name = dds_string_alloc(32);
(void) snprintf(gv.default_plist_pp.exec_name, 32, "%s: %u", DDSC_PROJECT_NAME, gv.default_plist_pp.process_id);
}
len = (uint32_t) (13 + strlen(gv.default_plist_pp.exec_name));
gv.default_plist_pp.present |= PP_PRISMTECH_EXEC_NAME;
if (os_gethostname(hostname, sizeof(hostname)) == os_resultSuccess)

View file

@ -533,7 +533,6 @@ void dds_qset_partition
)
{
uint32_t i;
size_t len;
if(!qos) {
DDS_ERROR("Argument qos may not be NULL\n");
@ -558,9 +557,7 @@ void dds_qset_partition
}
for (i = 0; i < n; i++) {
len = strlen (ps[i]) + 1;
qos->partition.strs[i] = dds_alloc (len);
strncpy (qos->partition.strs[i], ps[i], len);
qos->partition.strs[i] = dds_string_dup (ps[i]);
}
qos->present |= QP_PARTITION;
}

View file

@ -458,6 +458,7 @@ dds_create_topic(
nn_plist_t plist;
dds_entity_t hdl;
uint32_t index;
size_t keysz;
if (desc == NULL){
DDS_ERROR("Topic description is NULL");
@ -478,10 +479,9 @@ dds_create_topic(
}
typename = desc->m_typename;
key = (char*) dds_alloc (strlen (name) + strlen (typename) + 2);
strcpy (key, name);
strcat (key, "/");
strcat (key, typename);
keysz = strlen (name) + strlen (typename) + 2;
key = (char*) dds_alloc (keysz);
(void) snprintf(key, keysz, "%s/%s", name, typename);
st = dds_alloc (sizeof (*st));
@ -490,10 +490,8 @@ dds_create_topic(
st->c.status_cb = dds_topic_status_cb;
st->c.status_cb_entity = NULL; /* set by dds_create_topic_arbitrary */
st->c.name_typename = key;
st->c.name = dds_alloc (strlen (name) + 1);
strcpy (st->c.name, name);
st->c.typename = dds_alloc (strlen (typename) + 1);
strcpy (st->c.typename, typename);
st->c.name = dds_string_dup (name);
st->c.typename = dds_string_dup (typename);
st->c.ops = &ddsi_sertopic_ops_default;
st->c.serdata_ops = desc->m_nkeys ? &ddsi_serdata_ops_cdr : &ddsi_serdata_ops_cdr_nokey;
st->c.serdata_basehash = ddsi_sertopic_compute_serdata_basehash (st->c.serdata_ops);

View file

@ -45,9 +45,10 @@ static void config__check_env(
if ( !env_ok ) {
os_result r;
char *envstr;
size_t len = strlen(env_variable) + strlen("=") + strlen(expected_value) + 1;
envstr = os_malloc(strlen(env_variable) + strlen("=") + strlen(expected_value) + 1);
(void) sprintf(envstr, "%s=%s", env_variable, expected_value);
envstr = os_malloc(len);
(void)snprintf(envstr, len, "%s=%s", env_variable, expected_value);
r = os_putenv(envstr);
CU_ASSERT_EQUAL_FATAL(r, os_resultSuccess);

View file

@ -41,7 +41,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -47,7 +47,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -51,7 +51,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -312,7 +312,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -85,12 +85,12 @@ CU_Test(ddsc_participant, create_with_conf_no_env) {
dds_domainid_t valid_domain=3;
static char env_uri_str[1000];
(void) sprintf(env_uri_str, "%s=%s", DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI", CONFIG_ENV_SIMPLE_UDP);
(void) snprintf(env_uri_str, sizeof(env_uri_str), "%s=%s", DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI", CONFIG_ENV_SIMPLE_UDP);
os_putenv(env_uri_str);
printf("env_uri_str %s\n", env_uri_str);
static char env_mp_str[100];
(void) sprintf(env_mp_str, "%s=%s", "MAX_PARTICIPANTS", CONFIG_ENV_MAX_PARTICIPANTS);
(void) snprintf(env_mp_str, sizeof(env_mp_str), "%s=%s", "MAX_PARTICIPANTS", CONFIG_ENV_MAX_PARTICIPANTS);
os_putenv(env_mp_str);
const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");

View file

@ -68,7 +68,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -68,7 +68,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -61,7 +61,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -65,7 +65,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -85,7 +85,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -43,7 +43,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -69,7 +69,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -38,7 +38,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -43,7 +43,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -61,7 +61,7 @@ static char*
create_topic_name(const char *prefix, char *name, size_t size)
{
/* Get semi random g_topic name. */
os_procId pid = os_procIdSelf();
os_procId pid = os_getpid();
uintmax_t tid = os_threadIdToInteger(os_threadIdSelf());
(void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid);
return name;

View file

@ -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
@ -98,7 +96,6 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi"
q_gc.h
q_globals.h
q_hbcontrol.h
q_inline.h
q_lat_estim.h
q_lease.h
q_log.h
@ -117,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

View file

@ -14,7 +14,6 @@
#include "ddsi/q_time.h"
#include "ddsi/ddsi_sertopic.h"
#include "ddsi/sysdeps.h" /* for ddsi_iovec_t */
struct nn_rdata;
struct nn_keyhash;
@ -67,11 +66,11 @@ typedef void (*ddsi_serdata_to_ser_t) (const struct ddsi_serdata *d, size_t off,
calls to to_ser_ref() may be issued in parallel, the separate ref/unref bit is there to at least
have the option of lazily creating the serialised representation and freeing it when no one needs
it, while the sample itself remains valid */
typedef struct ddsi_serdata * (*ddsi_serdata_to_ser_ref_t) (const struct ddsi_serdata *d, size_t off, size_t sz, ddsi_iovec_t *ref);
typedef struct ddsi_serdata * (*ddsi_serdata_to_ser_ref_t) (const struct ddsi_serdata *d, size_t off, size_t sz, os_iovec_t *ref);
/* Release a lock on serialised data, ref must be a pointer previously obtained by calling
to_ser_ref(d, off, sz) for some offset off. */
typedef void (*ddsi_serdata_to_ser_unref_t) (struct ddsi_serdata *d, const ddsi_iovec_t *ref);
typedef void (*ddsi_serdata_to_ser_unref_t) (struct ddsi_serdata *d, const os_iovec_t *ref);
/* Turn serdata into an application sample (or just the key values if only key values are
available); return false on error (typically out-of-memory, but if from_ser doesn't do any
@ -146,11 +145,11 @@ inline void ddsi_serdata_to_ser (const struct ddsi_serdata *d, size_t off, size_
d->ops->to_ser (d, off, sz, buf);
}
inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, ddsi_iovec_t *ref) {
inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, os_iovec_t *ref) {
return d->ops->to_ser_ref (d, off, sz, ref);
}
inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const ddsi_iovec_t *ref) {
inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const os_iovec_t *ref) {
d->ops->to_ser_unref (d, ref);
}

View file

@ -14,7 +14,6 @@
#include "os/os.h"
#include "util/ut_avl.h"
#include "sysdeps.h"
#include "ddsi/ddsi_serdata.h"
#include "ddsi/ddsi_sertopic.h"
#include "ddsi/q_xqos.h"

View file

@ -16,7 +16,6 @@
#include "ddsi/q_plist.h" /* for nn_prismtech_writer_info */
#include "ddsi/q_freelist.h"
#include "util/ut_avl.h"
#include "sysdeps.h"
#include "ddsi/ddsi_serdata.h"
#include "ddsi/ddsi_sertopic.h"

View file

@ -37,10 +37,10 @@ typedef struct ddsi_tran_qos * ddsi_tran_qos_t;
/* Function pointer types */
typedef ssize_t (*ddsi_tran_read_fn_t) (ddsi_tran_conn_t, unsigned char *, size_t, nn_locator_t *);
typedef ssize_t (*ddsi_tran_write_fn_t) (ddsi_tran_conn_t, const nn_locator_t *, size_t, const ddsi_iovec_t *, uint32_t);
typedef ssize_t (*ddsi_tran_write_fn_t) (ddsi_tran_conn_t, const nn_locator_t *, size_t, const os_iovec_t *, uint32_t);
typedef int (*ddsi_tran_locator_fn_t) (ddsi_tran_base_t, nn_locator_t *);
typedef bool (*ddsi_tran_supports_fn_t) (int32_t);
typedef os_handle (*ddsi_tran_handle_fn_t) (ddsi_tran_base_t);
typedef os_socket (*ddsi_tran_handle_fn_t) (ddsi_tran_base_t);
typedef int (*ddsi_tran_listen_fn_t) (ddsi_tran_listener_t);
typedef void (*ddsi_tran_free_fn_t) (void);
typedef void (*ddsi_tran_peer_locator_fn_t) (ddsi_tran_conn_t, nn_locator_t *);
@ -188,7 +188,7 @@ int ddsi_tran_locator (ddsi_tran_base_t base, nn_locator_t * loc);
void ddsi_tran_free (ddsi_tran_base_t base);
void ddsi_tran_free_qos (ddsi_tran_qos_t qos);
ddsi_tran_qos_t ddsi_tran_create_qos (void);
os_handle ddsi_tran_handle (ddsi_tran_base_t base);
os_socket ddsi_tran_handle (ddsi_tran_base_t base);
#define ddsi_factory_create_listener(f,p,q) (((f)->m_create_listener_fn) ((p), (q)))
#define ddsi_factory_supports(f,k) (((f)->m_supports_fn) (k))
@ -208,7 +208,7 @@ void ddsi_factory_conn_init (ddsi_tran_factory_t factory, ddsi_tran_conn_t conn)
#define ddsi_conn_handle(c) (ddsi_tran_handle (&(c)->m_base))
#define ddsi_conn_locator(c,l) (ddsi_tran_locator (&(c)->m_base,(l)))
OSAPI_EXPORT ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsi_iovec_t *iov, uint32_t flags);
OSAPI_EXPORT ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const os_iovec_t *iov, uint32_t flags);
ssize_t ddsi_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, nn_locator_t *srcloc);
bool ddsi_conn_peer_locator (ddsi_tran_conn_t conn, nn_locator_t * loc);
void ddsi_conn_disable_multiplexing (ddsi_tran_conn_t conn);

View file

@ -15,22 +15,40 @@
#include <assert.h>
#include <string.h>
#include "ddsi/q_inline.h"
#include "ddsi/q_unused.h"
#if NN_HAVE_C99_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 */

View file

@ -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 NN_C99_INLINE
#undef NN_C99_INLINE
#define NN_C99_INLINE
#endif
NN_C99_INLINE int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx)
{
return idx < numbits && (bits[idx/32] & (1u << (31 - (idx%32))));
}
NN_C99_INLINE void nn_bitset_set (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
{
assert (idx < numbits);
bits[idx/32] |= 1u << (31 - (idx%32));
}
NN_C99_INLINE void nn_bitset_clear (UNUSED_ARG_NDEBUG (unsigned numbits), unsigned *bits, unsigned idx)
{
assert (idx < numbits);
bits[idx/32] &= ~(1u << (31 - (idx%32)));
}
NN_C99_INLINE void nn_bitset_zero (unsigned numbits, unsigned *bits)
{
memset (bits, 0, 4 * ((numbits + 31) / 32));
}
NN_C99_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);
}
}

View file

@ -14,7 +14,6 @@
#include "os/os.h"
#include "ddsi/q_inline.h"
#include "ddsi/q_rtps.h" /* for nn_guid_t, nn_guid_prefix_t */
#include "ddsi/q_protocol.h" /* for nn_sequence_number_t */
@ -22,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)

View file

@ -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 VDDS_INLINE
#undef VDDS_INLINE
#define VDDS_INLINE
#endif
VDDS_INLINE uint16_t bswap2u (uint16_t x)
{
return (unsigned short) ((x >> 8) | (x << 8));
}
VDDS_INLINE uint32_t bswap4u (uint32_t x)
{
return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
}
VDDS_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;
}
VDDS_INLINE void bswapSN (nn_sequence_number_t *sn)
{
sn->high = bswap4 (sn->high);
sn->low = bswap4u (sn->low);
}

View file

@ -87,7 +87,7 @@ struct q_security_plugins
q_securityDecoderSet (*new_decoder) (void);
c_bool (*free_encoder) (q_securityEncoderSet);
c_bool (*free_decoder) (q_securityDecoderSet);
ssize_t (*send_encoded) (ddsi_tran_conn_t, const nn_locator_t *dst, size_t niov, ddsi_iovec_t *iov, q_securityEncoderSet *, uint32_t, uint32_t);
ssize_t (*send_encoded) (ddsi_tran_conn_t, const nn_locator_t *dst, size_t niov, os_iovec_t *iov, q_securityEncoderSet *, uint32_t, uint32_t);
char * (*cipher_type) (q_cipherType);
c_bool (*cipher_type_from_string) (const char *, q_cipherType *);
uint32_t (*header_size) (q_securityEncoderSet, uint32_t);

View file

@ -13,7 +13,6 @@
#define NN_FREELIST_H
#include "os/os.h"
#include "ddsi/sysdeps.h"
#define FREELIST_SIMPLE 1
#define FREELIST_ATOMIC_LIFO 2

View file

@ -1,70 +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
*/
#ifndef NN_INLINE_H
#define NN_INLINE_H
#ifdef NN_SUPPRESS_C99_INLINE
#define NN_HAVE_C99_INLINE 0
#else
/* We want to inline these, but we don't want to emit an exernally
visible symbol for them and we don't want warnings if we don't use
them.
It appears as if a plain "inline" will do just that in C99.
In traditional GCC one had to use "extern inline" to achieve that
effect, but that will cause an externally visible symbol to be
emitted by a C99 compiler.
Starting with GCC 4.3, GCC conforms to the C99 standard if
compiling in C99 mode, unless -fgnu89-inline is specified. It
defines __GNUC_STDC_INLINE__ if "inline"/"extern inline" behaviour
is conforming the C99 standard.
So: GCC >= 4.3: choose between "inline" & "extern inline" based
upon __GNUC_STDC_INLINE__; for GCCs < 4.2, rely on the traditional
GCC behaiour; and for other compilers assume they behave conforming
the standard if they advertise themselves as C99 compliant (use
"inline"), and assume they do not support the inline keywords
otherwise.
GCC when not optimizing ignores "extern inline" functions. So we
need to distinguish between optimizing & non-optimizing ... */
#if __GNUC__
# if __OPTIMIZE__
# if 1 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
# ifdef __GNUC_STDC_INLINE__
# define NN_HAVE_C99_INLINE 1
# define NN_C99_INLINE inline
# else
# define NN_HAVE_C99_INLINE 1
# define NN_C99_INLINE extern inline
# endif
# else
# define NN_HAVE_C99_INLINE 1
# define NN_C99_INLINE extern inline
# endif
# endif
#elif __STDC_VERSION__ >= 199901L
# define NN_HAVE_C99_INLINE 1
# define NN_C99_INLINE inline
#endif
#endif /* NN_SUPPRESS_C99_INLINE */
#if ! NN_HAVE_C99_INLINE
#define NN_C99_INLINE
#endif
#endif /* NN_INLINE_H */

View file

@ -27,14 +27,17 @@ extern "C" {
if (dds_get_log_mask() & DDS_LC_TIMING) { \
nn_mtime_t tnowlt = now_mt(); \
if (tnowlt.v >= (guard).v) { \
const char fmt[] = "thread_cputime %d.%09d\n"; \
int64_t ts = get_thread_cputime (); \
dds_log( \
DDS_LC_TIMING, __FILE__, __LINE__, OS_FUNCTION, \
fmt, (int)(ts / T_SECOND), (int)(ts % T_SECOND)); \
os_rusage_t usage; \
if (os_getrusage(OS_RUSAGE_THREAD, &usage) == 0) { \
DDS_LOG( \
DDS_LC_TIMING, \
"thread_cputime %d.%09d\n", \
(int)usage.stime.tv_sec, \
(int)usage.stime.tv_nsec); \
(guard).v = tnowlt.v + T_SECOND; \
} \
} \
} \
} while (0)
#if defined (__cplusplus)

View file

@ -13,7 +13,6 @@
#define Q_SOCKWAITSET_H
#include "os/os_defs.h"
#include "ddsi/sysdeps.h"
#if defined (__cplusplus)
extern "C" {

View file

@ -13,8 +13,7 @@
#define Q_THREAD_H
#include "os/os.h"
#include "ddsi/q_inline.h"
#include "ddsi/q_static_assert.h"
#if defined (__cplusplus)
extern "C" {
@ -102,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 */

View file

@ -1,101 +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/sysdeps.h"
#include "os/os_atomics.h"
#include "ddsi/q_static_assert.h"
#if defined SUPPRESS_THREAD_INLINES && defined NN_C99_INLINE
#undef NN_C99_INLINE
#define NN_C99_INLINE
#endif
NN_C99_INLINE int vtime_awake_p (_In_ vtime_t vtime)
{
return (vtime % 2) == 0;
}
NN_C99_INLINE int vtime_asleep_p (_In_ vtime_t vtime)
{
return (vtime % 2) == 1;
}
NN_C99_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;
}
NN_C99_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;
}
}
NN_C99_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;
}
}
NN_C99_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;
}
}
NN_C99_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;
}
}

View file

@ -14,115 +14,6 @@
#include "os/os.h"
#include "ddsi/q_inline.h"
#ifndef os_sockECONNRESET
#ifdef WSAECONNRESET
#define os_sockECONNRESET WSAECONNRESET
#else
#define os_sockECONNRESET ECONNRESET
#endif
#endif
#ifndef os_sockEPERM
#ifdef WSAEACCES
#define os_sockEPERM WSAEACCES
#else
#define os_sockEPERM EPERM
#endif
#endif
#if defined (__linux) || defined (__sun) || defined (__APPLE__) || defined (INTEGRITY) || defined (AIX) || defined (OS_RTEMS_DEFS_H) || defined (__VXWORKS__) || defined (__Lynx__) || defined (__linux__) || defined (OS_QNX_DEFS_H)
#define SYSDEPS_HAVE_MSGHDR 1
#define SYSDEPS_HAVE_RECVMSG 1
#define SYSDEPS_HAVE_SENDMSG 1
#endif
#if defined (__linux) || defined (__sun) || defined (__APPLE__) || defined (INTEGRITY) || defined (AIX) || defined (OS_RTEMS_DEFS_H) || defined (__VXWORKS__) || defined (__linux__) || defined (OS_QNX_DEFS_H)
#define SYSDEPS_HAVE_IOVEC 1
#endif
#if defined (__linux) || defined (__sun) || defined (__APPLE__) || defined (AIX) || defined (__Lynx__) || defined (OS_QNX_DEFS_H)
#define SYSDEPS_HAVE_RANDOM 1
#include <unistd.h>
#endif
#if defined (__linux) || defined (__sun) || defined (__APPLE__) || defined (AIX) || defined (OS_QNX_DEFS_H)
#define SYSDEPS_HAVE_GETRUSAGE 1
#include <sys/time.h> /* needed for Linux, exists on all four */
#include <sys/times.h> /* needed for AIX, exists on all four */
#include <sys/resource.h>
#endif
#if defined (__linux) && defined (CLOCK_THREAD_CPUTIME_ID)
#define SYSDEPS_HAVE_CLOCK_THREAD_CPUTIME 1
#endif
#if defined (INTEGRITY)
#include <sys/uio.h>
#include <limits.h>
#endif
#if defined (VXWORKS_RTP)
#include <net/uio.h>
#endif
#if defined (_WIN32)
typedef SOCKET os_handle;
#define Q_VALID_SOCKET(s) ((s) != INVALID_SOCKET)
#define Q_INVALID_SOCKET INVALID_SOCKET
#else /* All Unixes have socket() return -1 on error */
typedef int os_handle;
#define Q_VALID_SOCKET(s) ((s) != -1)
#define Q_INVALID_SOCKET -1
#endif
/* From MSDN: from Vista & 2k3 onwards, a macro named MemoryBarrier is
defined, XP needs inline assembly. Unfortunately, MemoryBarrier()
is a function on x86 ...
Definition below is taken from the MSDN page on MemoryBarrier() */
#ifndef MemoryBarrier
#if NTDDI_VERSION >= NTDDI_WS03 && defined _M_IX86
#define MemoryBarrier() do { \
LONG Barrier; \
__asm { \
xchg Barrier, eax \
} \
} while (0)
#endif /* x86 */
/* Don't try interworking with thumb - one thing at a time. Do a DMB
SY if supported, else no need for a memory barrier. (I think.) */
#if defined _M_ARM && ! defined _M_ARMT
#define MemoryBarrierARM __emit (0xf57ff05f) /* 0xf57ff05f or 0x5ff07ff5 */
#if _M_ARM > 7
/* if targetting ARMv7 the dmb instruction is available */
#define MemoryBarrier() MemoryBarrierARM
#else
/* else conditional on actual hardware platform */
extern void (*q_maybe_membar) (void);
#define MemoryBarrier() q_maybe_membar ()
#define NEED_ARM_MEMBAR_SUPPORT 1
#endif /* ARM version */
#endif /* ARM */
#endif /* !def MemoryBarrier */
#if defined (__sun) && !defined (_XPG4_2)
#define SYSDEPS_MSGHDR_ACCRIGHTS 1
#else
#define SYSDEPS_MSGHDR_ACCRIGHTS 0
#endif
#if SYSDEPS_MSGHDR_ACCRIGHTS
#define SYSDEPS_MSGHDR_FLAGS 0
#else
#define SYSDEPS_MSGHDR_FLAGS 1
#endif
#if defined (__cplusplus)
}
#endif
#if defined (__cplusplus)
extern "C" {
@ -132,89 +23,8 @@ extern "C" {
#define ASSERT_WRLOCK_HELD(x) ((void) 0)
#define ASSERT_MUTEX_HELD(x) ((void) 0)
#if SYSDEPS_HAVE_IOVEC
typedef struct iovec ddsi_iovec_t;
typedef size_t ddsi_iov_len_t;
#elif defined _WIN32 && !defined WINCE
typedef unsigned ddsi_iov_len_t;
typedef struct ddsi_iovec {
ddsi_iov_len_t iov_len;
void *iov_base;
} ddsi_iovec_t;
#define DDSI_IOVEC_MATCHES_WSABUF do { \
struct ddsi_iovec_matches_WSABUF { \
char sizeof_matches[sizeof(struct ddsi_iovec) == sizeof(WSABUF) ? 1 : -1]; \
char base_off_matches[offsetof(struct ddsi_iovec, iov_base) == offsetof(WSABUF, buf) ? 1 : -1]; \
char base_size_matches[sizeof(((struct ddsi_iovec *)8)->iov_base) == sizeof(((WSABUF *)8)->buf) ? 1 : -1]; \
char len_off_matches[offsetof(struct ddsi_iovec, iov_len) == offsetof(WSABUF, len) ? 1 : -1]; \
char len_size_matches[sizeof(((struct ddsi_iovec *)8)->iov_len) == sizeof(((WSABUF *)8)->len) ? 1 : -1]; \
}; } while (0)
#else
typedef size_t ddsi_iov_len_t;
typedef struct ddsi_iovec {
void *iov_base;
ddsi_iov_len_t iov_len;
} ddsi_iovec_t;
#endif
#if ! SYSDEPS_HAVE_MSGHDR
#if defined _WIN32
typedef DWORD ddsi_msg_iovlen_t;
#else
typedef int ddsi_msg_iovlen_t;
#endif
struct msghdr
{
void *msg_name;
socklen_t msg_namelen;
ddsi_iovec_t *msg_iov;
ddsi_msg_iovlen_t msg_iovlen;
void *msg_control;
size_t msg_controllen;
int msg_flags;
};
#elif defined __linux
typedef size_t ddsi_msg_iovlen_t;
#else /* POSIX says int (which macOS, FreeBSD, Solaris do) */
typedef int ddsi_msg_iovlen_t;
#endif
#ifndef MSG_TRUNC
#define MSG_TRUNC 1
#endif
#if ! SYSDEPS_HAVE_RECVMSG
/* Only implements iovec of length 1, no control */
ssize_t recvmsg (os_handle fd, struct msghdr *message, int flags);
#endif
#if ! SYSDEPS_HAVE_SENDMSG
ssize_t sendmsg (os_handle fd, const struct msghdr *message, int flags);
#endif
#if ! SYSDEPS_HAVE_RANDOM
long random (void);
#endif
int64_t get_thread_cputime (void);
int os_threadEqual (os_threadId a, os_threadId b);
void log_stacktrace (const char *name, os_threadId tid);
#if (_LP64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || (!_LP64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
#define HAVE_ATOMIC_LIFO 1
#if _LP64
typedef union { __int128 x; struct { uintptr_t a, b; } s; } os_atomic_uintptr2_t;
#else
typedef union { uint64_t x; struct { uintptr_t a, b; } s; } os_atomic_uintptr2_t;
#endif
typedef struct os_atomic_lifo {
os_atomic_uintptr2_t aba_head;
} os_atomic_lifo_t;
void os_atomic_lifo_init (os_atomic_lifo_t *head);
void os_atomic_lifo_push (os_atomic_lifo_t *head, void *elem, size_t linkoff);
void os_atomic_lifo_pushmany (os_atomic_lifo_t *head, void *first, void *last, size_t linkoff);
void *os_atomic_lifo_pop (os_atomic_lifo_t *head, size_t linkoff);
#endif
#if defined (__cplusplus)
}
#endif

View file

@ -67,7 +67,7 @@ void ddsi_iid_init (void)
os_mutexInit (&gv.dds_iid.lock);
#endif
gv.dds_iid.key[0] = (uint32_t) os_procIdSelf();
gv.dds_iid.key[0] = (uint32_t) os_getpid();
gv.dds_iid.key[1] = (uint32_t) tnow.v;
gv.dds_iid.key[2] = (uint32_t) (tnow.v >> 32);
gv.dds_iid.key[3] = 0xdeadbeef;

View file

@ -74,15 +74,39 @@ enum ddsi_nearby_address_result ddsi_ipaddr_is_nearby_address (ddsi_tran_factory
enum ddsi_locator_from_string_result ddsi_ipaddr_from_string (ddsi_tran_factory_t tran, nn_locator_t *loc, const char *str, int32_t kind)
{
int af = AF_INET;
os_sockaddr_storage tmpaddr;
int ipv4 = (kind == NN_LOCATOR_KIND_UDPv4 || kind == NN_LOCATOR_KIND_TCPv4);
assert (kind == NN_LOCATOR_KIND_UDPv4 || kind == NN_LOCATOR_KIND_TCPv4 ||
kind == NN_LOCATOR_KIND_TCPv6 || kind == NN_LOCATOR_KIND_UDPv6);
(void)tran;
if (!os_sockaddrStringToAddress (str, (os_sockaddr *) &tmpaddr, ipv4))
return AFSR_INVALID;
if ((ipv4 && tmpaddr.ss_family != AF_INET) || (!ipv4 && tmpaddr.ss_family != AF_INET6))
switch (kind) {
case NN_LOCATOR_KIND_UDPv4:
case NN_LOCATOR_KIND_TCPv4:
break;
#if OS_SOCKET_HAS_IPV6
case NN_LOCATOR_KIND_UDPv6:
case NN_LOCATOR_KIND_TCPv6:
af = AF_INET6;
break;
#endif /* OS_SOCKET_HAS_IPV6 */
default:
return AFSR_MISMATCH;
}
(void)tran;
if (os_sockaddrfromstr(af, str, (os_sockaddr *) &tmpaddr) != 0) {
#if OS_SOCKET_HAS_DNS
/* Not a valid IP address. User may have specified a hostname instead. */
os_hostent_t *hent = NULL;
if (os_gethostbyname(str, af, &hent) != 0) {
return AFSR_UNKNOWN;
}
memcpy(&tmpaddr, &hent->addrs[0], sizeof(hent->addrs[0]));
#else
return AFSR_INVALID;
#endif /* OS_SOCKET_HAS_DNS */
}
if (tmpaddr.ss_family != af) {
return AFSR_MISMATCH;
}
ddsi_ipaddr_to_loc (loc, (os_sockaddr *)&tmpaddr, kind);
/* This is just an address, so there is no valid value for port, other than INVALID.
Without a guarantee that tmpaddr has port 0, best is to set it explicitly here */
@ -100,7 +124,7 @@ char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_
switch (src.ss_family)
{
case AF_INET:
os_sockaddrAddressToString ((const os_sockaddr *) &src, dst, sizeof_dst);
os_sockaddrtostr ((const os_sockaddr *) &src, dst, sizeof_dst);
if (with_port) {
pos = strlen (dst);
assert(pos <= sizeof_dst);
@ -110,7 +134,7 @@ char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_
#if OS_SOCKET_HAS_IPV6
case AF_INET6:
dst[0] = '[';
os_sockaddrAddressToString ((const os_sockaddr *) &src, dst + 1, sizeof_dst);
os_sockaddrtostr ((const os_sockaddr *) &src, dst + 1, sizeof_dst);
pos = strlen (dst);
if (with_port) {
assert(pos <= sizeof_dst);

View file

@ -128,16 +128,15 @@ static int unreg_group_membership (struct nn_group_membership *mship, ddsi_tran_
static char *make_joinleave_msg (char *buf, size_t bufsz, ddsi_tran_conn_t conn, int join, const nn_locator_t *srcloc, const nn_locator_t *mcloc, const struct nn_interface *interf, int err)
{
char mcstr[DDSI_LOCSTRLEN], srcstr[DDSI_LOCSTRLEN], interfstr[DDSI_LOCSTRLEN];
char mcstr[DDSI_LOCSTRLEN], interfstr[DDSI_LOCSTRLEN];
char srcstr[DDSI_LOCSTRLEN] = { '*', '\0' };
int n;
#ifdef DDSI_INCLUDE_SSM
if (srcloc)
if (srcloc) {
ddsi_locator_to_string_no_port(srcstr, sizeof(srcstr), srcloc);
else
strcpy (srcstr, "*");
}
#else
OS_UNUSED_ARG (srcloc);
strcpy (srcstr, "*");
#endif
ddsi_locator_to_string_no_port (mcstr, sizeof(mcstr), mcloc);
if (interf)

View file

@ -118,7 +118,7 @@ static ssize_t ddsi_raweth_conn_read (ddsi_tran_conn_t conn, unsigned char * buf
return ret;
}
static ssize_t ddsi_raweth_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsi_iovec_t *iov, uint32_t flags)
static ssize_t ddsi_raweth_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const os_iovec_t *iov, uint32_t flags)
{
ddsi_raweth_conn_t uc = (ddsi_raweth_conn_t) conn;
int err;
@ -138,7 +138,7 @@ static ssize_t ddsi_raweth_conn_write (ddsi_tran_conn_t conn, const nn_locator_t
msg.msg_name = &dstaddr;
msg.msg_namelen = sizeof(dstaddr);
msg.msg_flags = (int) flags;
msg.msg_iov = (ddsi_iovec_t *) iov;
msg.msg_iov = (os_iovec_t *) iov;
msg.msg_iovlen = niov;
#ifdef MSG_NOSIGNAL
sendflags |= MSG_NOSIGNAL;
@ -168,7 +168,7 @@ static ssize_t ddsi_raweth_conn_write (ddsi_tran_conn_t conn, const nn_locator_t
return ret;
}
static os_handle ddsi_raweth_conn_handle (ddsi_tran_base_t base)
static os_socket ddsi_raweth_conn_handle (ddsi_tran_base_t base)
{
return ((ddsi_raweth_conn_t) base)->m_sock;
}
@ -182,7 +182,7 @@ static int ddsi_raweth_conn_locator (ddsi_tran_base_t base, nn_locator_t *loc)
{
ddsi_raweth_conn_t uc = (ddsi_raweth_conn_t) base;
int ret = -1;
if (uc->m_sock != Q_INVALID_SOCKET)
if (uc->m_sock != OS_INVALID_SOCKET)
{
loc->kind = NN_LOCATOR_KIND_RAWETH;
loc->port = uc->m_base.m_base.m_port;

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"
@ -42,8 +41,8 @@ extern inline struct ddsi_serdata *ddsi_serdata_from_keyhash (const struct ddsi_
extern inline struct ddsi_serdata *ddsi_serdata_from_sample (const struct ddsi_sertopic *topic, enum ddsi_serdata_kind kind, const void *sample);
extern inline struct ddsi_serdata *ddsi_serdata_to_topicless (const struct ddsi_serdata *d);
extern inline void ddsi_serdata_to_ser (const struct ddsi_serdata *d, size_t off, size_t sz, void *buf);
extern inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, ddsi_iovec_t *ref);
extern inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const ddsi_iovec_t *ref);
extern inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, os_iovec_t *ref);
extern inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const os_iovec_t *ref);
extern inline bool ddsi_serdata_to_sample (const struct ddsi_serdata *d, void *sample, void **bufptr, void *buflim);
extern inline bool ddsi_serdata_topicless_to_sample (const struct ddsi_sertopic *topic, const struct ddsi_serdata *d, void *sample, void **bufptr, void *buflim);
extern inline bool ddsi_serdata_eqkey (const struct ddsi_serdata *a, const struct ddsi_serdata *b);

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"
@ -260,13 +259,13 @@ static void serdata_builtin_to_ser (const struct ddsi_serdata *serdata_common, s
(void)serdata_common; (void)off; (void)sz; (void)buf;
}
static struct ddsi_serdata *serdata_builtin_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, ddsi_iovec_t *ref)
static struct ddsi_serdata *serdata_builtin_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, os_iovec_t *ref)
{
(void)serdata_common; (void)off; (void)sz; (void)ref;
return NULL;
}
static void serdata_builtin_to_ser_unref (struct ddsi_serdata *serdata_common, const ddsi_iovec_t *ref)
static void serdata_builtin_to_ser_unref (struct ddsi_serdata *serdata_common, const os_iovec_t *ref)
{
(void)serdata_common; (void)ref;
}

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"
@ -479,17 +478,17 @@ static void serdata_default_to_ser (const struct ddsi_serdata *serdata_common, s
memcpy (buf, (char *)&d->hdr + off, sz);
}
static struct ddsi_serdata *serdata_default_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, ddsi_iovec_t *ref)
static struct ddsi_serdata *serdata_default_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, os_iovec_t *ref)
{
const struct ddsi_serdata_default *d = (const struct ddsi_serdata_default *)serdata_common;
assert (off < d->pos + sizeof(struct CDRHeader));
assert (sz <= alignup_size (d->pos + sizeof(struct CDRHeader), 4) - off);
ref->iov_base = (char *)&d->hdr + off;
ref->iov_len = (ddsi_iov_len_t)sz;
ref->iov_len = (os_iov_len_t)sz;
return ddsi_serdata_ref(serdata_common);
}
static void serdata_default_to_ser_unref (struct ddsi_serdata *serdata_common, const ddsi_iovec_t *ref)
static void serdata_default_to_ser_unref (struct ddsi_serdata *serdata_common, const os_iovec_t *ref)
{
(void)ref;
ddsi_serdata_unref(serdata_common);

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"

View file

@ -15,7 +15,6 @@
#include <string.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_md5.h"
#include "ddsi/q_bswap.h"
#include "ddsi/q_config.h"

View file

@ -361,7 +361,7 @@ static SSL * ddsi_ssl_accept (BIO * bio, os_socket * sock)
if (err <= 0)
{
SSL_free (ssl);
*sock = Q_INVALID_SOCKET;
*sock = OS_INVALID_SOCKET;
ssl = NULL;
}
}

View file

@ -159,12 +159,12 @@ static unsigned short get_socket_port (os_socket socket)
static void ddsi_tcp_conn_set_socket (ddsi_tcp_conn_t conn, os_socket sock)
{
conn->m_sock = sock;
conn->m_base.m_base.m_port = (sock == Q_INVALID_SOCKET) ? INVALID_PORT : get_socket_port (sock);
conn->m_base.m_base.m_port = (sock == OS_INVALID_SOCKET) ? INVALID_PORT : get_socket_port (sock);
}
static void ddsi_tcp_sock_free (os_socket sock, const char * msg)
{
if (sock != Q_INVALID_SOCKET)
if (sock != OS_INVALID_SOCKET)
{
if (msg)
{
@ -178,7 +178,7 @@ static void ddsi_tcp_sock_new (os_socket * sock, unsigned short port)
{
if (make_socket (sock, port, true, true) != 0)
{
*sock = Q_INVALID_SOCKET;
*sock = OS_INVALID_SOCKET;
}
}
@ -196,7 +196,7 @@ static void ddsi_tcp_conn_connect (ddsi_tcp_conn_t conn, const struct msghdr * m
os_socket sock;
ddsi_tcp_sock_new (&sock, 0);
if (sock != Q_INVALID_SOCKET)
if (sock != OS_INVALID_SOCKET)
{
/* Attempt to connect, expected that may fail */
@ -219,7 +219,7 @@ static void ddsi_tcp_conn_connect (ddsi_tcp_conn_t conn, const struct msghdr * m
conn->m_ssl = (ddsi_tcp_ssl_plugin.connect) (sock);
if (conn->m_ssl == NULL)
{
ddsi_tcp_conn_set_socket (conn, Q_INVALID_SOCKET);
ddsi_tcp_conn_set_socket (conn, OS_INVALID_SOCKET);
return;
}
}
@ -329,7 +329,7 @@ static ddsi_tcp_conn_t ddsi_tcp_cache_find (const struct msghdr * msg)
}
if (ret == NULL)
{
ret = ddsi_tcp_new_conn (Q_INVALID_SOCKET, false, (os_sockaddr *)&key.m_peer_addr);
ret = ddsi_tcp_new_conn (OS_INVALID_SOCKET, false, (os_sockaddr *)&key.m_peer_addr);
ddsi_tcp_cache_add (ret, &path);
}
os_mutexUnlock (&ddsi_tcp_cache_lock_g);
@ -521,7 +521,7 @@ static ssize_t ddsi_tcp_block_write
return (pos == sz) ? (ssize_t) pos : -1;
}
static size_t iovlen_sum (size_t niov, const ddsi_iovec_t *iov)
static size_t iovlen_sum (size_t niov, const os_iovec_t *iov)
{
size_t tot = 0;
while (niov--) {
@ -530,13 +530,13 @@ static size_t iovlen_sum (size_t niov, const ddsi_iovec_t *iov)
return tot;
}
static void set_msghdr_iov (struct msghdr *mhdr, ddsi_iovec_t *iov, size_t iovlen)
static void set_msghdr_iov (struct msghdr *mhdr, os_iovec_t *iov, size_t iovlen)
{
mhdr->msg_iov = iov;
mhdr->msg_iovlen = (ddsi_msg_iovlen_t)iovlen;
mhdr->msg_iovlen = (os_msg_iovlen_t)iovlen;
}
static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *dst, size_t niov, const ddsi_iovec_t *iov, uint32_t flags)
static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *dst, size_t niov, const os_iovec_t *iov, uint32_t flags)
{
#ifdef DDSI_INCLUDE_SSL
char msgbuf[4096]; /* stack buffer for merging smallish writes without requiring allocations */
@ -552,7 +552,7 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d
assert(niov <= INT_MAX);
ddsi_ipaddr_from_loc(&dstaddr, dst);
memset(&msg, 0, sizeof(msg));
set_msghdr_iov (&msg, (ddsi_iovec_t *) iov, niov);
set_msghdr_iov (&msg, (os_iovec_t *) iov, niov);
msg.msg_name = &dstaddr;
msg.msg_namelen = (socklen_t) os_sockaddr_get_size((os_sockaddr *) &dstaddr);
#if SYSDEPS_MSGHDR_FLAGS
@ -571,10 +571,10 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d
/* If not connected attempt to conect */
if ((conn->m_sock == Q_INVALID_SOCKET) && ! conn->m_base.m_server)
if ((conn->m_sock == OS_INVALID_SOCKET) && ! conn->m_base.m_server)
{
ddsi_tcp_conn_connect (conn, &msg);
if (conn->m_sock == Q_INVALID_SOCKET)
if (conn->m_sock == OS_INVALID_SOCKET)
{
os_mutexUnlock (&conn->m_mutex);
return -1;
@ -644,7 +644,7 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d
piecewise = 0;
if (err != os_sockECONNRESET)
{
if (! conn->m_base.m_closed && (conn->m_sock != Q_INVALID_SOCKET))
if (! conn->m_base.m_closed && (conn->m_sock != OS_INVALID_SOCKET))
{
DDS_WARNING
(
@ -711,7 +711,7 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d
return ((size_t) ret == len) ? ret : -1;
}
static os_handle ddsi_tcp_conn_handle (ddsi_tran_base_t base)
static os_socket ddsi_tcp_conn_handle (ddsi_tran_base_t base)
{
return ((ddsi_tcp_conn_t) base)->m_sock;
}
@ -756,7 +756,7 @@ static ddsi_tran_conn_t ddsi_tcp_accept (ddsi_tran_listener_t listener)
{
ddsi_tcp_listener_t tl = (ddsi_tcp_listener_t) listener;
ddsi_tcp_conn_t tcp = NULL;
os_socket sock = Q_INVALID_SOCKET;
os_socket sock = OS_INVALID_SOCKET;
os_sockaddr_storage addr;
socklen_t addrlen = sizeof (addr);
char buff[DDSI_LOCSTRLEN];
@ -783,11 +783,11 @@ static ddsi_tran_conn_t ddsi_tcp_accept (ddsi_tran_listener_t listener)
ddsi_tcp_sock_free (sock, NULL);
return NULL;
}
err = (sock == Q_INVALID_SOCKET) ? os_getErrno () : 0;
err = (sock == OS_INVALID_SOCKET) ? os_getErrno () : 0;
}
while ((err == os_sockEINTR) || (err == os_sockEAGAIN) || (err == os_sockEWOULDBLOCK));
if (sock == Q_INVALID_SOCKET)
if (sock == OS_INVALID_SOCKET)
{
getsockname (tl->m_sock, (struct sockaddr *) &addr, &addrlen);
sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&addr);
@ -821,7 +821,7 @@ static ddsi_tran_conn_t ddsi_tcp_accept (ddsi_tran_listener_t listener)
return tcp ? &tcp->m_base : NULL;
}
static os_handle ddsi_tcp_listener_handle (ddsi_tran_base_t base)
static os_socket ddsi_tcp_listener_handle (ddsi_tran_base_t base)
{
return ((ddsi_tcp_listener_t) base)->m_sock;
}
@ -836,7 +836,7 @@ static void ddsi_tcp_conn_peer_locator (ddsi_tran_conn_t conn, nn_locator_t * lo
{
char buff[DDSI_LOCSTRLEN];
ddsi_tcp_conn_t tc = (ddsi_tcp_conn_t) conn;
assert (tc->m_sock != Q_INVALID_SOCKET);
assert (tc->m_sock != OS_INVALID_SOCKET);
ddsi_ipaddr_to_loc (loc, (os_sockaddr *)&tc->m_peer_addr, tc->m_peer_addr.ss_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6);
ddsi_locator_to_string(buff, sizeof(buff), loc);
DDS_LOG(DDS_LC_TCP, "(%s EP:%s)", ddsi_name, buff);
@ -861,7 +861,7 @@ static ddsi_tcp_conn_t ddsi_tcp_new_conn (os_socket sock, bool server, os_sockad
memset (conn, 0, sizeof (*conn));
ddsi_tcp_base_init (&conn->m_base);
os_mutexInit (&conn->m_mutex);
conn->m_sock = Q_INVALID_SOCKET;
conn->m_sock = OS_INVALID_SOCKET;
(void)memcpy(&conn->m_peer_addr, peer, os_sockaddr_get_size(peer));
conn->m_peer_port = os_sockaddr_get_port (peer);
conn->m_base.m_server = server;
@ -883,7 +883,7 @@ static ddsi_tran_listener_t ddsi_tcp_create_listener (int port, ddsi_tran_qos_t
ddsi_tcp_sock_new (&sock, (unsigned short) port);
if (sock != Q_INVALID_SOCKET)
if (sock != OS_INVALID_SOCKET)
{
tl = (ddsi_tcp_listener_t) os_malloc (sizeof (*tl));
memset (tl, 0, sizeof (*tl));
@ -974,7 +974,7 @@ static void ddsi_tcp_unblock_listener (ddsi_tran_listener_t listener)
/* Connect to own listener socket to wake listener from blocking 'accept()' */
ddsi_tcp_sock_new (&sock, 0);
if (sock != Q_INVALID_SOCKET)
if (sock != OS_INVALID_SOCKET)
{
os_sockaddr_storage addr;
socklen_t addrlen = sizeof (addr);

View file

@ -16,7 +16,6 @@
#include "ddsi/q_gc.h"
#include "ddsi/q_globals.h"
#include "ddsi/q_config.h"
#include "ddsi/sysdeps.h"
#include "ddsi/ddsi_iid.h"
#include "ddsi/ddsi_tkmap.h"
#include "util/ut_hopscotch.h"

View file

@ -97,7 +97,7 @@ void ddsi_conn_free (ddsi_tran_conn_t conn)
{
conn->m_closed = true;
/* FIXME: rethink the socket waitset & the deleting of entries; the biggest issue is TCP handling that can open & close sockets at will and yet expects the waitset to wake up at the apprioriate times. (This pretty much works with the select-based version, but not the kqueue-based one.) TCP code can also have connections without a socket ... Calling sockWaitsetRemove here (where there shouldn't be any knowledge of it) at least ensures that it is removed in time and that there can't be aliasing of connections and sockets. */
if (ddsi_conn_handle (conn) != Q_INVALID_SOCKET)
if (ddsi_conn_handle (conn) != OS_INVALID_SOCKET)
{
unsigned i;
for (i = 0; i < gv.n_recv_threads; i++)
@ -149,7 +149,7 @@ ssize_t ddsi_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len,
return (conn->m_closed) ? -1 : (conn->m_read_fn) (conn, buf, len, srcloc);
}
ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsi_iovec_t *iov, uint32_t flags)
ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const os_iovec_t *iov, uint32_t flags)
{
ssize_t ret = -1;
if (! conn->m_closed)
@ -202,7 +202,7 @@ int ddsi_conn_leave_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const
return conn->m_factory->m_leave_mc_fn (conn, srcloc, mcloc, interf);
}
os_handle ddsi_tran_handle (ddsi_tran_base_t base)
os_socket ddsi_tran_handle (ddsi_tran_base_t base)
{
return (base->m_handle_fn) (base);
}

View file

@ -54,23 +54,18 @@ static ssize_t ddsi_udp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s
ssize_t ret;
struct msghdr msghdr;
os_sockaddr_storage src;
ddsi_iovec_t msg_iov;
os_iovec_t msg_iov;
socklen_t srclen = (socklen_t) sizeof (src);
msg_iov.iov_base = (void*) buf;
msg_iov.iov_len = (ddsi_iov_len_t)len; /* windows uses unsigned, POISX size_t */
msg_iov.iov_len = (os_iov_len_t)len; /* Windows uses unsigned, POSIX (except Linux) int */
msghdr.msg_name = &src;
msghdr.msg_namelen = srclen;
msghdr.msg_iov = &msg_iov;
msghdr.msg_iovlen = 1;
#if !defined(__sun) || defined(_XPG4_2)
msghdr.msg_control = NULL;
msghdr.msg_controllen = 0;
#else
msghdr.msg_accrights = NULL;
msghdr.msg_accrightslen = 0;
#endif
do {
ret = recvmsg(((ddsi_udp_conn_t) conn)->m_sock, &msghdr, 0);
@ -103,13 +98,13 @@ static ssize_t ddsi_udp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s
return ret;
}
static void set_msghdr_iov (struct msghdr *mhdr, ddsi_iovec_t *iov, size_t iovlen)
static void set_msghdr_iov (struct msghdr *mhdr, os_iovec_t *iov, size_t iovlen)
{
mhdr->msg_iov = iov;
mhdr->msg_iovlen = (ddsi_msg_iovlen_t)iovlen;
mhdr->msg_iovlen = (os_msg_iovlen_t)iovlen;
}
static ssize_t ddsi_udp_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsi_iovec_t *iov, uint32_t flags)
static ssize_t ddsi_udp_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const os_iovec_t *iov, uint32_t flags)
{
int err;
ssize_t ret;
@ -119,18 +114,15 @@ static ssize_t ddsi_udp_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *d
os_sockaddr_storage dstaddr;
assert(niov <= INT_MAX);
ddsi_ipaddr_from_loc(&dstaddr, dst);
set_msghdr_iov (&msg, (ddsi_iovec_t *) iov, niov);
set_msghdr_iov (&msg, (os_iovec_t *) iov, niov);
msg.msg_name = &dstaddr;
msg.msg_namelen = (socklen_t) os_sockaddr_get_size((os_sockaddr *) &dstaddr);
#if !defined(__sun) || defined(_XPG4_2)
msg.msg_control = NULL;
msg.msg_controllen = 0;
#else
msg.msg_accrights = NULL;
msg.msg_accrightslen = 0;
#endif
#if SYSDEPS_MSGHDR_FLAGS
msg.msg_flags = (int) flags;
#else
OS_UNUSED_ARG(flags);
#endif
#ifdef MSG_NOSIGNAL
sendflags |= MSG_NOSIGNAL;
@ -187,7 +179,7 @@ static void ddsi_udp_disable_multiplexing (ddsi_tran_conn_t base)
#endif
}
static os_handle ddsi_udp_conn_handle (ddsi_tran_base_t base)
static os_socket ddsi_udp_conn_handle (ddsi_tran_base_t base)
{
return ((ddsi_udp_conn_t) base)->m_sock;
}
@ -203,7 +195,7 @@ static int ddsi_udp_conn_locator (ddsi_tran_base_t base, nn_locator_t *loc)
{
int ret = -1;
ddsi_udp_conn_t uc = (ddsi_udp_conn_t) base;
if (uc->m_sock != Q_INVALID_SOCKET)
if (uc->m_sock != OS_INVALID_SOCKET)
{
loc->kind = ddsi_udp_factory_g.m_kind;
loc->port = uc->m_base.m_base.m_port;
@ -484,7 +476,7 @@ static char *ddsi_udp_locator_to_string (ddsi_tran_factory_t tran, char *dst, si
memset (&src, 0, sizeof (src));
src.sin_family = AF_INET;
memcpy (&src.sin_addr.s_addr, &mcgen.ipv4, 4);
os_sockaddrAddressToString ((const os_sockaddr *) &src, dst, sizeof_dst);
os_sockaddrtostr ((const os_sockaddr *) &src, dst, sizeof_dst);
pos = strlen (dst);
assert (pos <= sizeof_dst);
cnt = snprintf (dst + pos, sizeof_dst - pos, ";%u;%u;%u", mcgen.base, mcgen.count, mcgen.idx);

View file

@ -125,6 +125,7 @@ static int add_addresses_to_addrset_1 (struct addrset *as, const char *ip, int p
return 0;
}
OS_WARNING_MSVC_OFF(4996);
int add_addresses_to_addrset (struct addrset *as, const char *addrs, int port_mode, const char *msgtag, int req_mc)
{
/* port_mode: -1 => take from string, if 0 & unicast, add for a range of participant indices;
@ -177,6 +178,7 @@ int add_addresses_to_addrset (struct addrset *as, const char *addrs, int port_mo
os_free (addrs_copy);
return retval;
}
OS_WARNING_MSVC_ON(4996);
int compare_locators (const nn_locator_t *a, const nn_locator_t *b)
{

View file

@ -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);

View file

@ -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);

View file

@ -27,7 +27,6 @@
#include "ddsi/q_addrset.h"
#include "ddsi/q_nwif.h"
#include "ddsi/q_error.h"
#include "ddsi/sysdeps.h"
#include "util/ut_xmlparser.h"
#include "util/ut_expand_envvars.h"
@ -1473,6 +1472,7 @@ static int uf_string(struct cfgst *cfgst, void *parent, struct cfgelem const * c
return 1;
}
OS_WARNING_MSVC_OFF(4996);
static int uf_natint64_unit(struct cfgst *cfgst, int64_t *elem, const char *value, const struct unit *unittab, int64_t def_mult, int64_t max)
{
int pos;
@ -1502,6 +1502,7 @@ static int uf_natint64_unit(struct cfgst *cfgst, int64_t *elem, const char *valu
return cfg_error(cfgst, "%s: invalid value", value);
}
}
OS_WARNING_MSVC_ON(4996);
#ifdef DDSI_INCLUDE_BANDWIDTH_LIMITING
static int uf_bandwidth(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value)
@ -1761,6 +1762,7 @@ static void pf_sched_class(struct cfgst *cfgst, void *parent, struct cfgelem con
cfg_log(cfgst, "%s%s", str, is_default ? " [def]" : "");
}
OS_WARNING_MSVC_OFF(4996);
static int uf_maybe_int32(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value)
{
struct config_maybe_int32 *elem = cfg_address(cfgst, parent, cfgelem);
@ -1776,6 +1778,7 @@ static int uf_maybe_int32(struct cfgst *cfgst, void *parent, struct cfgelem cons
return cfg_error(cfgst, "'%s': neither 'default' nor a decimal integer\n", value);
}
}
OS_WARNING_MSVC_ON(4996);
static int uf_maybe_memsize(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value)
{
@ -1902,6 +1905,7 @@ static int uf_int_min_max(struct cfgst *cfgst, void *parent, struct cfgelem cons
return 1;
}
OS_WARNING_MSVC_OFF(4996);
static int uf_domainId(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value)
{
struct config_maybe_int32 *elem = cfg_address(cfgst, parent, cfgelem);
@ -1917,6 +1921,7 @@ static int uf_domainId(struct cfgst *cfgst, void *parent, struct cfgelem const *
return cfg_error(cfgst, "'%s': neither 'any' nor a decimal integer in 0 .. 230\n", value);
}
}
OS_WARNING_MSVC_ON(4996);
static int uf_participantIndex(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int first, const char *value)
{
@ -2745,6 +2750,7 @@ struct cfgst * config_init
struct ut_xmlpState *qx;
FILE *fp;
OS_WARNING_MSVC_OFF(4996);
if ( (fp = fopen(tok, "r")) == NULL ) {
if ( strncmp(tok, "file://", 7) != 0 || (fp = fopen(tok + 7, "r")) == NULL ) {
DDS_ERROR("can't open configuration file %s\n", tok);
@ -2753,6 +2759,7 @@ struct cfgst * config_init
return NULL;
}
}
OS_WARNING_MSVC_ON(4996);
cb.attr = proc_attr;
cb.elem_close = proc_elem_close;

View file

@ -41,8 +41,6 @@
#include "ddsi/q_md5.h"
#include "ddsi/q_feature_check.h"
#include "ddsi/sysdeps.h"
static const nn_vendorid_t ownvendorid = MY_VENDOR_ID;
static int get_locator (nn_locator_t *loc, const nn_locators_t *locs, int uc_same_subnet)
@ -305,9 +303,9 @@ int spdp_write (struct participant *pp)
os_gethostname(node, sizeof(node)-1);
node[sizeof(node)-1] = '\0';
size = strlen(node) + strlen(OSPL_VERSION_STR) + strlen(OSPL_HOST_STR) + strlen(OSPL_TARGET_STR) + 4; /* + ///'\0' */
size = strlen(node) + strlen(OS_VERSION) + strlen(OS_HOST_NAME) + strlen(OS_TARGET_NAME) + 4; /* + ///'\0' */
ps.prismtech_participant_version_info.internals = os_malloc(size);
(void) snprintf(ps.prismtech_participant_version_info.internals, size, "%s/%s/%s/%s", node, OSPL_VERSION_STR, OSPL_HOST_STR, OSPL_TARGET_STR);
(void) snprintf(ps.prismtech_participant_version_info.internals, size, "%s/%s/%s/%s", node, OS_VERSION, OS_HOST_NAME, OS_TARGET_NAME);
DDS_TRACE("spdp_write(%x:%x:%x:%x) - internals: %s\n", PGUID (pp->e.guid), ps.prismtech_participant_version_info.internals);
}

View file

@ -36,7 +36,6 @@
#include "ddsi/ddsi_tran.h"
#include "ddsi/ddsi_tcp.h"
#include "ddsi/sysdeps.h"
#include "dds__whc.h"
struct plugin {
@ -63,7 +62,7 @@ static int cpf (ddsi_tran_conn_t conn, const char *fmt, ...)
else
{
va_list ap;
ddsi_iovec_t iov;
os_iovec_t iov;
char buf[4096];
int n;
va_start (ap, fmt);

View file

@ -13,7 +13,6 @@
#include <assert.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "util/ut_hopscotch.h"
#include "ddsi/q_ephash.h"

View file

@ -12,7 +12,6 @@
#include <stddef.h>
#include "os/os.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_freelist.h"
#if FREELIST_TYPE == FREELIST_ATOMIC_LIFO

View file

@ -48,8 +48,6 @@
#include "ddsi/q_debmon.h"
#include "ddsi/q_init.h"
#include "ddsi/sysdeps.h"
#include "ddsi/ddsi_tran.h"
#include "ddsi/ddsi_udp.h"
#include "ddsi/ddsi_tcp.h"
@ -426,6 +424,7 @@ static int check_thread_properties (void)
return ok;
}
OS_WARNING_MSVC_OFF(4996);
int rtps_config_open (void)
{
int status;
@ -462,6 +461,7 @@ int rtps_config_open (void)
return status;
}
OS_WARNING_MSVC_ON(4996);
int rtps_config_prep (struct cfgst *cfgst)
{
@ -533,18 +533,6 @@ int rtps_config_prep (struct cfgst *cfgst)
goto err_config_late_error;
}
#if ! OS_SOCKET_HAS_IPV6
/* If the platform doesn't support IPv6, guarantee useIpv6 is
false. There are two ways of going about it, one is to do it
silently, the other to let the user fix his config. Clearly, we
have chosen the latter. */
if (config.useIpv6)
{
DDS_ERROR("IPv6 addressing requested but not supported on this platform\n");
goto err_config_late_error;
}
#endif
#ifdef DDSI_INCLUDE_NETWORK_CHANNELS
{
/* Determine number of configured channels to be able to
@ -1060,7 +1048,7 @@ int rtps_init (void)
/* Template PP guid -- protected by privileged_pp_lock for simplicity */
gv.next_ppguid.prefix.u[0] = locator_to_hopefully_unique_uint32 (&gv.ownloc);
gv.next_ppguid.prefix.u[1] = (unsigned) os_procIdSelf ();
gv.next_ppguid.prefix.u[1] = (unsigned) os_getpid ();
gv.next_ppguid.prefix.u[2] = 1;
gv.next_ppguid.entityid.u = NN_ENTITYID_PARTICIPANT;

View file

@ -38,8 +38,6 @@
#include "ddsi/q_lease.h"
#include "ddsi/q_gc.h"
#include "ddsi/sysdeps.h"
/* This is absolute bottom for signed integers, where -x = x and yet x
!= 0 -- and note that it had better be 2's complement machine! */
#define TSCHED_NOT_ON_HEAP INT64_MIN

View file

@ -17,10 +17,6 @@
#include "os/os.h"
#ifndef _WIN32
#include <netdb.h>
#endif
#include "ddsi/q_log.h"
#include "ddsi/q_nwif.h"
#include "ddsi/q_globals.h"
@ -46,12 +42,16 @@ unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src)
memcpy (&id, src->address + 12, sizeof (id));
else
{
#if OS_SOCKET_HAS_IPV6
md5_state_t st;
md5_byte_t digest[16];
md5_init (&st);
md5_append (&st, (const md5_byte_t *) ((const os_sockaddr_in6 *) src)->sin6_addr.s6_addr, 16);
md5_finish (&st, digest);
memcpy (&id, digest, sizeof (id));
#else
DDS_FATAL("IPv6 unavailable\n");
#endif
}
return id;
}
@ -377,7 +377,7 @@ int make_socket
return -2;
}
if (! Q_VALID_SOCKET (*sock))
if (! OS_VALID_SOCKET (*sock))
{
print_sockerror ("socket");
return rc;
@ -425,7 +425,7 @@ int make_socket
fail:
os_sockFree (*sock);
*sock = Q_INVALID_SOCKET;
*sock = OS_INVALID_SOCKET;
return rc;
}
@ -481,12 +481,11 @@ int find_own_ip (const char *requested_address)
char if_name[sizeof (last_if_name)];
int q = 0;
strncpy (if_name, ifa->name, sizeof (if_name) - 1);
if_name[sizeof (if_name) - 1] = 0;
os_strlcpy(if_name, ifa->name, sizeof(if_name));
if (strcmp (if_name, last_if_name))
DDS_LOG(DDS_LC_CONFIG, "%s%s", sep, if_name);
strcpy (last_if_name, if_name);
os_strlcpy(last_if_name, if_name, sizeof(last_if_name));
/* interface must be up */
if ((ifa->flags & IFF_UP) == 0) {

View file

@ -19,7 +19,6 @@
#include "ddsi/q_config.h"
#include "ddsi/q_globals.h"
#include "ddsi/q_bswap.h"
#include "ddsi/sysdeps.h"
#include "ddsi/q_pcap.h"
/* pcap format info taken from http://wiki.wireshark.org/Development/LibpcapFileFormat */
@ -79,6 +78,7 @@ static const ipv4_hdr_t ipv4_hdr_template = {
#define IPV4_HDR_SIZE 20
#define UDP_HDR_SIZE 8
OS_WARNING_MSVC_OFF(4996);
FILE *new_pcap_file (const char *name)
{
FILE *fp;
@ -101,6 +101,7 @@ FILE *new_pcap_file (const char *name)
return fp;
}
OS_WARNING_MSVC_ON(4996);
static void write_data (FILE *fp, const struct msghdr *msghdr, size_t sz)
{

View file

@ -40,8 +40,6 @@
#include "ddsi/q_thread.h"
#include "ddsi/q_globals.h" /* for mattr, cattr */
#include "ddsi/sysdeps.h"
/* OVERVIEW ------------------------------------------------------------
The receive path of DDSI2 has any number of receive threads that
@ -2509,6 +2507,7 @@ struct nn_dqueue *nn_dqueue_new (const char *name, uint32_t max_samples, nn_dque
{
struct nn_dqueue *q;
char *thrname;
size_t thrnamesz;
if ((q = os_malloc (sizeof (*q))) == NULL)
goto fail_q;
@ -2523,9 +2522,10 @@ struct nn_dqueue *nn_dqueue_new (const char *name, uint32_t max_samples, nn_dque
os_mutexInit (&q->lock);
os_condInit (&q->cond, &q->lock);
if ((thrname = os_malloc (3 + strlen (name) + 1)) == NULL)
thrnamesz = 3 + strlen (name) + 1;
if ((thrname = os_malloc (thrnamesz)) == NULL)
goto fail_thrname;
sprintf (thrname, "dq.%s", name);
snprintf (thrname, thrnamesz, "dq.%s", name);
if ((q->ts = create_thread (thrname, (uint32_t (*) (void *)) dqueue_thread, q)) == NULL)
goto fail_thread;
os_free (thrname);

View file

@ -3051,8 +3051,8 @@ static int local_participant_cmp (const void *va, const void *vb)
{
const struct local_participant_desc *a = va;
const struct local_participant_desc *b = vb;
os_handle h1 = ddsi_conn_handle (a->m_conn);
os_handle h2 = ddsi_conn_handle (b->m_conn);
os_socket h1 = ddsi_conn_handle (a->m_conn);
os_socket h2 = ddsi_conn_handle (b->m_conn);
return (h1 == h2) ? 0 : (h1 < h2) ? -1 : 1;
}
@ -3298,7 +3298,7 @@ void trigger_recv_threads (void)
char buf[DDSI_LOCSTRLEN];
char dummy = 0;
const nn_locator_t *dst = gv.recv_threads[i].arg.u.single.loc;
ddsi_iovec_t iov;
os_iovec_t iov;
iov.iov_base = &dummy;
iov.iov_len = 1;
DDS_TRACE("trigger_recv_threads: %d single %s\n", i, ddsi_locator_to_string (buf, sizeof (buf), dst));

View file

@ -11,10 +11,6 @@
*/
#ifdef DDSI_INCLUDE_ENCRYPTION
/* Ordering of the include files is utterly irrational but works.
Don't mess with it: you'll enter Dependency Hell Territory on
WinCE. Here Be Dragons. */
#include "ddsi/q_security.h"
#include "ddsi/q_config.h"
#include "ddsi/q_log.h"
@ -36,17 +32,6 @@
#include <openssl/bn.h>
#include <openssl/bio.h>
#include "ddsi/sysdeps.h"
/* We don't get FILENAME_MAX on WinCE but can't put it in the abstraction
* without complications to the examples so here we go: */
#ifndef FILENAME_MAX
#ifdef WINCE
#define FILENAME_MAX 260
#endif
#endif
/* Supported URI schema by parser */
#define URI_FILESCHEMA "file://"
@ -1661,7 +1646,7 @@ static os_ssize_t q_security_sendmsg
(
ddsi_tran_conn_t conn,
const nn_locator_t *dst,
size_t niov, ddsi_iovec_t *iov,
size_t niov, os_iovec_t *iov,
q_securityEncoderSet *codec,
os_uint32 encoderId,
os_uint32 flags

View file

@ -60,7 +60,7 @@ struct entry {
struct os_sockWaitset
{
int kqueue;
os_handle pipe[2]; /* pipe used for triggering */
os_socket pipe[2]; /* pipe used for triggering */
os_atomic_uint32_t sz;
struct entry *entries;
struct os_sockWaitsetCtx ctx; /* set of descriptors being handled */
@ -477,7 +477,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
{
WSANETWORKEVENTS nwev;
int idx = ctx->index;
os_handle handle;
os_socket handle;
ctx->index = -1;
handle = ddsi_conn_handle (ctx->conns[idx]);
@ -511,11 +511,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
#ifndef _WIN32
#ifndef __VXWORKS__
#if defined (AIX) || defined (__Lynx__) || defined (__QNX__)
#include <fcntl.h>
#elif ! defined(INTEGRITY)
#include <sys/fcntl.h>
#endif
#endif /* __VXWORKS__ */
#ifndef _WRS_KERNEL
@ -532,7 +528,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
typedef struct os_sockWaitsetSet
{
ddsi_tran_conn_t * conns; /* connections in set */
os_handle * fds; /* file descriptors in set */
os_socket * fds; /* file descriptors in set */
unsigned sz; /* max number of fds in context */
unsigned n; /* actual number of fds in context */
} os_sockWaitsetSet;
@ -546,7 +542,7 @@ struct os_sockWaitsetCtx
struct os_sockWaitset
{
os_handle pipe[2]; /* pipe used for triggering */
os_socket pipe[2]; /* pipe used for triggering */
os_mutex mutex; /* concurrency guard */
int fdmax_plus_1; /* value for first parameter of select() */
os_sockWaitsetSet set; /* set of descriptors handled next */
@ -554,13 +550,13 @@ struct os_sockWaitset
};
#if defined (_WIN32)
static int make_pipe (os_handle fd[2])
static int make_pipe (os_socket fd[2])
{
struct sockaddr_in addr;
socklen_t asize = sizeof (addr);
os_socket listener = socket (AF_INET, SOCK_STREAM, 0);
os_socket s1 = socket (AF_INET, SOCK_STREAM, 0);
os_socket s2 = Q_INVALID_SOCKET;
os_socket s2 = OS_INVALID_SOCKET;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
@ -759,7 +755,7 @@ void os_sockWaitsetTrigger (os_sockWaitset ws)
int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn)
{
os_handle handle = ddsi_conn_handle (conn);
os_socket handle = ddsi_conn_handle (conn);
os_sockWaitsetSet * set = &ws->set;
unsigned idx;
int ret;
@ -920,7 +916,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn)
while (ctx->index < ctx->set.n)
{
unsigned idx = ctx->index++;
os_handle fd = ctx->set.fds[idx];
os_socket fd = ctx->set.fds[idx];
assert(idx > 0);
if (FD_ISSET (fd, &ctx->rdset))
{

View file

@ -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);

View file

@ -42,8 +42,6 @@
#include "ddsi/q_freelist.h"
#include "ddsi/ddsi_serdata_default.h"
#include "ddsi/sysdeps.h"
#define NN_XMSG_MAX_ALIGN 8
#define NN_XMSG_CHUNK_SIZE 128
@ -73,7 +71,7 @@ struct nn_xmsg {
size_t sz;
int have_params;
struct ddsi_serdata *refd_payload;
ddsi_iovec_t refd_payload_iov;
os_iovec_t refd_payload_iov;
int64_t maxdelay;
#ifdef DDSI_INCLUDE_NETWORK_PARTITIONS
uint32_t encoderid;
@ -198,7 +196,7 @@ struct nn_xpack
ddsi_tran_conn_t conn;
os_sem_t sem;
size_t niov;
ddsi_iovec_t iov[NN_XMSG_MAX_MESSAGE_IOVECS];
os_iovec_t iov[NN_XMSG_MAX_MESSAGE_IOVECS];
enum nn_xmsg_dstmode dstmode;
union
@ -1322,7 +1320,7 @@ static ssize_t nn_xpack_send1 (const nn_locator_t *loc, void * varg)
{
/* We drop APPROXIMATELY a fraction of xmit_lossiness * 10**(-3)
of all packets to be sent */
if ((random () % 1000) < config.xmit_lossiness)
if ((os_random () % 1000) < config.xmit_lossiness)
{
DDS_TRACE("(dropped)");
xp->call_flags = 0;
@ -1803,11 +1801,11 @@ int nn_xpack_addmsg (struct nn_xpack *xp, struct nn_xmsg *m, const uint32_t flag
/* Append submessage; can possibly be merged with preceding iovec */
if ((char *) xp->iov[niov-1].iov_base + xp->iov[niov-1].iov_len == (char *) m->data->payload)
xp->iov[niov-1].iov_len += (ddsi_iov_len_t)m->sz;
xp->iov[niov-1].iov_len += (os_iov_len_t)m->sz;
else
{
xp->iov[niov].iov_base = m->data->payload;
xp->iov[niov].iov_len = (ddsi_iov_len_t)m->sz;
xp->iov[niov].iov_len = (os_iov_len_t)m->sz;
niov++;
}
sz += m->sz;

View file

@ -19,227 +19,6 @@
#include "ddsi/q_config.h"
#include "ddsi/sysdeps.h"
#ifdef NEED_ARM_MEMBAR_SUPPORT
static void q_membar_autodecide (void);
void (*q_maybe_membar) (void) = q_membar_autodecide;
static void q_membar_nop (void) { }
static void q_membar_dmb (void) { MemoryBarrierARM; }
static void q_membar_autodecide (void)
{
SYSTEM_INFO sysinfo;
GetSystemInfo (&sysinfo);
assert (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM);
if (sysinfo.wProcessorLevel >= 7)
{
q_maybe_membar = q_membar_dmb;
}
else
{
q_maybe_membar = q_membar_nop;
}
q_maybe_membar ();
}
#endif
/* MISSING IN OS ABSTRACTION LAYER ------------------------------------- */
#if ! SYSDEPS_HAVE_RECVMSG
ssize_t recvmsg (os_handle fd, struct msghdr *message, int flags)
{
ssize_t ret;
assert (message->msg_iovlen == 1);
#if SYSDEPS_MSGHDR_ACCRIGHTS
assert (message->msg_accrightslen == 0);
#else
assert (message->msg_controllen == 0);
#endif
#if SYSDEPS_MSGHDR_FLAGS
message->msg_flags = 0;
#endif
ret = recvfrom (fd, message->msg_iov[0].iov_base, (int)message->msg_iov[0].iov_len, flags,
message->msg_name, &message->msg_namelen); /* To fix the warning of conversion from 'size_t' to 'int', which may cause possible loss of data, type casting is done*/
#if defined (_WIN32)
/* Windows returns an error for too-large messages, Unix expects
original size and the MSG_TRUNC flag. MSDN says it is truncated,
which presumably means it returned as much of the message as it
could - so we return that the message was 1 byte larger than the
available space, and set MSG_TRUNC if we can. */
if (ret == -1 && os_getErrno () == WSAEMSGSIZE) {
ret = message->msg_iov[0].iov_len + 1;
#if SYSDEPS_MSGHDR_FLAGS
message->msg_flags |= MSG_TRUNC;
#endif
}
#endif
return ret;
}
#endif
#if ! SYSDEPS_HAVE_SENDMSG
#if !(defined _WIN32 && !defined WINCE)
ssize_t sendmsg (os_handle fd, const struct msghdr *message, int flags)
{
char stbuf[3072], *buf;
ssize_t sz, ret;
size_t sent = 0;
unsigned i;
#if SYSDEPS_MSGHDR_ACCRIGHTS
assert (message->msg_accrightslen == 0);
#else
assert (message->msg_controllen == 0);
#endif
if (message->msg_iovlen == 1)
{
/* if only one fragment, skip all copying */
buf = message->msg_iov[0].iov_base;
sz = message->msg_iov[0].iov_len;
}
else
{
/* first determine the size of the message, then select the
on-stack buffer or allocate one on the heap ... */
sz = 0;
for (i = 0; i < message->msg_iovlen; i++)
{
sz += message->msg_iov[i].iov_len;
}
if (sz <= sizeof (stbuf))
{
buf = stbuf;
}
else
{
buf = os_malloc (sz);
}
/* ... then copy data into buffer */
sz = 0;
for (i = 0; i < message->msg_iovlen; i++)
{
memcpy (buf + sz, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len);
sz += message->msg_iov[i].iov_len;
}
}
while (TRUE)
{
ret = sendto (fd, buf + sent, sz - sent, flags, message->msg_name, message->msg_namelen);
if (ret < 0)
{
break;
}
sent += (size_t) ret;
if (sent == sz)
{
ret = sent;
break;
}
}
if (buf != stbuf)
{
os_free (buf);
}
return ret;
}
#else /* _WIN32 && !WINCE */
ssize_t sendmsg (os_handle fd, const struct msghdr *message, int flags)
{
DWORD sent;
ssize_t ret;
DDSI_IOVEC_MATCHES_WSABUF;
#if SYSDEPS_MSGHDR_ACCRIGHTS
assert (message->msg_accrightslen == 0);
#else
assert (message->msg_controllen == 0);
#endif
if (WSASendTo (fd, (WSABUF *) message->msg_iov, (DWORD)message->msg_iovlen, &sent, flags, (SOCKADDR *) message->msg_name, message->msg_namelen, NULL, NULL) == 0)
ret = (ssize_t) sent;
else
ret = -1;
return ret;
}
#endif
#endif
#ifndef SYSDEPS_HAVE_RANDOM
long random (void)
{
/* rand() is a really terribly bad PRNG */
union { long x; unsigned char c[4]; } t;
int i;
for (i = 0; i < 4; i++)
t.c[i] = (unsigned char) ((rand () >> 4) & 0xff);
#if RAND_MAX == INT32_MAX || RAND_MAX == 0x7fff
t.x &= RAND_MAX;
#elif RAND_MAX <= 0x7ffffffe
t.x %= (RAND_MAX+1);
#else
#error "RAND_MAX out of range"
#endif
return t.x;
}
#endif
#if SYSDEPS_HAVE_CLOCK_THREAD_CPUTIME
int64_t get_thread_cputime (void)
{
struct timespec ts;
clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ts);
return ts.tv_sec * (int64_t) 1000000000 + ts.tv_nsec;
}
#else
int64_t get_thread_cputime (void)
{
return 0;
}
#endif
#if ! OS_HAVE_THREADEQUAL
int os_threadEqual (os_threadId a, os_threadId b)
{
/* on pthreads boxes, pthread_equal (a, b); as a workaround: */
return os_threadIdToInteger (a) == os_threadIdToInteger (b);
}
#endif
#if defined __sun && __GNUC__ && defined __sparc__
int __S_exchange_and_add (volatile int *mem, int val)
{
/* Hopefully cache lines are <= 64 bytes, we then use 8 bytes, 64
bytes. Should be a lot better than just one lock byte if it gets
used often, but the overhead is a bit larger, so who knows what's
best without trying it out?. We want 3 bits + 6 lsbs zero, so
need to shift addr_hash by 23 bits. */
static unsigned char locks[8 * 64];
unsigned addr_hash = 0xe2c7 * (unsigned short) ((os_address) mem >> 2);
unsigned lock_idx = (addr_hash >> 23) & ~0x1c0;
unsigned char * const lock = &locks[lock_idx];
int result, tmp;
__asm__ __volatile__("1: ldstub [%1], %0\n\t"
" cmp %0, 0\n\t"
" bne 1b\n\t"
" nop"
: "=&r" (tmp)
: "r" (lock)
: "memory");
result = *mem;
*mem += val;
__asm__ __volatile__("stb %%g0, [%0]"
: /* no outputs */
: "r" (lock)
: "memory");
return result;
}
#endif
#if !(defined __APPLE__ || defined __linux) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100)
void log_stacktrace (const char *name, os_threadId tid)
{
@ -304,46 +83,3 @@ void log_stacktrace (const char *name, os_threadId tid)
}
#endif
#if HAVE_ATOMIC_LIFO
static int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1)
{
os_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);
}
void os_atomic_lifo_init (os_atomic_lifo_t *head)
{
head->aba_head.s.a = head->aba_head.s.b = 0;
}
void os_atomic_lifo_push (os_atomic_lifo_t *head, void *elem, size_t linkoff)
{
uintptr_t a0, b0;
do {
a0 = *((volatile uintptr_t *) &head->aba_head.s.a);
b0 = *((volatile uintptr_t *) &head->aba_head.s.b);
*((volatile uintptr_t *) ((char *) elem + linkoff)) = b0;
} while (!os_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, (uintptr_t)elem));
}
void *os_atomic_lifo_pop (os_atomic_lifo_t *head, size_t linkoff) {
uintptr_t a0, b0, b1;
do {
a0 = *((volatile uintptr_t *) &head->aba_head.s.a);
b0 = *((volatile uintptr_t *) &head->aba_head.s.b);
if (b0 == 0) {
return NULL;
}
b1 = (*((volatile uintptr_t *) ((char *) b0 + linkoff)));
} while (!os_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, b1));
return (void *) b0;
}
void os_atomic_lifo_pushmany (os_atomic_lifo_t *head, void *first, void *last, size_t linkoff)
{
uintptr_t a0, b0;
do {
a0 = *((volatile uintptr_t *) &head->aba_head.s.a);
b0 = *((volatile uintptr_t *) &head->aba_head.s.b);
*((volatile uintptr_t *) ((char *) last + linkoff)) = b0;
} while (!os_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, (uintptr_t)first));
}
#endif

View file

@ -9,58 +9,129 @@
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#
string(TOLOWER ${CMAKE_SYSTEM_NAME} platform)
include(CheckCSourceCompiles)
include(CheckLibraryExists)
include(CheckTypeSize)
include(GenerateExportHeader)
include(TestBigEndian)
set (posix_platforms darwin linux sunos)
IF(${platform} IN_LIST posix_platforms)
set(platform posix)
ENDIF()
set(sources
src/os_atomics.c
src/os_init.c
src/os_log.c
src/os_ifaddrs.c
src/os_socket.c
src/os_thread.c
src/os_time.c
src/os_errno.c
src/os_iter.c
src/os_strlcpy.c
src/os_dns.c
src/os_process.c
src/os_random.c)
# For posix platforms include the files in the posix/ directory.
PREPEND(srcs_platform ${platform} os_platform_errno.c os_platform_heap.c os_platform_init.c os_platform_process.c os_platform_ifaddrs.c os_platform_socket.c os_platform_stdlib.c os_platform_sync.c os_platform_thread.c os_platform_time.c)
string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
set(system_sources
os_platform_errno.c
os_platform_heap.c
os_platform_ifaddrs.c
os_platform_socket.c
os_platform_stdlib.c
os_platform_sync.c
os_platform_thread.c
os_platform_time.c
os_platform_init.c
os_platform_rusage.c)
include (GenerateExportHeader)
PREPEND(srcs_os "${CMAKE_CURRENT_SOURCE_DIR}/src" os_atomics.c os_init.c os_log.c os_ifaddrs.c os_socket.c os_thread.c os_time.c os_errno.c os_iter.c ${srcs_platform})
foreach(source ${system_sources})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/${system_name}/${source}")
list(APPEND sources "src/${system_name}/${source}")
else()
list(APPEND sources "src/posix/${source}")
endif()
endforeach()
add_library(OSAPI ${srcs_os})
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/os_project.h.in"
"include/os/os_project.h")
add_library(OSAPI ${sources})
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
target_link_libraries(OSAPI INTERFACE Threads::Threads)
if(WIN32)
# Link with Win32 core-libraries
target_link_libraries(OSAPI INTERFACE wsock32 ws2_32 iphlpapi)
# Many of the secure versions provided by Microsoft have failure modes
# which are not supported by our abstraction layer, so efforts trying
# to use the _s versions aren't typically the proper solution and C11
# (which contains most of the secure versions) is 'too new'. So we rely
# on static detection of misuse instead of runtime detection, so all
# these warnings can be disabled on Windows.
target_compile_definitions(OSAPI PRIVATE _CRT_SECURE_NO_WARNINGS)
# Disable warnings for deprecated Winsock API calls in general.
target_compile_definitions(OSAPI PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS)
# Disable warnings for deprecated POSIX names.
target_compile_definitions(OSAPI PRIVATE -D_CRT_NONSTDC_NO_DEPRECATE)
elseif(UNIX AND NOT APPLE)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
# Shared libs will have this by default. Static libs need it too on x86_64.
set_property(TARGET OSAPI PROPERTY POSITION_INDEPENDENT_CODE TRUE)
endif()
check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
if(NOT HAVE_CLOCK_GETTIME)
# Before glibc 2.17, clock_gettime was in librt.
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if(HAVE_CLOCK_GETTIME)
target_link_libraries(OSAPI INTERFACE rt)
endif()
endif()
if(NOT HAVE_CLOCK_GETTIME)
message(FATAL_ERROR "clock_gettime is not available")
endif()
endif()
if(${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
target_link_libraries(OSAPI INTERFACE -lsocket -lnsl)
target_compile_definitions(OSAPI PRIVATE -KPIC)
endif()
# Determine if platform is big or little endian.
test_big_endian(BIG_ENDIAN)
if(BIG_ENDIAN)
set(OS_ENDIANNESS_CODE "#define OS_ENDIANNESS OS_BIG_ENDIAN")
else()
set(OS_ENDIANNESS_CODE "#define OS_ENDIANNESS OS_LITTLE_ENDIAN")
endif()
# Determine if platform is 32 or 64 bit.
check_type_size("void*" OS_SIZEOF_VOID_P BUILTIN_TYPES_ONLY LANGUAGE C)
configure_file("cmake/os_project.h.in" "include/os/os_project.h")
target_sources(OSAPI PRIVATE "include/os/os_project.h")
generate_export_header(OSAPI EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/exports/os/osapi_export.h")
target_link_libraries(OSAPI INTERFACE Abstraction)
target_include_directories(OSAPI PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/exports/>"
"$<INSTALL_INTERFACE:${INSTALL_PREFIX}/include/>" "$<INSTALL_INTERFACE:${INSTALL_PREFIX}/exports/>")
target_sources(OSAPI PRIVATE "include/os/os_project.h")
target_include_directories(OSAPI
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>")
target_include_directories(
OSAPI PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/exports/>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>"
"$<INSTALL_INTERFACE:${INSTALL_PREFIX}/include/>"
"$<INSTALL_INTERFACE:${INSTALL_PREFIX}/exports/>")
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
if(${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
target_link_libraries(OSAPI INTERFACE -lsocket -lnsl)
add_definitions(-KPIC)
endif()
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_public.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_decl_attributes.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_decl_attributes_sal.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ddsc/os"
COMPONENT dev)
# Currently, only windows and posix platforms are supported.
IF(WIN32 AND NOT UNIX)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/os/windows/os_platform_public.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ddsc/os"
COMPONENT dev)
ELSE()
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/os/posix/os_platform_public.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ddsc/os"
COMPONENT dev)
ENDIF()
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_public.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_decl_attributes.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/os/os_decl_attributes_sal.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/os/${system_name}/os_platform_public.h"
DESTINATION
"${CMAKE_INSTALL_INCLUDEDIR}/ddsc/os"
COMPONENT
dev)

View file

@ -12,6 +12,16 @@
#ifndef OS_PROJECT_H
#define OS_PROJECT_H
/* Set OS_ENDIANNESS to OS_BIG_ENDIAN or OS_LITTLE_ENDIAN */
@OS_ENDIANNESS_CODE@
/* Sets OS_SIZEOF_VOID_P to sizeof(void*) */
@OS_SIZEOF_VOID_P_CODE@
#if (OS_SIZEOF_VOID_P == 8)
#define OS_64BIT
#endif
#define OS_VERSION "@CycloneDDS_VERSION@"
#define OS_VERSION_MAJOR @CycloneDDS_VERSION_MAJOR@
#define OS_VERSION_MINOR @CycloneDDS_VERSION_MINOR@
@ -22,4 +32,7 @@
#define OS_PROJECT_NAME_NOSPACE "@CMAKE_PROJECT_NAME@"
#define OS_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
#define OS_HOST_NAME "@CMAKE_HOST_SYSTEM_NAME@"
#define OS_TARGET_NAME "@CMAKE_SYSTEM_NAME@"
#endif /* OS_PROJECT_H */

View file

@ -29,27 +29,10 @@ extern "C" {
#endif
#define OS_DARWIN 1
#define OS_SOCKET_USE_FCNTL 1
#define OS_SOCKET_USE_IOCTL 0
#define OS_HAS_UCONTEXT_T 1
#define OS_FILESEPCHAR '/'
#define OS_HAS_NO_SET_NAME_PRCTL 1
#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
#define OS_ENDIANNESS OS_LITTLE_ENDIAN
#else
#define OS_ENDIANNESS OS_BIG_ENDIAN
#endif
#ifdef _LP64
#define OS_64BIT
#endif
#define OS_HAVE_GETRUSAGE 1
typedef double os_timeReal;
typedef int os_timeSec;
typedef uid_t os_uid;
typedef gid_t os_gid;
typedef mode_t os_mode_t;
typedef pid_t os_procId;
#define PRIprocId "d"
@ -57,7 +40,6 @@ extern "C" {
#include "os/posix/os_platform_sync.h"
#include "os/posix/os_platform_thread.h"
#include "os/posix/os_platform_stdlib.h"
#include "os/posix/os_platform_process.h"
#if defined (__cplusplus)
}

View file

@ -29,23 +29,10 @@ extern "C" {
#endif
#define OS_LINUX 1
#define OS_SOCKET_USE_FCNTL 1
#define OS_SOCKET_USE_IOCTL 0
#define OS_HAS_UCONTEXT_T 1
#define OS_FILESEPCHAR '/'
#define OS_HAS_NO_SET_NAME_PRCTL 1
#define OS_ENDIANNESS OS_LITTLE_ENDIAN
#ifdef _LP64
#define OS_64BIT
#endif
#define OS_HAVE_GETRUSAGE 1
typedef double os_timeReal;
typedef int os_timeSec;
typedef uid_t os_uid;
typedef gid_t os_gid;
typedef mode_t os_mode_t;
typedef pid_t os_procId;
#define PRIprocId "d"
@ -53,7 +40,6 @@ extern "C" {
#include "os/posix/os_platform_sync.h"
#include "os/posix/os_platform_thread.h"
#include "os/posix/os_platform_stdlib.h"
#include "os/posix/os_platform_process.h"
#if defined (__cplusplus)
}

View file

@ -12,6 +12,7 @@
#ifndef OS_H
#define OS_H
#include "os/os_project.h"
#include "os/osapi_export.h"
#include "os_public.h"
@ -21,22 +22,10 @@
#include "vxworks/os_platform.h"
#elif __sun == 1
#include "solaris/os_platform.h"
#elif defined(__INTEGRITY)
#include "integrity/os_platform.h"
#elif __PikeOS__ == 1
#include "pikeos3/os_platform.h"
#elif defined(__QNX__)
#include "qnx/os_platform.h"
#elif defined(_MSC_VER)
#ifdef _WIN32_WCE
#include "wince/os_platform.h"
#else
#include "windows/os_platform.h"
#endif
#elif defined __APPLE__
#include "darwin/os_platform.h"
#elif defined __CYGWIN__
#include "cygwin/os_platform.h"
#else
#error "Platform missing from os.h list"
#endif
@ -54,11 +43,8 @@
#include "os_errno.h"
#include "os_iter.h"
#include "os_log.h"
#define OSPL_VERSION_STR "aap"
#define OSPL_HOST_STR "noot"
#define OSPL_TARGET_STR "mies"
#define OSPL_INNER_REV_STR "wim"
#define OSPL_OUTER_REV_STR "zus"
#include "os_strlcpy.h"
#include "os_random.h"
#include "os_rusage.h"
#endif

View file

@ -21,24 +21,13 @@
extern "C" {
#endif
/* Note: os_atomics_inlines.c overrules OS_HAVE_INLINE, VDDS_INLINE and
OS_ATOMICS_OMIT_FUNCTIONS */
#if ! OS_HAVE_INLINE && ! defined OS_ATOMICS_OMIT_FUNCTIONS
#define OS_ATOMICS_OMIT_FUNCTIONS 1
#endif
#if ! OS_ATOMIC_SUPPORT && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40100
#include "os/os_atomics_gcc.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined _WIN32
/* Windows.h causes HUGE problems when included too early, primarily
because you can't include only a subset and later include the rest
*/
#undef OS_HAVE_INLINE
#undef VDDS_INLINE
#define VDDS_INLINE
/* windows.h causes HUGE problems when included too early, primarily
because you can't include only a subset and later include the rest */
#include "os_atomics_win32.h"
#endif
@ -46,150 +35,21 @@ extern "C" {
#include "os_atomics_solaris.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined __INTEGRITY
#include "os_atomics_integrity.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined __VXWORKS__
#include "os_atomics_vxworks.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined __GNUC__ && defined __i386
#include "os_atomics_gcc_x86.h"
#endif
#if ! OS_ATOMIC_SUPPORT && \
((defined __GNUC__ && defined __ppc) || \
(defined __vxworks && defined __PPC__))
/* VxWorks uses GCC but removed the __GNUC__ macro ... */
#include "os_atomics_gcc_ppc.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined __GNUC__ && defined __sparc__
#include "os_atomics_gcc_sparc.h"
#endif
#if ! OS_ATOMIC_SUPPORT && defined __GNUC__ && defined __arm__
#include "os_atomics_gcc_arm.h"
#endif
#if ! OS_ATOMIC_SUPPORT
#error "No support for atomic operations on this platform"
#endif
#if ! OS_HAVE_INLINE
/* LIFO */
#if OS_ATOMIC_LIFO_SUPPORT
typedef struct os_atomic_lifo {
os_atomic_uintptr2_t aba_head;
} os_atomic_lifo_t;
/* LD, ST */
OSAPI_EXPORT uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x);
OSAPI_EXPORT void os_atomic_lifo_init (os_atomic_lifo_t *head);
OSAPI_EXPORT void os_atomic_lifo_push (os_atomic_lifo_t *head, void *elem, size_t linkoff);
OSAPI_EXPORT void *os_atomic_lifo_pop (os_atomic_lifo_t *head, size_t linkoff);
OSAPI_EXPORT void os_atomic_lifo_pushmany (os_atomic_lifo_t *head, void *first, void *last, size_t linkoff);
#endif
OSAPI_EXPORT uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x);
OSAPI_EXPORT void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x);
OSAPI_EXPORT void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v);
/* INC */
OSAPI_EXPORT void os_atomic_inc32 (volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_inc64 (volatile os_atomic_uint64_t *x);
#endif
OSAPI_EXPORT void os_atomic_incptr (volatile os_atomic_uintptr_t *x);
OSAPI_EXPORT uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x);
#endif
OSAPI_EXPORT uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x);
/* DEC */
OSAPI_EXPORT void os_atomic_dec32 (volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_dec64 (volatile os_atomic_uint64_t *x);
#endif
OSAPI_EXPORT void os_atomic_decptr (volatile os_atomic_uintptr_t *x);
OSAPI_EXPORT uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x);
#endif
OSAPI_EXPORT uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x);
OSAPI_EXPORT uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x);
#endif
OSAPI_EXPORT uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x);
/* ADD */
OSAPI_EXPORT void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
OSAPI_EXPORT uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
/* SUB */
OSAPI_EXPORT void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
OSAPI_EXPORT uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
/* AND */
OSAPI_EXPORT void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
/* OR */
OSAPI_EXPORT void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
OSAPI_EXPORT uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
#endif
OSAPI_EXPORT uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
/* CAS */
OSAPI_EXPORT int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des);
#if OS_ATOMIC64_SUPPORT
OSAPI_EXPORT int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des);
#endif
OSAPI_EXPORT int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
OSAPI_EXPORT int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des);
/* FENCES */
OSAPI_EXPORT void os_atomic_fence (void);
OSAPI_EXPORT void os_atomic_fence_acq (void);
OSAPI_EXPORT void os_atomic_fence_rel (void);
#endif /* OS_HAVE_INLINE */
#if defined (__cplusplus)
}

View file

@ -25,325 +25,270 @@
#endif
#endif
#if ! OS_ATOMICS_OMIT_FUNCTIONS
#if ( OS_ATOMIC64_SUPPORT && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || \
(!OS_ATOMIC64_SUPPORT && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
/* Eliminate C warnings */
#define OS_ATOMIC_LIFO_SUPPORT 1
#if ! defined (__cplusplus)
VDDS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x);
VDDS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x);
VDDS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x);
VDDS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v);
VDDS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x);
VDDS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x);
VDDS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x);
VDDS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x);
VDDS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x);
VDDS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x);
VDDS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x);
VDDS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x);
VDDS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x);
VDDS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x);
VDDS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
VDDS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
VDDS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v);
VDDS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v);
VDDS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v);
VDDS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v);
VDDS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des);
VDDS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des);
VDDS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des);
VDDS_INLINE void os_atomic_fence (void);
VDDS_INLINE void os_atomic_fence_acq (void);
VDDS_INLINE void os_atomic_fence_rel (void);
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x);
VDDS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x);
VDDS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x);
VDDS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x);
VDDS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x);
VDDS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x);
VDDS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v);
VDDS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des);
typedef union { __int128 x; struct { uintptr_t a, b; } s; } os_atomic_uintptr2_t;
#else
typedef union { uint64_t x; struct { uintptr_t a, b; } s; } os_atomic_uintptr2_t;
#endif
#endif
/* LD, ST */
VDDS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
#endif
VDDS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
VDDS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
VDDS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
#endif
VDDS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
VDDS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
/* INC */
VDDS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
#endif
VDDS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
__sync_fetch_and_add (&x->v, 1);
}
VDDS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
#endif
VDDS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
return __sync_add_and_fetch (&x->v, 1);
}
/* DEC */
VDDS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
#endif
VDDS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
__sync_fetch_and_sub (&x->v, 1);
}
VDDS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
#endif
VDDS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
return __sync_sub_and_fetch (&x->v, 1);
}
VDDS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
#endif
VDDS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
return __sync_fetch_and_sub (&x->v, 1);
}
/* ADD */
VDDS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_add (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_add (&x->v, v);
}
#endif
VDDS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_add (&x->v, v);
}
VDDS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
os_atomic_addptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
VDDS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_add_and_fetch (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_add_and_fetch (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_add_and_fetch (&x->v, v);
}
VDDS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) os_atomic_addptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
/* SUB */
VDDS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_sub (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_sub (&x->v, v);
}
#endif
VDDS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_sub (&x->v, v);
}
VDDS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
os_atomic_subptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
VDDS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_sub_and_fetch (&x->v, v);
}
VDDS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) os_atomic_subptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
/* AND */
VDDS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_and (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_and (&x->v, v);
}
#endif
VDDS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_and (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_fetch_and_and (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_fetch_and_and (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_fetch_and_and (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_and_and_fetch (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_and_and_fetch (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_and_and_fetch (&x->v, v);
}
/* OR */
VDDS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
__sync_fetch_and_or (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
__sync_fetch_and_or (&x->v, v);
}
#endif
VDDS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
__sync_fetch_and_or (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_fetch_and_or (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_fetch_and_or (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_fetch_and_or (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return __sync_or_and_fetch (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return __sync_or_and_fetch (&x->v, v);
}
#endif
VDDS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return __sync_or_and_fetch (&x->v, v);
}
/* CAS */
VDDS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
#if OS_ATOMIC64_SUPPORT
VDDS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
#endif
VDDS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return __sync_bool_compare_and_swap (&x->v, exp, des);
}
VDDS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
return os_atomic_casptr (x, (uintptr_t) exp, (uintptr_t) des);
}
#if OS_ATOMIC_LIFO_SUPPORT
inline int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1) {
os_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 /* OS_ATOMIC_LIFO_SUPPORT */
/* FENCES */
VDDS_INLINE void os_atomic_fence (void) {
inline void os_atomic_fence (void) {
__sync_synchronize ();
}
VDDS_INLINE void os_atomic_fence_ldld (void) {
inline void os_atomic_fence_ldld (void) {
#if !(defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64)
__sync_synchronize ();
#endif
}
VDDS_INLINE void os_atomic_fence_acq (void) {
inline void os_atomic_fence_acq (void) {
os_atomic_fence ();
}
VDDS_INLINE void os_atomic_fence_rel (void) {
inline void os_atomic_fence_rel (void) {
os_atomic_fence ();
}
#endif /* not omit functions */
#define OS_ATOMIC_SUPPORT 1
#endif

View file

@ -13,72 +13,70 @@
#define OS_ATOMIC64_SUPPORT 1
#if ! OS_ATOMICS_OMIT_FUNCTIONS
/* LD, ST */
VDDS_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
VDDS_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
VDDS_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
VDDS_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
VDDS_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
VDDS_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
VDDS_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
VDDS_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
/* INC */
VDDS_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
atomic_inc_32 (&x->v);
}
VDDS_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
atomic_inc_64 (&x->v);
}
VDDS_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
atomic_inc_ulong (&x->v);
}
VDDS_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
return atomic_inc_32_nv (&x->v);
}
VDDS_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
return atomic_inc_64_nv (&x->v);
}
VDDS_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
return atomic_inc_ulong_nv (&x->v);
}
/* DEC */
VDDS_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
atomic_dec_32 (&x->v);
}
VDDS_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
atomic_dec_64 (&x->v);
}
VDDS_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
atomic_dec_ulong (&x->v);
}
VDDS_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
return atomic_dec_32_nv (&x->v);
}
VDDS_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
return atomic_dec_64_nv (&x->v);
}
VDDS_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
return atomic_dec_ulong_nv (&x->v);
}
VDDS_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_ov (volatile os_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;
}
VDDS_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_ov (volatile os_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;
}
VDDS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_ov (volatile os_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;
@ -86,161 +84,159 @@ VDDS_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
/* ADD */
VDDS_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
atomic_add_32 (&x->v, v);
}
VDDS_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
atomic_add_64 (&x->v, v);
}
VDDS_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
atomic_add_long (&x->v, v);
}
VDDS_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
atomic_add_ptr (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return atomic_add_32_nv (&x->v, v);
}
VDDS_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return atomic_add_64_nv (&x->v, v);
}
VDDS_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return atomic_add_long_nv (&x->v, v);
}
VDDS_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return atomic_add_ptr_nv (&x->v, v);
}
/* SUB */
VDDS_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
atomic_add_32 (&x->v, -v);
}
VDDS_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
atomic_add_64 (&x->v, -v);
}
VDDS_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
atomic_add_long (&x->v, -v);
}
VDDS_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
atomic_add_ptr (&x->v, -v);
}
VDDS_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return atomic_add_32_nv (&x->v, -v);
}
VDDS_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return atomic_add_64_nv (&x->v, -v);
}
VDDS_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return atomic_add_long_nv (&x->v, -v);
}
VDDS_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return atomic_add_ptr_nv (&x->v, -v);
}
/* AND */
VDDS_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
atomic_and_32 (&x->v, v);
}
VDDS_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
atomic_and_64 (&x->v, v);
}
VDDS_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
atomic_and_ulong (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_ov (volatile os_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;
}
VDDS_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_ov (volatile os_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;
}
VDDS_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_ov (volatile os_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;
}
VDDS_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return atomic_and_32_nv (&x->v, v);
}
VDDS_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return atomic_and_64_nv (&x->v, v);
}
VDDS_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return atomic_and_ulong_nv (&x->v, v);
}
/* OR */
VDDS_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
atomic_or_32 (&x->v, v);
}
VDDS_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
atomic_or_64 (&x->v, v);
}
VDDS_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
atomic_or_ulong (&x->v, v);
}
VDDS_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_ov (volatile os_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;
}
VDDS_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_ov (volatile os_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;
}
VDDS_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_ov (volatile os_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;
}
VDDS_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return atomic_or_32_nv (&x->v, v);
}
VDDS_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return atomic_or_64_nv (&x->v, v);
}
VDDS_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return atomic_or_ulong_nv (&x->v, v);
}
/* CAS */
VDDS_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
return atomic_cas_32 (&x->v, exp, des) == exp;
}
VDDS_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
return atomic_cas_64 (&x->v, exp, des) == exp;
}
VDDS_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return atomic_cas_ulong (&x->v, exp, des) == exp;
}
VDDS_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
return atomic_cas_ptr (&x->v, exp, des) == exp;
}
/* FENCES */
VDDS_INLINE void os_atomic_fence (void) {
inline void os_atomic_fence (void) {
membar_exit ();
membar_enter ();
}
VDDS_INLINE void os_atomic_fence_ldld (void) {
inline void os_atomic_fence_ldld (void) {
membar_enter ();
}
VDDS_INLINE void os_atomic_fence_acq (void) {
inline void os_atomic_fence_acq (void) {
membar_enter ();
}
VDDS_INLINE void os_atomic_fence_rel (void) {
inline void os_atomic_fence_rel (void) {
membar_exit ();
}
#endif /* not omit functions */
#define OS_ATOMIC_SUPPORT 1

View file

@ -25,8 +25,6 @@
#define OS_ATOMIC_PTROP(name) name
#endif
#if ! OS_ATOMICS_OMIT_FUNCTIONS
/* Experience is that WinCE doesn't provide these, and that neither does VS8 */
#if ! defined OS_WINCE_DEFS_H && _MSC_VER > 1400
#if defined _M_IX86 || defined _M_ARM
@ -42,140 +40,134 @@
#endif
#endif
#if OS_ATOMIC_HAVE_INLINE
#define OS_ATOMIC_API_INLINE OS_ATOMIC_INLINE
#else
#define OS_ATOMIC_API_INLINE OSAPI_EXPORT
#endif
/* LD, ST */
OS_ATOMIC_API_INLINE uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; }
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; }
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
OS_ATOMIC_API_INLINE void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x) { return x->v; }
inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x) { return (void *) os_atomic_ldptr (x); }
OS_ATOMIC_API_INLINE void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; }
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; }
#endif
OS_ATOMIC_API_INLINE void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
OS_ATOMIC_API_INLINE void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { x->v = v; }
inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v) { os_atomic_stptr (x, (uintptr_t) v); }
/* CAS */
OS_ATOMIC_API_INLINE int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des) {
return InterlockedCompareExchange (&x->v, des, exp) == exp;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des) {
return InterlockedCompareExchange64 (&x->v, des, exp) == exp;
}
#endif
OS_ATOMIC_API_INLINE int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) {
return OS_ATOMIC_PTROP (InterlockedCompareExchange) (&x->v, des, exp) == exp;
}
OS_ATOMIC_API_INLINE int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des) {
return os_atomic_casptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) exp, (uintptr_t) des);
}
/* INC */
OS_ATOMIC_API_INLINE void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) {
InterlockedIncrement (&x->v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) {
InterlockedIncrement64 (&x->v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) {
OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) {
return InterlockedIncrement (&x->v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) {
return InterlockedIncrement64 (&x->v);
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) {
return OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v);
}
/* DEC */
OS_ATOMIC_API_INLINE void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) {
InterlockedDecrement (&x->v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) {
InterlockedDecrement64 (&x->v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) {
OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) {
return InterlockedDecrement (&x->v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) {
return InterlockedDecrement64 (&x->v);
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) {
return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) {
return InterlockedDecrement (&x->v) + 1;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) {
return InterlockedDecrement64 (&x->v) + 1;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) {
return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v) + 1;
}
/* ADD */
OS_ATOMIC_API_INLINE void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) {
InterlockedExchangeAdd (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) {
InterlockedExchangeAdd64 (&x->v, v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v);
}
OS_ATOMIC_API_INLINE void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
os_atomic_addptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return InterlockedExchangeAdd (&x->v, v) + v;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return InterlockedExchangeAdd64 (&x->v, v) + v;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v) + v;
}
OS_ATOMIC_API_INLINE void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) os_atomic_addptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
/* SUB */
OS_ATOMIC_API_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
@ -183,7 +175,7 @@ OS_ATOMIC_API_INLINE void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint3
#pragma warning (pop)
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
@ -191,17 +183,17 @@ OS_ATOMIC_API_INLINE void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint6
#pragma warning (pop)
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v);
#pragma warning (pop)
}
OS_ATOMIC_API_INLINE void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
os_atomic_subptr ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
@ -209,7 +201,7 @@ OS_ATOMIC_API_INLINE uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x
#pragma warning (pop)
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
@ -217,14 +209,14 @@ OS_ATOMIC_API_INLINE uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x
#pragma warning (pop)
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
/* disable unary minus applied to unsigned type, result still unsigned */
#pragma warning (push)
#pragma warning (disable: 4146)
return OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v) - v;
#pragma warning (pop)
}
OS_ATOMIC_API_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) {
return (void *) os_atomic_subptr_nv ((volatile os_atomic_uintptr_t *) x, (uintptr_t) v);
}
@ -232,85 +224,85 @@ OS_ATOMIC_API_INLINE void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x,
#if defined OS_ATOMIC_INTERLOCKED_AND
OS_ATOMIC_API_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
OS_ATOMIC_INTERLOCKED_AND (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
InterlockedAnd64 (&x->v, v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
return OS_ATOMIC_INTERLOCKED_AND (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
return InterlockedAnd64 (&x->v, v);
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return OS_ATOMIC_INTERLOCKED_AND (&x->v, v) & v;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return InterlockedAnd64 (&x->v, v) & v;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, v) & v;
}
#else /* synthesize via CAS */
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas32 (x, oldval, newval));
return oldval;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas64 (x, oldval, newval));
return oldval;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_casptr (x, oldval, newval));
return oldval;
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas32 (x, oldval, newval));
return newval;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_cas64 (x, oldval, newval));
return newval;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval & v; } while (!os_atomic_casptr (x, oldval, newval));
return newval;
}
OS_ATOMIC_API_INLINE void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) {
(void) os_atomic_and32_nv (x, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) {
(void) os_atomic_and64_nv (x, v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
(void) os_atomic_andptr_nv (x, v);
}
@ -320,85 +312,85 @@ OS_ATOMIC_API_INLINE void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uin
#if defined OS_ATOMIC_INTERLOCKED_OR
OS_ATOMIC_API_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
OS_ATOMIC_INTERLOCKED_OR (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
InterlockedOr64 (&x->v, v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
return OS_ATOMIC_INTERLOCKED_OR (&x->v, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
return InterlockedOr64 (&x->v, v);
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v);
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
return OS_ATOMIC_INTERLOCKED_OR (&x->v, v) | v;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
return InterlockedOr64 (&x->v, v) | v;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
return OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, v) | v;
}
#else /* synthesize via CAS */
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas32 (x, oldval, newval));
return oldval;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas64 (x, oldval, newval));
return oldval;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_casptr (x, oldval, newval));
return oldval;
}
OS_ATOMIC_API_INLINE uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) {
uint32_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas32 (x, oldval, newval));
return newval;
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) {
uint64_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_cas64 (x, oldval, newval));
return newval;
}
#endif
OS_ATOMIC_API_INLINE uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) {
uintptr_t oldval, newval;
do { oldval = x->v; newval = oldval | v; } while (!os_atomic_casptr (x, oldval, newval));
return newval;
}
OS_ATOMIC_API_INLINE void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) {
(void) os_atomic_or32_nv (x, v);
}
#if OS_ATOMIC64_SUPPORT
OS_ATOMIC_API_INLINE void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) {
(void) os_atomic_or64_nv (x, v);
}
#endif
OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) {
(void) os_atomic_orptr_nv (x, v);
}
@ -406,7 +398,7 @@ OS_ATOMIC_API_INLINE void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uint
/* FENCES */
OS_ATOMIC_API_INLINE void os_atomic_fence (void) {
inline void os_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. */
@ -416,15 +408,15 @@ OS_ATOMIC_API_INLINE void os_atomic_fence (void) {
InterlockedExchange (&tmp, 0);
#pragma warning (pop)
}
OS_ATOMIC_API_INLINE void os_atomic_fence_ldld (void) {
inline void os_atomic_fence_ldld (void) {
#if !(defined _M_IX86 || defined _M_X64)
os_atomic_fence ();
#endif
}
OS_ATOMIC_API_INLINE void os_atomic_fence_acq (void) {
inline void os_atomic_fence_acq (void) {
os_atomic_fence ();
}
OS_ATOMIC_API_INLINE void os_atomic_fence_rel (void) {
inline void os_atomic_fence_rel (void) {
os_atomic_fence ();
}
@ -432,9 +424,6 @@ OS_ATOMIC_API_INLINE void os_atomic_fence_rel (void) {
#undef OS_ATOMIC_INTERLOCKED_OR
#undef OS_ATOMIC_INTERLOCKED_AND64
#undef OS_ATOMIC_INTERLOCKED_OR64
#undef OS_ATOMIC_API_INLINE
#endif /* not omit functions */
#undef OS_ATOMIC_PTROP
#define OS_ATOMIC_SUPPORT 1

View file

@ -18,21 +18,6 @@
#if OS_ENDIANNESS != OS_LITTLE_ENDIAN && OS_ENDIANNESS != OS_BIG_ENDIAN
#error "OS_ENDIANNESS not set correctly"
#endif
#ifndef OS_HAS_UCONTEXT_T
#error "OS_HAS_UCONTEXT_T not set"
#endif
#ifndef OS_SOCKET_USE_FCNTL
#error "OS_SOCKET_USE_FCNTL must be defined for this platform."
#endif
#ifndef OS_SOCKET_USE_IOCTL
#error "OS_SOCKET_USE_IOCTL must be defined for this platform."
#endif
#if (OS_SOCKET_USE_IOCTL == 1) && (OS_SOCKET_USE_FCNTL == 1)
#error "this platform must set only one of OS_SOCKET_USE_IOCTL and OS_SOCKET_USE_FCNTL to 1"
#endif
#ifndef OS_FILESEPCHAR
#error "OS_FILESEPCHAR must be defined for this platform."
#endif
#include "os/os_decl_attributes.h"
@ -204,66 +189,6 @@ __pragma (warning(pop))
os_resultFail
} os_result;
/* We want to inline these, but we don't want to emit an exernally
visible symbol for them and we don't want warnings if we don't use
them.
It appears as if a plain "inline" will do just that in C99.
In traditional GCC one had to use "extern inline" to achieve that
effect, but that will cause an externally visible symbol to be
emitted by a C99 compiler.
Starting with GCC 4.3, GCC conforms to the C99 standard if
compiling in C99 mode, unless -fgnu89-inline is specified. It
defines __GNUC_STDC_INLINE__ if "inline"/"extern inline" behaviour
is conforming the C99 standard.
So: GCC >= 4.3: choose between "inline" & "extern inline" based
upon __GNUC_STDC_INLINE__; for GCCs < 4.2, rely on the traditional
GCC behaiour; and for other compilers assume they behave conforming
the standard if they advertise themselves as C99 compliant (use
"inline"), and assume they do not support the inline keywords
otherwise.
GCC when not optimizing ignores "extern inline" functions. So we
need to distinguish between optimizing & non-optimizing ... */
/* Defining OS_HAVE_INLINE is a supported way of overruling this file */
#ifndef OS_HAVE_INLINE
#if __STDC_VERSION__ >= 199901L
# /* C99, but old GCC nonetheless doesn't implement C99 semantics ... */
# if __GNUC__ && ! defined __GNUC_STDC_INLINE__
# define OS_HAVE_INLINE 1
# define VDDS_INLINE extern __inline__
# else
# define OS_HAVE_INLINE 1
# define VDDS_INLINE inline
# endif
#elif defined __STDC__ && defined __GNUC__ && ! defined __cplusplus
# if __OPTIMIZE__
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
# ifdef __GNUC_STDC_INLINE__
# define OS_HAVE_INLINE 1
# define VDDS_INLINE __inline__
# else
# define OS_HAVE_INLINE 1
# define VDDS_INLINE extern __inline__
# endif
# else
# define OS_HAVE_INLINE 1
# define VDDS_INLINE extern __inline__
# endif
# endif
#endif
#if ! OS_HAVE_INLINE
#define VDDS_INLINE
#endif
#endif /* not defined OS_HAVE_INLINE */
#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,

View file

@ -22,7 +22,20 @@ extern "C" {
#include <winerror.h>
#endif
#include <errno.h> /* Required on Windows platforms too */
#include <errno.h> /* Required on Windows platforms too. */
/* DNS runtime functions require custom error codes to be defined. For POSIX
platforms a high enough 32-bit number (not too close to any system specified
error number) should be safe. Microsoft Windows error codes, however, are
encoded after the HRESULT (https://en.wikipedia.org/wiki/HRESULT) scheme. To
avoid clashes the customer code bit (0x20000000) must be set. */
#define OS_ERRBASE (0x20000000)
#define OS_HOST_NOT_FOUND (OS_ERRBASE + 1)
#define OS_NO_DATA (OS_ERRBASE + 2)
#define OS_NO_RECOVERY (OS_ERRBASE + 3)
#define OS_TRY_AGAIN (OS_ERRBASE + 4)
/** \brief Get error code set by last operation that failed
*
@ -41,6 +54,28 @@ extern "C" {
os_setErrno (
int err);
/**
* \brief Return string describing internal error number.
*
* @param[in] errnum
* @param[out] buf
* @param[in] buflen
*
* @returns 0 on success or a valid error number on failure.
*
* @retval 0
* Success. The error message is copied to the buffer.
* @retval EINVAL
* Not a valid internal error code.
* @retval ERANGE
* Buffer is not large enough to store the error message.
*/
OSAPI_EXPORT int _Success_(return == 0)
os_errstr(
_In_ int errnum,
_Out_writes_opt_z_(buflen) char *buf,
_In_ size_t buflen);
/**
* \brief Get description for specified error code
*

View file

@ -32,45 +32,7 @@ extern "C" {
* Possible Results:
* - returns the process ID of the calling process
*/
OSAPI_EXPORT os_procId os_procIdSelf(void);
/** \brief Figure out the identity of the current process
*
* Possible Results:
* - returns the actual length of procIdentity
*
* Postcondition:
* - \b procIdentity is ""
* the process identity could not be determined
* - \b procIdentity is "<decimal number>" | "0x<hexadecimal number>"
* only the process numeric identity could be determined
* - \b procIdentity is "<process name> (<decimal number>)" | "<process name> (0x<hexadecimal number>)"
* the process name and numeric identity could be determined
*
* \b procIdentity will not be filled beyond the specified \b procIdentitySize
*/
OSAPI_EXPORT int
os_procNamePid(
_Out_writes_z_(procIdentitySize) char *procIdentity,
_In_ size_t procIdentitySize);
/** \brief Figure out the name of the current process
*
* Possible Results:
* - returns the actual length of procName
*
* Postcondition:
* - \b procName is ""
* the process name could not be determined
* - \b procName is "<process name>"
* the process name could be determined
*
* \b procName will not be filled beyond the specified \b procNameSize
*/
OSAPI_EXPORT int
os_procName(
_Out_writes_z_(procNameSize) char *procName,
_In_ size_t procNameSize);
OSAPI_EXPORT os_procId os_getpid(void);
#if defined (__cplusplus)
}

View file

@ -9,16 +9,19 @@
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
#ifndef OS_PLATFORM_PROCESS_H
#define OS_PLATFORM_PROCESS_H
#ifndef OS_RANDOM_H
#define OS_RANDOM_H
#include "os/os_defs.h"
#if defined (__cplusplus)
extern "C" {
#endif
void os_processModuleInit(void);
void os_processModuleExit(void);
OSAPI_EXPORT long os_random(void);
#if defined (__cplusplus)
}
#endif
#endif
#endif /* OS_RANDOM_H */

View file

@ -0,0 +1,35 @@
/*
* 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 OS_RUSAGE_H
#define OS_RUSAGE_H
#include "os/os_defs.h"
typedef struct {
os_time utime; /* User CPU time used. */
os_time 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. */
} os_rusage_t;
#define OS_RUSAGE_SELF 0
#define OS_RUSAGE_THREAD 1
_Pre_satisfies_((who == OS_RUSAGE_SELF) || \
(who == OS_RUSAGE_THREAD))
_Success_(return == 0)
int os_getrusage(_In_ int who, _Out_ os_rusage_t *usage);
#endif /* OS_GETRUSAGE_H */

View file

@ -36,6 +36,7 @@ extern "C" {
* @addtogroup OS_NET
* @{
*/
#define OS_VALID_SOCKET(s) ((s) != OS_INVALID_SOCKET)
/**
* Socket handle type. SOCKET on windows, int otherwise.
@ -46,68 +47,24 @@ extern "C" {
typedef struct sockaddr_in os_sockaddr_in;
typedef struct sockaddr os_sockaddr;
typedef struct sockaddr_storage os_sockaddr_storage;
#ifdef OS_SOCKET_HAS_IPV6
#if (OS_SOCKET_HAS_IPV6 == 0)
struct foo_in6_addr {
unsigned char foo_s6_addr[16];
};
typedef struct foo_in6_addr os_in6_addr;
struct foo_sockaddr_in6 {
os_os_ushort sin6_family;
os_os_ushort sin6_port;
uint32_t sin6_flowinfo;
os_in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
typedef struct foo_sockaddr_in6 os_sockaddr_in6;
struct foo_sockaddr_storage {
#if (OS_SOCKET_HAS_SA_LEN == 1)
os_uchar ss_len;
os_uchar ss_family;
#else
os_os_ushort ss_family;
#endif
/* Below aren't 'real' members. Just here for padding to make it big enough
for any possible IPv6 address. Not that IPv6 works on this OS. */
os_os_ushort sin6_port;
uint32_t sin6_flowinfo;
os_in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
typedef struct foo_sockaddr_storage os_sockaddr_storage;
struct foo_ipv6_mreq {
os_in6_addr ipv6mr_multiaddr;
unsigned int ipv6mr_interface;
};
typedef struct foo_ipv6_mreq os_ipv6_mreq;
#else
#if OS_SOCKET_HAS_IPV6
typedef struct ipv6_mreq os_ipv6_mreq;
typedef struct in6_addr os_in6_addr;
typedef struct sockaddr_storage os_sockaddr_storage;
typedef struct sockaddr_in6 os_sockaddr_in6;
#endif
#else
#error OS_SOCKET_HAS_IPV6 not defined
#endif
extern const os_in6_addr os_in6addr_any;
extern const os_in6_addr os_in6addr_loopback;
#endif /* OS_SOCKET_HAS_IPV6 */
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46 /* strlen("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") + 1 */
#endif
#define INET6_ADDRSTRLEN_EXTENDED (INET6_ADDRSTRLEN + 8) /* + strlen("[]:12345") */
/* The maximum buffersize needed to safely store the output of
* os_sockaddrAddressPortToString or os_sockaddrAddressToString. */
#define OS_SOCKET_MAX_ADDRSTRLEN INET6_ADDRSTRLEN_EXTENDED
#define SD_FLAG_IS_SET(flags, flag) ((((uint32_t)(flags) & (uint32_t)(flag))) != 0U)
#define OS_AF_NULL (-1)
@ -279,58 +236,107 @@ extern "C" {
*/
OSAPI_EXPORT int
os_sockaddr_is_unspecified(
const os_sockaddr *const sa) __nonnull_all__;
_In_ const os_sockaddr *__restrict sa) __nonnull_all__;
/* docced in implementation file */
/**
* Check this address to see if it represents loopback.
* @return true if it does. false otherwise, or if unknown address type.
* @param thisSock A pointer to an os_sockaddr to be checked.
*/
OSAPI_EXPORT int
os_sockaddr_is_loopback(
_In_ const os_sockaddr *__restrict sa) __nonnull_all__;
/**
* Checks two socket IP host addresses for be on the same subnet, considering the given subnetmask.
* It will not consider the possibility of IPv6 mapped IPv4 addresses or anything arcane like that.
* @param thisSock First address
* @param thatSock Second address.
* @param mask Subnetmask.
* @return true if equal, false otherwise.
*/
OSAPI_EXPORT bool
os_sockaddrSameSubnet(const os_sockaddr* thisSock,
const os_sockaddr* thatSock,
const os_sockaddr* mask);
/**
* Convert a socket address to a string format presentation representation
* @param sa The socket address struct.
* @param buffer A character buffer to hold the string rep of the address.
* @param buflen The (max) size of the buffer
* @return Pointer to start of string
*/
OSAPI_EXPORT char*
os_sockaddrAddressToString(const os_sockaddr* sa,
char* buffer, size_t buflen);
#ifdef OS_SOCKET_HAS_DNS
typedef struct {
size_t naddrs;
os_sockaddr_storage addrs[];
} os_hostent_t;
/**
* Convert the provided addressString into a os_sockaddr.
* Lookup addresses for given host name.
*
* @param addressString The string representation of a network address.
* @param addressOut A pointer to an os_sockaddr. Must be big enough for
* the address type specified by the string. This implies it should
* generally be the address of an os_sockaddr_storage for safety's sake.
* @param isIPv4 If the addressString is a hostname specifies whether
* and IPv4 address should be returned. If false an Ipv6 address will be
* requested. If the address is in either valid decimal presentation format
* param will be ignored.
* @return true on successful conversion. false otherwise
* @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 os_hostent_t.
*
* @returns 0 on success or valid error number on failure.
*
* @retval 0
* Success. Host name successfully resolved to address(es).
* @retval OS_HOST_NOT_FOUND
* Host not found.
* @retval OS_NO_DATA
* Valid name, no data record of requested type.
* @retval OS_NO_RECOVERY
* Nonrecoverable error.
* @retval OS_TRY_AGAIN
* Nonauthoratitative host not found.
*/
_Success_(return) OSAPI_EXPORT bool
os_sockaddrStringToAddress(
_In_z_ const char *addressString,
_When_(isIPv4, _Out_writes_bytes_(sizeof(os_sockaddr_in)))
_When_(!isIPv4, _Out_writes_bytes_(sizeof(os_sockaddr_in6)))
os_sockaddr *addressOut,
_In_ bool isIPv4);
OSAPI_EXPORT _Success_(return == 0) int
os_gethostbyname(
_In_z_ const char *name,
_In_ int af,
_Out_ os_hostent_t **hent);
/* docced in implementation file */
OSAPI_EXPORT bool
os_sockaddrIsLoopback(const os_sockaddr* thisSock);
#endif /* OS_SOCKET_HAS_DNS */
/**
* Sets the address of the sockaddr to the special IN_ADDR_ANY value.
* @param sa the sockaddr to set the address for
* @pre sa is a valid sockaddr pointer
* @post Address of sa is set to the special IN_ADDR_ANY value
* Convert IPv4 and IPv6 addresses from text to socket address.
*
* @param af[in] Address family, either AF_INET or AF_INET6.
* @param str[in] Network address in text form.
* @param sa[out] Pointer to a sufficiently large enough socket address
* structure. This implies it should generally be the
* address to a structure of type struct sockaddr_storage.
*
* @return 0 on success or a valid error number on failure.
*/
OSAPI_EXPORT void
os_sockaddrSetInAddrAny(os_sockaddr* sa);
OSAPI_EXPORT _Success_(return) int
os_sockaddrfromstr(
_In_ int af,
_In_z_ const char *str,
_When_(af == AF_INET, _Out_writes_bytes_(sizeof(os_sockaddr_in)))
#if OS_SOCKET_HAS_IPV6
_When_(af == AF_INET6, _Out_writes_bytes_(sizeof(os_sockaddr_in6)))
#endif
void *sa);
/**
* Convert a socket address to text form.
*
* @param[in] sa Socket address structure.
* @param[out] buf Buffer to which resulting string is copied.
* @param[in] size Number of bytes available in the buffer.
*
* @returns 0 on success or a valid error number on failure.
*
* @retval 0
* Success. Socket address structure converted to text form.
* @retval EAFNOSUPPORT
* Socket address structure of unsupported valid address family.
* @retval ENOSPC
* Text form would exceed the size specified by size.
*/
OSAPI_EXPORT _Success_(return == 0) int
os_sockaddrtostr(
_In_ const void *sa,
_Out_writes_z_(size) char *buf,
_In_ size_t size);
/**
* @}

View file

@ -186,31 +186,6 @@ extern "C" {
const char *format,
va_list args);
/** \brief fprintf wrapper with disabled broken pipe signals
*
* A fprintf can cause an broken pipe signal that can result in a deadlock
* if the interrupted thread is holding recourses needed by for example the
* signal handler thread.
*
* Precondition:
* None
* Postcondition:
* None
*
* Possible results:
* - return
* Upon successful completion will return the number of
* bytes written to file
* or a negative value if an error occurred.
* errno will be set in such case
* - Writes formatted output to file.
*/
int
os_vfprintfnosigpipe(
FILE *file,
const char *format,
va_list args);
/** \brief strtoll wrapper
*
* Translate string str to long long value considering base,

View file

@ -0,0 +1,72 @@
/*
* 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 OS_STRLCPY_H
#define OS_STRLCPY_H
#include "os/os_defs.h"
#if defined (__cplusplus)
extern "C" {
#endif
/**
* @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.
*/
_Success_(return < size)
OSAPI_EXPORT
size_t
os_strlcpy(
_Out_writes_z_(size) char * __restrict dest,
_In_z_ const char * __restrict src,
_In_ size_t size);
/**
* @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.
*/
_Success_(return < size)
OSAPI_EXPORT
size_t
os_strlcat(
_Inout_updates_z_(size) char * __restrict dest,
_In_z_ const char * __restrict src,
_In_ size_t size);
#if defined (__cplusplus)
}
#endif
#endif /* OS_STRLCPY_H */

View file

@ -130,7 +130,7 @@ extern "C" {
os_condInit(
_Out_ os_cond *cond,
_In_ os_mutex *mutex)
__nonnull((1,2));
__nonnull_all__;
/** \brief Destroy the condition variable
*/

View file

@ -127,6 +127,8 @@ extern "C" {
OSAPI_EXPORT os_threadId
os_threadIdSelf(void);
int os_threadEqual (os_threadId a, os_threadId b);
/** \brief Wait for the termination of the identified thread
*
* If the identified thread is still running, wait for its termination
@ -147,26 +149,6 @@ extern "C" {
_In_ os_threadId threadId,
_Out_opt_ uint32_t *thread_result);
/** \brief Figure out the identity of the current thread
*
* Possible Results:
* - returns the actual length of threadIdentity
*
* Postcondition:
* - \b threadIdentity is ""
* the thread identity could not be determined
* - \b threadIdentity is "<decimal number>" | "0x<hexadecimal number>"
* only the thread numeric identity could be determined
* - \b threadIdentity is "<process name> (<decimal number>)" | "<process name> (0x<hexadecimal number>)"
* the thread name and numeric identity could be determined
*
* \b threadIdentity will not be filled beyond the specified \b threadIdentitySize
*/
OSAPI_EXPORT int32_t
os_threadFigureIdentity(
char *threadIdentity,
uint32_t threadIdentitySize);
/** \brief Get name of current thread
*
* Postcondition:

View file

@ -19,25 +19,25 @@
#endif /* __VXWORKS__ */
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <sys/select.h>
#ifdef __APPLE__
#include <sys/sockio.h>
#endif /* __APPLE__ */
#include <unistd.h>
#include <ifaddrs.h>
#if defined (__cplusplus)
extern "C" {
#endif
/* Keep defines before common header */
#define OS_SOCKET_HAS_DNS 1
#define OS_SOCKET_HAS_IPV6 1
#define OS_SOCKET_HAS_SA_LEN 1
#define OS_NO_SIOCGIFINDEX 1
@ -68,9 +68,24 @@ extern "C" {
typedef int os_socket; /* signed */
#define PRIsock "d"
#define OS_SOCKET_INVALID (-1)
#define OS_INVALID_SOCKET (-1)
typedef struct iovec os_iovec_t;
typedef size_t os_iov_len_t;
#if defined(__sun) && !defined(_XPG4_2)
#define msg_accrights msg_control
#define msg_accrightslen msg_controllen
#define OS_MSGHDR_FLAGS 0
#else
#define OS_MSGHDR_FLAGS 1
#endif
#if defined(__linux)
typedef size_t os_msg_iovlen_t;
#else /* POSIX says int (which macOS, FreeBSD, Solaris do) */
typedef int os_msg_iovlen_t;
#endif
#if defined (__cplusplus)
}

View file

@ -29,23 +29,10 @@ extern "C" {
#endif
#define OS_SOLARIS 1
#define OS_SOCKET_USE_FCNTL 1
#define OS_SOCKET_USE_IOCTL 0
#define OS_HAS_UCONTEXT_T 1
#define OS_FILESEPCHAR '/'
#define OS_HAS_NO_SET_NAME_PRCTL 1
#define OS_ENDIANNESS OS_LITTLE_ENDIAN
#ifdef _LP64
#define OS_64BIT
#endif
#define OS_HAVE_GETRUSAGE 1
typedef double os_timeReal;
typedef int os_timeSec;
typedef uid_t os_uid;
typedef gid_t os_gid;
typedef mode_t os_mode_t;
typedef pid_t os_procId;
#define PRIprocId "d"
@ -53,7 +40,6 @@ extern "C" {
#include "os/posix/os_platform_sync.h"
#include "os/posix/os_platform_thread.h"
#include "os/posix/os_platform_stdlib.h"
#include "os/posix/os_platform_process.h"
#if defined (__cplusplus)
}

View file

@ -98,27 +98,10 @@ extern "C" {
#endif
#define OS_VXWORKS 1
#define OS_SOCKET_USE_FCNTL 0
#define OS_SOCKET_USE_IOCTL 1
#define OS_FILESEPCHAR '/'
#define OS_HAS_NO_SET_NAME_PRCTL 1 /* FIXME: Move to CMake */
#define OS_HAS_UCONTEXT_T 1
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ /* FIXME: Move to CMake */
#define OS_ENDIANNESS OS_BIG_ENDIAN
#else
#define OS_ENDIANNESS OS_LITTLE_ENDIAN
#endif
#if defined(__PPC) || defined(__x86_64__) /* FIXME: Move to CMake */
#define OS_64BIT
#endif
#define OS_HAVE_GETRUSAGE 0
typedef double os_timeReal;
typedef int os_timeSec;
typedef uid_t os_uid;
typedef gid_t os_gid;
typedef mode_t os_mode_t;
#ifdef _WRS_KERNEL
typedef RTP_ID os_procId; /* typedef struct wind_rtp *RTP_ID */
#define PRIprocId "d"

View file

@ -34,33 +34,16 @@ extern "C" {
#endif
#define OS_WIN32 1
#define OS_SOCKET_USE_FCNTL 0
#define OS_SOCKET_USE_IOCTL 1
#define OS_FILESEPCHAR '/'
#define OS_HAS_NO_SET_NAME_PRCTL 1
#define OS_HAS_UCONTEXT_T 0
#ifdef __BIG_ENDIAN
#define OS_ENDIANNESS OS_BIG_ENDIAN
#else
#define OS_ENDIANNESS OS_LITTLE_ENDIAN
#endif
#ifdef _WIN64
#define OS_64BIT
#endif
#define OS_HAVE_GETRUSAGE 1
typedef double os_timeReal;
typedef int os_timeSec;
typedef DWORD os_procId;
#define PRIprocId "u"
/* keep in sync with st_mode field def in struct stat in sys/stat.h */
typedef unsigned short os_mode_t;
typedef SSIZE_T ssize_t;
#include "os/windows/os_platform_socket.h"
#include "os/windows/os_platform_sync.h"
#include "os/windows/os_platform_process.h"
#include "os/windows/os_platform_thread.h"
#include "os/windows/os_platform_stdlib.h"
#include "os/windows/os_platform_time.h"

View file

@ -25,6 +25,7 @@ extern "C" {
/* Keep defines before common header */
#define OS_SOCKET_HAS_IPV6 1
#define OS_SOCKET_HAS_DNS 1
#define OS_SOCKET_HAS_SA_LEN 0
#define OS_NO_SIOCGIFINDEX 1
#define OS_NO_NETLINK 1
@ -42,7 +43,7 @@ extern "C" {
#define os_sockENOMEM WSABASEERR
#define os_sockENOSR WSABASEERR
#define os_sockENOENT WSABASEERR
#define os_sockEPERM WSABASEERR
#define os_sockEPERM WSAEACCES
#define os_sockEINTR WSAEINTR
#define os_sockEBADF WSAEBADF
#define os_sockEACCES WSAEACCES
@ -60,7 +61,36 @@ extern "C" {
typedef SOCKET os_socket;
#define PRIsock PRIuPTR
#define OS_SOCKET_INVALID (-1)
#define OS_INVALID_SOCKET (INVALID_SOCKET)
typedef unsigned os_iov_len_t;
typedef struct os_iovec {
os_iov_len_t iov_len;
void *iov_base;
} os_iovec_t;
typedef DWORD os_msg_iovlen_t;
struct msghdr {
void *msg_name;
socklen_t msg_namelen;
os_iovec_t *msg_iov;
os_msg_iovlen_t msg_iovlen;
void *msg_control;
size_t msg_controllen;
int msg_flags;
};
#define OS_MSGHDR_FLAGS 1
/* Only implements iovec of length 1, no control */
ssize_t recvmsg (os_socket fd, struct msghdr *message, int flags);
ssize_t sendmsg (os_socket fd, const struct msghdr *message, int flags);
#ifndef MSG_TRUNC
#define MSG_TRUNC 1
#endif
void os_socketModuleInit(void);
void os_socketModuleExit(void);

View file

@ -19,12 +19,6 @@
extern "C" {
#endif
#define OS_OS_FILESEPCHAR '\\'
#define OS_OS_PATHSEPCHAR ';'
#define OS_OS_EXESUFFIX ".exe"
#define OS_OS_BATSUFFIX ".bat"
#define OS_OS_LIB_LOAD_PATH_VAR "PATH"
#define OS_ROK (_S_IREAD)
#define OS_WOK (_S_IWRITE)
#define OS_XOK (_S_IEXEC)
@ -39,14 +33,6 @@ extern "C" {
#define S_IRWXG 00070
#define S_IRWXO 00007
/* The value _POSIX_PATH_MAX is defined in limits.h, however you have
* to define _POSIX_ during compilation.This again will remove the
* _read, _open and _close prototypes!
*/
#define OS_PATH_MAX 255
typedef HANDLE os_os_dirHandle;
#define MAXHOSTNAMELEN MAX_HOSTNAME_LEN
#if _MSC_VER < 1900

Some files were not shown because too many files have changed in this diff Show more