From cd6742ee125d70486b4699f0fad19223459f04ee Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Fri, 18 Jan 2019 14:10:19 +0100 Subject: [PATCH] Rearrange and fixup abstraction layer - Replace os_result by dds_retcode_t and move DDS return code defines down. Eliminates the need to convert between different return code types. - Move dds_time_t down and remove os_time. Eliminates the need to convert between different time representations and reduces code duplication. - Remove use of Microsoft source-code annotation language (SAL). SAL annotations are Microsoft specific and not very well documented. This makes it very difficult for contributers to write. - Rearrange the abstraction layer to be feature-based. The previous layout falsely assumed that the operating system dictates which implementation is best suited. For general purpose operating systems this is mostly true, but embedded targets require a slightly different approach and may not even offer all features. The new layout makes it possible to mix-and-match feature implementations and allows for features to not be implemented at all. - Replace the os prefix by ddsrt to avoid name collisions. - Remove various portions of unused and unwanted code. - Export thread names on all supported platforms. - Return native thread identifier on POSIX compatible platforms. - Add timed wait for condition variables that takes an absolute time. - Remove system abstraction for errno. The os_getErrno and os_setErrno were incorrect. Functions that might fail now simply return a DDS return code instead. - Remove thread-specific memory abstraction. os_threadMemGet and accompanying functions were a mess and their use has been eliminated by other changes in this commit. - Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name collisions and problems with faulty __nonnull__ attributes. Signed-off-by: Jeroen Koekkoek --- docs/dev/modules.md | 201 + src/CMakeLists.txt | 7 +- src/cmake/modules/CUnit.cmake | 2 +- src/core/CMakeLists.txt | 10 +- src/core/ddsc/CMakeLists.txt | 48 +- src/core/ddsc/include/dds/dds.h | 3074 +++++++++++++++ .../include/{ => dds}/ddsc/dds_public_alloc.h | 5 +- .../ddsc/include/dds/ddsc/dds_public_error.h | 51 + .../include/{ => dds}/ddsc/dds_public_impl.h | 7 +- .../{ => dds}/ddsc/dds_public_listener.h | 81 +- .../include/{ => dds}/ddsc/dds_public_qos.h | 395 +- .../{ => dds}/ddsc/dds_public_status.h | 61 +- .../{ => dds}/ddsc/dds_public_stream.h | 6 +- src/core/ddsc/include/ddsc/dds.h | 3303 +---------------- src/core/ddsc/include/ddsc/dds_public_error.h | 155 - src/core/ddsc/include/ddsc/dds_public_time.h | 96 - src/core/ddsc/src/dds__builtin.h | 2 +- src/core/ddsc/src/dds__entity.h | 86 +- src/core/ddsc/src/dds__err.h | 3 +- src/core/ddsc/src/dds__guardcond.h | 4 +- src/core/ddsc/src/dds__init.h | 5 +- src/core/ddsc/src/dds__listener.h | 2 +- src/core/ddsc/src/dds__publisher.h | 2 +- src/core/ddsc/src/dds__qos.h | 10 +- src/core/ddsc/src/dds__readcond.h | 10 +- src/core/ddsc/src/dds__rhc.h | 3 - src/core/ddsc/src/dds__serdata_builtintopic.h | 6 +- src/core/ddsc/src/dds__stream.h | 6 +- src/core/ddsc/src/dds__subscriber.h | 15 +- src/core/ddsc/src/dds__types.h | 22 +- src/core/ddsc/src/dds__whc.h | 2 +- src/core/ddsc/src/dds__whc_builtintopic.h | 2 +- src/core/ddsc/src/dds_alloc.c | 19 +- src/core/ddsc/src/dds_builtin.c | 10 +- src/core/ddsc/src/dds_coherent.c | 94 +- src/core/ddsc/src/dds_domain.c | 10 +- src/core/ddsc/src/dds_entity.c | 165 +- src/core/ddsc/src/dds_err.c | 102 - src/core/ddsc/src/dds_guardcond.c | 26 +- src/core/ddsc/src/dds_init.c | 74 +- src/core/ddsc/src/dds_instance.c | 184 +- src/core/ddsc/src/dds_key.c | 6 +- src/core/ddsc/src/dds_listener.c | 57 +- src/core/ddsc/src/dds_participant.c | 66 +- src/core/ddsc/src/dds_publisher.c | 52 +- src/core/ddsc/src/dds_qos.c | 169 +- src/core/ddsc/src/dds_querycond.c | 16 +- src/core/ddsc/src/dds_read.c | 324 +- src/core/ddsc/src/dds_readcond.c | 29 +- src/core/ddsc/src/dds_reader.c | 136 +- src/core/ddsc/src/dds_rhc.c | 108 +- src/core/ddsc/src/dds_serdata_builtintopic.c | 27 +- src/core/ddsc/src/dds_sertopic_builtintopic.c | 18 +- src/core/ddsc/src/dds_stream.c | 14 +- src/core/ddsc/src/dds_subscriber.c | 43 +- src/core/ddsc/src/dds_time.c | 41 - src/core/ddsc/src/dds_topic.c | 114 +- src/core/ddsc/src/dds_waitset.c | 120 +- src/core/ddsc/src/dds_whc.c | 105 +- src/core/ddsc/src/dds_whc_builtintopic.c | 20 +- src/core/ddsc/src/dds_write.c | 38 +- src/core/ddsc/src/dds_writer.c | 87 +- src/core/ddsc/tests/CMakeLists.txt | 3 +- src/core/ddsc/tests/basic.c | 2 +- src/core/ddsc/tests/builtin_topics.c | 4 +- src/core/ddsc/tests/config.c | 35 +- src/core/ddsc/tests/dispose.c | 80 +- src/core/ddsc/tests/entity_api.c | 6 +- src/core/ddsc/tests/entity_hierarchy.c | 25 +- src/core/ddsc/tests/entity_status.c | 12 +- src/core/ddsc/tests/err.c | 32 - src/core/ddsc/tests/file_id.c | 9 +- src/core/ddsc/tests/instance_get_key.c | 8 +- src/core/ddsc/tests/listener.c | 147 +- src/core/ddsc/tests/participant.c | 34 +- src/core/ddsc/tests/publisher.c | 2 +- src/core/ddsc/tests/qos.c | 14 +- src/core/ddsc/tests/querycondition.c | 20 +- src/core/ddsc/tests/read_instance.c | 15 +- src/core/ddsc/tests/readcondition.c | 17 +- src/core/ddsc/tests/reader.c | 23 +- src/core/ddsc/tests/reader_iterator.c | 14 +- src/core/ddsc/tests/register.c | 16 +- src/core/ddsc/tests/return_loan.c | 3 +- src/core/ddsc/tests/subscriber.c | 2 +- src/core/ddsc/tests/take_instance.c | 14 +- src/core/ddsc/tests/test-common.c | 2 +- src/core/ddsc/tests/time.c | 2 +- src/core/ddsc/tests/topic.c | 30 +- src/core/ddsc/tests/transientlocal.c | 2 +- src/core/ddsc/tests/types.c | 2 +- src/core/ddsc/tests/unregister.c | 12 +- src/core/ddsc/tests/unsupported.c | 2 +- src/core/ddsc/tests/waitset.c | 63 +- src/core/ddsc/tests/write.c | 14 +- src/core/ddsc/tests/writer.c | 13 +- src/core/ddsi/CMakeLists.txt | 10 +- .../ddsi/include/{ => dds}/ddsi/ddsi_iid.h | 11 +- .../ddsi/include/{ => dds}/ddsi/ddsi_ipaddr.h | 8 +- .../include/{ => dds}/ddsi/ddsi_mcgroup.h | 2 +- .../ddsi/include/{ => dds}/ddsi/ddsi_raweth.h | 0 .../include/{ => dds}/ddsi/ddsi_rhc_plugin.h | 0 .../include/{ => dds}/ddsi/ddsi_serdata.h | 19 +- .../{ => dds}/ddsi/ddsi_serdata_default.h | 26 +- .../include/{ => dds}/ddsi/ddsi_sertopic.h | 7 +- .../ddsi/include/{ => dds}/ddsi/ddsi_ssl.h | 0 .../ddsi/include/{ => dds}/ddsi/ddsi_tcp.h | 14 +- .../ddsi/include/{ => dds}/ddsi/ddsi_tkmap.h | 10 +- .../ddsi/include/{ => dds}/ddsi/ddsi_tran.h | 20 +- .../ddsi/include/{ => dds}/ddsi/ddsi_udp.h | 0 .../ddsi/include/{ => dds}/ddsi/ddsi_vendor.h | 0 .../include/{ => dds}/ddsi/probes-constants.h | 0 .../ddsi/include/{ => dds}/ddsi/q_addrset.h | 15 +- .../ddsi/include/{ => dds}/ddsi/q_bitset.h | 2 +- .../ddsi/include/{ => dds}/ddsi/q_bswap.h | 10 +- .../ddsi/include/{ => dds}/ddsi/q_config.h | 30 +- .../include/{ => dds}/ddsi/q_ddsi_discovery.h | 2 +- .../ddsi/include/{ => dds}/ddsi/q_debmon.h | 0 .../ddsi/include/{ => dds}/ddsi/q_entity.h | 48 +- .../ddsi/include/{ => dds}/ddsi/q_ephash.h | 3 +- .../ddsi/include/{ => dds}/ddsi/q_error.h | 0 .../include/{ => dds}/ddsi/q_feature_check.h | 8 +- .../ddsi/include/{ => dds}/ddsi/q_freelist.h | 23 +- src/core/ddsi/include/{ => dds}/ddsi/q_gc.h | 4 +- .../ddsi/include/{ => dds}/ddsi/q_globals.h | 51 +- .../ddsi/include/{ => dds}/ddsi/q_hbcontrol.h | 0 src/core/ddsi/include/{ => dds}/ddsi/q_init.h | 0 .../{ => dds}/ddsi/q_inverse_uint32_set.h | 2 +- .../ddsi/include/{ => dds}/ddsi/q_lat_estim.h | 4 +- .../ddsi/include/{ => dds}/ddsi/q_lease.h | 2 +- src/core/ddsi/include/{ => dds}/ddsi/q_log.h | 37 +- src/core/ddsi/include/{ => dds}/ddsi/q_md5.h | 0 src/core/ddsi/include/{ => dds}/ddsi/q_misc.h | 2 +- src/core/ddsi/include/{ => dds}/ddsi/q_nwif.h | 9 +- src/core/ddsi/include/{ => dds}/ddsi/q_pcap.h | 10 +- .../ddsi/include/{ => dds}/ddsi/q_plist.h | 16 +- .../ddsi/include/{ => dds}/ddsi/q_protocol.h | 18 +- .../ddsi/include/{ => dds}/ddsi/q_qosmatch.h | 0 .../ddsi/include/{ => dds}/ddsi/q_radmin.h | 13 +- .../ddsi/include/{ => dds}/ddsi/q_receive.h | 0 src/core/ddsi/include/{ => dds}/ddsi/q_rtps.h | 3 +- .../ddsi/include/{ => dds}/ddsi/q_security.h | 0 .../include/{ => dds}/ddsi/q_servicelease.h | 0 .../include/{ => dds}/ddsi/q_sockwaitset.h | 6 +- .../include/{ => dds}/ddsi/q_static_assert.h | 0 .../ddsi/include/{ => dds}/ddsi/q_thread.h | 52 +- src/core/ddsi/include/{ => dds}/ddsi/q_time.h | 18 +- .../ddsi/include/{ => dds}/ddsi/q_transmit.h | 3 +- .../ddsi/include/{ => dds}/ddsi/q_unused.h | 0 src/core/ddsi/include/{ => dds}/ddsi/q_whc.h | 4 +- .../ddsi/include/{ => dds}/ddsi/q_xevent.h | 0 src/core/ddsi/include/{ => dds}/ddsi/q_xmsg.h | 7 +- src/core/ddsi/include/{ => dds}/ddsi/q_xqos.h | 36 +- .../ddsi/include/{ => dds}/ddsi/sysdeps.h | 5 +- src/core/ddsi/src/ddsi_eth.c | 11 +- src/core/ddsi/src/ddsi_eth.h | 5 +- src/core/ddsi/src/ddsi_iid.c | 31 +- src/core/ddsi/src/ddsi_ipaddr.c | 79 +- src/core/ddsi/src/ddsi_mcgroup.c | 50 +- src/core/ddsi/src/ddsi_raweth.c | 124 +- src/core/ddsi/src/ddsi_rhc_plugin.c | 6 +- src/core/ddsi/src/ddsi_serdata.c | 17 +- src/core/ddsi/src/ddsi_serdata_default.c | 42 +- src/core/ddsi/src/ddsi_sertopic.c | 28 +- src/core/ddsi/src/ddsi_sertopic_default.c | 13 +- src/core/ddsi/src/ddsi_ssl.c | 108 +- src/core/ddsi/src/ddsi_tcp.c | 430 ++- src/core/ddsi/src/ddsi_tkmap.c | 91 +- src/core/ddsi/src/ddsi_tran.c | 35 +- src/core/ddsi/src/ddsi_udp.c | 218 +- src/core/ddsi/src/ddsi_vendor.c | 2 +- src/core/ddsi/src/q_addrset.c | 67 +- src/core/ddsi/src/q_bitset_inlines.c | 2 +- src/core/ddsi/src/q_bswap.c | 2 +- src/core/ddsi/src/q_bswap_inlines.c | 2 +- src/core/ddsi/src/q_config.c | 222 +- src/core/ddsi/src/q_ddsi_discovery.c | 98 +- src/core/ddsi/src/q_debmon.c | 124 +- src/core/ddsi/src/q_entity.c | 541 +-- src/core/ddsi/src/q_ephash.c | 29 +- src/core/ddsi/src/q_freelist.c | 111 +- src/core/ddsi/src/q_gc.c | 97 +- src/core/ddsi/src/q_init.c | 225 +- src/core/ddsi/src/q_inverse_uint32_set.c | 22 +- src/core/ddsi/src/q_lat_estim.c | 6 +- src/core/ddsi/src/q_lease.c | 87 +- src/core/ddsi/src/q_md5.c | 10 +- src/core/ddsi/src/q_misc.c | 6 +- src/core/ddsi/src/q_nwif.c | 176 +- src/core/ddsi/src/q_pcap.c | 53 +- src/core/ddsi/src/q_plist.c | 777 +--- src/core/ddsi/src/q_qosmatch.c | 8 +- src/core/ddsi/src/q_radmin.c | 212 +- src/core/ddsi/src/q_receive.c | 187 +- src/core/ddsi/src/q_security.c | 74 +- src/core/ddsi/src/q_servicelease.c | 103 +- src/core/ddsi/src/q_sockwaitset.c | 179 +- src/core/ddsi/src/q_thread.c | 193 +- src/core/ddsi/src/q_thread_inlines.c | 16 +- src/core/ddsi/src/q_time.c | 55 +- src/core/ddsi/src/q_transmit.c | 99 +- src/core/ddsi/src/q_whc.c | 7 +- src/core/ddsi/src/q_xevent.c | 219 +- src/core/ddsi/src/q_xmsg.c | 259 +- src/core/ddsi/src/sysdeps.c | 39 +- src/core/xtests/CMakeLists.txt | 2 +- src/core/xtests/rhc_torture.c | 59 +- src/ddsrt/CMakeLists.txt | 210 ++ .../include/dds/ddsrt/arch.h} | 26 +- src/ddsrt/include/dds/ddsrt/atomics.h | 66 + src/ddsrt/include/dds/ddsrt/atomics/arm.h | 213 ++ src/ddsrt/include/dds/ddsrt/atomics/gcc.h | 291 ++ src/ddsrt/include/dds/ddsrt/atomics/msvc.h | 299 ++ src/ddsrt/include/dds/ddsrt/atomics/sun.h | 241 ++ src/ddsrt/include/dds/ddsrt/attributes.h | 104 + src/ddsrt/include/dds/ddsrt/cdtors.h | 24 + src/ddsrt/include/dds/ddsrt/endian.h | 47 + src/ddsrt/include/dds/ddsrt/environ.h | 103 + src/ddsrt/include/dds/ddsrt/heap.h | 155 + .../include/dds/ddsrt/ifaddrs.h} | 37 +- src/ddsrt/include/dds/ddsrt/io.h | 41 + .../include/dds/ddsrt/log.h} | 110 +- src/ddsrt/include/dds/ddsrt/misc.h | 81 + src/ddsrt/include/dds/ddsrt/process.h | 48 + .../include/dds/ddsrt/random.h} | 12 +- src/ddsrt/include/dds/ddsrt/retcode.h | 89 + src/ddsrt/include/dds/ddsrt/rusage.h | 50 + src/ddsrt/include/dds/ddsrt/sockets.h | 262 ++ src/ddsrt/include/dds/ddsrt/sockets/posix.h | 54 + src/ddsrt/include/dds/ddsrt/sockets/windows.h | 52 + src/ddsrt/include/dds/ddsrt/string.h | 198 + src/ddsrt/include/dds/ddsrt/strtod.h | 75 + src/ddsrt/include/dds/ddsrt/strtol.h | 168 + src/ddsrt/include/dds/ddsrt/sync.h | 298 ++ .../include/dds/ddsrt/sync/posix.h} | 29 +- .../include/dds/ddsrt/sync/windows.h} | 28 +- src/ddsrt/include/dds/ddsrt/threads.h | 262 ++ src/ddsrt/include/dds/ddsrt/threads/posix.h | 59 + .../include/dds/ddsrt/threads/windows.h} | 16 +- src/ddsrt/include/dds/ddsrt/time.h | 149 + src/ddsrt/include/dds/ddsrt/types.h | 30 + .../include/dds/ddsrt/types/posix.h} | 16 +- src/ddsrt/include/dds/ddsrt/types/vxworks.h | 74 + src/ddsrt/include/dds/ddsrt/types/windows.h | 27 + src/ddsrt/include/dds/version.h.in | 28 + src/ddsrt/include/getopt.h.in | 24 + src/ddsrt/src/atomics.c | 163 + src/ddsrt/src/cdtors.c | 149 + src/ddsrt/src/environ/posix/environ.c | 88 + src/ddsrt/src/environ/windows/environ.c | 73 + .../os_stdlib_getopt.c => ddsrt/src/getopt.c} | 4 + src/ddsrt/src/heap/posix/heap.c | 91 + .../src/heap/vxworks/heap.c} | 8 +- .../src/os_ifaddrs.c => ddsrt/src/ifaddrs.c} | 25 +- src/ddsrt/src/ifaddrs/posix/ifaddrs.c | 135 + src/ddsrt/src/ifaddrs/windows/ifaddrs.c | 283 ++ src/ddsrt/src/io.c | 72 + src/ddsrt/src/log.c | 302 ++ .../src/os_process.c => ddsrt/src/process.c} | 12 +- .../src/os_random.c => ddsrt/src/random.c} | 26 +- src/ddsrt/src/retcode.c | 60 + src/ddsrt/src/rusage/posix/rusage.c | 101 + .../src/rusage/windows/rusage.c} | 29 +- src/ddsrt/src/sockets.c | 354 ++ .../sockets/include/dds/ddsrt/sockets_priv.h | 82 + src/ddsrt/src/sockets/posix/gethostname.c | 61 + src/ddsrt/src/sockets/posix/socket.c | 530 +++ src/ddsrt/src/sockets/windows/gethostname.c | 42 + src/ddsrt/src/sockets/windows/socket.c | 680 ++++ src/ddsrt/src/string.c | 180 + .../src/string/posix/strerror.c} | 49 +- src/ddsrt/src/string/vxworks/strerror.c | 69 + src/ddsrt/src/string/windows/strerror.c | 71 + src/ddsrt/src/strtod.c | 208 ++ src/ddsrt/src/strtol.c | 276 ++ src/ddsrt/src/sync/posix/sync.c | 236 ++ src/ddsrt/src/sync/windows/sync.c | 214 ++ .../src/threads.c} | 20 +- .../threads/include/dds/ddsrt/threads_priv.h | 30 + src/ddsrt/src/threads/posix/threads.c | 447 +++ src/ddsrt/src/threads/windows/threads.c | 303 ++ src/ddsrt/src/time.c | 74 + src/ddsrt/src/time/darwin/time.c | 58 + .../src/time/include/dds/ddsrt/timeconv.h | 68 + src/ddsrt/src/time/posix/time.c | 41 + src/ddsrt/src/time/windows/time.c | 161 + src/ddsrt/tests/CMakeLists.txt | 43 + src/ddsrt/tests/atomics.c | 393 ++ src/ddsrt/tests/environ.c | 98 + src/ddsrt/tests/heap.c | 156 + src/ddsrt/tests/ifaddrs.c | 187 + src/ddsrt/tests/log.c | 366 ++ src/ddsrt/tests/select.c | 325 ++ src/ddsrt/tests/socket.c | 198 + src/ddsrt/tests/string.c | 101 + src/ddsrt/tests/strlcpy.c | 80 + src/ddsrt/tests/strtoll.c | 343 ++ src/ddsrt/tests/sync.c | 357 ++ src/ddsrt/tests/thread.c | 233 ++ src/ddsrt/tests/thread_cleanup.c | 286 ++ src/docs/CMakeLists.txt | 2 +- .../helloworld_indepth.rst | 4 +- src/examples/helloworld/publisher.c | 89 +- src/examples/helloworld/subscriber.c | 115 +- src/examples/roundtrip/ping.c | 51 +- src/examples/roundtrip/pong.c | 38 +- src/examples/throughput/publisher.c | 55 +- src/examples/throughput/subscriber.c | 38 +- .../eclipse/cyclonedds/templates/h/file.st | 2 +- src/os/CMakeLists.txt | 139 - src/os/cmake/os_project.h.in | 38 - src/os/include/os/darwin/os_platform.h | 48 - src/os/include/os/linux/os_platform.h | 48 - src/os/include/os/os.h | 50 - src/os/include/os/os_atomics.h | 58 - src/os/include/os/os_atomics_gcc.h | 294 -- src/os/include/os/os_atomics_solaris.h | 242 -- src/os/include/os/os_atomics_win32.h | 429 --- src/os/include/os/os_decl_attributes.h | 129 - src/os/include/os/os_decl_attributes_sal.h | 2071 ----------- src/os/include/os/os_defs.h | 213 -- src/os/include/os/os_errno.h | 107 - src/os/include/os/os_heap.h | 167 - src/os/include/os/os_init.h | 22 - src/os/include/os/os_iter.h | 79 - src/os/include/os/os_platform_public.h | 29 - src/os/include/os/os_process.h | 41 - src/os/include/os/os_public.h | 19 - src/os/include/os/os_rusage.h | 35 - src/os/include/os/os_socket.h | 349 -- src/os/include/os/os_stdlib.h | 595 --- src/os/include/os/os_strlcpy.h | 72 - src/os/include/os/os_sync.h | 371 -- src/os/include/os/os_thread.h | 260 -- src/os/include/os/os_time.h | 276 -- src/os/include/os/posix/os_platform_socket.h | 93 - src/os/include/os/posix/os_platform_stdlib.h | 12 - src/os/include/os/posix/os_platform_sync.h | 47 - src/os/include/os/solaris/os_platform.h | 48 - src/os/include/os/vxworks/os_platform.h | 135 - src/os/include/os/windows/os_platform.h | 55 - .../include/os/windows/os_platform_socket.h | 102 - .../include/os/windows/os_platform_stdlib.h | 46 - src/os/src/os_atomics.c | 164 - src/os/src/os_dns.c | 146 - src/os/src/os_errno.c | 134 - src/os/src/os_init.c | 75 - src/os/src/os_iter.c | 229 -- src/os/src/os_log.c | 299 -- src/os/src/os_socket.c | 271 -- src/os/src/os_strlcpy.c | 80 - src/os/src/os_thread.c | 45 - src/os/src/os_time.c | 355 -- src/os/src/posix/os_platform_errno.c | 12 - src/os/src/posix/os_platform_heap.c | 19 - src/os/src/posix/os_platform_ifaddrs.c | 119 - src/os/src/posix/os_platform_init.c | 57 - src/os/src/posix/os_platform_rusage.c | 93 - src/os/src/posix/os_platform_socket.c | 232 -- src/os/src/posix/os_platform_stdlib.c | 22 - src/os/src/posix/os_platform_sync.c | 368 -- src/os/src/posix/os_platform_thread.c | 12 - src/os/src/posix/os_platform_time.c | 149 - src/os/src/snippets/code/os_gethostname.c | 36 - src/os/src/snippets/code/os_heap.c | 143 - src/os/src/snippets/code/os_posix_thread.c | 512 --- src/os/src/snippets/code/os_stdlib.c | 99 - src/os/src/snippets/code/os_stdlib_asprintf.c | 48 - src/os/src/snippets/code/os_stdlib_bsearch.c | 17 - src/os/src/snippets/code/os_stdlib_rindex.c | 28 - .../src/snippets/code/os_stdlib_strcasecmp.c | 34 - src/os/src/snippets/code/os_stdlib_strdup.c | 23 - .../src/snippets/code/os_stdlib_strncasecmp.c | 35 - src/os/src/snippets/code/os_stdlib_strsep.c | 28 - src/os/src/snippets/code/os_stdlib_strtod.c | 187 - src/os/src/snippets/code/os_stdlib_strtok_r.c | 70 - src/os/src/snippets/code/os_stdlib_strtol.c | 266 -- src/os/src/snippets/include/os_posix_stdlib.h | 45 - src/os/src/vxworks/os_platform_errno.c | 87 - src/os/src/vxworks/os_platform_init.c | 129 - src/os/src/vxworks/os_platform_socket.c | 12 - src/os/src/vxworks/os_platform_stdlib.c | 50 - src/os/src/vxworks/os_platform_sync.c | 12 - src/os/src/vxworks/os_platform_thread.c | 12 - src/os/src/vxworks/os_platform_time.c | 12 - src/os/src/windows/os_platform_errno.c | 96 - src/os/src/windows/os_platform_heap.c | 19 - src/os/src/windows/os_platform_ifaddrs.c | 272 -- src/os/src/windows/os_platform_init.c | 69 - src/os/src/windows/os_platform_socket.c | 599 --- src/os/src/windows/os_platform_stdlib.c | 197 - src/os/src/windows/os_platform_sync.c | 221 -- src/os/src/windows/os_platform_thread.c | 580 --- src/os/src/windows/os_platform_time.c | 210 -- src/os/tests/CMakeLists.txt | 34 - src/os/tests/atomics.c | 467 --- src/os/tests/error_no.c | 67 - src/os/tests/heap.c | 197 - src/os/tests/ifaddrs.c | 192 - src/os/tests/iter.c | 239 -- src/os/tests/log.c | 362 -- src/os/tests/mutex.c | 300 -- src/os/tests/once.c | 167 - src/os/tests/rwlock.c | 576 --- src/os/tests/socket.c | 167 - src/os/tests/stdlib.c | 230 -- src/os/tests/strcasecmp.c | 56 - src/os/tests/strlcpy.c | 80 - src/os/tests/strtoll.c | 321 -- src/os/tests/thread.c | 698 ---- src/os/tests/thread_cleanup.c | 283 -- src/tools/ddsls/CMakeLists.txt | 5 +- src/tools/ddsls/ddsls.c | 23 +- src/tools/pubsub/CMakeLists.txt | 2 +- src/tools/pubsub/common.c | 45 +- src/tools/pubsub/common.h | 22 +- src/tools/pubsub/pubsub.c | 207 +- src/tools/pubsub/testtype.h | 4 +- src/util/CMakeLists.txt | 27 +- src/util/include/dds/util/ut_avl.h | 359 ++ src/util/include/{ => dds}/util/ut_crc.h | 11 +- .../{ => dds}/util/ut_expand_envvars.h | 7 +- src/util/include/{ => dds}/util/ut_fibheap.h | 21 +- .../include/{ => dds}/util/ut_handleserver.h | 75 +- src/util/include/dds/util/ut_hopscotch.h | 110 + .../include/{ => dds}/util/ut_thread_pool.h | 21 +- .../include/{ => dds}/util/ut_xmlparser.h | 15 +- src/util/include/util/ut_avl.h | 356 -- src/util/include/util/ut_hopscotch.h | 109 - src/util/src/ut_avl.c | 169 +- src/util/src/ut_crc.c | 3 +- src/util/src/ut_expand_envvars.c | 58 +- src/util/src/ut_fibheap.c | 5 +- src/util/src/ut_handleserver.c | 166 +- src/util/src/ut_hopscotch.c | 231 +- src/util/src/ut_thread_pool.c | 98 +- src/util/src/ut_xmlparser.c | 86 +- src/util/tests/CMakeLists.txt | 18 +- src/util/tests/handleserver.c | 68 +- 439 files changed, 22117 insertions(+), 28782 deletions(-) create mode 100644 docs/dev/modules.md create mode 100644 src/core/ddsc/include/dds/dds.h rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_alloc.h (97%) create mode 100644 src/core/ddsc/include/dds/ddsc/dds_public_error.h rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_impl.h (97%) rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_listener.h (70%) rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_qos.h (73%) rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_status.h (88%) rename src/core/ddsc/include/{ => dds}/ddsc/dds_public_stream.h (98%) delete mode 100644 src/core/ddsc/include/ddsc/dds_public_error.h delete mode 100644 src/core/ddsc/include/ddsc/dds_public_time.h delete mode 100644 src/core/ddsc/src/dds_err.c delete mode 100644 src/core/ddsc/src/dds_time.c delete mode 100644 src/core/ddsc/tests/err.c rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_iid.h (82%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_ipaddr.h (75%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_mcgroup.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_raweth.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_rhc_plugin.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_serdata.h (94%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_serdata_default.h (86%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_sertopic.h (94%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_ssl.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_tcp.h (66%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_tkmap.h (78%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_tran.h (94%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_udp.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/ddsi_vendor.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/probes-constants.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_addrset.h (93%) rename src/core/ddsi/include/{ => dds}/ddsi/q_bitset.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_bswap.h (91%) rename src/core/ddsi/include/{ => dds}/ddsi/q_config.h (95%) rename src/core/ddsi/include/{ => dds}/ddsi/q_ddsi_discovery.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_debmon.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_entity.h (95%) rename src/core/ddsi/include/{ => dds}/ddsi/q_ephash.h (99%) rename src/core/ddsi/include/{ => dds}/ddsi/q_error.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_feature_check.h (91%) rename src/core/ddsi/include/{ => dds}/ddsi/q_freelist.h (63%) rename src/core/ddsi/include/{ => dds}/ddsi/q_gc.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_globals.h (91%) rename src/core/ddsi/include/{ => dds}/ddsi/q_hbcontrol.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_init.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_inverse_uint32_set.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_lat_estim.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_lease.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_log.h (73%) rename src/core/ddsi/include/{ => dds}/ddsi/q_md5.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_misc.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_nwif.h (79%) rename src/core/ddsi/include/{ => dds}/ddsi/q_pcap.h (82%) rename src/core/ddsi/include/{ => dds}/ddsi/q_plist.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_protocol.h (98%) rename src/core/ddsi/include/{ => dds}/ddsi/q_qosmatch.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_radmin.h (97%) rename src/core/ddsi/include/{ => dds}/ddsi/q_receive.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_rtps.h (98%) rename src/core/ddsi/include/{ => dds}/ddsi/q_security.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_servicelease.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_sockwaitset.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_static_assert.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_thread.h (75%) rename src/core/ddsi/include/{ => dds}/ddsi/q_time.h (75%) rename src/core/ddsi/include/{ => dds}/ddsi/q_transmit.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_unused.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_whc.h (98%) rename src/core/ddsi/include/{ => dds}/ddsi/q_xevent.h (100%) rename src/core/ddsi/include/{ => dds}/ddsi/q_xmsg.h (96%) rename src/core/ddsi/include/{ => dds}/ddsi/q_xqos.h (94%) rename src/core/ddsi/include/{ => dds}/ddsi/sysdeps.h (88%) create mode 100644 src/ddsrt/CMakeLists.txt rename src/{os/include/os/posix/os_platform_public.h => ddsrt/include/dds/ddsrt/arch.h} (64%) create mode 100644 src/ddsrt/include/dds/ddsrt/atomics.h create mode 100644 src/ddsrt/include/dds/ddsrt/atomics/arm.h create mode 100644 src/ddsrt/include/dds/ddsrt/atomics/gcc.h create mode 100644 src/ddsrt/include/dds/ddsrt/atomics/msvc.h create mode 100644 src/ddsrt/include/dds/ddsrt/atomics/sun.h create mode 100644 src/ddsrt/include/dds/ddsrt/attributes.h create mode 100644 src/ddsrt/include/dds/ddsrt/cdtors.h create mode 100644 src/ddsrt/include/dds/ddsrt/endian.h create mode 100644 src/ddsrt/include/dds/ddsrt/environ.h create mode 100644 src/ddsrt/include/dds/ddsrt/heap.h rename src/{os/include/os/windows/os_platform_sync.h => ddsrt/include/dds/ddsrt/ifaddrs.h} (51%) create mode 100644 src/ddsrt/include/dds/ddsrt/io.h rename src/{os/include/os/os_log.h => ddsrt/include/dds/ddsrt/log.h} (69%) create mode 100644 src/ddsrt/include/dds/ddsrt/misc.h create mode 100644 src/ddsrt/include/dds/ddsrt/process.h rename src/{os/include/os/windows/os_platform_time.h => ddsrt/include/dds/ddsrt/random.h} (79%) create mode 100644 src/ddsrt/include/dds/ddsrt/retcode.h create mode 100644 src/ddsrt/include/dds/ddsrt/rusage.h create mode 100644 src/ddsrt/include/dds/ddsrt/sockets.h create mode 100644 src/ddsrt/include/dds/ddsrt/sockets/posix.h create mode 100644 src/ddsrt/include/dds/ddsrt/sockets/windows.h create mode 100644 src/ddsrt/include/dds/ddsrt/string.h create mode 100644 src/ddsrt/include/dds/ddsrt/strtod.h create mode 100644 src/ddsrt/include/dds/ddsrt/strtol.h create mode 100644 src/ddsrt/include/dds/ddsrt/sync.h rename src/{os/include/os/posix/os_platform_thread.h => ddsrt/include/dds/ddsrt/sync/posix.h} (57%) rename src/{os/include/os/windows/os_platform_thread.h => ddsrt/include/dds/ddsrt/sync/windows.h} (56%) create mode 100644 src/ddsrt/include/dds/ddsrt/threads.h create mode 100644 src/ddsrt/include/dds/ddsrt/threads/posix.h rename src/{os/include/os/os_random.h => ddsrt/include/dds/ddsrt/threads/windows.h} (68%) create mode 100644 src/ddsrt/include/dds/ddsrt/time.h create mode 100644 src/ddsrt/include/dds/ddsrt/types.h rename src/{os/include/os/windows/os_platform_public.h => ddsrt/include/dds/ddsrt/types/posix.h} (74%) create mode 100644 src/ddsrt/include/dds/ddsrt/types/vxworks.h create mode 100644 src/ddsrt/include/dds/ddsrt/types/windows.h create mode 100644 src/ddsrt/include/dds/version.h.in create mode 100644 src/ddsrt/include/getopt.h.in create mode 100644 src/ddsrt/src/atomics.c create mode 100644 src/ddsrt/src/cdtors.c create mode 100644 src/ddsrt/src/environ/posix/environ.c create mode 100644 src/ddsrt/src/environ/windows/environ.c rename src/{os/src/snippets/code/os_stdlib_getopt.c => ddsrt/src/getopt.c} (97%) create mode 100644 src/ddsrt/src/heap/posix/heap.c rename src/{os/src/vxworks/os_platform_heap.c => ddsrt/src/heap/vxworks/heap.c} (97%) rename src/{os/src/os_ifaddrs.c => ddsrt/src/ifaddrs.c} (57%) create mode 100644 src/ddsrt/src/ifaddrs/posix/ifaddrs.c create mode 100644 src/ddsrt/src/ifaddrs/windows/ifaddrs.c create mode 100644 src/ddsrt/src/io.c create mode 100644 src/ddsrt/src/log.c rename src/{os/src/os_process.c => ddsrt/src/process.c} (81%) rename src/{os/src/os_random.c => ddsrt/src/random.c} (60%) create mode 100644 src/ddsrt/src/retcode.c create mode 100644 src/ddsrt/src/rusage/posix/rusage.c rename src/{os/src/windows/os_platform_rusage.c => ddsrt/src/rusage/windows/rusage.c} (63%) create mode 100644 src/ddsrt/src/sockets.c create mode 100644 src/ddsrt/src/sockets/include/dds/ddsrt/sockets_priv.h create mode 100644 src/ddsrt/src/sockets/posix/gethostname.c create mode 100644 src/ddsrt/src/sockets/posix/socket.c create mode 100644 src/ddsrt/src/sockets/windows/gethostname.c create mode 100644 src/ddsrt/src/sockets/windows/socket.c create mode 100644 src/ddsrt/src/string.c rename src/{os/src/snippets/code/os_posix_errno.c => ddsrt/src/string/posix/strerror.c} (55%) create mode 100644 src/ddsrt/src/string/vxworks/strerror.c create mode 100644 src/ddsrt/src/string/windows/strerror.c create mode 100644 src/ddsrt/src/strtod.c create mode 100644 src/ddsrt/src/strtol.c create mode 100644 src/ddsrt/src/sync/posix/sync.c create mode 100644 src/ddsrt/src/sync/windows/sync.c rename src/{os/src/snippets/code/os_stdlib_memdup.c => ddsrt/src/threads.c} (65%) create mode 100644 src/ddsrt/src/threads/include/dds/ddsrt/threads_priv.h create mode 100644 src/ddsrt/src/threads/posix/threads.c create mode 100644 src/ddsrt/src/threads/windows/threads.c create mode 100644 src/ddsrt/src/time.c create mode 100644 src/ddsrt/src/time/darwin/time.c create mode 100644 src/ddsrt/src/time/include/dds/ddsrt/timeconv.h create mode 100644 src/ddsrt/src/time/posix/time.c create mode 100644 src/ddsrt/src/time/windows/time.c create mode 100644 src/ddsrt/tests/CMakeLists.txt create mode 100644 src/ddsrt/tests/atomics.c create mode 100644 src/ddsrt/tests/environ.c create mode 100644 src/ddsrt/tests/heap.c create mode 100644 src/ddsrt/tests/ifaddrs.c create mode 100644 src/ddsrt/tests/log.c create mode 100644 src/ddsrt/tests/select.c create mode 100644 src/ddsrt/tests/socket.c create mode 100644 src/ddsrt/tests/string.c create mode 100644 src/ddsrt/tests/strlcpy.c create mode 100644 src/ddsrt/tests/strtoll.c create mode 100644 src/ddsrt/tests/sync.c create mode 100644 src/ddsrt/tests/thread.c create mode 100644 src/ddsrt/tests/thread_cleanup.c delete mode 100644 src/os/CMakeLists.txt delete mode 100644 src/os/cmake/os_project.h.in delete mode 100644 src/os/include/os/darwin/os_platform.h delete mode 100644 src/os/include/os/linux/os_platform.h delete mode 100644 src/os/include/os/os.h delete mode 100644 src/os/include/os/os_atomics.h delete mode 100644 src/os/include/os/os_atomics_gcc.h delete mode 100644 src/os/include/os/os_atomics_solaris.h delete mode 100644 src/os/include/os/os_atomics_win32.h delete mode 100644 src/os/include/os/os_decl_attributes.h delete mode 100644 src/os/include/os/os_decl_attributes_sal.h delete mode 100644 src/os/include/os/os_defs.h delete mode 100644 src/os/include/os/os_errno.h delete mode 100644 src/os/include/os/os_heap.h delete mode 100644 src/os/include/os/os_init.h delete mode 100644 src/os/include/os/os_iter.h delete mode 100644 src/os/include/os/os_platform_public.h delete mode 100644 src/os/include/os/os_process.h delete mode 100644 src/os/include/os/os_public.h delete mode 100644 src/os/include/os/os_rusage.h delete mode 100644 src/os/include/os/os_socket.h delete mode 100644 src/os/include/os/os_stdlib.h delete mode 100644 src/os/include/os/os_strlcpy.h delete mode 100644 src/os/include/os/os_sync.h delete mode 100644 src/os/include/os/os_thread.h delete mode 100644 src/os/include/os/os_time.h delete mode 100644 src/os/include/os/posix/os_platform_socket.h delete mode 100644 src/os/include/os/posix/os_platform_stdlib.h delete mode 100644 src/os/include/os/posix/os_platform_sync.h delete mode 100644 src/os/include/os/solaris/os_platform.h delete mode 100644 src/os/include/os/vxworks/os_platform.h delete mode 100644 src/os/include/os/windows/os_platform.h delete mode 100644 src/os/include/os/windows/os_platform_socket.h delete mode 100644 src/os/include/os/windows/os_platform_stdlib.h delete mode 100644 src/os/src/os_atomics.c delete mode 100644 src/os/src/os_dns.c delete mode 100644 src/os/src/os_errno.c delete mode 100644 src/os/src/os_init.c delete mode 100644 src/os/src/os_iter.c delete mode 100644 src/os/src/os_log.c delete mode 100644 src/os/src/os_socket.c delete mode 100644 src/os/src/os_strlcpy.c delete mode 100644 src/os/src/os_thread.c delete mode 100644 src/os/src/os_time.c delete mode 100644 src/os/src/posix/os_platform_errno.c delete mode 100644 src/os/src/posix/os_platform_heap.c delete mode 100644 src/os/src/posix/os_platform_ifaddrs.c delete mode 100644 src/os/src/posix/os_platform_init.c delete mode 100644 src/os/src/posix/os_platform_rusage.c delete mode 100644 src/os/src/posix/os_platform_socket.c delete mode 100644 src/os/src/posix/os_platform_stdlib.c delete mode 100644 src/os/src/posix/os_platform_sync.c delete mode 100644 src/os/src/posix/os_platform_thread.c delete mode 100644 src/os/src/posix/os_platform_time.c delete mode 100644 src/os/src/snippets/code/os_gethostname.c delete mode 100644 src/os/src/snippets/code/os_heap.c delete mode 100644 src/os/src/snippets/code/os_posix_thread.c delete mode 100644 src/os/src/snippets/code/os_stdlib.c delete mode 100644 src/os/src/snippets/code/os_stdlib_asprintf.c delete mode 100644 src/os/src/snippets/code/os_stdlib_bsearch.c delete mode 100644 src/os/src/snippets/code/os_stdlib_rindex.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strcasecmp.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strdup.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strncasecmp.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strsep.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strtod.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strtok_r.c delete mode 100644 src/os/src/snippets/code/os_stdlib_strtol.c delete mode 100644 src/os/src/snippets/include/os_posix_stdlib.h delete mode 100644 src/os/src/vxworks/os_platform_errno.c delete mode 100644 src/os/src/vxworks/os_platform_init.c delete mode 100644 src/os/src/vxworks/os_platform_socket.c delete mode 100644 src/os/src/vxworks/os_platform_stdlib.c delete mode 100644 src/os/src/vxworks/os_platform_sync.c delete mode 100644 src/os/src/vxworks/os_platform_thread.c delete mode 100644 src/os/src/vxworks/os_platform_time.c delete mode 100644 src/os/src/windows/os_platform_errno.c delete mode 100644 src/os/src/windows/os_platform_heap.c delete mode 100644 src/os/src/windows/os_platform_ifaddrs.c delete mode 100644 src/os/src/windows/os_platform_init.c delete mode 100644 src/os/src/windows/os_platform_socket.c delete mode 100644 src/os/src/windows/os_platform_stdlib.c delete mode 100644 src/os/src/windows/os_platform_sync.c delete mode 100644 src/os/src/windows/os_platform_thread.c delete mode 100644 src/os/src/windows/os_platform_time.c delete mode 100644 src/os/tests/CMakeLists.txt delete mode 100644 src/os/tests/atomics.c delete mode 100644 src/os/tests/error_no.c delete mode 100644 src/os/tests/heap.c delete mode 100644 src/os/tests/ifaddrs.c delete mode 100644 src/os/tests/iter.c delete mode 100644 src/os/tests/log.c delete mode 100644 src/os/tests/mutex.c delete mode 100644 src/os/tests/once.c delete mode 100644 src/os/tests/rwlock.c delete mode 100644 src/os/tests/socket.c delete mode 100644 src/os/tests/stdlib.c delete mode 100644 src/os/tests/strcasecmp.c delete mode 100644 src/os/tests/strlcpy.c delete mode 100644 src/os/tests/strtoll.c delete mode 100644 src/os/tests/thread.c delete mode 100644 src/os/tests/thread_cleanup.c create mode 100644 src/util/include/dds/util/ut_avl.h rename src/util/include/{ => dds}/util/ut_crc.h (72%) rename src/util/include/{ => dds}/util/ut_expand_envvars.h (81%) rename src/util/include/{ => dds}/util/ut_fibheap.h (54%) rename src/util/include/{ => dds}/util/ut_handleserver.h (79%) create mode 100644 src/util/include/dds/util/ut_hopscotch.h rename src/util/include/{ => dds}/util/ut_thread_pool.h (78%) rename src/util/include/{ => dds}/util/ut_xmlparser.h (73%) delete mode 100644 src/util/include/util/ut_avl.h delete mode 100644 src/util/include/util/ut_hopscotch.h diff --git a/docs/dev/modules.md b/docs/dev/modules.md new file mode 100644 index 0000000..721c7a7 --- /dev/null +++ b/docs/dev/modules.md @@ -0,0 +1,201 @@ +# Eclipse Cyclone DDS Module Layout + +Cyclone DDS is made up of multiple modules, each of which provides a certain +set of functionality, either private, public or a combination therof. Since +Cyclone DDS is a middleware product, the api is of course the most visible +interface. Cyclone DDS uses the *dds* (not followed by an underscore) prefix +to avoid name collisions with other code. + +The fact that Cyclone DDS is made up of multiple modules is largely historic, +but does offer a neat way to separate features logically. + + |-------------| + | | DDS is not a target, it is the product, the sum of the + | DDS | targets that together form Cyclone DDS. i.e. the stable + | | api prefixed with dds\_ and the libddsc.so library. + |---|---------| + | | | ddsc implements most of dds\_ api. A modern, + | | ddsc | user-friendly implementation of the DDS specification. + | | | + | |---------| + | | | ddsi, as the name suggests, is an implementation of the + | | ddsi | RTPS-DDSI specification. + | | | + | |---------| + | | | util is a collection of snippets that do not require + | | util | per-target implementations and may be used by the ddsc + | | | and ddsi targets. util will be merged into ddsrt. + | |---------| + | | ddsrt offers target agnostic implementations of + | ddsrt | functionality required by the ddsc and ddsi targets, but + | | also exports a subset of the dds\_ api directly. e.g. + |-------------| dds_time_t and functions to read the current time from + the target are implemented here. + +> The need for a separate utility module (util) has disappeared with the +> restructuring of the runtime module. The two will be merged in the not too +> distant future. + +All modules are exported seperately, for convenience. e.g. the *ddsrt* module +offers target agnostic interfaces to create and manage threads and +synchronization primitives, retrieve resource usage, system time, etc. +However, all symbols not referenced by including *dds.h* or prefixed with +*dds_* are considered internal and there are no guarantees with regard to api +stability and backwards compatibility. That being said, they are not expected +to change frequently. Module specific headers are located in the respective +directory under `INSTALL_PREFIX/include/dds`. + + +## DDS Runtime (ddsrt) +The main purpose of the runtime module is to allow modules stacked on top of +it, e.g. ddsi and dds, to be target agnostic. Meaning that, it ensures that +features required by other modules can be used in the same way across supported +targets. The runtime module will NOT try to mimic or stub features that it can +simply cannot offer on a given target. For features that cannot be implemented +on all targets, a feature macro will be introduced that other modules can use +to test for availability. e.g. *DDSRT_HAVE_IPV6* can be used to determine if +the target supports IPv6 addresses. + + +### Feature discovery +Discovery of target features at compile time is lagely dynamic. Various target +specific predefined macros determine if a feature is supported and which +implementation is built. This is on purpose, to avoid a target specific +include directory and an abundance of configuration header files and works +well for most use cases. Of course, there are exceptions where the preprocessor +requires some hints to make the right the descision. e.g. when the lwIP TCP/IP +stack should be used as opposed to the native stack. The build system is +responsible for the availability of the proper macros at compile time. + +Feature implementations are often tied directly to the operating system for +general purpose operating systems. This level of abstraction is not good +enough for embedded targets though. Whether a feature is available or not +depends on (a combination) of the following. + +1. Operating system. e.g. Linux, Windows, FreeRTOS. +2. Compiler. e.g. GCC, Clang, MSVC, IAR. +3. Architecture. e.g. i386, amd64, ARM. +4. C library. e.g. glibc (GNU), dlib (IAR). + +#### Atomic operations +Support for atomic operations is determined by the target architecture. Most +compilers (at least GCC, Clang, Microsoft Visual Studio and Solaris Studio) +offer atomic builtins, but if support is unavailable, fall back on the +target architecture specific implementation. + +#### Network stack +General purpose operating systems like Microsoft Windows and Linux come with +a network stack, as does VxWorks. FreeRTOS, however, does not and requires a +seperate TCP/IP stack, which is often part of the Board Support Package (BSP). +But separate stacks can be used on Microsoft Windows and Linux too. e.g. the +network stack in Tizen RT is based on lwIP, but the platform uses the Linux +kernel. Wheter or not lwIP must be used cannot be determined automatically and +the build system must hint which implementation is to be used. + + +### Structure +The runtime module uses a very specific directory structure to allow for +feature-based implementations and sane fallback defaults. + +#### Header files +The include directory must provide a header file per feature. e.g. +`dds/ddsrt/sync.h` is used for synchronisation primitives. If there are +only minor differences between targets, everything is contained within +that file. If not, as is the case with `dds/ddsrt/types.h`, a header file per +target is a better choice. + +Private headers may also be required to share type definitions between target +implementations that do not need to be public. These are located in a feature +specific include directory with the sources. + + ddsrt + |- include + | \- dds + | \- ddsrt + | |- atomics + | | |- arm.h + | | |- gcc.h + | | |- msvc.h + | | \- sun.h + | |- atomics.h + | |- time.h + | |- threads + | | |- posix.h + | | \- windows.h + | \- threads.h + | + \- src + \- threads + \- include + \- dds + \- ddsrt + \- threads_priv.h + +> Which target specific header file is included is determined by the top-level +> header file, not the build system. However, which files are exported +> automatically is determined by the build system. + +#### Source files +Source files are grouped per feature too, but here the build system determines +what is compiled and what is not. By default the build system looks for a +directory with the system name, e.g. windows or linux, but it is possible to +overwrite it from a feature test. This allows for a non-default target to be +used as would be the case with e.g. lwip for sockets. If a target-specific +implementation cannot be found, the build system will fall back to posix. All +files with a .c extension under the selected directory will be compiled. Code +that can be shared among targets can be put in a file named after the feature +with the .c extension. Of course if there is no target-specific code, or if +there are only minimal differences there is not need to create a feature +directory. + + ddsrt + \- src + |- atomics.c + |- sockets + | |- posix + | | |- gethostname.c + | | \- sockets.c + | \- windows + | |- gethostname.c + | \- sockets.c + \- sockets.c + +### Development guidelines +* Be pragmatic. Use ifdefs (only) where it makes sense. Do not ifdef if target + implementations are completely different. Add a seperate implementation. If + there are only minor differences, as is typically the case between unices, + use an ifdef. +* Header and source files are not prefixed. Instead they reside in a directory + named after the module that serves as a namespace. e.g. the threads feature + interface is defined in `dds/ddsrt/threads.h`. +* Macros that influence which implementation is used, must be prefixed by + *DDSRT_USE_* followed by the feature name. e.g. *DDSRT_USE_LWIP* to indicate + the lwIP TCP/IP stack must be used. Macros that are defined at compile time + to indicate whether or not a certain feature is available, must be prefixed + by *DDSR_HAVE_* followed by the feature name. e.g. *DDSRT_HAVE_IPV6* to + indicate the target supports IPv6 addresses. + +### Constructors and destructors +The runtime module (on some targets) requires initialization. For that reason, +`void ddsrt_init(void)` and `void ddsrt_fini(void)` are exported. They are +called automatically when the library is loaded if the target supports it, but +even if the target does not, the application should not need to invoke the +functions as they are called by `dds_init` and `dds_fini` respectively. + +Of course, if the runtime module is used by itself, and the target does not +support constructors and/or destructors, the application is required to call +the functions before any of the features from the runtime module are used. + +> `ddsrt_init` and `ddsrt_fini` are idempotent. Meaning that, it is safe to +> call `ddsrt_init` more than once. However, initialization is reference +> counted and the number of calls to `ddsrt_init` must match the number of +> calls to `ddsrt_fini`. + +#### Threads +Threads require initialization and finalization if not created by the runtime +module. `void ddsrt_thread_init(void)` and `void ddsrt_thread_fini(void)` are +provided for that purpose. Initialization is always automatic, finalization is +automatic if the target supports it. Finalization is primarily used to release +thread-specific memory and call routines registered by +`ddsrt_thread_cleanup_push`. + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab49099..a71eb86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,9 +147,8 @@ if(NOT USE_SANITIZER) endif() if(NOT (${USE_SANITIZER} STREQUAL "none")) message(STATUS "Sanitizer set to ${USE_SANITIZER}") - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}") - set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}") + add_compile_options(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) + link_libraries(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) endif() include(FileIDs) @@ -172,7 +171,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") add_subdirectory(idlc) -add_subdirectory(os) +add_subdirectory(ddsrt) add_subdirectory(etc) add_subdirectory(util) add_subdirectory(core) diff --git a/src/cmake/modules/CUnit.cmake b/src/cmake/modules/CUnit.cmake index cd766c3..ac63690 100644 --- a/src/cmake/modules/CUnit.cmake +++ b/src/cmake/modules/CUnit.cmake @@ -305,7 +305,7 @@ function(add_cunit_executable TARGET) add_executable( ${TARGET} "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.c" ${sources}) - target_link_libraries(${TARGET} CUnit) + target_link_libraries(${TARGET} PRIVATE CUnit) target_include_directories(${TARGET} PRIVATE "${CUNIT_DIR}/include") endfunction() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 89abc81..6eb4a82 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -51,17 +51,13 @@ include(ddsi/CMakeLists.txt) include(ddsc/CMakeLists.txt) target_link_libraries(ddsc PRIVATE util) -target_link_libraries(ddsc PRIVATE OSAPI) +target_link_libraries(ddsc PRIVATE ddsrt) +target_include_directories( + ddsc PUBLIC $>) # SOVERSION should increase on incompatible ABI change set_target_properties(ddsc PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) -get_target_property(os_api_src_dir OSAPI SOURCE_DIR) -# We need to expose some of the OS headers as well. -target_include_directories(ddsc - PUBLIC - "$") - set_target_file_ids(ddsc) # Create a pseudo-target that other targets (i.e. examples, tests) can depend diff --git a/src/core/ddsc/CMakeLists.txt b/src/core/ddsc/CMakeLists.txt index 919c2c7..5b3658e 100644 --- a/src/core/ddsc/CMakeLists.txt +++ b/src/core/ddsc/CMakeLists.txt @@ -19,7 +19,6 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src" dds_init.c dds_publisher.c dds_rhc.c - dds_time.c dds_domain.c dds_instance.c dds_qos.c @@ -27,7 +26,6 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src" dds_key.c dds_querycond.c dds_topic.c - dds_err.c dds_listener.c dds_read.c dds_stream.c @@ -41,16 +39,15 @@ PREPEND(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src" dds_serdata_builtintopic.c dds_sertopic_builtintopic.c ) - -PREPEND(hdrs_public_ddsc "$$" + +PREPEND(hdrs_public_ddsc "$$" dds.h - dds_public_error.h - dds_public_impl.h - dds_public_listener.h - dds_public_qos.h - dds_public_status.h - dds_public_stream.h - dds_public_time.h + ddsc/dds_public_error.h + ddsc/dds_public_impl.h + ddsc/dds_public_listener.h + ddsc/dds_public_qos.h + ddsc/dds_public_status.h + ddsc/dds_public_stream.h ) PREPEND(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src" @@ -80,32 +77,24 @@ PREPEND(hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src" dds__serdata_builtintopic.h ) -configure_file( - "${CMAKE_CURRENT_LIST_DIR}/cmake/ddsc_project.h.in" - "include/ddsc/ddsc_project.h") - generate_export_header( ddsc BASE_NAME DDS - EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/ddsc/dds_export.h" + EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h" ) -target_include_directories(ddsc - PUBLIC - "$") - -target_include_directories(ddsc - PUBLIC - "$") +target_include_directories( + ddsc PUBLIC + "$" + "$") target_sources(ddsc PRIVATE ${srcs_ddsc} ${hdrs_private_ddsc} - "include/ddsc/ddsc_project.h" PUBLIC ${hdrs_public_ddsc} - "$$/ddsc/dds_export.h" + "$$/dds/export.h" ) target_include_directories(ddsc @@ -116,14 +105,19 @@ target_include_directories(ddsc target_include_directories(ddsc INTERFACE $) +install( + DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/dds" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT dev) + install( DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/ddsc" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT dev) install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/include/ddsc/dds_export.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ddsc" + FILES "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dds" COMPONENT dev) # TODO: improve test inclusion. diff --git a/src/core/ddsc/include/dds/dds.h b/src/core/ddsc/include/dds/dds.h new file mode 100644 index 0000000..124a2e6 --- /dev/null +++ b/src/core/ddsc/include/dds/dds.h @@ -0,0 +1,3074 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDS_H +#define DDS_H + +#include +#include + +/** @file + * + * @brief Eclipse Cyclone DDS C header + */ + +#if defined (__cplusplus) +#define restrict +#endif + +#include "dds/export.h" + +/* TODO: Move to appropriate location */ +/** + * Return code indicating success (DDS_RETCODE_OK) or failure. If a given + * operation failed the value will be a unique error code and dds_err_nr() must + * be used to extract the DDS_RETCODE_* value. + */ +typedef int32_t dds_return_t; +/** + * Handle to an entity. A valid entity handle will always have a positive + * integer value. Should the value be negative, the value represents a unique + * error code. dds_err_nr() can be used to extract the DDS_RETCODE_* value. + */ +typedef int32_t dds_entity_t; + +/* Sub components */ + +#include "dds/ddsrt/time.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsc/dds_public_stream.h" +#include "dds/ddsc/dds_public_impl.h" +#include "dds/ddsc/dds_public_alloc.h" +#include "dds/ddsc/dds_public_qos.h" +#include "dds/ddsc/dds_public_error.h" +#include "dds/ddsc/dds_public_status.h" +#include "dds/ddsc/dds_public_listener.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +struct ddsi_serdata; + +/** + * @brief Returns the default domain identifier. + * + * The default domain identifier can be configured in the configuration file + * or be set through an evironment variable ({DDSC_PROJECT_NAME_NOSPACE_CAPS}_DOMAIN). + * + * @returns Default domain identifier + */ +DDS_EXPORT dds_domainid_t dds_domain_default (void); + +/* @defgroup builtintopic_constants Convenience constants for referring to builtin topics + * + * These constants can be used in place of an actual dds_topic_t, when creating + * readers or writers for builtin-topics. + * + * @{ + */ +extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSPARTICIPANT; +extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSTOPIC; +extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSPUBLICATION; +extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION; +/** @}*/ + +/** @name Communication Status definitions + @{**/ +/** Another topic exists with the same name but with different characteristics. */ +typedef enum dds_status_id { + DDS_INCONSISTENT_TOPIC_STATUS_ID, + DDS_OFFERED_DEADLINE_MISSED_STATUS_ID, + DDS_REQUESTED_DEADLINE_MISSED_STATUS_ID, + DDS_OFFERED_INCOMPATIBLE_QOS_STATUS_ID, + DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS_ID, + DDS_SAMPLE_LOST_STATUS_ID, + DDS_SAMPLE_REJECTED_STATUS_ID, + DDS_DATA_ON_READERS_STATUS_ID, + DDS_DATA_AVAILABLE_STATUS_ID, + DDS_LIVELINESS_LOST_STATUS_ID, + DDS_LIVELINESS_CHANGED_STATUS_ID, + DDS_PUBLICATION_MATCHED_STATUS_ID, + DDS_SUBSCRIPTION_MATCHED_STATUS_ID +} +dds_status_id_t; +#define DDS_INCONSISTENT_TOPIC_STATUS (1u << DDS_INCONSISTENT_TOPIC_STATUS_ID) +/** The deadline that the writer has committed through its deadline QoS policy was not respected for a specific instance. */ +#define DDS_OFFERED_DEADLINE_MISSED_STATUS (1u << DDS_OFFERED_DEADLINE_MISSED_STATUS_ID) +/** The deadline that the reader was expecting through its deadline QoS policy was not respected for a specific instance. */ +#define DDS_REQUESTED_DEADLINE_MISSED_STATUS (1u << DDS_REQUESTED_DEADLINE_MISSED_STATUS_ID) +/** A QoS policy setting was incompatible with what was requested. */ +#define DDS_OFFERED_INCOMPATIBLE_QOS_STATUS (1u << DDS_OFFERED_INCOMPATIBLE_QOS_STATUS_ID) +/** A QoS policy setting was incompatible with what is offered. */ +#define DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS (1u << DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS_ID) +/** A sample has been lost (never received). */ +#define DDS_SAMPLE_LOST_STATUS (1u << DDS_SAMPLE_LOST_STATUS_ID) +/** A (received) sample has been rejected. */ +#define DDS_SAMPLE_REJECTED_STATUS (1u << DDS_SAMPLE_REJECTED_STATUS_ID) +/** New information is available. */ +#define DDS_DATA_ON_READERS_STATUS (1u << DDS_DATA_ON_READERS_STATUS_ID) +/** New information is available. */ +#define DDS_DATA_AVAILABLE_STATUS (1u << DDS_DATA_AVAILABLE_STATUS_ID) +/** The liveliness that the DDS_DataWriter has committed through its liveliness QoS policy was not respected; thus readers will consider the writer as no longer "alive". */ +#define DDS_LIVELINESS_LOST_STATUS (1u << DDS_LIVELINESS_LOST_STATUS_ID) +/** The liveliness of one or more writers, that were writing instances read through the readers has changed. Some writers have become "alive" or "not alive". */ +#define DDS_LIVELINESS_CHANGED_STATUS (1u << DDS_LIVELINESS_CHANGED_STATUS_ID) +/** The writer has found a reader that matches the topic and has a compatible QoS. */ +#define DDS_PUBLICATION_MATCHED_STATUS (1u << DDS_PUBLICATION_MATCHED_STATUS_ID) +/** The reader has found a writer that matches the topic and has a compatible QoS. */ +#define DDS_SUBSCRIPTION_MATCHED_STATUS (1u << DDS_SUBSCRIPTION_MATCHED_STATUS_ID) +/** @}*/ + +/** Read state for a data value */ +typedef enum dds_sample_state +{ + DDS_SST_READ = DDS_READ_SAMPLE_STATE, /**0 + * A valid publisher handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic dds entity relations documentation. */ +DDS_EXPORT dds_entity_t +dds_get_publisher(dds_entity_t writer); + +/** + * @brief Get entity subscriber. + * + * This operation returns the subscriber to which the given entity belongs. + * For instance, it will return the Subscriber that was used when + * creating a DataReader (when that DataReader was provided here). + * + * @param[in] entity Entity from which to get its subscriber. + * + * @returns A valid subscriber handle or an error code. + * + * @retval >0 + * A valid subscriber handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic dds entity relations documentation. */ +DDS_EXPORT dds_entity_t +dds_get_subscriber(dds_entity_t entity); + +/** + * @brief Get entity datareader. + * + * This operation returns the datareader to which the given entity belongs. + * For instance, it will return the DataReader that was used when + * creating a ReadCondition (when that ReadCondition was provided here). + * + * @param[in] entity Entity from which to get its datareader. + * + * @returns A valid reader handle or an error code. + * + * @retval >0 + * A valid reader handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic dds entity relations documentation. */ +DDS_EXPORT dds_entity_t +dds_get_datareader(dds_entity_t condition); + +/** + * @brief Get the mask of a condition. + * + * This operation returns the mask that was used to create the given + * condition. + * + * @param[in] condition Read or Query condition that has a mask. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success (given mask is set). + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The mask arg is NULL. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_get_mask(dds_entity_t condition, uint32_t *mask); + +/** + * @brief Returns the instance handle that represents the entity. + * + * @param[in] entity Entity of which to get the instance handle. + * @param[out] ihdl Pointer to dds_instance_handle_t. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + */ +/* TODO: Check list of return codes is complete. */ +DDS_EXPORT dds_return_t +dds_get_instance_handle(dds_entity_t entity, dds_instance_handle_t *ihdl); + +/* + All entities have a set of "status conditions" (following the DCPS + spec), read peeks, take reads & resets (analogously to read & take + operations on reader). The "mask" allows operating only on a subset + of the statuses. Enabled status analogously to DCPS spec. +*/ + +/** + * @brief Read the status set for the entity + * + * This operation reads the status(es) set for the entity based on + * the enabled status and mask set. It does not clear the read status(es). + * + * @param[in] entity Entity on which the status has to be read. + * @param[out] status Returns the status set on the entity, based on the enabled status. + * @param[in] mask Filter the status condition to be read (can be NULL). + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_status(dds_entity_t entity, uint32_t *status, uint32_t mask); + +/** + * @brief Read the status set for the entity + * + * This operation reads the status(es) set for the entity based on the enabled + * status and mask set. It clears the status set after reading. + * + * @param[in] entity Entity on which the status has to be read. + * @param[out] status Returns the status set on the entity, based on the enabled status. + * @param[in] mask Filter the status condition to be read (can be NULL). + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_status(dds_entity_t entity, uint32_t *status, uint32_t mask); + +/** + * @brief Get changed status(es) + * + * This operation returns the status changes since they were last read. + * + * @param[in] entity Entity on which the statuses are read. + * @param[out] status Returns the current set of triggered statuses. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_get_status_changes(dds_entity_t entity, uint32_t *status); + +/** + * @brief Get enabled status on entity + * + * This operation returns the status enabled on the entity + * + * @param[in] entity Entity to get the status. + * @param[out] status Status set on the entity. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_get_status_mask(dds_entity_t entity, uint32_t *mask); + +DDS_DEPRECATED_EXPORT dds_return_t +dds_get_enabled_status(dds_entity_t entity, uint32_t *mask); + +/** + * @brief Set status enabled on entity + * + * This operation enables the status(es) based on the mask set + * + * @param[in] entity Entity to enable the status. + * @param[in] mask Status value that indicates the status to be enabled. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_set_status_mask(dds_entity_t entity, uint32_t mask); + +DDS_DEPRECATED_EXPORT dds_return_t +dds_set_enabled_status(dds_entity_t entity, uint32_t mask); + +/* + Almost all entities have get/set qos operations defined on them, + again following the DCPS spec. But unlike the DCPS spec, the + "present" field in qos_t allows one to initialize just the one QoS + one wants to set & pass it to set_qos. +*/ + +/** + * @brief Get entity QoS policies. + * + * This operation allows access to the existing set of QoS policies + * for the entity. + * + * @param[in] entity Entity on which to get qos. + * @param[out] qos Pointer to the qos structure that returns the set policies. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The existing set of QoS policy values applied to the entity + * has successfully been copied into the specified qos parameter. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The qos parameter is NULL. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic QoS information documentation. */ +DDS_EXPORT dds_return_t +dds_get_qos(dds_entity_t entity, dds_qos_t *qos); + +/** + * @brief Set entity QoS policies. + * + * This operation replaces the existing set of Qos Policy settings for an + * entity. The parameter qos must contain the struct with the QosPolicy + * settings which is checked for self-consistency. + * + * The set of QosPolicy settings specified by the qos parameter are applied on + * top of the existing QoS, replacing the values of any policies previously set + * (provided, the operation returned DDS_RETCODE_OK). + * + * Not all policies are changeable when the entity is enabled. + * + * @note Currently only Latency Budget and Ownership Strength are changeable QoS + * that can be set. + * + * @param[in] entity Entity from which to get qos. + * @param[in] qos Pointer to the qos structure that provides the policies. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The new QoS policies are set. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The qos parameter is NULL. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_IMMUTABLE_POLICY + * The entity is enabled and one or more of the policies of the QoS + * are immutable. + * @retval DDS_RETCODE_INCONSISTENT_POLICY + * A few policies within the QoS are not consistent with each other. + */ +/* TODO: Link to generic QoS information documentation. */ +DDS_EXPORT dds_return_t +dds_set_qos(dds_entity_t entity, const dds_qos_t * qos); + +/* + Get or set listener associated with an entity, type of listener + provided much match type of entity. +*/ + +/** + * @brief Get entity listeners. + * + * This operation allows access to the existing listeners attached to + * the entity. + * + * @param[in] entity Entity on which to get the listeners. + * @param[out] listener Pointer to the listener structure that returns the + * set of listener callbacks. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The listeners of to the entity have been successfully been + * copied into the specified listener parameter. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The listener parameter is NULL. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to (generic) Listener and status information. */ +DDS_EXPORT dds_return_t +dds_get_listener(dds_entity_t entity, dds_listener_t * listener); + +/** + * @brief Set entity listeners. + * + * This operation attaches a dds_listener_t to the dds_entity_t. Only one + * Listener can be attached to each Entity. If a Listener was already + * attached, this operation will replace it with the new one. In other + * words, all related callbacks are replaced (possibly with NULL). + * + * When listener parameter is NULL, all listener callbacks that were possibly + * set on the Entity will be removed. + * + * @note Not all listener callbacks are related to all entities. + * + * Communication Status
+ * For each communication status, the StatusChangedFlag flag is initially set to + * FALSE. It becomes TRUE whenever that plain communication status changes. For + * each plain communication status activated in the mask, the associated + * Listener callback is invoked and the communication status is reset + * to FALSE, as the listener implicitly accesses the status which is passed as a + * parameter to that operation. + * The status is reset prior to calling the listener, so if the application calls + * the get_ from inside the listener it will see the + * status already reset. + * + * Status Propagation
+ * In case a related callback within the Listener is not set, the Listener of + * the Parent entity is called recursively, until a Listener with the appropriate + * callback set has been found and called. This allows the application to set + * (for instance) a default behaviour in the Listener of the containing Publisher + * and a DataWriter specific behaviour when needed. In case the callback is not + * set in the Publishers' Listener either, the communication status will be + * propagated to the Listener of the DomainParticipant of the containing + * DomainParticipant. In case the callback is not set in the DomainParticipants' + * Listener either, the Communication Status flag will be set, resulting in a + * possible WaitSet trigger. + * + * @param[in] entity Entity on which to get the listeners. + * @param[in] listener Pointer to the listener structure that contains the + * set of listener callbacks (maybe NULL). + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The listeners of to the entity have been successfully been + * copied into the specified listener parameter. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to (generic) Listener and status information. */ +DDS_EXPORT dds_return_t +dds_set_listener(dds_entity_t entity, const dds_listener_t * listener); + +/* + Creation functions for various entities. Creating a subscriber or + publisher is optional: if one creates a reader as a descendant of a + participant, it is as if a subscriber is created specially for + that reader. + + QoS default values are those of the DDS specification, but the + inheritance rules are different: + + * publishers and subscribers inherit from the participant QoS + * readers and writers always inherit from the topic QoS + * the QoS's present in the "qos" parameter override the inherited values +*/ + +/** + * @brief Creates a new instance of a DDS participant in a domain + * + * If domain is set (not DDS_DOMAIN_DEFAULT) then it must match if the domain has also + * been configured or an error status will be returned. + * Currently only a single domain can be configured by providing configuration file. + * If no configuration file exists, the default domain is configured as 0. + * + * + * @param[in] domain The domain in which to create the participant (can be DDS_DOMAIN_DEFAULT). Valid values for domain id are between 0 and 230. DDS_DOMAIN_DEFAULT is for using the domain in the configuration. + * @param[in] qos The QoS to set on the new participant (can be NULL). + * @param[in] listener Any listener functions associated with the new participant (can be NULL). + + * @returns A valid participant handle or an error code. + * + * @retval >0 + * A valid participant handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + */ +DDS_EXPORT dds_entity_t +dds_create_participant( + const dds_domainid_t domain, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/** + * @brief Get entity parent. + * + * This operation returns the parent to which the given entity belongs. + * For instance, it will return the Participant that was used when + * creating a Publisher (when that Publisher was provided here). + * + * When a reader or a writer are created with a partition, then a + * subscriber or publisher respectively are created implicitly. These + * implicit subscribers or publishers will be deleted automatically + * when the reader or writer is deleted. However, when this function + * returns such an implicit entity, it is from there on out considered + * 'explicit'. This means that it isn't deleted automatically anymore. + * The application should explicitly call dds_delete on those entities + * now (or delete the parent participant which will delete all entities + * within its hierarchy). + * + * @param[in] entity Entity from which to get its parent. + * + * @returns A valid entity handle or an error code. + * + * @retval >0 + * A valid entity handle. + * @retval DDS_ENTITY_NIL + * Called with a participant. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic dds entity relations documentation. */ +DDS_EXPORT dds_entity_t +dds_get_parent(dds_entity_t entity); + +/** + * @brief Get entity participant. + * + * This operation returns the participant to which the given entity belongs. + * For instance, it will return the Participant that was used when + * creating a Publisher that was used to create a DataWriter (when that + * DataWriter was provided here). + * + * TODO: Link to generic dds entity relations documentation. + * + * @param[in] entity Entity from which to get its participant. + * + * @returns A valid entity or an error code. + * + * @retval >0 + * A valid participant handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_entity_t +dds_get_participant(dds_entity_t entity); + +/** + * @brief Get entity children. + * + * This operation returns the children that the entity contains. + * For instance, it will return all the Topics, Publishers and Subscribers + * of the Participant that was used to create those entities (when that + * Participant is provided here). + * + * This functions takes a pre-allocated list to put the children in and + * will return the number of found children. It is possible that the given + * size of the list is not the same as the number of found children. If + * less children are found, then the last few entries in the list are + * untouched. When more children are found, then only 'size' number of + * entries are inserted into the list, but still complete count of the + * found children is returned. Which children are returned in the latter + * case is undefined. + * + * When supplying NULL as list and 0 as size, you can use this to acquire + * the number of children without having to pre-allocate a list. + * + * When a reader or a writer are created with a partition, then a + * subscriber or publisher respectively are created implicitly. These + * implicit subscribers or publishers will be deleted automatically + * when the reader or writer is deleted. However, when this function + * returns such an implicit entity, it is from there on out considered + * 'explicit'. This means that it isn't deleted automatically anymore. + * The application should explicitly call dds_delete on those entities + * now (or delete the parent participant which will delete all entities + * within its hierarchy). + * + * @param[in] entity Entity from which to get its children. + * @param[out] children Pre-allocated array to contain the found children. + * @param[in] size Size of the pre-allocated children's list. + * + * @returns Number of children or an error code. + * + * @retval >=0 + * Number of childer found children (can be larger than 'size'). + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The children parameter is NULL, while a size is provided. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Link to generic dds entity relations documentation. */ +DDS_EXPORT dds_return_t +dds_get_children(dds_entity_t entity, dds_entity_t *children, size_t size); + +/** + * @brief Get the domain id to which this entity is attached. + * + * When creating a participant entity, it is attached to a certain domain. + * All the children (like Publishers) and childrens' children (like + * DataReaders), etc are also attached to that domain. + * + * This function will return the original domain ID when called on + * any of the entities within that hierarchy. + * + * @param[in] entity Entity from which to get its children. + * @param[out] id Pointer to put the domain ID in. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Domain ID was returned. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The id parameter is NULL. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_get_domainid(dds_entity_t entity, dds_domainid_t *id); + +/** + * @brief Get participants of a domain. + * + * This operation acquires the participants created on a domain and returns + * the number of found participants. + * + * This function takes a domain id with the size of pre-allocated participant's + * list in and will return the number of found participants. It is possible that + * the given size of the list is not the same as the number of found participants. + * If less participants are found, then the last few entries in an array stay + * untouched. If more participants are found and the array is too small, then the + * participants returned are undefined. + * + * @param[in] domain_id The domain id. + * @param[out] participants The participant for domain. + * @param[in] size Size of the pre-allocated participant's list. + * + * @returns Number of participants found or and error code. + * + * @retval >0 + * Number of participants found. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The participant parameter is NULL, while a size is provided. + */ +DDS_EXPORT dds_return_t +dds_lookup_participant( + dds_domainid_t domain_id, + dds_entity_t *participants, + size_t size); + +/** + * @brief Creates a new topic with default type handling. + * + * The type name for the topic is taken from the generated descriptor. Topic + * matching is done on a combination of topic name and type name. + * + * @param[in] participant Participant on which to create the topic. + * @param[in] descriptor An IDL generated topic descriptor. + * @param[in] name Name of the topic. + * @param[in] qos QoS to set on the new topic (can be NULL). + * @param[in] listener Any listener functions associated with the new topic (can be NULL). + * + * @returns A valid topic handle or an error code. + * + * @retval >=0 + * A valid topic handle. + * @retval DDS_RETCODE_BAD_PARAMETER + * Either participant, descriptor, name or qos is invalid. + */ +/* TODO: Check list of retcodes is complete. */ +DDS_EXPORT dds_entity_t +dds_create_topic( + dds_entity_t participant, + const dds_topic_descriptor_t *descriptor, + const char *name, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/** + * @brief Creates a new topic with arbitrary type handling. + * + * The type name for the topic is taken from the provided "sertopic" object. Topic + * matching is done on a combination of topic name and type name. + * + * @param[in] participant Participant on which to create the topic. + * @param[in] sertopic Internal description of the topic type. + * @param[in] name Name of the topic. + * @param[in] qos QoS to set on the new topic (can be NULL). + * @param[in] listener Any listener functions associated with the new topic (can be NULL). + * @param[in] sedp_plist Topic description to be published as part of discovery (if NULL, not published). + * + * @returns A valid topic handle or an error code. + * + * @retval >=0 + * A valid topic handle. + * @retval DDS_RETCODE_BAD_PARAMETER + * Either participant, descriptor, name or qos is invalid. + */ +/* TODO: Check list of retcodes is complete. */ +struct ddsi_sertopic; +struct nn_plist; +DDS_EXPORT dds_entity_t +dds_create_topic_arbitrary ( + dds_entity_t participant, + struct ddsi_sertopic *sertopic, + const char *name, + const dds_qos_t *qos, + const dds_listener_t *listener, + const struct nn_plist *sedp_plist); + +/** + * @brief Finds a named topic. + * + * The returned topic should be released with dds_delete. + * + * @param[in] participant The participant on which to find the topic. + * @param[in] name The name of the topic to find. + * + * @returns A valid topic handle or an error code. + * + * @retval >0 + * A valid topic handle. + * @retval DDS_RETCODE_BAD_PARAMETER + * Participant was invalid. + */ +/* TODO: Check list of retcodes is complete. */ +DDS_EXPORT dds_entity_t +dds_find_topic(dds_entity_t participant, const char *name); + +/** + * @brief Returns the name of a given topic. + * + * @param[in] topic The topic. + * @param[out] name Buffer to write the topic name to. + * @param[in] size Number of bytes available in the buffer. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Success. + */ +/* TODO: do we need a convenience version as well that allocates and add a _s suffix to this one? */ +/* TODO: Check annotation. Could be _Out_writes_to_(size, return + 1) as well. */ +DDS_EXPORT dds_return_t +dds_get_name(dds_entity_t topic, char *name, size_t size); + +/** + * @brief Returns the type name of a given topic. + * + * @param[in] topic The topic. + * @param[out] name Buffer to write the topic type name to. + * @param[in] size Number of bytes available in the buffer. + * + * @returns A dds_return_t indicating success or failure. + * + * @return DDS_RETCODE_OK + * Success. + */ +DDS_EXPORT dds_return_t +dds_get_type_name(dds_entity_t topic, char *name, size_t size); + +/** Topic filter function */ +typedef bool (*dds_topic_filter_fn) (const void * sample); + +/** + * @brief Sets a filter on a topic. + * + * @param[in] topic The topic on which the content filter is set. + * @param[in] filter The filter function used to filter topic samples. + */ +DDS_EXPORT void +dds_set_topic_filter(dds_entity_t topic, dds_topic_filter_fn filter); + +DDS_DEPRECATED_EXPORT void +dds_topic_set_filter(dds_entity_t topic, dds_topic_filter_fn filter); + +/** + * @brief Gets the filter for a topic. + * + * @param[in] topic The topic from which to get the filter. + * + * @returns The topic filter. + */ +DDS_EXPORT dds_topic_filter_fn +dds_get_topic_filter(dds_entity_t topic); + +DDS_DEPRECATED_EXPORT dds_topic_filter_fn +dds_topic_get_filter(dds_entity_t topic); + +/** + * @brief Creates a new instance of a DDS subscriber + * + * @param[in] participant The participant on which the subscriber is being created. + * @param[in] qos The QoS to set on the new subscriber (can be NULL). + * @param[in] listener Any listener functions associated with the new subscriber (can be NULL). + * + * @returns A valid subscriber handle or an error code. + * + * @retval >0 + * A valid subscriber handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the parameters is invalid. + */ +DDS_EXPORT dds_entity_t +dds_create_subscriber( + dds_entity_t participant, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/** + * @brief Creates a new instance of a DDS publisher + * + * @param[in] participant The participant to create a publisher for. + * @param[in] qos The QoS to set on the new publisher (can be NULL). + * @param[in] listener Any listener functions associated with the new publisher (can be NULL). + * + * @returns A valid publisher handle or an error code. + * + * @retval >0 + * A valid publisher handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + */ +/* TODO: Check list of error codes is complete. */ +DDS_EXPORT dds_entity_t +dds_create_publisher( + dds_entity_t participant, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/** + * @brief Suspends the publications of the Publisher + * + * This operation is a hint to the Service so it can optimize its performance by e.g., collecting + * modifications to DDS writers and then batching them. The Service is not required to use the hint. + * + * Every invocation of this operation must be matched by a corresponding call to @see dds_resume + * indicating that the set of modifications has completed. + * + * @param[in] publisher The publisher for which all publications will be suspended. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Publications suspended successfully. + * @retval DDS_RETCODE_BAD_PARAMETER + * The pub parameter is not a valid publisher. + * @retval DDS_RETCODE_UNSUPPORTED + * Operation is not supported. + */ +DDS_EXPORT dds_return_t +dds_suspend(dds_entity_t publisher); + +/** + * @brief Resumes the publications of the Publisher + * + * This operation is a hint to the Service to indicate that the application has + * completed changes initiated by a previous dds_suspend(). The Service is not + * required to use the hint. + * + * The call to resume_publications must match a previous call to @see suspend_publications. + * + * @param[in] publisher The publisher for which all publications will be resumed. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Publications resumed successfully. + * @retval DDS_RETCODE_BAD_PARAMETER + * The pub parameter is not a valid publisher. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * No previous matching dds_suspend(). + * @retval DDS_RETCODE_UNSUPPORTED + * Operation is not supported. + */ +DDS_EXPORT dds_return_t +dds_resume(dds_entity_t publisher); + +/** + * @brief Waits at most for the duration timeout for acks for data in the publisher or writer. + * + * This operation blocks the calling thread until either all data written by the publisher + * or writer is acknowledged by all matched reliable reader entities, or else the duration + * specified by the timeout parameter elapses, whichever happens first. + * + * @param[in] publisher_or_writer Publisher or writer whose acknowledgments must be waited for + * @param[in] timeout How long to wait for acknowledgments before time out + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * All acknowledgments successfully received with the timeout. + * @retval DDS_RETCODE_BAD_PARAMETER + * The publisher_or_writer is not a valid publisher or writer. + * @retval DDS_RETCODE_TIMEOUT + * Timeout expired before all acknowledgments from reliable reader entities were received. + * @retval DDS_RETCODE_UNSUPPORTED + * Operation is not supported. + */ +DDS_EXPORT dds_return_t +dds_wait_for_acks(dds_entity_t publisher_or_writer, dds_duration_t timeout); + +/** + * @brief Creates a new instance of a DDS reader. + * + * This implicit subscriber will be deleted automatically when the created reader + * is deleted. + * + * @param[in] participant_or_subscriber The participant or subscriber on which the reader is being created. + * @param[in] topic The topic to read. + * @param[in] qos The QoS to set on the new reader (can be NULL). + * @param[in] listener Any listener functions associated with the new reader (can be NULL). + * + * @returns A valid reader handle or an error code. + * + * @retval >0 + * A valid reader handle. + * @retval DDS_RETCODE_ERROR + * An internal error occurred. + */ +/* TODO: Complete list of error codes */ +DDS_EXPORT dds_entity_t +dds_create_reader( + dds_entity_t participant_or_subscriber, + dds_entity_t topic, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/** + * @brief Wait until reader receives all historic data + * + * The operation blocks the calling thread until either all "historical" data is + * received, or else the duration specified by the max_wait parameter elapses, whichever happens + * first. A return value of 0 indicates that all the "historical" data was received; a return + * value of TIMEOUT indicates that max_wait elapsed before all the data was received. + * + * @param[in] reader The reader on which to wait for historical data. + * @param[in] max_wait How long to wait for historical data before time out. + * + * @returns a status, 0 on success, TIMEOUT on timeout or a negative value to indicate error. + */ +/* TODO: Complete list of error codes */ +DDS_EXPORT int +dds_reader_wait_for_historical_data( + dds_entity_t reader, + dds_duration_t max_wait); + +/** + * @brief Creates a new instance of a DDS writer. + * + * This implicit publisher will be deleted automatically when the created writer + * is deleted. + * + * @param[in] participant_or_publisher The participant or publisher on which the writer is being created. + * @param[in] topic The topic to write. + * @param[in] qos The QoS to set on the new writer (can be NULL). + * @param[in] listener Any listener functions associated with the new writer (can be NULL). + * + * @returns A valid writer handle or an error code. + * + * @returns >0 + * A valid writer handle. + * @returns DDS_RETCODE_ERROR + * An internal error occurred. + */ +/* TODO: Complete list of error codes */ +DDS_EXPORT dds_entity_t +dds_create_writer( + dds_entity_t participant_or_publisher, + dds_entity_t topic, + const dds_qos_t *qos, + const dds_listener_t *listener); + +/* + Writing data (and variants of it) is straightforward. The first set + is equivalent to the second set with -1 passed for "timestamp", + meaning, substitute the result of a call to time(). The dispose + and unregister operations take an object of the topic's type, but + only touch the key fields; the remained may be undefined. +*/ +/** + * @brief Registers an instance + * + * This operation registers an instance with a key value to the data writer and + * returns an instance handle that could be used for successive write & dispose + * operations. When the handle is not allocated, the function will return and + * error and the handle will be un-touched. + * + * @param[in] writer The writer to which instance has be associated. + * @param[out] handle The instance handle. + * @param[in] data The instance with the key value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + */ +DDS_EXPORT dds_return_t +dds_register_instance( + dds_entity_t writer, + dds_instance_handle_t *handle, + const void *data); + +/** + * @brief Unregisters an instance + * + * This operation reverses the action of register instance, removes all information regarding + * the instance and unregisters an instance with a key value from the data writer. + * + * @param[in] writer The writer to which instance is associated. + * @param[in] data The instance with the key value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + */ +DDS_EXPORT dds_return_t +dds_unregister_instance(dds_entity_t writer, const void *data); + +/** + * @brief Unregisters an instance + * + *This operation unregisters the instance which is identified by the key fields of the given + *typed instance handle. + * + * @param[in] writer The writer to which instance is associated. + * @param[in] handle The instance handle. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + */ +DDS_EXPORT dds_return_t +dds_unregister_instance_ih(dds_entity_t writer, dds_instance_handle_t handle); + +/** + * @brief Unregisters an instance + * + * This operation reverses the action of register instance, removes all information regarding + * the instance and unregisters an instance with a key value from the data writer. It also + * provides a value for the timestamp explicitly. + * + * @param[in] writer The writer to which instance is associated. + * @param[in] data The instance with the key value. + * @param[in] timestamp The timestamp used at registration. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + */ +DDS_EXPORT dds_return_t +dds_unregister_instance_ts( + dds_entity_t writer, + const void *data, + dds_time_t timestamp); + +/** + * @brief Unregisters an instance + * + * This operation unregisters an instance with a key value from the handle. Instance can be identified + * from instance handle. If an unregistered key ID is passed as an instance data, an error is logged and + * not flagged as return value. + * + * @param[in] writer The writer to which instance is associated. + * @param[in] handle The instance handle. + * @param[in] timestamp The timestamp used at registration. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object + */ +DDS_EXPORT dds_return_t +dds_unregister_instance_ih_ts( + dds_entity_t writer, + dds_instance_handle_t handle, + dds_time_t timestamp); + +/** + * @brief This operation modifies and disposes a data instance. + * + * This operation requests the Data Distribution Service to modify the instance and + * mark it for deletion. Copies of the instance and its corresponding samples, which are + * stored in every connected reader and, dependent on the QoS policy settings (also in + * the Transient and Persistent stores) will be modified and marked for deletion by + * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. + * + * Blocking
+ * If the history QoS policy is set to DDS_HISTORY_KEEP_ALL, the + * dds_writedispose operation on the writer may block if the modification + * would cause data to be lost because one of the limits, specified in the + * resource_limits QoS policy, to be exceeded. In case the synchronous + * attribute value of the reliability Qos policy is set to true for + * communicating writers and readers then the writer will wait until + * all synchronous readers have acknowledged the data. Under these + * circumstances, the max_blocking_time attribute of the reliability + * QoS policy configures the maximum time the dds_writedispose operation + * may block. + * If max_blocking_time elapses before the writer is able to store the + * modification without exceeding the limits and all expected acknowledgements + * are received, the dds_writedispose operation will fail and returns + * DDS_RETCODE_TIMEOUT. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] data The data to be written and disposed. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_TIMEOUT + * Either the current action overflowed the available resources as + * specified by the combination of the reliability QoS policy, + * history QoS policy and resource_limits QoS policy, or the + * current action was waiting for data delivery acknowledgement + * by synchronous readers. This caused blocking of this operation, + * which could not be resolved before max_blocking_time of the + * reliability QoS policy elapsed. + */ +DDS_EXPORT dds_return_t +dds_writedispose(dds_entity_t writer, const void *data); + +/** + * @brief This operation modifies and disposes a data instance with a specific + * timestamp. + * + * This operation performs the same functions as dds_writedispose except that + * the application provides the value for the source_timestamp that is made + * available to connected reader objects. This timestamp is important for the + * interpretation of the destination_order QoS policy. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] data The data to be written and disposed. + * @param[in] timestamp The timestamp used as source timestamp. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_TIMEOUT + * Either the current action overflowed the available resources as + * specified by the combination of the reliability QoS policy, + * history QoS policy and resource_limits QoS policy, or the + * current action was waiting for data delivery acknowledgement + * by synchronous readers. This caused blocking of this operation, + * which could not be resolved before max_blocking_time of the + * reliability QoS policy elapsed. + */ +DDS_EXPORT dds_return_t +dds_writedispose_ts( + dds_entity_t writer, + const void *data, + dds_time_t timestamp); + +/** + * @brief This operation disposes an instance, identified by the data sample. + * + * This operation requests the Data Distribution Service to modify the instance and + * mark it for deletion. Copies of the instance and its corresponding samples, which are + * stored in every connected reader and, dependent on the QoS policy settings (also in + * the Transient and Persistent stores) will be modified and marked for deletion by + * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. + * + * Blocking
+ * If the history QoS policy is set to DDS_HISTORY_KEEP_ALL, the + * dds_writedispose operation on the writer may block if the modification + * would cause data to be lost because one of the limits, specified in the + * resource_limits QoS policy, to be exceeded. In case the synchronous + * attribute value of the reliability Qos policy is set to true for + * communicating writers and readers then the writer will wait until + * all synchronous readers have acknowledged the data. Under these + * circumstances, the max_blocking_time attribute of the reliability + * QoS policy configures the maximum time the dds_writedispose operation + * may block. + * If max_blocking_time elapses before the writer is able to store the + * modification without exceeding the limits and all expected acknowledgements + * are received, the dds_writedispose operation will fail and returns + * DDS_RETCODE_TIMEOUT. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] data The data sample that identifies the instance + * to be disposed. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_TIMEOUT + * Either the current action overflowed the available resources as + * specified by the combination of the reliability QoS policy, + * history QoS policy and resource_limits QoS policy, or the + * current action was waiting for data delivery acknowledgement + * by synchronous readers. This caused blocking of this operation, + * which could not be resolved before max_blocking_time of the + * reliability QoS policy elapsed. + */ +DDS_EXPORT dds_return_t +dds_dispose(dds_entity_t writer, const void *data); + +/** + * @brief This operation disposes an instance with a specific timestamp, identified by the data sample. + * + * This operation performs the same functions as dds_dispose except that + * the application provides the value for the source_timestamp that is made + * available to connected reader objects. This timestamp is important for the + * interpretation of the destination_order QoS policy. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] data The data sample that identifies the instance + * to be disposed. + * @param[in] timestamp The timestamp used as source timestamp. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion + * @retval DDS_RETCODE_ERROR + * An internal error has occurred + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted + * @retval DDS_RETCODE_TIMEOUT + * Either the current action overflowed the available resources as + * specified by the combination of the reliability QoS policy, + * history QoS policy and resource_limits QoS policy, or the + * current action was waiting for data delivery acknowledgment + * by synchronous readers. This caused blocking of this operation, + * which could not be resolved before max_blocking_time of the + * reliability QoS policy elapsed. + */ +DDS_EXPORT dds_return_t +dds_dispose_ts( + dds_entity_t writer, + const void *data, + dds_time_t timestamp); + +/** + * @brief This operation disposes an instance, identified by the instance handle. + * + * This operation requests the Data Distribution Service to modify the instance and + * mark it for deletion. Copies of the instance and its corresponding samples, which are + * stored in every connected reader and, dependent on the QoS policy settings (also in + * the Transient and Persistent stores) will be modified and marked for deletion by + * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. + * + * Instance Handle
+ * The given instance handle must correspond to the value that was returned by either + * the dds_register_instance operation, dds_register_instance_ts or dds_lookup_instance. + * If there is no correspondence, then the result of the operation is unspecified. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] handle The handle to identify an instance. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this writer + */ +DDS_EXPORT dds_return_t +dds_dispose_ih(dds_entity_t writer, dds_instance_handle_t handle); + +/** + * @brief This operation disposes an instance with a specific timestamp, identified by the instance handle. + * + * This operation performs the same functions as dds_dispose_ih except that + * the application provides the value for the source_timestamp that is made + * available to connected reader objects. This timestamp is important for the + * interpretation of the destination_order QoS policy. + * + * @param[in] writer The writer to dispose the data instance from. + * @param[in] handle The handle to identify an instance. + * @param[in] timestamp The timestamp used as source timestamp. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The sample is written and the instance is marked for deletion. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * At least one of the arguments is invalid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this writer. + */ +DDS_EXPORT dds_return_t +dds_dispose_ih_ts( + dds_entity_t writer, + dds_instance_handle_t handle, + dds_time_t timestamp); + +/** + * @brief Write the value of a data instance + * + * With this API, the value of the source timestamp is automatically made + * available to the data reader by the service. + * + * @param[in] writer The writer entity. + * @param[in] data Value to be written. + * + * @returns dds_return_t indicating success or failure. + */ +DDS_EXPORT dds_return_t +dds_write(dds_entity_t writer, const void *data); + +/*TODO: What is it for and is it really needed? */ +DDS_EXPORT void +dds_write_flush(dds_entity_t writer); + +/** + * @brief Write a CDR serialized value of a data instance + * + * @param[in] writer The writer entity. + * @param[in] cdr CDR serialized value to be written. + * @param[in] size Size (in bytes) of CDR encoded data to be written. + * + * @returns A dds_return_t indicating success or failure. + */ +DDS_EXPORT dds_return_t +dds_writecdr(dds_entity_t writer, struct ddsi_serdata *serdata); + +/** + * @brief Write the value of a data instance along with the source timestamp passed. + * + * @param[in] writer The writer entity. + * @param[in] data Value to be written. + * @param[in] timestamp Source timestamp. + * + * @returns A dds_return_t indicating success or failure. + */ +DDS_EXPORT dds_return_t +dds_write_ts( + dds_entity_t writer, + const void *data, + dds_time_t timestamp); + +/** + * @brief Creates a readcondition associated to the given reader. + * + * The readcondition allows specifying which samples are of interest in + * a data reader's history, by means of a mask. The mask is or'd with + * the flags that are dds_sample_state_t, dds_view_state_t and + * dds_instance_state_t. + * + * Based on the mask value set, the readcondition gets triggered when + * data is available on the reader. + * + * Waitsets allow waiting for an event on some of any set of entities. + * This means that the readcondition can be used to wake up a waitset when + * data is in the reader history with states that matches the given mask. + * + * @note The parent reader and every of its associated conditions (whether + * they are readconditions or queryconditions) share the same resources. + * This means that one of these entities reads or takes data, the states + * of the data will change for other entities automatically. For instance, + * if one reads a sample, then the sample state will become 'read' for all + * associated reader/conditions. Or if one takes a sample, then it's not + * available to any other associated reader/condition. + * + * @param[in] reader Reader to associate the condition to. + * @param[in] mask Interest (dds_sample_state_t|dds_view_state_t|dds_instance_state_t). + * + * @returns A valid condition handle or an error code. + * + * @retval >0 + * A valid condition handle + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_entity_t +dds_create_readcondition(dds_entity_t reader, uint32_t mask); + +typedef bool (*dds_querycondition_filter_fn) (const void * sample); + +/** + * @brief Creates a queryondition associated to the given reader. + * + * The queryondition allows specifying which samples are of interest in + * a data reader's history, by means of a mask and a filter. The mask is + * or'd with the flags that are dds_sample_state_t, dds_view_state_t and + * dds_instance_state_t. + * + * Based on the mask value set and data that matches the filter, the + * querycondition gets triggered when data is available on the reader. + * + * Waitsets allow waiting for an event on some of any set of entities. + * This means that the querycondition can be used to wake up a waitset when + * data is in the reader history with states that matches the given mask + * and filter. + * + * @note The parent reader and every of its associated conditions (whether + * they are readconditions or queryconditions) share the same resources. + * This means that one of these entities reads or takes data, the states + * of the data will change for other entities automatically. For instance, + * if one reads a sample, then the sample state will become 'read' for all + * associated reader/conditions. Or if one takes a sample, then it's not + * available to any other associated reader/condition. + * + * @param[in] reader Reader to associate the condition to. + * @param[in] mask Interest (dds_sample_state_t|dds_view_state_t|dds_instance_state_t). + * @param[in] filter Callback that the application can use to filter specific samples. + * + * @returns A valid condition handle or an error code + * + * @retval >=0 + * A valid condition handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +/* TODO: Explain the filter (aka expression & parameters) of the (to be + * implemented) new querycondition implementation. + * TODO: Update parameters when new querycondition is introduced. + */ +DDS_EXPORT dds_entity_t +dds_create_querycondition( + dds_entity_t reader, + uint32_t mask, + dds_querycondition_filter_fn filter); + +/** + * @brief Creates a guardcondition. + * + * Waitsets allow waiting for an event on some of any set of entities. + * This means that the guardcondition can be used to wake up a waitset when + * data is in the reader history with states that matches the given mask. + * + * @returns A valid condition handle or an error code. + * + * @retval >0 + * A valid condition handle + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_entity_t +dds_create_guardcondition(dds_entity_t participant); + +/** + * @brief Sets the trigger status of a guardcondition. + * + * @retval DDS_RETCODE_OK + * Operation successful + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_set_guardcondition(dds_entity_t guardcond, bool triggered); + +/** + * @brief Reads the trigger status of a guardcondition. + * + * @retval DDS_RETCODE_OK + * Operation successful + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_guardcondition(dds_entity_t guardcond, bool *triggered); + +/** + * @brief Reads and resets the trigger status of a guardcondition. + * + * @retval DDS_RETCODE_OK + * Operation successful + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_guardcondition(dds_entity_t guardcond, bool *triggered); + +/** + * @brief Waitset attachment argument. + * + * Every entity that is attached to the waitset can be accompanied by such + * an attachment argument. When the waitset wait is unblocked because of an + * entity that triggered, then the returning array will be populated with + * these attachment arguments that are related to the triggered entity. + */ +typedef intptr_t dds_attach_t; + +/** + * @brief Create a waitset and allocate the resources required + * + * A WaitSet object allows an application to wait until one or more of the + * conditions of the attached entities evaluates to TRUE or until the timeout + * expires. + * + * @param[in] participant Domain participant which the WaitSet contains. + * + * @returns A valid waitset handle or an error code. + * + * @retval >=0 + * A valid waitset handle. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_entity_t +dds_create_waitset(dds_entity_t participant); + +/** + * @brief Acquire previously attached entities. + * + * This functions takes a pre-allocated list to put the entities in and + * will return the number of found entities. It is possible that the given + * size of the list is not the same as the number of found entities. If + * less entities are found, then the last few entries in the list are + * untouched. When more entities are found, then only 'size' number of + * entries are inserted into the list, but still the complete count of the + * found entities is returned. Which entities are returned in the latter + * case is undefined. + * + * @param[in] waitset Waitset from which to get its attached entities. + * @param[out] entities Pre-allocated array to contain the found entities. + * @param[in] size Size of the pre-allocated entities' list. + * + * @returns A dds_return_t with the number of children or an error code. + * + * @retval >=0 + * Number of children found (can be larger than 'size'). + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entities parameter is NULL, while a size is provided. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_waitset_get_entities( + dds_entity_t waitset, + dds_entity_t *entities, + size_t size); + +/** + * @brief This operation attaches an Entity to the WaitSet. + * + * This operation attaches an Entity to the WaitSet. The dds_waitset_wait() + * will block when none of the attached entities are triggered. 'Triggered' + * (dds_triggered()) doesn't mean the same for every entity: + * - Reader/Writer/Publisher/Subscriber/Topic/Participant + * - These are triggered when their status changed. + * - WaitSet + * - Triggered when trigger value was set to true by the application. + * It stays triggered until application sets the trigger value to + * false (dds_waitset_set_trigger()). This can be used to wake up an + * waitset for different reasons (f.i. termination) than the 'normal' + * status change (like new data). + * - ReadCondition/QueryCondition + * - Triggered when data is available on the related Reader that matches + * the Condition. + * + * Multiple entities can be attached to a single waitset. A particular entity + * can be attached to multiple waitsets. However, a particular entity can not + * be attached to a particular waitset multiple times. + * + * @param[in] waitset The waitset to attach the given entity to. + * @param[in] entity The entity to attach. + * @param[in] x Blob that will be supplied when the waitset wait is + * triggerd by the given entity. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Entity attached. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The given waitset or entity are not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The entity was already attached. + */ +DDS_EXPORT dds_return_t +dds_waitset_attach( + dds_entity_t waitset, + dds_entity_t entity, + dds_attach_t x); + +/** + * @brief This operation detaches an Entity to the WaitSet. + * + * @param[in] waitset The waitset to detach the given entity from. + * @param[in] entity The entity to detach. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Entity attached. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The given waitset or entity are not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The entity is not attached. + */ +DDS_EXPORT dds_return_t +dds_waitset_detach( + dds_entity_t waitset, + dds_entity_t entity); + +/** + * @brief Sets the trigger_value associated with a waitset. + * + * When the waitset is attached to itself and the trigger value is + * set to 'true', then the waitset will wake up just like with an + * other status change of the attached entities. + * + * This can be used to forcefully wake up a waitset, for instance + * when the application wants to shut down. So, when the trigger + * value is true, the waitset will wake up or not wait at all. + * + * The trigger value will remain true until the application sets it + * false again deliberately. + * + * @param[in] waitset The waitset to set the trigger value on. + * @param[in] trigger The trigger value to set. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Entity attached. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The given waitset is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_waitset_set_trigger( + dds_entity_t waitset, + bool trigger); + +/** + * @brief This operation allows an application thread to wait for the a status + * change or other trigger on (one of) the entities that are attached to + * the WaitSet. + * + * The "dds_waitset_wait" operation blocks until the some of the attached + * entities have triggered or "reltimeout" has elapsed. + * 'Triggered' (dds_triggered()) doesn't mean the same for every entity: + * - Reader/Writer/Publisher/Subscriber/Topic/Participant + * - These are triggered when their status changed. + * - WaitSet + * - Triggered when trigger value was set to true by the application. + * It stays triggered until application sets the trigger value to + * false (dds_waitset_set_trigger()). This can be used to wake up an + * waitset for different reasons (f.i. termination) than the 'normal' + * status change (like new data). + * - ReadCondition/QueryCondition + * - Triggered when data is available on the related Reader that matches + * the Condition. + * + * This functions takes a pre-allocated list to put the "xs" blobs in (that + * were provided during the attach of the related entities) and will return + * the number of triggered entities. It is possible that the given size + * of the list is not the same as the number of triggered entities. If less + * entities were triggered, then the last few entries in the list are + * untouched. When more entities are triggered, then only 'size' number of + * entries are inserted into the list, but still the complete count of the + * triggered entities is returned. Which "xs" blobs are returned in the + * latter case is undefined. + * + * In case of a time out, the return value is 0. + * + * Deleting the waitset while the application is blocked results in an + * error code (i.e. < 0) returned by "wait". + * + * Multiple threads may block on a single waitset at the same time; + * the calls are entirely independent. + * + * An empty waitset never triggers (i.e., dds_waitset_wait on an empty + * waitset is essentially equivalent to a sleep). + * + * The "dds_waitset_wait_until" operation is the same as the + * "dds_waitset_wait" except that it takes an absolute timeout. + * + * @param[in] waitset The waitset to set the trigger value on. + * @param[out] xs Pre-allocated list to store the 'blobs' that were + * provided during the attach of the triggered entities. + * @param[in] nxs The size of the pre-allocated blobs list. + * @param[in] reltimeout Relative timeout + * + * @returns A dds_return_t with the number of entities triggered or an error code + * + * @retval >0 + * Number of entities triggered. + * @retval 0 + * Time out (no entities were triggered). + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The given waitset is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_waitset_wait( + dds_entity_t waitset, + dds_attach_t *xs, + size_t nxs, + dds_duration_t reltimeout); + +/** + * @brief This operation allows an application thread to wait for the a status + * change or other trigger on (one of) the entities that are attached to + * the WaitSet. + * + * The "dds_waitset_wait" operation blocks until the some of the attached + * entities have triggered or "abstimeout" has been reached. + * 'Triggered' (dds_triggered()) doesn't mean the same for every entity: + * - Reader/Writer/Publisher/Subscriber/Topic/Participant + * - These are triggered when their status changed. + * - WaitSet + * - Triggered when trigger value was set to true by the application. + * It stays triggered until application sets the trigger value to + * false (dds_waitset_set_trigger()). This can be used to wake up an + * waitset for different reasons (f.i. termination) than the 'normal' + * status change (like new data). + * - ReadCondition/QueryCondition + * - Triggered when data is available on the related Reader that matches + * the Condition. + * + * This functions takes a pre-allocated list to put the "xs" blobs in (that + * were provided during the attach of the related entities) and will return + * the number of triggered entities. It is possible that the given size + * of the list is not the same as the number of triggered entities. If less + * entities were triggered, then the last few entries in the list are + * untouched. When more entities are triggered, then only 'size' number of + * entries are inserted into the list, but still the complete count of the + * triggered entities is returned. Which "xs" blobs are returned in the + * latter case is undefined. + * + * In case of a time out, the return value is 0. + * + * Deleting the waitset while the application is blocked results in an + * error code (i.e. < 0) returned by "wait". + * + * Multiple threads may block on a single waitset at the same time; + * the calls are entirely independent. + * + * An empty waitset never triggers (i.e., dds_waitset_wait on an empty + * waitset is essentially equivalent to a sleep). + * + * The "dds_waitset_wait" operation is the same as the + * "dds_waitset_wait_until" except that it takes an relative timeout. + * + * The "dds_waitset_wait" operation is the same as the "dds_wait" + * except that it takes an absolute timeout. + * + * @param[in] waitset The waitset to set the trigger value on. + * @param[out] xs Pre-allocated list to store the 'blobs' that were + * provided during the attach of the triggered entities. + * @param[in] nxs The size of the pre-allocated blobs list. + * @param[in] abstimeout Absolute timeout + * + * @returns A dds_return_t with the number of entities triggered or an error code. + * + * @retval >0 + * Number of entities triggered. + * @retval 0 + * Time out (no entities were triggered). + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The given waitset is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The waitset has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_waitset_wait_until( + dds_entity_t waitset, + dds_attach_t *xs, + size_t nxs, + dds_time_t abstimeout); + +/* + There are a number of read and take variations. + + Return value is the number of elements returned. "max_samples" + should have the same type, as one can't return more than MAX_INT + this way, anyway. X, Y, CX, CY return to the various filtering + options, see the DCPS spec. + + O ::= read | take + + X => CX + (empty) (empty) + _next_instance instance_handle_t prev + + Y => CY + (empty) uint32_t mask + _cond cond_t cond -- refers to a read condition (or query if implemented) + */ + +/** + * @brief Access and read the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition. + * + * Return value provides information about number of samples read, which will + * be <= maxs. Based on the count, the buffer will contain data to be read only + * when valid_data bit in sample info structure is set. + * The buffer required for data values, could be allocated explicitly or can + * use the memory from data reader to prevent copy. In the latter case, buffer and + * sample_info should be returned back, once it is no longer using the Data. + * Data values once read will remain in the buffer with the sample_state set to READ + * and view_state set to NOT_NEW. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs); + +/** + * @brief Access and read loaned samples of data reader, readcondition or querycondition. + * + * After dds_read_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL) + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value + * @param[in] maxs Maximum number of samples to read + * + * @returns A dds_return_t with the number of samples read or an error code + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs); + +/** + * @brief Read the collection of data values and sample info from the data reader, readcondition + * or querycondition based on mask. + * + * When using a readcondition or querycondition, their masks are or'd with the given mask. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_mask( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + uint32_t mask); + +/** + * @brief Access and read loaned samples of data reader, readcondition + * or querycondition based on mask + * + * When using a readcondition or querycondition, their masks are or'd with the given mask. + * + * After dds_read_mask_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_mask_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + uint32_t mask); + +/** + * @brief Access and read the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition, coped by the provided instance handle. + * + * This operation implements the same functionality as dds_read, except that only data scoped to + * the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_read_instance( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle); + +/** + * @brief Access and read loaned samples of data reader, readcondition or querycondition, + * scoped by the provided instance handle. + * + * This operation implements the same functionality as dds_read_wl, except that only data + * scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_read_instance_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle); + +/** + * @brief Read the collection of data values and sample info from the data reader, readcondition + * or querycondition based on mask and scoped by the provided instance handle. + * + * This operation implements the same functionality as dds_read_mask, except that only data + * scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_read_instance_mask( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask); + +/** + * @brief Access and read loaned samples of data reader, readcondition or + * querycondition based on mask, scoped by the provided instance handle. + * + * This operation implements the same functionality as dds_read_mask_wl, except that + * only data scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_read_instance_mask_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask); + +/** + * @brief Access the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition. + * + * Data value once read is removed from the Data Reader cannot to + * 'read' or 'taken' again. + * Return value provides information about number of samples read, which will + * be <= maxs. Based on the count, the buffer will contain data to be read only + * when valid_data bit in sample info structure is set. + * The buffer required for data values, could be allocated explicitly or can + * use the memory from data reader to prevent copy. In the latter case, buffer and + * sample_info should be returned back, once it is no longer using the Data. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs); + +/** + * @brief Access loaned samples of data reader, readcondition or querycondition. + * + * After dds_take_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs); + +/** + * @brief Take the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition based on mask + * + * When using a readcondition or querycondition, their masks are or'd with the given mask. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_mask( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + uint32_t mask); + +/** + * @brief Access loaned samples of data reader, readcondition or querycondition based on mask. + * + * When using a readcondition or querycondition, their masks are or'd with the given mask. + * + * After dds_take_mask_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_mask_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + uint32_t mask); + +DDS_EXPORT int +dds_takecdr( + dds_entity_t reader_or_condition, + struct ddsi_serdata **buf, + uint32_t maxs, + dds_sample_info_t *si, + uint32_t mask); + +/** + * @brief Access the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition but scoped by the given + * instance handle. + * + * This operation mplements the same functionality as dds_take, except that only data + * scoped to the provided instance handle is taken. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_take_instance( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle); + +/** + * @brief Access loaned samples of data reader, readcondition or querycondition, + * scoped by the given instance handle. + * + * This operation implements the same functionality as dds_take_wl, except that + * only data scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_take_instance_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle); + +/** + * @brief Take the collection of data values (of same type) and sample info from the + * data reader, readcondition or querycondition based on mask and scoped + * by the given instance handle. + * + * This operation implements the same functionality as dds_take_mask, except that only + * data scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] bufsz The size of buffer provided. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples read or an error code. + * + * @retval >=0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_take_instance_mask( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask); + +/** + * @brief Access loaned samples of data reader, readcondition or querycondition based + * on mask and scoped by the given intance handle. + * + * This operation implements the same functionality as dds_take_mask_wl, except that + * only data scoped to the provided instance handle is read. + * + * @param[in] reader_or_condition Reader, readcondition or querycondition entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. + * @param[in] maxs Maximum number of samples to read. + * @param[in] handle Instance handle related to the samples to read. + * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. + * + * @returns A dds_return_t with the number of samples or an error code. + * + * @retval >= 0 + * Number of samples read. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the given arguments is not valid. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + * @retval DDS_RETCODE_PRECONDITION_NOT_MET + * The instance handle has not been registered with this reader. + */ +DDS_EXPORT dds_return_t +dds_take_instance_mask_wl( + dds_entity_t reader_or_condition, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask); + +/* + The read/take next functions return a single sample. The returned sample + has a sample state of NOT_READ, a view state of ANY_VIEW_STATE and an + instance state of ANY_INSTANCE_STATE. +*/ + +/** + * @brief Read, copy and remove the status set for the entity + * + * This operation copies the next, non-previously accessed + * data value and corresponding sample info and removes from + * the data reader. As an entity, only reader is accepted. + * + * @param[in] reader The reader entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_next( + dds_entity_t reader, + void **buf, + dds_sample_info_t *si); + +/** + * @brief Read, copy and remove the status set for the entity + * + * This operation copies the next, non-previously accessed + * data value and corresponding sample info and removes from + * the data reader. As an entity, only reader is accepted. + * + * After dds_take_next_wl function is being called and the data has been handled, + * dds_return_loan function must be called to possibly free memory. + * + * @param[in] reader The reader entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_take_next_wl( + dds_entity_t reader, + void **buf, + dds_sample_info_t *si); + +/** + * @brief Read and copy the status set for the entity + * + * This operation copies the next, non-previously accessed + * data value and corresponding sample info. As an entity, + * only reader is accepted. + * + * @param[in] reader The reader entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_next( + dds_entity_t reader, + void **buf, + dds_sample_info_t *si); + +/** + * @brief Read and copy the status set for the loaned sample + * + * This operation copies the next, non-previously accessed + * data value and corresponding loaned sample info. As an entity, + * only reader is accepted. + * + * After dds_read_next_wl function is being called and the data has been handled, + * dds_return_loan function must be called to possibly free memory. + * + * @param[in] reader The reader entity. + * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). + * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_read_next_wl( + dds_entity_t reader, + void **buf, + dds_sample_info_t *si); + +/** + * @brief Return loaned samples to data-reader or condition associated with a data-reader + * + * Used to release sample buffers returned by a read/take operation. When the application + * provides an empty buffer, memory is allocated and managed by DDS. By calling dds_return_loan, + * the memory is released so that the buffer can be reused during a successive read/take operation. + * When a condition is provided, the reader to which the condition belongs is looked up. + * + * @param[in] rd_or_cnd Reader or condition that belongs to a reader. + * @param[in] buf An array of (pointers to) samples. + * @param[in] bufsz The number of (pointers to) samples stored in buf. + * + * @returns A dds_return_t indicating success or failure + */ +/* TODO: Add list of possible return codes */ +DDS_EXPORT dds_return_t +dds_return_loan( + dds_entity_t reader_or_condition, + void **buf, + int32_t bufsz); + +/* + Instance handle <=> key value mapping. + Functions exactly as read w.r.t. treatment of data + parameter. On output, only key values set. + + T x = { ... }; + T y; + dds_instance_handle_t ih; + ih = dds_lookup_instance (e, &x); + dds_instance_get_key (e, ih, &y); +*/ + +/** + * @brief This operation takes a sample and returns an instance handle to be used for subsequent operations. + * + * @param[in] entity Reader or Writer entity. + * @param[in] data Sample with a key fields set. + * + * @returns instance handle or DDS_HANDLE_NIL if instance could not be found from key. + */ +DDS_EXPORT dds_instance_handle_t +dds_lookup_instance(dds_entity_t entity, const void *data); + +DDS_DEPRECATED_EXPORT dds_instance_handle_t +dds_instance_lookup(dds_entity_t entity, const void *data); + +/** + * @brief This operation takes an instance handle and return a key-value corresponding to it. + * + * @param[in] entity Reader or writer entity. + * @param[in] inst Instance handle. + * @param[out] data pointer to an instance, to which the key ID corresponding to the instance handle will be + * returned, the sample in the instance should be ignored. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * One of the parameters was invalid or the topic does not exist. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + */ +/* TODO: Check return codes for completeness */ +DDS_EXPORT dds_return_t +dds_instance_get_key( + dds_entity_t entity, + dds_instance_handle_t inst, + void *data); + +/** + * @brief Begin coherent publishing or begin accessing a coherent set in a subscriber + * + * Invoking on a Writer or Reader behaves as if dds_begin_coherent was invoked on its parent + * Publisher or Subscriber respectively. + * + * @param[in] entity The entity that is prepared for coherent access. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_ERROR + * An internal error has occurred. + * @retval DDS_RETCODE_BAD_PARAMETER + * The provided entity is invalid or not supported. + */ +DDS_EXPORT dds_return_t +dds_begin_coherent(dds_entity_t entity); + +/** + * @brief End coherent publishing or end accessing a coherent set in a subscriber + * + * Invoking on a Writer or Reader behaves as if dds_end_coherent was invoked on its parent + * Publisher or Subscriber respectively. + * + * @param[in] entity The entity on which coherent access is finished. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The provided entity is invalid or not supported. + */ +DDS_EXPORT dds_return_t +dds_end_coherent(dds_entity_t entity); + +/** + * @brief Trigger DATA_AVAILABLE event on contained readers + * + * The DATA_AVAILABLE event is broadcast to all readers owned by this subscriber that currently + * have new data available. Any on_data_available listener callbacks attached to respective + * readers are invoked. + * + * @param[in] subscriber A valid subscriber handle. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The provided subscriber is invalid. + */ +DDS_EXPORT dds_return_t +dds_notify_readers(dds_entity_t subscriber); + +/** + * @brief Checks whether the entity has one of its enabled statuses triggered. + * + * @param[in] entity Entity for which to check for triggered status. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_return_t +dds_triggered(dds_entity_t entity); + +/** + * @brief Get the topic + * + * This operation returns a topic (handle) when the function call is done + * with reader, writer, read condition or query condition. For instance, it + * will return the topic when it is used for creating the reader or writer. + * For the conditions, it returns the topic that is used for creating the reader + * which was used to create the condition. + * + * @param[in] entity The entity. + * + * @returns A dds_return_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * The operation was successful. + * @retval DDS_RETCODE_BAD_PARAMETER + * The entity parameter is not a valid parameter. + * @retval DDS_RETCODE_ILLEGAL_OPERATION + * The operation is invoked on an inappropriate object. + * @retval DDS_RETCODE_ALREADY_DELETED + * The entity has already been deleted. + */ +DDS_EXPORT dds_entity_t +dds_get_topic(dds_entity_t entity); + +#if defined (__cplusplus) +} +#endif +#endif /* DDS_H */ diff --git a/src/core/ddsc/include/ddsc/dds_public_alloc.h b/src/core/ddsc/include/dds/ddsc/dds_public_alloc.h similarity index 97% rename from src/core/ddsc/include/ddsc/dds_public_alloc.h rename to src/core/ddsc/include/dds/ddsc/dds_public_alloc.h index 647272a..9e66a11 100644 --- a/src/core/ddsc/include/ddsc/dds_public_alloc.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_alloc.h @@ -21,8 +21,9 @@ #ifndef DDS_ALLOC_H #define DDS_ALLOC_H -#include "os/os_public.h" -#include "ddsc/dds_export.h" +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/include/dds/ddsc/dds_public_error.h b/src/core/ddsc/include/dds/ddsc/dds_public_error.h new file mode 100644 index 0000000..b574371 --- /dev/null +++ b/src/core/ddsc/include/dds/ddsc/dds_public_error.h @@ -0,0 +1,51 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +/** @file + * + * @brief DDS C Error API + * + * This header file defines the public API of error values and convenience + * functions in the CycloneDDS C language binding. + */ +#ifndef DDS_ERROR_H +#define DDS_ERROR_H + +#include "dds/export.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/retcode.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +/* Error masks for returned status values */ + +#define DDS_ERR_NR_MASK 0x000000ff +#define DDS_ERR_LINE_MASK 0x003fff00 +#define DDS_ERR_FILE_ID_MASK 0x7fc00000 + +/* Error code handling functions */ + +/** Macro to extract error number */ +#define dds_err_nr(e) ((-(e)) & DDS_ERR_NR_MASK) + +/** Macro to extract line number */ +#define dds_err_line(e) (((-(e)) & DDS_ERR_LINE_MASK) >> 8) + +/** Macro to extract file identifier */ +#define dds_err_file_id(e) (((-(e)) & DDS_ERR_FILE_ID_MASK) >> 22) + +#if defined (__cplusplus) +} +#endif +#endif diff --git a/src/core/ddsc/include/ddsc/dds_public_impl.h b/src/core/ddsc/include/dds/ddsc/dds_public_impl.h similarity index 97% rename from src/core/ddsc/include/ddsc/dds_public_impl.h rename to src/core/ddsc/include/dds/ddsc/dds_public_impl.h index a34959b..923ea24 100644 --- a/src/core/ddsc/include/ddsc/dds_public_impl.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_impl.h @@ -21,10 +21,9 @@ #ifndef DDS_IMPL_H #define DDS_IMPL_H -#include "ddsc/dds_public_alloc.h" -#include "ddsc/dds_public_stream.h" -#include "os/os_public.h" -#include "ddsc/dds_export.h" +#include "dds/export.h" +#include "dds/ddsc/dds_public_alloc.h" +#include "dds/ddsc/dds_public_stream.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/include/ddsc/dds_public_listener.h b/src/core/ddsc/include/dds/ddsc/dds_public_listener.h similarity index 70% rename from src/core/ddsc/include/ddsc/dds_public_listener.h rename to src/core/ddsc/include/dds/ddsc/dds_public_listener.h index e749629..762e72c 100644 --- a/src/core/ddsc/include/ddsc/dds_public_listener.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_listener.h @@ -20,10 +20,9 @@ #ifndef _DDS_PUBLIC_LISTENER_H_ #define _DDS_PUBLIC_LISTENER_H_ -#include "ddsc/dds_export.h" -#include "ddsc/dds_public_impl.h" -#include "ddsc/dds_public_status.h" -#include "os/os_public.h" +#include "dds/export.h" +#include "dds/ddsc/dds_public_impl.h" +#include "dds/ddsc/dds_public_status.h" #if defined (__cplusplus) extern "C" { @@ -55,26 +54,24 @@ typedef struct dds_listener dds_listener_t; * * @return Returns a pointer to the allocated memory for dds_listener_t structure. */ -_Ret_notnull_ -DDS_EXPORT dds_listener_t* dds_create_listener (_In_opt_ void* arg); -_Ret_notnull_ -DDS_DEPRECATED_EXPORT dds_listener_t* dds_listener_create (_In_opt_ void* arg); +DDS_EXPORT dds_listener_t* dds_create_listener (void* arg); +DDS_DEPRECATED_EXPORT dds_listener_t* dds_listener_create (void* arg); /** * @brief Delete the memory allocated to listener structure * * @param[in] listener pointer to the listener struct to delete */ -DDS_EXPORT void dds_delete_listener (_In_ _Post_invalid_ dds_listener_t * __restrict listener); -DDS_DEPRECATED_EXPORT void dds_listener_delete (_In_ _Post_invalid_ dds_listener_t * __restrict listener); +DDS_EXPORT void dds_delete_listener (dds_listener_t * __restrict listener); +DDS_DEPRECATED_EXPORT void dds_listener_delete (dds_listener_t * __restrict listener); /** * @brief Reset the listener structure contents to ::DDS_LUNSET * * @param[in,out] listener pointer to the listener struct to reset */ -DDS_EXPORT void dds_reset_listener (_Out_ dds_listener_t * __restrict listener); -DDS_DEPRECATED_EXPORT void dds_listener_reset (_Out_ dds_listener_t * __restrict listener); +DDS_EXPORT void dds_reset_listener (dds_listener_t * __restrict listener); +DDS_DEPRECATED_EXPORT void dds_listener_reset (dds_listener_t * __restrict listener); /** * @brief Copy the listener callbacks from source to destination @@ -82,8 +79,8 @@ DDS_DEPRECATED_EXPORT void dds_listener_reset (_Out_ dds_listener_t * __restrict * @param[in,out] dst The pointer to the destination listener structure, where the content is to copied * @param[in] src The pointer to the source listener structure to be copied */ -DDS_EXPORT void dds_copy_listener (_Out_ dds_listener_t * __restrict dst, _In_ const dds_listener_t * __restrict src); -DDS_DEPRECATED_EXPORT void dds_listener_copy (_Out_ dds_listener_t * __restrict dst, _In_ const dds_listener_t * __restrict src); +DDS_EXPORT void dds_copy_listener (dds_listener_t * __restrict dst, const dds_listener_t * __restrict src); +DDS_DEPRECATED_EXPORT void dds_listener_copy (dds_listener_t * __restrict dst, const dds_listener_t * __restrict src); /** * @brief Copy the listener callbacks from source to destination, unless already set @@ -94,8 +91,8 @@ DDS_DEPRECATED_EXPORT void dds_listener_copy (_Out_ dds_listener_t * __restrict * @param[in,out] dst The pointer to the destination listener structure, where the content is merged * @param[in] src The pointer to the source listener structure to be copied */ -DDS_EXPORT void dds_merge_listener (_Inout_ dds_listener_t * __restrict dst, _In_ const dds_listener_t * __restrict src); -DDS_DEPRECATED_EXPORT void dds_listener_merge (_Inout_ dds_listener_t * __restrict dst, _In_ const dds_listener_t * __restrict src); +DDS_EXPORT void dds_merge_listener (dds_listener_t * __restrict dst, const dds_listener_t * __restrict src); +DDS_DEPRECATED_EXPORT void dds_listener_merge (dds_listener_t * __restrict dst, const dds_listener_t * __restrict src); /************************************************************************************************ * Setters @@ -107,7 +104,7 @@ DDS_DEPRECATED_EXPORT void dds_listener_merge (_Inout_ dds_listener_t * __restri * @param listener The pointer to the listener structure, where the callback will be set * @param callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_inconsistent_topic (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_inconsistent_topic_fn callback); +DDS_EXPORT void dds_lset_inconsistent_topic (dds_listener_t * __restrict listener, dds_on_inconsistent_topic_fn callback); /** * @brief Set the liveliness_lost callback in the listener structure. @@ -115,7 +112,7 @@ DDS_EXPORT void dds_lset_inconsistent_topic (_Inout_ dds_listener_t * __restrict * @param[out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_liveliness_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_liveliness_lost_fn callback); +DDS_EXPORT void dds_lset_liveliness_lost (dds_listener_t * __restrict listener, dds_on_liveliness_lost_fn callback); /** * @brief Set the offered_deadline_missed callback in the listener structure. @@ -123,7 +120,7 @@ DDS_EXPORT void dds_lset_liveliness_lost (_Inout_ dds_listener_t * __restrict li * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_offered_deadline_missed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_offered_deadline_missed_fn callback); +DDS_EXPORT void dds_lset_offered_deadline_missed (dds_listener_t * __restrict listener, dds_on_offered_deadline_missed_fn callback); /** * @brief Set the offered_incompatible_qos callback in the listener structure. @@ -131,7 +128,7 @@ DDS_EXPORT void dds_lset_offered_deadline_missed (_Inout_ dds_listener_t * __res * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_offered_incompatible_qos (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_offered_incompatible_qos_fn callback); +DDS_EXPORT void dds_lset_offered_incompatible_qos (dds_listener_t * __restrict listener, dds_on_offered_incompatible_qos_fn callback); /** * @brief Set the data_on_readers callback in the listener structure. @@ -139,7 +136,7 @@ DDS_EXPORT void dds_lset_offered_incompatible_qos (_Inout_ dds_listener_t * __re * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_data_on_readers (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_data_on_readers_fn callback); +DDS_EXPORT void dds_lset_data_on_readers (dds_listener_t * __restrict listener, dds_on_data_on_readers_fn callback); /** * @brief Set the sample_lost callback in the listener structure. @@ -147,7 +144,7 @@ DDS_EXPORT void dds_lset_data_on_readers (_Inout_ dds_listener_t * __restrict li * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_sample_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_sample_lost_fn callback); +DDS_EXPORT void dds_lset_sample_lost (dds_listener_t * __restrict listener, dds_on_sample_lost_fn callback); /** * @brief Set the data_available callback in the listener structure. @@ -155,7 +152,7 @@ DDS_EXPORT void dds_lset_sample_lost (_Inout_ dds_listener_t * __restrict listen * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_data_available (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_data_available_fn callback); +DDS_EXPORT void dds_lset_data_available (dds_listener_t * __restrict listener, dds_on_data_available_fn callback); /** * @brief Set the sample_rejected callback in the listener structure. @@ -163,7 +160,7 @@ DDS_EXPORT void dds_lset_data_available (_Inout_ dds_listener_t * __restrict lis * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_sample_rejected (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_sample_rejected_fn callback); +DDS_EXPORT void dds_lset_sample_rejected (dds_listener_t * __restrict listener, dds_on_sample_rejected_fn callback); /** * @brief Set the liveliness_changed callback in the listener structure. @@ -171,7 +168,7 @@ DDS_EXPORT void dds_lset_sample_rejected (_Inout_ dds_listener_t * __restrict li * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_liveliness_changed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_liveliness_changed_fn callback); +DDS_EXPORT void dds_lset_liveliness_changed (dds_listener_t * __restrict listener, dds_on_liveliness_changed_fn callback); /** * @brief Set the requested_deadline_missed callback in the listener structure. @@ -179,7 +176,7 @@ DDS_EXPORT void dds_lset_liveliness_changed (_Inout_ dds_listener_t * __restrict * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_requested_deadline_missed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_requested_deadline_missed_fn callback); +DDS_EXPORT void dds_lset_requested_deadline_missed (dds_listener_t * __restrict listener, dds_on_requested_deadline_missed_fn callback); /** * @brief Set the requested_incompatible_qos callback in the listener structure. @@ -187,7 +184,7 @@ DDS_EXPORT void dds_lset_requested_deadline_missed (_Inout_ dds_listener_t * __r * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_requested_incompatible_qos (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_requested_incompatible_qos_fn callback); +DDS_EXPORT void dds_lset_requested_incompatible_qos (dds_listener_t * __restrict listener, dds_on_requested_incompatible_qos_fn callback); /** * @brief Set the publication_matched callback in the listener structure. @@ -195,7 +192,7 @@ DDS_EXPORT void dds_lset_requested_incompatible_qos (_Inout_ dds_listener_t * __ * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_publication_matched (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_publication_matched_fn callback); +DDS_EXPORT void dds_lset_publication_matched (dds_listener_t * __restrict listener, dds_on_publication_matched_fn callback); /** * @brief Set the subscription_matched callback in the listener structure. @@ -203,7 +200,7 @@ DDS_EXPORT void dds_lset_publication_matched (_Inout_ dds_listener_t * __restric * @param[in,out] listener The pointer to the listener structure, where the callback will be set * @param[in] callback The callback to set in the listener, can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lset_subscription_matched (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_subscription_matched_fn callback); +DDS_EXPORT void dds_lset_subscription_matched (dds_listener_t * __restrict listener, dds_on_subscription_matched_fn callback); /************************************************************************************************ @@ -216,7 +213,7 @@ DDS_EXPORT void dds_lset_subscription_matched (_Inout_ dds_listener_t * __restri * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_inconsistent_topic (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_inconsistent_topic_fn *callback); +DDS_EXPORT void dds_lget_inconsistent_topic (const dds_listener_t * __restrict listener, dds_on_inconsistent_topic_fn *callback); /** * @brief Get the liveliness_lost callback from the listener structure. @@ -224,7 +221,7 @@ DDS_EXPORT void dds_lget_inconsistent_topic (_In_ const dds_listener_t * __restr * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_liveliness_lost (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_liveliness_lost_fn *callback); +DDS_EXPORT void dds_lget_liveliness_lost (const dds_listener_t * __restrict listener, dds_on_liveliness_lost_fn *callback); /** * @brief Get the offered_deadline_missed callback from the listener structure. @@ -232,7 +229,7 @@ DDS_EXPORT void dds_lget_liveliness_lost (_In_ const dds_listener_t * __restrict * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_offered_deadline_missed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_offered_deadline_missed_fn *callback); +DDS_EXPORT void dds_lget_offered_deadline_missed (const dds_listener_t * __restrict listener, dds_on_offered_deadline_missed_fn *callback); /** * @brief Get the offered_incompatible_qos callback from the listener structure. @@ -240,7 +237,7 @@ DDS_EXPORT void dds_lget_offered_deadline_missed (_In_ const dds_listener_t * __ * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_offered_incompatible_qos (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_offered_incompatible_qos_fn *callback); +DDS_EXPORT void dds_lget_offered_incompatible_qos (const dds_listener_t * __restrict listener, dds_on_offered_incompatible_qos_fn *callback); /** * @brief Get the data_on_readers callback from the listener structure. @@ -248,7 +245,7 @@ DDS_EXPORT void dds_lget_offered_incompatible_qos (_In_ const dds_listener_t * _ * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_data_on_readers (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_data_on_readers_fn *callback); +DDS_EXPORT void dds_lget_data_on_readers (const dds_listener_t * __restrict listener, dds_on_data_on_readers_fn *callback); /** * @brief Get the sample_lost callback from the listener structure. @@ -256,7 +253,7 @@ DDS_EXPORT void dds_lget_data_on_readers (_In_ const dds_listener_t * __restrict * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_sample_lost (_In_ const dds_listener_t *__restrict listener, _Outptr_result_maybenull_ dds_on_sample_lost_fn *callback); +DDS_EXPORT void dds_lget_sample_lost (const dds_listener_t *__restrict listener, dds_on_sample_lost_fn *callback); /** * @brief Get the data_available callback from the listener structure. @@ -264,7 +261,7 @@ DDS_EXPORT void dds_lget_sample_lost (_In_ const dds_listener_t *__restrict list * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_data_available (_In_ const dds_listener_t *__restrict listener, _Outptr_result_maybenull_ dds_on_data_available_fn *callback); +DDS_EXPORT void dds_lget_data_available (const dds_listener_t *__restrict listener, dds_on_data_available_fn *callback); /** * @brief Get the sample_rejected callback from the listener structure. @@ -272,7 +269,7 @@ DDS_EXPORT void dds_lget_data_available (_In_ const dds_listener_t *__restrict l * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_sample_rejected (_In_ const dds_listener_t *__restrict listener, _Outptr_result_maybenull_ dds_on_sample_rejected_fn *callback); +DDS_EXPORT void dds_lget_sample_rejected (const dds_listener_t *__restrict listener, dds_on_sample_rejected_fn *callback); /** * @brief Get the liveliness_changed callback from the listener structure. @@ -280,7 +277,7 @@ DDS_EXPORT void dds_lget_sample_rejected (_In_ const dds_listener_t *__restrict * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_liveliness_changed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_liveliness_changed_fn *callback); +DDS_EXPORT void dds_lget_liveliness_changed (const dds_listener_t * __restrict listener, dds_on_liveliness_changed_fn *callback); /** * @brief Get the requested_deadline_missed callback from the listener structure. @@ -288,7 +285,7 @@ DDS_EXPORT void dds_lget_liveliness_changed (_In_ const dds_listener_t * __restr * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_requested_deadline_missed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_requested_deadline_missed_fn *callback); +DDS_EXPORT void dds_lget_requested_deadline_missed (const dds_listener_t * __restrict listener, dds_on_requested_deadline_missed_fn *callback); /** * @brief Get the requested_incompatible_qos callback from the listener structure. @@ -296,7 +293,7 @@ DDS_EXPORT void dds_lget_requested_deadline_missed (_In_ const dds_listener_t * * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_requested_incompatible_qos (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_requested_incompatible_qos_fn *callback); +DDS_EXPORT void dds_lget_requested_incompatible_qos (const dds_listener_t * __restrict listener, dds_on_requested_incompatible_qos_fn *callback); /** * @brief Get the publication_matched callback from the listener structure. @@ -304,7 +301,7 @@ DDS_EXPORT void dds_lget_requested_incompatible_qos (_In_ const dds_listener_t * * @param[in] listener The pointer to the listener structure, where the callback will be retrieved from * @param[in,out] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer */ -DDS_EXPORT void dds_lget_publication_matched (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_publication_matched_fn *callback); +DDS_EXPORT void dds_lget_publication_matched (const dds_listener_t * __restrict listener, dds_on_publication_matched_fn *callback); /** * @brief Get the subscription_matched callback from the listener structure. @@ -312,7 +309,7 @@ DDS_EXPORT void dds_lget_publication_matched (_In_ const dds_listener_t * __rest * @param[in] callback Pointer where the retrieved callback can be stored; can be NULL, ::DDS_LUNSET or a valid callback pointer * @param[in,out] listener The pointer to the listener structure, where the callback will be retrieved from */ -DDS_EXPORT void dds_lget_subscription_matched (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_subscription_matched_fn *callback); +DDS_EXPORT void dds_lget_subscription_matched (const dds_listener_t * __restrict listener, dds_on_subscription_matched_fn *callback); #if defined (__cplusplus) } diff --git a/src/core/ddsc/include/ddsc/dds_public_qos.h b/src/core/ddsc/include/dds/ddsc/dds_public_qos.h similarity index 73% rename from src/core/ddsc/include/ddsc/dds_public_qos.h rename to src/core/ddsc/include/dds/ddsc/dds_public_qos.h index 8f58517..4ffceb4 100644 --- a/src/core/ddsc/include/ddsc/dds_public_qos.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_qos.h @@ -20,8 +20,7 @@ #ifndef DDS_QOS_H #define DDS_QOS_H -#include "os/os_public.h" -#include "ddsc/dds_export.h" +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -142,10 +141,8 @@ dds_presentation_access_scope_kind_t; * * @returns - Pointer to the initialized dds_qos_t structure, NULL if unsuccessful. */ -_Ret_notnull_ DDS_EXPORT dds_qos_t * dds_create_qos (void); -_Ret_notnull_ DDS_DEPRECATED_EXPORT dds_qos_t * dds_qos_create (void); @@ -154,14 +151,11 @@ dds_qos_t * dds_qos_create (void); * * @param[in] qos - Pointer to dds_qos_t structure */ -DDS_EXPORT -void dds_delete_qos ( - _In_ _Post_invalid_ dds_qos_t * __restrict qos -); -DDS_DEPRECATED_EXPORT -void dds_qos_delete ( - _In_ _Post_invalid_ dds_qos_t * __restrict qos -); +DDS_EXPORT void +dds_delete_qos (dds_qos_t * __restrict qos); + +DDS_DEPRECATED_EXPORT void +dds_qos_delete (dds_qos_t * __restrict qos); /** * @brief Reset a QoS-policies structure to default values @@ -169,11 +163,10 @@ void dds_qos_delete ( * @param[in,out] qos - Pointer to the dds_qos_t structure */ DDS_EXPORT void -dds_reset_qos( - _Out_ dds_qos_t * __restrict qos); +dds_reset_qos(dds_qos_t * __restrict qos); + DDS_DEPRECATED_EXPORT -void dds_qos_reset ( - _Out_ dds_qos_t * __restrict qos +void dds_qos_reset (dds_qos_t * __restrict qos ); /** @@ -184,16 +177,11 @@ void dds_qos_reset ( * * @returns - Return-code indicating success or failure */ -DDS_EXPORT -dds_return_t dds_copy_qos ( - _Out_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src -); -DDS_DEPRECATED_EXPORT -dds_return_t dds_qos_copy ( - _Out_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src -); +DDS_EXPORT dds_return_t +dds_copy_qos (dds_qos_t * __restrict dst, const dds_qos_t * __restrict src); + +DDS_DEPRECATED_EXPORT dds_return_t +dds_qos_copy (dds_qos_t * __restrict dst, const dds_qos_t * __restrict src); /** * @brief Copy all QoS-policies from one structure to another, unless already set @@ -203,18 +191,11 @@ dds_return_t dds_qos_copy ( * @param[in,out] dst - Pointer to the destination qos structure * @param[in] src - Pointer to the source qos structure */ -DDS_EXPORT -void dds_merge_qos -( - _Inout_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src -); -DDS_DEPRECATED_EXPORT -void dds_qos_merge -( - _Inout_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src -); +DDS_EXPORT void +dds_merge_qos (dds_qos_t * __restrict dst, const dds_qos_t * __restrict src); + +DDS_DEPRECATED_EXPORT void +dds_qos_merge (dds_qos_t * __restrict dst, const dds_qos_t * __restrict src); /** * @brief Copy all QoS-policies from one structure to another, unless already set @@ -224,12 +205,8 @@ void dds_qos_merge * @param[in,out] dst - Pointer to the destination qos structure * @param[in] src - Pointer to the source qos structure */ -DDS_EXPORT -bool dds_qos_equal -( - _In_ const dds_qos_t * __restrict a, - _In_ const dds_qos_t * __restrict b -); +DDS_EXPORT bool +dds_qos_equal (const dds_qos_t * __restrict a, const dds_qos_t * __restrict b); /** * @brief Set the userdata of a qos structure. @@ -238,13 +215,11 @@ bool dds_qos_equal * @param[in] value - Pointer to the userdata * @param[in] sz - Size of userdata stored in value */ -DDS_EXPORT -void dds_qset_userdata -( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz -); +DDS_EXPORT void +dds_qset_userdata ( + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz); /** * @brief Set the topicdata of a qos structure. @@ -253,13 +228,11 @@ void dds_qset_userdata * @param[in] value - Pointer to the topicdata * @param[in] sz - Size of the topicdata stored in value */ -DDS_EXPORT -void dds_qset_topicdata -( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz -); +DDS_EXPORT void +dds_qset_topicdata ( + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz); /** * @brief Set the groupdata of a qos structure. @@ -268,13 +241,11 @@ void dds_qset_topicdata * @param[in] value - Pointer to the group data * @param[in] sz - Size of groupdata stored in value */ -DDS_EXPORT -void dds_qset_groupdata -( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz -); +DDS_EXPORT void +dds_qset_groupdata ( + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz); /** * @brief Set the durability policy of a qos structure. @@ -282,12 +253,8 @@ void dds_qset_groupdata * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] kind - Durability kind value \ref DCPS_QoS_Durability */ -DDS_EXPORT -void dds_qset_durability -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_DURABILITY_VOLATILE, DDS_DURABILITY_PERSISTENT) dds_durability_kind_t kind -); +DDS_EXPORT void +dds_qset_durability (dds_qos_t * __restrict qos, dds_durability_kind_t kind); /** * @brief Set the history policy of a qos structure. @@ -296,13 +263,11 @@ void dds_qset_durability * @param[in] kind - History kind value \ref DCPS_QoS_History * @param[in] depth - History depth value \ref DCPS_QoS_History */ -DDS_EXPORT -void dds_qset_history -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_HISTORY_KEEP_LAST, DDS_HISTORY_KEEP_ALL) dds_history_kind_t kind, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t depth -); +DDS_EXPORT void +dds_qset_history ( + dds_qos_t * __restrict qos, + dds_history_kind_t kind, + int32_t depth); /** * @brief Set the resource limits policy of a qos structure. @@ -312,15 +277,12 @@ void dds_qset_history * @param[in] max_instances - Number of instances resource-limit value * @param[in] max_samples_per_instance - Number of samples per instance resource-limit value */ -DDS_EXPORT -void dds_qset_resource_limits -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_instances, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples_per_instance -); - +DDS_EXPORT void +dds_qset_resource_limits ( + dds_qos_t * __restrict qos, + int32_t max_samples, + int32_t max_instances, + int32_t max_samples_per_instance); /** * @brief Set the presentation policy of a qos structure. @@ -330,13 +292,12 @@ void dds_qset_resource_limits * @param[in] coherent_access - Coherent access enable value * @param[in] ordered_access - Ordered access enable value */ -DDS_EXPORT void dds_qset_presentation -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_PRESENTATION_INSTANCE, DDS_PRESENTATION_GROUP) dds_presentation_access_scope_kind_t access_scope, - _In_ bool coherent_access, - _In_ bool ordered_access -); +DDS_EXPORT void +dds_qset_presentation ( + dds_qos_t * __restrict qos, + dds_presentation_access_scope_kind_t access_scope, + bool coherent_access, + bool ordered_access); /** * @brief Set the lifespan policy of a qos structure. @@ -344,12 +305,10 @@ DDS_EXPORT void dds_qset_presentation * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] lifespan - Lifespan duration (expiration time relative to source timestamp of a sample) */ -DDS_EXPORT -void dds_qset_lifespan -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t lifespan -); +DDS_EXPORT void +dds_qset_lifespan ( + dds_qos_t * __restrict qos, + dds_duration_t lifespan); /** * @brief Set the deadline policy of a qos structure. @@ -357,12 +316,10 @@ void dds_qset_lifespan * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] deadline - Deadline duration */ -DDS_EXPORT -void dds_qset_deadline -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t deadline -); +DDS_EXPORT void +dds_qset_deadline ( + dds_qos_t * __restrict qos, + dds_duration_t deadline); /** * @brief Set the latency-budget policy of a qos structure @@ -370,12 +327,10 @@ void dds_qset_deadline * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] duration - Latency budget duration */ -DDS_EXPORT -void dds_qset_latency_budget -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t duration -); +DDS_EXPORT void +dds_qset_latency_budget ( + dds_qos_t * __restrict qos, + dds_duration_t duration); /** * @brief Set the ownership policy of a qos structure @@ -383,12 +338,10 @@ void dds_qset_latency_budget * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] kind - Ownership kind */ -DDS_EXPORT -void dds_qset_ownership -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_OWNERSHIP_SHARED, DDS_OWNERSHIP_EXCLUSIVE) dds_ownership_kind_t kind -); +DDS_EXPORT void +dds_qset_ownership ( + dds_qos_t * __restrict qos, + dds_ownership_kind_t kind); /** * @brief Set the ownership strength policy of a qos structure @@ -396,12 +349,8 @@ void dds_qset_ownership * param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * param[in] value - Ownership strength value */ -DDS_EXPORT -void dds_qset_ownership_strength -( - _Inout_ dds_qos_t * __restrict qos, - _In_ int32_t value -); +DDS_EXPORT void +dds_qset_ownership_strength (dds_qos_t * __restrict qos, int32_t value); /** * @brief Set the liveliness policy of a qos structure @@ -410,13 +359,11 @@ void dds_qset_ownership_strength * param[in] kind - Liveliness kind * param[in[ lease_duration - Lease duration */ -DDS_EXPORT -void dds_qset_liveliness -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_LIVELINESS_AUTOMATIC, DDS_LIVELINESS_MANUAL_BY_TOPIC) dds_liveliness_kind_t kind, - _In_range_(0, DDS_INFINITY) dds_duration_t lease_duration -); +DDS_EXPORT void +dds_qset_liveliness ( + dds_qos_t * __restrict qos, + dds_liveliness_kind_t kind, + dds_duration_t lease_duration); /** * @brief Set the time-based filter policy of a qos structure @@ -424,12 +371,10 @@ void dds_qset_liveliness * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] minimum_separation - Minimum duration between sample delivery for an instance */ -DDS_EXPORT -void dds_qset_time_based_filter -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t minimum_separation -); +DDS_EXPORT void +dds_qset_time_based_filter ( + dds_qos_t * __restrict qos, + dds_duration_t minimum_separation); /** * @brief Set the partition policy of a qos structure @@ -438,13 +383,11 @@ void dds_qset_time_based_filter * @param[in] n - Number of partitions stored in ps * @param[in[ ps - Pointer to string(s) storing partition name(s) */ -DDS_EXPORT -void dds_qset_partition -( - _Inout_ dds_qos_t * __restrict qos, - _In_ uint32_t n, - _In_count_(n) _Deref_pre_z_ const char ** __restrict ps -); +DDS_EXPORT void +dds_qset_partition ( + dds_qos_t * __restrict qos, + uint32_t n, + const char ** __restrict ps); /** * @brief Set the reliability policy of a qos structure @@ -453,13 +396,11 @@ void dds_qset_partition * @param[in] kind - Reliability kind * @param[in] max_blocking_time - Max blocking duration applied when kind is reliable. */ -DDS_EXPORT -void dds_qset_reliability -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_RELIABILITY_BEST_EFFORT, DDS_RELIABILITY_RELIABLE) dds_reliability_kind_t kind, - _In_range_(0, DDS_INFINITY) dds_duration_t max_blocking_time -); +DDS_EXPORT void +dds_qset_reliability ( + dds_qos_t * __restrict qos, + dds_reliability_kind_t kind, + dds_duration_t max_blocking_time); /** * @brief Set the transport-priority policy of a qos structure @@ -467,12 +408,8 @@ void dds_qset_reliability * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] value - Priority value */ -DDS_EXPORT -void dds_qset_transport_priority -( - _Inout_ dds_qos_t * __restrict qos, - _In_ int32_t value -); +DDS_EXPORT void +dds_qset_transport_priority (dds_qos_t * __restrict qos, int32_t value); /** * @brief Set the destination-order policy of a qos structure @@ -480,13 +417,10 @@ void dds_qset_transport_priority * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] kind - Destination-order kind */ -DDS_EXPORT -void dds_qset_destination_order -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_DESTINATIONORDER_BY_RECEPTION_TIMESTAMP, - DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP) dds_destination_order_kind_t kind -); +DDS_EXPORT void +dds_qset_destination_order ( + dds_qos_t * __restrict qos, + dds_destination_order_kind_t kind); /** * @brief Set the writer data-lifecycle policy of a qos structure @@ -494,12 +428,8 @@ void dds_qset_destination_order * @param[in,out] qos - Pointer to a dds_qos_t structure that will store the policy * @param[in] autodispose_unregistered_instances - Automatic disposal of unregistered instances */ -DDS_EXPORT -void dds_qset_writer_data_lifecycle -( - _Inout_ dds_qos_t * __restrict qos, - _In_ bool autodispose -); +DDS_EXPORT void +dds_qset_writer_data_lifecycle (dds_qos_t * __restrict qos, bool autodispose); /** * @brief Set the reader data-lifecycle policy of a qos structure @@ -508,13 +438,11 @@ void dds_qset_writer_data_lifecycle * @param[in] autopurge_nowriter_samples_delay - Delay for purging of samples from instances in a no-writers state * @param[in] autopurge_disposed_samples_delay - Delay for purging of samples from disposed instances */ -DDS_EXPORT -void dds_qset_reader_data_lifecycle -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t autopurge_nowriter_samples_delay, - _In_range_(0, DDS_INFINITY) dds_duration_t autopurge_disposed_samples_delay -); +DDS_EXPORT void +dds_qset_reader_data_lifecycle ( + dds_qos_t * __restrict qos, + dds_duration_t autopurge_nowriter_samples_delay, + dds_duration_t autopurge_disposed_samples_delay); /** * @brief Set the durability-service policy of a qos structure @@ -527,17 +455,15 @@ void dds_qset_reader_data_lifecycle * @param[in] max_instances - Number of instances resource-limit policy applied by the durability service * @param[in] max_samples_per_instance - Number of samples per instance resource-limit policy applied by the durability service */ -DDS_EXPORT -void dds_qset_durability_service -( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t service_cleanup_delay, - _In_range_(DDS_HISTORY_KEEP_LAST, DDS_HISTORY_KEEP_ALL) dds_history_kind_t history_kind, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t history_depth, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_instances, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples_per_instance -); +DDS_EXPORT void +dds_qset_durability_service ( + dds_qos_t * __restrict qos, + dds_duration_t service_cleanup_delay, + dds_history_kind_t history_kind, + int32_t history_depth, + int32_t max_samples, + int32_t max_instances, + int32_t max_samples_per_instance); /** * @brief Get the userdata from a qos structure @@ -603,7 +529,12 @@ DDS_EXPORT bool dds_qget_history (const dds_qos_t * __restrict qos, dds_history_ * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_resource_limits (const dds_qos_t * __restrict qos, int32_t *max_samples, int32_t *max_instances, int32_t *max_samples_per_instance); +DDS_EXPORT bool +dds_qget_resource_limits ( + const dds_qos_t * __restrict qos, + int32_t *max_samples, + int32_t *max_instances, + int32_t *max_samples_per_instance); /** * @brief Get the presentation policy from a qos structure @@ -615,7 +546,12 @@ DDS_EXPORT bool dds_qget_resource_limits (const dds_qos_t * __restrict qos, int3 * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_presentation (const dds_qos_t * __restrict qos, dds_presentation_access_scope_kind_t *access_scope, bool *coherent_access, bool *ordered_access); +DDS_EXPORT bool +dds_qget_presentation ( + const dds_qos_t * __restrict qos, + dds_presentation_access_scope_kind_t *access_scope, + bool *coherent_access, + bool *ordered_access); /** * @brief Get the lifespan policy from a qos structure @@ -625,7 +561,10 @@ DDS_EXPORT bool dds_qget_presentation (const dds_qos_t * __restrict qos, dds_pre * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_lifespan (const dds_qos_t * __restrict qos, dds_duration_t *lifespan); +DDS_EXPORT bool +dds_qget_lifespan ( + const dds_qos_t * __restrict qos, + dds_duration_t *lifespan); /** * @brief Get the deadline policy from a qos structure @@ -635,7 +574,10 @@ DDS_EXPORT bool dds_qget_lifespan (const dds_qos_t * __restrict qos, dds_duratio * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_deadline (const dds_qos_t * __restrict qos, dds_duration_t *deadline); +DDS_EXPORT bool +dds_qget_deadline ( + const dds_qos_t * __restrict qos, + dds_duration_t *deadline); /** * @brief Get the latency-budget policy from a qos structure @@ -645,7 +587,10 @@ DDS_EXPORT bool dds_qget_deadline (const dds_qos_t * __restrict qos, dds_duratio * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_latency_budget (const dds_qos_t * __restrict qos, dds_duration_t *duration); +DDS_EXPORT bool +dds_qget_latency_budget ( + const dds_qos_t * __restrict qos, + dds_duration_t *duration); /** * @brief Get the ownership policy from a qos structure @@ -655,7 +600,10 @@ DDS_EXPORT bool dds_qget_latency_budget (const dds_qos_t * __restrict qos, dds_d * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_ownership (const dds_qos_t * __restrict qos, dds_ownership_kind_t *kind); +DDS_EXPORT bool +dds_qget_ownership ( + const dds_qos_t * __restrict qos, + dds_ownership_kind_t *kind); /** * @brief Get the ownership strength qos policy @@ -665,7 +613,10 @@ DDS_EXPORT bool dds_qget_ownership (const dds_qos_t * __restrict qos, dds_owners * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_ownership_strength (const dds_qos_t * __restrict qos, int32_t *value); +DDS_EXPORT bool +dds_qget_ownership_strength ( + const dds_qos_t * __restrict qos, + int32_t *value); /** * @brief Get the liveliness qos policy @@ -676,7 +627,11 @@ DDS_EXPORT bool dds_qget_ownership_strength (const dds_qos_t * __restrict qos, i * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_liveliness (const dds_qos_t * __restrict qos, dds_liveliness_kind_t *kind, dds_duration_t *lease_duration); +DDS_EXPORT bool +dds_qget_liveliness ( + const dds_qos_t * __restrict qos, + dds_liveliness_kind_t *kind, + dds_duration_t *lease_duration); /** * @brief Get the time-based filter qos policy @@ -686,7 +641,10 @@ DDS_EXPORT bool dds_qget_liveliness (const dds_qos_t * __restrict qos, dds_livel * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_time_based_filter (const dds_qos_t * __restrict qos, dds_duration_t *minimum_separation); +DDS_EXPORT bool +dds_qget_time_based_filter ( + const dds_qos_t * __restrict qos, + dds_duration_t *minimum_separation); /** * @brief Get the partition qos policy @@ -697,7 +655,11 @@ DDS_EXPORT bool dds_qget_time_based_filter (const dds_qos_t * __restrict qos, dd * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_partition (const dds_qos_t * __restrict qos, uint32_t *n, char ***ps); +DDS_EXPORT bool +dds_qget_partition ( + const dds_qos_t * __restrict qos, + uint32_t *n, + char ***ps); /** * @brief Get the reliability qos policy @@ -708,7 +670,11 @@ DDS_EXPORT bool dds_qget_partition (const dds_qos_t * __restrict qos, uint32_t * * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_reliability (const dds_qos_t * __restrict qos, dds_reliability_kind_t *kind, dds_duration_t *max_blocking_time); +DDS_EXPORT bool +dds_qget_reliability ( + const dds_qos_t * __restrict qos, + dds_reliability_kind_t *kind, + dds_duration_t *max_blocking_time); /** * @brief Get the transport priority qos policy @@ -718,7 +684,10 @@ DDS_EXPORT bool dds_qget_reliability (const dds_qos_t * __restrict qos, dds_reli * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_transport_priority (const dds_qos_t * __restrict qos, int32_t *value); +DDS_EXPORT bool +dds_qget_transport_priority ( + const dds_qos_t * __restrict qos, + int32_t *value); /** * @brief Get the destination-order qos policy @@ -728,7 +697,10 @@ DDS_EXPORT bool dds_qget_transport_priority (const dds_qos_t * __restrict qos, i * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_destination_order (const dds_qos_t * __restrict qos, dds_destination_order_kind_t *kind); +DDS_EXPORT bool +dds_qget_destination_order ( + const dds_qos_t * __restrict qos, + dds_destination_order_kind_t *kind); /** * @brief Get the writer data-lifecycle qos policy @@ -738,7 +710,10 @@ DDS_EXPORT bool dds_qget_destination_order (const dds_qos_t * __restrict qos, dd * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_writer_data_lifecycle (const dds_qos_t * __restrict qos, bool *autodispose); +DDS_EXPORT bool +dds_qget_writer_data_lifecycle ( + const dds_qos_t * __restrict qos, + bool *autodispose); /** * @brief Get the reader data-lifecycle qos policy @@ -749,7 +724,11 @@ DDS_EXPORT bool dds_qget_writer_data_lifecycle (const dds_qos_t * __restrict qos * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_reader_data_lifecycle (const dds_qos_t * __restrict qos, dds_duration_t *autopurge_nowriter_samples_delay, dds_duration_t *autopurge_disposed_samples_delay); +DDS_EXPORT bool +dds_qget_reader_data_lifecycle ( + const dds_qos_t * __restrict qos, + dds_duration_t *autopurge_nowriter_samples_delay, + dds_duration_t *autopurge_disposed_samples_delay); /** * @brief Get the durability-service qos policy values. @@ -764,7 +743,15 @@ DDS_EXPORT bool dds_qget_reader_data_lifecycle (const dds_qos_t * __restrict qos * * @returns - false iff any of the arguments is invalid or the qos is not present in the qos object */ -DDS_EXPORT bool dds_qget_durability_service (const dds_qos_t * __restrict qos, dds_duration_t *service_cleanup_delay, dds_history_kind_t *history_kind, int32_t *history_depth, int32_t *max_samples, int32_t *max_instances, int32_t *max_samples_per_instance); +DDS_EXPORT bool +dds_qget_durability_service ( + const dds_qos_t * __restrict qos, + dds_duration_t *service_cleanup_delay, + dds_history_kind_t *history_kind, + int32_t *history_depth, + int32_t *max_samples, + int32_t *max_instances, + int32_t *max_samples_per_instance); #if defined (__cplusplus) } diff --git a/src/core/ddsc/include/ddsc/dds_public_status.h b/src/core/ddsc/include/dds/ddsc/dds_public_status.h similarity index 88% rename from src/core/ddsc/include/ddsc/dds_public_status.h rename to src/core/ddsc/include/dds/ddsc/dds_public_status.h index aa79bcd..ce9ae79 100644 --- a/src/core/ddsc/include/ddsc/dds_public_status.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_status.h @@ -20,8 +20,7 @@ #ifndef DDS_STATUS_H #define DDS_STATUS_H -#include "os/os_public.h" -#include "ddsc/dds_export.h" +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -197,11 +196,10 @@ dds_inconsistent_topic_status_t; * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) DDS_EXPORT dds_return_t dds_get_inconsistent_topic_status ( - _In_ dds_entity_t topic, - _Out_opt_ dds_inconsistent_topic_status_t * status); + dds_entity_t topic, + dds_inconsistent_topic_status_t * status); /** * @brief Get PUBLICATION_MATCHED status @@ -225,11 +223,10 @@ dds_get_inconsistent_topic_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) DDS_EXPORT dds_return_t dds_get_publication_matched_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_publication_matched_status_t * status); + dds_entity_t writer, + dds_publication_matched_status_t * status); /** * @brief Get LIVELINESS_LOST status @@ -253,10 +250,10 @@ dds_get_publication_matched_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) -DDS_EXPORT dds_return_t dds_get_liveliness_lost_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_liveliness_lost_status_t * status); +DDS_EXPORT dds_return_t +dds_get_liveliness_lost_status ( + dds_entity_t writer, + dds_liveliness_lost_status_t * status); /** * @brief Get OFFERED_DEADLINE_MISSED status @@ -280,11 +277,10 @@ DDS_EXPORT dds_return_t dds_get_liveliness_lost_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) DDS_EXPORT dds_return_t dds_get_offered_deadline_missed_status( - _In_ dds_entity_t writer, - _Out_opt_ dds_offered_deadline_missed_status_t *status); + dds_entity_t writer, + dds_offered_deadline_missed_status_t *status); /** * @brief Get OFFERED_INCOMPATIBLE_QOS status @@ -308,11 +304,10 @@ dds_get_offered_deadline_missed_status( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) DDS_EXPORT dds_return_t dds_get_offered_incompatible_qos_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_offered_incompatible_qos_status_t * status); + dds_entity_t writer, + dds_offered_incompatible_qos_status_t * status); /** * @brief Get SUBSCRIPTION_MATCHED status @@ -336,11 +331,10 @@ dds_get_offered_incompatible_qos_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_subscription_matched_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_subscription_matched_status_t * status); + dds_entity_t reader, + dds_subscription_matched_status_t * status); /** * @brief Get LIVELINESS_CHANGED status @@ -364,11 +358,10 @@ dds_get_subscription_matched_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_liveliness_changed_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_liveliness_changed_status_t * status); + dds_entity_t reader, + dds_liveliness_changed_status_t * status); /** * @brief Get SAMPLE_REJECTED status @@ -392,11 +385,10 @@ dds_get_liveliness_changed_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_sample_rejected_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_sample_rejected_status_t * status); + dds_entity_t reader, + dds_sample_rejected_status_t * status); /** * @brief Get SAMPLE_LOST status @@ -421,11 +413,10 @@ dds_get_sample_rejected_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_sample_lost_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_sample_lost_status_t * status); + dds_entity_t reader, + dds_sample_lost_status_t * status); /** * @brief Get REQUESTED_DEADLINE_MISSED status @@ -450,11 +441,10 @@ dds_get_sample_lost_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_requested_deadline_missed_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_requested_deadline_missed_status_t * status); + dds_entity_t reader, + dds_requested_deadline_missed_status_t * status); /** * @brief Get REQUESTED_INCOMPATIBLE_QOS status @@ -479,11 +469,10 @@ dds_get_requested_deadline_missed_status ( * @retval DDS_RETCODE_ALREADY_DELETED * The entity has already been deleted. */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_return_t dds_get_requested_incompatible_qos_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_requested_incompatible_qos_status_t * status); + dds_entity_t reader, + dds_requested_incompatible_qos_status_t * status); #if defined (__cplusplus) } diff --git a/src/core/ddsc/include/ddsc/dds_public_stream.h b/src/core/ddsc/include/dds/ddsc/dds_public_stream.h similarity index 98% rename from src/core/ddsc/include/ddsc/dds_public_stream.h rename to src/core/ddsc/include/dds/ddsc/dds_public_stream.h index 94ad667..6a3d56f 100644 --- a/src/core/ddsc/include/ddsc/dds_public_stream.h +++ b/src/core/ddsc/include/dds/ddsc/dds_public_stream.h @@ -20,9 +20,11 @@ #ifndef DDS_STREAM_H #define DDS_STREAM_H -#include "os/os_public.h" #include -#include "ddsc/dds_export.h" +#include +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/include/ddsc/dds.h b/src/core/ddsc/include/ddsc/dds.h index 0612ada..60a9b3c 100644 --- a/src/core/ddsc/include/ddsc/dds.h +++ b/src/core/ddsc/include/ddsc/dds.h @@ -9,3303 +9,12 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef DDS_H -#define DDS_H +#ifndef DDSC_DDS_H +#define DDSC_DDS_H -/** @file - * - * @brief Eclipse Cyclone DDS C header - */ +/* All header files distributed with Cyclone DDS reside in dds. This file is + merely a proxy for dds/dds.h and must be considered deprecated. */ +#include "dds/dds.h" -#if defined (__cplusplus) -#define restrict -#endif +#endif /* DDSC_DDS_H */ -#include "os/os_public.h" -#include "ddsc/dds_export.h" - -/* TODO: Move to appropriate location */ -/** - * Return code indicating success (DDS_RETCODE_OK) or failure. If a given - * operation failed the value will be a unique error code and dds_err_nr() must - * be used to extract the DDS_RETCODE_* value. - */ -typedef _Return_type_success_(return >= 0) int32_t dds_return_t; -/** - * Handle to an entity. A valid entity handle will always have a positive - * integer value. Should the value be negative, the value represents a unique - * error code. dds_err_nr() can be used to extract the DDS_RETCODE_* value. - */ -typedef _Return_type_success_(return > 0) int32_t dds_entity_t; - -/* Sub components */ - -#include "ddsc/dds_public_stream.h" -#include "ddsc/dds_public_impl.h" -#include "ddsc/dds_public_alloc.h" -#include "ddsc/dds_public_time.h" -#include "ddsc/dds_public_qos.h" -#include "ddsc/dds_public_error.h" -#include "ddsc/dds_public_status.h" -#include "ddsc/dds_public_listener.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -struct ddsi_serdata; - -/** - * @brief Returns the default domain identifier. - * - * The default domain identifier can be configured in the configuration file - * or be set through an evironment variable ({DDSC_PROJECT_NAME_NOSPACE_CAPS}_DOMAIN). - * - * @returns Default domain identifier - */ -DDS_EXPORT dds_domainid_t dds_domain_default (void); - -/* @defgroup builtintopic_constants Convenience constants for referring to builtin topics - * - * These constants can be used in place of an actual dds_topic_t, when creating - * readers or writers for builtin-topics. - * - * @{ - */ -extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSPARTICIPANT; -extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSTOPIC; -extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSPUBLICATION; -extern DDS_EXPORT const dds_entity_t DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION; -/** @}*/ - -/** @name Communication Status definitions - @{**/ -/** Another topic exists with the same name but with different characteristics. */ -typedef enum dds_status_id { - DDS_INCONSISTENT_TOPIC_STATUS_ID, - DDS_OFFERED_DEADLINE_MISSED_STATUS_ID, - DDS_REQUESTED_DEADLINE_MISSED_STATUS_ID, - DDS_OFFERED_INCOMPATIBLE_QOS_STATUS_ID, - DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS_ID, - DDS_SAMPLE_LOST_STATUS_ID, - DDS_SAMPLE_REJECTED_STATUS_ID, - DDS_DATA_ON_READERS_STATUS_ID, - DDS_DATA_AVAILABLE_STATUS_ID, - DDS_LIVELINESS_LOST_STATUS_ID, - DDS_LIVELINESS_CHANGED_STATUS_ID, - DDS_PUBLICATION_MATCHED_STATUS_ID, - DDS_SUBSCRIPTION_MATCHED_STATUS_ID -} -dds_status_id_t; -#define DDS_INCONSISTENT_TOPIC_STATUS (1u << DDS_INCONSISTENT_TOPIC_STATUS_ID) -/** The deadline that the writer has committed through its deadline QoS policy was not respected for a specific instance. */ -#define DDS_OFFERED_DEADLINE_MISSED_STATUS (1u << DDS_OFFERED_DEADLINE_MISSED_STATUS_ID) -/** The deadline that the reader was expecting through its deadline QoS policy was not respected for a specific instance. */ -#define DDS_REQUESTED_DEADLINE_MISSED_STATUS (1u << DDS_REQUESTED_DEADLINE_MISSED_STATUS_ID) -/** A QoS policy setting was incompatible with what was requested. */ -#define DDS_OFFERED_INCOMPATIBLE_QOS_STATUS (1u << DDS_OFFERED_INCOMPATIBLE_QOS_STATUS_ID) -/** A QoS policy setting was incompatible with what is offered. */ -#define DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS (1u << DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS_ID) -/** A sample has been lost (never received). */ -#define DDS_SAMPLE_LOST_STATUS (1u << DDS_SAMPLE_LOST_STATUS_ID) -/** A (received) sample has been rejected. */ -#define DDS_SAMPLE_REJECTED_STATUS (1u << DDS_SAMPLE_REJECTED_STATUS_ID) -/** New information is available. */ -#define DDS_DATA_ON_READERS_STATUS (1u << DDS_DATA_ON_READERS_STATUS_ID) -/** New information is available. */ -#define DDS_DATA_AVAILABLE_STATUS (1u << DDS_DATA_AVAILABLE_STATUS_ID) -/** The liveliness that the DDS_DataWriter has committed through its liveliness QoS policy was not respected; thus readers will consider the writer as no longer "alive". */ -#define DDS_LIVELINESS_LOST_STATUS (1u << DDS_LIVELINESS_LOST_STATUS_ID) -/** The liveliness of one or more writers, that were writing instances read through the readers has changed. Some writers have become "alive" or "not alive". */ -#define DDS_LIVELINESS_CHANGED_STATUS (1u << DDS_LIVELINESS_CHANGED_STATUS_ID) -/** The writer has found a reader that matches the topic and has a compatible QoS. */ -#define DDS_PUBLICATION_MATCHED_STATUS (1u << DDS_PUBLICATION_MATCHED_STATUS_ID) -/** The reader has found a writer that matches the topic and has a compatible QoS. */ -#define DDS_SUBSCRIPTION_MATCHED_STATUS (1u << DDS_SUBSCRIPTION_MATCHED_STATUS_ID) -/** @}*/ - -/** Read state for a data value */ -typedef enum dds_sample_state -{ - DDS_SST_READ = DDS_READ_SAMPLE_STATE, /**0 - * A valid publisher handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic dds entity relations documentation. */ -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) -DDS_EXPORT dds_entity_t -dds_get_publisher( - _In_ dds_entity_t writer); - -/** - * @brief Get entity subscriber. - * - * This operation returns the subscriber to which the given entity belongs. - * For instance, it will return the Subscriber that was used when - * creating a DataReader (when that DataReader was provided here). - * - * @param[in] entity Entity from which to get its subscriber. - * - * @returns A valid subscriber handle or an error code. - * - * @retval >0 - * A valid subscriber handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic dds entity relations documentation. */ -_Pre_satisfies_(((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY) ) -DDS_EXPORT dds_entity_t -dds_get_subscriber( - _In_ dds_entity_t entity); - -/** - * @brief Get entity datareader. - * - * This operation returns the datareader to which the given entity belongs. - * For instance, it will return the DataReader that was used when - * creating a ReadCondition (when that ReadCondition was provided here). - * - * @param[in] entity Entity from which to get its datareader. - * - * @returns A valid reader handle or an error code. - * - * @retval >0 - * A valid reader handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic dds entity relations documentation. */ -_Pre_satisfies_(((condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY) ) -DDS_EXPORT dds_entity_t -dds_get_datareader( - _In_ dds_entity_t condition); - -/** - * @brief Get the mask of a condition. - * - * This operation returns the mask that was used to create the given - * condition. - * - * @param[in] condition Read or Query condition that has a mask. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success (given mask is set). - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The mask arg is NULL. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY) ) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_mask( - _In_ dds_entity_t condition, - _Out_ uint32_t *mask); - -/** - * @brief Returns the instance handle that represents the entity. - * - * @param[in] entity Entity of which to get the instance handle. - * @param[out] ihdl Pointer to dds_instance_handle_t. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - */ -/* TODO: Check list of return codes is complete. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_instance_handle( - _In_ dds_entity_t entity, - _Out_ dds_instance_handle_t *ihdl); - -/* - All entities have a set of "status conditions" (following the DCPS - spec), read peeks, take reads & resets (analogously to read & take - operations on reader). The "mask" allows operating only on a subset - of the statuses. Enabled status analogously to DCPS spec. -*/ - -/** - * @brief Read the status set for the entity - * - * This operation reads the status(es) set for the entity based on - * the enabled status and mask set. It does not clear the read status(es). - * - * @param[in] entity Entity on which the status has to be read. - * @param[out] status Returns the status set on the entity, based on the enabled status. - * @param[in] mask Filter the status condition to be read (can be NULL). - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_read_status( - _In_ dds_entity_t entity, - _Out_ uint32_t *status, - _In_ uint32_t mask); - -/** - * @brief Read the status set for the entity - * - * This operation reads the status(es) set for the entity based on the enabled - * status and mask set. It clears the status set after reading. - * - * @param[in] entity Entity on which the status has to be read. - * @param[out] status Returns the status set on the entity, based on the enabled status. - * @param[in] mask Filter the status condition to be read (can be NULL). - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_take_status( - _In_ dds_entity_t entity, - _Out_ uint32_t *status, - _In_ uint32_t mask); - -/** - * @brief Get changed status(es) - * - * This operation returns the status changes since they were last read. - * - * @param[in] entity Entity on which the statuses are read. - * @param[out] status Returns the current set of triggered statuses. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Must_inspect_result_ dds_return_t -dds_get_status_changes( - _In_ dds_entity_t entity, - _Out_ uint32_t *status); - -/** - * @brief Get enabled status on entity - * - * This operation returns the status enabled on the entity - * - * @param[in] entity Entity to get the status. - * @param[out] status Status set on the entity. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_status_mask( - _In_ dds_entity_t entity, - _Out_ uint32_t *mask); - -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_DEPRECATED_EXPORT _Check_return_ dds_return_t -dds_get_enabled_status( - _In_ dds_entity_t entity, - _Out_ uint32_t *mask); - -/** - * @brief Set status enabled on entity - * - * This operation enables the status(es) based on the mask set - * - * @param[in] entity Entity to enable the status. - * @param[in] mask Status value that indicates the status to be enabled. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_return_t -dds_set_status_mask( - _In_ dds_entity_t entity, - _In_ uint32_t mask); - -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_DEPRECATED_EXPORT dds_return_t -dds_set_enabled_status( - _In_ dds_entity_t entity, - _In_ uint32_t mask); - -/* - Almost all entities have get/set qos operations defined on them, - again following the DCPS spec. But unlike the DCPS spec, the - "present" field in qos_t allows one to initialize just the one QoS - one wants to set & pass it to set_qos. -*/ - -/** - * @brief Get entity QoS policies. - * - * This operation allows access to the existing set of QoS policies - * for the entity. - * - * @param[in] entity Entity on which to get qos. - * @param[out] qos Pointer to the qos structure that returns the set policies. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The existing set of QoS policy values applied to the entity - * has successfully been copied into the specified qos parameter. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The qos parameter is NULL. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic QoS information documentation. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_qos( - _In_ dds_entity_t entity, - _Out_ dds_qos_t *qos); - -/** - * @brief Set entity QoS policies. - * - * This operation replaces the existing set of Qos Policy settings for an - * entity. The parameter qos must contain the struct with the QosPolicy - * settings which is checked for self-consistency. - * - * The set of QosPolicy settings specified by the qos parameter are applied on - * top of the existing QoS, replacing the values of any policies previously set - * (provided, the operation returned DDS_RETCODE_OK). - * - * Not all policies are changeable when the entity is enabled. - * - * @note Currently only Latency Budget and Ownership Strength are changeable QoS - * that can be set. - * - * @param[in] entity Entity from which to get qos. - * @param[in] qos Pointer to the qos structure that provides the policies. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The new QoS policies are set. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The qos parameter is NULL. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_IMMUTABLE_POLICY - * The entity is enabled and one or more of the policies of the QoS - * are immutable. - * @retval DDS_RETCODE_INCONSISTENT_POLICY - * A few policies within the QoS are not consistent with each other. - */ -/* TODO: Link to generic QoS information documentation. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_set_qos( - _In_ dds_entity_t entity, - _In_ const dds_qos_t * qos); - -/* - Get or set listener associated with an entity, type of listener - provided much match type of entity. -*/ - -/** - * @brief Get entity listeners. - * - * This operation allows access to the existing listeners attached to - * the entity. - * - * @param[in] entity Entity on which to get the listeners. - * @param[out] listener Pointer to the listener structure that returns the - * set of listener callbacks. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The listeners of to the entity have been successfully been - * copied into the specified listener parameter. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The listener parameter is NULL. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to (generic) Listener and status information. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_return_t -dds_get_listener( - _In_ dds_entity_t entity, - _Out_ dds_listener_t * listener); - -/** - * @brief Set entity listeners. - * - * This operation attaches a dds_listener_t to the dds_entity_t. Only one - * Listener can be attached to each Entity. If a Listener was already - * attached, this operation will replace it with the new one. In other - * words, all related callbacks are replaced (possibly with NULL). - * - * When listener parameter is NULL, all listener callbacks that were possibly - * set on the Entity will be removed. - * - * @note Not all listener callbacks are related to all entities. - * - * Communication Status
- * For each communication status, the StatusChangedFlag flag is initially set to - * FALSE. It becomes TRUE whenever that plain communication status changes. For - * each plain communication status activated in the mask, the associated - * Listener callback is invoked and the communication status is reset - * to FALSE, as the listener implicitly accesses the status which is passed as a - * parameter to that operation. - * The status is reset prior to calling the listener, so if the application calls - * the get_ from inside the listener it will see the - * status already reset. - * - * Status Propagation
- * In case a related callback within the Listener is not set, the Listener of - * the Parent entity is called recursively, until a Listener with the appropriate - * callback set has been found and called. This allows the application to set - * (for instance) a default behaviour in the Listener of the containing Publisher - * and a DataWriter specific behaviour when needed. In case the callback is not - * set in the Publishers' Listener either, the communication status will be - * propagated to the Listener of the DomainParticipant of the containing - * DomainParticipant. In case the callback is not set in the DomainParticipants' - * Listener either, the Communication Status flag will be set, resulting in a - * possible WaitSet trigger. - * - * @param[in] entity Entity on which to get the listeners. - * @param[in] listener Pointer to the listener structure that contains the - * set of listener callbacks (maybe NULL). - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The listeners of to the entity have been successfully been - * copied into the specified listener parameter. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to (generic) Listener and status information. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_return_t -dds_set_listener( - _In_ dds_entity_t entity, - _In_opt_ const dds_listener_t * listener); - -/* - Creation functions for various entities. Creating a subscriber or - publisher is optional: if one creates a reader as a descendant of a - participant, it is as if a subscriber is created specially for - that reader. - - QoS default values are those of the DDS specification, but the - inheritance rules are different: - - * publishers and subscribers inherit from the participant QoS - * readers and writers always inherit from the topic QoS - * the QoS's present in the "qos" parameter override the inherited values -*/ - -/** - * @brief Creates a new instance of a DDS participant in a domain - * - * If domain is set (not DDS_DOMAIN_DEFAULT) then it must match if the domain has also - * been configured or an error status will be returned. - * Currently only a single domain can be configured by providing configuration file. - * If no configuration file exists, the default domain is configured as 0. - * - * - * @param[in] domain The domain in which to create the participant (can be DDS_DOMAIN_DEFAULT). Valid values for domain id are between 0 and 230. DDS_DOMAIN_DEFAULT is for using the domain in the configuration. - * @param[in] qos The QoS to set on the new participant (can be NULL). - * @param[in] listener Any listener functions associated with the new participant (can be NULL). - - * @returns A valid participant handle or an error code. - * - * @retval >0 - * A valid participant handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - */ -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_participant( - _In_ const dds_domainid_t domain, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/** - * @brief Get entity parent. - * - * This operation returns the parent to which the given entity belongs. - * For instance, it will return the Participant that was used when - * creating a Publisher (when that Publisher was provided here). - * - * When a reader or a writer are created with a partition, then a - * subscriber or publisher respectively are created implicitly. These - * implicit subscribers or publishers will be deleted automatically - * when the reader or writer is deleted. However, when this function - * returns such an implicit entity, it is from there on out considered - * 'explicit'. This means that it isn't deleted automatically anymore. - * The application should explicitly call dds_delete on those entities - * now (or delete the parent participant which will delete all entities - * within its hierarchy). - * - * @param[in] entity Entity from which to get its parent. - * - * @returns A valid entity handle or an error code. - * - * @retval >0 - * A valid entity handle. - * @retval DDS_ENTITY_NIL - * Called with a participant. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic dds entity relations documentation. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_entity_t -dds_get_parent( - _In_ dds_entity_t entity); - -/** - * @brief Get entity participant. - * - * This operation returns the participant to which the given entity belongs. - * For instance, it will return the Participant that was used when - * creating a Publisher that was used to create a DataWriter (when that - * DataWriter was provided here). - * - * TODO: Link to generic dds entity relations documentation. - * - * @param[in] entity Entity from which to get its participant. - * - * @returns A valid entity or an error code. - * - * @retval >0 - * A valid participant handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_entity_t -dds_get_participant ( - _In_ dds_entity_t entity); - -/** - * @brief Get entity children. - * - * This operation returns the children that the entity contains. - * For instance, it will return all the Topics, Publishers and Subscribers - * of the Participant that was used to create those entities (when that - * Participant is provided here). - * - * This functions takes a pre-allocated list to put the children in and - * will return the number of found children. It is possible that the given - * size of the list is not the same as the number of found children. If - * less children are found, then the last few entries in the list are - * untouched. When more children are found, then only 'size' number of - * entries are inserted into the list, but still complete count of the - * found children is returned. Which children are returned in the latter - * case is undefined. - * - * When supplying NULL as list and 0 as size, you can use this to acquire - * the number of children without having to pre-allocate a list. - * - * When a reader or a writer are created with a partition, then a - * subscriber or publisher respectively are created implicitly. These - * implicit subscribers or publishers will be deleted automatically - * when the reader or writer is deleted. However, when this function - * returns such an implicit entity, it is from there on out considered - * 'explicit'. This means that it isn't deleted automatically anymore. - * The application should explicitly call dds_delete on those entities - * now (or delete the parent participant which will delete all entities - * within its hierarchy). - * - * @param[in] entity Entity from which to get its children. - * @param[out] children Pre-allocated array to contain the found children. - * @param[in] size Size of the pre-allocated children's list. - * - * @returns Number of children or an error code. - * - * @retval >=0 - * Number of childer found children (can be larger than 'size'). - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The children parameter is NULL, while a size is provided. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Link to generic dds entity relations documentation. */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_children( - _In_ dds_entity_t entity, - _Out_opt_ dds_entity_t *children, - _In_ size_t size); - -/** - * @brief Get the domain id to which this entity is attached. - * - * When creating a participant entity, it is attached to a certain domain. - * All the children (like Publishers) and childrens' children (like - * DataReaders), etc are also attached to that domain. - * - * This function will return the original domain ID when called on - * any of the entities within that hierarchy. - * - * @param[in] entity Entity from which to get its children. - * @param[out] id Pointer to put the domain ID in. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Domain ID was returned. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The id parameter is NULL. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT _Check_return_ dds_return_t -dds_get_domainid( - _In_ dds_entity_t entity, - _Out_ dds_domainid_t *id); - -/** - * @brief Get participants of a domain. - * - * This operation acquires the participants created on a domain and returns - * the number of found participants. - * - * This function takes a domain id with the size of pre-allocated participant's - * list in and will return the number of found participants. It is possible that - * the given size of the list is not the same as the number of found participants. - * If less participants are found, then the last few entries in an array stay - * untouched. If more participants are found and the array is too small, then the - * participants returned are undefined. - * - * @param[in] domain_id The domain id. - * @param[out] participants The participant for domain. - * @param[in] size Size of the pre-allocated participant's list. - * - * @returns Number of participants found or and error code. - * - * @retval >0 - * Number of participants found. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The participant parameter is NULL, while a size is provided. - */ -DDS_EXPORT _Check_return_ dds_return_t -dds_lookup_participant( - _In_ dds_domainid_t domain_id, - _Out_opt_ dds_entity_t *participants, - _In_ size_t size); - -/** - * @brief Creates a new topic with default type handling. - * - * The type name for the topic is taken from the generated descriptor. Topic - * matching is done on a combination of topic name and type name. - * - * @param[in] participant Participant on which to create the topic. - * @param[in] descriptor An IDL generated topic descriptor. - * @param[in] name Name of the topic. - * @param[in] qos QoS to set on the new topic (can be NULL). - * @param[in] listener Any listener functions associated with the new topic (can be NULL). - * - * @returns A valid topic handle or an error code. - * - * @retval >=0 - * A valid topic handle. - * @retval DDS_RETCODE_BAD_PARAMETER - * Either participant, descriptor, name or qos is invalid. - */ -/* TODO: Check list of retcodes is complete. */ -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT dds_entity_t -dds_create_topic( - _In_ dds_entity_t participant, - _In_ const dds_topic_descriptor_t *descriptor, - _In_z_ const char *name, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/** - * @brief Creates a new topic with arbitrary type handling. - * - * The type name for the topic is taken from the provided "sertopic" object. Topic - * matching is done on a combination of topic name and type name. - * - * @param[in] participant Participant on which to create the topic. - * @param[in] sertopic Internal description of the topic type. - * @param[in] name Name of the topic. - * @param[in] qos QoS to set on the new topic (can be NULL). - * @param[in] listener Any listener functions associated with the new topic (can be NULL). - * @param[in] sedp_plist Topic description to be published as part of discovery (if NULL, not published). - * - * @returns A valid topic handle or an error code. - * - * @retval >=0 - * A valid topic handle. - * @retval DDS_RETCODE_BAD_PARAMETER - * Either participant, descriptor, name or qos is invalid. - */ -/* TODO: Check list of retcodes is complete. */ -struct ddsi_sertopic; -struct nn_plist; -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT dds_entity_t -dds_create_topic_arbitrary ( - _In_ dds_entity_t participant, - _In_ struct ddsi_sertopic *sertopic, - _In_z_ const char *name, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener, - _In_opt_ const struct nn_plist *sedp_plist); - -/** - * @brief Finds a named topic. - * - * The returned topic should be released with dds_delete. - * - * @param[in] participant The participant on which to find the topic. - * @param[in] name The name of the topic to find. - * - * @returns A valid topic handle or an error code. - * - * @retval >0 - * A valid topic handle. - * @retval DDS_RETCODE_BAD_PARAMETER - * Participant was invalid. - */ -/* TODO: Check list of retcodes is complete. */ -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT dds_entity_t -dds_find_topic( - _In_ dds_entity_t participant, - _In_z_ const char *name); - -/** - * @brief Returns the name of a given topic. - * - * @param[in] topic The topic. - * @param[out] name Buffer to write the topic name to. - * @param[in] size Number of bytes available in the buffer. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Success. - */ -/* TODO: do we need a convenience version as well that allocates and add a _s suffix to this one? */ -/* TODO: Check annotation. Could be _Out_writes_to_(size, return + 1) as well. */ -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_EXPORT dds_return_t -dds_get_name( - _In_ dds_entity_t topic, - _Out_writes_z_(size) char *name, - _In_ size_t size); - -/** - * @brief Returns the type name of a given topic. - * - * @param[in] topic The topic. - * @param[out] name Buffer to write the topic type name to. - * @param[in] size Number of bytes available in the buffer. - * - * @returns A dds_return_t indicating success or failure. - * - * @return DDS_RETCODE_OK - * Success. - */ -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_EXPORT dds_return_t -dds_get_type_name( - _In_ dds_entity_t topic, - _Out_writes_z_(size) char *name, - _In_ size_t size); - -/** Topic filter function */ -typedef bool (*dds_topic_filter_fn) (const void * sample); - -/** - * @brief Sets a filter on a topic. - * - * @param[in] topic The topic on which the content filter is set. - * @param[in] filter The filter function used to filter topic samples. - */ -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_EXPORT void -dds_set_topic_filter( - dds_entity_t topic, - dds_topic_filter_fn filter); - -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_DEPRECATED_EXPORT void -dds_topic_set_filter( - dds_entity_t topic, - dds_topic_filter_fn filter); - -/** - * @brief Gets the filter for a topic. - * - * @param[in] topic The topic from which to get the filter. - * - * @returns The topic filter. - */ -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_EXPORT dds_topic_filter_fn -dds_get_topic_filter( - dds_entity_t topic); - -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) -DDS_DEPRECATED_EXPORT dds_topic_filter_fn -dds_topic_get_filter( - dds_entity_t topic); - -/** - * @brief Creates a new instance of a DDS subscriber - * - * @param[in] participant The participant on which the subscriber is being created. - * @param[in] qos The QoS to set on the new subscriber (can be NULL). - * @param[in] listener Any listener functions associated with the new subscriber (can be NULL). - * - * @returns A valid subscriber handle or an error code. - * - * @retval >0 - * A valid subscriber handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the parameters is invalid. - */ -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_subscriber( - _In_ dds_entity_t participant, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/** - * @brief Creates a new instance of a DDS publisher - * - * @param[in] participant The participant to create a publisher for. - * @param[in] qos The QoS to set on the new publisher (can be NULL). - * @param[in] listener Any listener functions associated with the new publisher (can be NULL). - * - * @returns A valid publisher handle or an error code. - * - * @retval >0 - * A valid publisher handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - */ -/* TODO: Check list of error codes is complete. */ -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_publisher( - _In_ dds_entity_t participant, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/** - * @brief Suspends the publications of the Publisher - * - * This operation is a hint to the Service so it can optimize its performance by e.g., collecting - * modifications to DDS writers and then batching them. The Service is not required to use the hint. - * - * Every invocation of this operation must be matched by a corresponding call to @see dds_resume - * indicating that the set of modifications has completed. - * - * @param[in] publisher The publisher for which all publications will be suspended. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Publications suspended successfully. - * @retval DDS_RETCODE_BAD_PARAMETER - * The pub parameter is not a valid publisher. - * @retval DDS_RETCODE_UNSUPPORTED - * Operation is not supported. - */ -_Pre_satisfies_((publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) -DDS_EXPORT dds_return_t -dds_suspend( - _In_ dds_entity_t publisher); - -/** - * @brief Resumes the publications of the Publisher - * - * This operation is a hint to the Service to indicate that the application has - * completed changes initiated by a previous dds_suspend(). The Service is not - * required to use the hint. - * - * The call to resume_publications must match a previous call to @see suspend_publications. - * - * @param[in] publisher The publisher for which all publications will be resumed. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Publications resumed successfully. - * @retval DDS_RETCODE_BAD_PARAMETER - * The pub parameter is not a valid publisher. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * No previous matching dds_suspend(). - * @retval DDS_RETCODE_UNSUPPORTED - * Operation is not supported. - */ -_Pre_satisfies_((publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) -DDS_EXPORT dds_return_t -dds_resume( - _In_ dds_entity_t publisher); - - -/** - * @brief Waits at most for the duration timeout for acks for data in the publisher or writer. - * - * This operation blocks the calling thread until either all data written by the publisher - * or writer is acknowledged by all matched reliable reader entities, or else the duration - * specified by the timeout parameter elapses, whichever happens first. - * - * @param[in] publisher_or_writer Publisher or writer whose acknowledgments must be waited for - * @param[in] timeout How long to wait for acknowledgments before time out - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * All acknowledgments successfully received with the timeout. - * @retval DDS_RETCODE_BAD_PARAMETER - * The publisher_or_writer is not a valid publisher or writer. - * @retval DDS_RETCODE_TIMEOUT - * Timeout expired before all acknowledgments from reliable reader entities were received. - * @retval DDS_RETCODE_UNSUPPORTED - * Operation is not supported. - */ -_Pre_satisfies_(((publisher_or_writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) ||\ - ((publisher_or_writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) ) -DDS_EXPORT dds_return_t -dds_wait_for_acks( - _In_ dds_entity_t publisher_or_writer, - _In_ dds_duration_t timeout); - - -/** - * @brief Creates a new instance of a DDS reader. - * - * This implicit subscriber will be deleted automatically when the created reader - * is deleted. - * - * @param[in] participant_or_subscriber The participant or subscriber on which the reader is being created. - * @param[in] topic The topic to read. - * @param[in] qos The QoS to set on the new reader (can be NULL). - * @param[in] listener Any listener functions associated with the new reader (can be NULL). - * - * @returns A valid reader handle or an error code. - * - * @retval >0 - * A valid reader handle. - * @retval DDS_RETCODE_ERROR - * An internal error occurred. - */ -/* TODO: Complete list of error codes */ -_Pre_satisfies_(((participant_or_subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER ) ||\ - ((participant_or_subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) ) -_Pre_satisfies_(((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC ) ||\ - ((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_INTERNAL) ) -DDS_EXPORT dds_entity_t -dds_create_reader( - _In_ dds_entity_t participant_or_subscriber, - _In_ dds_entity_t topic, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/** - * @brief Wait until reader receives all historic data - * - * The operation blocks the calling thread until either all "historical" data is - * received, or else the duration specified by the max_wait parameter elapses, whichever happens - * first. A return value of 0 indicates that all the "historical" data was received; a return - * value of TIMEOUT indicates that max_wait elapsed before all the data was received. - * - * @param[in] reader The reader on which to wait for historical data. - * @param[in] max_wait How long to wait for historical data before time out. - * - * @returns a status, 0 on success, TIMEOUT on timeout or a negative value to indicate error. - */ -/* TODO: Complete list of error codes */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) -DDS_EXPORT int -dds_reader_wait_for_historical_data( - dds_entity_t reader, - dds_duration_t max_wait); - -/** - * @brief Creates a new instance of a DDS writer. - * - * This implicit publisher will be deleted automatically when the created writer - * is deleted. - * - * @param[in] participant_or_publisher The participant or publisher on which the writer is being created. - * @param[in] topic The topic to write. - * @param[in] qos The QoS to set on the new writer (can be NULL). - * @param[in] listener Any listener functions associated with the new writer (can be NULL). - * - * @returns A valid writer handle or an error code. - * - * @returns >0 - * A valid writer handle. - * @returns DDS_RETCODE_ERROR - * An internal error occurred. - */ -/* TODO: Complete list of error codes */ -_Pre_satisfies_(((participant_or_publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER ) ||\ - ((participant_or_publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) ) -_Pre_satisfies_( (topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC ) -DDS_EXPORT dds_entity_t -dds_create_writer( - _In_ dds_entity_t participant_or_publisher, - _In_ dds_entity_t topic, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); - -/* - Writing data (and variants of it) is straightforward. The first set - is equivalent to the second set with -1 passed for "timestamp", - meaning, substitute the result of a call to time(). The dispose - and unregister operations take an object of the topic's type, but - only touch the key fields; the remained may be undefined. -*/ -/** - * @brief Registers an instance - * - * This operation registers an instance with a key value to the data writer and - * returns an instance handle that could be used for successive write & dispose - * operations. When the handle is not allocated, the function will return and - * error and the handle will be un-touched. - * - * @param[in] writer The writer to which instance has be associated. - * @param[out] handle The instance handle. - * @param[in] data The instance with the key value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_register_instance( - _In_ dds_entity_t writer, - _Out_ dds_instance_handle_t *handle, - _In_ const void *data); - -/** - * @brief Unregisters an instance - * - * This operation reverses the action of register instance, removes all information regarding - * the instance and unregisters an instance with a key value from the data writer. - * - * @param[in] writer The writer to which instance is associated. - * @param[in] data The instance with the key value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_unregister_instance( - _In_ dds_entity_t writer, - _In_opt_ const void *data); - -/** - * @brief Unregisters an instance - * - *This operation unregisters the instance which is identified by the key fields of the given - *typed instance handle. - * - * @param[in] writer The writer to which instance is associated. - * @param[in] handle The instance handle. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_unregister_instance_ih( - _In_ dds_entity_t writer, - _In_opt_ dds_instance_handle_t handle); - -/** - * @brief Unregisters an instance - * - * This operation reverses the action of register instance, removes all information regarding - * the instance and unregisters an instance with a key value from the data writer. It also - * provides a value for the timestamp explicitly. - * - * @param[in] writer The writer to which instance is associated. - * @param[in] data The instance with the key value. - * @param[in] timestamp The timestamp used at registration. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_unregister_instance_ts( - _In_ dds_entity_t writer, - _In_opt_ const void *data, - _In_ dds_time_t timestamp); - -/** - * @brief Unregisters an instance - * - * This operation unregisters an instance with a key value from the handle. Instance can be identified - * from instance handle. If an unregistered key ID is passed as an instance data, an error is logged and - * not flagged as return value. - * - * @param[in] writer The writer to which instance is associated. - * @param[in] handle The instance handle. - * @param[in] timestamp The timestamp used at registration. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_unregister_instance_ih_ts( - _In_ dds_entity_t writer, - _In_opt_ dds_instance_handle_t handle, - _In_ dds_time_t timestamp); - -/** - * @brief This operation modifies and disposes a data instance. - * - * This operation requests the Data Distribution Service to modify the instance and - * mark it for deletion. Copies of the instance and its corresponding samples, which are - * stored in every connected reader and, dependent on the QoS policy settings (also in - * the Transient and Persistent stores) will be modified and marked for deletion by - * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. - * - * Blocking
- * If the history QoS policy is set to DDS_HISTORY_KEEP_ALL, the - * dds_writedispose operation on the writer may block if the modification - * would cause data to be lost because one of the limits, specified in the - * resource_limits QoS policy, to be exceeded. In case the synchronous - * attribute value of the reliability Qos policy is set to true for - * communicating writers and readers then the writer will wait until - * all synchronous readers have acknowledged the data. Under these - * circumstances, the max_blocking_time attribute of the reliability - * QoS policy configures the maximum time the dds_writedispose operation - * may block. - * If max_blocking_time elapses before the writer is able to store the - * modification without exceeding the limits and all expected acknowledgements - * are received, the dds_writedispose operation will fail and returns - * DDS_RETCODE_TIMEOUT. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] data The data to be written and disposed. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_TIMEOUT - * Either the current action overflowed the available resources as - * specified by the combination of the reliability QoS policy, - * history QoS policy and resource_limits QoS policy, or the - * current action was waiting for data delivery acknowledgement - * by synchronous readers. This caused blocking of this operation, - * which could not be resolved before max_blocking_time of the - * reliability QoS policy elapsed. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_writedispose( - _In_ dds_entity_t writer, - _In_ const void *data); - -/** - * @brief This operation modifies and disposes a data instance with a specific - * timestamp. - * - * This operation performs the same functions as dds_writedispose except that - * the application provides the value for the source_timestamp that is made - * available to connected reader objects. This timestamp is important for the - * interpretation of the destination_order QoS policy. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] data The data to be written and disposed. - * @param[in] timestamp The timestamp used as source timestamp. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_TIMEOUT - * Either the current action overflowed the available resources as - * specified by the combination of the reliability QoS policy, - * history QoS policy and resource_limits QoS policy, or the - * current action was waiting for data delivery acknowledgement - * by synchronous readers. This caused blocking of this operation, - * which could not be resolved before max_blocking_time of the - * reliability QoS policy elapsed. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_writedispose_ts( - _In_ dds_entity_t writer, - _In_ const void *data, - _In_ dds_time_t timestamp); - -/** - * @brief This operation disposes an instance, identified by the data sample. - * - * This operation requests the Data Distribution Service to modify the instance and - * mark it for deletion. Copies of the instance and its corresponding samples, which are - * stored in every connected reader and, dependent on the QoS policy settings (also in - * the Transient and Persistent stores) will be modified and marked for deletion by - * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. - * - * Blocking
- * If the history QoS policy is set to DDS_HISTORY_KEEP_ALL, the - * dds_writedispose operation on the writer may block if the modification - * would cause data to be lost because one of the limits, specified in the - * resource_limits QoS policy, to be exceeded. In case the synchronous - * attribute value of the reliability Qos policy is set to true for - * communicating writers and readers then the writer will wait until - * all synchronous readers have acknowledged the data. Under these - * circumstances, the max_blocking_time attribute of the reliability - * QoS policy configures the maximum time the dds_writedispose operation - * may block. - * If max_blocking_time elapses before the writer is able to store the - * modification without exceeding the limits and all expected acknowledgements - * are received, the dds_writedispose operation will fail and returns - * DDS_RETCODE_TIMEOUT. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] data The data sample that identifies the instance - * to be disposed. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_TIMEOUT - * Either the current action overflowed the available resources as - * specified by the combination of the reliability QoS policy, - * history QoS policy and resource_limits QoS policy, or the - * current action was waiting for data delivery acknowledgement - * by synchronous readers. This caused blocking of this operation, - * which could not be resolved before max_blocking_time of the - * reliability QoS policy elapsed. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_dispose( - _In_ dds_entity_t writer, - _In_ const void *data); - -/** - * @brief This operation disposes an instance with a specific timestamp, identified by the data sample. - * - * This operation performs the same functions as dds_dispose except that - * the application provides the value for the source_timestamp that is made - * available to connected reader objects. This timestamp is important for the - * interpretation of the destination_order QoS policy. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] data The data sample that identifies the instance - * to be disposed. - * @param[in] timestamp The timestamp used as source timestamp. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion - * @retval DDS_RETCODE_ERROR - * An internal error has occurred - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted - * @retval DDS_RETCODE_TIMEOUT - * Either the current action overflowed the available resources as - * specified by the combination of the reliability QoS policy, - * history QoS policy and resource_limits QoS policy, or the - * current action was waiting for data delivery acknowledgment - * by synchronous readers. This caused blocking of this operation, - * which could not be resolved before max_blocking_time of the - * reliability QoS policy elapsed. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_dispose_ts( - _In_ dds_entity_t writer, - _In_ const void *data, - _In_ dds_time_t timestamp); - -/** - * @brief This operation disposes an instance, identified by the instance handle. - * - * This operation requests the Data Distribution Service to modify the instance and - * mark it for deletion. Copies of the instance and its corresponding samples, which are - * stored in every connected reader and, dependent on the QoS policy settings (also in - * the Transient and Persistent stores) will be modified and marked for deletion by - * setting their dds_instance_state_t to DDS_IST_NOT_ALIVE_DISPOSED. - * - * Instance Handle
- * The given instance handle must correspond to the value that was returned by either - * the dds_register_instance operation, dds_register_instance_ts or dds_lookup_instance. - * If there is no correspondence, then the result of the operation is unspecified. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] handle The handle to identify an instance. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this writer - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_dispose_ih( - _In_ dds_entity_t writer, - _In_ dds_instance_handle_t handle); - -/** - * @brief This operation disposes an instance with a specific timestamp, identified by the instance handle. - * - * This operation performs the same functions as dds_dispose_ih except that - * the application provides the value for the source_timestamp that is made - * available to connected reader objects. This timestamp is important for the - * interpretation of the destination_order QoS policy. - * - * @param[in] writer The writer to dispose the data instance from. - * @param[in] handle The handle to identify an instance. - * @param[in] timestamp The timestamp used as source timestamp. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The sample is written and the instance is marked for deletion. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * At least one of the arguments is invalid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this writer. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_dispose_ih_ts( - _In_ dds_entity_t writer, - _In_ dds_instance_handle_t handle, - _In_ dds_time_t timestamp); - -/** - * @brief Write the value of a data instance - * - * With this API, the value of the source timestamp is automatically made - * available to the data reader by the service. - * - * @param[in] writer The writer entity. - * @param[in] data Value to be written. - * - * @returns dds_return_t indicating success or failure. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_write( - _In_ dds_entity_t writer, - _In_ const void *data); - -/*TODO: What is it for and is it really needed? */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT void -dds_write_flush( - dds_entity_t writer); - -/** - * @brief Write a CDR serialized value of a data instance - * - * @param[in] writer The writer entity. - * @param[in] cdr CDR serialized value to be written. - * @param[in] size Size (in bytes) of CDR encoded data to be written. - * - * @returns A dds_return_t indicating success or failure. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_writecdr( - dds_entity_t writer, - struct ddsi_serdata *serdata); - -/** - * @brief Write the value of a data instance along with the source timestamp passed. - * - * @param[in] writer The writer entity. - * @param[in] data Value to be written. - * @param[in] timestamp Source timestamp. - * - * @returns A dds_return_t indicating success or failure. - */ -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) -DDS_EXPORT dds_return_t -dds_write_ts( - _In_ dds_entity_t writer, - _In_ const void *data, - _In_ dds_time_t timestamp); - -/** - * @brief Creates a readcondition associated to the given reader. - * - * The readcondition allows specifying which samples are of interest in - * a data reader's history, by means of a mask. The mask is or'd with - * the flags that are dds_sample_state_t, dds_view_state_t and - * dds_instance_state_t. - * - * Based on the mask value set, the readcondition gets triggered when - * data is available on the reader. - * - * Waitsets allow waiting for an event on some of any set of entities. - * This means that the readcondition can be used to wake up a waitset when - * data is in the reader history with states that matches the given mask. - * - * @note The parent reader and every of its associated conditions (whether - * they are readconditions or queryconditions) share the same resources. - * This means that one of these entities reads or takes data, the states - * of the data will change for other entities automatically. For instance, - * if one reads a sample, then the sample state will become 'read' for all - * associated reader/conditions. Or if one takes a sample, then it's not - * available to any other associated reader/condition. - * - * @param[in] reader Reader to associate the condition to. - * @param[in] mask Interest (dds_sample_state_t|dds_view_state_t|dds_instance_state_t). - * - * @returns A valid condition handle or an error code. - * - * @retval >0 - * A valid condition handle - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_readcondition( - _In_ dds_entity_t reader, - _In_ uint32_t mask); - -typedef bool (*dds_querycondition_filter_fn) (const void * sample); - -/** - * @brief Creates a queryondition associated to the given reader. - * - * The queryondition allows specifying which samples are of interest in - * a data reader's history, by means of a mask and a filter. The mask is - * or'd with the flags that are dds_sample_state_t, dds_view_state_t and - * dds_instance_state_t. - * - * Based on the mask value set and data that matches the filter, the - * querycondition gets triggered when data is available on the reader. - * - * Waitsets allow waiting for an event on some of any set of entities. - * This means that the querycondition can be used to wake up a waitset when - * data is in the reader history with states that matches the given mask - * and filter. - * - * @note The parent reader and every of its associated conditions (whether - * they are readconditions or queryconditions) share the same resources. - * This means that one of these entities reads or takes data, the states - * of the data will change for other entities automatically. For instance, - * if one reads a sample, then the sample state will become 'read' for all - * associated reader/conditions. Or if one takes a sample, then it's not - * available to any other associated reader/condition. - * - * @param[in] reader Reader to associate the condition to. - * @param[in] mask Interest (dds_sample_state_t|dds_view_state_t|dds_instance_state_t). - * @param[in] filter Callback that the application can use to filter specific samples. - * - * @returns A valid condition handle or an error code - * - * @retval >=0 - * A valid condition handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -/* TODO: Explain the filter (aka expression & parameters) of the (to be - * implemented) new querycondition implementation. - * TODO: Update parameters when new querycondition is introduced. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) -DDS_EXPORT dds_entity_t -dds_create_querycondition( - _In_ dds_entity_t reader, - _In_ uint32_t mask, - _In_ dds_querycondition_filter_fn filter); - -/** - * @brief Creates a guardcondition. - * - * Waitsets allow waiting for an event on some of any set of entities. - * This means that the guardcondition can be used to wake up a waitset when - * data is in the reader history with states that matches the given mask. - * - * @returns A valid condition handle or an error code. - * - * @retval >0 - * A valid condition handle - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_guardcondition( - _In_ dds_entity_t participant); - -/** - * @brief Sets the trigger status of a guardcondition. - * - * @retval DDS_RETCODE_OK - * Operation successful - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_GUARD) -DDS_EXPORT dds_return_t -dds_set_guardcondition( - _In_ dds_entity_t guardcond, - _In_ bool triggered); - -/** - * @brief Reads the trigger status of a guardcondition. - * - * @retval DDS_RETCODE_OK - * Operation successful - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_GUARD) -DDS_EXPORT dds_return_t -dds_read_guardcondition( - _In_ dds_entity_t guardcond, - _Out_ bool *triggered); - -/** - * @brief Reads and resets the trigger status of a guardcondition. - * - * @retval DDS_RETCODE_OK - * Operation successful - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_GUARD) -DDS_EXPORT dds_return_t -dds_take_guardcondition( - _In_ dds_entity_t guardcond, - _Out_ bool *triggered); - -/** - * @brief Waitset attachment argument. - * - * Every entity that is attached to the waitset can be accompanied by such - * an attachment argument. When the waitset wait is unblocked because of an - * entity that triggered, then the returning array will be populated with - * these attachment arguments that are related to the triggered entity. - */ -typedef intptr_t dds_attach_t; - -/** - * @brief Create a waitset and allocate the resources required - * - * A WaitSet object allows an application to wait until one or more of the - * conditions of the attached entities evaluates to TRUE or until the timeout - * expires. - * - * @param[in] participant Domain participant which the WaitSet contains. - * - * @returns A valid waitset handle or an error code. - * - * @retval >=0 - * A valid waitset handle. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT _Must_inspect_result_ dds_entity_t -dds_create_waitset( - _In_ dds_entity_t participant); - -/** - * @brief Acquire previously attached entities. - * - * This functions takes a pre-allocated list to put the entities in and - * will return the number of found entities. It is possible that the given - * size of the list is not the same as the number of found entities. If - * less entities are found, then the last few entries in the list are - * untouched. When more entities are found, then only 'size' number of - * entries are inserted into the list, but still the complete count of the - * found entities is returned. Which entities are returned in the latter - * case is undefined. - * - * @param[in] waitset Waitset from which to get its attached entities. - * @param[out] entities Pre-allocated array to contain the found entities. - * @param[in] size Size of the pre-allocated entities' list. - * - * @returns A dds_return_t with the number of children or an error code. - * - * @retval >=0 - * Number of children found (can be larger than 'size'). - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entities parameter is NULL, while a size is provided. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_get_entities( - _In_ dds_entity_t waitset, - _Out_writes_to_(size, return < 0 ? 0 : return) dds_entity_t *entities, - _In_ size_t size); - - -/** - * @brief This operation attaches an Entity to the WaitSet. - * - * This operation attaches an Entity to the WaitSet. The dds_waitset_wait() - * will block when none of the attached entities are triggered. 'Triggered' - * (dds_triggered()) doesn't mean the same for every entity: - * - Reader/Writer/Publisher/Subscriber/Topic/Participant - * - These are triggered when their status changed. - * - WaitSet - * - Triggered when trigger value was set to true by the application. - * It stays triggered until application sets the trigger value to - * false (dds_waitset_set_trigger()). This can be used to wake up an - * waitset for different reasons (f.i. termination) than the 'normal' - * status change (like new data). - * - ReadCondition/QueryCondition - * - Triggered when data is available on the related Reader that matches - * the Condition. - * - * Multiple entities can be attached to a single waitset. A particular entity - * can be attached to multiple waitsets. However, a particular entity can not - * be attached to a particular waitset multiple times. - * - * @param[in] waitset The waitset to attach the given entity to. - * @param[in] entity The entity to attach. - * @param[in] x Blob that will be supplied when the waitset wait is - * triggerd by the given entity. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Entity attached. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The given waitset or entity are not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The entity was already attached. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_attach( - _In_ dds_entity_t waitset, - _In_ dds_entity_t entity, - _In_ dds_attach_t x); - -/** - * @brief This operation detaches an Entity to the WaitSet. - * - * @param[in] waitset The waitset to detach the given entity from. - * @param[in] entity The entity to detach. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Entity attached. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The given waitset or entity are not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The entity is not attached. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_detach( - _In_ dds_entity_t waitset, - _In_ dds_entity_t entity); - -/** - * @brief Sets the trigger_value associated with a waitset. - * - * When the waitset is attached to itself and the trigger value is - * set to 'true', then the waitset will wake up just like with an - * other status change of the attached entities. - * - * This can be used to forcefully wake up a waitset, for instance - * when the application wants to shut down. So, when the trigger - * value is true, the waitset will wake up or not wait at all. - * - * The trigger value will remain true until the application sets it - * false again deliberately. - * - * @param[in] waitset The waitset to set the trigger value on. - * @param[in] trigger The trigger value to set. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * Entity attached. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The given waitset is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_set_trigger( - _In_ dds_entity_t waitset, - _In_ bool trigger); - -/** - * @brief This operation allows an application thread to wait for the a status - * change or other trigger on (one of) the entities that are attached to - * the WaitSet. - * - * The "dds_waitset_wait" operation blocks until the some of the attached - * entities have triggered or "reltimeout" has elapsed. - * 'Triggered' (dds_triggered()) doesn't mean the same for every entity: - * - Reader/Writer/Publisher/Subscriber/Topic/Participant - * - These are triggered when their status changed. - * - WaitSet - * - Triggered when trigger value was set to true by the application. - * It stays triggered until application sets the trigger value to - * false (dds_waitset_set_trigger()). This can be used to wake up an - * waitset for different reasons (f.i. termination) than the 'normal' - * status change (like new data). - * - ReadCondition/QueryCondition - * - Triggered when data is available on the related Reader that matches - * the Condition. - * - * This functions takes a pre-allocated list to put the "xs" blobs in (that - * were provided during the attach of the related entities) and will return - * the number of triggered entities. It is possible that the given size - * of the list is not the same as the number of triggered entities. If less - * entities were triggered, then the last few entries in the list are - * untouched. When more entities are triggered, then only 'size' number of - * entries are inserted into the list, but still the complete count of the - * triggered entities is returned. Which "xs" blobs are returned in the - * latter case is undefined. - * - * In case of a time out, the return value is 0. - * - * Deleting the waitset while the application is blocked results in an - * error code (i.e. < 0) returned by "wait". - * - * Multiple threads may block on a single waitset at the same time; - * the calls are entirely independent. - * - * An empty waitset never triggers (i.e., dds_waitset_wait on an empty - * waitset is essentially equivalent to a sleep). - * - * The "dds_waitset_wait_until" operation is the same as the - * "dds_waitset_wait" except that it takes an absolute timeout. - * - * @param[in] waitset The waitset to set the trigger value on. - * @param[out] xs Pre-allocated list to store the 'blobs' that were - * provided during the attach of the triggered entities. - * @param[in] nxs The size of the pre-allocated blobs list. - * @param[in] reltimeout Relative timeout - * - * @returns A dds_return_t with the number of entities triggered or an error code - * - * @retval >0 - * Number of entities triggered. - * @retval 0 - * Time out (no entities were triggered). - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The given waitset is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_wait( - _In_ dds_entity_t waitset, - _Out_writes_to_opt_(nxs, return < 0 ? 0 : return) dds_attach_t *xs, - _In_ size_t nxs, - _In_ dds_duration_t reltimeout); - -/** - * @brief This operation allows an application thread to wait for the a status - * change or other trigger on (one of) the entities that are attached to - * the WaitSet. - * - * The "dds_waitset_wait" operation blocks until the some of the attached - * entities have triggered or "abstimeout" has been reached. - * 'Triggered' (dds_triggered()) doesn't mean the same for every entity: - * - Reader/Writer/Publisher/Subscriber/Topic/Participant - * - These are triggered when their status changed. - * - WaitSet - * - Triggered when trigger value was set to true by the application. - * It stays triggered until application sets the trigger value to - * false (dds_waitset_set_trigger()). This can be used to wake up an - * waitset for different reasons (f.i. termination) than the 'normal' - * status change (like new data). - * - ReadCondition/QueryCondition - * - Triggered when data is available on the related Reader that matches - * the Condition. - * - * This functions takes a pre-allocated list to put the "xs" blobs in (that - * were provided during the attach of the related entities) and will return - * the number of triggered entities. It is possible that the given size - * of the list is not the same as the number of triggered entities. If less - * entities were triggered, then the last few entries in the list are - * untouched. When more entities are triggered, then only 'size' number of - * entries are inserted into the list, but still the complete count of the - * triggered entities is returned. Which "xs" blobs are returned in the - * latter case is undefined. - * - * In case of a time out, the return value is 0. - * - * Deleting the waitset while the application is blocked results in an - * error code (i.e. < 0) returned by "wait". - * - * Multiple threads may block on a single waitset at the same time; - * the calls are entirely independent. - * - * An empty waitset never triggers (i.e., dds_waitset_wait on an empty - * waitset is essentially equivalent to a sleep). - * - * The "dds_waitset_wait" operation is the same as the - * "dds_waitset_wait_until" except that it takes an relative timeout. - * - * The "dds_waitset_wait" operation is the same as the "dds_wait" - * except that it takes an absolute timeout. - * - * @param[in] waitset The waitset to set the trigger value on. - * @param[out] xs Pre-allocated list to store the 'blobs' that were - * provided during the attach of the triggered entities. - * @param[in] nxs The size of the pre-allocated blobs list. - * @param[in] abstimeout Absolute timeout - * - * @returns A dds_return_t with the number of entities triggered or an error code. - * - * @retval >0 - * Number of entities triggered. - * @retval 0 - * Time out (no entities were triggered). - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The given waitset is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The waitset has already been deleted. - */ -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) -DDS_EXPORT dds_return_t -dds_waitset_wait_until( - _In_ dds_entity_t waitset, - _Out_writes_to_opt_(nxs, return < 0 ? 0 : return) dds_attach_t *xs, - _In_ size_t nxs, - _In_ dds_time_t abstimeout); - -/* - There are a number of read and take variations. - - Return value is the number of elements returned. "max_samples" - should have the same type, as one can't return more than MAX_INT - this way, anyway. X, Y, CX, CY return to the various filtering - options, see the DCPS spec. - - O ::= read | take - - X => CX - (empty) (empty) - _next_instance instance_handle_t prev - - Y => CY - (empty) uint32_t mask - _cond cond_t cond -- refers to a read condition (or query if implemented) - */ - -/** - * @brief Access and read the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition. - * - * Return value provides information about number of samples read, which will - * be <= maxs. Based on the count, the buffer will contain data to be read only - * when valid_data bit in sample info structure is set. - * The buffer required for data values, could be allocated explicitly or can - * use the memory from data reader to prevent copy. In the latter case, buffer and - * sample_info should be returned back, once it is no longer using the Data. - * Data values once read will remain in the buffer with the sample_state set to READ - * and view_state set to NOT_NEW. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs); - -/** - * @brief Access and read loaned samples of data reader, readcondition or querycondition. - * - * After dds_read_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL) - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value - * @param[in] maxs Maximum number of samples to read - * - * @returns A dds_return_t with the number of samples read or an error code - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs); - -/** - * @brief Read the collection of data values and sample info from the data reader, readcondition - * or querycondition based on mask. - * - * When using a readcondition or querycondition, their masks are or'd with the given mask. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_mask( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ uint32_t mask); - -/** - * @brief Access and read loaned samples of data reader, readcondition - * or querycondition based on mask - * - * When using a readcondition or querycondition, their masks are or'd with the given mask. - * - * After dds_read_mask_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_mask_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ uint32_t mask); - -/** - * @brief Access and read the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition, coped by the provided instance handle. - * - * This operation implements the same functionality as dds_read, except that only data scoped to - * the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_instance( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle); - -/** - * @brief Access and read loaned samples of data reader, readcondition or querycondition, - * scoped by the provided instance handle. - * - * This operation implements the same functionality as dds_read_wl, except that only data - * scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_instance_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle); - -/** - * @brief Read the collection of data values and sample info from the data reader, readcondition - * or querycondition based on mask and scoped by the provided instance handle. - * - * This operation implements the same functionality as dds_read_mask, except that only data - * scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_instance_mask( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask); - -/** - * @brief Access and read loaned samples of data reader, readcondition or - * querycondition based on mask, scoped by the provided instance handle. - * - * This operation implements the same functionality as dds_read_mask_wl, except that - * only data scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_read_instance_mask_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask); - -/** - * @brief Access the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition. - * - * Data value once read is removed from the Data Reader cannot to - * 'read' or 'taken' again. - * Return value provides information about number of samples read, which will - * be <= maxs. Based on the count, the buffer will contain data to be read only - * when valid_data bit in sample info structure is set. - * The buffer required for data values, could be allocated explicitly or can - * use the memory from data reader to prevent copy. In the latter case, buffer and - * sample_info should be returned back, once it is no longer using the Data. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs); - -/** - * @brief Access loaned samples of data reader, readcondition or querycondition. - * - * After dds_take_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs); - -/** - * @brief Take the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition based on mask - * - * When using a readcondition or querycondition, their masks are or'd with the given mask. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_mask( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ uint32_t mask); - -/** - * @brief Access loaned samples of data reader, readcondition or querycondition based on mask. - * - * When using a readcondition or querycondition, their masks are or'd with the given mask. - * - * After dds_take_mask_wl function is being called and the data has been handled, dds_return_loan function must be called to possibly free memory - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_mask_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ uint32_t mask); - -DDS_EXPORT int -dds_takecdr( - dds_entity_t reader_or_condition, - struct ddsi_serdata **buf, - uint32_t maxs, - dds_sample_info_t *si, - uint32_t mask); - -/** - * @brief Access the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition but scoped by the given - * instance handle. - * - * This operation mplements the same functionality as dds_take, except that only data - * scoped to the provided instance handle is taken. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_instance( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle); - -/** - * @brief Access loaned samples of data reader, readcondition or querycondition, - * scoped by the given instance handle. - * - * This operation implements the same functionality as dds_take_wl, except that - * only data scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_instance_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle); - -/** - * @brief Take the collection of data values (of same type) and sample info from the - * data reader, readcondition or querycondition based on mask and scoped - * by the given instance handle. - * - * This operation implements the same functionality as dds_take_mask, except that only - * data scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] bufsz The size of buffer provided. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples read or an error code. - * - * @retval >=0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_instance_mask( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask); - -/** - * @brief Access loaned samples of data reader, readcondition or querycondition based - * on mask and scoped by the given intance handle. - * - * This operation implements the same functionality as dds_take_mask_wl, except that - * only data scoped to the provided instance handle is read. - * - * @param[in] reader_or_condition Reader, readcondition or querycondition entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si Pointer to an array of \ref dds_sample_info_t returned for each data value. - * @param[in] maxs Maximum number of samples to read. - * @param[in] handle Instance handle related to the samples to read. - * @param[in] mask Filter the data based on dds_sample_state_t|dds_view_state_t|dds_instance_state_t. - * - * @returns A dds_return_t with the number of samples or an error code. - * - * @retval >= 0 - * Number of samples read. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the given arguments is not valid. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - * @retval DDS_RETCODE_PRECONDITION_NOT_MET - * The instance handle has not been registered with this reader. - */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_take_instance_mask_wl( - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask); - -/* - The read/take next functions return a single sample. The returned sample - has a sample state of NOT_READ, a view state of ANY_VIEW_STATE and an - instance state of ANY_INSTANCE_STATE. -*/ - -/** - * @brief Read, copy and remove the status set for the entity - * - * This operation copies the next, non-previously accessed - * data value and corresponding sample info and removes from - * the data reader. As an entity, only reader is accepted. - * - * @param[in] reader The reader entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) -DDS_EXPORT dds_return_t -dds_take_next( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si); - -/** - * @brief Read, copy and remove the status set for the entity - * - * This operation copies the next, non-previously accessed - * data value and corresponding sample info and removes from - * the data reader. As an entity, only reader is accepted. - * - * After dds_take_next_wl function is being called and the data has been handled, - * dds_return_loan function must be called to possibly free memory. - * - * @param[in] reader The reader entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) -DDS_EXPORT dds_return_t -dds_take_next_wl( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si); - -/** - * @brief Read and copy the status set for the entity - * - * This operation copies the next, non-previously accessed - * data value and corresponding sample info. As an entity, - * only reader is accepted. - * - * @param[in] reader The reader entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) -DDS_EXPORT dds_return_t -dds_read_next( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si); - -/** - * @brief Read and copy the status set for the loaned sample - * - * This operation copies the next, non-previously accessed - * data value and corresponding loaned sample info. As an entity, - * only reader is accepted. - * - * After dds_read_next_wl function is being called and the data has been handled, - * dds_return_loan function must be called to possibly free memory. - * - * @param[in] reader The reader entity. - * @param[out] buf An array of pointers to samples into which data is read (pointers can be NULL). - * @param[out] si The pointer to \ref dds_sample_info_t returned for a data value. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) -DDS_EXPORT dds_return_t -dds_read_next_wl( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si); - -/** - * @brief Return loaned samples to data-reader or condition associated with a data-reader - * - * Used to release sample buffers returned by a read/take operation. When the application - * provides an empty buffer, memory is allocated and managed by DDS. By calling dds_return_loan, - * the memory is released so that the buffer can be reused during a successive read/take operation. - * When a condition is provided, the reader to which the condition belongs is looked up. - * - * @param[in] rd_or_cnd Reader or condition that belongs to a reader. - * @param[in] buf An array of (pointers to) samples. - * @param[in] bufsz The number of (pointers to) samples stored in buf. - * - * @returns A dds_return_t indicating success or failure - */ -/* TODO: Add list of possible return codes */ -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -DDS_EXPORT dds_return_t -dds_return_loan( - _In_ dds_entity_t reader_or_condition, - _Inout_updates_(bufsz) void **buf, - _In_ int32_t bufsz); - -/* - Instance handle <=> key value mapping. - Functions exactly as read w.r.t. treatment of data - parameter. On output, only key values set. - - T x = { ... }; - T y; - dds_instance_handle_t ih; - ih = dds_lookup_instance (e, &x); - dds_instance_get_key (e, ih, &y); -*/ - -/** - * @brief This operation takes a sample and returns an instance handle to be used for subsequent operations. - * - * @param[in] entity Reader or Writer entity. - * @param[in] data Sample with a key fields set. - * - * @returns instance handle or DDS_HANDLE_NIL if instance could not be found from key. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_instance_handle_t -dds_lookup_instance( - dds_entity_t entity, - const void *data); - -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_DEPRECATED_EXPORT dds_instance_handle_t -dds_instance_lookup ( - dds_entity_t entity, - const void *data); - -/** - * @brief This operation takes an instance handle and return a key-value corresponding to it. - * - * @param[in] entity Reader or writer entity. - * @param[in] inst Instance handle. - * @param[out] data pointer to an instance, to which the key ID corresponding to the instance handle will be - * returned, the sample in the instance should be ignored. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * One of the parameters was invalid or the topic does not exist. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - */ -/* TODO: Check return codes for completeness */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_return_t -dds_instance_get_key( - dds_entity_t entity, - dds_instance_handle_t inst, - void *data); - -/** - * @brief Begin coherent publishing or begin accessing a coherent set in a subscriber - * - * Invoking on a Writer or Reader behaves as if dds_begin_coherent was invoked on its parent - * Publisher or Subscriber respectively. - * - * @param[in] entity The entity that is prepared for coherent access. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_ERROR - * An internal error has occurred. - * @retval DDS_RETCODE_BAD_PARAMETER - * The provided entity is invalid or not supported. - */ -_Pre_satisfies_(((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) ) -DDS_EXPORT dds_return_t -dds_begin_coherent( - _In_ dds_entity_t entity); - -/** - * @brief End coherent publishing or end accessing a coherent set in a subscriber - * - * Invoking on a Writer or Reader behaves as if dds_end_coherent was invoked on its parent - * Publisher or Subscriber respectively. - * - * @param[in] entity The entity on which coherent access is finished. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The provided entity is invalid or not supported. - */ -_Pre_satisfies_(((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) ) -DDS_EXPORT dds_return_t -dds_end_coherent( - _In_ dds_entity_t entity); - -/** - * @brief Trigger DATA_AVAILABLE event on contained readers - * - * The DATA_AVAILABLE event is broadcast to all readers owned by this subscriber that currently - * have new data available. Any on_data_available listener callbacks attached to respective - * readers are invoked. - * - * @param[in] subscriber A valid subscriber handle. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The provided subscriber is invalid. - */ -_Pre_satisfies_((subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) -DDS_EXPORT dds_return_t -dds_notify_readers( - _In_ dds_entity_t subscriber); - -/** - * @brief Checks whether the entity has one of its enabled statuses triggered. - * - * @param[in] entity Entity for which to check for triggered status. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_return_t -dds_triggered( - _In_ dds_entity_t entity); - -/** - * @brief Get the topic - * - * This operation returns a topic (handle) when the function call is done - * with reader, writer, read condition or query condition. For instance, it - * will return the topic when it is used for creating the reader or writer. - * For the conditions, it returns the topic that is used for creating the reader - * which was used to create the condition. - * - * @param[in] entity The entity. - * - * @returns A dds_return_t indicating success or failure. - * - * @retval DDS_RETCODE_OK - * The operation was successful. - * @retval DDS_RETCODE_BAD_PARAMETER - * The entity parameter is not a valid parameter. - * @retval DDS_RETCODE_ILLEGAL_OPERATION - * The operation is invoked on an inappropriate object. - * @retval DDS_RETCODE_ALREADY_DELETED - * The entity has already been deleted. - */ -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) -DDS_EXPORT dds_entity_t -dds_get_topic( - _In_ dds_entity_t entity); - -#if defined (__cplusplus) -} -#endif -#endif /* DDS_H */ diff --git a/src/core/ddsc/include/ddsc/dds_public_error.h b/src/core/ddsc/include/ddsc/dds_public_error.h deleted file mode 100644 index 8082440..0000000 --- a/src/core/ddsc/include/ddsc/dds_public_error.h +++ /dev/null @@ -1,155 +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 - */ - -/** @file - * - * @brief DDS C Error API - * - * This header file defines the public API of error values and convenience - * functions in the CycloneDDS C language binding. - */ -#ifndef DDS_ERROR_H -#define DDS_ERROR_H - -#include "os/os_public.h" -#include "ddsc/dds_export.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -/* Error masks for returned status values */ - -#define DDS_ERR_NR_MASK 0x000000ff -#define DDS_ERR_LINE_MASK 0x003fff00 -#define DDS_ERR_FILE_ID_MASK 0x7fc00000 - - -/* - State is unchanged following a function call returning an error - other than UNSPECIFIED, OUT_OF_RESOURCES and ALREADY_DELETED. - - Error handling functions. Three components to returned int status value. - - 1 - The DDS_ERR_xxx error number - 2 - The file identifier - 3 - The line number - - All functions return >= 0 on success, < 0 on error -*/ -/** @name Return codes - @{**/ -#define DDS_RETCODE_OK 0 /**< Success */ -#define DDS_RETCODE_ERROR 1 /**< Non specific error */ -#define DDS_RETCODE_UNSUPPORTED 2 /**< Feature unsupported */ -#define DDS_RETCODE_BAD_PARAMETER 3 /**< Bad parameter value */ -#define DDS_RETCODE_PRECONDITION_NOT_MET 4 /**< Precondition for operation not met */ -#define DDS_RETCODE_OUT_OF_RESOURCES 5 /**< When an operation fails because of a lack of resources */ -#define DDS_RETCODE_NOT_ENABLED 6 /**< When a configurable feature is not enabled */ -#define DDS_RETCODE_IMMUTABLE_POLICY 7 /**< When an attempt is made to modify an immutable policy */ -#define DDS_RETCODE_INCONSISTENT_POLICY 8 /**< When a policy is used with inconsistent values */ -#define DDS_RETCODE_ALREADY_DELETED 9 /**< When an attempt is made to delete something more than once */ -#define DDS_RETCODE_TIMEOUT 10 /**< When a timeout has occurred */ -#define DDS_RETCODE_NO_DATA 11 /**< When expected data is not provided */ -#define DDS_RETCODE_ILLEGAL_OPERATION 12 /**< When a function is called when it should not be */ -#define DDS_RETCODE_NOT_ALLOWED_BY_SECURITY 13 /**< When credentials are not enough to use the function */ - - -/** @}*/ - -/* For backwards compatability */ - -#define DDS_SUCCESS DDS_RETCODE_OK - -/** @name DDS_Error_Type - @{**/ -#define DDS_CHECK_REPORT 0x01 -#define DDS_CHECK_FAIL 0x02 -#define DDS_CHECK_EXIT 0x04 -/** @}*/ - -/* Error code handling functions */ - -/** @name Macros for error handling - @{**/ -#define DDS_TO_STRING(n) #n -#define DDS_INT_TO_STRING(n) DDS_TO_STRING(n) -/** @}*/ - -/** Macro to extract error number */ -#define dds_err_nr(e) ((-(e)) & DDS_ERR_NR_MASK) - -/** Macro to extract line number */ -#define dds_err_line(e) (((-(e)) & DDS_ERR_LINE_MASK) >> 8) - -/** Macro to extract file identifier */ -#define dds_err_file_id(e) (((-(e)) & DDS_ERR_FILE_ID_MASK) >> 22) - -/** - * @brief Takes the error value and outputs a string corresponding to it. - * - * @param[in] err Error value to be converted to a string - * @returns String corresponding to the error value - */ -DDS_EXPORT const char * dds_err_str (dds_return_t err); - -/** - * @brief Takes the error number, error type and filename and line number and formats it to - * a string which can be used for debugging. - * - * @param[in] err Error value - * @param[in] flags Indicates Fail, Exit or Report - * @param[in] where File and line number - * @returns true - True - * @returns false - False - */ - -DDS_EXPORT bool dds_err_check (dds_return_t err, unsigned flags, const char * where); - -/** Macro that defines dds_err_check function */ -#define DDS_ERR_CHECK(e, f) (dds_err_check ((e), (f), __FILE__ ":" DDS_INT_TO_STRING(__LINE__))) - -/* Failure handling */ - -/** Failure handler */ -typedef void (*dds_fail_fn) (const char *, const char *); - -/** Macro that defines dds_fail function */ -#define DDS_FAIL(m) (dds_fail (m, __FILE__ ":" DDS_INT_TO_STRING (__LINE__))) - -/** - * @brief Set the failure function - * - * @param[in] fn Function to invoke on failure - */ -DDS_EXPORT void dds_fail_set (dds_fail_fn fn); - -/** - * @brief Get the failure function - * - * @returns Failure function - */ -DDS_EXPORT dds_fail_fn dds_fail_get (void); - -/** - * @brief Handles failure through an installed failure handler - * - * @params[in] msg String containing failure message - * @params[in] where String containing file and location - */ -DDS_EXPORT void dds_fail (const char * msg, const char * where); - - -#if defined (__cplusplus) -} -#endif -#endif diff --git a/src/core/ddsc/include/ddsc/dds_public_time.h b/src/core/ddsc/include/ddsc/dds_public_time.h deleted file mode 100644 index 4ecaabc..0000000 --- a/src/core/ddsc/include/ddsc/dds_public_time.h +++ /dev/null @@ -1,96 +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 - */ - -/** @file - * - * @brief DDS C Time support API - * - * This header file defines the public API of the in the - * Eclipse Cyclone DDS C language binding. - */ -#ifndef DDS_TIME_H -#define DDS_TIME_H - -#include "os/os_public.h" -#include "ddsc/dds_export.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -/* - Times are represented using a 64-bit signed integer, encoding - nanoseconds since the epoch. Considering the nature of these - systems, one would best use TAI, International Atomic Time, rather - than something UTC, but availability may be limited. - - Valid times are non-negative and times up to 2**63-2 can be - represented. 2**63-1 is defined to represent, essentially, "never". - This is good enough for a couple of centuries. -*/ - -/** Absolute Time definition */ -typedef int64_t dds_time_t; - -/** Relative Time definition */ -typedef int64_t dds_duration_t; - -/** @name Macro definition for time units in nanoseconds. - @{**/ -#define DDS_NSECS_IN_SEC 1000000000LL -#define DDS_NSECS_IN_MSEC 1000000LL -#define DDS_NSECS_IN_USEC 1000LL -/** @}*/ - -/** @name Infinite timeout for indicate absolute time */ -#define DDS_NEVER ((dds_time_t) INT64_MAX) - -/** @name Infinite timeout for relative time */ -#define DDS_INFINITY ((dds_duration_t) INT64_MAX) - -/** @name Macro definition for time conversion from nanoseconds - @{**/ -#define DDS_SECS(n) ((n) * DDS_NSECS_IN_SEC) -#define DDS_MSECS(n) ((n) * DDS_NSECS_IN_MSEC) -#define DDS_USECS(n) ((n) * DDS_NSECS_IN_USEC) -/** @}*/ - -/** - * Description : This operation returns the current time (in nanoseconds) - * - * Arguments : - * -# Returns current time - */ -DDS_EXPORT dds_time_t dds_time (void); - -/** - * Description : This operation blocks the calling thread until the relative time - * n has elapsed - * - * Arguments : - * -# n Relative Time to block a thread - */ -DDS_EXPORT void dds_sleepfor (dds_duration_t n); - -/** - * Description : This operation blocks the calling thread until the absolute time - * n has elapsed - * - * Arguments : - * -# n absolute Time to block a thread - */ -DDS_EXPORT void dds_sleepuntil (dds_time_t n); - -#if defined (__cplusplus) -} -#endif -#endif diff --git a/src/core/ddsc/src/dds__builtin.h b/src/core/ddsc/src/dds__builtin.h index 38c7d11..fd191f9 100644 --- a/src/core/ddsc/src/dds__builtin.h +++ b/src/core/ddsc/src/dds__builtin.h @@ -12,7 +12,7 @@ #ifndef _DDS_BUILTIN_H_ #define _DDS_BUILTIN_H_ -#include "ddsi/q_time.h" +#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" diff --git a/src/core/ddsc/src/dds__entity.h b/src/core/ddsc/src/dds__entity.h index 5154504..77ae66b 100644 --- a/src/core/ddsc/src/dds__entity.h +++ b/src/core/ddsc/src/dds__entity.h @@ -13,35 +13,31 @@ #define _DDS_ENTITY_H_ #include "dds__types.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_thread.h" #if defined (__cplusplus) extern "C" { #endif -_Check_return_ DDS_EXPORT dds_entity_t dds_entity_init( - _In_ dds_entity * e, - _When_(kind != DDS_KIND_PARTICIPANT, _Notnull_) - _When_(kind == DDS_KIND_PARTICIPANT, _Null_) - _In_opt_ dds_entity * parent, - _In_ dds_entity_kind_t kind, - _In_opt_ dds_qos_t * qos, - _In_opt_ const dds_listener_t *listener, - _In_ uint32_t mask); + dds_entity * e, + dds_entity * parent, + dds_entity_kind_t kind, + dds_qos_t * qos, + const dds_listener_t *listener, + uint32_t mask); DDS_EXPORT void -dds_entity_add_ref( - _In_ dds_entity *e); +dds_entity_add_ref(dds_entity *e); + DDS_EXPORT void -dds_entity_add_ref_nolock( - _In_ dds_entity *e); +dds_entity_add_ref_nolock(dds_entity *e); #define DEFINE_ENTITY_LOCK_UNLOCK(qualifier_, type_, kind_) \ - qualifier_ dds__retcode_t type_##_lock (dds_entity_t hdl, type_ **x) \ + qualifier_ dds_retcode_t type_##_lock (dds_entity_t hdl, type_ **x) \ { \ - dds__retcode_t rc; \ + dds_retcode_t rc; \ dds_entity *e; \ if ((rc = dds_entity_lock (hdl, kind_, &e)) != DDS_RETCODE_OK) \ return rc; \ @@ -54,7 +50,7 @@ dds_entity_add_ref_nolock( dds_entity_unlock (&x->m_entity); \ } #define DECL_ENTITY_LOCK_UNLOCK(qualifier_, type_) \ - qualifier_ dds__retcode_t type_##_lock (dds_entity_t hdl, type_ **x); \ + qualifier_ dds_retcode_t type_##_lock (dds_entity_t hdl, type_ **x); \ qualifier_ void type_##_unlock (type_ *x); DDS_EXPORT inline bool dds_entity_is_enabled (const dds_entity *e) { @@ -83,58 +79,52 @@ DDS_EXPORT void dds_entity_status_signal (dds_entity *e); DDS_EXPORT void dds_entity_invoke_listener (const dds_entity *entity, enum dds_status_id which, const void *vst); -_Check_return_ DDS_EXPORT dds__retcode_t -dds_valid_hdl( - _In_ dds_entity_t hdl, - _In_ dds_entity_kind_t kind); +DDS_EXPORT dds_retcode_t +dds_valid_hdl(dds_entity_t hdl, dds_entity_kind_t kind); -_Acquires_exclusive_lock_(*e) -_Check_return_ DDS_EXPORT dds__retcode_t +DDS_EXPORT dds_retcode_t dds_entity_lock( - _In_ dds_entity_t hdl, - _In_ dds_entity_kind_t kind, - _Out_ dds_entity **e); + dds_entity_t hdl, + dds_entity_kind_t kind, + dds_entity **e); -_Releases_exclusive_lock_(e) DDS_EXPORT void -dds_entity_unlock( - _Inout_ dds_entity *e); +dds_entity_unlock(dds_entity *e); -_Check_return_ DDS_EXPORT dds__retcode_t +DDS_EXPORT dds_retcode_t dds_entity_observer_register_nl( - _In_ dds_entity* observed, - _In_ dds_entity_t observer, - _In_ dds_entity_callback cb); + dds_entity *observed, + dds_entity_t observer, + dds_entity_callback cb); -_Check_return_ DDS_EXPORT dds__retcode_t +DDS_EXPORT dds_retcode_t dds_entity_observer_register( - _In_ dds_entity_t observed, - _In_ dds_entity_t observer, - _In_ dds_entity_callback cb); + dds_entity_t observed, + dds_entity_t observer, + dds_entity_callback cb); -DDS_EXPORT dds__retcode_t +DDS_EXPORT dds_retcode_t dds_entity_observer_unregister_nl( - _In_ dds_entity* observed, - _In_ dds_entity_t observer); + dds_entity *observed, + dds_entity_t observer); -DDS_EXPORT dds__retcode_t +DDS_EXPORT dds_retcode_t dds_entity_observer_unregister( - _In_ dds_entity_t observed, - _In_ dds_entity_t observer); + dds_entity_t observed, + dds_entity_t observer); -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) DDS_EXPORT dds_return_t dds_delete_impl( - _In_ dds_entity_t entity, - _In_ bool keep_if_explicit); + dds_entity_t entity, + bool keep_if_explicit); DDS_EXPORT const char * dds__entity_kind_str( - _In_ dds_entity_t e); + dds_entity_t e); DDS_EXPORT dds_domain * dds__entity_domain( - _In_ dds_entity* e); + dds_entity* e); #if defined (__cplusplus) } diff --git a/src/core/ddsc/src/dds__err.h b/src/core/ddsc/src/dds__err.h index 2bf976a..917051a 100644 --- a/src/core/ddsc/src/dds__err.h +++ b/src/core/ddsc/src/dds__err.h @@ -13,7 +13,8 @@ #define _DDS_ERR_H_ #include -#include "os/os.h" + +#include "dds/ddsrt/retcode.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/src/dds__guardcond.h b/src/core/ddsc/src/dds__guardcond.h index 5f1b030..7d57643 100644 --- a/src/core/ddsc/src/dds__guardcond.h +++ b/src/core/ddsc/src/dds__guardcond.h @@ -14,9 +14,9 @@ #include "dds__entity.h" -_Must_inspect_result_ dds_guardcond* +dds_guardcond* dds_create_guardcond( - _In_ dds_participant *pp); + dds_participant *pp); DEFINE_ENTITY_LOCK_UNLOCK(inline, dds_guardcond, DDS_KIND_COND_GUARD) diff --git a/src/core/ddsc/src/dds__init.h b/src/core/ddsc/src/dds__init.h index ea3136f..859a459 100644 --- a/src/core/ddsc/src/dds__init.h +++ b/src/core/ddsc/src/dds__init.h @@ -19,8 +19,7 @@ extern "C" { #endif dds_return_t -dds__check_domain( - _In_ dds_domainid_t domain); +dds__check_domain(dds_domainid_t domain); /** *Description : Initialization function, called from main. This operation @@ -46,8 +45,6 @@ dds_init(dds_domainid_t domain); void dds_fini(void); - - /** * Description : Function that provides the explicit ID of default domain * It should be called after DDS initialization. diff --git a/src/core/ddsc/src/dds__listener.h b/src/core/ddsc/src/dds__listener.h index 2d3ee90..fef4c37 100644 --- a/src/core/ddsc/src/dds__listener.h +++ b/src/core/ddsc/src/dds__listener.h @@ -13,7 +13,7 @@ #define _DDS_LISTENER_H_ #include "dds__types.h" -#include "ddsc/dds_public_listener.h" +#include "dds/ddsc/dds_public_listener.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/src/dds__publisher.h b/src/core/ddsc/src/dds__publisher.h index 8551d42..61427df 100644 --- a/src/core/ddsc/src/dds__publisher.h +++ b/src/core/ddsc/src/dds__publisher.h @@ -12,7 +12,7 @@ #ifndef _DDS_PUBLISHER_H_ #define _DDS_PUBLISHER_H_ -#include "ddsc/dds.h" +#include "dds/dds.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/src/dds__qos.h b/src/core/ddsc/src/dds__qos.h index 0f2e1a1..eec04ff 100644 --- a/src/core/ddsc/src/dds__qos.h +++ b/src/core/ddsc/src/dds__qos.h @@ -13,9 +13,9 @@ #define _DDS_QOS_H_ #include "dds__entity.h" -#include "ddsi/q_xqos.h" -#include "ddsi/q_time.h" -#include "ddsi/q_plist.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_plist.h" #if defined (__cplusplus) extern "C" { @@ -24,12 +24,12 @@ extern "C" { bool validate_deadline_and_timebased_filter (const nn_duration_t deadline, const nn_duration_t minimum_separation); bool validate_entityfactory_qospolicy (const nn_entity_factory_qospolicy_t * entityfactory); bool validate_octetseq (const nn_octetseq_t* seq); -bool validate_partition_qospolicy (_In_ const nn_partition_qospolicy_t * partition); +bool validate_partition_qospolicy (const nn_partition_qospolicy_t * partition); bool validate_reliability_qospolicy (const nn_reliability_qospolicy_t * reliability); bool validate_stringseq (const nn_stringseq_t* seq); bool dds_qos_validate_common (const dds_qos_t *qos); -dds_return_t dds_qos_validate_mutable_common (_In_ const dds_qos_t *qos); +dds_return_t dds_qos_validate_mutable_common (const dds_qos_t *qos); #if defined (__cplusplus) } diff --git a/src/core/ddsc/src/dds__readcond.h b/src/core/ddsc/src/dds__readcond.h index b5465c0..aa0494e 100644 --- a/src/core/ddsc/src/dds__readcond.h +++ b/src/core/ddsc/src/dds__readcond.h @@ -14,11 +14,11 @@ #include "dds__entity.h" -_Must_inspect_result_ dds_readcond* +dds_readcond * dds_create_readcond( - _In_ dds_reader *rd, - _In_ dds_entity_kind_t kind, - _In_ uint32_t mask, - _In_opt_ dds_querycondition_filter_fn filter); + dds_reader *rd, + dds_entity_kind_t kind, + uint32_t mask, + dds_querycondition_filter_fn filter); #endif diff --git a/src/core/ddsc/src/dds__rhc.h b/src/core/ddsc/src/dds__rhc.h index 21106bc..e01f7c4 100644 --- a/src/core/ddsc/src/dds__rhc.h +++ b/src/core/ddsc/src/dds__rhc.h @@ -12,11 +12,8 @@ #ifndef _DDS_RHC_H_ #define _DDS_RHC_H_ -#include "os/os_defs.h" - #define NO_STATE_MASK_SET (DDS_ANY_STATE + 1) - #if defined (__cplusplus) extern "C" { #endif diff --git a/src/core/ddsc/src/dds__serdata_builtintopic.h b/src/core/ddsc/src/dds__serdata_builtintopic.h index ff0771d..46ccf88 100644 --- a/src/core/ddsc/src/dds__serdata_builtintopic.h +++ b/src/core/ddsc/src/dds__serdata_builtintopic.h @@ -12,9 +12,9 @@ #ifndef DDSI_SERDATA_BUILTINTOPIC_H #define DDSI_SERDATA_BUILTINTOPIC_H -#include "ddsi/q_xqos.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_sertopic.h" struct ddsi_serdata_builtintopic { struct ddsi_serdata c; diff --git a/src/core/ddsc/src/dds__stream.h b/src/core/ddsc/src/dds__stream.h index fc0d62f..79eadd1 100644 --- a/src/core/ddsc/src/dds__stream.h +++ b/src/core/ddsc/src/dds__stream.h @@ -12,8 +12,8 @@ #ifndef _DDS_STREAM_H_ #define _DDS_STREAM_H_ -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_serdata_default.h" #if defined (__cplusplus) extern "C" { @@ -32,7 +32,7 @@ void dds_stream_read_sample const struct ddsi_sertopic_default * topic ); -size_t dds_stream_check_optimize (_In_ const dds_topic_descriptor_t * desc); +size_t dds_stream_check_optimize (const dds_topic_descriptor_t * desc); void dds_stream_from_serdata_default (dds_stream_t * s, const struct ddsi_serdata_default *d); void dds_stream_add_to_serdata_default (dds_stream_t * s, struct ddsi_serdata_default **d); diff --git a/src/core/ddsc/src/dds__subscriber.h b/src/core/ddsc/src/dds__subscriber.h index 3345cbf..0609b03 100644 --- a/src/core/ddsc/src/dds__subscriber.h +++ b/src/core/ddsc/src/dds__subscriber.h @@ -12,7 +12,7 @@ #ifndef _DDS_SUBSCRIBER_H_ #define _DDS_SUBSCRIBER_H_ -#include "ddsc/dds.h" +#include "dds/dds.h" #if defined (__cplusplus) extern "C" { @@ -20,20 +20,19 @@ extern "C" { struct dds_entity; -_Requires_exclusive_lock_held_(participant) -_Check_return_ dds_entity_t +dds_entity_t dds__create_subscriber_l( - _Inout_ struct dds_entity *participant, /* entity-lock must be held */ - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener); + struct dds_entity *participant, /* entity-lock must be held */ + const dds_qos_t *qos, + const dds_listener_t *listener); dds_return_t dds_subscriber_begin_coherent( - _In_ dds_entity_t e); + dds_entity_t e); dds_return_t dds_subscriber_end_coherent ( - _In_ dds_entity_t e); + dds_entity_t e); #if defined (__cplusplus) } diff --git a/src/core/ddsc/src/dds__types.h b/src/core/ddsc/src/dds__types.h index f9da5b7..75c53b8 100644 --- a/src/core/ddsc/src/dds__types.h +++ b/src/core/ddsc/src/dds__types.h @@ -14,18 +14,16 @@ /* DDS internal type definitions */ -#include "os/os.h" -#include "ddsc/dds.h" -#include "ddsi/q_rtps.h" -#include "util/ut_avl.h" -#include "util/ut_handleserver.h" +#include "dds/dds.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/util/ut_avl.h" +#include "dds/util/ut_handleserver.h" #if defined (__cplusplus) extern "C" { #endif -typedef _Return_type_success_(return == DDS_RETCODE_OK) int32_t dds__retcode_t; - struct dds_domain; struct dds_entity; struct dds_participant; @@ -139,11 +137,11 @@ typedef struct dds_entity dds_domainid_t m_domainid; nn_guid_t m_guid; uint32_t m_flags; - os_mutex m_mutex; - os_cond m_cond; + ddsrt_mutex_t m_mutex; + ddsrt_cond_t m_cond; - os_mutex m_observers_lock; - os_cond m_observers_cond; + ddsrt_mutex_t m_observers_lock; + ddsrt_cond_t m_observers_cond; dds_listener_t m_listener; uint32_t m_trigger; uint32_t m_status_enable; @@ -287,7 +285,7 @@ typedef struct dds_globals void (*m_dur_init) (void); void (*m_dur_fini) (void); ut_avlTree_t m_domains; - os_mutex m_mutex; + ddsrt_mutex_t m_mutex; } dds_globals; diff --git a/src/core/ddsc/src/dds__whc.h b/src/core/ddsc/src/dds__whc.h index 0c5a9c2..13b542d 100644 --- a/src/core/ddsc/src/dds__whc.h +++ b/src/core/ddsc/src/dds__whc.h @@ -12,7 +12,7 @@ #ifndef DDS__WHC_H #define DDS__WHC_H -#include "ddsi/q_whc.h" +#include "dds/ddsi/q_whc.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsc/src/dds__whc_builtintopic.h b/src/core/ddsc/src/dds__whc_builtintopic.h index 6c38157..47772fe 100644 --- a/src/core/ddsc/src/dds__whc_builtintopic.h +++ b/src/core/ddsc/src/dds__whc_builtintopic.h @@ -12,7 +12,7 @@ #ifndef DDS_WHC_BUILTINTOPIC_H #define DDS_WHC_BUILTINTOPIC_H -#include "ddsi/q_whc.h" +#include "dds/ddsi/q_whc.h" #include "dds__serdata_builtintopic.h" #if defined (__cplusplus) diff --git a/src/core/ddsc/src/dds_alloc.c b/src/core/ddsc/src/dds_alloc.c index 3c5546d..954f77d 100644 --- a/src/core/ddsc/src/dds_alloc.c +++ b/src/core/ddsc/src/dds_alloc.c @@ -11,10 +11,11 @@ */ #include #include + #include "dds__alloc.h" #include "dds__stream.h" -#include "os/os_heap.h" -#include "ddsi/q_config.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsi/q_config.h" /* #define OP_DEBUG_FREE 1 @@ -28,26 +29,24 @@ static const char * stream_op_type[11] = }; #endif -static dds_allocator_t dds_allocator_fns = { os_malloc, os_realloc, os_free }; +static dds_allocator_t dds_allocator_fns = { ddsrt_malloc, ddsrt_realloc, ddsrt_free }; void * dds_alloc (size_t size) { void * ret = (dds_allocator_fns.malloc) (size); - if (ret) - { + if (ret == NULL) { + DDS_FATAL("dds_alloc"); + } else { memset (ret, 0, size); } - else - { - DDS_FAIL ("dds_alloc"); - } return ret; } void * dds_realloc (void * ptr, size_t size) { void * ret = (dds_allocator_fns.realloc) (ptr, size); - if (ret == NULL) DDS_FAIL ("dds_realloc"); + if (ret == NULL) + DDS_FATAL("dds_realloc"); return ret; } diff --git a/src/core/ddsc/src/dds_builtin.c b/src/core/ddsc/src/dds_builtin.c index d5ad2f1..1cdb382 100644 --- a/src/core/ddsc/src/dds_builtin.c +++ b/src/core/ddsc/src/dds_builtin.c @@ -11,9 +11,9 @@ */ #include #include -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_config.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_config.h" #include "dds__init.h" #include "dds__qos.h" #include "dds__domain.h" @@ -26,8 +26,8 @@ #include "dds__writer.h" #include "dds__whc_builtintopic.h" #include "dds__serdata_builtintopic.h" -#include "ddsi/q_qosmatch.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/q_qosmatch.h" +#include "dds/ddsi/ddsi_tkmap.h" static struct ddsi_sertopic *builtin_participant_topic; static struct ddsi_sertopic *builtin_reader_topic; diff --git a/src/core/ddsc/src/dds_coherent.c b/src/core/ddsc/src/dds_coherent.c index 9556776..7f35660 100644 --- a/src/core/ddsc/src/dds_coherent.c +++ b/src/core/ddsc/src/dds_coherent.c @@ -11,70 +11,62 @@ */ #include -#include "ddsc/dds.h" +#include "dds/dds.h" #include "dds__entity.h" #include "dds__subscriber.h" #include "dds__publisher.h" #include "dds__err.h" -_Pre_satisfies_(((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) ) dds_return_t dds_begin_coherent( - _In_ dds_entity_t entity) + dds_entity_t entity) { - dds_return_t ret; + dds_return_t ret; - switch(dds_entity_kind_from_handle(entity)) { - case DDS_KIND_READER: - case DDS_KIND_WRITER: - /* Invoking on a writer/reader behaves as if invoked on - * its parent publisher/subscriber. */ - ret = dds_begin_coherent(dds_get_parent(entity)); - break; - case DDS_KIND_PUBLISHER: - ret = dds_publisher_begin_coherent(entity); - break; - case DDS_KIND_SUBSCRIBER: - ret = dds_subscriber_begin_coherent(entity); - break; - default: - DDS_ERROR("Given entity can not control coherency\n"); - ret = DDS_ERRNO(DDS_RETCODE_BAD_PARAMETER); - break; - } - return ret; + switch(dds_entity_kind_from_handle(entity)) { + case DDS_KIND_READER: + case DDS_KIND_WRITER: + /* Invoking on a writer/reader behaves as if invoked on + * its parent publisher/subscriber. */ + ret = dds_begin_coherent(dds_get_parent(entity)); + break; + case DDS_KIND_PUBLISHER: + ret = dds_publisher_begin_coherent(entity); + break; + case DDS_KIND_SUBSCRIBER: + ret = dds_subscriber_begin_coherent(entity); + break; + default: + DDS_ERROR("Given entity can not control coherency\n"); + ret = DDS_ERRNO(DDS_RETCODE_BAD_PARAMETER); + break; + } + return ret; } -_Pre_satisfies_(((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) || \ - ((entity & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) ) dds_return_t dds_end_coherent( - _In_ dds_entity_t entity) + dds_entity_t entity) { - dds_return_t ret; + dds_return_t ret; - switch(dds_entity_kind_from_handle(entity)) { - case DDS_KIND_READER: - case DDS_KIND_WRITER: - /* Invoking on a writer/reader behaves as if invoked on - * its parent publisher/subscriber. */ - ret = dds_end_coherent(dds_get_parent(entity)); - break; - case DDS_KIND_PUBLISHER: - ret = dds_publisher_end_coherent(entity); - break; - case DDS_KIND_SUBSCRIBER: - ret = dds_subscriber_end_coherent(entity); - break; - default: - DDS_ERROR("Given entity can not control coherency\n"); - ret = DDS_ERRNO(DDS_RETCODE_BAD_PARAMETER); - break; - } - return ret; + switch(dds_entity_kind_from_handle(entity)) { + case DDS_KIND_READER: + case DDS_KIND_WRITER: + /* Invoking on a writer/reader behaves as if invoked on + * its parent publisher/subscriber. */ + ret = dds_end_coherent(dds_get_parent(entity)); + break; + case DDS_KIND_PUBLISHER: + ret = dds_publisher_end_coherent(entity); + break; + case DDS_KIND_SUBSCRIBER: + ret = dds_subscriber_end_coherent(entity); + break; + default: + DDS_ERROR("Given entity can not control coherency\n"); + ret = DDS_ERRNO(DDS_RETCODE_BAD_PARAMETER); + break; + } + return ret; } diff --git a/src/core/ddsc/src/dds_domain.c b/src/core/ddsc/src/dds_domain.c index 08613b8..f2dfaa4 100644 --- a/src/core/ddsc/src/dds_domain.c +++ b/src/core/ddsc/src/dds_domain.c @@ -10,7 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "dds__domain.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" static int dds_domain_compare (const int32_t * a, const int32_t * b) { @@ -33,7 +33,7 @@ dds_domain * dds_domain_find_locked (dds_domainid_t id) dds_domain * dds_domain_create (dds_domainid_t id) { dds_domain * domain; - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); domain = dds_domain_find_locked (id); if (domain == NULL) { @@ -43,17 +43,17 @@ dds_domain * dds_domain_create (dds_domainid_t id) ut_avlInsert (&dds_domaintree_def, &dds_global.m_domains, domain); } domain->m_refc++; - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); return domain; } void dds_domain_free (dds_domain * domain) { - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); if (--domain->m_refc == 0) { ut_avlDelete (&dds_domaintree_def, &dds_global.m_domains, domain); dds_free (domain); } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); } diff --git a/src/core/ddsc/src/dds_entity.c b/src/core/ddsc/src/dds_entity.c index 0c4a91a..cbb34d3 100644 --- a/src/core/ddsc/src/dds_entity.c +++ b/src/core/ddsc/src/dds_entity.c @@ -11,13 +11,16 @@ */ #include #include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" #include "dds__entity.h" #include "dds__write.h" #include "dds__writer.h" #include "dds__reader.h" #include "dds__listener.h" #include "dds__err.h" -#include "ddsc/ddsc_project.h" +#include "dds/version.h" /* Sanity check. */ #if DDS_ENTITY_KIND_MASK != UT_HANDLE_KIND_MASK @@ -40,9 +43,9 @@ void dds_entity_add_ref_nolock (dds_entity *e) void dds_entity_add_ref (dds_entity *e) { - os_mutexLock (&e->m_mutex); + ddsrt_mutex_lock (&e->m_mutex); dds_entity_add_ref_nolock (e); - os_mutexUnlock (&e->m_mutex); + ddsrt_mutex_unlock (&e->m_mutex); } dds_domain *dds__entity_domain (dds_entity *e) @@ -53,7 +56,7 @@ dds_domain *dds__entity_domain (dds_entity *e) static void dds_set_explicit (dds_entity_t entity) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) == DDS_RETCODE_OK) { e->m_flags &= ~DDS_ENTITY_IMPLICIT; @@ -83,10 +86,10 @@ dds_entity_t dds_entity_init (dds_entity *e, dds_entity *parent, dds_entity_kind /* set the status enable based on kind */ e->m_status_enable = mask | DDS_INTERNAL_STATUS_MASK; - os_mutexInit (&e->m_mutex); - os_mutexInit (&e->m_observers_lock); - os_condInit (&e->m_cond, &e->m_mutex); - os_condInit (&e->m_observers_cond, &e->m_observers_lock); + ddsrt_mutex_init (&e->m_mutex); + ddsrt_mutex_init (&e->m_observers_lock); + ddsrt_cond_init (&e->m_cond); + ddsrt_cond_init (&e->m_observers_cond); if (parent) { @@ -108,9 +111,9 @@ dds_entity_t dds_entity_init (dds_entity *e, dds_entity *parent, dds_entity_kind dds_merge_listener (&e->m_listener, listener); if (parent) { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); dds_inherit_listener (&e->m_listener, &parent->m_listener); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); } e->m_hdllink = NULL; @@ -126,7 +129,7 @@ dds_entity_t dds_entity_init (dds_entity *e, dds_entity *parent, dds_entity_kind DDS_ERROR ("Can not create new entity; too many where created previously\n"); e->m_hdl = DDS_ERRNO (DDS_RETCODE_OUT_OF_RESOURCES); } else if (e->m_hdl == UT_HANDLE_NOT_INITALIZED) { - DDS_ERROR (DDSC_PROJECT_NAME" is not yet initialized. Please create a participant before executing an other method\n"); + DDS_ERROR (DDS_PROJECT_NAME" is not yet initialized. Please create a participant before executing an other method\n"); e->m_hdl = DDS_ERRNO (DDS_RETCODE_PRECONDITION_NOT_MET); } else { DDS_ERROR ("An internal error has occurred\n"); @@ -152,14 +155,14 @@ static dds_entity *next_non_topic_child (dds_entity *remaining_children) dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) { - os_time timeout = { 10, 0 }; + dds_time_t timeout = DDS_SECS(10); dds_entity *e; dds_entity *child; dds_entity *parent; dds_entity *prev = NULL; dds_entity *next = NULL; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; rc = dds_entity_lock (entity, UT_HANDLE_DONTCARE_KIND, &e); if (rc != DDS_RETCODE_OK) @@ -181,13 +184,13 @@ dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) } ut_handle_close (e->m_hdl, e->m_hdllink); - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); while (e->m_cb_count > 0) - os_condWait (&e->m_observers_cond, &e->m_observers_lock); + ddsrt_cond_wait (&e->m_observers_cond, &e->m_observers_lock); e->m_status_enable = 0; dds_reset_listener (&e->m_listener); e->m_trigger |= DDS_DELETING_STATUS; - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); dds_entity_unlock(e); /* Signal observers that this entity will be deleted. */ @@ -251,7 +254,7 @@ dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) /* Remove from parent */ if ((parent = dds__nonself_parent(e)) != NULL) { - os_mutexLock (&parent->m_mutex); + ddsrt_mutex_lock (&parent->m_mutex); child = parent->m_children; while (child && child != e) { @@ -263,7 +266,7 @@ dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) prev->m_next = e->m_next; else parent->m_children = e->m_next; - os_mutexUnlock (&parent->m_mutex); + ddsrt_mutex_unlock (&parent->m_mutex); } /* Do some specific deletion when needed. */ @@ -274,10 +277,10 @@ dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) if (ret == DDS_RETCODE_OK) { dds_delete_qos (e->m_qos); - os_condDestroy (&e->m_cond); - os_condDestroy (&e->m_observers_cond); - os_mutexDestroy (&e->m_mutex); - os_mutexDestroy (&e->m_observers_lock); + ddsrt_cond_destroy (&e->m_cond); + ddsrt_cond_destroy (&e->m_observers_cond); + ddsrt_mutex_destroy (&e->m_mutex); + ddsrt_mutex_destroy (&e->m_observers_lock); dds_free (e); } @@ -287,7 +290,7 @@ dds_return_t dds_delete_impl (dds_entity_t entity, bool keep_if_explicit) dds_entity_t dds_get_parent (dds_entity_t entity) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); else @@ -309,7 +312,7 @@ dds_entity_t dds_get_parent (dds_entity_t entity) dds_entity_t dds_get_participant (dds_entity_t entity) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); else @@ -323,7 +326,7 @@ dds_entity_t dds_get_participant (dds_entity_t entity) dds_return_t dds_get_children (dds_entity_t entity, dds_entity_t *children, size_t size) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if (children != NULL && (size <= 0 || size >= INT32_MAX)) return DDS_ERRNO (DDS_RETCODE_BAD_PARAMETER); @@ -354,7 +357,7 @@ dds_return_t dds_get_children (dds_entity_t entity, dds_entity_t *children, size dds_return_t dds_get_qos (dds_entity_t entity, dds_qos_t *qos) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (qos == NULL) @@ -377,7 +380,7 @@ dds_return_t dds_get_qos (dds_entity_t entity, dds_qos_t *qos) dds_return_t dds_set_qos (dds_entity_t entity, const dds_qos_t *qos) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (qos == NULL) @@ -406,14 +409,14 @@ dds_return_t dds_get_listener (dds_entity_t entity, dds_listener_t *listener) { dds_entity *e; dds_return_t ret = DDS_RETCODE_OK; - dds__retcode_t rc; + dds_retcode_t rc; if (listener != NULL) { rc = dds_entity_lock(entity, DDS_KIND_DONTCARE, &e); if (rc == DDS_RETCODE_OK) { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); dds_copy_listener (listener, &e->m_listener); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); dds_entity_unlock(e); } else { DDS_ERROR("Error occurred on locking entity\n"); @@ -538,7 +541,7 @@ static void pushdown_listener (dds_entity_t entity) while ((ncs = dds_get_children (entity, cs, (size_t) size)) > size) { size = ncs; - cs = os_realloc (cs, (size_t) size * sizeof (*cs)); + cs = ddsrt_realloc (cs, (size_t) size * sizeof (*cs)); } for (int i = 0; i < ncs; i++) { @@ -546,30 +549,30 @@ static void pushdown_listener (dds_entity_t entity) if (dds_entity_lock (cs[i], DDS_KIND_DONTCARE, &e) == DDS_RETCODE_OK) { dds_listener_t tmp; - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); while (e->m_cb_count > 0) - os_condWait (&e->m_observers_cond, &e->m_observers_lock); + ddsrt_cond_wait (&e->m_observers_cond, &e->m_observers_lock); dds_get_listener (entity, &tmp); dds_override_inherited_listener (&e->m_listener, &tmp); clear_status_with_listener (e); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); dds_entity_unlock (e); } } - os_free (cs); + ddsrt_free (cs); } dds_return_t dds_set_listener (dds_entity_t entity, const dds_listener_t *listener) { dds_entity *e, *x; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); while (e->m_cb_count > 0) - os_condWait (&e->m_observers_cond, &e->m_observers_lock); + ddsrt_cond_wait (&e->m_observers_cond, &e->m_observers_lock); /* new listener is constructed by combining "listener" with the ancestral listeners; the new set of listeners is then pushed down into the descendant entities, overriding @@ -584,7 +587,7 @@ dds_return_t dds_set_listener (dds_entity_t entity, const dds_listener_t *listen dds_inherit_listener (&e->m_listener, &x->m_listener); } clear_status_with_listener (e); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); dds_entity_unlock (e); pushdown_listener (entity); return DDS_RETCODE_OK; @@ -593,7 +596,7 @@ dds_return_t dds_set_listener (dds_entity_t entity, const dds_listener_t *listen dds_return_t dds_enable (dds_entity_t entity) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock(entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); @@ -611,7 +614,7 @@ dds_return_t dds_enable (dds_entity_t entity) dds_return_t dds_get_status_changes (dds_entity_t entity, uint32_t *status) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (status == NULL) @@ -624,9 +627,9 @@ dds_return_t dds_get_status_changes (dds_entity_t entity, uint32_t *status) ret = DDS_ERRNO (DDS_RETCODE_ILLEGAL_OPERATION); else { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); *status = e->m_trigger; - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); ret = DDS_RETCODE_OK; } dds_entity_unlock(e); @@ -636,7 +639,7 @@ dds_return_t dds_get_status_changes (dds_entity_t entity, uint32_t *status) dds_return_t dds_get_status_mask (dds_entity_t entity, uint32_t *mask) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (mask == NULL) @@ -649,9 +652,9 @@ dds_return_t dds_get_status_mask (dds_entity_t entity, uint32_t *mask) ret = DDS_ERRNO (DDS_RETCODE_ILLEGAL_OPERATION); else { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); *mask = (e->m_status_enable & ~DDS_INTERNAL_STATUS_MASK); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); ret = DDS_RETCODE_OK; } dds_entity_unlock(e); @@ -666,7 +669,7 @@ dds_return_t dds_get_enabled_status (dds_entity_t entity, uint32_t *status) dds_return_t dds_set_status_mask (dds_entity_t entity, uint32_t mask) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) @@ -676,12 +679,12 @@ dds_return_t dds_set_status_mask (dds_entity_t entity, uint32_t mask) ret = DDS_ERRNO (DDS_RETCODE_ILLEGAL_OPERATION); else if ((ret = e->m_deriver.validate_status (mask)) == DDS_RETCODE_OK) { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); /* Don't block internal status triggers. */ mask |= DDS_INTERNAL_STATUS_MASK; e->m_status_enable = mask; e->m_trigger &= mask; - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); } dds_entity_unlock(e); return ret; @@ -695,7 +698,7 @@ dds_return_t dds_set_enabled_status(dds_entity_t entity, uint32_t mask) static dds_return_t dds_readtake_status (dds_entity_t entity, uint32_t *status, uint32_t mask, bool reset) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (status == NULL) @@ -708,11 +711,11 @@ static dds_return_t dds_readtake_status (dds_entity_t entity, uint32_t *status, ret = DDS_ERRNO (DDS_RETCODE_ILLEGAL_OPERATION); else if ((ret = e->m_deriver.validate_status (mask)) == DDS_RETCODE_OK) { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); *status = e->m_trigger & mask; if (reset) e->m_trigger &= ~mask; - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); } dds_entity_unlock (e); return ret; @@ -732,7 +735,7 @@ dds_return_t dds_take_status (dds_entity_t entity, uint32_t *status, uint32_t ma dds_return_t dds_get_domainid (dds_entity_t entity, dds_domainid_t *id) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; if (id == NULL) return DDS_ERRNO (DDS_RETCODE_BAD_PARAMETER); @@ -748,7 +751,7 @@ dds_return_t dds_get_domainid (dds_entity_t entity, dds_domainid_t *id) dds_return_t dds_get_instance_handle (dds_entity_t entity, dds_instance_handle_t *ihdl) { dds_entity *e; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if (ihdl == NULL) @@ -766,7 +769,7 @@ dds_return_t dds_get_instance_handle (dds_entity_t entity, dds_instance_handle_t } -dds__retcode_t dds_valid_hdl (dds_entity_t hdl, dds_entity_kind_t kind) +dds_retcode_t dds_valid_hdl (dds_entity_t hdl, dds_entity_kind_t kind) { ut_handle_t utr; if ((utr = ut_handle_status (hdl, NULL, (int32_t) kind)) == UT_HANDLE_OK) @@ -793,7 +796,7 @@ dds__retcode_t dds_valid_hdl (dds_entity_t hdl, dds_entity_kind_t kind) } } -dds__retcode_t dds_entity_lock (dds_entity_t hdl, dds_entity_kind_t kind, dds_entity **eptr) +dds_retcode_t dds_entity_lock (dds_entity_t hdl, dds_entity_kind_t kind, dds_entity **eptr) { ut_handle_t utr; void *raw; @@ -804,7 +807,7 @@ dds__retcode_t dds_entity_lock (dds_entity_t hdl, dds_entity_kind_t kind, dds_en { dds_entity *e; *eptr = e = raw; - os_mutexLock (&e->m_mutex); + ddsrt_mutex_lock (&e->m_mutex); /* FIXME: The handle could have been closed while we were waiting for the mutex -- that should be handled differently! For now, however, it is really important at two points in the logic: @@ -845,7 +848,7 @@ dds__retcode_t dds_entity_lock (dds_entity_t hdl, dds_entity_kind_t kind, dds_en void dds_entity_unlock (dds_entity *e) { - os_mutexUnlock (&e->m_mutex); + ddsrt_mutex_unlock (&e->m_mutex); ut_handle_release (e->m_hdl, e->m_hdllink); } @@ -853,13 +856,13 @@ dds_return_t dds_triggered (dds_entity_t entity) { dds_entity *e; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_entity_lock(entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); ret = (e->m_trigger != 0); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); dds_entity_unlock (e); return ret; } @@ -873,29 +876,29 @@ static bool in_observer_list_p (const struct dds_entity *observed, const dds_ent return false; } -dds__retcode_t dds_entity_observer_register_nl (dds_entity *observed, dds_entity_t observer, dds_entity_callback cb) +dds_retcode_t dds_entity_observer_register_nl (dds_entity *observed, dds_entity_t observer, dds_entity_callback cb) { - dds__retcode_t rc; + dds_retcode_t rc; assert (observed); - os_mutexLock (&observed->m_observers_lock); + ddsrt_mutex_lock (&observed->m_observers_lock); if (in_observer_list_p (observed, observer)) rc = DDS_RETCODE_PRECONDITION_NOT_MET; else { - dds_entity_observer *o = os_malloc (sizeof (dds_entity_observer)); + dds_entity_observer *o = ddsrt_malloc (sizeof (dds_entity_observer)); o->m_cb = cb; o->m_observer = observer; o->m_next = observed->m_observers; observed->m_observers = o; rc = DDS_RETCODE_OK; } - os_mutexUnlock (&observed->m_observers_lock); + ddsrt_mutex_unlock (&observed->m_observers_lock); return rc; } -dds__retcode_t dds_entity_observer_register (dds_entity_t observed, dds_entity_t observer, dds_entity_callback cb) +dds_retcode_t dds_entity_observer_register (dds_entity_t observed, dds_entity_t observer, dds_entity_callback cb) { - dds__retcode_t rc; + dds_retcode_t rc; dds_entity *e; assert (cb); if ((rc = dds_entity_lock (observed, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) @@ -905,12 +908,12 @@ dds__retcode_t dds_entity_observer_register (dds_entity_t observed, dds_entity_t return rc; } -dds__retcode_t dds_entity_observer_unregister_nl (dds_entity *observed, dds_entity_t observer) +dds_retcode_t dds_entity_observer_unregister_nl (dds_entity *observed, dds_entity_t observer) { - dds__retcode_t rc; + dds_retcode_t rc; dds_entity_observer *prev, *idx; - os_mutexLock (&observed->m_observers_lock); + ddsrt_mutex_lock (&observed->m_observers_lock); prev = NULL; idx = observed->m_observers; while (idx != NULL && idx->m_observer != observer) @@ -926,16 +929,16 @@ dds__retcode_t dds_entity_observer_unregister_nl (dds_entity *observed, dds_enti observed->m_observers = idx->m_next; else prev->m_next = idx->m_next; - os_free (idx); + ddsrt_free (idx); rc = DDS_RETCODE_OK; } - os_mutexUnlock (&observed->m_observers_lock); + ddsrt_mutex_unlock (&observed->m_observers_lock); return rc; } -dds__retcode_t dds_entity_observer_unregister (dds_entity_t observed, dds_entity_t observer) +dds_retcode_t dds_entity_observer_unregister (dds_entity_t observed, dds_entity_t observer) { - dds__retcode_t rc; + dds_retcode_t rc; dds_entity *e; if ((rc = dds_entity_lock (observed, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return rc; @@ -947,16 +950,16 @@ dds__retcode_t dds_entity_observer_unregister (dds_entity_t observed, dds_entity static void dds_entity_observers_delete (dds_entity *observed) { dds_entity_observer *idx; - os_mutexLock (&observed->m_observers_lock); + ddsrt_mutex_lock (&observed->m_observers_lock); idx = observed->m_observers; while (idx != NULL) { dds_entity_observer *next = idx->m_next; - os_free (idx); + ddsrt_free (idx); idx = next; } observed->m_observers = NULL; - os_mutexUnlock (&observed->m_observers_lock); + ddsrt_mutex_unlock (&observed->m_observers_lock); } static void dds_entity_observers_signal (dds_entity *observed, uint32_t status) @@ -967,9 +970,9 @@ static void dds_entity_observers_signal (dds_entity *observed, uint32_t status) void dds_entity_status_signal (dds_entity *e) { - os_mutexLock (&e->m_observers_lock); + ddsrt_mutex_lock (&e->m_observers_lock); dds_entity_observers_signal (e, e->m_trigger); - os_mutexUnlock (&e->m_observers_lock); + ddsrt_mutex_unlock (&e->m_observers_lock); } void dds_entity_status_set (dds_entity *e, uint32_t t) @@ -983,7 +986,7 @@ void dds_entity_status_set (dds_entity *e, uint32_t t) dds_entity_t dds_get_topic (dds_entity_t entity) { - dds__retcode_t rc; + dds_retcode_t rc; dds_entity_t hdl; dds_entity *e; diff --git a/src/core/ddsc/src/dds_err.c b/src/core/ddsc/src/dds_err.c deleted file mode 100644 index 7992113..0000000 --- a/src/core/ddsc/src/dds_err.c +++ /dev/null @@ -1,102 +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 - */ -#include -#include "os/os.h" -#include "dds__types.h" -#include "dds__err.h" - -#define DDS_ERR_CODE_NUM 12 -#define DDS_ERR_MSG_MAX 128 - -#define DDS_ERR_NR_INDEX(e) (((-e) & DDS_ERR_NR_MASK) -1) - -static const char * dds_err_code_array[DDS_ERR_CODE_NUM] = -{ - "Error", - "Unsupported", - "Bad Parameter", - "Precondition Not Met", - "Out Of Resources", - "Not Enabled", - "Immutable Policy", - "Inconsistent Policy", - "Already Deleted", - "Timeout", - "No Data", - "Illegal Operation" -}; - -const char * dds_err_str (dds_return_t err) -{ - unsigned index = (unsigned)DDS_ERR_NR_INDEX (err); - if (err >= 0) - { - return "Success"; - } - if (index >= DDS_ERR_CODE_NUM) - { - return "Unknown"; - } - return dds_err_code_array[index]; -} - -bool dds_err_check (dds_return_t err, unsigned flags, const char * where) -{ - if (err < 0) - { - if (flags & (DDS_CHECK_REPORT | DDS_CHECK_FAIL)) - { - char msg[DDS_ERR_MSG_MAX]; - (void) snprintf (msg, DDS_ERR_MSG_MAX, "Error %d:M%d:%s", dds_err_file_id(err), dds_err_line(err), dds_err_str(err)); - if (flags & DDS_CHECK_REPORT) - { - printf ("%s: %s\n", where, msg); - } - if (flags & DDS_CHECK_FAIL) - { - dds_fail (msg, where); - } - } - if (flags & DDS_CHECK_EXIT) - { - exit (-1); - } - } - return (err >= 0); -} - - -static void dds_fail_default (const char * msg, const char * where) -{ - fprintf (stderr, "Aborting Failure: %s %s\n", where, msg); - abort (); -} - -static dds_fail_fn dds_fail_func = dds_fail_default; - -void dds_fail_set (dds_fail_fn fn) -{ - dds_fail_func = fn; -} - -dds_fail_fn dds_fail_get (void) -{ - return dds_fail_func; -} - -void dds_fail (const char * msg, const char * where) -{ - if (dds_fail_func) - { - (dds_fail_func) (msg, where); - } -} diff --git a/src/core/ddsc/src/dds_guardcond.c b/src/core/ddsc/src/dds_guardcond.c index eadbadc..c1e289a 100644 --- a/src/core/ddsc/src/dds_guardcond.c +++ b/src/core/ddsc/src/dds_guardcond.c @@ -15,16 +15,16 @@ #include "dds__guardcond.h" #include "dds__participant.h" #include "dds__err.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" DECL_ENTITY_LOCK_UNLOCK(extern inline, dds_guardcond) dds_entity_t dds_create_guardcondition (dds_entity_t participant) { dds_participant *pp; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_participant_lock (participant, &pp)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); @@ -40,18 +40,18 @@ dds_entity_t dds_create_guardcondition (dds_entity_t participant) dds_return_t dds_set_guardcondition (dds_entity_t condition, bool triggered) { dds_guardcond *gcond; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_guardcond_lock (condition, &gcond)) != DDS_RETCODE_OK) return DDS_ERRNO (dds_valid_hdl (condition, DDS_KIND_COND_GUARD)); else { - os_mutexLock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_lock (&gcond->m_entity.m_observers_lock); if (triggered) dds_entity_status_set (&gcond->m_entity, DDS_WAITSET_TRIGGER_STATUS); else dds_entity_status_reset (&gcond->m_entity, DDS_WAITSET_TRIGGER_STATUS); - os_mutexUnlock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&gcond->m_entity.m_observers_lock); dds_guardcond_unlock (gcond); return DDS_RETCODE_OK; } @@ -60,7 +60,7 @@ dds_return_t dds_set_guardcondition (dds_entity_t condition, bool triggered) dds_return_t dds_read_guardcondition (dds_entity_t condition, bool *triggered) { dds_guardcond *gcond; - dds__retcode_t rc; + dds_retcode_t rc; if (triggered == NULL) return DDS_ERRNO (DDS_RETCODE_BAD_PARAMETER); @@ -70,9 +70,9 @@ dds_return_t dds_read_guardcondition (dds_entity_t condition, bool *triggered) return DDS_ERRNO (dds_valid_hdl (condition, DDS_KIND_COND_GUARD)); else { - os_mutexLock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_lock (&gcond->m_entity.m_observers_lock); *triggered = dds_entity_status_match (&gcond->m_entity, DDS_WAITSET_TRIGGER_STATUS); - os_mutexUnlock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&gcond->m_entity.m_observers_lock); dds_guardcond_unlock (gcond); return DDS_RETCODE_OK; } @@ -81,7 +81,7 @@ dds_return_t dds_read_guardcondition (dds_entity_t condition, bool *triggered) dds_return_t dds_take_guardcondition (dds_entity_t condition, bool *triggered) { dds_guardcond *gcond; - dds__retcode_t rc; + dds_retcode_t rc; if (triggered == NULL) return DDS_ERRNO (DDS_RETCODE_BAD_PARAMETER); @@ -91,10 +91,10 @@ dds_return_t dds_take_guardcondition (dds_entity_t condition, bool *triggered) return DDS_ERRNO (dds_valid_hdl (condition, DDS_KIND_COND_GUARD)); else { - os_mutexLock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_lock (&gcond->m_entity.m_observers_lock); *triggered = dds_entity_status_match (&gcond->m_entity, DDS_WAITSET_TRIGGER_STATUS); dds_entity_status_reset (&gcond->m_entity, DDS_WAITSET_TRIGGER_STATUS); - os_mutexUnlock (&gcond->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&gcond->m_entity.m_observers_lock); dds_guardcond_unlock (gcond); return DDS_RETCODE_OK; } diff --git a/src/core/ddsc/src/dds_init.c b/src/core/ddsc/src/dds_init.c index 821964d..1a434b5 100644 --- a/src/core/ddsc/src/dds_init.c +++ b/src/core/ddsc/src/dds_init.c @@ -12,24 +12,23 @@ #include #include #include -#include "os/os.h" + +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/process.h" #include "dds__init.h" #include "dds__rhc.h" #include "dds__domain.h" #include "dds__err.h" #include "dds__builtin.h" #include "dds__whc_builtintopic.h" -#include "ddsi/ddsi_iid.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_servicelease.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_config.h" -#include "ddsc/ddsc_project.h" - -#ifdef _WRS_KERNEL -char *os_environ[] = { NULL }; -#endif +#include "dds/ddsi/ddsi_iid.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_servicelease.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_config.h" +#include "dds/version.h" #define DOMAIN_ID_MIN 0 #define DOMAIN_ID_MAX 230 @@ -43,17 +42,17 @@ dds_return_t dds_init(dds_domainid_t domain) { dds_return_t ret = DDS_RETCODE_OK; - const char * uri; + char * uri = NULL; char progname[50] = "UNKNOWN"; /* FIXME: once retrieving process names is back in */ char hostname[64]; uint32_t len; - os_mutex *init_mutex; + ddsrt_mutex_t *init_mutex; /* Be sure the DDS lifecycle resources are initialized. */ - os_osInit(); - init_mutex = os_getSingletonMutex(); + ddsrt_init(); + init_mutex = ddsrt_get_singleton_mutex(); - os_mutexLock(init_mutex); + ddsrt_mutex_lock(init_mutex); dds_global.m_init_count++; if (dds_global.m_init_count > 1) @@ -70,10 +69,10 @@ dds_init(dds_domainid_t domain) gv.tstart = now (); gv.exception = false; - os_mutexInit (&dds_global.m_mutex); + ddsrt_mutex_init (&dds_global.m_mutex); thread_states_init_static(); - uri = os_getenv (DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI"); + (void)ddsrt_getenv (DDS_PROJECT_NAME_NOSPACE_CAPS"_URI", &uri); dds_cfgst = config_init (uri); if (dds_cfgst == NULL) { @@ -150,13 +149,13 @@ dds_init(dds_domainid_t domain) /* Set additional default participant properties */ - gv.default_plist_pp.process_id = (unsigned)os_getpid(); + gv.default_plist_pp.process_id = (unsigned)ddsrt_getpid(); gv.default_plist_pp.present |= PP_PRISMTECH_PROCESS_ID; 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); + (void) snprintf(gv.default_plist_pp.exec_name, 32, "%s: %u", DDS_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) + if (ddsrt_gethostname(hostname, sizeof(hostname)) == DDS_RETCODE_OK) { gv.default_plist_pp.node_name = dds_string_dup(hostname); gv.default_plist_pp.present |= PP_PRISMTECH_NODE_NAME; @@ -167,7 +166,7 @@ dds_init(dds_domainid_t domain) gv.default_plist_pp.present |= PP_ENTITY_NAME; skip: - os_mutexUnlock(init_mutex); + ddsrt_mutex_unlock(init_mutex); return DDS_RETCODE_OK; fail_servicelease_start: @@ -189,20 +188,20 @@ fail_config_domainid: config_fini (dds_cfgst); dds_cfgst = NULL; fail_config: - os_mutexDestroy (&dds_global.m_mutex); + ddsrt_mutex_destroy (&dds_global.m_mutex); ut_handleserver_fini(); fail_handleserver: dds_global.m_init_count--; - os_mutexUnlock(init_mutex); - os_osExit(); + ddsrt_mutex_unlock(init_mutex); + ddsrt_fini(); return ret; } extern void dds_fini (void) { - os_mutex *init_mutex; - init_mutex = os_getSingletonMutex(); - os_mutexLock(init_mutex); + ddsrt_mutex_t *init_mutex; + init_mutex = ddsrt_get_singleton_mutex(); + ddsrt_mutex_lock(init_mutex); assert(dds_global.m_init_count > 0); dds_global.m_init_count--; if (dds_global.m_init_count == 0) @@ -220,18 +219,14 @@ extern void dds_fini (void) config_fini (dds_cfgst); dds_cfgst = NULL; - os_mutexDestroy (&dds_global.m_mutex); + ddsrt_mutex_destroy (&dds_global.m_mutex); ut_handleserver_fini(); dds_global.m_default_domain = DDS_DOMAIN_DEFAULT; } - os_mutexUnlock(init_mutex); - os_osExit(); + ddsrt_mutex_unlock(init_mutex); + ddsrt_fini(); } - - - - static int dds__init_plugin (void) { if (dds_global.m_dur_init) (dds_global.m_dur_init) (); @@ -260,18 +255,15 @@ void ddsi_plugin_init (void) ddsi_plugin.rhc_plugin.rhc_set_qos_fn = dds_rhc_set_qos; } - - //provides explicit default domain id. dds_domainid_t dds_domain_default (void) { - return dds_global.m_default_domain; + return dds_global.m_default_domain; } - dds_return_t dds__check_domain( - _In_ dds_domainid_t domain) + dds_domainid_t domain) { dds_return_t ret = DDS_RETCODE_OK; /* If domain is default: use configured id. */ diff --git a/src/core/ddsc/src/dds_instance.c b/src/core/ddsc/src/dds_instance.c index 7912217..4ed3b20 100644 --- a/src/core/ddsc/src/dds_instance.c +++ b/src/core/ddsc/src/dds_instance.c @@ -11,50 +11,48 @@ */ #include #include -#include "ddsc/dds.h" + +#include "dds/dds.h" #include "dds__entity.h" #include "dds__write.h" #include "dds__writer.h" #include "dds__rhc.h" #include "dds__err.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_writedispose( - _In_ dds_entity_t writer, - _In_ const void *data) + dds_entity_t writer, + const void *data) { return dds_writedispose_ts(writer, data, dds_time()); } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_dispose( - _In_ dds_entity_t writer, - _In_ const void *data) + dds_entity_t writer, + const void *data) { return dds_dispose_ts(writer, data, dds_time()); } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_dispose_ih( - _In_ dds_entity_t writer, - _In_ dds_instance_handle_t handle) + dds_entity_t writer, + dds_instance_handle_t handle) { return dds_dispose_ih_ts(writer, handle, dds_time()); } static struct ddsi_tkmap_instance* dds_instance_find( - _In_ const dds_topic *topic, - _In_ const void *data, - _In_ const bool create) + const dds_topic *topic, + const void *data, + const bool create) { struct ddsi_serdata *sd = ddsi_serdata_from_sample (topic->m_stopic, SDK_KEY, data); struct ddsi_tkmap_instance * inst = ddsi_tkmap_find (sd, false, create); @@ -64,73 +62,77 @@ dds_instance_find( static void dds_instance_remove( - _In_ const dds_topic *topic, - _In_opt_ const void *data, - _In_ dds_instance_handle_t handle) + const dds_topic *topic, + const void *data, + dds_instance_handle_t handle) { struct ddsi_tkmap_instance * inst; - if (handle != DDS_HANDLE_NIL) { + if (handle != DDS_HANDLE_NIL) + { inst = ddsi_tkmap_find_by_id (gv.m_tkmap, handle); - } else { - assert (data); - inst = dds_instance_find (topic, data, false); } - if (inst) { + else + { + assert (data); + inst = dds_instance_find (topic, data, false); + } + if (inst) + { ddsi_tkmap_instance_unref (inst); } } static const dds_topic *dds_instance_info (dds_entity *e) { - const dds_topic *topic; - switch (dds_entity_kind (e)) - { - case DDS_KIND_READER: - topic = ((dds_reader*) e)->m_topic; - break; - case DDS_KIND_WRITER: - topic = ((dds_writer*) e)->m_topic; - break; - default: - assert (0); - topic = NULL; - } - return topic; + const dds_topic *topic; + switch (dds_entity_kind (e)) + { + case DDS_KIND_READER: + topic = ((dds_reader*) e)->m_topic; + break; + case DDS_KIND_WRITER: + topic = ((dds_writer*) e)->m_topic; + break; + default: + assert (0); + topic = NULL; + } + return topic; } static const dds_topic * dds_instance_info_by_hdl (dds_entity_t e) { const dds_topic * topic = NULL; - dds__retcode_t rc; + dds_retcode_t rc; dds_entity *w_or_r; rc = dds_entity_lock(e, DDS_KIND_WRITER, &w_or_r); - if (rc == DDS_RETCODE_ILLEGAL_OPERATION) { + if (rc == DDS_RETCODE_ILLEGAL_OPERATION) + { rc = dds_entity_lock(e, DDS_KIND_READER, &w_or_r); } - if (rc == DDS_RETCODE_OK) { - topic = dds_instance_info(w_or_r); - dds_entity_unlock(w_or_r); - } else { - DDS_ERROR("Error occurred on locking entity"); + if (rc != DDS_RETCODE_OK) + { + return NULL; } + topic = dds_instance_info(w_or_r); + dds_entity_unlock(w_or_r); return topic; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_register_instance( - _In_ dds_entity_t writer, - _Out_ dds_instance_handle_t *handle, - _In_ const void *data) + dds_entity_t writer, + dds_instance_handle_t *handle, + const void *data) { struct thread_state1 * const thr = lookup_thread_state(); const bool asleep = !vtime_awake_p(thr->vtime); struct ddsi_tkmap_instance * inst; dds_writer *wr; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; if(data == NULL){ DDS_ERROR("Argument data is NULL\n"); @@ -167,35 +169,32 @@ err: return ret; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_unregister_instance( - _In_ dds_entity_t writer, - _In_opt_ const void *data) + dds_entity_t writer, + const void *data) { return dds_unregister_instance_ts (writer, data, dds_time()); } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_unregister_instance_ih( - _In_ dds_entity_t writer, - _In_opt_ dds_instance_handle_t handle) + dds_entity_t writer, + dds_instance_handle_t handle) { return dds_unregister_instance_ih_ts(writer, handle, dds_time()); } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_unregister_instance_ts( - _In_ dds_entity_t writer, - _In_opt_ const void *data, - _In_ dds_time_t timestamp) + dds_entity_t writer, + const void *data, + dds_time_t timestamp) { struct thread_state1 * const thr = lookup_thread_state(); const bool asleep = !vtime_awake_p(thr->vtime); dds_return_t ret = DDS_RETCODE_OK; - dds__retcode_t rc; + dds_retcode_t rc; bool autodispose = true; dds_write_action action = DDS_WR_ACTION_UNREGISTER; dds_writer *wr; @@ -236,17 +235,16 @@ err: return ret; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_unregister_instance_ih_ts( - _In_ dds_entity_t writer, - _In_opt_ dds_instance_handle_t handle, - _In_ dds_time_t timestamp) + dds_entity_t writer, + dds_instance_handle_t handle, + dds_time_t timestamp) { struct thread_state1 * const thr = lookup_thread_state(); const bool asleep = !vtime_awake_p(thr->vtime); dds_return_t ret = DDS_RETCODE_OK; - dds__retcode_t rc; + dds_retcode_t rc; bool autodispose = true; dds_write_action action = DDS_WR_ACTION_UNREGISTER; dds_writer *wr; @@ -290,15 +288,14 @@ err: return ret; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_writedispose_ts( - _In_ dds_entity_t writer, - _In_ const void *data, - _In_ dds_time_t timestamp) + dds_entity_t writer, + const void *data, + dds_time_t timestamp) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; rc = dds_writer_lock(writer, &wr); @@ -326,10 +323,10 @@ dds_writedispose_ts( static dds_return_t dds_dispose_impl( - _In_ dds_writer *wr, - _In_ const void *data, - _In_ dds_instance_handle_t handle, - _In_ dds_time_t timestamp) + dds_writer *wr, + const void *data, + dds_instance_handle_t handle, + dds_time_t timestamp) { dds_return_t ret; assert(vtime_awake_p(lookup_thread_state()->vtime)); @@ -341,15 +338,14 @@ dds_dispose_impl( return ret; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_dispose_ts( - _In_ dds_entity_t writer, - _In_ const void *data, - _In_ dds_time_t timestamp) + dds_entity_t writer, + const void *data, + dds_time_t timestamp) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; rc = dds_writer_lock(writer, &wr); @@ -372,15 +368,14 @@ dds_dispose_ts( return ret; } -_Pre_satisfies_((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER) dds_return_t dds_dispose_ih_ts( - _In_ dds_entity_t writer, - _In_ dds_instance_handle_t handle, - _In_ dds_time_t timestamp) + dds_entity_t writer, + dds_instance_handle_t handle, + dds_time_t timestamp) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; rc = dds_writer_lock(writer, &wr); @@ -414,11 +409,10 @@ dds_dispose_ih_ts( return ret; } -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) dds_instance_handle_t dds_lookup_instance( - dds_entity_t entity, - const void *data) + dds_entity_t entity, + const void *data) { dds_instance_handle_t ih = DDS_HANDLE_NIL; const dds_topic * topic; @@ -450,21 +444,19 @@ err: return ih; } -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) dds_instance_handle_t dds_instance_lookup ( - dds_entity_t entity, - const void *data) + dds_entity_t entity, + const void *data) { return dds_lookup_instance(entity, data); } -_Pre_satisfies_(entity & DDS_ENTITY_KIND_MASK) dds_return_t dds_instance_get_key( - dds_entity_t entity, - dds_instance_handle_t ih, - void *data) + dds_entity_t entity, + dds_instance_handle_t ih, + void *data) { struct thread_state1 * const thr = lookup_thread_state(); const bool asleep = !vtime_awake_p(thr->vtime); diff --git a/src/core/ddsc/src/dds_key.c b/src/core/ddsc/src/dds_key.c index a7652c2..d0ab249 100644 --- a/src/core/ddsc/src/dds_key.c +++ b/src/core/ddsc/src/dds_key.c @@ -13,9 +13,9 @@ #include #include "dds__key.h" #include "dds__stream.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_md5.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_md5.h" #ifndef NDEBUG static bool keyhash_is_reset(const dds_key_hash_t *kh) diff --git a/src/core/ddsc/src/dds_listener.c b/src/core/ddsc/src/dds_listener.c index 640745b..a325753 100644 --- a/src/core/ddsc/src/dds_listener.c +++ b/src/core/ddsc/src/dds_listener.c @@ -10,7 +10,8 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "ddsc/dds.h" + +#include "dds/dds.h" #include "dds__listener.h" dds_listener_t *dds_create_listener (void* arg) @@ -204,7 +205,7 @@ void dds_merge_listener (dds_listener_t * __restrict dst, const dds_listener_t * } } -void dds_listener_merge (_Inout_ dds_listener_t * __restrict dst, _In_ const dds_listener_t * __restrict src) +void dds_listener_merge (dds_listener_t * __restrict dst, const dds_listener_t * __restrict src) { dds_merge_listener(dst, src); } @@ -214,7 +215,7 @@ void dds_listener_merge (_Inout_ dds_listener_t * __restrict dst, _In_ const dds ************************************************************************************************/ void -dds_lset_data_available (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_data_available_fn callback) +dds_lset_data_available (dds_listener_t * __restrict listener, dds_on_data_available_fn callback) { if (listener) { listener->on_data_available = callback; @@ -224,7 +225,7 @@ dds_lset_data_available (_Inout_ dds_listener_t * __restrict listener, _In_opt_ } void -dds_lset_data_on_readers (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_data_on_readers_fn callback) +dds_lset_data_on_readers (dds_listener_t * __restrict listener, dds_on_data_on_readers_fn callback) { if (listener) { listener->on_data_on_readers = callback; @@ -234,7 +235,7 @@ dds_lset_data_on_readers (_Inout_ dds_listener_t * __restrict listener, _In_opt_ } void -dds_lset_inconsistent_topic (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_inconsistent_topic_fn callback) +dds_lset_inconsistent_topic (dds_listener_t * __restrict listener, dds_on_inconsistent_topic_fn callback) { if (listener) { listener->on_inconsistent_topic = callback; @@ -244,7 +245,7 @@ dds_lset_inconsistent_topic (_Inout_ dds_listener_t * __restrict listener, _In_o } void -dds_lset_liveliness_changed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_liveliness_changed_fn callback) +dds_lset_liveliness_changed (dds_listener_t * __restrict listener, dds_on_liveliness_changed_fn callback) { if (listener) { listener->on_liveliness_changed = callback; @@ -254,7 +255,7 @@ dds_lset_liveliness_changed (_Inout_ dds_listener_t * __restrict listener, _In_o } void -dds_lset_liveliness_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_liveliness_lost_fn callback) +dds_lset_liveliness_lost (dds_listener_t * __restrict listener, dds_on_liveliness_lost_fn callback) { if (listener) { listener->on_liveliness_lost = callback; @@ -264,7 +265,7 @@ dds_lset_liveliness_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ } void -dds_lset_offered_deadline_missed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_offered_deadline_missed_fn callback) +dds_lset_offered_deadline_missed (dds_listener_t * __restrict listener, dds_on_offered_deadline_missed_fn callback) { if (listener) { listener->on_offered_deadline_missed = callback; @@ -274,7 +275,7 @@ dds_lset_offered_deadline_missed (_Inout_ dds_listener_t * __restrict listener, } void -dds_lset_offered_incompatible_qos (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_offered_incompatible_qos_fn callback) +dds_lset_offered_incompatible_qos (dds_listener_t * __restrict listener, dds_on_offered_incompatible_qos_fn callback) { if (listener) { listener->on_offered_incompatible_qos = callback; @@ -284,7 +285,7 @@ dds_lset_offered_incompatible_qos (_Inout_ dds_listener_t * __restrict listener, } void -dds_lset_publication_matched (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_publication_matched_fn callback) +dds_lset_publication_matched (dds_listener_t * __restrict listener, dds_on_publication_matched_fn callback) { if (listener) { listener->on_publication_matched = callback; @@ -294,7 +295,7 @@ dds_lset_publication_matched (_Inout_ dds_listener_t * __restrict listener, _In_ } void -dds_lset_requested_deadline_missed (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_requested_deadline_missed_fn callback) +dds_lset_requested_deadline_missed (dds_listener_t * __restrict listener, dds_on_requested_deadline_missed_fn callback) { if (listener) { listener->on_requested_deadline_missed = callback; @@ -304,7 +305,7 @@ dds_lset_requested_deadline_missed (_Inout_ dds_listener_t * __restrict listener } void -dds_lset_requested_incompatible_qos (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_requested_incompatible_qos_fn callback) +dds_lset_requested_incompatible_qos (dds_listener_t * __restrict listener, dds_on_requested_incompatible_qos_fn callback) { if (listener) { listener->on_requested_incompatible_qos = callback; @@ -314,7 +315,7 @@ dds_lset_requested_incompatible_qos (_Inout_ dds_listener_t * __restrict listene } void -dds_lset_sample_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_sample_lost_fn callback) +dds_lset_sample_lost (dds_listener_t * __restrict listener, dds_on_sample_lost_fn callback) { if (listener) { listener->on_sample_lost = callback; @@ -324,7 +325,7 @@ dds_lset_sample_lost (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds } void -dds_lset_sample_rejected (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_sample_rejected_fn callback) +dds_lset_sample_rejected (dds_listener_t * __restrict listener, dds_on_sample_rejected_fn callback) { if (listener) { listener->on_sample_rejected = callback; @@ -334,7 +335,7 @@ dds_lset_sample_rejected (_Inout_ dds_listener_t * __restrict listener, _In_opt_ } void -dds_lset_subscription_matched (_Inout_ dds_listener_t * __restrict listener, _In_opt_ dds_on_subscription_matched_fn callback) +dds_lset_subscription_matched (dds_listener_t * __restrict listener, dds_on_subscription_matched_fn callback) { if (listener) { listener->on_subscription_matched = callback; @@ -348,7 +349,7 @@ dds_lset_subscription_matched (_Inout_ dds_listener_t * __restrict listener, _In ************************************************************************************************/ void -dds_lget_data_available (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_data_available_fn *callback) +dds_lget_data_available (const dds_listener_t * __restrict listener, dds_on_data_available_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -362,7 +363,7 @@ dds_lget_data_available (_In_ const dds_listener_t * __restrict listener, _Outpt } void -dds_lget_data_on_readers (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_data_on_readers_fn *callback) +dds_lget_data_on_readers (const dds_listener_t * __restrict listener, dds_on_data_on_readers_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -375,7 +376,7 @@ dds_lget_data_on_readers (_In_ const dds_listener_t * __restrict listener, _Outp *callback = listener->on_data_on_readers; } -void dds_lget_inconsistent_topic (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_inconsistent_topic_fn *callback) +void dds_lget_inconsistent_topic (const dds_listener_t * __restrict listener, dds_on_inconsistent_topic_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -389,7 +390,7 @@ void dds_lget_inconsistent_topic (_In_ const dds_listener_t * __restrict listene } void -dds_lget_liveliness_changed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_liveliness_changed_fn *callback) +dds_lget_liveliness_changed (const dds_listener_t * __restrict listener, dds_on_liveliness_changed_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -403,7 +404,7 @@ dds_lget_liveliness_changed (_In_ const dds_listener_t * __restrict listener, _O } void -dds_lget_liveliness_lost (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_liveliness_lost_fn *callback) +dds_lget_liveliness_lost (const dds_listener_t * __restrict listener, dds_on_liveliness_lost_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -417,7 +418,7 @@ dds_lget_liveliness_lost (_In_ const dds_listener_t * __restrict listener, _Outp } void -dds_lget_offered_deadline_missed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_offered_deadline_missed_fn *callback) +dds_lget_offered_deadline_missed (const dds_listener_t * __restrict listener, dds_on_offered_deadline_missed_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -431,7 +432,7 @@ dds_lget_offered_deadline_missed (_In_ const dds_listener_t * __restrict listene } void -dds_lget_offered_incompatible_qos (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_offered_incompatible_qos_fn *callback) +dds_lget_offered_incompatible_qos (const dds_listener_t * __restrict listener, dds_on_offered_incompatible_qos_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -445,7 +446,7 @@ dds_lget_offered_incompatible_qos (_In_ const dds_listener_t * __restrict listen } void -dds_lget_publication_matched (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_publication_matched_fn *callback) +dds_lget_publication_matched (const dds_listener_t * __restrict listener, dds_on_publication_matched_fn *callback) { if(!callback){ DDS_ERROR("Argument callback is NULL\n"); @@ -459,7 +460,7 @@ dds_lget_publication_matched (_In_ const dds_listener_t * __restrict listener, _ } void -dds_lget_requested_deadline_missed (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_requested_deadline_missed_fn *callback) +dds_lget_requested_deadline_missed (const dds_listener_t * __restrict listener, dds_on_requested_deadline_missed_fn *callback) { if(!callback) { DDS_ERROR("Argument callback is NULL\n"); @@ -473,7 +474,7 @@ dds_lget_requested_deadline_missed (_In_ const dds_listener_t * __restrict liste } void -dds_lget_requested_incompatible_qos (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_requested_incompatible_qos_fn *callback) +dds_lget_requested_incompatible_qos (const dds_listener_t * __restrict listener, dds_on_requested_incompatible_qos_fn *callback) { if(!callback) { DDS_ERROR("Argument callback is NULL\n"); @@ -487,7 +488,7 @@ dds_lget_requested_incompatible_qos (_In_ const dds_listener_t * __restrict list } void -dds_lget_sample_lost (_In_ const dds_listener_t *__restrict listener, _Outptr_result_maybenull_ dds_on_sample_lost_fn *callback) +dds_lget_sample_lost (const dds_listener_t *__restrict listener, dds_on_sample_lost_fn *callback) { if(!callback) { DDS_ERROR("Argument callback is NULL\n"); @@ -501,7 +502,7 @@ dds_lget_sample_lost (_In_ const dds_listener_t *__restrict listener, _Outptr_re } void -dds_lget_sample_rejected (_In_ const dds_listener_t *__restrict listener, _Outptr_result_maybenull_ dds_on_sample_rejected_fn *callback) +dds_lget_sample_rejected (const dds_listener_t *__restrict listener, dds_on_sample_rejected_fn *callback) { if(!callback) { DDS_ERROR("Argument callback is NULL\n"); @@ -515,7 +516,7 @@ dds_lget_sample_rejected (_In_ const dds_listener_t *__restrict listener, _Outp } void -dds_lget_subscription_matched (_In_ const dds_listener_t * __restrict listener, _Outptr_result_maybenull_ dds_on_subscription_matched_fn *callback) +dds_lget_subscription_matched (const dds_listener_t * __restrict listener, dds_on_subscription_matched_fn *callback) { if(!callback) { DDS_ERROR("Argument callback is NULL\n"); diff --git a/src/core/ddsc/src/dds_participant.c b/src/core/ddsc/src/dds_participant.c index 5a56ea5..94d42a0 100644 --- a/src/core/ddsc/src/dds_participant.c +++ b/src/core/ddsc/src/dds_participant.c @@ -10,9 +10,11 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_config.h" + +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_config.h" #include "dds__init.h" #include "dds__qos.h" #include "dds__domain.h" @@ -30,7 +32,7 @@ static dds_entity * dds_pp_head = NULL; static dds_return_t dds_participant_status_validate( - uint32_t mask) + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; @@ -44,7 +46,7 @@ dds_participant_status_validate( static dds_return_t dds_participant_delete( - dds_entity *e) + dds_entity *e) { struct thread_state1 * const thr = lookup_thread_state (); const bool asleep = !vtime_awake_p (thr->vtime); @@ -61,7 +63,7 @@ dds_participant_delete( dds_domain_free (e->m_domain); - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); iter = dds_pp_head; while (iter) { if (iter == e) { @@ -75,7 +77,7 @@ dds_participant_delete( prev = iter; iter = iter->m_next; } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); assert (iter); @@ -91,8 +93,8 @@ dds_participant_delete( static dds_return_t dds_participant_instance_hdl( - dds_entity *e, - dds_instance_handle_t *i) + dds_entity *e, + dds_instance_handle_t *i) { assert(e); assert(i); @@ -102,8 +104,8 @@ dds_participant_instance_hdl( static dds_return_t dds_participant_qos_validate( - const dds_qos_t *qos, - bool enabled) + const dds_qos_t *qos, + bool enabled) { dds_return_t ret = DDS_RETCODE_OK; assert(qos); @@ -124,9 +126,9 @@ dds_participant_qos_validate( static dds_return_t dds_participant_qos_set( - dds_entity *e, - const dds_qos_t *qos, - bool enabled) + dds_entity *e, + const dds_qos_t *qos, + bool enabled) { dds_return_t ret = dds_participant_qos_validate(qos, enabled); (void)e; @@ -140,11 +142,11 @@ dds_participant_qos_set( return ret; } -_Must_inspect_result_ dds_entity_t +dds_entity_t dds_create_participant( - _In_ const dds_domainid_t domain, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + const dds_domainid_t domain, + const dds_qos_t *qos, + const dds_listener_t *listener) { int q_rc; dds_return_t ret; @@ -222,10 +224,10 @@ dds_create_participant( pp->m_builtin_subscriber = 0; /* Add participant to extent */ - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); pp->m_entity.m_next = dds_pp_head; dds_pp_head = &pp->m_entity; - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); return e; @@ -240,18 +242,18 @@ fail_dds_init: return e; } -_Check_return_ dds_return_t +dds_entity_t dds_lookup_participant( - _In_ dds_domainid_t domain_id, - _Out_opt_ dds_entity_t *participants, - _In_ size_t size) + dds_domainid_t domain_id, + dds_entity_t *participants, + size_t size) { dds_return_t ret = 0; - os_mutex *init_mutex; + ddsrt_mutex_t *init_mutex; /* Be sure the DDS lifecycle resources are initialized. */ - os_osInit(); - init_mutex = os_getSingletonMutex(); + ddsrt_init(); + init_mutex = ddsrt_get_singleton_mutex(); if ((participants != NULL) && ((size <= 0) || (size >= INT32_MAX))) { DDS_ERROR("Array is given, but with invalid size\n"); @@ -268,12 +270,12 @@ dds_lookup_participant( participants[0] = 0; } - os_mutexLock (init_mutex); + ddsrt_mutex_lock (init_mutex); /* Check if dds is intialized. */ if (dds_global.m_init_count > 0) { dds_entity* iter; - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); iter = dds_pp_head; while (iter) { if(iter->m_domainid == domain_id) { @@ -284,12 +286,12 @@ dds_lookup_participant( } iter = iter->m_next; } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); } - os_mutexUnlock (init_mutex); + ddsrt_mutex_unlock (init_mutex); err: - os_osExit(); + ddsrt_fini(); return ret; } diff --git a/src/core/ddsc/src/dds_publisher.c b/src/core/ddsc/src/dds_publisher.c index 33d10f9..ff920e1 100644 --- a/src/core/ddsc/src/dds_publisher.c +++ b/src/core/ddsc/src/dds_publisher.c @@ -14,15 +14,15 @@ #include "dds__listener.h" #include "dds__qos.h" #include "dds__err.h" -#include "ddsi/q_entity.h" -#include "ddsc/ddsc_project.h" +#include "dds/ddsi/q_entity.h" +#include "dds/version.h" #define DDS_PUBLISHER_STATUS_MASK 0u static dds_return_t dds_publisher_instance_hdl( - dds_entity *e, - dds_instance_handle_t *i) + dds_entity *e, + dds_instance_handle_t *i) { (void)e; (void)i; @@ -33,8 +33,8 @@ dds_publisher_instance_hdl( static dds_return_t dds_publisher_qos_validate( - _In_ const dds_qos_t *qos, - _In_ bool enabled) + const dds_qos_t *qos, + bool enabled) { dds_return_t ret = DDS_RETCODE_OK; assert(qos); @@ -66,16 +66,16 @@ dds_publisher_qos_validate( static dds_return_t dds_publisher_qos_set( - dds_entity *e, - const dds_qos_t *qos, - bool enabled) + dds_entity *e, + const dds_qos_t *qos, + bool enabled) { dds_return_t ret = dds_publisher_qos_validate(qos, enabled); (void)e; if (ret == DDS_RETCODE_OK) { if (enabled) { /* TODO: CHAM-95: DDSI does not support changing QoS policies. */ - DDS_ERROR(DDSC_PROJECT_NAME" does not support changing QoS policies yet\n"); + DDS_ERROR(DDS_PROJECT_NAME" does not support changing QoS policies yet\n"); ret = DDS_ERRNO(DDS_RETCODE_UNSUPPORTED); } } @@ -94,19 +94,18 @@ static dds_return_t dds_publisher_status_validate (uint32_t mask) return ret; } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -_Must_inspect_result_ dds_entity_t +dds_entity_t dds_create_publisher( - _In_ dds_entity_t participant, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity_t participant, + const dds_qos_t *qos, + const dds_listener_t *listener) { dds_entity * par; dds_publisher * pub; dds_entity_t hdl; dds_qos_t * new_qos = NULL; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; rc = dds_entity_lock(participant, DDS_KIND_PARTICIPANT, &par); if (rc != DDS_RETCODE_OK) { @@ -141,11 +140,9 @@ lock_err: return hdl; } - -_Pre_satisfies_((publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) DDS_EXPORT dds_return_t dds_suspend( - _In_ dds_entity_t publisher) + dds_entity_t publisher) { dds_return_t ret; @@ -161,11 +158,9 @@ err: return ret; } - -_Pre_satisfies_((publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) dds_return_t dds_resume( - _In_ dds_entity_t publisher) + dds_entity_t publisher) { dds_return_t ret = DDS_RETCODE_OK; @@ -181,18 +176,15 @@ err: return ret; } - -_Pre_satisfies_(((publisher_or_writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER ) ||\ - ((publisher_or_writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) ) dds_return_t dds_wait_for_acks( - _In_ dds_entity_t publisher_or_writer, - _In_ dds_duration_t timeout) + dds_entity_t publisher_or_writer, + dds_duration_t timeout) { dds_return_t ret; /* TODO: CHAM-125 Currently unsupported. */ - OS_UNUSED_ARG(timeout); + DDSRT_UNUSED_ARG(timeout); switch(dds_entity_kind_from_handle(publisher_or_writer)) { case DDS_KIND_WRITER: @@ -214,7 +206,7 @@ dds_wait_for_acks( dds_return_t dds_publisher_begin_coherent( - _In_ dds_entity_t e) + dds_entity_t e) { /* TODO: CHAM-124 Currently unsupported. */ (void)e; @@ -224,7 +216,7 @@ dds_publisher_begin_coherent( dds_return_t dds_publisher_end_coherent( - _In_ dds_entity_t e) + dds_entity_t e) { /* TODO: CHAM-124 Currently unsupported. */ (void)e; diff --git a/src/core/ddsc/src/dds_qos.c b/src/core/ddsc/src/dds_qos.c index 38c61e3..bc1869c 100644 --- a/src/core/ddsc/src/dds_qos.c +++ b/src/core/ddsc/src/dds_qos.c @@ -13,7 +13,7 @@ #include #include "dds__qos.h" #include "dds__err.h" -#include "ddsi/q_config.h" +#include "dds/ddsi/q_config.h" /* TODO: dd_duration_t is converted to nn_ddsi_time_t declared in q_time.h This structure contain seconds and fractions. @@ -22,9 +22,9 @@ static void dds_qos_data_copy_in( - _Inout_ nn_octetseq_t * data, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz) + nn_octetseq_t * data, + const void * __restrict value, + size_t sz) { if (data->value) { dds_free (data->value); @@ -39,11 +39,9 @@ dds_qos_data_copy_in( static bool dds_qos_data_copy_out( - _In_ const nn_octetseq_t * data, - _When_(*sz == 0, _At_(*value, _Post_null_)) - _When_(*sz > 0, _At_(*value, _Post_notnull_)) - _Outptr_result_bytebuffer_all_maybenull_(*sz) void ** value, - _Out_ size_t * sz) + const nn_octetseq_t * data, + void ** value, + size_t * sz) { if (sz == NULL && value != NULL) { return false; @@ -137,7 +135,7 @@ dds_qos_validate_common ( dds_return_t dds_qos_validate_mutable_common ( - _In_ const dds_qos_t *qos) + const dds_qos_t *qos) { dds_return_t ret = DDS_RETCODE_OK; @@ -176,7 +174,7 @@ dds_qos_validate_mutable_common ( static void dds_qos_init_defaults ( - _Inout_ dds_qos_t * __restrict qos) + dds_qos_t * __restrict qos) { assert (qos); memset (qos, 0, sizeof (*qos)); @@ -208,7 +206,6 @@ dds_qos_init_defaults ( qos->reader_data_lifecycle.autopurge_disposed_samples_delay = nn_to_ddsi_duration (DDS_INFINITY); } -_Ret_notnull_ dds_qos_t * dds_create_qos (void) { dds_qos_t *qos = dds_alloc (sizeof (dds_qos_t)); @@ -216,7 +213,6 @@ dds_qos_t * dds_create_qos (void) return qos; } -_Ret_notnull_ dds_qos_t * dds_qos_create (void) { return dds_create_qos (); @@ -224,7 +220,7 @@ dds_qos_t * dds_qos_create (void) void dds_reset_qos( - _Out_ dds_qos_t * __restrict qos) + dds_qos_t * __restrict qos) { if (qos) { nn_xqos_fini (qos); @@ -236,14 +232,14 @@ dds_reset_qos( void dds_qos_reset( - _Out_ dds_qos_t * __restrict qos) + dds_qos_t * __restrict qos) { dds_reset_qos (qos); } void dds_delete_qos( - _In_ _Post_invalid_ dds_qos_t * __restrict qos) + dds_qos_t * __restrict qos) { if (qos) { dds_reset_qos(qos); @@ -253,15 +249,15 @@ dds_delete_qos( void dds_qos_delete( - _In_ _Post_invalid_ dds_qos_t * __restrict qos) + dds_qos_t * __restrict qos) { dds_delete_qos (qos); } dds_return_t dds_copy_qos ( - _Out_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src) + dds_qos_t * __restrict dst, + const dds_qos_t * __restrict src) { if(!src){ DDS_ERROR("Argument source(src) is NULL\n"); @@ -277,15 +273,15 @@ dds_copy_qos ( dds_return_t dds_qos_copy ( - _Out_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src) + dds_qos_t * __restrict dst, + const dds_qos_t * __restrict src) { return dds_copy_qos (dst, src); } void dds_merge_qos ( - _Inout_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src) + dds_qos_t * __restrict dst, + const dds_qos_t * __restrict src) { if(!src){ DDS_ERROR("Argument source(src) is NULL\n"); @@ -300,15 +296,15 @@ void dds_merge_qos ( } void dds_qos_merge ( - _Inout_ dds_qos_t * __restrict dst, - _In_ const dds_qos_t * __restrict src) + dds_qos_t * __restrict dst, + const dds_qos_t * __restrict src) { dds_merge_qos (dst, src); } bool dds_qos_equal ( - _In_opt_ const dds_qos_t * __restrict a, - _In_opt_ const dds_qos_t * __restrict b) + const dds_qos_t * __restrict a, + const dds_qos_t * __restrict b) { /* FIXME: a bit of a hack - and I am not so sure I like accepting null pointers here anyway */ if (a == NULL && b == NULL) { @@ -321,9 +317,9 @@ bool dds_qos_equal ( } void dds_qset_userdata( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz) + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz) { if (!qos) { DDS_ERROR("Argument qos is NULL\n"); @@ -334,9 +330,9 @@ void dds_qset_userdata( } void dds_qset_topicdata( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz) + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz) { if (!qos) { DDS_ERROR("Argument qos is NULL\n"); @@ -347,9 +343,9 @@ void dds_qset_topicdata( } void dds_qset_groupdata( - _Inout_ dds_qos_t * __restrict qos, - _In_reads_bytes_opt_(sz) const void * __restrict value, - _In_ size_t sz) + dds_qos_t * __restrict qos, + const void * __restrict value, + size_t sz) { if (!qos) { DDS_ERROR("Argument qos is NULL\n"); @@ -361,8 +357,8 @@ void dds_qset_groupdata( void dds_qset_durability ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_DURABILITY_VOLATILE, DDS_DURABILITY_PERSISTENT) dds_durability_kind_t kind + dds_qos_t * __restrict qos, + dds_durability_kind_t kind ) { if (qos) { @@ -375,9 +371,9 @@ void dds_qset_durability void dds_qset_history ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_HISTORY_KEEP_LAST, DDS_HISTORY_KEEP_ALL) dds_history_kind_t kind, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t depth + dds_qos_t * __restrict qos, + dds_history_kind_t kind, + int32_t depth ) { if (qos) { @@ -391,10 +387,10 @@ void dds_qset_history void dds_qset_resource_limits ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_instances, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples_per_instance + dds_qos_t * __restrict qos, + int32_t max_samples, + int32_t max_instances, + int32_t max_samples_per_instance ) { if (qos) { @@ -409,10 +405,10 @@ void dds_qset_resource_limits void dds_qset_presentation ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_PRESENTATION_INSTANCE, DDS_PRESENTATION_GROUP) dds_presentation_access_scope_kind_t access_scope, - _In_ bool coherent_access, - _In_ bool ordered_access + dds_qos_t * __restrict qos, + dds_presentation_access_scope_kind_t access_scope, + bool coherent_access, + bool ordered_access ) { if (qos) { @@ -427,8 +423,8 @@ void dds_qset_presentation void dds_qset_lifespan ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t lifespan + dds_qos_t * __restrict qos, + dds_duration_t lifespan ) { if (qos) { @@ -441,8 +437,8 @@ void dds_qset_lifespan void dds_qset_deadline ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t deadline + dds_qos_t * __restrict qos, + dds_duration_t deadline ) { if (qos) { @@ -455,8 +451,8 @@ void dds_qset_deadline void dds_qset_latency_budget ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t duration + dds_qos_t * __restrict qos, + dds_duration_t duration ) { if (qos) { @@ -469,8 +465,8 @@ void dds_qset_latency_budget void dds_qset_ownership ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_OWNERSHIP_SHARED, DDS_OWNERSHIP_EXCLUSIVE) dds_ownership_kind_t kind + dds_qos_t * __restrict qos, + dds_ownership_kind_t kind ) { if (qos) { @@ -483,8 +479,8 @@ void dds_qset_ownership void dds_qset_ownership_strength ( - _Inout_ dds_qos_t * __restrict qos, - _In_ int32_t value + dds_qos_t * __restrict qos, + int32_t value ) { if (qos) { @@ -497,9 +493,9 @@ void dds_qset_ownership_strength void dds_qset_liveliness ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_LIVELINESS_AUTOMATIC, DDS_LIVELINESS_MANUAL_BY_TOPIC) dds_liveliness_kind_t kind, - _In_range_(0, DDS_INFINITY) dds_duration_t lease_duration + dds_qos_t * __restrict qos, + dds_liveliness_kind_t kind, + dds_duration_t lease_duration ) { if (qos) { @@ -513,8 +509,8 @@ void dds_qset_liveliness void dds_qset_time_based_filter ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t minimum_separation + dds_qos_t * __restrict qos, + dds_duration_t minimum_separation ) { if (qos) { @@ -527,9 +523,9 @@ void dds_qset_time_based_filter void dds_qset_partition ( - _Inout_ dds_qos_t * __restrict qos, - _In_ uint32_t n, - _In_count_(n) _Deref_pre_z_ const char ** __restrict ps + dds_qos_t * __restrict qos, + uint32_t n, + const char ** __restrict ps ) { uint32_t i; @@ -564,9 +560,9 @@ void dds_qset_partition void dds_qset_reliability ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_RELIABILITY_BEST_EFFORT, DDS_RELIABILITY_RELIABLE) dds_reliability_kind_t kind, - _In_range_(0, DDS_INFINITY) dds_duration_t max_blocking_time + dds_qos_t * __restrict qos, + dds_reliability_kind_t kind, + dds_duration_t max_blocking_time ) { if (qos) { @@ -580,8 +576,8 @@ void dds_qset_reliability void dds_qset_transport_priority ( - _Inout_ dds_qos_t * __restrict qos, - _In_ int32_t value + dds_qos_t * __restrict qos, + int32_t value ) { if (qos) { @@ -594,9 +590,8 @@ void dds_qset_transport_priority void dds_qset_destination_order ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(DDS_DESTINATIONORDER_BY_RECEPTION_TIMESTAMP, - DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP) dds_destination_order_kind_t kind + dds_qos_t * __restrict qos, + dds_destination_order_kind_t kind ) { if (qos) { @@ -609,8 +604,8 @@ void dds_qset_destination_order void dds_qset_writer_data_lifecycle ( - _Inout_ dds_qos_t * __restrict qos, - _In_ bool autodispose + dds_qos_t * __restrict qos, + bool autodispose ) { if(qos) { @@ -623,9 +618,9 @@ void dds_qset_writer_data_lifecycle void dds_qset_reader_data_lifecycle ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t autopurge_nowriter_samples_delay, - _In_range_(0, DDS_INFINITY) dds_duration_t autopurge_disposed_samples_delay + dds_qos_t * __restrict qos, + dds_duration_t autopurge_nowriter_samples_delay, + dds_duration_t autopurge_disposed_samples_delay ) { if (qos) { @@ -641,13 +636,13 @@ void dds_qset_reader_data_lifecycle void dds_qset_durability_service ( - _Inout_ dds_qos_t * __restrict qos, - _In_range_(0, DDS_INFINITY) dds_duration_t service_cleanup_delay, - _In_range_(DDS_HISTORY_KEEP_LAST, DDS_HISTORY_KEEP_ALL) dds_history_kind_t history_kind, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t history_depth, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_instances, - _In_range_(>=, DDS_LENGTH_UNLIMITED) int32_t max_samples_per_instance + dds_qos_t * __restrict qos, + dds_duration_t service_cleanup_delay, + dds_history_kind_t history_kind, + int32_t history_depth, + int32_t max_samples, + int32_t max_instances, + int32_t max_samples_per_instance ) { if (qos) { diff --git a/src/core/ddsc/src/dds_querycond.c b/src/core/ddsc/src/dds_querycond.c index 73cbda1..490fc3c 100644 --- a/src/core/ddsc/src/dds_querycond.c +++ b/src/core/ddsc/src/dds_querycond.c @@ -10,24 +10,26 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include + +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/log.h" #include "dds__entity.h" #include "dds__reader.h" #include "dds__topic.h" #include "dds__querycond.h" #include "dds__readcond.h" #include "dds__err.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_sertopic.h" -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) DDS_EXPORT dds_entity_t dds_create_querycondition( - _In_ dds_entity_t reader, - _In_ uint32_t mask, - _In_ dds_querycondition_filter_fn filter) + dds_entity_t reader, + uint32_t mask, + dds_querycondition_filter_fn filter) { dds_entity_t hdl; - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *r; rc = dds_reader_lock(reader, &r); diff --git a/src/core/ddsc/src/dds_read.c b/src/core/ddsc/src/dds_read.c index 197aa9b..9353829 100644 --- a/src/core/ddsc/src/dds_read.c +++ b/src/core/ddsc/src/dds_read.c @@ -13,17 +13,17 @@ #include #include "dds__entity.h" #include "dds__reader.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__rhc.h" #include "dds__err.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/ddsi_sertopic.h" -static dds__retcode_t dds_read_lock (dds_entity_t hdl, dds_reader **reader, dds_readcond **condition, bool only_reader) +static dds_retcode_t dds_read_lock (dds_entity_t hdl, dds_reader **reader, dds_readcond **condition, bool only_reader) { - dds__retcode_t rc; + dds_retcode_t rc; dds_entity *entity, *parent_entity; if ((rc = dds_entity_lock (hdl, DDS_KIND_DONTCARE, &entity)) != DDS_RETCODE_OK) { @@ -77,19 +77,19 @@ static void dds_read_unlock (dds_reader *reader, dds_readcond *condition) */ static dds_return_t dds_read_impl( - _In_ bool take, - _In_ dds_entity_t reader_or_condition, - _Inout_ void **buf, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _Out_ dds_sample_info_t *si, - _In_ uint32_t mask, - _In_ dds_instance_handle_t hand, - _In_ bool lock, - _In_ bool only_reader) + bool take, + dds_entity_t reader_or_condition, + void **buf, + size_t bufsz, + uint32_t maxs, + dds_sample_info_t *si, + uint32_t mask, + dds_instance_handle_t hand, + bool lock, + bool only_reader) { dds_return_t ret = DDS_RETCODE_OK; - dds__retcode_t rc; + dds_retcode_t rc; struct dds_reader * rd; struct dds_readcond * cond; struct thread_state1 * const thr = lookup_thread_state (); @@ -182,17 +182,17 @@ fail: static dds_return_t dds_readcdr_impl( - _In_ bool take, - _In_ dds_entity_t reader_or_condition, - _Out_ struct ddsi_serdata ** buf, - _In_ uint32_t maxs, - _Out_ dds_sample_info_t * si, - _In_ uint32_t mask, - _In_ dds_instance_handle_t hand, - _In_ bool lock) + bool take, + dds_entity_t reader_or_condition, + struct ddsi_serdata ** buf, + uint32_t maxs, + dds_sample_info_t * si, + uint32_t mask, + dds_instance_handle_t hand, + bool lock) { dds_return_t ret = DDS_RETCODE_OK; - dds__retcode_t rc; + dds_retcode_t rc; struct dds_reader * rd; struct dds_readcond * cond; struct thread_state1 * const thr = lookup_thread_state (); @@ -243,16 +243,13 @@ dds_readcdr_impl( return ret; } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ size_t bufsz, - _In_ uint32_t maxs) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + size_t bufsz, + uint32_t maxs) { bool lock = true; @@ -265,15 +262,12 @@ dds_read( return dds_read_impl (false, rd_or_cnd, buf, bufsz, maxs, si, NO_STATE_MASK_SET, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ uint32_t maxs) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + uint32_t maxs) { bool lock = true; @@ -286,17 +280,14 @@ dds_read_wl( return dds_read_impl (false, rd_or_cnd, buf, maxs, maxs, si, NO_STATE_MASK_SET, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_mask( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + size_t bufsz, + uint32_t maxs, + uint32_t mask) { bool lock = true; @@ -309,16 +300,13 @@ dds_read_mask( return dds_read_impl (false, rd_or_cnd, buf, bufsz, maxs, si, mask, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_mask_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ uint32_t maxs, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + uint32_t maxs, + uint32_t mask) { bool lock = true; @@ -331,17 +319,14 @@ dds_read_mask_wl( return dds_read_impl (false, rd_or_cnd, buf, maxs, maxs, si, mask, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_instance( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -363,16 +348,13 @@ fail: return ret; } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_instance_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -394,19 +376,15 @@ fail: return ret; } - -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_instance_mask( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -428,18 +406,14 @@ fail: return ret; } - -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_read_instance_mask_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -460,38 +434,33 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) dds_return_t dds_read_next( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si) + dds_entity_t reader, + void **buf, + dds_sample_info_t *si) { uint32_t mask = DDS_NOT_READ_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE; return dds_read_impl (false, reader, buf, 1u, 1u, si, mask, DDS_HANDLE_NIL, true, true); } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) dds_return_t dds_read_next_wl( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si) + dds_entity_t reader, + void **buf, + dds_sample_info_t *si) { uint32_t mask = DDS_NOT_READ_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE; return dds_read_impl (false, reader, buf, 1u, 1u, si, mask, DDS_HANDLE_NIL, true, true); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ size_t bufsz, - _In_ uint32_t maxs) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + size_t bufsz, + uint32_t maxs) { bool lock = true; @@ -504,15 +473,12 @@ dds_take( return dds_read_impl (true, rd_or_cnd, buf, bufsz, maxs, si, NO_STATE_MASK_SET, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ uint32_t maxs) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + uint32_t maxs) { bool lock = true; @@ -525,17 +491,14 @@ dds_take_wl( return dds_read_impl (true, rd_or_cnd, buf, maxs, maxs, si, NO_STATE_MASK_SET, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_mask( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + size_t bufsz, + uint32_t maxs, + uint32_t mask) { bool lock = true; @@ -548,16 +511,13 @@ dds_take_mask( return dds_read_impl (true, rd_or_cnd, buf, bufsz, maxs, si, mask, DDS_HANDLE_NIL, lock, false); } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_mask_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void ** buf, - _Out_ dds_sample_info_t * si, - _In_ uint32_t maxs, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void ** buf, + dds_sample_info_t * si, + uint32_t maxs, + uint32_t mask) { bool lock = true; @@ -589,18 +549,14 @@ dds_takecdr( return dds_readcdr_impl (true, rd_or_cnd, buf, maxs, si, mask, DDS_HANDLE_NIL, lock); } - -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_instance( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -622,16 +578,13 @@ fail: return ret; } -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_instance_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -652,19 +605,15 @@ fail: return ret; } - -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_instance_mask( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ size_t bufsz, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + size_t bufsz, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -685,18 +634,14 @@ fail: return ret; } - -_Pre_satisfies_(((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((rd_or_cnd & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) dds_return_t dds_take_instance_mask_wl( - _In_ dds_entity_t rd_or_cnd, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si, - _In_ uint32_t maxs, - _In_ dds_instance_handle_t handle, - _In_ uint32_t mask) + dds_entity_t rd_or_cnd, + void **buf, + dds_sample_info_t *si, + uint32_t maxs, + dds_instance_handle_t handle, + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; bool lock = true; @@ -717,38 +662,33 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) dds_return_t dds_take_next( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si) + dds_entity_t reader, + void **buf, + dds_sample_info_t *si) { uint32_t mask = DDS_NOT_READ_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE; return dds_read_impl (true, reader, buf, 1u, 1u, si, mask, DDS_HANDLE_NIL, true, true); } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) dds_return_t dds_take_next_wl( - _In_ dds_entity_t reader, - _Inout_ void **buf, - _Out_ dds_sample_info_t *si) + dds_entity_t reader, + void **buf, + dds_sample_info_t *si) { uint32_t mask = DDS_NOT_READ_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE; return dds_read_impl (true, reader, buf, 1u, 1u, si, mask, DDS_HANDLE_NIL, true, true); } -_Pre_satisfies_(((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER ) ||\ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_READ ) || \ - ((reader_or_condition & DDS_ENTITY_KIND_MASK) == DDS_KIND_COND_QUERY )) -_Must_inspect_result_ dds_return_t +dds_return_t dds_return_loan( - _In_ dds_entity_t reader_or_condition, - _Inout_updates_(bufsz) void **buf, - _In_ int32_t bufsz) + dds_entity_t reader_or_condition, + void **buf, + int32_t bufsz) { - dds__retcode_t rc; + dds_retcode_t rc; const struct ddsi_sertopic *st; dds_reader *rd; dds_readcond *cond; diff --git a/src/core/ddsc/src/dds_readcond.c b/src/core/ddsc/src/dds_readcond.c index bd85fd9..3d169de 100644 --- a/src/core/ddsc/src/dds_readcond.c +++ b/src/core/ddsc/src/dds_readcond.c @@ -15,24 +15,24 @@ #include "dds__rhc.h" #include "dds__entity.h" #include "dds__err.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" static dds_return_t dds_readcond_delete( - dds_entity *e) + dds_entity *e) { dds_rhc_remove_readcondition((dds_readcond*)e); return DDS_RETCODE_OK; } -_Must_inspect_result_ dds_readcond* +dds_readcond* dds_create_readcond( - _In_ dds_reader *rd, - _In_ dds_entity_kind_t kind, - _In_ uint32_t mask, - _In_opt_ dds_querycondition_filter_fn filter) + dds_reader *rd, + dds_entity_kind_t kind, + uint32_t mask, + dds_querycondition_filter_fn filter) { dds_readcond * cond = dds_alloc(sizeof(*cond)); assert((kind == DDS_KIND_COND_READ && filter == 0) || (kind == DDS_KIND_COND_QUERY && filter != 0)); @@ -56,15 +56,14 @@ dds_create_readcond( return cond; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) -_Must_inspect_result_ dds_entity_t +dds_entity_t dds_create_readcondition( - _In_ dds_entity_t reader, - _In_ uint32_t mask) + dds_entity_t reader, + uint32_t mask) { dds_entity_t hdl; dds_reader * rd; - dds__retcode_t rc; + dds_retcode_t rc; rc = dds_reader_lock(reader, &rd); if (rc == DDS_RETCODE_OK) { @@ -100,7 +99,7 @@ dds_entity_t dds_get_datareader (dds_entity_t condition) dds_return_t dds_get_mask (dds_entity_t condition, uint32_t *mask) { dds_entity *entity; - dds__retcode_t rc; + dds_retcode_t rc; if (mask == NULL) return DDS_ERRNO (DDS_RETCODE_BAD_PARAMETER); diff --git a/src/core/ddsc/src/dds_reader.c b/src/core/ddsc/src/dds_reader.c index b0e16cf..2f37d8a 100644 --- a/src/core/ddsc/src/dds_reader.c +++ b/src/core/ddsc/src/dds_reader.c @@ -11,7 +11,8 @@ */ #include #include -#include "ddsc/dds.h" +#include "dds/dds.h" +#include "dds/version.h" #include "dds__subscriber.h" #include "dds__reader.h" #include "dds__listener.h" @@ -20,13 +21,10 @@ #include "dds__rhc.h" #include "dds__err.h" #include "dds__topic.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" #include "dds__builtin.h" -#include "ddsi/ddsi_sertopic.h" -#include "ddsc/ddsc_project.h" - -#include "os/os.h" +#include "dds/ddsi/ddsi_sertopic.h" DECL_ENTITY_LOCK_UNLOCK(extern inline, dds_reader) @@ -54,7 +52,7 @@ static dds_return_t dds_reader_close( dds_entity *e) { - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret = DDS_RETCODE_OK; struct thread_state1 * const thr = lookup_thread_state(); const bool asleep = !vtime_awake_p(thr->vtime); @@ -146,7 +144,7 @@ dds_reader_qos_set( if (ret == DDS_RETCODE_OK) { if (enabled) { /* TODO: CHAM-95: DDSI does not support changing QoS policies. */ - DDS_ERROR(DDSC_PROJECT_NAME" does not support changing QoS policies\n"); + DDS_ERROR(DDS_PROJECT_NAME" does not support changing QoS policies\n"); ret = DDS_ERRNO(DDS_RETCODE_UNSUPPORTED); } } @@ -172,47 +170,47 @@ void dds_reader_data_available_cb (struct dds_reader *rd) struct dds_listener const * const lst = &rd->m_entity.m_listener; dds_entity * const sub = rd->m_entity.m_parent; - os_mutexLock (&rd->m_entity.m_observers_lock); + ddsrt_mutex_lock (&rd->m_entity.m_observers_lock); while (rd->m_entity.m_cb_count > 0) - os_condWait (&rd->m_entity.m_observers_cond, &rd->m_entity.m_observers_lock); + ddsrt_cond_wait (&rd->m_entity.m_observers_cond, &rd->m_entity.m_observers_lock); rd->m_entity.m_cb_count++; if (lst->on_data_on_readers) { - os_mutexUnlock (&rd->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&rd->m_entity.m_observers_lock); - os_mutexLock (&sub->m_observers_lock); + ddsrt_mutex_lock (&sub->m_observers_lock); while (sub->m_cb_count > 0) - os_condWait (&sub->m_observers_cond, &sub->m_observers_lock); + ddsrt_cond_wait (&sub->m_observers_cond, &sub->m_observers_lock); sub->m_cb_count++; - os_mutexUnlock (&sub->m_observers_lock); + ddsrt_mutex_unlock (&sub->m_observers_lock); lst->on_data_on_readers (sub->m_hdl, lst->on_data_on_readers_arg); - os_mutexLock (&rd->m_entity.m_observers_lock); - os_mutexLock (&sub->m_observers_lock); + ddsrt_mutex_lock (&rd->m_entity.m_observers_lock); + ddsrt_mutex_lock (&sub->m_observers_lock); sub->m_cb_count--; - os_condBroadcast (&sub->m_observers_cond); - os_mutexUnlock (&sub->m_observers_lock); + ddsrt_cond_broadcast (&sub->m_observers_cond); + ddsrt_mutex_unlock (&sub->m_observers_lock); } else if (rd->m_entity.m_listener.on_data_available) { - os_mutexUnlock (&rd->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&rd->m_entity.m_observers_lock); lst->on_data_available (rd->m_entity.m_hdl, lst->on_data_available_arg); - os_mutexLock (&rd->m_entity.m_observers_lock); + ddsrt_mutex_lock (&rd->m_entity.m_observers_lock); } else { dds_entity_status_set (&rd->m_entity, DDS_DATA_AVAILABLE_STATUS); - os_mutexLock (&sub->m_observers_lock); + ddsrt_mutex_lock (&sub->m_observers_lock); dds_entity_status_set (sub, DDS_DATA_ON_READERS_STATUS); - os_mutexUnlock (&sub->m_observers_lock); + ddsrt_mutex_unlock (&sub->m_observers_lock); } rd->m_entity.m_cb_count--; - os_condBroadcast (&rd->m_entity.m_observers_cond); - os_mutexUnlock (&rd->m_entity.m_observers_lock); + ddsrt_cond_broadcast (&rd->m_entity.m_observers_cond); + ddsrt_mutex_unlock (&rd->m_entity.m_observers_lock); } void dds_reader_status_cb (void *ventity, const status_cb_data_t *data) @@ -245,9 +243,9 @@ void dds_reader_status_cb (void *ventity, const status_cb_data_t *data) m_observers_lock for the duration of the listener call itself, and that similarly the listener function and argument pointers are stable */ - os_mutexLock (&entity->m_observers_lock); + ddsrt_mutex_lock (&entity->m_observers_lock); while (entity->m_cb_count > 0) - os_condWait (&entity->m_observers_cond, &entity->m_observers_lock); + ddsrt_cond_wait (&entity->m_observers_cond, &entity->m_observers_lock); entity->m_cb_count++; /* Update status metrics. */ @@ -337,9 +335,9 @@ void dds_reader_status_cb (void *ventity, const status_cb_data_t *data) if (invoke) { - os_mutexUnlock (&entity->m_observers_lock); + ddsrt_mutex_unlock (&entity->m_observers_lock); dds_entity_invoke_listener(entity, status_id, vst); - os_mutexLock (&entity->m_observers_lock); + ddsrt_mutex_lock (&entity->m_observers_lock); *reset[0] = 0; if (reset[1]) *reset[1] = 0; @@ -350,23 +348,19 @@ void dds_reader_status_cb (void *ventity, const status_cb_data_t *data) } entity->m_cb_count--; - os_condBroadcast (&entity->m_observers_cond); - os_mutexUnlock (&entity->m_observers_lock); + ddsrt_cond_broadcast (&entity->m_observers_cond); + ddsrt_mutex_unlock (&entity->m_observers_lock); } -_Pre_satisfies_(((participant_or_subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER ) ||\ - ((participant_or_subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) ) -_Pre_satisfies_(((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC ) ||\ - ((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_INTERNAL) ) dds_entity_t dds_create_reader( - _In_ dds_entity_t participant_or_subscriber, - _In_ dds_entity_t topic, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity_t participant_or_subscriber, + dds_entity_t topic, + const dds_qos_t *qos, + const dds_listener_t *listener) { dds_qos_t * rqos; - dds__retcode_t rc; + dds_retcode_t rc; dds_entity * sub = NULL; dds_entity_t subscriber; dds_reader * rd; @@ -467,16 +461,16 @@ dds_create_reader( assert(0); } - os_mutexUnlock(&tp->m_entity.m_mutex); - os_mutexUnlock(&sub->m_mutex); + ddsrt_mutex_unlock(&tp->m_entity.m_mutex); + ddsrt_mutex_unlock(&sub->m_mutex); if (asleep) { thread_state_awake (thr); } rd->m_rd = new_reader(&rd->m_entity.m_guid, NULL, &sub->m_participant->m_guid, tp->m_stopic, rqos, rhc, dds_reader_status_cb, rd); - os_mutexLock(&sub->m_mutex); - os_mutexLock(&tp->m_entity.m_mutex); + ddsrt_mutex_lock(&sub->m_mutex); + ddsrt_mutex_lock(&tp->m_entity.m_mutex); assert (rd->m_rd); if (asleep) { thread_state_asleep (thr); @@ -524,7 +518,7 @@ void dds_reader_ddsi2direct (dds_entity_t entity, ddsi2direct_directread_cb_t cb struct proxy_writer *pwr; struct rd_pwr_match *m; memset (&pwrguid, 0, sizeof (pwrguid)); - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); rd->ddsi2direct_cb = cb; rd->ddsi2direct_cbarg = cbarg; @@ -542,18 +536,18 @@ void dds_reader_ddsi2direct (dds_entity_t entity, ddsi2direct_directread_cb_t cb memset (&pwrguid_next, 0xff, sizeof (pwrguid_next)); pwrguid_next.entityid.u = (pwrguid_next.entityid.u & ~(uint32_t)0xff) | NN_ENTITYID_KIND_WRITER_NO_KEY; } - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); if ((pwr = ephash_lookup_proxy_writer_guid (&pwrguid)) != NULL) { - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); pwr->ddsi2direct_cb = cb; pwr->ddsi2direct_cbarg = cbarg; - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); } pwrguid = pwrguid_next; - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); } - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); ut_handle_release(entity, dds_rd->m_entity.m_hdllink); } } @@ -612,13 +606,12 @@ dds_entity_t dds_get_subscriber (dds_entity_t entity) return hdl; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_subscription_matched_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_subscription_matched_status_t * status) + dds_entity_t reader, + dds_subscription_matched_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; @@ -642,13 +635,12 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_liveliness_changed_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_liveliness_changed_status_t * status) + dds_entity_t reader, + dds_liveliness_changed_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; @@ -672,12 +664,11 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_sample_rejected_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_sample_rejected_status_t * status) + dds_entity_t reader, + dds_sample_rejected_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; @@ -701,12 +692,11 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_sample_lost_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_sample_lost_status_t * status) + dds_entity_t reader, + dds_sample_lost_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; @@ -729,12 +719,11 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_requested_deadline_missed_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_requested_deadline_missed_status_t * status) + dds_entity_t reader, + dds_requested_deadline_missed_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; @@ -757,12 +746,11 @@ fail: return ret; } -_Pre_satisfies_((reader & DDS_ENTITY_KIND_MASK) == DDS_KIND_READER) dds_return_t dds_get_requested_incompatible_qos_status ( - _In_ dds_entity_t reader, - _Out_opt_ dds_requested_incompatible_qos_status_t * status) + dds_entity_t reader, + dds_requested_incompatible_qos_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_reader *rd; dds_return_t ret = DDS_RETCODE_OK; diff --git a/src/core/ddsc/src/dds_rhc.c b/src/core/ddsc/src/dds_rhc.c index bbeac8d..81b3f0c 100644 --- a/src/core/ddsc/src/dds_rhc.c +++ b/src/core/ddsc/src/dds_rhc.c @@ -19,25 +19,25 @@ #define USE_VALGRIND 0 #endif -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" #include "dds__entity.h" #include "dds__reader.h" #include "dds__rhc.h" -#include "ddsi/ddsi_tkmap.h" -#include "util/ut_hopscotch.h" - -#include "util/ut_avl.h" -#include "ddsi/q_xqos.h" -#include "ddsi/q_error.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_config.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_radmin.h" /* sampleinfo */ -#include "ddsi/q_entity.h" /* proxy_writer_info */ -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_serdata_default.h" -#include "ddsi/sysdeps.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/util/ut_hopscotch.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_radmin.h" /* sampleinfo */ +#include "dds/ddsi/q_entity.h" /* proxy_writer_info */ +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/sysdeps.h" /* INSTANCE MANAGEMENT =================== @@ -277,7 +277,7 @@ struct rhc { /* Instance/Sample maximums from resource limits QoS */ - os_atomic_uint32_t n_cbs; /* # callbacks in progress */ + ddsrt_atomic_uint32_t n_cbs; /* # callbacks in progress */ int32_t max_instances; /* FIXME: probably better as uint32_t with MAX_UINT32 for unlimited */ int32_t max_samples; /* FIXME: probably better as uint32_t with MAX_UINT32 for unlimited */ int32_t max_samples_per_instance; /* FIXME: probably better as uint32_t with MAX_UINT32 for unlimited */ @@ -300,7 +300,7 @@ struct rhc { const struct ddsi_sertopic *topic; /* topic description */ unsigned history_depth; /* depth, 1 for KEEP_LAST_1, 2**32-1 for KEEP_ALL */ - os_mutex lock; + ddsrt_mutex_t lock; dds_readcond * conds; /* List of associated read conditions */ uint32_t nconds; /* Number of associated read conditions */ uint32_t nqconds; /* Number of associated query conditions */ @@ -400,7 +400,7 @@ static int instance_iid_eq (const void *va, const void *vb) return (a->iid == b->iid); } -static void add_inst_to_nonempty_list (_Inout_ struct rhc *rhc, _Inout_ struct rhc_instance *inst) +static void add_inst_to_nonempty_list (struct rhc *rhc, struct rhc_instance *inst) { if (rhc->nonempty_instances == NULL) { @@ -455,11 +455,11 @@ static void remove_inst_from_nonempty_list (struct rhc *rhc, struct rhc_instance struct rhc * dds_rhc_new (dds_reader * reader, const struct ddsi_sertopic * topic) { - struct rhc * rhc = os_malloc (sizeof (*rhc)); + struct rhc * rhc = ddsrt_malloc (sizeof (*rhc)); memset (rhc, 0, sizeof (*rhc)); lwregs_init (&rhc->registrations); - os_mutexInit (&rhc->lock); + ddsrt_mutex_init (&rhc->lock); rhc->instances = ut_hhNew (1, instance_iid_hash, instance_iid_eq); rhc->topic = topic; rhc->reader = reader; @@ -509,7 +509,7 @@ static struct rhc_sample *alloc_sample (struct rhc_instance *inst) { /* This instead of sizeof(rhc_sample) gets us type checking */ struct rhc_sample *s; - s = os_malloc (sizeof (*s)); + s = ddsrt_malloc (sizeof (*s)); return s; } } @@ -527,7 +527,7 @@ static void free_sample (struct rhc_instance *inst, struct rhc_sample *s) } else { - os_free (s); + ddsrt_free (s); } } @@ -569,7 +569,7 @@ static void free_empty_instance (struct rhc_instance *inst) { assert (inst_is_empty (inst)); ddsi_tkmap_instance_unref (inst->tk); - os_free (inst); + ddsrt_free (inst); } static void free_instance_rhc_free (struct rhc_instance *inst, struct rhc *rhc) @@ -598,17 +598,17 @@ static void free_instance_rhc_free (struct rhc_instance *inst, struct rhc *rhc) remove_inst_from_nonempty_list (rhc, inst); } ddsi_tkmap_instance_unref (inst->tk); - os_free (inst); + ddsrt_free (inst); } uint32_t dds_rhc_lock_samples (struct rhc *rhc) { uint32_t no; - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); no = rhc->n_vsamples + rhc->n_invsamples; if (no == 0) { - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); } return no; } @@ -627,19 +627,19 @@ void dds_rhc_free (struct rhc *rhc) lwregs_fini (&rhc->registrations); if (rhc->qcond_eval_samplebuf != NULL) ddsi_sertopic_free_sample (rhc->topic, rhc->qcond_eval_samplebuf, DDS_FREE_ALL); - os_mutexDestroy (&rhc->lock); - os_free (rhc); + ddsrt_mutex_destroy (&rhc->lock); + ddsrt_free (rhc); } void dds_rhc_fini (struct rhc * rhc) { - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); rhc->reader = NULL; - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); /* Wait for all callbacks to complete */ - while (os_atomic_ld32 (&rhc->n_cbs) > 0) + while (ddsrt_atomic_ld32 (&rhc->n_cbs) > 0) { dds_sleepfor (DDS_MSECS (1)); } @@ -1130,7 +1130,7 @@ static struct rhc_instance *alloc_new_instance (const struct rhc *rhc, const str struct rhc_instance *inst; ddsi_tkmap_instance_ref (tk); - inst = os_malloc (sizeof (*inst)); + inst = ddsrt_malloc (sizeof (*inst)); memset (inst, 0, sizeof (*inst)); inst->iid = tk->m_iid; inst->tk = tk; @@ -1258,7 +1258,7 @@ bool dds_rhc_store (struct rhc * __restrict rhc, const struct proxy_writer_info init_trigger_info_qcond (&trig_qc); - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); inst = ut_hhLookup (rhc->instances, &dummy_instance); if (inst == NULL) @@ -1463,15 +1463,15 @@ bool dds_rhc_store (struct rhc * __restrict rhc, const struct proxy_writer_info assert (rhc_check_counts_locked (rhc, true, true)); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); if (rhc->reader) { if (notify_data_available && (rhc->reader->m_entity.m_status_enable & DDS_DATA_AVAILABLE_STATUS)) { - os_atomic_inc32 (&rhc->n_cbs); + ddsrt_atomic_inc32 (&rhc->n_cbs); dds_reader_data_available_cb (rhc->reader); - os_atomic_dec32 (&rhc->n_cbs); + ddsrt_atomic_dec32 (&rhc->n_cbs); } if (trigger_waitsets) @@ -1489,16 +1489,16 @@ error_or_nochange: delivered = false; } - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); TRACE (")\n"); /* Make any reader status callback */ if (cb_data.raw_status_id >= 0 && rhc->reader && rhc->reader->m_entity.m_status_enable) { - os_atomic_inc32 (&rhc->n_cbs); + ddsrt_atomic_inc32 (&rhc->n_cbs); dds_reader_status_cb (&rhc->reader->m_entity, &cb_data); - os_atomic_dec32 (&rhc->n_cbs); + ddsrt_atomic_dec32 (&rhc->n_cbs); } return delivered; @@ -1527,7 +1527,7 @@ void dds_rhc_unregister_wr (struct rhc * __restrict rhc, const struct proxy_writ const uint64_t wr_iid = pwr_info->iid; const int auto_dispose = pwr_info->auto_dispose; - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); TRACE ("rhc_unregister_wr_iid(%"PRIx64",%d:\n", wr_iid, auto_dispose); for (inst = ut_hhIterFirst (rhc->instances, &iter); inst; inst = ut_hhIterNext (&iter)) { @@ -1573,7 +1573,7 @@ void dds_rhc_unregister_wr (struct rhc * __restrict rhc, const struct proxy_writ } } TRACE (")\n"); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); if (trigger_waitsets) dds_entity_status_signal (&rhc->reader->m_entity); @@ -1583,7 +1583,7 @@ void dds_rhc_relinquish_ownership (struct rhc * __restrict rhc, const uint64_t w { struct rhc_instance *inst; struct ut_hhIter iter; - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); TRACE ("rhc_relinquish_ownership(%"PRIx64":\n", wr_iid); for (inst = ut_hhIterFirst (rhc->instances, &iter); inst; inst = ut_hhIterNext (&iter)) { @@ -1594,7 +1594,7 @@ void dds_rhc_relinquish_ownership (struct rhc * __restrict rhc, const uint64_t w } TRACE (")\n"); assert (rhc_check_counts_locked (rhc, true, false)); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); } /* STATUSES: @@ -1778,7 +1778,7 @@ static int dds_rhc_read_w_qminv (struct rhc *rhc, bool lock, void **values, dds_ if (lock) { - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); } TRACE ("read_w_qminv(%p,%p,%p,%u,%x,%p) - inst %u nonempty %u disp %u nowr %u new %u samples %u+%u read %u+%u\n", @@ -1884,7 +1884,7 @@ static int dds_rhc_read_w_qminv (struct rhc *rhc, bool lock, void **values, dds_ } TRACE ("read: returning %u\n", n); assert (rhc_check_counts_locked (rhc, true, false)); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); if (trigger_waitsets) dds_entity_status_signal (&rhc->reader->m_entity); @@ -1901,7 +1901,7 @@ static int dds_rhc_take_w_qminv (struct rhc *rhc, bool lock, void **values, dds_ if (lock) { - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); } TRACE ("take_w_qminv(%p,%p,%p,%u,%x) - inst %u nonempty %u disp %u nowr %u new %u samples %u+%u read %u+%u\n", @@ -2046,7 +2046,7 @@ static int dds_rhc_take_w_qminv (struct rhc *rhc, bool lock, void **values, dds_ } TRACE ("take: returning %u\n", n); assert (rhc_check_counts_locked (rhc, true, false)); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); if (trigger_waitsets) dds_entity_status_signal(&rhc->reader->m_entity); @@ -2064,7 +2064,7 @@ static int dds_rhc_takecdr_w_qminv (struct rhc *rhc, bool lock, struct ddsi_serd if (lock) { - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); } TRACE ("take_w_qminv(%p,%p,%p,%u,%x) - inst %u nonempty %u disp %u nowr %u new %u samples %u+%u read %u+%u\n", @@ -2198,7 +2198,7 @@ static int dds_rhc_takecdr_w_qminv (struct rhc *rhc, bool lock, struct ddsi_serd } TRACE ("take: returning %u\n", n); assert (rhc_check_counts_locked (rhc, true, false)); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); if (trigger_waitsets) dds_entity_status_signal (&rhc->reader->m_entity); @@ -2267,7 +2267,7 @@ bool dds_rhc_add_readcondition (dds_readcond *cond) cond->m_qminv = qmask_from_dcpsquery (cond->m_sample_states, cond->m_view_states, cond->m_instance_states); - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); /* Allocate a slot in the condition bitmasks; return an error no more slots are available */ if (cond->m_query.m_filter != 0) @@ -2281,7 +2281,7 @@ bool dds_rhc_add_readcondition (dds_readcond *cond) if (avail_qcmask == 0) { /* no available indices */ - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); return false; } @@ -2350,7 +2350,7 @@ bool dds_rhc_add_readcondition (dds_readcond *cond) (void *) rhc, cond->m_sample_states, cond->m_view_states, cond->m_instance_states, (void *) cond, cond->m_qminv, rhc->nconds); - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); return true; } @@ -2358,7 +2358,7 @@ void dds_rhc_remove_readcondition (dds_readcond *cond) { struct rhc *rhc = cond->m_rhc; dds_readcond **ptr; - os_mutexLock (&rhc->lock); + ddsrt_mutex_lock (&rhc->lock); ptr = &rhc->conds; while (*ptr != cond) ptr = &(*ptr)->m_next; @@ -2376,7 +2376,7 @@ void dds_rhc_remove_readcondition (dds_readcond *cond) rhc->qcond_eval_samplebuf = NULL; } } - os_mutexUnlock (&rhc->lock); + ddsrt_mutex_unlock (&rhc->lock); } static bool update_conditions_locked (struct rhc *rhc, bool called_from_insert, const struct trigger_info_pre *pre, const struct trigger_info_post *post, const struct trigger_info_qcond *trig_qc, const struct rhc_instance *inst) diff --git a/src/core/ddsc/src/dds_serdata_builtintopic.c b/src/core/ddsc/src/dds_serdata_builtintopic.c index c288a83..4d45df5 100644 --- a/src/core/ddsc/src/dds_serdata_builtintopic.c +++ b/src/core/ddsc/src/dds_serdata_builtintopic.c @@ -14,19 +14,16 @@ #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include -#include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" #include "dds__key.h" #include "dds__stream.h" #include "dds__serdata_builtintopic.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/q_entity.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/q_entity.h" static const uint64_t unihashconsts[] = { UINT64_C (16292676669999574021), @@ -63,12 +60,12 @@ static void serdata_builtin_free(struct ddsi_serdata *dcmn) struct ddsi_serdata_builtintopic *d = (struct ddsi_serdata_builtintopic *)dcmn; if (d->c.kind == SDK_DATA) nn_xqos_fini (&d->xqos); - os_free (d); + ddsrt_free (d); } static struct ddsi_serdata_builtintopic *serdata_builtin_new(const struct ddsi_sertopic_builtintopic *tp, enum ddsi_serdata_kind kind) { - struct ddsi_serdata_builtintopic *d = os_malloc(sizeof (*d)); + struct ddsi_serdata_builtintopic *d = ddsrt_malloc(sizeof (*d)); ddsi_serdata_init (&d->c, &tp->c, kind); return d; } @@ -188,7 +185,7 @@ static dds_qos_t *dds_qos_from_xqos_reuse (dds_qos_t *old, const nn_xqos_t *src) { if (old == NULL) { - old = os_malloc (sizeof (*old)); + old = ddsrt_malloc (sizeof (*old)); nn_xqos_init_empty (old); old->present |= QP_TOPIC_NAME | QP_TYPE_NAME; nn_xqos_mergein_missing (old, src); @@ -267,13 +264,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, os_iovec_t *ref) +static struct ddsi_serdata *serdata_builtin_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, ddsrt_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 os_iovec_t *ref) +static void serdata_builtin_to_ser_unref (struct ddsi_serdata *serdata_common, const ddsrt_iovec_t *ref) { (void)serdata_common; (void)ref; } diff --git a/src/core/ddsc/src/dds_sertopic_builtintopic.c b/src/core/ddsc/src/dds_sertopic_builtintopic.c index 5783ab5..87bfe0d 100644 --- a/src/core/ddsc/src/dds_sertopic_builtintopic.c +++ b/src/core/ddsc/src/dds_sertopic_builtintopic.c @@ -14,20 +14,20 @@ #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include "ddsi/ddsi_sertopic.h" -#include "ddsc/dds.h" +#include "dds/dds.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" +#include "dds/ddsi/ddsi_sertopic.h" #include "dds__serdata_builtintopic.h" /* FIXME: sertopic /= ddstopic so a lot of stuff needs to be moved here from dds_topic.c and the free function needs to be implemented properly */ struct ddsi_sertopic *new_sertopic_builtintopic (enum ddsi_sertopic_builtintopic_type type, const char *name, const char *typename) { - struct ddsi_sertopic_builtintopic *tp = os_malloc (sizeof (*tp)); + struct ddsi_sertopic_builtintopic *tp = ddsrt_malloc (sizeof (*tp)); tp->c.iid = ddsi_iid_gen(); tp->c.name = dds_string_dup (name); tp->c.typename = dds_string_dup (typename); @@ -39,7 +39,7 @@ struct ddsi_sertopic *new_sertopic_builtintopic (enum ddsi_sertopic_builtintopic tp->c.serdata_basehash = ddsi_sertopic_compute_serdata_basehash (tp->c.serdata_ops); tp->c.status_cb = 0; tp->c.status_cb_entity = NULL; - os_atomic_st32 (&tp->c.refc, 1); + ddsrt_atomic_st32 (&tp->c.refc, 1); tp->type = type; return &tp->c; } diff --git a/src/core/ddsc/src/dds_stream.c b/src/core/ddsc/src/dds_stream.c index 4a1f232..2fbee03 100644 --- a/src/core/ddsc/src/dds_stream.c +++ b/src/core/ddsc/src/dds_stream.c @@ -11,13 +11,13 @@ */ #include #include -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" #include "dds__stream.h" #include "dds__key.h" #include "dds__alloc.h" -#include "os/os.h" -#include "ddsi/q_md5.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsrt/endian.h" //#define OP_DEBUG_READ 1 //#define OP_DEBUG_WRITE 1 @@ -32,7 +32,7 @@ static const char * stream_op_type[11] = }; #endif -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN #define DDS_ENDIAN true #else #define DDS_ENDIAN false @@ -139,7 +139,7 @@ bool dds_stream_endian (void) return DDS_ENDIAN; } -size_t dds_stream_check_optimize (_In_ const dds_topic_descriptor_t * desc) +size_t dds_stream_check_optimize (const dds_topic_descriptor_t * desc) { dds_stream_t os; void * sample = dds_alloc (desc->m_size); @@ -1193,7 +1193,7 @@ void dds_stream_write_sample (dds_stream_t * os, const void * data, const struct } } -void dds_stream_from_serdata_default (_Out_ dds_stream_t * s, _In_ const struct ddsi_serdata_default *d) +void dds_stream_from_serdata_default (dds_stream_t * s, const struct ddsi_serdata_default *d) { s->m_failed = false; s->m_buffer.p8 = (uint8_t*) d; diff --git a/src/core/ddsc/src/dds_subscriber.c b/src/core/ddsc/src/dds_subscriber.c index a55dd93..7a3281e 100644 --- a/src/core/ddsc/src/dds_subscriber.c +++ b/src/core/ddsc/src/dds_subscriber.c @@ -13,8 +13,8 @@ #include "dds__listener.h" #include "dds__qos.h" #include "dds__err.h" -#include "ddsi/q_entity.h" -#include "ddsc/ddsc_project.h" +#include "dds/ddsi/q_entity.h" +#include "dds/version.h" #define DDS_SUBSCRIBER_STATUS_MASK \ DDS_DATA_ON_READERS_STATUS @@ -33,8 +33,8 @@ dds_subscriber_instance_hdl( static dds_return_t dds__subscriber_qos_validate( - _In_ const dds_qos_t *qos, - _In_ bool enabled) + const dds_qos_t *qos, + bool enabled) { dds_return_t ret = DDS_RETCODE_OK; @@ -76,7 +76,7 @@ dds_subscriber_qos_set( if (ret == DDS_RETCODE_OK) { if (enabled) { /* TODO: CHAM-95: DDSI does not support changing QoS policies. */ - DDS_ERROR(DDSC_PROJECT_NAME" does not support changing QoS policies yet\n"); + DDS_ERROR(DDS_PROJECT_NAME" does not support changing QoS policies yet\n"); ret = DDS_ERRNO(DDS_RETCODE_UNSUPPORTED); } } @@ -97,12 +97,11 @@ dds_subscriber_status_validate( return ret; } -_Requires_exclusive_lock_held_(participant) -_Check_return_ dds_entity_t +dds_entity_t dds__create_subscriber_l( - _Inout_ dds_entity *participant, /* entity-lock must be held */ - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity *participant, /* entity-lock must be held */ + const dds_qos_t *qos, + const dds_listener_t *listener) { dds_subscriber * sub; dds_entity_t subscriber; @@ -136,16 +135,15 @@ err_param: return ret; } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -_Must_inspect_result_ dds_entity_t +dds_entity_t dds_create_subscriber( - _In_ dds_entity_t participant, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity_t participant, + const dds_qos_t *qos, + const dds_listener_t *listener) { dds_entity * par; dds_entity_t hdl; - dds__retcode_t errnr; + dds_retcode_t errnr; errnr = dds_entity_lock(participant, DDS_KIND_PARTICIPANT, &par); if (errnr != DDS_RETCODE_OK) { @@ -160,14 +158,13 @@ dds_create_subscriber( return hdl; } -_Pre_satisfies_((subscriber & DDS_ENTITY_KIND_MASK) == DDS_KIND_SUBSCRIBER) dds_return_t dds_notify_readers( - _In_ dds_entity_t subscriber) + dds_entity_t subscriber) { dds_entity *iter; dds_entity *sub; - dds__retcode_t errnr; + dds_retcode_t errnr; dds_return_t ret; errnr = dds_entity_lock(subscriber, DDS_KIND_SUBSCRIBER, &sub); @@ -177,9 +174,9 @@ dds_notify_readers( ret = DDS_ERRNO(errnr); iter = sub->m_children; while (iter) { - os_mutexLock(&iter->m_mutex); + ddsrt_mutex_lock(&iter->m_mutex); // TODO: check if reader has data available, call listener - os_mutexUnlock(&iter->m_mutex); + ddsrt_mutex_unlock(&iter->m_mutex); iter = iter->m_next; } dds_entity_unlock(sub); @@ -193,7 +190,7 @@ dds_notify_readers( dds_return_t dds_subscriber_begin_coherent( - _In_ dds_entity_t e) + dds_entity_t e) { /* TODO: CHAM-124 Currently unsupported. */ (void)e; @@ -203,7 +200,7 @@ dds_subscriber_begin_coherent( dds_return_t dds_subscriber_end_coherent( - _In_ dds_entity_t e) + dds_entity_t e) { /* TODO: CHAM-124 Currently unsupported. */ (void)e; diff --git a/src/core/ddsc/src/dds_time.c b/src/core/ddsc/src/dds_time.c deleted file mode 100644 index 65f370c..0000000 --- a/src/core/ddsc/src/dds_time.c +++ /dev/null @@ -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 - */ -#include "ddsc/dds.h" -#include "os/os.h" - -dds_time_t dds_time (void) -{ - os_time time; - - /* Get the current time */ - time = os_timeGet (); - - /* convert os_time to dds_time_t */ - dds_time_t dds_time = time.tv_nsec + (time.tv_sec * DDS_NSECS_IN_SEC); - - return dds_time; -} - -void dds_sleepfor (dds_duration_t n) -{ - os_time interval = { (os_timeSec) (n / DDS_NSECS_IN_SEC), (int32_t) (n % DDS_NSECS_IN_SEC) }; - os_nanoSleep (interval); -} - -void dds_sleepuntil (dds_time_t n) -{ - dds_time_t interval = n - dds_time (); - if (interval > 0) - { - dds_sleepfor (interval); - } -} diff --git a/src/core/ddsc/src/dds_topic.c b/src/core/ddsc/src/dds_topic.c index b9c193e..940d493 100644 --- a/src/core/ddsc/src/dds_topic.c +++ b/src/core/ddsc/src/dds_topic.c @@ -12,6 +12,8 @@ #include #include #include + +#include "dds/ddsrt/atomics.h" #include "dds__topic.h" #include "dds__listener.h" #include "dds__qos.h" @@ -19,12 +21,11 @@ #include "dds__init.h" #include "dds__domain.h" #include "dds__err.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" -#include "ddsi/ddsi_sertopic.h" -#include "ddsi/q_ddsi_discovery.h" -#include "os/os_atomics.h" -#include "ddsi/ddsi_iid.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/ddsi_sertopic.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/ddsi_iid.h" DECL_ENTITY_LOCK_UNLOCK(extern inline, dds_topic) @@ -47,7 +48,7 @@ const dds_entity_t DDS_BUILTIN_TOPIC_DCPSSUBSCRIPTION = (DDS_KIND_INTERNAL + 4); static bool is_valid_name( - _In_ const char *name) + const char *name) { bool valid = false; /* DDS Spec: @@ -75,7 +76,7 @@ is_valid_name( static dds_return_t dds_topic_status_validate( - uint32_t mask) + uint32_t mask) { dds_return_t ret = DDS_RETCODE_OK; @@ -96,25 +97,25 @@ static void dds_topic_status_cb (struct dds_topic *tp) { struct dds_listener const * const lst = &tp->m_entity.m_listener; - os_mutexLock (&tp->m_entity.m_observers_lock); + ddsrt_mutex_lock (&tp->m_entity.m_observers_lock); while (tp->m_entity.m_cb_count > 0) - os_condWait (&tp->m_entity.m_observers_cond, &tp->m_entity.m_observers_lock); + ddsrt_cond_wait (&tp->m_entity.m_observers_cond, &tp->m_entity.m_observers_lock); tp->m_entity.m_cb_count++; tp->m_inconsistent_topic_status.total_count++; tp->m_inconsistent_topic_status.total_count_change++; if (lst->on_inconsistent_topic) { - os_mutexUnlock (&tp->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&tp->m_entity.m_observers_lock); dds_entity_invoke_listener(&tp->m_entity, DDS_INCONSISTENT_TOPIC_STATUS_ID, &tp->m_inconsistent_topic_status); - os_mutexLock (&tp->m_entity.m_observers_lock); + ddsrt_mutex_lock (&tp->m_entity.m_observers_lock); tp->m_inconsistent_topic_status.total_count_change = 0; } dds_entity_status_set(&tp->m_entity, DDS_INCONSISTENT_TOPIC_STATUS); tp->m_entity.m_cb_count--; - os_condBroadcast (&tp->m_entity.m_observers_cond); - os_mutexUnlock (&tp->m_entity.m_observers_lock); + ddsrt_cond_broadcast (&tp->m_entity.m_observers_cond); + ddsrt_mutex_unlock (&tp->m_entity.m_observers_lock); } struct ddsi_sertopic * @@ -144,9 +145,9 @@ dds_topic_lookup( const char *name) { struct ddsi_sertopic *st; - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); st = dds_topic_lookup_locked(domain, name); - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); return st; } @@ -159,12 +160,12 @@ dds_topic_free( assert (st); - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); domain = ut_avlLookup (&dds_domaintree_def, &dds_global.m_domains, &domainid); if (domain != NULL) { ut_avlDelete (&dds_topictree_def, &domain->m_topics, st); } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); st->status_cb_entity = NULL; ddsi_sertopic_unref (st); } @@ -180,21 +181,20 @@ dds_topic_add_locked( ut_avlInsert (&dds_topictree_def, &dom->m_topics, st); } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) DDS_EXPORT dds_entity_t dds_find_topic( - _In_ dds_entity_t participant, - _In_z_ const char *name) + dds_entity_t participant, + const char *name) { dds_entity_t tp; dds_entity *p = NULL; struct ddsi_sertopic *st; - dds__retcode_t rc; + dds_retcode_t rc; if (name) { rc = dds_entity_lock(participant, DDS_KIND_PARTICIPANT, &p); if (rc == DDS_RETCODE_OK) { - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); st = dds_topic_lookup_locked (p->m_domain, name); if (st) { dds_entity_add_ref (&st->status_cb_entity->m_entity); @@ -203,7 +203,7 @@ dds_find_topic( DDS_ERROR("Topic is not being created yet\n"); tp = DDS_ERRNO(DDS_RETCODE_PRECONDITION_NOT_MET); } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); dds_entity_unlock(p); } else { DDS_ERROR("Error occurred on locking entity\n"); @@ -303,18 +303,17 @@ static bool sertopic_equivalent (const struct ddsi_sertopic *a, const struct dds return true; } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) DDS_EXPORT dds_entity_t dds_create_topic_arbitrary ( - _In_ dds_entity_t participant, - _In_ struct ddsi_sertopic *sertopic, - _In_z_ const char *name, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener, - _In_opt_ const nn_plist_t *sedp_plist) + dds_entity_t participant, + struct ddsi_sertopic *sertopic, + const char *name, + const dds_qos_t *qos, + const dds_listener_t *listener, + const nn_plist_t *sedp_plist) { struct ddsi_sertopic *stgeneric; - dds__retcode_t rc; + dds_retcode_t rc; dds_entity *par; dds_topic *top; dds_qos_t *new_qos = NULL; @@ -359,7 +358,7 @@ dds_create_topic_arbitrary ( /* FIXME: I find it weird that qos may be NULL in the entity */ /* Check if topic already exists with same name */ - os_mutexLock (&dds_global.m_mutex); + ddsrt_mutex_lock (&dds_global.m_mutex); if ((stgeneric = dds_topic_lookup_locked (par->m_domain, name)) != NULL) { if (!sertopic_equivalent (stgeneric,sertopic)) { /* FIXME: should copy the type, perhaps? but then the pointers will no longer be the same */ @@ -373,7 +372,7 @@ dds_create_topic_arbitrary ( dds_entity_add_ref (&stgeneric->status_cb_entity->m_entity); hdl = stgeneric->status_cb_entity->m_entity.m_hdl; } - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); } else { if (qos) { new_qos = dds_create_qos(); @@ -393,7 +392,7 @@ dds_create_topic_arbitrary ( /* Add topic to extent */ dds_topic_add_locked (par->m_domainid, sertopic); - os_mutexUnlock (&dds_global.m_mutex); + ddsrt_mutex_unlock (&dds_global.m_mutex); /* Publish Topic */ if (asleep) { @@ -416,14 +415,13 @@ bad_param_err: return hdl; } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) DDS_EXPORT dds_entity_t dds_create_topic( - _In_ dds_entity_t participant, - _In_ const dds_topic_descriptor_t *desc, - _In_z_ const char *name, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity_t participant, + const dds_topic_descriptor_t *desc, + const char *name, + const dds_qos_t *qos, + const dds_listener_t *listener) { char *key = NULL; struct ddsi_sertopic_default *st; @@ -459,7 +457,7 @@ dds_create_topic( st = dds_alloc (sizeof (*st)); - os_atomic_st32 (&st->c.refc, 1); + ddsrt_atomic_st32 (&st->c.refc, 1); st->c.iid = ddsi_iid_gen (); st->c.status_cb = dds_topic_status_cb; st->c.status_cb_entity = NULL; /* set by dds_create_topic_arbitrary */ @@ -469,7 +467,7 @@ dds_create_topic( 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); - st->native_encoding_identifier = (PLATFORM_IS_LITTLE_ENDIAN ? CDR_LE : CDR_BE); + st->native_encoding_identifier = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? CDR_LE : CDR_BE); st->type = (void*) desc; st->nkeys = desc->m_nkeys; @@ -543,7 +541,6 @@ dds_topic_mod_filter( } } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) void dds_set_topic_filter( dds_entity_t topic, @@ -554,7 +551,6 @@ dds_set_topic_filter( dds_topic_mod_filter (topic, &chaining, &realf, true); } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) void dds_topic_set_filter( dds_entity_t topic, @@ -563,7 +559,6 @@ dds_topic_set_filter( dds_set_topic_filter(topic, filter); } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) dds_topic_filter_fn dds_get_topic_filter( dds_entity_t topic) @@ -574,7 +569,6 @@ dds_get_topic_filter( return (filter == dds_topic_chaining_filter) ? (dds_topic_filter_fn)ctx : 0; } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) dds_topic_filter_fn dds_topic_get_filter( dds_entity_t topic) @@ -601,16 +595,15 @@ dds_topic_get_filter_with_ctx( return (filter == dds_topic_chaining_filter) ? 0 : filter; } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) DDS_EXPORT dds_return_t dds_get_name( - _In_ dds_entity_t topic, - _Out_writes_z_(size) char *name, - _In_ size_t size) + dds_entity_t topic, + char *name, + size_t size) { dds_topic *t; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; if(size <= 0){ DDS_ERROR("Argument size is smaller than 0\n"); @@ -637,15 +630,14 @@ fail: return ret; } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) DDS_EXPORT dds_return_t dds_get_type_name( - _In_ dds_entity_t topic, - _Out_writes_z_(size) char *name, - _In_ size_t size) + dds_entity_t topic, + char *name, + size_t size) { dds_topic *t; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; if(size <= 0){ @@ -671,13 +663,13 @@ dds_get_type_name( fail: return ret; } -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) + dds_return_t dds_get_inconsistent_topic_status( - _In_ dds_entity_t topic, - _Out_opt_ dds_inconsistent_topic_status_t *status) + dds_entity_t topic, + dds_inconsistent_topic_status_t *status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_topic *t; dds_return_t ret = DDS_RETCODE_OK; diff --git a/src/core/ddsc/src/dds_waitset.c b/src/core/ddsc/src/dds_waitset.c index 1b0782a..a594049 100644 --- a/src/core/ddsc/src/dds_waitset.c +++ b/src/core/ddsc/src/dds_waitset.c @@ -10,7 +10,9 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "os/os.h" + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" #include "dds__entity.h" #include "dds__querycond.h" #include "dds__readcond.h" @@ -21,10 +23,10 @@ DEFINE_ENTITY_LOCK_UNLOCK(static, dds_waitset, DDS_KIND_WAITSET) static void dds_waitset_swap( - _Inout_ dds_attachment **dst, - _In_ dds_attachment **src, - _In_opt_ dds_attachment *prev, - _In_ dds_attachment *idx) + dds_attachment **dst, + dds_attachment **src, + dds_attachment *prev, + dds_attachment *idx) { /* Remove from source. */ if (prev == NULL) { @@ -40,15 +42,15 @@ dds_waitset_swap( static dds_return_t dds_waitset_wait_impl( - _In_ dds_entity_t waitset, - _Out_writes_to_opt_(nxs, return < 0 ? 0 : return) dds_attach_t *xs, - _In_ size_t nxs, - _In_ dds_time_t abstimeout, - _In_ dds_time_t tnow) + dds_entity_t waitset, + dds_attach_t *xs, + size_t nxs, + dds_time_t abstimeout, + dds_time_t tnow) { dds_waitset *ws; dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_attachment *idx; dds_attachment *next; dds_attachment *prev; @@ -98,20 +100,12 @@ dds_waitset_wait_impl( rc = DDS_RETCODE_OK; while ((ws->observed != NULL) && (ws->triggered == NULL) && (rc == DDS_RETCODE_OK)) { if (abstimeout == DDS_NEVER) { - os_condWait(&ws->m_entity.m_cond, &ws->m_entity.m_mutex); + ddsrt_cond_wait(&ws->m_entity.m_cond, &ws->m_entity.m_mutex); } else if (abstimeout <= tnow) { rc = DDS_RETCODE_TIMEOUT; } else { dds_duration_t dt = abstimeout - tnow; - os_time to; - if ((dt / (dds_duration_t)DDS_NSECS_IN_SEC) >= (dds_duration_t)OS_TIME_INFINITE_SEC) { - to.tv_sec = OS_TIME_INFINITE_SEC; - to.tv_nsec = DDS_NSECS_IN_SEC - 1; - } else { - to.tv_sec = (os_timeSec) (dt / DDS_NSECS_IN_SEC); - to.tv_nsec = (int32_t) (dt % DDS_NSECS_IN_SEC); - } - (void)os_condTimedWait(&ws->m_entity.m_cond, &ws->m_entity.m_mutex, &to); + (void)ddsrt_cond_waitfor(&ws->m_entity.m_cond, &ws->m_entity.m_mutex, dt); tnow = dds_time(); } } @@ -151,15 +145,15 @@ dds_waitset_wait_impl( static void dds_waitset_close_list( - _In_ dds_attachment **list, - _In_ dds_entity_t waitset) + dds_attachment **list, + dds_entity_t waitset) { dds_attachment *idx = *list; dds_attachment *next; while (idx != NULL) { next = idx->next; (void)dds_entity_observer_unregister(idx->entity->m_hdl, waitset); - os_free(idx); + ddsrt_free(idx); idx = next; } *list = NULL; @@ -167,8 +161,8 @@ dds_waitset_close_list( static bool dds_waitset_remove_from_list( - _In_ dds_attachment **list, - _In_ dds_entity_t observed) + dds_attachment **list, + dds_entity_t observed) { dds_attachment *idx = *list; dds_attachment *prev = NULL; @@ -180,7 +174,7 @@ dds_waitset_remove_from_list( } else { prev->next = idx->next; } - os_free(idx); + ddsrt_free(idx); /* We're done. */ return true; @@ -201,19 +195,18 @@ dds_waitset_close( dds_waitset_close_list(&ws->triggered, e->m_hdl); /* Trigger waitset to wake up. */ - os_condBroadcast(&e->m_cond); + ddsrt_cond_broadcast(&e->m_cond); return DDS_RETCODE_OK; } -_Pre_satisfies_((participant & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT) -DDS_EXPORT _Must_inspect_result_ dds_entity_t +DDS_EXPORT dds_entity_t dds_create_waitset( - _In_ dds_entity_t participant) + dds_entity_t participant) { dds_entity_t hdl; dds_entity *par; - dds__retcode_t rc; + dds_retcode_t rc; rc = dds_entity_lock(participant, DDS_KIND_PARTICIPANT, &par); if (rc == DDS_RETCODE_OK) { @@ -232,15 +225,14 @@ dds_create_waitset( } -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) DDS_EXPORT dds_return_t dds_waitset_get_entities( - _In_ dds_entity_t waitset, - _Out_writes_to_(size, return < 0 ? 0 : return) dds_entity_t *entities, - _In_ size_t size) + dds_entity_t waitset, + dds_entity_t *entities, + size_t size) { dds_return_t ret = 0; - dds__retcode_t rc; + dds_retcode_t rc; dds_waitset *ws; rc = dds_waitset_lock(waitset, &ws); @@ -276,9 +268,9 @@ dds_waitset_get_entities( static void dds_waitset_move( - _In_ dds_attachment **src, - _Inout_ dds_attachment **dst, - _In_ dds_entity_t entity) + dds_attachment **src, + dds_attachment **dst, + dds_entity_t entity) { dds_attachment *idx = *src; dds_attachment *prev = NULL; @@ -326,21 +318,20 @@ dds_waitset_observer( dds_waitset_move(&(ws->triggered), &(ws->observed), observed); } /* Trigger waitset to wake up. */ - os_condBroadcast(&ws->m_entity.m_cond); + ddsrt_cond_broadcast(&ws->m_entity.m_cond); dds_waitset_unlock(ws); } } -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) DDS_EXPORT dds_return_t dds_waitset_attach( - _In_ dds_entity_t waitset, - _In_ dds_entity_t entity, - _In_ dds_attach_t x) + dds_entity_t waitset, + dds_entity_t entity, + dds_attach_t x) { dds_entity *e = NULL; dds_waitset *ws; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; rc = dds_waitset_lock(waitset, &ws); @@ -360,7 +351,7 @@ dds_waitset_attach( } if (rc == DDS_RETCODE_OK) { - dds_attachment *a = os_malloc(sizeof(dds_attachment)); + dds_attachment *a = ddsrt_malloc(sizeof(dds_attachment)); a->arg = x; a->entity = e; if (e->m_trigger > 0) { @@ -390,14 +381,13 @@ dds_waitset_attach( return ret; } -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) DDS_EXPORT dds_return_t dds_waitset_detach( - _In_ dds_entity_t waitset, - _In_ dds_entity_t entity) + dds_entity_t waitset, + dds_entity_t entity) { dds_waitset *ws; - dds__retcode_t rc; + dds_retcode_t rc; dds_return_t ret; rc = dds_waitset_lock(waitset, &ws); @@ -427,24 +417,22 @@ dds_waitset_detach( return ret; } -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) dds_return_t dds_waitset_wait_until( - _In_ dds_entity_t waitset, - _Out_writes_to_opt_(nxs, return < 0 ? 0 : return) dds_attach_t *xs, - _In_ size_t nxs, - _In_ dds_time_t abstimeout) + dds_entity_t waitset, + dds_attach_t *xs, + size_t nxs, + dds_time_t abstimeout) { return dds_waitset_wait_impl(waitset, xs, nxs, abstimeout, dds_time()); } -_Pre_satisfies_((waitset & DDS_ENTITY_KIND_MASK) == DDS_KIND_WAITSET) dds_return_t dds_waitset_wait( - _In_ dds_entity_t waitset, - _Out_writes_to_opt_(nxs, return < 0 ? 0 : return) dds_attach_t *xs, - _In_ size_t nxs, - _In_ dds_duration_t reltimeout) + dds_entity_t waitset, + dds_attach_t *xs, + size_t nxs, + dds_duration_t reltimeout) { dds_entity_t ret; @@ -463,21 +451,21 @@ dds_waitset_wait( dds_return_t dds_waitset_set_trigger (dds_entity_t waitset, bool trigger) { dds_waitset *ws; - dds__retcode_t rc; + dds_retcode_t rc; if ((rc = dds_waitset_lock (waitset, &ws)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); - os_mutexUnlock (&ws->m_entity.m_mutex); + ddsrt_mutex_unlock (&ws->m_entity.m_mutex); - os_mutexLock (&ws->m_entity.m_observers_lock); + ddsrt_mutex_lock (&ws->m_entity.m_observers_lock); if (trigger) dds_entity_status_set (&ws->m_entity, DDS_WAITSET_TRIGGER_STATUS); else dds_entity_status_reset (&ws->m_entity, DDS_WAITSET_TRIGGER_STATUS); - os_mutexUnlock (&ws->m_entity.m_observers_lock); + ddsrt_mutex_unlock (&ws->m_entity.m_observers_lock); - os_mutexLock (&ws->m_entity.m_mutex); + ddsrt_mutex_lock (&ws->m_entity.m_mutex); dds_waitset_unlock (ws); return DDS_RETCODE_OK; } diff --git a/src/core/ddsc/src/dds_whc.c b/src/core/ddsc/src/dds_whc.c index 1f02d62..4e1333b 100644 --- a/src/core/ddsc/src/dds_whc.c +++ b/src/core/ddsc/src/dds_whc.c @@ -13,18 +13,19 @@ #include #include -#include "os/os.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_config.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_config.h" #include "dds__whc.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" -#include "util/ut_avl.h" -#include "util/ut_hopscotch.h" -#include "ddsi/q_time.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_freelist.h" +#include "dds/util/ut_avl.h" +#include "dds/util/ut_hopscotch.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_freelist.h" #define USE_EHH 0 @@ -73,7 +74,7 @@ struct whc_seq_entry { struct whc_impl { struct whc common; - os_mutex lock; + ddsrt_mutex_t lock; unsigned seq_size; size_t unacked_bytes; size_t sample_overhead; @@ -343,9 +344,9 @@ struct whc *whc_new (int is_transient_local, unsigned hdepth, unsigned tldepth) assert((hdepth == 0 || tldepth <= hdepth) || is_transient_local); - whc = os_malloc (sizeof (*whc)); + whc = ddsrt_malloc (sizeof (*whc)); whc->common.ops = &whc_ops; - os_mutexInit (&whc->lock); + ddsrt_mutex_init (&whc->lock); whc->is_transient_local = is_transient_local ? 1 : 0; whc->hdepth = hdepth; whc->tldepth = tldepth; @@ -368,7 +369,7 @@ struct whc *whc_new (int is_transient_local, unsigned hdepth, unsigned tldepth) /* seq interval tree: always has an "open" node */ ut_avlInit (&whc_seq_treedef, &whc->seq); - intv = os_malloc (sizeof (*intv)); + intv = ddsrt_malloc (sizeof (*intv)); intv->min = intv->maxp1 = 1; intv->first = intv->last = NULL; ut_avlInsert (&whc_seq_treedef, &whc->seq, intv); @@ -387,7 +388,7 @@ static void free_whc_node_contents (struct whc_node *whcn) ddsi_serdata_unref (whcn->serdata); if (whcn->plist) { nn_plist_fini (whcn->plist); - os_free (whcn->plist); + ddsrt_free (whcn->plist); } } @@ -402,7 +403,7 @@ void whc_default_free (struct whc *whc_generic) struct ut_hhIter it; struct whc_idxnode *n; for (n = ut_hhIterFirst(whc->idx_hash, &it); n != NULL; n = ut_hhIterNext(&it)) - os_free(n); + ddsrt_free(n); ut_hhFree(whc->idx_hash); } @@ -412,24 +413,24 @@ void whc_default_free (struct whc *whc_generic) { struct whc_node *tmp = whcn; /* The compiler doesn't realize that whcn->prev_seq is always initialized. */ -OS_WARNING_MSVC_OFF(6001); +DDSRT_WARNING_MSVC_OFF(6001); whcn = whcn->prev_seq; -OS_WARNING_MSVC_ON(6001); +DDSRT_WARNING_MSVC_ON(6001); free_whc_node_contents (tmp); - os_free (tmp); + ddsrt_free (tmp); } } - ut_avlFree (&whc_seq_treedef, &whc->seq, os_free); - nn_freelist_fini (&whc->freelist, os_free); + ut_avlFree (&whc_seq_treedef, &whc->seq, ddsrt_free); + nn_freelist_fini (&whc->freelist, ddsrt_free); #if USE_EHH ut_ehhFree (whc->seq_hash); #else ut_hhFree (whc->seq_hash); #endif - os_mutexDestroy (&whc->lock); - os_free (whc); + ddsrt_mutex_destroy (&whc->lock); + ddsrt_free (whc); } static void get_state_locked(const struct whc_impl *whc, struct whc_state *st) @@ -456,10 +457,10 @@ static void get_state_locked(const struct whc_impl *whc, struct whc_state *st) static void whc_default_get_state(const struct whc *whc_generic, struct whc_state *st) { const struct whc_impl * const whc = (const struct whc_impl *)whc_generic; - os_mutexLock ((struct os_mutex *)&whc->lock); + ddsrt_mutex_lock ((ddsrt_mutex_t *)&whc->lock); check_whc (whc); get_state_locked(whc, st); - os_mutexUnlock ((struct os_mutex *)&whc->lock); + ddsrt_mutex_unlock ((ddsrt_mutex_t *)&whc->lock); } static struct whc_node *find_nextseq_intv (struct whc_intvnode **p_intv, const struct whc_impl *whc, seqno_t seq) @@ -510,13 +511,13 @@ static seqno_t whc_default_next_seq (const struct whc *whc_generic, seqno_t seq) struct whc_node *n; struct whc_intvnode *intv; seqno_t nseq; - os_mutexLock ((struct os_mutex *)&whc->lock); + ddsrt_mutex_lock ((ddsrt_mutex_t *)&whc->lock); check_whc (whc); if ((n = find_nextseq_intv (&intv, whc, seq)) == NULL) nseq = MAX_SEQ_NUMBER; else nseq = n->seq; - os_mutexUnlock ((struct os_mutex *)&whc->lock); + ddsrt_mutex_unlock ((ddsrt_mutex_t *)&whc->lock); return nseq; } @@ -538,7 +539,7 @@ static void delete_one_sample_from_idx (struct whc_impl *whc, struct whc_node *w if (!ut_hhRemove (whc->idx_hash, idxn)) assert (0); ddsi_tkmap_instance_unref(idxn->tk); - os_free (idxn); + ddsrt_free (idxn); } whcn->idxnode = NULL; } @@ -560,7 +561,7 @@ static void free_one_instance_from_idx (struct whc_impl *whc, seqno_t max_drop_s } } } - os_free(idxn); + ddsrt_free(idxn); } static void delete_one_instance_from_idx (struct whc_impl *whc, seqno_t max_drop_seq, struct whc_idxnode *idxn) @@ -591,14 +592,14 @@ static unsigned whc_default_downgrade_to_volatile (struct whc *whc_generic, stru /* We only remove them from whc->tlidx: we don't remove them from whc->seq yet. That'll happen eventually. */ - os_mutexLock (&whc->lock); + ddsrt_mutex_lock (&whc->lock); check_whc (whc); if (whc->idxdepth == 0) { /* if not maintaining an index at all, this is nonsense */ get_state_locked(whc, st); - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return 0; } @@ -628,7 +629,7 @@ static unsigned whc_default_downgrade_to_volatile (struct whc *whc_generic, stru whc_default_free_deferred_free_list (whc_generic, deferred_free_list); assert (whc->max_drop_seq == old_max_drop_seq); get_state_locked(whc, st); - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return cnt; } @@ -680,7 +681,7 @@ static void whc_delete_one_intv (struct whc_impl *whc, struct whc_intvnode **p_i *p_intv = ut_avlFindSucc (&whc_seq_treedef, &whc->seq, intv); /* only sample in interval and not the open interval => delete interval */ ut_avlDelete (&whc_seq_treedef, &whc->seq, tmp); - os_free (tmp); + ddsrt_free (tmp); } else { @@ -711,7 +712,7 @@ static void whc_delete_one_intv (struct whc_impl *whc, struct whc_intvnode **p_i struct whc_intvnode *new_intv; ut_avlIPath_t path; - new_intv = os_malloc (sizeof (*new_intv)); + new_intv = ddsrt_malloc (sizeof (*new_intv)); /* new interval starts at the next node */ assert (whcn->next_seq); @@ -770,7 +771,7 @@ static void free_deferred_free_list (struct whc_impl *whc, struct whc_node *defe { struct whc_node *tmp = cur; cur = cur->next_seq; - os_free (tmp); + ddsrt_free (tmp); } } } @@ -996,7 +997,7 @@ static unsigned whc_default_remove_acked_messages (struct whc *whc_generic, seqn struct whc_impl * const whc = (struct whc_impl *)whc_generic; unsigned cnt; - os_mutexLock (&whc->lock); + ddsrt_mutex_lock (&whc->lock); assert (max_drop_seq < MAX_SEQ_NUMBER); assert (max_drop_seq >= whc->max_drop_seq); @@ -1016,7 +1017,7 @@ static unsigned whc_default_remove_acked_messages (struct whc *whc_generic, seqn else cnt = whc_default_remove_acked_messages_full (whc, max_drop_seq, deferred_free_list); get_state_locked(whc, whcst); - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return cnt; } @@ -1025,7 +1026,7 @@ static struct whc_node *whc_default_insert_seq (struct whc_impl *whc, seqno_t ma struct whc_node *newn = NULL; if ((newn = nn_freelist_pop (&whc->freelist)) == NULL) - newn = os_malloc (sizeof (*newn)); + newn = ddsrt_malloc (sizeof (*newn)); newn->seq = seq; newn->plist = plist; newn->unacked = (seq > max_drop_seq); @@ -1067,7 +1068,7 @@ static struct whc_node *whc_default_insert_seq (struct whc_impl *whc, seqno_t ma /* gap => need new open_intv */ struct whc_intvnode *intv1; ut_avlIPath_t path; - intv1 = os_malloc (sizeof (*intv1)); + intv1 = ddsrt_malloc (sizeof (*intv1)); intv1->min = seq; intv1->maxp1 = seq + 1; intv1->first = intv1->last = newn; @@ -1091,7 +1092,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se char pad[sizeof(struct whc_idxnode) + sizeof(struct whc_node *)]; } template; - os_mutexLock (&whc->lock); + ddsrt_mutex_lock (&whc->lock); check_whc (whc); if (dds_get_log_mask() & DDS_LC_WHC) @@ -1120,7 +1121,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se if (serdata->kind == SDK_EMPTY || whc->idxdepth == 0) { DDS_LOG(DDS_LC_WHC, " empty or no hist\n"); - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return 0; } @@ -1188,7 +1189,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se if (!(serdata->statusinfo & NN_STATUSINFO_UNREGISTER)) { unsigned i; - idxn = os_malloc (sizeof (*idxn) + whc->idxdepth * sizeof (idxn->hist[0])); + idxn = ddsrt_malloc (sizeof (*idxn) + whc->idxdepth * sizeof (idxn->hist[0])); DDS_LOG(DDS_LC_WHC, " idxn %p", (void *)idxn); ddsi_tkmap_instance_ref(tk); idxn->iid = tk->m_iid; @@ -1216,7 +1217,7 @@ static int whc_default_insert (struct whc *whc_generic, seqno_t max_drop_seq, se } DDS_LOG(DDS_LC_WHC, "\n"); } - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return 0; } @@ -1237,7 +1238,7 @@ static bool whc_default_borrow_sample (const struct whc *whc_generic, seqno_t se const struct whc_impl * const whc = (const struct whc_impl *)whc_generic; struct whc_node *whcn; bool found; - os_mutexLock ((os_mutex *)&whc->lock); + ddsrt_mutex_lock ((ddsrt_mutex_t *)&whc->lock); if ((whcn = whc_findseq(whc, seq)) == NULL) found = false; else @@ -1245,7 +1246,7 @@ static bool whc_default_borrow_sample (const struct whc *whc_generic, seqno_t se make_borrowed_sample(sample, whcn); found = true; } - os_mutexUnlock ((os_mutex *)&whc->lock); + ddsrt_mutex_unlock ((ddsrt_mutex_t *)&whc->lock); return found; } @@ -1254,7 +1255,7 @@ static bool whc_default_borrow_sample_key (const struct whc *whc_generic, const const struct whc_impl * const whc = (const struct whc_impl *)whc_generic; struct whc_node *whcn; bool found; - os_mutexLock ((os_mutex *)&whc->lock); + ddsrt_mutex_lock ((ddsrt_mutex_t *)&whc->lock); if ((whcn = whc_findkey(whc, serdata_key)) == NULL) found = false; else @@ -1262,7 +1263,7 @@ static bool whc_default_borrow_sample_key (const struct whc *whc_generic, const make_borrowed_sample(sample, whcn); found = true; } - os_mutexUnlock ((os_mutex *)&whc->lock); + ddsrt_mutex_unlock ((ddsrt_mutex_t *)&whc->lock); return found; } @@ -1275,7 +1276,7 @@ static void return_sample_locked (struct whc_impl *whc, struct whc_borrowed_samp ddsi_serdata_unref (sample->serdata); if (sample->plist) { nn_plist_fini (sample->plist); - os_free (sample->plist); + ddsrt_free (sample->plist); } } else @@ -1293,9 +1294,9 @@ static void return_sample_locked (struct whc_impl *whc, struct whc_borrowed_samp static void whc_default_return_sample (struct whc *whc_generic, struct whc_borrowed_sample *sample, bool update_retransmit_info) { struct whc_impl * const whc = (struct whc_impl *)whc_generic; - os_mutexLock (&whc->lock); + ddsrt_mutex_lock (&whc->lock); return_sample_locked (whc, sample, update_retransmit_info); - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); } static void whc_default_sample_iter_init (const struct whc *whc_generic, struct whc_sample_iter *opaque_it) @@ -1313,7 +1314,7 @@ static bool whc_default_sample_iter_borrow_next (struct whc_sample_iter *opaque_ struct whc_intvnode *intv; seqno_t seq; bool valid; - os_mutexLock (&whc->lock); + ddsrt_mutex_lock (&whc->lock); check_whc (whc); if (!it->first) { @@ -1332,6 +1333,6 @@ static bool whc_default_sample_iter_borrow_next (struct whc_sample_iter *opaque_ make_borrowed_sample(sample, whcn); valid = true; } - os_mutexUnlock (&whc->lock); + ddsrt_mutex_unlock (&whc->lock); return valid; } diff --git a/src/core/ddsc/src/dds_whc_builtintopic.c b/src/core/ddsc/src/dds_whc_builtintopic.c index 3453102..ded5cf3 100644 --- a/src/core/ddsc/src/dds_whc_builtintopic.c +++ b/src/core/ddsc/src/dds_whc_builtintopic.c @@ -13,13 +13,13 @@ #include #include -#include "os/os.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_config.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__serdata_builtintopic.h" #include "dds__whc_builtintopic.h" #include "dds__builtin.h" @@ -50,7 +50,7 @@ struct bwhc_sample_iter_sizecheck { static void bwhc_free (struct whc *whc_generic) { - os_free (whc_generic); + ddsrt_free (whc_generic); } static void bwhc_sample_iter_init (const struct whc *whc_generic, struct whc_sample_iter *opaque_it) @@ -151,7 +151,7 @@ static int bwhc_insert (struct whc *whc, seqno_t max_drop_seq, seqno_t seq, stru (void)serdata; (void)tk; if (plist) - os_free (plist); + ddsrt_free (plist); return 0; } @@ -194,7 +194,7 @@ static const struct whc_ops bwhc_ops = { struct whc *builtintopic_whc_new (enum ddsi_sertopic_builtintopic_type type) { - struct bwhc *whc = os_malloc (sizeof (*whc)); + struct bwhc *whc = ddsrt_malloc (sizeof (*whc)); whc->common.ops = &bwhc_ops; whc->type = type; return (struct whc *) whc; diff --git a/src/core/ddsc/src/dds_write.c b/src/core/ddsc/src/dds_write.c index da7982d..969c6f3 100644 --- a/src/core/ddsc/src/dds_write.c +++ b/src/core/ddsc/src/dds_write.c @@ -13,23 +13,23 @@ #include #include "dds__writer.h" #include "dds__write.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/q_error.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/ddsi_serdata.h" #include "dds__stream.h" #include "dds__err.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_config.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_radmin.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_radmin.h" dds_return_t dds_write (dds_entity_t writer, const void *data) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; if (data == NULL) @@ -45,7 +45,7 @@ dds_return_t dds_write (dds_entity_t writer, const void *data) dds_return_t dds_writecdr (dds_entity_t writer, struct ddsi_serdata *serdata) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; if (serdata == NULL) @@ -61,7 +61,7 @@ dds_return_t dds_writecdr (dds_entity_t writer, struct ddsi_serdata *serdata) dds_return_t dds_write_ts (dds_entity_t writer, const void *data, dds_time_t timestamp) { dds_return_t ret; - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; if (data == NULL || timestamp < 0) @@ -95,7 +95,7 @@ static dds_return_t try_store (struct rhc *rhc, const struct proxy_writer_info * static dds_return_t deliver_locally (struct writer *wr, struct ddsi_serdata *payload, struct ddsi_tkmap_instance *tk) { dds_return_t ret = DDS_RETCODE_OK; - os_mutexLock (&wr->rdary.rdary_lock); + ddsrt_mutex_lock (&wr->rdary.rdary_lock); if (wr->rdary.fastpath_ok) { struct reader ** const rdary = wr->rdary.rdary; @@ -111,7 +111,7 @@ static dds_return_t deliver_locally (struct writer *wr, struct ddsi_serdata *pay break; } } - os_mutexUnlock (&wr->rdary.rdary_lock); + ddsrt_mutex_unlock (&wr->rdary.rdary_lock); } else { @@ -127,9 +127,9 @@ static dds_return_t deliver_locally (struct writer *wr, struct ddsi_serdata *pay struct pwr_rd_match *m; struct proxy_writer_info pwr_info; dds_duration_t max_block_ms = nn_from_ddsi_duration (wr->xqos->reliability.max_blocking_time); - os_mutexUnlock (&wr->rdary.rdary_lock); + ddsrt_mutex_unlock (&wr->rdary.rdary_lock); make_proxy_writer_info (&pwr_info, &wr->e, wr->xqos); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); for (m = ut_avlIterFirst (&wr_local_readers_treedef, &wr->local_readers, &it); m != NULL; m = ut_avlIterNext (&it)) { struct reader *rd; @@ -141,7 +141,7 @@ static dds_return_t deliver_locally (struct writer *wr, struct ddsi_serdata *pay break; } } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } return ret; } @@ -266,7 +266,7 @@ void dds_write_flush (dds_entity_t writer) struct thread_state1 * const thr = lookup_thread_state (); const bool asleep = !vtime_awake_p (thr->vtime); dds_writer *wr; - dds__retcode_t rc; + dds_retcode_t rc; if (asleep) thread_state_awake (thr); diff --git a/src/core/ddsc/src/dds_writer.c b/src/core/ddsc/src/dds_writer.c index 85f868c..e15bbbf 100644 --- a/src/core/ddsc/src/dds_writer.c +++ b/src/core/ddsc/src/dds_writer.c @@ -10,20 +10,21 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "ddsc/dds.h" -#include "ddsi/q_config.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_xmsg.h" + +#include "dds/dds.h" +#include "dds/version.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_xmsg.h" #include "dds__writer.h" #include "dds__listener.h" #include "dds__qos.h" #include "dds__err.h" #include "dds__init.h" #include "dds__topic.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__whc.h" -#include "ddsc/ddsc_project.h" DECL_ENTITY_LOCK_UNLOCK(extern inline, dds_writer) @@ -84,9 +85,9 @@ static void dds_writer_status_cb (void *ventity, const status_cb_data_t *data) void *vst = NULL; int32_t *reset[2] = { NULL, NULL }; - os_mutexLock (&entity->m_observers_lock); + ddsrt_mutex_lock (&entity->m_observers_lock); while (entity->m_cb_count > 0) - os_condWait (&entity->m_observers_cond, &entity->m_observers_lock); + ddsrt_cond_wait (&entity->m_observers_cond, &entity->m_observers_lock); entity->m_cb_count++; /* Reset the status for possible Listener call. @@ -154,9 +155,9 @@ static void dds_writer_status_cb (void *ventity, const status_cb_data_t *data) if (invoke) { - os_mutexUnlock (&entity->m_observers_lock); + ddsrt_mutex_unlock (&entity->m_observers_lock); dds_entity_invoke_listener(entity, status_id, vst); - os_mutexLock (&entity->m_observers_lock); + ddsrt_mutex_lock (&entity->m_observers_lock); *reset[0] = 0; if (reset[1]) *reset[1] = 0; @@ -167,8 +168,8 @@ static void dds_writer_status_cb (void *ventity, const status_cb_data_t *data) } entity->m_cb_count--; - os_condBroadcast (&entity->m_observers_cond); - os_mutexUnlock (&entity->m_observers_lock); + ddsrt_cond_broadcast (&entity->m_observers_cond); + ddsrt_mutex_unlock (&entity->m_observers_lock); } static uint32_t @@ -313,11 +314,11 @@ dds_writer_qos_set( } /* FIXME: with QoS changes being unsupported by the underlying stack I wonder what will happen; locking the underlying DDSI writer is of doubtful value as well */ - os_mutexLock (&ddsi_wr->e.lock); + ddsrt_mutex_lock (&ddsi_wr->e.lock); if (qos->ownership_strength.value != ddsi_wr->xqos->ownership_strength.value) { ddsi_wr->xqos->ownership_strength.value = qos->ownership_strength.value; } - os_mutexUnlock (&ddsi_wr->e.lock); + ddsrt_mutex_unlock (&ddsi_wr->e.lock); if (asleep) { thread_state_asleep (thr); @@ -328,7 +329,7 @@ dds_writer_qos_set( } } else { if (enabled) { - DDS_ERROR(DDSC_PROJECT_NAME" does not support changing QoS policies yet\n"); + DDS_ERROR(DDS_PROJECT_NAME" does not support changing QoS policies yet\n"); ret = DDS_ERRNO(DDS_RETCODE_UNSUPPORTED); } } @@ -387,17 +388,14 @@ static struct whc *make_whc(const dds_qos_t *qos) } -_Pre_satisfies_(((participant_or_publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PUBLISHER) || \ - ((participant_or_publisher & DDS_ENTITY_KIND_MASK) == DDS_KIND_PARTICIPANT)) -_Pre_satisfies_((topic & DDS_ENTITY_KIND_MASK) == DDS_KIND_TOPIC) dds_entity_t dds_create_writer( - _In_ dds_entity_t participant_or_publisher, - _In_ dds_entity_t topic, - _In_opt_ const dds_qos_t *qos, - _In_opt_ const dds_listener_t *listener) + dds_entity_t participant_or_publisher, + dds_entity_t topic, + const dds_qos_t *qos, + const dds_listener_t *listener) { - dds__retcode_t rc; + dds_retcode_t rc; dds_qos_t * wqos; dds_writer * wr; dds_entity_t writer; @@ -481,15 +479,15 @@ dds_create_writer( assert(0); } - os_mutexUnlock(&tp->m_entity.m_mutex); - os_mutexUnlock(&pub->m_mutex); + ddsrt_mutex_unlock(&tp->m_entity.m_mutex); + ddsrt_mutex_unlock(&pub->m_mutex); if (asleep) { thread_state_awake(thr); } wr->m_wr = new_writer(&wr->m_entity.m_guid, NULL, &pub->m_participant->m_guid, tp->m_stopic, wqos, wr->m_whc, dds_writer_status_cb, wr); - os_mutexLock(&pub->m_mutex); - os_mutexLock(&tp->m_entity.m_mutex); + ddsrt_mutex_lock(&pub->m_mutex); + ddsrt_mutex_lock(&tp->m_entity.m_mutex); assert(wr->m_wr); if (asleep) { thread_state_asleep(thr); @@ -509,12 +507,9 @@ err_pub_lock: return writer; } - - -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) dds_entity_t dds_get_publisher( - _In_ dds_entity_t writer) + dds_entity_t writer) { dds_entity_t hdl = DDS_RETCODE_OK; @@ -529,13 +524,12 @@ dds_get_publisher( return hdl; } -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) dds_return_t dds_get_publication_matched_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_publication_matched_status_t * status) + dds_entity_t writer, + dds_publication_matched_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; dds_return_t ret = DDS_RETCODE_OK; @@ -559,13 +553,12 @@ fail: return ret; } -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) dds_return_t dds_get_liveliness_lost_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_liveliness_lost_status_t * status) + dds_entity_t writer, + dds_liveliness_lost_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; dds_return_t ret = DDS_RETCODE_OK; @@ -588,13 +581,12 @@ fail: return ret; } -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) dds_return_t dds_get_offered_deadline_missed_status( - _In_ dds_entity_t writer, - _Out_opt_ dds_offered_deadline_missed_status_t *status) + dds_entity_t writer, + dds_offered_deadline_missed_status_t *status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; dds_return_t ret = DDS_RETCODE_OK; @@ -617,13 +609,12 @@ fail: return ret; } -_Pre_satisfies_(((writer & DDS_ENTITY_KIND_MASK) == DDS_KIND_WRITER)) dds_return_t dds_get_offered_incompatible_qos_status ( - _In_ dds_entity_t writer, - _Out_opt_ dds_offered_incompatible_qos_status_t * status) + dds_entity_t writer, + dds_offered_incompatible_qos_status_t * status) { - dds__retcode_t rc; + dds_retcode_t rc; dds_writer *wr; dds_return_t ret = DDS_RETCODE_OK; diff --git a/src/core/ddsc/tests/CMakeLists.txt b/src/core/ddsc/tests/CMakeLists.txt index 5e00360..bd44687 100644 --- a/src/core/ddsc/tests/CMakeLists.txt +++ b/src/core/ddsc/tests/CMakeLists.txt @@ -23,7 +23,6 @@ set(ddsc_test_sources "entity_api.c" "entity_hierarchy.c" "entity_status.c" - "err.c" "file_id.c" "instance_get_key.c" "listener.c" @@ -53,7 +52,7 @@ add_cunit_executable(cunit_ddsc ${ddsc_test_sources}) target_include_directories( cunit_ddsc PRIVATE "$") -target_link_libraries(cunit_ddsc RoundTrip Space TypesArrayKey ddsc OSAPI) +target_link_libraries(cunit_ddsc PRIVATE RoundTrip Space TypesArrayKey ddsc) # Setup environment for config-tests get_test_property(CUnit_ddsc_config_simple_udp ENVIRONMENT CUnit_ddsc_config_simple_udp_env) diff --git a/src/core/ddsc/tests/basic.c b/src/core/ddsc/tests/basic.c index 11b6bd1..b2bb597 100644 --- a/src/core/ddsc/tests/basic.c +++ b/src/core/ddsc/tests/basic.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "CUnit/Test.h" CU_Test(ddsc_basic, test) diff --git a/src/core/ddsc/tests/builtin_topics.c b/src/core/ddsc/tests/builtin_topics.c index 2395a8f..3a63478 100644 --- a/src/core/ddsc/tests/builtin_topics.c +++ b/src/core/ddsc/tests/builtin_topics.c @@ -9,13 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ +#include "dds/dds.h" #include "RoundTrip.h" #include "Space.h" -#include "ddsc/dds.h" -#include "os/os.h" #include "test-common.h" #include "CUnit/Test.h" -#include "CUnit/Theory.h" static dds_entity_t g_participant = 0; static dds_entity_t g_subscriber = 0; diff --git a/src/core/ddsc/tests/config.c b/src/core/ddsc/tests/config.c index 2bd3e49..b751a2c 100644 --- a/src/core/ddsc/tests/config.c +++ b/src/core/ddsc/tests/config.c @@ -9,22 +9,28 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include + +#include "dds/dds.h" #include "CUnit/Test.h" -#include "os/os.h" #include "config_env.h" -#include "ddsc/ddsc_project.h" + +#include "dds/version.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/heap.h" #define FORCE_ENV -#define URI_VARIABLE DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI" +#define URI_VARIABLE DDS_PROJECT_NAME_NOSPACE_CAPS"_URI" #define MAX_PARTICIPANTS_VARIABLE "MAX_PARTICIPANTS" static void config__check_env( - _In_z_ const char * env_variable, - _In_z_ const char * expected_value) + const char * env_variable, + const char * expected_value) { - const char * env_uri = os_getenv(env_variable); + char * env_uri = NULL; + ddsrt_getenv(env_variable, &env_uri); #if 0 const char * const env_not_set = "Environment variable '%s' isn't set. This needs to be set to '%s' for this test to run."; const char * const env_not_as_expected = "Environment variable '%s' has an unexpected value: '%s' (expected: '%s')"; @@ -43,17 +49,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; + dds_retcode_t r; - 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); - - os_free(envstr); + r = ddsrt_setenv(env_variable, expected_value); + CU_ASSERT_EQUAL_FATAL(r, DDS_RETCODE_OK); } } #else @@ -63,7 +62,7 @@ static void config__check_env( } -CU_Test(ddsc_config, simple_udp, .init = os_osInit, .fini = os_osExit) { +CU_Test(ddsc_config, simple_udp, .init = ddsrt_init, .fini = ddsrt_fini) { dds_entity_t participant; diff --git a/src/core/ddsc/tests/dispose.c b/src/core/ddsc/tests/dispose.c index 6701abd..ee504fc 100644 --- a/src/core/ddsc/tests/dispose.c +++ b/src/core/ddsc/tests/dispose.c @@ -9,12 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" -#include "CUnit/Test.h" +#include + +#include "dds/dds.h" #include "CUnit/Theory.h" #include "Space.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -41,9 +45,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -146,9 +150,9 @@ CU_Test(ddsc_writedispose, deleted, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; dds_delete(g_writer); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose(g_writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED); } /*************************************************************************************************/ @@ -157,9 +161,9 @@ CU_Test(ddsc_writedispose, deleted, .init=disposing_init, .fini=disposing_fini) CU_Test(ddsc_writedispose, null, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose(g_writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -173,9 +177,9 @@ CU_Theory((dds_entity_t writer), ddsc_writedispose, invalid_writers, .init=dispo dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1; dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose(writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), dds_err_nr(exp)); } /*************************************************************************************************/ @@ -187,9 +191,9 @@ CU_TheoryDataPoints(ddsc_writedispose, non_writers) = { CU_Theory((dds_entity_t *writer), ddsc_writedispose, non_writers, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose(*writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION); } /*************************************************************************************************/ @@ -303,9 +307,9 @@ CU_Test(ddsc_writedispose_ts, deleted, .init=disposing_init, .fini=disposing_fin { dds_return_t ret; dds_delete(g_writer); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose_ts(g_writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED); } /*************************************************************************************************/ @@ -314,9 +318,9 @@ CU_Test(ddsc_writedispose_ts, deleted, .init=disposing_init, .fini=disposing_fin CU_Test(ddsc_writedispose_ts, null, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose_ts(g_writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -344,9 +348,9 @@ CU_Theory((dds_entity_t writer), ddsc_writedispose_ts, invalid_writers, .init=di dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1; dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose_ts(writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), dds_err_nr(exp)); } /*************************************************************************************************/ @@ -358,9 +362,9 @@ CU_TheoryDataPoints(ddsc_writedispose_ts, non_writers) = { CU_Theory((dds_entity_t *writer), ddsc_writedispose_ts, non_writers, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_writedispose_ts(*writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION); } /*************************************************************************************************/ @@ -503,9 +507,9 @@ CU_Test(ddsc_dispose, deleted, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; dds_delete(g_writer); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose(g_writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED); } /*************************************************************************************************/ @@ -514,9 +518,9 @@ CU_Test(ddsc_dispose, deleted, .init=disposing_init, .fini=disposing_fini) CU_Test(ddsc_dispose, null, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose(g_writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -544,9 +548,9 @@ CU_Theory((dds_entity_t writer), ddsc_dispose, invalid_writers, .init=disposing_ dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1; dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose(writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), dds_err_nr(exp)); } /*************************************************************************************************/ @@ -558,9 +562,9 @@ CU_TheoryDataPoints(ddsc_dispose, non_writers) = { CU_Theory((dds_entity_t *writer), ddsc_dispose, non_writers, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose(*writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION); } /*************************************************************************************************/ @@ -658,9 +662,9 @@ CU_Test(ddsc_dispose_ts, deleted, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; dds_delete(g_writer); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose_ts(g_writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_ON(6387); /* Disable SAL warning on intentional misuse of the API */ CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ALREADY_DELETED); } /*************************************************************************************************/ @@ -669,9 +673,9 @@ CU_Test(ddsc_dispose_ts, deleted, .init=disposing_init, .fini=disposing_fini) CU_Test(ddsc_dispose_ts, null, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose_ts(g_writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -699,9 +703,9 @@ CU_Theory((dds_entity_t writer), ddsc_dispose_ts, invalid_writers, .init=disposi dds_entity_t exp = DDS_RETCODE_BAD_PARAMETER * -1; dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose_ts(writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), dds_err_nr(exp)); } /*************************************************************************************************/ @@ -713,9 +717,9 @@ CU_TheoryDataPoints(ddsc_dispose_ts, non_writers) = { CU_Theory((dds_entity_t *writer), ddsc_dispose_ts, non_writers, .init=disposing_init, .fini=disposing_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_dispose_ts(*writer, NULL, g_present); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_ILLEGAL_OPERATION); } /*************************************************************************************************/ diff --git a/src/core/ddsc/tests/entity_api.c b/src/core/ddsc/tests/entity_api.c index 8ef9421..8befa14 100644 --- a/src/core/ddsc/tests/entity_api.c +++ b/src/core/ddsc/tests/entity_api.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "CUnit/Test.h" /* We are deliberately testing some bad arguments that SAL will complain about. @@ -338,7 +338,7 @@ CU_Test(ddsc_entity, get_entities, .init = create_entity, .fini = delete_entity) CU_Test(ddsc_entity, get_domainid, .init = create_entity, .fini = delete_entity) { dds_return_t status; - dds_domainid_t id; + dds_domainid_t id = -1; /* Check getting ID with bad parameters. */ status = dds_get_domainid (0, NULL); @@ -351,7 +351,7 @@ CU_Test(ddsc_entity, get_domainid, .init = create_entity, .fini = delete_entity) /* Get and check the domain id. */ status = dds_get_domainid (entity, &id); cu_assert_status_eq(status, DDS_RETCODE_OK); - CU_ASSERT_EQUAL_FATAL(id, 0); + CU_ASSERT_FATAL(id != -1); } CU_Test(ddsc_entity, delete, .init = create_entity) diff --git a/src/core/ddsc/tests/entity_hierarchy.c b/src/core/ddsc/tests/entity_hierarchy.c index 822228a..ef2f1f4 100644 --- a/src/core/ddsc/tests/entity_hierarchy.c +++ b/src/core/ddsc/tests/entity_hierarchy.c @@ -9,15 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" +#include + +#include "dds/dds.h" #include "CUnit/Test.h" #include "CUnit/Theory.h" #include "RoundTrip.h" -/* Add --verbose command line argument to get the cr_log_info traces (if there are any). */ - - +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" /************************************************************************************************** * @@ -47,9 +48,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -772,10 +773,10 @@ CU_Test(ddsc_entity_implicit_publisher, invalid_topic) CU_ASSERT_FATAL(participant > 0); /* Disable SAL warning on intentional misuse of the API */ - OS_WARNING_MSVC_OFF(28020); + DDSRT_WARNING_MSVC_OFF(28020); writer = dds_create_writer(participant, 0, NULL, NULL); /* Disable SAL warning on intentional misuse of the API */ - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_FATAL(writer < 0); dds_delete(writer); @@ -826,9 +827,9 @@ CU_Test(ddsc_entity_explicit_subscriber, invalid_topic) subscriber = dds_create_subscriber(participant, NULL,NULL); /* Disable SAL warning on intentional misuse of the API */ - OS_WARNING_MSVC_OFF(28020); + DDSRT_WARNING_MSVC_OFF(28020); reader = dds_create_reader(subscriber, 0, NULL, NULL); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_FATAL(reader < 0); dds_delete(reader); diff --git a/src/core/ddsc/tests/entity_status.c b/src/core/ddsc/tests/entity_status.c index c157f75..f14245f 100644 --- a/src/core/ddsc/tests/entity_status.c +++ b/src/core/ddsc/tests/entity_status.c @@ -9,12 +9,14 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ +#include #include #include "CUnit/Theory.h" -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "RoundTrip.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" /**************************************************************************** * Test globals. @@ -51,9 +53,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } diff --git a/src/core/ddsc/tests/err.c b/src/core/ddsc/tests/err.c deleted file mode 100644 index 09700f6..0000000 --- a/src/core/ddsc/tests/err.c +++ /dev/null @@ -1,32 +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 - */ -#include "ddsc/dds.h" -#include "CUnit/Test.h" - -CU_Test(ddsc_err, str) -{ - CU_ASSERT_STRING_EQUAL(dds_err_str(1 ), "Success"); - CU_ASSERT_STRING_EQUAL(dds_err_str(-255 ), "Unknown"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_OK * -1), "Success"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_ERROR * -1), "Error"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_UNSUPPORTED * -1), "Unsupported"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_BAD_PARAMETER * -1), "Bad Parameter"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_PRECONDITION_NOT_MET * -1), "Precondition Not Met"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_OUT_OF_RESOURCES * -1), "Out Of Resources"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_NOT_ENABLED * -1), "Not Enabled"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_IMMUTABLE_POLICY * -1), "Immutable Policy"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_INCONSISTENT_POLICY * -1), "Inconsistent Policy"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_ALREADY_DELETED * -1), "Already Deleted"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_TIMEOUT * -1), "Timeout"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_NO_DATA * -1), "No Data"); - CU_ASSERT_STRING_EQUAL(dds_err_str(DDS_RETCODE_ILLEGAL_OPERATION * -1), "Illegal Operation"); -} diff --git a/src/core/ddsc/tests/file_id.c b/src/core/ddsc/tests/file_id.c index dee2849..a2ce5b8 100644 --- a/src/core/ddsc/tests/file_id.c +++ b/src/core/ddsc/tests/file_id.c @@ -9,9 +9,10 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "CUnit/Test.h" -#include "os/os.h" + +#include "dds/ddsrt/misc.h" CU_Test(ddsc_err, unique_file_id) { @@ -21,14 +22,14 @@ CU_Test(ddsc_err, unique_file_id) CU_ASSERT_FATAL(participant > 0); /* Disable SAL warning on intentional misuse of the API */ - OS_WARNING_MSVC_OFF(28020); + DDSRT_WARNING_MSVC_OFF(28020); reader = dds_create_reader(0, 0, NULL, NULL); CU_ASSERT_FATAL(reader < 0); writer = dds_create_writer(0, 0, NULL, NULL); CU_ASSERT_FATAL(writer < 0); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_NOT_EQUAL_FATAL(dds_err_file_id(reader), dds_err_file_id(writer)); diff --git a/src/core/ddsc/tests/instance_get_key.c b/src/core/ddsc/tests/instance_get_key.c index aaa0f9a..48bd0d3 100644 --- a/src/core/ddsc/tests/instance_get_key.c +++ b/src/core/ddsc/tests/instance_get_key.c @@ -12,10 +12,10 @@ #include #include #include -#include "CUnit/Test.h" -#include "os/os.h" -#include "ddsc/dds.h" +#include "CUnit/Test.h" +#include "dds/dds.h" +#include "dds/ddsrt/string.h" #include "RoundTrip.h" static dds_entity_t participant = DDS_ENTITY_NIL; @@ -42,7 +42,7 @@ static void setup(void) CU_ASSERT_FATAL(writer > 0); memset(&data, 0, sizeof(data)); - data.ip = os_strdup("some data"); + data.ip = ddsrt_strdup("some data"); CU_ASSERT_PTR_NOT_NULL_FATAL(data.ip); data.port = 1; } diff --git a/src/core/ddsc/tests/listener.c b/src/core/ddsc/tests/listener.c index 4eba4d1..e3f5c65 100644 --- a/src/core/ddsc/tests/listener.c +++ b/src/core/ddsc/tests/listener.c @@ -9,20 +9,23 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "RoundTrip.h" #include "CUnit/Test.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" + /**************************************************************************** - * TODO: (CHAM-279) Add DDS_INCONSISTENT_TOPIC_STATUS test - * TODO: (CHAM-277) Add DDS_OFFERED/REQUESTED_DEADLINE_MISSED_STATUS test - * TODO: (CHAM-278) Add DDS_LIVELINESS_LOST_STATUS test + * TODO: Add DDS_INCONSISTENT_TOPIC_STATUS test + * TODO: Add DDS_OFFERED/REQUESTED_DEADLINE_MISSED_STATUS test + * TODO: Add DDS_LIVELINESS_LOST_STATUS test * TODO: Check DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS intermittent fail (total_count != 1) ****************************************************************************/ - - /**************************************************************************** * Convenience test macros. ****************************************************************************/ @@ -68,8 +71,8 @@ static dds_entity_t g_reader = 0; static dds_listener_t *g_listener = NULL; static dds_qos_t *g_qos = NULL; -static os_mutex g_mutex; -static os_cond g_cond; +static ddsrt_mutex_t g_mutex; +static ddsrt_cond_t g_cond; @@ -101,12 +104,12 @@ inconsistent_topic_cb( const dds_inconsistent_topic_status_t status, void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_topic = topic; cb_inconsistent_topic_status = status; cb_called |= DDS_INCONSISTENT_TOPIC_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -116,12 +119,12 @@ liveliness_lost_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_writer = writer; cb_liveliness_lost_status = status; cb_called |= DDS_LIVELINESS_LOST_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -131,12 +134,12 @@ offered_deadline_missed_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_writer = writer; cb_offered_deadline_missed_status = status; cb_called |= DDS_OFFERED_DEADLINE_MISSED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -146,12 +149,12 @@ offered_incompatible_qos_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_writer = writer; cb_offered_incompatible_qos_status = status; cb_called |= DDS_OFFERED_INCOMPATIBLE_QOS_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -160,11 +163,11 @@ data_on_readers_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_subscriber = subscriber; cb_called |= DDS_DATA_ON_READERS_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -174,12 +177,12 @@ sample_lost_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_sample_lost_status = status; cb_called |= DDS_SAMPLE_LOST_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -188,11 +191,11 @@ data_available_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_called |= DDS_DATA_AVAILABLE_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -202,12 +205,12 @@ sample_rejected_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_sample_rejected_status = status; cb_called |= DDS_SAMPLE_REJECTED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -217,12 +220,12 @@ liveliness_changed_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_liveliness_changed_status = status; cb_called |= DDS_LIVELINESS_CHANGED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -232,12 +235,12 @@ requested_deadline_missed_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_requested_deadline_missed_status = status; cb_called |= DDS_REQUESTED_DEADLINE_MISSED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -247,12 +250,12 @@ requested_incompatible_qos_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_requested_incompatible_qos_status = status; cb_called |= DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -262,12 +265,12 @@ publication_matched_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_writer = writer; cb_publication_matched_status = status; cb_called |= DDS_PUBLICATION_MATCHED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -277,12 +280,12 @@ subscription_matched_cb( void* arg) { (void)arg; - os_mutexLock(&g_mutex); + ddsrt_mutex_lock(&g_mutex); cb_reader = reader; cb_subscription_matched_status = status; cb_called |= DDS_SUBSCRIPTION_MATCHED_STATUS; - os_condBroadcast(&g_cond); - os_mutexUnlock(&g_mutex); + ddsrt_cond_broadcast(&g_cond); + ddsrt_mutex_unlock(&g_mutex); } static void @@ -293,13 +296,13 @@ callback_dummy(void) static uint32_t waitfor_cb(uint32_t expected) { - os_time timeout = { 5, 0 }; - os_result osr = os_resultSuccess; - os_mutexLock(&g_mutex); - while (((cb_called & expected) != expected) && (osr == os_resultSuccess)) { - osr = os_condTimedWait(&g_cond, &g_mutex, &timeout); + dds_time_t timeout = 5 * DDS_NSECS_IN_SEC; + bool signalled = true; + ddsrt_mutex_lock(&g_mutex); + while (((cb_called & expected) != expected) && (signalled)) { + signalled = ddsrt_cond_waitfor(&g_cond, &g_mutex, timeout); } - os_mutexUnlock(&g_mutex); + ddsrt_mutex_unlock(&g_mutex); return cb_called; } @@ -312,9 +315,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -323,10 +326,10 @@ init_triggering_base(void) { char name[100]; - os_osInit(); + ddsrt_init(); - os_mutexInit(&g_mutex); - os_condInit(&g_cond, &g_mutex); + ddsrt_mutex_init(&g_mutex); + ddsrt_cond_init(&g_cond); g_participant = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL); CU_ASSERT_FATAL(g_participant > 0); @@ -347,6 +350,8 @@ init_triggering_base(void) CU_ASSERT_PTR_NOT_NULL_FATAL(g_qos); dds_qset_reliability(g_qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(1)); dds_qset_history(g_qos, DDS_HISTORY_KEEP_ALL, 0); + + cb_called = 0; } static void @@ -386,9 +391,9 @@ fini_triggering_base(void) dds_delete_qos(g_qos); dds_delete_listener(g_listener); dds_delete(g_participant); - os_condDestroy(&g_cond); - os_mutexDestroy(&g_mutex); - os_osExit(); + ddsrt_cond_destroy(&g_cond); + ddsrt_mutex_destroy(&g_mutex); + ddsrt_fini(); } static void @@ -426,9 +431,9 @@ CU_Test(ddsc_listener, create_and_delete) ASSERT_CALLBACK_EQUAL(data_available, listener, DDS_LUNSET); dds_delete_listener(listener); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ dds_delete_listener(NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); } CU_Test(ddsc_listener, reset) @@ -475,11 +480,11 @@ CU_Test(ddsc_listener, copy) ASSERT_CALLBACK_EQUAL(sample_lost, listener2, sample_lost_cb); /* Calling copy with NULL should not crash and be noops. */ - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ dds_copy_listener(listener2, NULL); dds_copy_listener(NULL, listener1); dds_copy_listener(NULL, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); dds_delete_listener(listener1); dds_delete_listener(listener2); @@ -568,7 +573,7 @@ CU_Test(ddsc_listener, getters_setters) dds_listener_t *listener = dds_create_listener(NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(listener); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ \ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ \ TEST_GET_SET(listener, inconsistent_topic, inconsistent_topic_cb); TEST_GET_SET(listener, liveliness_lost, liveliness_lost_cb); TEST_GET_SET(listener, offered_deadline_missed, offered_deadline_missed_cb); @@ -582,7 +587,7 @@ CU_Test(ddsc_listener, getters_setters) TEST_GET_SET(listener, publication_matched, publication_matched_cb); TEST_GET_SET(listener, subscription_matched, subscription_matched_cb); TEST_GET_SET(listener, data_available, data_available_cb); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); dds_delete_listener(listener); } @@ -1013,8 +1018,8 @@ Test(ddsc_listener, inconsistent_topic, .init=init_triggering_base, .fini=fini_t os_osInit(); - os_mutexInit(&g_mutex); - os_condInit(&g_cond, &g_mutex); + ddsrt_mutex_init(&g_mutex); + ddsrt_cond_init(&g_cond); g_qos = dds_create_qos(); cr_assert_not_null(g_qos, "Failed to create prerequisite g_qos"); diff --git a/src/core/ddsc/tests/participant.c b/src/core/ddsc/tests/participant.c index 2a68be0..14a8171 100644 --- a/src/core/ddsc/tests/participant.c +++ b/src/core/ddsc/tests/participant.c @@ -9,12 +9,13 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "CUnit/Test.h" -#include -#include "config_env.h" -#include "ddsc/ddsc_project.h" +#include +#include "dds/dds.h" +#include "CUnit/Test.h" +#include "config_env.h" +#include "dds/version.h" +#include "dds/ddsrt/environ.h" #define cu_assert_status_eq(s1, s2) CU_ASSERT_EQUAL_FATAL(dds_err_nr(s1), s2) @@ -41,14 +42,14 @@ CU_Test(ddsc_participant, create_and_delete) { /* Test for creating participant with no configuration file */ -CU_Test(ddsc_participant, create_with_no_conf_no_env) { +CU_Test(ddsc_participant, create_with_no_conf_no_env) +{ dds_entity_t participant, participant2, participant3; dds_return_t status; dds_domainid_t domain_id; dds_domainid_t valid_domain=3; - const char * env_uri = os_getenv(DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI"); - CU_ASSERT_EQUAL_FATAL(env_uri, NULL); + ddsrt_unsetenv(DDS_PROJECT_NAME_NOSPACE_CAPS"_URI"); //invalid domain participant = dds_create_participant (-2, NULL, NULL); @@ -70,8 +71,6 @@ CU_Test(ddsc_participant, create_with_no_conf_no_env) { dds_delete(participant2); dds_delete(participant3); - - } @@ -84,17 +83,12 @@ CU_Test(ddsc_participant, create_with_conf_no_env) { dds_domainid_t domain_id; dds_domainid_t valid_domain=3; - static char env_uri_str[1000]; - (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); + ddsrt_setenv(DDS_PROJECT_NAME_NOSPACE_CAPS"_URI", CONFIG_ENV_SIMPLE_UDP); + ddsrt_setenv("MAX_PARTICIPANTS", CONFIG_ENV_MAX_PARTICIPANTS); - static char env_mp_str[100]; - (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"); - CU_ASSERT_NOT_EQUAL_FATAL(env_uri, NULL); + char * env_uri = NULL; + ddsrt_getenv(DDS_PROJECT_NAME_NOSPACE_CAPS"_URI", &env_uri); + CU_ASSERT_PTR_NOT_EQUAL_FATAL(env_uri, NULL); //invalid domain participant = dds_create_participant (1, NULL, NULL); diff --git a/src/core/ddsc/tests/publisher.c b/src/core/ddsc/tests/publisher.c index a136e7c..5ea49d3 100644 --- a/src/core/ddsc/tests/publisher.c +++ b/src/core/ddsc/tests/publisher.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "CUnit/Test.h" /* We are deliberately testing some bad arguments that SAL will complain about. diff --git a/src/core/ddsc/tests/qos.c b/src/core/ddsc/tests/qos.c index efadd3b..a947390 100644 --- a/src/core/ddsc/tests/qos.c +++ b/src/core/ddsc/tests/qos.c @@ -10,16 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "CUnit/Test.h" -#include "ddsc/dds.h" -#include "os/os.h" - -/* We are deliberately testing some bad arguments that SAL will complain about. - * So, silence SAL regarding these issues. */ -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 6387 28020) -#endif - +#include "dds/dds.h" /**************************************************************************** * Convenience global policies @@ -655,6 +646,3 @@ CU_Test(ddsc_qos, durability_service, .init=qos_init, .fini=qos_fini) CU_ASSERT_EQUAL_FATAL(p.max_samples_per_instance, g_pol_durability_service.max_samples_per_instance); } -#ifdef _MSC_VER -#pragma warning(pop) -#endif diff --git a/src/core/ddsc/tests/querycondition.c b/src/core/ddsc/tests/querycondition.c index df6cf8c..1638a79 100644 --- a/src/core/ddsc/tests/querycondition.c +++ b/src/core/ddsc/tests/querycondition.c @@ -9,12 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" -#include "CUnit/Test.h" +#include + +#include "dds/dds.h" #include "CUnit/Theory.h" #include "Space.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -68,9 +72,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -305,9 +309,9 @@ CU_Test(ddsc_querycondition_get_mask, null, .init=querycondition_init, .fini=que dds_return_t ret; condition = dds_create_querycondition(g_reader, mask, filter_mod2); CU_ASSERT_FATAL(condition > 0); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_get_mask(condition, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); dds_delete(condition); } diff --git a/src/core/ddsc/tests/read_instance.c b/src/core/ddsc/tests/read_instance.c index c99b97f..7ef1384 100644 --- a/src/core/ddsc/tests/read_instance.c +++ b/src/core/ddsc/tests/read_instance.c @@ -10,13 +10,16 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "ddsc/dds.h" -#include "os/os.h" +#include + +#include "dds/dds.h" #include "Space.h" #include "RoundTrip.h" -#include "CUnit/Test.h" #include "CUnit/Theory.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -68,9 +71,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } diff --git a/src/core/ddsc/tests/readcondition.c b/src/core/ddsc/tests/readcondition.c index b1f0688..534f51c 100644 --- a/src/core/ddsc/tests/readcondition.c +++ b/src/core/ddsc/tests/readcondition.c @@ -9,12 +9,15 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "CUnit/Test.h" #include "CUnit/Theory.h" #include "Space.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -61,9 +64,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -288,9 +291,9 @@ CU_Test(ddsc_readcondition_get_mask, null, .init=readcondition_init, .fini=readc dds_return_t ret; condition = dds_create_readcondition(g_reader, mask); CU_ASSERT_FATAL(condition > 0); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_get_mask(condition, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); dds_delete(condition); } diff --git a/src/core/ddsc/tests/reader.c b/src/core/ddsc/tests/reader.c index 11f370a..4698172 100644 --- a/src/core/ddsc/tests/reader.c +++ b/src/core/ddsc/tests/reader.c @@ -10,14 +10,17 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "Space.h" #include "RoundTrip.h" -#include "CUnit/Test.h" #include "CUnit/Theory.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -65,9 +68,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -234,9 +237,9 @@ CU_Test(ddsc_reader_create, invalid_qos_participant, .init=reader_init, .fini=re dds_entity_t rdr; dds_qos_t *qos = dds_create_qos(); /* Set invalid reader data lifecycle policy */ - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ dds_qset_reader_data_lifecycle(qos, DDS_SECS(-1), DDS_SECS(-1)); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); rdr = dds_create_reader(g_participant, g_topic, qos, NULL); CU_ASSERT_EQUAL_FATAL(dds_err_nr(rdr), DDS_RETCODE_INCONSISTENT_POLICY); dds_delete_qos(qos); @@ -249,9 +252,9 @@ CU_Test(ddsc_reader_create, invalid_qos_subscriber, .init=reader_init, .fini=rea dds_entity_t rdr; dds_qos_t *qos = dds_create_qos(); /* Set invalid reader data lifecycle policy */ - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ dds_qset_reader_data_lifecycle(qos, DDS_SECS(-1), DDS_SECS(-1)); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); rdr = dds_create_reader(g_subscriber, g_topic, qos, NULL); CU_ASSERT_EQUAL_FATAL(dds_err_nr(rdr), DDS_RETCODE_INCONSISTENT_POLICY); dds_delete_qos(qos); diff --git a/src/core/ddsc/tests/reader_iterator.c b/src/core/ddsc/tests/reader_iterator.c index 10222d0..7a840ca 100644 --- a/src/core/ddsc/tests/reader_iterator.c +++ b/src/core/ddsc/tests/reader_iterator.c @@ -10,14 +10,16 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "Space.h" #include "RoundTrip.h" -#include "CUnit/Test.h" #include "CUnit/Theory.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -85,9 +87,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } diff --git a/src/core/ddsc/tests/register.c b/src/core/ddsc/tests/register.c index 1f17370..a075ae5 100644 --- a/src/core/ddsc/tests/register.c +++ b/src/core/ddsc/tests/register.c @@ -11,12 +11,14 @@ */ #include -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "CUnit/Test.h" #include "CUnit/Theory.h" #include "Space.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" /************************************************************************************************** * @@ -43,9 +45,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -164,9 +166,9 @@ CU_Theory((dds_instance_handle_t *hndl2, void *datap), ddsc_register_instance, i /* Only test when the combination of parameters is actually invalid.*/ CU_ASSERT_FATAL((hndl2 == NULL) || (datap == NULL)); - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_register_instance(g_writer, hndl2, datap); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_BAD_PARAMETER); } diff --git a/src/core/ddsc/tests/return_loan.c b/src/core/ddsc/tests/return_loan.c index e031406..365ea76 100644 --- a/src/core/ddsc/tests/return_loan.c +++ b/src/core/ddsc/tests/return_loan.c @@ -9,9 +9,8 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" -#include "os/os.h" #include #include "CUnit/Test.h" diff --git a/src/core/ddsc/tests/subscriber.c b/src/core/ddsc/tests/subscriber.c index 6dd2786..7e881d1 100644 --- a/src/core/ddsc/tests/subscriber.c +++ b/src/core/ddsc/tests/subscriber.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" #include #include "CUnit/Test.h" diff --git a/src/core/ddsc/tests/take_instance.c b/src/core/ddsc/tests/take_instance.c index cef8252..d9ef401 100644 --- a/src/core/ddsc/tests/take_instance.c +++ b/src/core/ddsc/tests/take_instance.c @@ -10,14 +10,16 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "Space.h" #include "RoundTrip.h" -#include "CUnit/Test.h" #include "CUnit/Theory.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -69,9 +71,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } diff --git a/src/core/ddsc/tests/test-common.c b/src/core/ddsc/tests/test-common.c index 8f2dc4c..44b846f 100644 --- a/src/core/ddsc/tests/test-common.c +++ b/src/core/ddsc/tests/test-common.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" +#include "dds/dds.h" const char* entity_kind_str(dds_entity_t ent) { diff --git a/src/core/ddsc/tests/time.c b/src/core/ddsc/tests/time.c index d7c6dba..8b28576 100644 --- a/src/core/ddsc/tests/time.c +++ b/src/core/ddsc/tests/time.c @@ -10,7 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "CUnit/Test.h" -#include "ddsc/dds.h" +#include "dds/dds.h" CU_Test(ddsc_time, request_time) { diff --git a/src/core/ddsc/tests/topic.c b/src/core/ddsc/tests/topic.c index aff59d6..665d38d 100644 --- a/src/core/ddsc/tests/topic.c +++ b/src/core/ddsc/tests/topic.c @@ -9,12 +9,14 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "RoundTrip.h" -#include "CUnit/Test.h" #include "CUnit/Theory.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" + /************************************************************************************************** * * Test fixtures @@ -38,9 +40,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -102,9 +104,9 @@ CU_Test(ddsc_topic_create, invalid_qos, .init=ddsc_topic_init, .fini=ddsc_topic_ { dds_entity_t topic; dds_qos_t *qos = dds_create_qos(); - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ dds_qset_lifespan(qos, DDS_SECS(-1)); - OS_WARNING_MSVC_OFF(28020); + DDSRT_WARNING_MSVC_OFF(28020); topic = dds_create_topic(g_participant, &RoundTripModule_DataType_desc, "inconsistent", qos, NULL); CU_ASSERT_EQUAL_FATAL(dds_err_nr(topic), DDS_RETCODE_INCONSISTENT_POLICY); dds_delete_qos(qos); @@ -164,9 +166,9 @@ CU_Test(ddsc_topic_create, recreate, .init=ddsc_topic_init, .fini=ddsc_topic_fin CU_Test(ddsc_topic_create, desc_null, .init=ddsc_topic_init, .fini=ddsc_topic_fini) { dds_entity_t topic; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ topic = dds_create_topic (g_participant, NULL, "desc_null", NULL, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(topic), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -219,9 +221,9 @@ CU_Test(ddsc_topic_find, non_participants, .init=ddsc_topic_init, .fini=ddsc_top CU_Test(ddsc_topic_find, null, .init=ddsc_topic_init, .fini=ddsc_topic_fini) { dds_entity_t topic; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ topic = dds_find_topic(g_participant, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(topic), DDS_RETCODE_BAD_PARAMETER); } /*************************************************************************************************/ @@ -411,9 +413,9 @@ CU_Test(ddsc_topic_set_qos, valid, .init=ddsc_topic_init, .fini=ddsc_topic_fini) CU_Test(ddsc_topic_set_qos, inconsistent, .init=ddsc_topic_init, .fini=ddsc_topic_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ dds_qset_lifespan(g_qos, DDS_SECS(-1)); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); ret = dds_set_qos(g_topicRtmDataType, g_qos); CU_ASSERT_EQUAL_FATAL(dds_err_nr(ret), DDS_RETCODE_INCONSISTENT_POLICY); } diff --git a/src/core/ddsc/tests/transientlocal.c b/src/core/ddsc/tests/transientlocal.c index 6dba616..d487a25 100644 --- a/src/core/ddsc/tests/transientlocal.c +++ b/src/core/ddsc/tests/transientlocal.c @@ -10,7 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "ddsc/dds.h" +#include "dds/dds.h" #include "Space.h" #include "CUnit/Test.h" diff --git a/src/core/ddsc/tests/types.c b/src/core/ddsc/tests/types.c index 4588a1e..a2f6c28 100644 --- a/src/core/ddsc/tests/types.c +++ b/src/core/ddsc/tests/types.c @@ -10,7 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "CUnit/Test.h" -#include "ddsc/dds.h" +#include "dds/dds.h" #include "TypesArrayKey.h" diff --git a/src/core/ddsc/tests/unregister.c b/src/core/ddsc/tests/unregister.c index 370b4dc..c79cb9a 100644 --- a/src/core/ddsc/tests/unregister.c +++ b/src/core/ddsc/tests/unregister.c @@ -10,13 +10,15 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include -#include "ddsc/dds.h" -#include "os/os.h" +#include "dds/dds.h" #include "CUnit/Test.h" #include "CUnit/Theory.h" #include "Space.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" /************************************************************************************************** * @@ -43,9 +45,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } diff --git a/src/core/ddsc/tests/unsupported.c b/src/core/ddsc/tests/unsupported.c index b07ac10..2a15f25 100644 --- a/src/core/ddsc/tests/unsupported.c +++ b/src/core/ddsc/tests/unsupported.c @@ -12,7 +12,7 @@ #include #include "CUnit/Test.h" -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" #include "test-common.h" diff --git a/src/core/ddsc/tests/waitset.c b/src/core/ddsc/tests/waitset.c index 0a64ab7..24c9954 100644 --- a/src/core/ddsc/tests/waitset.c +++ b/src/core/ddsc/tests/waitset.c @@ -10,13 +10,18 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include -#include "ddsc/dds.h" -#include "os/os.h" -#include "CUnit/Test.h" +#include "dds/dds.h" #include "CUnit/Theory.h" #include "RoundTrip.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsrt/time.h" + /************************************************************************************************** * * Some thread related convenience stuff. @@ -30,7 +35,7 @@ typedef enum thread_state_t { } thread_state_t; typedef struct thread_arg_t { - os_threadId tid; + ddsrt_thread_t tid; thread_state_t state; dds_entity_t expected; } thread_arg_t; @@ -61,9 +66,9 @@ static char* create_topic_name(const char *prefix, char *name, size_t size) { /* Get semi random g_topic name. */ - os_procId pid = os_getpid(); - uintmax_t tid = os_threadIdToInteger(os_threadIdSelf()); - (void) snprintf(name, size, "%s_pid%"PRIprocId"_tid%"PRIuMAX"", prefix, pid, tid); + ddsrt_pid_t pid = ddsrt_getpid(); + ddsrt_tid_t tid = ddsrt_gettid(); + (void) snprintf(name, size, "%s_pid%"PRIdPID"_tid%"PRIdTID"", prefix, pid, tid); return name; } @@ -93,7 +98,7 @@ ddsc_waitset_init(void) uint32_t mask = DDS_ANY_SAMPLE_STATE | DDS_ANY_VIEW_STATE | DDS_ANY_INSTANCE_STATE; char name[100]; - os_osInit(); + ddsrt_init(); ddsc_waitset_basic_init(); @@ -128,7 +133,7 @@ ddsc_waitset_fini(void) dds_delete(publisher); dds_delete(subscriber); ddsc_waitset_basic_fini(); - os_osExit(); + ddsrt_fini(); } static void @@ -823,9 +828,9 @@ CU_Theory((size_t size), ddsc_waitset_get_entities, array_sizes, .init=ddsc_wait CU_Test(ddsc_waitset_get_entities, no_array, .init=ddsc_waitset_attached_init, .fini=ddsc_waitset_attached_fini) { dds_return_t ret; - OS_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(6387); /* Disable SAL warning on intentional misuse of the API */ ret = dds_waitset_get_entities(waitset, NULL, 1); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); /* ddsc_waitset_attached_init attached 7 entities. */ CU_ASSERT_EQUAL_FATAL(ret, 7); } @@ -1068,41 +1073,41 @@ waiting_thread(void *a) return 0; } -static os_result +static dds_retcode_t thread_reached_state(thread_state_t *actual, thread_state_t expected, int32_t msec) { /* Convenience function. */ - os_time msec10 = { 0, 10000000 }; + dds_time_t msec10 = DDS_MSECS(10); while ((msec > 0) && (*actual != expected)) { - os_nanoSleep(msec10); + dds_sleepfor(msec10); msec -= 10; } - return (*actual == expected) ? os_resultSuccess : os_resultTimeout; + return (*actual == expected) ? DDS_RETCODE_OK : DDS_RETCODE_TIMEOUT; } static void waiting_thread_start(struct thread_arg_t *arg, dds_entity_t expected) { - os_threadId thread_id; - os_threadAttr thread_attr; - os_result osr; + ddsrt_thread_t thread_id; + ddsrt_threadattr_t thread_attr; + dds_retcode_t rc; assert(arg); /* Create an other thread that will blocking wait on the waitset. */ arg->expected = expected; arg->state = STARTING; - os_threadAttrInit(&thread_attr); - osr = os_threadCreate(&thread_id, "waiting_thread", &thread_attr, waiting_thread, arg); - CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess); + ddsrt_threadattr_init(&thread_attr); + rc = ddsrt_thread_create(&thread_id, "waiting_thread", &thread_attr, waiting_thread, arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); /* The thread should reach 'waiting' state. */ - osr = thread_reached_state(&(arg->state), WAITING, 1000); - CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess); + rc = thread_reached_state(&(arg->state), WAITING, 1000); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); /* But thread should block and thus NOT reach 'stopped' state. */ - osr = thread_reached_state(&(arg->state), STOPPED, 100); - CU_ASSERT_EQUAL_FATAL(osr, os_resultTimeout); + rc = thread_reached_state(&(arg->state), STOPPED, 100); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_TIMEOUT); arg->tid = thread_id; } @@ -1110,11 +1115,11 @@ waiting_thread_start(struct thread_arg_t *arg, dds_entity_t expected) static dds_return_t waiting_thread_expect_exit(struct thread_arg_t *arg) { - os_result osr; + dds_retcode_t rc; assert(arg); - osr = thread_reached_state(&(arg->state), STOPPED, 5000); - if (osr == os_resultSuccess) { - os_threadWaitExit(arg->tid, NULL); + rc = thread_reached_state(&(arg->state), STOPPED, 5000); + if (rc == DDS_RETCODE_OK) { + ddsrt_thread_join(arg->tid, NULL); return DDS_RETCODE_OK; } return DDS_RETCODE_TIMEOUT; diff --git a/src/core/ddsc/tests/write.c b/src/core/ddsc/tests/write.c index a67814b..93dae69 100644 --- a/src/core/ddsc/tests/write.c +++ b/src/core/ddsc/tests/write.c @@ -10,12 +10,12 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "CUnit/Test.h" + #include "CUnit/Theory.h" -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" #include "Space.h" -#include "os/os.h" +#include "dds/ddsrt/misc.h" /* Tests in this file only concern themselves with very basic api tests of dds_write and dds_write_ts */ @@ -73,9 +73,9 @@ CU_Test(ddsc_write, null_writer, .init = setup, .fini = teardown) dds_return_t status; /* Disable warning related to improper API usage by passing incompatible parameter. */ - OS_WARNING_MSVC_OFF(28020); + DDSRT_WARNING_MSVC_OFF(28020); status = dds_write(0, &data); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_EQUAL_FATAL(dds_err_nr(status), DDS_RETCODE_BAD_PARAMETER); } @@ -103,9 +103,9 @@ CU_Test(ddsc_write, null_sample, .init = setup, .fini = teardown) dds_return_t status; /* Disable warning related to improper API usage by passing NULL to a non-NULL parameter. */ - OS_WARNING_MSVC_OFF(6387); + DDSRT_WARNING_MSVC_OFF(6387); status = dds_write(writer, NULL); - OS_WARNING_MSVC_ON(6387); + DDSRT_WARNING_MSVC_ON(6387); CU_ASSERT_EQUAL_FATAL(dds_err_nr(status), DDS_RETCODE_BAD_PARAMETER); } diff --git a/src/core/ddsc/tests/writer.c b/src/core/ddsc/tests/writer.c index 025413a..f738ddb 100644 --- a/src/core/ddsc/tests/writer.c +++ b/src/core/ddsc/tests/writer.c @@ -10,10 +10,11 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include + #include "CUnit/Test.h" -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" -#include "os/os.h" +#include "dds/ddsrt/misc.h" static dds_entity_t participant = 0; static dds_entity_t topic = 0; @@ -53,9 +54,9 @@ CU_Test(ddsc_create_writer, basic, .init = setup, .fini = teardown) CU_Test(ddsc_create_writer, null_parent, .init = setup, .fini = teardown) { - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ writer = dds_create_writer(0, topic, NULL, NULL); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_EQUAL_FATAL(dds_err_nr(writer), DDS_RETCODE_BAD_PARAMETER); } @@ -87,9 +88,9 @@ CU_Test(ddsc_create_writer, deleted_publisher, .init = setup, .fini = teardown) CU_Test(ddsc_create_writer, null_topic, .init = setup, .fini = teardown) { - OS_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ + DDSRT_WARNING_MSVC_OFF(28020); /* Disable SAL warning on intentional misuse of the API */ writer = dds_create_writer(publisher, 0, NULL, NULL); - OS_WARNING_MSVC_ON(28020); + DDSRT_WARNING_MSVC_ON(28020); CU_ASSERT_EQUAL_FATAL(dds_err_nr(writer), DDS_RETCODE_BAD_PARAMETER); } diff --git a/src/core/ddsi/CMakeLists.txt b/src/core/ddsi/CMakeLists.txt index 74d2421..29725a1 100644 --- a/src/core/ddsi/CMakeLists.txt +++ b/src/core/ddsi/CMakeLists.txt @@ -64,7 +64,7 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src" # The includes should reside close to the code. As long as that's not the case, # pull them in from this CMakeLists.txt. -PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi" +PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/dds/ddsi" ddsi_ssl.h ddsi_tcp.h ddsi_tran.h @@ -124,11 +124,7 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/ddsi" ) target_sources(ddsc - PRIVATE - ${srcs_ddsi} - ${hdrs_private_ddsi} -) + PRIVATE ${srcs_ddsi} ${hdrs_private_ddsi}) target_include_directories(ddsc - PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/include") + PRIVATE "${CMAKE_CURRENT_LIST_DIR}/include") diff --git a/src/core/ddsi/include/ddsi/ddsi_iid.h b/src/core/ddsi/include/dds/ddsi/ddsi_iid.h similarity index 82% rename from src/core/ddsi/include/ddsi/ddsi_iid.h rename to src/core/ddsi/include/dds/ddsi/ddsi_iid.h index 8ca925d..65ecf90 100644 --- a/src/core/ddsi/include/ddsi/ddsi_iid.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_iid.h @@ -12,18 +12,19 @@ #ifndef _DDS_IID_H_ #define _DDS_IID_H_ -#include "os/os.h" -#include "ddsc/dds_export.h" +#include "dds/export.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/sync.h" #if defined (__cplusplus) extern "C" { #endif struct ddsi_iid { -#if OS_ATOMIC64_SUPPORT - os_atomic_uint64_t counter; +#if DDSRT_ATOMIC64_SUPPORT + ddsrt_atomic_uint64_t counter; #else - os_mutex lock; + ddsrt_mutex_t lock; uint64_t counter; #endif uint32_t key[4]; diff --git a/src/core/ddsi/include/ddsi/ddsi_ipaddr.h b/src/core/ddsi/include/dds/ddsi/ddsi_ipaddr.h similarity index 75% rename from src/core/ddsi/include/ddsi/ddsi_ipaddr.h rename to src/core/ddsi/include/dds/ddsi/ddsi_ipaddr.h index 35bdc44..3bc6f2f 100644 --- a/src/core/ddsi/include/ddsi/ddsi_ipaddr.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_ipaddr.h @@ -12,13 +12,13 @@ #ifndef DDSI_IPADDR_H #define DDSI_IPADDR_H -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tran.h" enum ddsi_nearby_address_result ddsi_ipaddr_is_nearby_address (ddsi_tran_factory_t tran, const nn_locator_t *loc, size_t ninterf, const struct nn_interface interf[]); 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 ddsi_ipaddr_compare (const os_sockaddr *const sa1, const os_sockaddr *const sa2); +int ddsi_ipaddr_compare (const struct sockaddr *const sa1, const struct sockaddr *const sa2); char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_dst, const nn_locator_t *loc, int with_port); -void ddsi_ipaddr_to_loc (nn_locator_t *dst, const os_sockaddr *src, int32_t kind); -void ddsi_ipaddr_from_loc (os_sockaddr_storage *dst, const nn_locator_t *src); +void ddsi_ipaddr_to_loc (nn_locator_t *dst, const struct sockaddr *src, int32_t kind); +void ddsi_ipaddr_from_loc (struct sockaddr_storage *dst, const nn_locator_t *src); #endif diff --git a/src/core/ddsi/include/ddsi/ddsi_mcgroup.h b/src/core/ddsi/include/dds/ddsi/ddsi_mcgroup.h similarity index 96% rename from src/core/ddsi/include/ddsi/ddsi_mcgroup.h rename to src/core/ddsi/include/dds/ddsi/ddsi_mcgroup.h index 176f01f..018237a 100644 --- a/src/core/ddsi/include/ddsi/ddsi_mcgroup.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_mcgroup.h @@ -12,7 +12,7 @@ #ifndef DDSI_MCGROUP_H #define DDSI_MCGROUP_H -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tran.h" struct nn_group_membership; diff --git a/src/core/ddsi/include/ddsi/ddsi_raweth.h b/src/core/ddsi/include/dds/ddsi/ddsi_raweth.h similarity index 100% rename from src/core/ddsi/include/ddsi/ddsi_raweth.h rename to src/core/ddsi/include/dds/ddsi/ddsi_raweth.h diff --git a/src/core/ddsi/include/ddsi/ddsi_rhc_plugin.h b/src/core/ddsi/include/dds/ddsi/ddsi_rhc_plugin.h similarity index 100% rename from src/core/ddsi/include/ddsi/ddsi_rhc_plugin.h rename to src/core/ddsi/include/dds/ddsi/ddsi_rhc_plugin.h diff --git a/src/core/ddsi/include/ddsi/ddsi_serdata.h b/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h similarity index 94% rename from src/core/ddsi/include/ddsi/ddsi_serdata.h rename to src/core/ddsi/include/dds/ddsi/ddsi_serdata.h index 6d23a2f..0bddb32 100644 --- a/src/core/ddsi/include/ddsi/ddsi_serdata.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_serdata.h @@ -12,8 +12,9 @@ #ifndef DDSI_SERDATA_H #define DDSI_SERDATA_H -#include "ddsi/q_time.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/ddsi_sertopic.h" struct nn_rdata; struct nn_keyhash; @@ -27,7 +28,7 @@ enum ddsi_serdata_kind { struct ddsi_serdata { const struct ddsi_serdata_ops *ops; /* cached from topic->serdata_ops */ uint32_t hash; - os_atomic_uint32_t refc; + ddsrt_atomic_uint32_t refc; enum ddsi_serdata_kind kind; const struct ddsi_sertopic *topic; @@ -66,11 +67,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, os_iovec_t *ref); +typedef struct ddsi_serdata * (*ddsi_serdata_to_ser_ref_t) (const struct ddsi_serdata *d, size_t off, size_t sz, ddsrt_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 os_iovec_t *ref); +typedef void (*ddsi_serdata_to_ser_unref_t) (struct ddsi_serdata *d, const ddsrt_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 @@ -112,12 +113,12 @@ DDS_EXPORT void ddsi_serdata_init (struct ddsi_serdata *d, const struct ddsi_ser DDS_EXPORT inline struct ddsi_serdata *ddsi_serdata_ref (const struct ddsi_serdata *serdata_const) { struct ddsi_serdata *serdata = (struct ddsi_serdata *)serdata_const; - os_atomic_inc32 (&serdata->refc); + ddsrt_atomic_inc32 (&serdata->refc); return serdata; } DDS_EXPORT inline void ddsi_serdata_unref (struct ddsi_serdata *serdata) { - if (os_atomic_dec32_ov (&serdata->refc) == 1) + if (ddsrt_atomic_dec32_ov (&serdata->refc) == 1) serdata->ops->free (serdata); } @@ -145,11 +146,11 @@ DDS_EXPORT inline void ddsi_serdata_to_ser (const struct ddsi_serdata *d, size_t d->ops->to_ser (d, off, sz, buf); } -DDS_EXPORT inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, os_iovec_t *ref) { +DDS_EXPORT inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, ddsrt_iovec_t *ref) { return d->ops->to_ser_ref (d, off, sz, ref); } -DDS_EXPORT inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const os_iovec_t *ref) { +DDS_EXPORT inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const ddsrt_iovec_t *ref) { d->ops->to_ser_unref (d, ref); } diff --git a/src/core/ddsi/include/ddsi/ddsi_serdata_default.h b/src/core/ddsi/include/dds/ddsi/ddsi_serdata_default.h similarity index 86% rename from src/core/ddsi/include/ddsi/ddsi_serdata_default.h rename to src/core/ddsi/include/dds/ddsi/ddsi_serdata_default.h index bb80fa2..403a1c0 100644 --- a/src/core/ddsi/include/ddsi/ddsi_serdata_default.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_serdata_default.h @@ -12,27 +12,17 @@ #ifndef DDSI_SERDATA_DEFAULT_H #define DDSI_SERDATA_DEFAULT_H -#include "os/os.h" -#include "ddsi/q_plist.h" /* for nn_prismtech_writer_info */ -#include "ddsi/q_freelist.h" -#include "util/ut_avl.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/ddsrt/endian.h" +#include "dds/ddsi/q_plist.h" /* for nn_prismtech_writer_info */ +#include "dds/ddsi/q_freelist.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_sertopic.h" -#include "ddsc/dds.h" +#include "dds/dds.h" #include "dds__topic.h" -#ifndef PLATFORM_IS_LITTLE_ENDIAN -# if OS_ENDIANNESS == OS_BIG_ENDIAN -# define PLATFORM_IS_LITTLE_ENDIAN 0 -# elif OS_ENDIANNESS == OS_LITTLE_ENDIAN -# define PLATFORM_IS_LITTLE_ENDIAN 1 -# else -# error "invalid endianness setting" -# endif -#endif /* PLATFORM_IS_LITTLE_ENDIAN */ - -#if PLATFORM_IS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN #define CDR_BE 0x0000 #define CDR_LE 0x0100 #else diff --git a/src/core/ddsi/include/ddsi/ddsi_sertopic.h b/src/core/ddsi/include/dds/ddsi/ddsi_sertopic.h similarity index 94% rename from src/core/ddsi/include/ddsi/ddsi_sertopic.h rename to src/core/ddsi/include/dds/ddsi/ddsi_sertopic.h index 3bd8dd8..2b48ad5 100644 --- a/src/core/ddsi/include/ddsi/ddsi_sertopic.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_sertopic.h @@ -12,8 +12,9 @@ #ifndef DDSI_SERTOPIC_H #define DDSI_SERTOPIC_H -#include "util/ut_avl.h" -#include "ddsc/dds_public_alloc.h" +#include "dds/ddsrt/atomics.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsc/dds_public_alloc.h" struct ddsi_serdata; struct ddsi_serdata_ops; @@ -32,7 +33,7 @@ struct ddsi_sertopic { char *name; char *typename; uint64_t iid; - os_atomic_uint32_t refc; /* counts refs from entities, not from data */ + ddsrt_atomic_uint32_t refc; /* counts refs from entities, not from data */ topic_cb_t status_cb; struct dds_topic * status_cb_entity; diff --git a/src/core/ddsi/include/ddsi/ddsi_ssl.h b/src/core/ddsi/include/dds/ddsi/ddsi_ssl.h similarity index 100% rename from src/core/ddsi/include/ddsi/ddsi_ssl.h rename to src/core/ddsi/include/dds/ddsi/ddsi_ssl.h diff --git a/src/core/ddsi/include/ddsi/ddsi_tcp.h b/src/core/ddsi/include/dds/ddsi/ddsi_tcp.h similarity index 66% rename from src/core/ddsi/include/ddsi/ddsi_tcp.h rename to src/core/ddsi/include/dds/ddsi/ddsi_tcp.h index b7f6fc0..bdf28d9 100644 --- a/src/core/ddsi/include/ddsi/ddsi_tcp.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_tcp.h @@ -12,11 +12,11 @@ #ifndef _DDSI_TCP_H_ #define _DDSI_TCP_H_ -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tran.h" #ifdef DDSI_INCLUDE_SSL -#include "ddsi/ddsi_ssl.h" +#include "dds/ddsi/ddsi_ssl.h" struct ddsi_ssl_plugins { @@ -24,11 +24,11 @@ struct ddsi_ssl_plugins void (*fini) (void); void (*ssl_free) (SSL *ssl); void (*bio_vfree) (BIO *bio); - ssize_t (*read) (SSL *ssl, void *buf, size_t len, int *err); - ssize_t (*write) (SSL *ssl, const void *msg, size_t len, int *err); - SSL * (*connect) (os_socket sock); - BIO * (*listen) (os_socket sock); - SSL * (*accept) (BIO *bio, os_socket *sock); + ssize_t (*read) (SSL *ssl, void *buf, size_t len, dds_retcode_t *err); + ssize_t (*write) (SSL *ssl, const void *msg, size_t len, dds_retcode_t *err); + SSL * (*connect) (ddsrt_socket_t sock); + BIO * (*listen) (ddsrt_socket_t sock); + SSL * (*accept) (BIO *bio, ddsrt_socket_t *sock); }; #endif diff --git a/src/core/ddsi/include/ddsi/ddsi_tkmap.h b/src/core/ddsi/include/dds/ddsi/ddsi_tkmap.h similarity index 78% rename from src/core/ddsi/include/ddsi/ddsi_tkmap.h rename to src/core/ddsi/include/dds/ddsi/ddsi_tkmap.h index 8c124d1..2029bd7 100644 --- a/src/core/ddsi/include/ddsi/ddsi_tkmap.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_tkmap.h @@ -13,7 +13,7 @@ #define _DDS_TKMAP_H_ #include "dds__types.h" -#include "os/os_atomics.h" +#include "dds/ddsrt/atomics.h" #if defined (__cplusplus) extern "C" { @@ -27,13 +27,13 @@ struct ddsi_tkmap_instance { struct ddsi_serdata * m_sample; uint64_t m_iid; - os_atomic_uint32_t m_refc; + ddsrt_atomic_uint32_t m_refc; }; DDS_EXPORT struct ddsi_tkmap * ddsi_tkmap_new (void); -DDS_EXPORT void ddsi_tkmap_free (_Inout_ _Post_invalid_ struct ddsi_tkmap *tkmap); -DDS_EXPORT void ddsi_tkmap_instance_ref (_In_ struct ddsi_tkmap_instance *tk); -DDS_EXPORT uint64_t ddsi_tkmap_lookup (_In_ struct ddsi_tkmap *tkmap, _In_ const struct ddsi_serdata *serdata); +DDS_EXPORT void ddsi_tkmap_free (struct ddsi_tkmap *tkmap); +DDS_EXPORT void ddsi_tkmap_instance_ref (struct ddsi_tkmap_instance *tk); +DDS_EXPORT uint64_t ddsi_tkmap_lookup (struct ddsi_tkmap *tkmap, const struct ddsi_serdata *serdata); DDS_EXPORT struct ddsi_tkmap_instance * ddsi_tkmap_find(struct ddsi_serdata *sd, const bool rd, const bool create); DDS_EXPORT struct ddsi_tkmap_instance * ddsi_tkmap_find_by_id (struct ddsi_tkmap *map, uint64_t iid); DDS_EXPORT struct ddsi_tkmap_instance * ddsi_tkmap_lookup_instance_ref (struct ddsi_serdata * sd); diff --git a/src/core/ddsi/include/ddsi/ddsi_tran.h b/src/core/ddsi/include/dds/ddsi/ddsi_tran.h similarity index 94% rename from src/core/ddsi/include/ddsi/ddsi_tran.h rename to src/core/ddsi/include/dds/ddsi/ddsi_tran.h index 5ae1687..7946ca9 100644 --- a/src/core/ddsi/include/ddsi/ddsi_tran.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_tran.h @@ -14,8 +14,8 @@ /* DDSI Transport module */ -#include "ddsi/q_globals.h" -#include "ddsi/q_protocol.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_protocol.h" /* Types supporting handles */ @@ -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, bool, nn_locator_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 ssize_t (*ddsi_tran_write_fn_t) (ddsi_tran_conn_t, const nn_locator_t *, size_t, const ddsrt_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_socket (*ddsi_tran_handle_fn_t) (ddsi_tran_base_t); +typedef ddsrt_socket_t (*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 *); @@ -76,7 +76,7 @@ typedef enum ddsi_locator_from_string_result (*ddsi_locator_from_string_fn_t) (d typedef char * (*ddsi_locator_to_string_fn_t) (ddsi_tran_factory_t tran, char *dst, size_t sizeof_dst, const nn_locator_t *loc, int with_port); -typedef int (*ddsi_enumerate_interfaces_fn_t) (ddsi_tran_factory_t tran, os_ifaddrs_t **interfs); +typedef int (*ddsi_enumerate_interfaces_fn_t) (ddsi_tran_factory_t tran, ddsrt_ifaddrs_t **interfs); /* Data types */ @@ -111,7 +111,7 @@ struct ddsi_tran_conn bool m_connless; bool m_stream; bool m_closed; - os_atomic_uint32_t m_count; + ddsrt_atomic_uint32_t m_count; /* Relationships */ @@ -198,14 +198,14 @@ inline ddsi_tran_listener_t ddsi_factory_create_listener (ddsi_tran_factory_t fa 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); -inline os_socket ddsi_tran_handle (ddsi_tran_base_t base) { +inline ddsrt_socket_t ddsi_tran_handle (ddsi_tran_base_t base) { return base->m_handle_fn (base); } inline int ddsi_tran_locator (ddsi_tran_base_t base, nn_locator_t * loc) { return base->m_locator_fn (base, loc); } -inline os_socket ddsi_conn_handle (ddsi_tran_conn_t conn) { +inline ddsrt_socket_t ddsi_conn_handle (ddsi_tran_conn_t conn) { return conn->m_base.m_handle_fn (&conn->m_base); } inline uint32_t ddsi_conn_type (ddsi_tran_conn_t conn) { @@ -217,7 +217,7 @@ inline uint32_t ddsi_conn_port (ddsi_tran_conn_t conn) { inline int ddsi_conn_locator (ddsi_tran_conn_t conn, nn_locator_t * loc) { return conn->m_base.m_locator_fn (&conn->m_base, loc); } -inline 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) { +inline ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsrt_iovec_t *iov, uint32_t flags) { return conn->m_closed ? -1 : (conn->m_write_fn) (conn, dst, niov, iov, flags); } inline ssize_t ddsi_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, bool allow_spurious, nn_locator_t *srcloc) { @@ -251,7 +251,7 @@ enum ddsi_locator_from_string_result ddsi_locator_from_string (nn_locator_t *loc char *ddsi_locator_to_string (char *dst, size_t sizeof_dst, const nn_locator_t *loc); char *ddsi_locator_to_string_no_port (char *dst, size_t sizeof_dst, const nn_locator_t *loc); -int ddsi_enumerate_interfaces (ddsi_tran_factory_t factory, os_ifaddrs_t **interfs); +int ddsi_enumerate_interfaces (ddsi_tran_factory_t factory, ddsrt_ifaddrs_t **interfs); inline int ddsi_listener_locator (ddsi_tran_listener_t listener, nn_locator_t * loc) { return listener->m_base.m_locator_fn (&listener->m_base, loc); diff --git a/src/core/ddsi/include/ddsi/ddsi_udp.h b/src/core/ddsi/include/dds/ddsi/ddsi_udp.h similarity index 100% rename from src/core/ddsi/include/ddsi/ddsi_udp.h rename to src/core/ddsi/include/dds/ddsi/ddsi_udp.h diff --git a/src/core/ddsi/include/ddsi/ddsi_vendor.h b/src/core/ddsi/include/dds/ddsi/ddsi_vendor.h similarity index 100% rename from src/core/ddsi/include/ddsi/ddsi_vendor.h rename to src/core/ddsi/include/dds/ddsi/ddsi_vendor.h diff --git a/src/core/ddsi/include/ddsi/probes-constants.h b/src/core/ddsi/include/dds/ddsi/probes-constants.h similarity index 100% rename from src/core/ddsi/include/ddsi/probes-constants.h rename to src/core/ddsi/include/dds/ddsi/probes-constants.h diff --git a/src/core/ddsi/include/ddsi/q_addrset.h b/src/core/ddsi/include/dds/ddsi/q_addrset.h similarity index 93% rename from src/core/ddsi/include/ddsi/q_addrset.h rename to src/core/ddsi/include/dds/ddsi/q_addrset.h index 459fd7d..500337f 100644 --- a/src/core/ddsi/include/ddsi/q_addrset.h +++ b/src/core/ddsi/include/dds/ddsi/q_addrset.h @@ -12,12 +12,11 @@ #ifndef NN_ADDRSET_H #define NN_ADDRSET_H -#include "os/os.h" - -#include "util/ut_avl.h" -#include "ddsi/q_log.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_feature_check.h" +#include "dds/ddsrt/sync.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_feature_check.h" #if defined (__cplusplus) extern "C" { @@ -29,8 +28,8 @@ typedef struct addrset_node { } * addrset_node_t; struct addrset { - os_mutex lock; - os_atomic_uint32_t refc; + ddsrt_mutex_t lock; + ddsrt_atomic_uint32_t refc; ut_avlCTree_t ucaddrs, mcaddrs; }; diff --git a/src/core/ddsi/include/ddsi/q_bitset.h b/src/core/ddsi/include/dds/ddsi/q_bitset.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_bitset.h rename to src/core/ddsi/include/dds/ddsi/q_bitset.h index 006097a..efe9ba0 100644 --- a/src/core/ddsi/include/ddsi/q_bitset.h +++ b/src/core/ddsi/include/dds/ddsi/q_bitset.h @@ -15,7 +15,7 @@ #include #include -#include "ddsi/q_unused.h" +#include "dds/ddsi/q_unused.h" inline int nn_bitset_isset (unsigned numbits, const unsigned *bits, unsigned idx) { diff --git a/src/core/ddsi/include/ddsi/q_bswap.h b/src/core/ddsi/include/dds/ddsi/q_bswap.h similarity index 91% rename from src/core/ddsi/include/ddsi/q_bswap.h rename to src/core/ddsi/include/dds/ddsi/q_bswap.h index c3ae2a4..7478f87 100644 --- a/src/core/ddsi/include/ddsi/q_bswap.h +++ b/src/core/ddsi/include/dds/ddsi/q_bswap.h @@ -12,10 +12,12 @@ #ifndef NN_BSWAP_H #define NN_BSWAP_H -#include "os/os.h" +#include -#include "ddsi/q_rtps.h" /* for nn_guid_t, nn_guid_prefix_t */ -#include "ddsi/q_protocol.h" /* for nn_sequence_number_t */ +#include "dds/ddsrt/endian.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsi/q_rtps.h" /* for nn_guid_t, nn_guid_prefix_t */ +#include "dds/ddsi/q_protocol.h" /* for nn_sequence_number_t */ inline uint16_t bswap2u (uint16_t x) { @@ -55,7 +57,7 @@ inline void bswapSN (nn_sequence_number_t *sn) sn->low = bswap4u (sn->low); } -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN #define toBE2(x) bswap2 (x) #define toBE2u(x) bswap2u (x) #define toBE4(x) bswap4 (x) diff --git a/src/core/ddsi/include/ddsi/q_config.h b/src/core/ddsi/include/dds/ddsi/q_config.h similarity index 95% rename from src/core/ddsi/include/ddsi/q_config.h rename to src/core/ddsi/include/dds/ddsi/q_config.h index 6f842b2..c771810 100644 --- a/src/core/ddsi/include/ddsi/q_config.h +++ b/src/core/ddsi/include/dds/ddsi/q_config.h @@ -12,17 +12,15 @@ #ifndef NN_CONFIG_H #define NN_CONFIG_H -#include "os/os.h" - -#include "ddsi/q_log.h" -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_thread.h" #ifdef DDSI_INCLUDE_ENCRYPTION -#include "ddsi/q_security.h" +#include "dds/ddsi/q_security.h" #endif /* DDSI_INCLUDE_ENCRYPTION */ -#include "ddsi/q_xqos.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/q_feature_check.h" -#include "ddsi/ddsi_rhc_plugin.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/q_feature_check.h" +#include "dds/ddsi/ddsi_rhc_plugin.h" #if defined (__cplusplus) extern "C" { @@ -86,7 +84,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, os_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, ddsrt_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); @@ -170,7 +168,7 @@ struct config_maybe_int64 { struct config_thread_properties_listelem { struct config_thread_properties_listelem *next; char *name; - os_schedClass sched_class; + ddsrt_sched_t sched_class; struct config_maybe_int32 sched_priority; struct config_maybe_uint32 stack_size; }; @@ -410,7 +408,7 @@ struct config /* not used by ddsi2, only validated; user layer directly accesses the configuration tree */ - os_schedClass watchdog_sched_class; + ddsrt_sched_t watchdog_sched_class; int32_t watchdog_sched_priority; q__schedPrioClass watchdog_sched_priority_class; }; @@ -428,14 +426,14 @@ struct ddsi_plugin struct ddsi_rhc_plugin rhc_plugin; }; -extern struct config OSAPI_EXPORT config; +extern struct config DDS_EXPORT config; extern struct ddsi_plugin ddsi_plugin; struct cfgst; -struct cfgst *config_init (_In_opt_ const char *configfile); -void config_print_cfgst (_In_ struct cfgst *cfgst); -void config_fini (_In_ struct cfgst *cfgst); +struct cfgst *config_init (const char *configfile); +void config_print_cfgst (struct cfgst *cfgst); +void config_fini (struct cfgst *cfgst); #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS struct config_partitionmapping_listelem *find_partitionmapping (const char *partition, const char *topic); diff --git a/src/core/ddsi/include/ddsi/q_ddsi_discovery.h b/src/core/ddsi/include/dds/ddsi/q_ddsi_discovery.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_ddsi_discovery.h rename to src/core/ddsi/include/dds/ddsi/q_ddsi_discovery.h index d2ae27a..72b5de6 100644 --- a/src/core/ddsi/include/ddsi/q_ddsi_discovery.h +++ b/src/core/ddsi/include/dds/ddsi/q_ddsi_discovery.h @@ -12,7 +12,7 @@ #ifndef NN_DDSI_DISCOVERY_H #define NN_DDSI_DISCOVERY_H -#include "ddsi/q_unused.h" +#include "dds/ddsi/q_unused.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_debmon.h b/src/core/ddsi/include/dds/ddsi/q_debmon.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_debmon.h rename to src/core/ddsi/include/dds/ddsi/q_debmon.h diff --git a/src/core/ddsi/include/ddsi/q_entity.h b/src/core/ddsi/include/dds/ddsi/q_entity.h similarity index 95% rename from src/core/ddsi/include/ddsi/q_entity.h rename to src/core/ddsi/include/dds/ddsi/q_entity.h index 6840643..6f79aac 100644 --- a/src/core/ddsi/include/ddsi/q_entity.h +++ b/src/core/ddsi/include/dds/ddsi/q_entity.h @@ -12,17 +12,17 @@ #ifndef Q_ENTITY_H #define Q_ENTITY_H -#include "os/os.h" -#include "util/ut_avl.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_lat_estim.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_hbcontrol.h" -#include "ddsi/q_feature_check.h" -#include "ddsi/q_inverse_uint32_set.h" +#include "dds/ddsrt/atomics.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_lat_estim.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_hbcontrol.h" +#include "dds/ddsi/q_feature_check.h" +#include "dds/ddsi/q_inverse_uint32_set.h" -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tran.h" #if defined (__cplusplus) extern "C" { @@ -136,12 +136,12 @@ struct entity_common { char *name; uint64_t iid; struct ddsi_tkmap_instance *tk; - os_mutex lock; + ddsrt_mutex_t lock; bool onlylocal; }; struct local_reader_ary { - os_mutex rdary_lock; + ddsrt_mutex_t rdary_lock; unsigned valid: 1; /* always true until (proxy-)writer is being deleted; !valid => !fastpath_ok */ unsigned fastpath_ok: 1; /* if not ok, fall back to using GUIDs (gives access to the reader-writer match data for handling readers that bumped into resource limits, hence can flip-flop, unlike "valid") */ unsigned n_readers; @@ -165,7 +165,7 @@ struct participant nn_locator_t m_locator; ddsi_tran_conn_t m_conn; struct avail_entityid_set avail_entityids; /* available entity ids [e.lock] */ - os_mutex refc_lock; + ddsrt_mutex_t refc_lock; int32_t user_refc; /* number of non-built-in endpoints in this participant [refc_lock] */ int32_t builtin_refc; /* number of built-in endpoints in this participant [refc_lock] */ int builtins_deleted; /* whether deletion of built-in endpoints has been initiated [refc_lock] */ @@ -187,14 +187,14 @@ enum writer_state { WRST_DELETING /* writer is actually being deleted (removed from hash table) */ }; -#if OS_ATOMIC64_SUPPORT -typedef os_atomic_uint64_t seq_xmit_t; -#define INIT_SEQ_XMIT(wr, v) os_atomic_st64(&(wr)->seq_xmit, (uint64_t) (v)) -#define READ_SEQ_XMIT(wr) ((seqno_t) os_atomic_ld64(&(wr)->seq_xmit)) +#if DDSRT_ATOMIC64_SUPPORT +typedef ddsrt_atomic_uint64_t seq_xmit_t; +#define INIT_SEQ_XMIT(wr, v) ddsrt_atomic_st64(&(wr)->seq_xmit, (uint64_t) (v)) +#define READ_SEQ_XMIT(wr) ((seqno_t) ddsrt_atomic_ld64(&(wr)->seq_xmit)) #define UPDATE_SEQ_XMIT_LOCKED(wr, nv) do { uint64_t ov_; do { \ - ov_ = os_atomic_ld64(&(wr)->seq_xmit); \ + ov_ = ddsrt_atomic_ld64(&(wr)->seq_xmit); \ if ((uint64_t) nv <= ov_) break; \ -} while (!os_atomic_cas64(&(wr)->seq_xmit, ov_, (uint64_t) nv)); } while (0) +} while (!ddsrt_atomic_cas64(&(wr)->seq_xmit, ov_, (uint64_t) nv)); } while (0) #define UPDATE_SEQ_XMIT_UNLOCKED(sx, nv) UPDATE_SEQ_XMIT_LOCKED(sx, nv) #else typedef seqno_t seq_xmit_t; @@ -204,9 +204,9 @@ typedef seqno_t seq_xmit_t; if ((nv) > (wr)->seq_xmit) { (wr)->seq_xmit = (nv); } \ } while (0) #define UPDATE_SEQ_XMIT_UNLOCKED(wr, nv) do { \ - os_mutexLock (&(wr)->e.lock); \ + ddsrt_mutex_lock (&(wr)->e.lock); \ if ((nv) > (wr)->seq_xmit) { (wr)->seq_xmit = (nv); } \ - os_mutexUnlock (&(wr)->e.lock); \ + ddsrt_mutex_unlock (&(wr)->e.lock); \ } while (0) #endif @@ -216,7 +216,7 @@ struct writer struct endpoint_common c; status_cb_t status_cb; void * status_cb_entity; - os_cond throttle_cond; /* used to trigger a transmit thread blocked in throttle_writer() */ + ddsrt_cond_t throttle_cond; /* used to trigger a transmit thread blocked in throttle_writer() */ seqno_t seq; /* last sequence number (transmitted seqs are 1 ... seq) */ seqno_t cs_seq; /* 1st seq in coherent set (or 0) */ seq_xmit_t seq_xmit; /* last sequence number actually transmitted */ @@ -295,7 +295,7 @@ struct proxy_participant unsigned prismtech_bes; /* prismtech-specific extension of built-in endpoints set */ nn_guid_t privileged_pp_guid; /* if this PP depends on another PP for its SEDP writing */ nn_plist_t *plist; /* settings/QoS for this participant */ - os_atomic_voidp_t lease; /* lease object for this participant, for automatic leases */ + ddsrt_atomic_voidp_t lease; /* lease object for this participant, for automatic leases */ struct addrset *as_default; /* default address set to use for user data traffic */ struct addrset *as_meta; /* default address set to use for discovery traffic */ struct proxy_endpoint_common *endpoints; /* all proxy endpoints can be reached from here */ @@ -346,7 +346,7 @@ struct proxy_writer { seqno_t last_seq; /* highest known seq published by the writer, not last delivered */ uint32_t last_fragnum; /* last known frag for last_seq, or ~0u if last_seq not partial */ nn_count_t nackfragcount; /* last nackfrag seq number */ - os_atomic_uint32_t next_deliv_seq_lowword; /* lower 32-bits for next sequence number that will be delivered; for generating acks; 32-bit so atomic reads on all supported platforms */ + ddsrt_atomic_uint32_t next_deliv_seq_lowword; /* lower 32-bits for next sequence number that will be delivered; for generating acks; 32-bit so atomic reads on all supported platforms */ unsigned last_fragnum_reset: 1; /* iff set, heartbeat advertising last_seq as highest seq resets last_fragnum */ unsigned deliver_synchronously: 1; /* iff 1, delivery happens straight from receive thread for non-historical data; else through delivery queue "dqueue" */ unsigned have_seen_heartbeat: 1; /* iff 1, we have received at least on heartbeat from this proxy writer */ diff --git a/src/core/ddsi/include/ddsi/q_ephash.h b/src/core/ddsi/include/dds/ddsi/q_ephash.h similarity index 99% rename from src/core/ddsi/include/ddsi/q_ephash.h rename to src/core/ddsi/include/dds/ddsi/q_ephash.h index 3779d00..e6e0d4a 100644 --- a/src/core/ddsi/include/ddsi/q_ephash.h +++ b/src/core/ddsi/include/dds/ddsi/q_ephash.h @@ -12,8 +12,7 @@ #ifndef Q_EPHASH_H #define Q_EPHASH_H -#include "os/os_defs.h" -#include "util/ut_hopscotch.h" +#include "dds/util/ut_hopscotch.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_error.h b/src/core/ddsi/include/dds/ddsi/q_error.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_error.h rename to src/core/ddsi/include/dds/ddsi/q_error.h diff --git a/src/core/ddsi/include/ddsi/q_feature_check.h b/src/core/ddsi/include/dds/ddsi/q_feature_check.h similarity index 91% rename from src/core/ddsi/include/ddsi/q_feature_check.h rename to src/core/ddsi/include/dds/ddsi/q_feature_check.h index f7c80cf..9c62c20 100644 --- a/src/core/ddsi/include/ddsi/q_feature_check.h +++ b/src/core/ddsi/include/dds/ddsi/q_feature_check.h @@ -42,10 +42,10 @@ #error "SSM requires NETWORK_PARTITIONS" #endif - #include "os/os_socket.h" - #ifndef OS_SOCKET_HAS_SSM - #error "OS_SOCKET_HAS_SSM should be defined" - #elif ! OS_SOCKET_HAS_SSM + #include "dds/ddsrt/sockets.h" + #ifndef DDSRT_HAVE_SSM + #error "DDSRT_HAVE_SSM should be defined" + #elif ! DDSRT_HAVE_SSM #undef DDSI_INCLUDE_SSM #endif #endif diff --git a/src/core/ddsi/include/ddsi/q_freelist.h b/src/core/ddsi/include/dds/ddsi/q_freelist.h similarity index 63% rename from src/core/ddsi/include/ddsi/q_freelist.h rename to src/core/ddsi/include/dds/ddsi/q_freelist.h index 0c80ae3..8e40ff7 100644 --- a/src/core/ddsi/include/ddsi/q_freelist.h +++ b/src/core/ddsi/include/dds/ddsi/q_freelist.h @@ -12,7 +12,8 @@ #ifndef NN_FREELIST_H #define NN_FREELIST_H -#include "os/os.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/sync.h" #define FREELIST_SIMPLE 1 #define FREELIST_ATOMIC_LIFO 2 @@ -31,8 +32,8 @@ #if FREELIST_TYPE == FREELIST_ATOMIC_LIFO struct nn_freelist { - os_atomic_lifo_t x; - os_atomic_uint32_t count; + ddsrt_atomic_lifo_t x; + ddsrt_atomic_uint32_t count; uint32_t max; off_t linkoff; }; @@ -49,15 +50,15 @@ struct nn_freelistM { }; struct nn_freelist1 { - os_mutex lock; + ddsrt_mutex_t lock; uint32_t count; struct nn_freelistM *m; }; struct nn_freelist { struct nn_freelist1 inner[NN_FREELIST_NPAR]; - os_atomic_uint32_t cc; - os_mutex lock; + ddsrt_atomic_uint32_t cc; + ddsrt_mutex_t lock; struct nn_freelistM *mlist; struct nn_freelistM *emlist; uint32_t count; @@ -67,10 +68,10 @@ struct nn_freelist { #endif -void nn_freelist_init (_Out_ struct nn_freelist *fl, uint32_t max, off_t linkoff); -void nn_freelist_fini (_Inout_ _Post_invalid_ struct nn_freelist *fl, _In_ void (*free) (void *elem)); -_Check_return_ bool nn_freelist_push (_Inout_ struct nn_freelist *fl, _Inout_ _When_ (return != 0, _Post_invalid_) void *elem); -_Check_return_ _Ret_maybenull_ void *nn_freelist_pushmany (_Inout_ struct nn_freelist *fl, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *first, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *last, uint32_t n); -_Check_return_ _Ret_maybenull_ void *nn_freelist_pop (_Inout_ struct nn_freelist *fl); +void nn_freelist_init (struct nn_freelist *fl, uint32_t max, off_t linkoff); +void nn_freelist_fini (struct nn_freelist *fl, void (*free) (void *elem)); +bool nn_freelist_push (struct nn_freelist *fl, void *elem); +void *nn_freelist_pushmany (struct nn_freelist *fl, void *first, void *last, uint32_t n); +void *nn_freelist_pop (struct nn_freelist *fl); #endif /* NN_FREELIST_H */ diff --git a/src/core/ddsi/include/ddsi/q_gc.h b/src/core/ddsi/include/dds/ddsi/q_gc.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_gc.h rename to src/core/ddsi/include/dds/ddsi/q_gc.h index 4bbea29..6a155fd 100644 --- a/src/core/ddsi/include/ddsi/q_gc.h +++ b/src/core/ddsi/include/dds/ddsi/q_gc.h @@ -12,8 +12,8 @@ #ifndef Q_GC_H #define Q_GC_H -#include "ddsc/dds_export.h" -#include "ddsi/q_thread.h" +#include "dds/export.h" +#include "dds/ddsi/q_thread.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_globals.h b/src/core/ddsi/include/dds/ddsi/q_globals.h similarity index 91% rename from src/core/ddsi/include/ddsi/q_globals.h rename to src/core/ddsi/include/dds/ddsi/q_globals.h index e4c0d15..177793c 100644 --- a/src/core/ddsi/include/ddsi/q_globals.h +++ b/src/core/ddsi/include/dds/ddsi/q_globals.h @@ -14,20 +14,20 @@ #include -#include "os/os.h" +#include "dds/export.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/sync.h" +#include "dds/util/ut_fibheap.h" -#include "util/ut_fibheap.h" - -#include "ddsc/dds_export.h" - -#include "ddsi/q_plist.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_sockwaitset.h" -#include "ddsi/ddsi_iid.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_sockwaitset.h" +#include "dds/ddsi/ddsi_iid.h" #ifdef DDSI_INCLUDE_ENCRYPTION -#include "ddsi/q_security.h" /* for q_securityDecoderSet */ +#include "dds/ddsi/q_security.h" /* for q_securityDecoderSet */ #endif /* DDSI_INCLUDE_ENCRYPTION */ #if defined (__cplusplus) @@ -108,8 +108,8 @@ struct q_globals { struct nn_servicelease *servicelease; /* Lease junk */ - os_mutex leaseheap_lock; - os_mutex lease_locks[N_LEASE_LOCKS]; + ddsrt_mutex_t leaseheap_lock; + ddsrt_mutex_t lease_locks[N_LEASE_LOCKS]; ut_fibheap_t leaseheap; /* Transport factory */ @@ -138,13 +138,13 @@ struct q_globals { /* In many sockets mode, the receive threads maintain a local array with participant GUIDs and sockets, participant_set_generation is used to notify them. */ - os_atomic_uint32_t participant_set_generation; + ddsrt_atomic_uint32_t participant_set_generation; /* nparticipants is used primarily for limiting the number of active participants, but also during shutdown to determine when it is safe to stop the GC thread. */ - os_mutex participant_set_lock; - os_cond participant_set_cond; + ddsrt_mutex_t participant_set_lock; + ddsrt_cond_t participant_set_cond; uint32_t nparticipants; /* For participants without (some) built-in writers, we fall back to @@ -152,7 +152,7 @@ struct q_globals { built-in writers present. It MUST be created before any in need of it pops up! */ struct participant *privileged_pp; - os_mutex privileged_pp_lock; + ddsrt_mutex_t privileged_pp_lock; /* GUID to be used in next call to new_participant; also protected by privileged_pp_lock */ @@ -164,7 +164,7 @@ struct q_globals { int selected_interface; struct nn_interface interfaces[MAX_INTERFACES]; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 /* whether we're using an IPv6 link-local address (and therefore only listening to multicasts on that interface) */ int ipv6_link_local; @@ -201,9 +201,9 @@ struct q_globals { /* qoslock serializes QoS changes, probably not strictly necessary, but a lot more straightforward that way */ - os_rwlock qoslock; + ddsrt_rwlock_t qoslock; - os_mutex lock; + ddsrt_mutex_t lock; /* Receive thread. (We can only has one for now, cos of the signal trigger socket.) Receive buffer pool is per receive thread, @@ -254,7 +254,7 @@ struct q_globals { we accept from writers we don't know) and have their very own do-nothing defragmentation and reordering thingummies, as well as a global mutex to in lieu of the proxy writer lock. */ - os_mutex spdp_lock; + ddsrt_mutex_t spdp_lock; struct nn_defrag *spdp_defrag; struct nn_reorder *spdp_reorder; @@ -288,8 +288,8 @@ struct q_globals { remove the need to include kernelModule.h) */ uint32_t myNetworkId; - os_mutex sendq_lock; - os_cond sendq_cond; + ddsrt_mutex_t sendq_lock; + ddsrt_cond_t sendq_cond; unsigned sendq_length; struct nn_xpack *sendq_head; struct nn_xpack *sendq_tail; @@ -305,10 +305,7 @@ struct q_globals { /* File for dumping captured packets, NULL if disabled */ FILE *pcap_fp; - os_mutex pcap_lock; - - /* Data structure to capture power events */ - os_timePowerEvents powerEvents; + ddsrt_mutex_t pcap_lock; struct nn_group_membership *mship; }; diff --git a/src/core/ddsi/include/ddsi/q_hbcontrol.h b/src/core/ddsi/include/dds/ddsi/q_hbcontrol.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_hbcontrol.h rename to src/core/ddsi/include/dds/ddsi/q_hbcontrol.h diff --git a/src/core/ddsi/include/ddsi/q_init.h b/src/core/ddsi/include/dds/ddsi/q_init.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_init.h rename to src/core/ddsi/include/dds/ddsi/q_init.h diff --git a/src/core/ddsi/include/ddsi/q_inverse_uint32_set.h b/src/core/ddsi/include/dds/ddsi/q_inverse_uint32_set.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_inverse_uint32_set.h rename to src/core/ddsi/include/dds/ddsi/q_inverse_uint32_set.h index 3498ea0..927d94c 100644 --- a/src/core/ddsi/include/ddsi/q_inverse_uint32_set.h +++ b/src/core/ddsi/include/dds/ddsi/q_inverse_uint32_set.h @@ -12,7 +12,7 @@ #ifndef NN_INVERSE_UINT32_SET_H #define NN_INVERSE_UINT32_SET_H -#include "util/ut_avl.h" +#include "dds/util/ut_avl.h" struct inverse_uint32_set_node { ut_avlNode_t avlnode; diff --git a/src/core/ddsi/include/ddsi/q_lat_estim.h b/src/core/ddsi/include/dds/ddsi/q_lat_estim.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_lat_estim.h rename to src/core/ddsi/include/dds/ddsi/q_lat_estim.h index 6878e5e..9b3b41c 100644 --- a/src/core/ddsi/include/ddsi/q_lat_estim.h +++ b/src/core/ddsi/include/dds/ddsi/q_lat_estim.h @@ -12,9 +12,7 @@ #ifndef NN_LAT_ESTIM_H #define NN_LAT_ESTIM_H -#include "os/os_defs.h" - -#include "ddsi/q_log.h" +#include "dds/ddsi/q_log.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_lease.h b/src/core/ddsi/include/dds/ddsi/q_lease.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_lease.h rename to src/core/ddsi/include/dds/ddsi/q_lease.h index 1bb463c..2a24abe 100644 --- a/src/core/ddsi/include/ddsi/q_lease.h +++ b/src/core/ddsi/include/dds/ddsi/q_lease.h @@ -12,7 +12,7 @@ #ifndef Q_LEASE_H #define Q_LEASE_H -#include "ddsi/q_time.h" +#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_log.h b/src/core/ddsi/include/dds/ddsi/q_log.h similarity index 73% rename from src/core/ddsi/include/ddsi/q_log.h rename to src/core/ddsi/include/dds/ddsi/q_log.h index b5fcf5d..7a0bfda 100644 --- a/src/core/ddsi/include/ddsi/q_log.h +++ b/src/core/ddsi/include/dds/ddsi/q_log.h @@ -14,30 +14,31 @@ #include -#include "os/os.h" -#include "ddsi/q_time.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsrt/rusage.h" #if defined (__cplusplus) extern "C" { #endif /* LOG_THREAD_CPUTIME must be considered private. */ -#define LOG_THREAD_CPUTIME(guard) \ - do { \ - if (dds_get_log_mask() & DDS_LC_TIMING) { \ - nn_mtime_t tnowlt = now_mt(); \ - if (tnowlt.v >= (guard).v) { \ - 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; \ - } \ - } \ - } \ +#define LOG_THREAD_CPUTIME(guard) \ + do { \ + if (dds_get_log_mask() & DDS_LC_TIMING) { \ + nn_mtime_t tnowlt = now_mt(); \ + if (tnowlt.v >= (guard).v) { \ + ddsrt_rusage_t usage; \ + if (ddsrt_getrusage(DDSRT_RUSAGE_THREAD, &usage) == 0) { \ + DDS_LOG( \ + DDS_LC_TIMING, \ + "thread_cputime %d.%09d\n", \ + (int)(usage.stime / DDS_NSECS_IN_SEC), \ + (int)(usage.stime % DDS_NSECS_IN_SEC)); \ + (guard).v = tnowlt.v + T_SECOND; \ + } \ + } \ + } \ } while (0) #if defined (__cplusplus) diff --git a/src/core/ddsi/include/ddsi/q_md5.h b/src/core/ddsi/include/dds/ddsi/q_md5.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_md5.h rename to src/core/ddsi/include/dds/ddsi/q_md5.h diff --git a/src/core/ddsi/include/ddsi/q_misc.h b/src/core/ddsi/include/dds/ddsi/q_misc.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_misc.h rename to src/core/ddsi/include/dds/ddsi/q_misc.h index 912ccb0..dcc4224 100644 --- a/src/core/ddsi/include/ddsi/q_misc.h +++ b/src/core/ddsi/include/dds/ddsi/q_misc.h @@ -12,7 +12,7 @@ #ifndef NN_MISC_H #define NN_MISC_H -#include "ddsi/q_protocol.h" +#include "dds/ddsi/q_protocol.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_nwif.h b/src/core/ddsi/include/dds/ddsi/q_nwif.h similarity index 79% rename from src/core/ddsi/include/ddsi/q_nwif.h rename to src/core/ddsi/include/dds/ddsi/q_nwif.h index 5e9da11..90777d2 100644 --- a/src/core/ddsi/include/ddsi/q_nwif.h +++ b/src/core/ddsi/include/dds/ddsi/q_nwif.h @@ -12,8 +12,11 @@ #ifndef Q_NWIF_H #define Q_NWIF_H -#include "os/os_socket.h" -#include "ddsi/q_protocol.h" /* for nn_locator_t */ +#include + +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsi/q_protocol.h" /* for nn_locator_t */ #if defined (__cplusplus) extern "C" { @@ -29,7 +32,7 @@ struct nn_interface { char *name; }; -int make_socket (os_socket *socket, unsigned short port, bool stream, bool reuse); +int make_socket (ddsrt_socket_t *socket, unsigned short port, bool stream, bool reuse); int find_own_ip (const char *requested_address); unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src); diff --git a/src/core/ddsi/include/ddsi/q_pcap.h b/src/core/ddsi/include/dds/ddsi/q_pcap.h similarity index 82% rename from src/core/ddsi/include/ddsi/q_pcap.h rename to src/core/ddsi/include/dds/ddsi/q_pcap.h index d774dff..478b038 100644 --- a/src/core/ddsi/include/ddsi/q_pcap.h +++ b/src/core/ddsi/include/dds/ddsi/q_pcap.h @@ -13,7 +13,7 @@ #define Q_PCAP_H #include -#include "ddsi/q_time.h" +#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { @@ -27,8 +27,8 @@ void write_pcap_received ( FILE * fp, nn_wctime_t tstamp, - const os_sockaddr_storage * src, - const os_sockaddr_storage * dst, + const struct sockaddr_storage * src, + const struct sockaddr_storage * dst, unsigned char * buf, size_t sz ); @@ -37,8 +37,8 @@ void write_pcap_sent ( FILE * fp, nn_wctime_t tstamp, - const os_sockaddr_storage * src, - const struct msghdr * hdr, + const struct sockaddr_storage * src, + const ddsrt_msghdr_t * hdr, size_t sz ); diff --git a/src/core/ddsi/include/ddsi/q_plist.h b/src/core/ddsi/include/dds/ddsi/q_plist.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_plist.h rename to src/core/ddsi/include/dds/ddsi/q_plist.h index 8975724..6481caa 100644 --- a/src/core/ddsi/include/ddsi/q_plist.h +++ b/src/core/ddsi/include/dds/ddsi/q_plist.h @@ -12,8 +12,8 @@ #ifndef NN_PLIST_H #define NN_PLIST_H -#include "ddsi/q_feature_check.h" -#include "ddsi/q_xqos.h" +#include "dds/ddsi/q_feature_check.h" +#include "dds/ddsi/q_xqos.h" #if defined (__cplusplus) @@ -113,16 +113,6 @@ typedef struct nn_reader_favours_ssm { } nn_reader_favours_ssm_t; #endif -typedef struct nn_dataholder -{ - char *class_id; - nn_propertyseq_t properties; - nn_binarypropertyseq_t binary_properties; -} nn_dataholder_t; - -typedef nn_dataholder_t nn_token_t; - - typedef struct nn_prismtech_participant_version_info { unsigned version; @@ -185,8 +175,6 @@ typedef struct nn_plist { char *type_description; nn_sequence_number_t coherent_set_seqno; nn_prismtech_eotinfo_t eotinfo; - nn_token_t identity_token; - nn_token_t permissions_token; #ifdef DDSI_INCLUDE_SSM nn_reader_favours_ssm_t reader_favours_ssm; #endif diff --git a/src/core/ddsi/include/ddsi/q_protocol.h b/src/core/ddsi/include/dds/ddsi/q_protocol.h similarity index 98% rename from src/core/ddsi/include/ddsi/q_protocol.h rename to src/core/ddsi/include/dds/ddsi/q_protocol.h index a29e19f..b86dc05 100644 --- a/src/core/ddsi/include/ddsi/q_protocol.h +++ b/src/core/ddsi/include/dds/ddsi/q_protocol.h @@ -12,17 +12,11 @@ #ifndef NN_PROTOCOL_H #define NN_PROTOCOL_H -#include "os/os.h" -#include "ddsi/q_feature_check.h" +#include "dds/ddsrt/endian.h" +#include "dds/ddsi/q_feature_check.h" -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN -#define PLATFORM_IS_LITTLE_ENDIAN 1 -#else -#define PLATFORM_IS_LITTLE_ENDIAN 0 -#endif - -#include "ddsi/q_rtps.h" -#include "ddsi/q_time.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_time.h" #if defined (__cplusplus) extern "C" { @@ -134,7 +128,7 @@ typedef struct Header { nn_vendorid_t vendorid; nn_guid_prefix_t guid_prefix; } Header_t; -#if PLATFORM_IS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN #define NN_PROTOCOLID_AS_UINT32 (((uint32_t)'R' << 0) | ((uint32_t)'T' << 8) | ((uint32_t)'P' << 16) | ((uint32_t)'S' << 24)) #else #define NN_PROTOCOLID_AS_UINT32 (((uint32_t)'R' << 24) | ((uint32_t)'T' << 16) | ((uint32_t)'P' << 8) | ((uint32_t)'S' << 0)) @@ -192,7 +186,7 @@ typedef struct InfoSRC { nn_guid_prefix_t guid_prefix; } InfoSRC_t; -#if PLATFORM_IS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN #define PL_CDR_BE 0x0200u #define PL_CDR_LE 0x0300u #else diff --git a/src/core/ddsi/include/ddsi/q_qosmatch.h b/src/core/ddsi/include/dds/ddsi/q_qosmatch.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_qosmatch.h rename to src/core/ddsi/include/dds/ddsi/q_qosmatch.h diff --git a/src/core/ddsi/include/ddsi/q_radmin.h b/src/core/ddsi/include/dds/ddsi/q_radmin.h similarity index 97% rename from src/core/ddsi/include/ddsi/q_radmin.h rename to src/core/ddsi/include/dds/ddsi/q_radmin.h index 8be7b21..829cdcd 100644 --- a/src/core/ddsi/include/ddsi/q_radmin.h +++ b/src/core/ddsi/include/dds/ddsi/q_radmin.h @@ -12,9 +12,10 @@ #ifndef NN_RADMIN_H #define NN_RADMIN_H -#include "os/os_thread.h" -#include "ddsi/q_rtps.h" -#include "ddsi/ddsi_tran.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/ddsi_tran.h" #if defined (__cplusplus) extern "C" { @@ -72,7 +73,7 @@ struct nn_rmsg { decrementing of refcounts until after a sample has been added to all radmins even though be delivery of it may take place in concurrently. */ - os_atomic_uint32_t refcount; + ddsrt_atomic_uint32_t refcount; /* Worst-case memory requirement is gigantic (64kB UDP packet, only 1-byte final fragments, each of one a new interval, or maybe 1 @@ -130,7 +131,7 @@ struct nn_rdata { uint16_t submsg_zoff; /* offset to submessage from packet start, or 0 */ uint16_t payload_zoff; /* offset to payload from packet start */ #ifndef NDEBUG - os_atomic_uint32_t refcount_bias_added; + ddsrt_atomic_uint32_t refcount_bias_added; #endif }; @@ -195,7 +196,7 @@ typedef int32_t nn_reorder_result_t; typedef void (*nn_dqueue_callback_t) (void *arg); struct nn_rbufpool *nn_rbufpool_new (uint32_t rbuf_size, uint32_t max_rmsg_size); -void nn_rbufpool_setowner (struct nn_rbufpool *rbp, os_threadId tid); +void nn_rbufpool_setowner (struct nn_rbufpool *rbp, ddsrt_thread_t tid); void nn_rbufpool_free (struct nn_rbufpool *rbp); struct nn_rmsg *nn_rmsg_new (struct nn_rbufpool *rbufpool); diff --git a/src/core/ddsi/include/ddsi/q_receive.h b/src/core/ddsi/include/dds/ddsi/q_receive.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_receive.h rename to src/core/ddsi/include/dds/ddsi/q_receive.h diff --git a/src/core/ddsi/include/ddsi/q_rtps.h b/src/core/ddsi/include/dds/ddsi/q_rtps.h similarity index 98% rename from src/core/ddsi/include/ddsi/q_rtps.h rename to src/core/ddsi/include/dds/ddsi/q_rtps.h index 561e284..e9793d6 100644 --- a/src/core/ddsi/include/ddsi/q_rtps.h +++ b/src/core/ddsi/include/dds/ddsi/q_rtps.h @@ -12,8 +12,7 @@ #ifndef NN_RTPS_H #define NN_RTPS_H -#include "os/os_defs.h" -#include "ddsi/ddsi_vendor.h" +#include "dds/ddsi/ddsi_vendor.h" #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_security.h b/src/core/ddsi/include/dds/ddsi/q_security.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_security.h rename to src/core/ddsi/include/dds/ddsi/q_security.h diff --git a/src/core/ddsi/include/ddsi/q_servicelease.h b/src/core/ddsi/include/dds/ddsi/q_servicelease.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_servicelease.h rename to src/core/ddsi/include/dds/ddsi/q_servicelease.h diff --git a/src/core/ddsi/include/ddsi/q_sockwaitset.h b/src/core/ddsi/include/dds/ddsi/q_sockwaitset.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_sockwaitset.h rename to src/core/ddsi/include/dds/ddsi/q_sockwaitset.h index 5c6f8c7..3842d7f 100644 --- a/src/core/ddsi/include/ddsi/q_sockwaitset.h +++ b/src/core/ddsi/include/dds/ddsi/q_sockwaitset.h @@ -12,8 +12,6 @@ #ifndef Q_SOCKWAITSET_H #define Q_SOCKWAITSET_H -#include "os/os_defs.h" - #if defined (__cplusplus) extern "C" { #endif @@ -41,8 +39,8 @@ void os_sockWaitsetFree (os_sockWaitset ws); Triggers the waitset, from any thread. It is level triggered, when called while no thread is waiting in os_sockWaitsetWait the trigger will cause an (early) wakeup on the - next call to os_sockWaitsetWait. Returns os_resultSuccess if - successfully triggered, os_resultInvalid if an error occurs. + next call to os_sockWaitsetWait. Returns DDS_RETCODE_OK if + successfully triggered, DDS_RETCODE_BAD_PARAMETER if an error occurs. Triggering a waitset may require resources and they may be counted. Do not trigger a waitset arbitrarily often without ensuring diff --git a/src/core/ddsi/include/ddsi/q_static_assert.h b/src/core/ddsi/include/dds/ddsi/q_static_assert.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_static_assert.h rename to src/core/ddsi/include/dds/ddsi/q_static_assert.h diff --git a/src/core/ddsi/include/ddsi/q_thread.h b/src/core/ddsi/include/dds/ddsi/q_thread.h similarity index 75% rename from src/core/ddsi/include/ddsi/q_thread.h rename to src/core/ddsi/include/dds/ddsi/q_thread.h index cefa3b1..fef01ea 100644 --- a/src/core/ddsi/include/ddsi/q_thread.h +++ b/src/core/ddsi/include/dds/ddsi/q_thread.h @@ -12,9 +12,11 @@ #ifndef Q_THREAD_H #define Q_THREAD_H -#include "os/os.h" -#include "ddsc/dds_export.h" -#include "ddsi/q_static_assert.h" +#include "dds/export.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsi/q_static_assert.h" #if defined (__cplusplus) extern "C" { @@ -58,8 +60,8 @@ struct logbuf; #define THREAD_BASE \ volatile vtime_t vtime; \ volatile vtime_t watchdog; \ - os_threadId tid; \ - os_threadId extTid; \ + ddsrt_thread_t tid; \ + ddsrt_thread_t extTid; \ enum thread_state state; \ char *name /* note: no semicolon! */ @@ -77,16 +79,16 @@ struct thread_state1 { #undef THREAD_BASE struct thread_states { - os_mutex lock; + ddsrt_mutex_t lock; unsigned nthreads; struct thread_state1 *ts; /* [nthreads] */ }; extern DDS_EXPORT struct thread_states thread_states; -extern os_threadLocal struct thread_state1 *tsd_thread_state; +extern ddsrt_thread_local struct thread_state1 *tsd_thread_state; DDS_EXPORT void thread_states_init_static (void); -DDS_EXPORT void thread_states_init (_In_ unsigned maxthreads); +DDS_EXPORT void thread_states_init (unsigned maxthreads); DDS_EXPORT void thread_states_fini (void); DDS_EXPORT void upgrade_main_thread (void); @@ -95,43 +97,43 @@ DDS_EXPORT const struct config_thread_properties_listelem *lookup_thread_propert DDS_EXPORT struct thread_state1 *create_thread (const char *name, uint32_t (*f) (void *arg), void *arg); DDS_EXPORT struct thread_state1 *lookup_thread_state (void); DDS_EXPORT struct thread_state1 *lookup_thread_state_real (void); -DDS_EXPORT int join_thread (_Inout_ struct thread_state1 *ts1); +DDS_EXPORT int join_thread (struct thread_state1 *ts1); DDS_EXPORT void log_stack_traces (void); -DDS_EXPORT struct thread_state1 *get_thread_state (_In_ os_threadId id); -DDS_EXPORT struct thread_state1 * init_thread_state (_In_z_ const char *tname); -DDS_EXPORT void reset_thread_state (_Inout_opt_ struct thread_state1 *ts1); -DDS_EXPORT int thread_exists (_In_z_ const char *name); +DDS_EXPORT struct thread_state1 *get_thread_state (ddsrt_thread_t id); +DDS_EXPORT struct thread_state1 * init_thread_state (const char *tname); +DDS_EXPORT void reset_thread_state (struct thread_state1 *ts1); +DDS_EXPORT int thread_exists (const char *name); -DDS_EXPORT inline int vtime_awake_p (_In_ vtime_t vtime) +DDS_EXPORT inline int vtime_awake_p (vtime_t vtime) { return (vtime % 2) == 0; } -DDS_EXPORT inline int vtime_asleep_p (_In_ vtime_t vtime) +DDS_EXPORT inline int vtime_asleep_p (vtime_t vtime) { return (vtime % 2) == 1; } -DDS_EXPORT inline int vtime_gt (_In_ vtime_t vtime1, _In_ vtime_t vtime0) +DDS_EXPORT inline int vtime_gt (vtime_t vtime1, vtime_t vtime0) { Q_STATIC_ASSERT_CODE (sizeof (vtime_t) == sizeof (svtime_t)); return (svtime_t) (vtime1 - vtime0) > 0; } -DDS_EXPORT inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1) +DDS_EXPORT inline void thread_state_asleep (struct thread_state1 *ts1) { vtime_t vt = ts1->vtime; vtime_t wd = ts1->watchdog; if (vtime_awake_p (vt)) { - os_atomic_fence_rel (); + ddsrt_atomic_fence_rel (); ts1->vtime = vt + 1; } else { - os_atomic_fence_rel (); + ddsrt_atomic_fence_rel (); ts1->vtime = vt + 2; - os_atomic_fence_acq (); + ddsrt_atomic_fence_acq (); } if ( wd % 2 ){ @@ -141,7 +143,7 @@ DDS_EXPORT inline void thread_state_asleep (_Inout_ struct thread_state1 *ts1) } } -DDS_EXPORT inline void thread_state_awake (_Inout_ struct thread_state1 *ts1) +DDS_EXPORT inline void thread_state_awake (struct thread_state1 *ts1) { vtime_t vt = ts1->vtime; vtime_t wd = ts1->watchdog; @@ -149,10 +151,10 @@ DDS_EXPORT inline void thread_state_awake (_Inout_ struct thread_state1 *ts1) ts1->vtime = vt + 1; else { - os_atomic_fence_rel (); + ddsrt_atomic_fence_rel (); ts1->vtime = vt + 2; } - os_atomic_fence_acq (); + ddsrt_atomic_fence_acq (); if ( wd % 2 ){ ts1->watchdog = wd + 1; @@ -161,7 +163,7 @@ DDS_EXPORT inline void thread_state_awake (_Inout_ struct thread_state1 *ts1) } } -DDS_EXPORT inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1) +DDS_EXPORT inline void thread_state_blocked (struct thread_state1 *ts1) { vtime_t wd = ts1->watchdog; if ( wd % 2 ){ @@ -171,7 +173,7 @@ DDS_EXPORT inline void thread_state_blocked (_Inout_ struct thread_state1 *ts1) } } -DDS_EXPORT inline void thread_state_unblocked (_Inout_ struct thread_state1 *ts1) +DDS_EXPORT inline void thread_state_unblocked (struct thread_state1 *ts1) { vtime_t wd = ts1->watchdog; if ( wd % 2 ){ diff --git a/src/core/ddsi/include/ddsi/q_time.h b/src/core/ddsi/include/dds/ddsi/q_time.h similarity index 75% rename from src/core/ddsi/include/ddsi/q_time.h rename to src/core/ddsi/include/dds/ddsi/q_time.h index bbe79c9..8048cfd 100644 --- a/src/core/ddsi/include/ddsi/q_time.h +++ b/src/core/ddsi/include/dds/ddsi/q_time.h @@ -12,8 +12,9 @@ #ifndef NN_TIME_H #define NN_TIME_H -#include "os/os.h" -#include "ddsc/dds_export.h" +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -29,14 +30,7 @@ typedef struct { unsigned fraction; } nn_ddsi_time_t; -#if DDSI_DURATION_ACCORDING_TO_SPEC /* what the spec says */ -typedef struct { /* why different from ddsi_time_t? */ - int sec; - int nanosec; -} nn_duration_t; -#else /* this is what I used to do & what wireshark does - probably right */ typedef nn_ddsi_time_t nn_duration_t; -#endif typedef struct { int64_t v; @@ -59,9 +53,9 @@ int valid_ddsi_timestamp (nn_ddsi_time_t t); DDS_EXPORT nn_wctime_t now (void); /* wall clock time */ DDS_EXPORT nn_mtime_t now_mt (void); /* monotonic time */ DDS_EXPORT nn_etime_t now_et (void); /* elapsed time */ -DDS_EXPORT void mtime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_mtime_t t); -DDS_EXPORT void wctime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_wctime_t t); -DDS_EXPORT void etime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_etime_t t); +DDS_EXPORT void mtime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_mtime_t t); +DDS_EXPORT void wctime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_wctime_t t); +DDS_EXPORT void etime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_etime_t t); DDS_EXPORT nn_mtime_t mtime_round_up (nn_mtime_t t, int64_t round); DDS_EXPORT nn_mtime_t add_duration_to_mtime (nn_mtime_t t, int64_t d); DDS_EXPORT nn_wctime_t add_duration_to_wctime (nn_wctime_t t, int64_t d); diff --git a/src/core/ddsi/include/ddsi/q_transmit.h b/src/core/ddsi/include/dds/ddsi/q_transmit.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_transmit.h rename to src/core/ddsi/include/dds/ddsi/q_transmit.h index 1f87abd..14330a2 100644 --- a/src/core/ddsi/include/ddsi/q_transmit.h +++ b/src/core/ddsi/include/dds/ddsi/q_transmit.h @@ -12,8 +12,7 @@ #ifndef Q_TRANSMIT_H #define Q_TRANSMIT_H -#include "os/os_defs.h" -#include "ddsi/q_rtps.h" /* for nn_entityid_t */ +#include "dds/ddsi/q_rtps.h" /* for nn_entityid_t */ #if defined (__cplusplus) extern "C" { diff --git a/src/core/ddsi/include/ddsi/q_unused.h b/src/core/ddsi/include/dds/ddsi/q_unused.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_unused.h rename to src/core/ddsi/include/dds/ddsi/q_unused.h diff --git a/src/core/ddsi/include/ddsi/q_whc.h b/src/core/ddsi/include/dds/ddsi/q_whc.h similarity index 98% rename from src/core/ddsi/include/ddsi/q_whc.h rename to src/core/ddsi/include/dds/ddsi/q_whc.h index 5f33613..038772b 100644 --- a/src/core/ddsi/include/ddsi/q_whc.h +++ b/src/core/ddsi/include/dds/ddsi/q_whc.h @@ -12,6 +12,8 @@ #ifndef Q_WHC_H #define Q_WHC_H +#include + #if defined (__cplusplus) extern "C" { #endif @@ -69,7 +71,7 @@ typedef void (*whc_free_t)(struct whc *whc); /* min_seq is lowest sequence number that must be retained because of reliable readers that have not acknowledged all data */ /* max_drop_seq must go soon, it's way too ugly. */ -/* plist may be NULL or os_malloc'd, WHC takes ownership of plist */ +/* plist may be NULL or ddsrt_malloc'd, WHC takes ownership of plist */ typedef int (*whc_insert_t)(struct whc *whc, seqno_t max_drop_seq, seqno_t seq, struct nn_plist *plist, struct ddsi_serdata *serdata, struct ddsi_tkmap_instance *tk); typedef unsigned (*whc_downgrade_to_volatile_t)(struct whc *whc, struct whc_state *st); typedef unsigned (*whc_remove_acked_messages_t)(struct whc *whc, seqno_t max_drop_seq, struct whc_state *whcst, struct whc_node **deferred_free_list); diff --git a/src/core/ddsi/include/ddsi/q_xevent.h b/src/core/ddsi/include/dds/ddsi/q_xevent.h similarity index 100% rename from src/core/ddsi/include/ddsi/q_xevent.h rename to src/core/ddsi/include/dds/ddsi/q_xevent.h diff --git a/src/core/ddsi/include/ddsi/q_xmsg.h b/src/core/ddsi/include/dds/ddsi/q_xmsg.h similarity index 96% rename from src/core/ddsi/include/ddsi/q_xmsg.h rename to src/core/ddsi/include/dds/ddsi/q_xmsg.h index 5ae7ba7..9236c44 100644 --- a/src/core/ddsi/include/ddsi/q_xmsg.h +++ b/src/core/ddsi/include/dds/ddsi/q_xmsg.h @@ -14,9 +14,9 @@ #include -#include "ddsi/q_protocol.h" /* for, e.g., SubmessageKind_t */ -#include "ddsi/q_xqos.h" /* for, e.g., octetseq, stringseq */ -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/q_protocol.h" /* for, e.g., SubmessageKind_t */ +#include "dds/ddsi/q_xqos.h" /* for, e.g., octetseq, stringseq */ +#include "dds/ddsi/ddsi_tran.h" #if defined (__cplusplus) extern "C" { @@ -135,7 +135,6 @@ void nn_xmsg_addpar_subscription_keys (struct nn_xmsg *m, unsigned pid, const st void nn_xmsg_addpar_parvinfo (struct nn_xmsg *m, unsigned pid, const struct nn_prismtech_participant_version_info *pvi); void nn_xmsg_addpar_eotinfo (struct nn_xmsg *m, unsigned pid, const struct nn_prismtech_eotinfo *txnid); -void nn_xmsg_addpar_dataholder (_In_ struct nn_xmsg *m, _In_ unsigned pid, _In_ const struct nn_dataholder *dh); void nn_xmsg_addpar_sentinel (struct nn_xmsg *m); int nn_xmsg_addpar_sentinel_ifparam (struct nn_xmsg *m); diff --git a/src/core/ddsi/include/ddsi/q_xqos.h b/src/core/ddsi/include/dds/ddsi/q_xqos.h similarity index 94% rename from src/core/ddsi/include/ddsi/q_xqos.h rename to src/core/ddsi/include/dds/ddsi/q_xqos.h index c39c765..46a15bf 100644 --- a/src/core/ddsi/include/ddsi/q_xqos.h +++ b/src/core/ddsi/include/dds/ddsi/q_xqos.h @@ -13,10 +13,10 @@ #define NN_XQOS_H /*XXX*/ -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" /*XXX*/ -#include "ddsi/q_log.h" +#include "dds/ddsi/q_log.h" #if defined (__cplusplus) extern "C" { @@ -33,33 +33,6 @@ typedef nn_octetseq_t nn_userdata_qospolicy_t; typedef nn_octetseq_t nn_topicdata_qospolicy_t; typedef nn_octetseq_t nn_groupdata_qospolicy_t; -typedef struct nn_property { - char *name; - char *value; - bool propagate; -} nn_property_t; - -typedef struct nn_propertyseq { - uint32_t n; - nn_property_t *props; -} nn_propertyseq_t; - -typedef struct nn_binaryproperty { - char *name; - nn_octetseq_t value; - bool propagate; -} nn_binaryproperty_t; - -typedef struct nn_binarypropertyseq { - uint32_t n; - nn_binaryproperty_t *props; -} nn_binarypropertyseq_t; - -typedef struct nn_property_qospolicy { - nn_propertyseq_t value; - nn_binarypropertyseq_t binary_value; -} nn_property_qospolicy_t; - typedef enum nn_durability_kind { NN_VOLATILE_DURABILITY_QOS, NN_TRANSIENT_LOCAL_DURABILITY_QOS, @@ -264,7 +237,6 @@ typedef struct nn_share_qospolicy { #define QP_PRISMTECH_ENTITY_FACTORY ((uint64_t)1 << 27) #define QP_PRISMTECH_SYNCHRONOUS_ENDPOINT ((uint64_t)1 << 28) #define QP_RTI_TYPECODE ((uint64_t)1 << 29) -#define QP_PROPERTY ((uint64_t)1 << 30) /* Partition QoS is not RxO according to the specification (DDS 1.2, section 7.1.3), but communication will not take place unless it @@ -319,8 +291,6 @@ typedef struct nn_xqos { /*x xR*/nn_share_qospolicy_t share; /*xxx */nn_synchronous_endpoint_qospolicy_t synchronous_endpoint; - /*xxx */nn_property_qospolicy_t property; - /* X*/nn_octetseq_t rti_typecode; } nn_xqos_t; diff --git a/src/core/ddsi/include/ddsi/sysdeps.h b/src/core/ddsi/include/dds/ddsi/sysdeps.h similarity index 88% rename from src/core/ddsi/include/ddsi/sysdeps.h rename to src/core/ddsi/include/dds/ddsi/sysdeps.h index bae81f6..f828c39 100644 --- a/src/core/ddsi/include/ddsi/sysdeps.h +++ b/src/core/ddsi/include/dds/ddsi/sysdeps.h @@ -12,8 +12,7 @@ #ifndef SYSDEPS_H #define SYSDEPS_H -#include "os/os.h" - +#include "dds/ddsrt/threads.h" #if defined (__cplusplus) extern "C" { @@ -23,7 +22,7 @@ extern "C" { #define ASSERT_WRLOCK_HELD(x) ((void) 0) #define ASSERT_MUTEX_HELD(x) ((void) 0) -void log_stacktrace (const char *name, os_threadId tid); +void log_stacktrace (const char *name, ddsrt_thread_t tid); #if defined (__cplusplus) } diff --git a/src/core/ddsi/src/ddsi_eth.c b/src/core/ddsi/src/ddsi_eth.c index 45cb563..979badc 100644 --- a/src/core/ddsi/src/ddsi_eth.c +++ b/src/core/ddsi/src/ddsi_eth.c @@ -10,20 +10,21 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "ddsi_eth.h" +#include "dds/ddsi/q_config.h" -int ddsi_eth_enumerate_interfaces(ddsi_tran_factory_t fact, os_ifaddrs_t **ifs) +int ddsi_eth_enumerate_interfaces(ddsi_tran_factory_t fact, ddsrt_ifaddrs_t **ifs) { - int afs[] = { AF_INET, OS_AF_NULL }; + int afs[] = { AF_INET, DDSRT_AF_TERM }; (void)fact; -#if OS_SOCKET_HAVE_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6 || config.transport_selector == TRANS_UDP6) { afs[0] = AF_INET6; } -#endif /* OS_SOCKET_HAVE_IPV6 */ +#endif /* DDSRT_HAVE_IPV6 */ - return -os_getifaddrs(ifs, afs); + return -ddsrt_getifaddrs(ifs, afs); } diff --git a/src/core/ddsi/src/ddsi_eth.h b/src/core/ddsi/src/ddsi_eth.h index 0954755..60d17b7 100644 --- a/src/core/ddsi/src/ddsi_eth.h +++ b/src/core/ddsi/src/ddsi_eth.h @@ -12,9 +12,8 @@ #ifndef DDSI_ETH_H #define DDSI_ETH_H -#include "ddsi/ddsi_tran.h" -#include "os/os.h" +#include "dds/ddsi/ddsi_tran.h" -int ddsi_eth_enumerate_interfaces(ddsi_tran_factory_t fact, os_ifaddrs_t **ifs); +int ddsi_eth_enumerate_interfaces(ddsi_tran_factory_t fact, ddsrt_ifaddrs_t **ifs); #endif /* DDSI_ETH_H */ diff --git a/src/core/ddsi/src/ddsi_iid.c b/src/core/ddsi/src/ddsi_iid.c index 7961ff4..5625973 100644 --- a/src/core/ddsi/src/ddsi_iid.c +++ b/src/core/ddsi/src/ddsi_iid.c @@ -9,9 +9,12 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/ddsi_iid.h" -#include "ddsi/q_time.h" -#include "ddsi/q_globals.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/ddsi_iid.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_globals.h" static void dds_tea_encrypt (uint32_t v[2], const uint32_t k[4]) { @@ -45,12 +48,12 @@ uint64_t ddsi_iid_gen (void) uint64_t iid; union { uint64_t u64; uint32_t u32[2]; } tmp; -#if OS_ATOMIC64_SUPPORT - tmp.u64 = os_atomic_inc64_nv (&gv.dds_iid.counter); +#if DDSRT_ATOMIC64_SUPPORT + tmp.u64 = ddsrt_atomic_inc64_nv (&gv.dds_iid.counter); #else - os_mutexLock (&gv.dds_iid.lock); + ddsrt_mutex_lock (&gv.dds_iid.lock); tmp.u64 = ++gv.dds_iid.counter; - os_mutexUnlock (&gv.dds_iid.lock); + ddsrt_mutex_unlock (&gv.dds_iid.lock); #endif dds_tea_encrypt (tmp.u32, gv.dds_iid.key); @@ -63,19 +66,19 @@ void ddsi_iid_init (void) union { uint64_t u64; uint32_t u32[2]; } tmp; nn_wctime_t tnow = now (); -#if ! OS_ATOMIC64_SUPPORT - os_mutexInit (&gv.dds_iid.lock); +#if ! DDSRT_ATOMIC64_SUPPORT + ddsrt_mutex_init (&gv.dds_iid.lock); #endif - gv.dds_iid.key[0] = (uint32_t) os_getpid(); + gv.dds_iid.key[0] = (uint32_t) ddsrt_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; tmp.u64 = 0; dds_tea_decrypt (tmp.u32, gv.dds_iid.key); -#if OS_ATOMIC64_SUPPORT - os_atomic_st64 (&gv.dds_iid.counter, tmp.u64); +#if DDSRT_ATOMIC64_SUPPORT + ddsrt_atomic_st64 (&gv.dds_iid.counter, tmp.u64); #else gv.dds_iid.counter = tmp.u64; #endif @@ -83,7 +86,7 @@ void ddsi_iid_init (void) void ddsi_iid_fini (void) { -#if ! OS_ATOMIC64_SUPPORT - os_mutexDestroy (&gv.dds_iid.lock); +#if ! DDSRT_ATOMIC64_SUPPORT + ddsrt_mutex_destroy (&gv.dds_iid.lock); #endif } diff --git a/src/core/ddsi/src/ddsi_ipaddr.c b/src/core/ddsi/src/ddsi_ipaddr.c index 733240f..dc84dc7 100644 --- a/src/core/ddsi/src/ddsi_ipaddr.c +++ b/src/core/ddsi/src/ddsi_ipaddr.c @@ -11,32 +11,35 @@ */ #include #include -#include "os/os.h" -#include "ddsi/ddsi_ipaddr.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_config.h" -int ddsi_ipaddr_compare (const os_sockaddr *const sa1, const os_sockaddr *const sa2) +#include "dds/ddsrt/endian.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsi/ddsi_ipaddr.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_config.h" + +int ddsi_ipaddr_compare (const struct sockaddr *const sa1, const struct sockaddr *const sa2) { int eq; size_t sz; if ((eq = sa1->sa_family - sa2->sa_family) == 0) { switch(sa1->sa_family) { -#if (OS_SOCKET_HAS_IPV6 == 1) +#if DDSRT_HAVE_IPV6 case AF_INET6: { - os_sockaddr_in6 *sin61, *sin62; - sin61 = (os_sockaddr_in6 *)sa1; - sin62 = (os_sockaddr_in6 *)sa2; + struct sockaddr_in6 *sin61, *sin62; + sin61 = (struct sockaddr_in6 *)sa1; + sin62 = (struct sockaddr_in6 *)sa2; sz = sizeof(sin61->sin6_addr); eq = memcmp(&sin61->sin6_addr, &sin62->sin6_addr, sz); break; } -#endif /* OS_SOCKET_HAS_IPV6 */ +#endif case AF_INET: { - os_sockaddr_in *sin1, *sin2; - sin1 = (os_sockaddr_in *)sa1; - sin2 = (os_sockaddr_in *)sa2; + struct sockaddr_in *sin1, *sin2; + sin1 = (struct sockaddr_in *)sa1; + sin2 = (struct sockaddr_in *)sa2; sz = sizeof(sin1->sin_addr); eq = memcmp(&sin1->sin_addr, &sin2->sin_addr, sz); break; @@ -52,7 +55,7 @@ int ddsi_ipaddr_compare (const os_sockaddr *const sa1, const os_sockaddr *const enum ddsi_nearby_address_result ddsi_ipaddr_is_nearby_address (ddsi_tran_factory_t tran, const nn_locator_t *loc, size_t ninterf, const struct nn_interface interf[]) { - os_sockaddr_storage tmp, iftmp, nmtmp, ownip; + struct sockaddr_storage tmp, iftmp, nmtmp, ownip; size_t i; (void)tran; ddsi_ipaddr_from_loc(&tmp, loc); @@ -61,9 +64,9 @@ enum ddsi_nearby_address_result ddsi_ipaddr_is_nearby_address (ddsi_tran_factory ddsi_ipaddr_from_loc(&iftmp, &interf[i].loc); ddsi_ipaddr_from_loc(&nmtmp, &interf[i].netmask); ddsi_ipaddr_from_loc(&ownip, &gv.ownloc); - if (os_sockaddrSameSubnet ((os_sockaddr *) &tmp, (os_sockaddr *) &iftmp, (os_sockaddr *) &nmtmp)) + if (ddsrt_sockaddr_insamesubnet ((struct sockaddr *) &tmp, (struct sockaddr *) &iftmp, (struct sockaddr *) &nmtmp)) { - if (ddsi_ipaddr_compare((os_sockaddr *)&iftmp, (os_sockaddr *)&ownip) == 0) + if (ddsi_ipaddr_compare((struct sockaddr *)&iftmp, (struct sockaddr *)&ownip) == 0) return DNAR_SAME; else return DNAR_LOCAL; @@ -75,39 +78,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; + struct sockaddr_storage tmpaddr; switch (kind) { case NN_LOCATOR_KIND_UDPv4: case NN_LOCATOR_KIND_TCPv4: break; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case NN_LOCATOR_KIND_UDPv6: case NN_LOCATOR_KIND_TCPv6: af = AF_INET6; break; -#endif /* OS_SOCKET_HAS_IPV6 */ +#endif default: return AFSR_MISMATCH; } (void)tran; - if (os_sockaddrfromstr(af, str, (os_sockaddr *) &tmpaddr) != 0) { -#if OS_SOCKET_HAS_DNS + if (ddsrt_sockaddrfromstr(af, str, (struct sockaddr *) &tmpaddr) != 0) { +#if DDSRT_HAVE_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) { + ddsrt_hostent_t *hent = NULL; + if (ddsrt_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 */ +#endif } if (tmpaddr.ss_family != af) { return AFSR_MISMATCH; } - ddsi_ipaddr_to_loc (loc, (os_sockaddr *)&tmpaddr, kind); + ddsi_ipaddr_to_loc (loc, (struct 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 */ loc->port = NN_LOCATOR_PORT_INVALID; @@ -116,7 +119,7 @@ enum ddsi_locator_from_string_result ddsi_ipaddr_from_string (ddsi_tran_factory_ char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_dst, const nn_locator_t *loc, int with_port) { - os_sockaddr_storage src; + struct sockaddr_storage src; size_t pos; (void)tran; assert (sizeof_dst > 1); @@ -124,17 +127,17 @@ char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_ switch (src.ss_family) { case AF_INET: - os_sockaddrtostr ((const os_sockaddr *) &src, dst, sizeof_dst); + ddsrt_sockaddrtostr ((const struct sockaddr *) &src, dst, sizeof_dst); if (with_port) { pos = strlen (dst); assert(pos <= sizeof_dst); snprintf (dst + pos, sizeof_dst - pos, ":%d", loc->port); } break; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case AF_INET6: dst[0] = '['; - os_sockaddrtostr ((const os_sockaddr *) &src, dst + 1, sizeof_dst); + ddsrt_sockaddrtostr ((const struct sockaddr *) &src, dst + 1, sizeof_dst); pos = strlen (dst); if (with_port) { assert(pos <= sizeof_dst); @@ -152,14 +155,14 @@ char *ddsi_ipaddr_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_ return dst; } -void ddsi_ipaddr_to_loc (nn_locator_t *dst, const os_sockaddr *src, int32_t kind) +void ddsi_ipaddr_to_loc (nn_locator_t *dst, const struct sockaddr *src, int32_t kind) { dst->kind = kind; switch (src->sa_family) { case AF_INET: { - const os_sockaddr_in *x = (const os_sockaddr_in *) src; + const struct sockaddr_in *x = (const struct sockaddr_in *) src; assert (kind == NN_LOCATOR_KIND_UDPv4 || kind == NN_LOCATOR_KIND_TCPv4); if (x->sin_addr.s_addr == htonl (INADDR_ANY)) { @@ -175,10 +178,10 @@ void ddsi_ipaddr_to_loc (nn_locator_t *dst, const os_sockaddr *src, int32_t kind } break; } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case AF_INET6: { - const os_sockaddr_in6 *x = (const os_sockaddr_in6 *) src; + const struct sockaddr_in6 *x = (const struct sockaddr_in6 *) src; assert (kind == NN_LOCATOR_KIND_UDPv6 || kind == NN_LOCATOR_KIND_TCPv6); if (IN6_IS_ADDR_UNSPECIFIED (&x->sin6_addr)) { @@ -199,13 +202,13 @@ void ddsi_ipaddr_to_loc (nn_locator_t *dst, const os_sockaddr *src, int32_t kind } } -void ddsi_ipaddr_from_loc (os_sockaddr_storage *dst, const nn_locator_t *src) +void ddsi_ipaddr_from_loc (struct sockaddr_storage *dst, const nn_locator_t *src) { memset (dst, 0, sizeof (*dst)); switch (src->kind) { case NN_LOCATOR_KIND_INVALID: -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 dst->ss_family = (config.transport_selector == TRANS_UDP6 || config.transport_selector == TRANS_TCP6) ? AF_INET6 : AF_INET; #else dst->ss_family = AF_INET; @@ -214,17 +217,17 @@ void ddsi_ipaddr_from_loc (os_sockaddr_storage *dst, const nn_locator_t *src) case NN_LOCATOR_KIND_UDPv4: case NN_LOCATOR_KIND_TCPv4: { - os_sockaddr_in *x = (os_sockaddr_in *) dst; + struct sockaddr_in *x = (struct sockaddr_in *) dst; x->sin_family = AF_INET; x->sin_port = (src->port == NN_LOCATOR_PORT_INVALID) ? 0 : htons ((unsigned short) src->port); memcpy (&x->sin_addr.s_addr, src->address + 12, 4); break; } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case NN_LOCATOR_KIND_UDPv6: case NN_LOCATOR_KIND_TCPv6: { - os_sockaddr_in6 *x = (os_sockaddr_in6 *) dst; + struct sockaddr_in6 *x = (struct sockaddr_in6 *) dst; x->sin6_family = AF_INET6; x->sin6_port = (src->port == NN_LOCATOR_PORT_INVALID) ? 0 : htons ((unsigned short) src->port); memcpy (&x->sin6_addr.s6_addr, src->address, 16); diff --git a/src/core/ddsi/src/ddsi_mcgroup.c b/src/core/ddsi/src/ddsi_mcgroup.c index a148a0a..744ace4 100644 --- a/src/core/ddsi/src/ddsi_mcgroup.c +++ b/src/core/ddsi/src/ddsi_mcgroup.c @@ -12,13 +12,15 @@ #include #include #include -#include "os/os.h" -#include "os/os_atomics.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "util/ut_avl.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/util/ut_avl.h" struct nn_group_membership_node { ut_avlNode_t avlnode; @@ -29,7 +31,7 @@ struct nn_group_membership_node { }; struct nn_group_membership { - os_mutex lock; + ddsrt_mutex_t lock; ut_avlTree_t mships; }; @@ -62,17 +64,17 @@ static ut_avlTreedef_t mship_td = UT_AVL_TREEDEF_INITIALIZER(offsetof (struct nn struct nn_group_membership *new_group_membership (void) { - struct nn_group_membership *mship = os_malloc (sizeof (*mship)); - os_mutexInit (&mship->lock); + struct nn_group_membership *mship = ddsrt_malloc (sizeof (*mship)); + ddsrt_mutex_init (&mship->lock); ut_avlInit (&mship_td, &mship->mships); return mship; } void free_group_membership (struct nn_group_membership *mship) { - ut_avlFree (&mship_td, &mship->mships, os_free); - os_mutexDestroy (&mship->lock); - os_free (mship); + ut_avlFree (&mship_td, &mship->mships, ddsrt_free); + ddsrt_mutex_destroy (&mship->lock); + ddsrt_free (mship); } static int reg_group_membership (struct nn_group_membership *mship, ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_locator_t *mcloc) @@ -91,7 +93,7 @@ static int reg_group_membership (struct nn_group_membership *mship, ddsi_tran_co n->count++; } else { isnew = 1; - n = os_malloc (sizeof (*n)); + n = ddsrt_malloc (sizeof (*n)); n->conn = conn; n->srcloc = key.srcloc; n->mcloc = key.mcloc; @@ -121,7 +123,7 @@ static int unreg_group_membership (struct nn_group_membership *mship, ddsi_tran_ { mustdel = 1; ut_avlDeleteDPath (&mship_td, &mship->mships, n, &dp); - os_free (n); + ddsrt_free (n); } return mustdel; } @@ -136,7 +138,7 @@ static char *make_joinleave_msg (char *buf, size_t bufsz, ddsi_tran_conn_t conn, ddsi_locator_to_string_no_port(srcstr, sizeof(srcstr), srcloc); } #else - OS_UNUSED_ARG (srcloc); + DDSRT_UNUSED_ARG (srcloc); #endif ddsi_locator_to_string_no_port (mcstr, sizeof(mcstr), mcloc); if (interf) @@ -223,7 +225,7 @@ static int joinleave_mcgroups (ddsi_tran_conn_t conn, int join, const nn_locator int ddsi_join_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_locator_t *mcloc) { int ret; - os_mutexLock (&gv.mship->lock); + ddsrt_mutex_lock (&gv.mship->lock); if (!reg_group_membership (gv.mship, conn, srcloc, mcloc)) { char buf[256]; @@ -234,14 +236,14 @@ int ddsi_join_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_lo { ret = joinleave_mcgroups (conn, 1, srcloc, mcloc); } - os_mutexUnlock (&gv.mship->lock); + ddsrt_mutex_unlock (&gv.mship->lock); return ret; } int ddsi_leave_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_locator_t *mcloc) { int ret; - os_mutexLock (&gv.mship->lock); + ddsrt_mutex_lock (&gv.mship->lock); if (!unreg_group_membership (gv.mship, conn, srcloc, mcloc)) { char buf[256]; @@ -252,7 +254,7 @@ int ddsi_leave_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_l { ret = joinleave_mcgroups (conn, 0, srcloc, mcloc); } - os_mutexUnlock (&gv.mship->lock); + ddsrt_mutex_unlock (&gv.mship->lock); return ret; } @@ -265,7 +267,7 @@ void ddsi_transfer_group_membership (ddsi_tran_conn_t conn, ddsi_tran_conn_t new /* ordering is on socket, then src IP, then mc IP; IP compare checks family first and AF_INET, AF_INET6 are neither 0 nor maximum representable, min and max define the range of key values that relate to oldsock */ - os_mutexLock (&gv.mship->lock); + ddsrt_mutex_lock (&gv.mship->lock); n = ut_avlLookupSuccEq (&mship_td, &gv.mship->mships, &min); while (n != NULL && cmp_group_membership (n, &max) <= 0) { @@ -275,7 +277,7 @@ void ddsi_transfer_group_membership (ddsi_tran_conn_t conn, ddsi_tran_conn_t new ut_avlInsert (&mship_td, &gv.mship->mships, n); n = nn; } - os_mutexUnlock (&gv.mship->lock); + ddsrt_mutex_unlock (&gv.mship->lock); } int ddsi_rejoin_transferred_mcgroups (ddsi_tran_conn_t conn) @@ -286,13 +288,13 @@ int ddsi_rejoin_transferred_mcgroups (ddsi_tran_conn_t conn) memset(&min, 0, sizeof(min)); memset(&max, 0xff, sizeof(max)); min.conn = max.conn = conn; - os_mutexLock (&gv.mship->lock); + ddsrt_mutex_lock (&gv.mship->lock); for (n = ut_avlIterSuccEq (&mship_td, &gv.mship->mships, &it, &min); n != NULL && ret >= 0 && cmp_group_membership(n, &max) <= 0; n = ut_avlIterNext (&it)) { int have_srcloc = (memcmp(&n->srcloc, &min.srcloc, sizeof(n->srcloc)) != 0); assert (n->conn == conn); ret = joinleave_mcgroups (conn, 1, have_srcloc ? &n->srcloc : NULL, &n->mcloc); } - os_mutexUnlock (&gv.mship->lock); + ddsrt_mutex_unlock (&gv.mship->lock); return ret; } diff --git a/src/core/ddsi/src/ddsi_raweth.c b/src/core/ddsi/src/ddsi_raweth.c index 4b12a97..edad8b4 100644 --- a/src/core/ddsi/src/ddsi_raweth.c +++ b/src/core/ddsi/src/ddsi_raweth.c @@ -9,17 +9,19 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_raweth.h" -#include "ddsi/ddsi_ipaddr.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_error.h" -#include "ddsi/q_pcap.h" -#include "os/os_atomics.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_raweth.h" +#include "dds/ddsi/ddsi_ipaddr.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_pcap.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets.h" #ifdef __linux #include @@ -28,6 +30,7 @@ #include #include #include +#include typedef struct ddsi_tran_factory * ddsi_raweth_factory_t; @@ -40,14 +43,14 @@ typedef struct ddsi_raweth_config typedef struct ddsi_raweth_conn { struct ddsi_tran_conn m_base; - os_socket m_sock; + ddsrt_socket_t m_sock; int m_ifindex; } * ddsi_raweth_conn_t; static struct ddsi_raweth_config ddsi_raweth_config_g; static struct ddsi_tran_factory ddsi_raweth_factory_g; -static os_atomic_uint32_t init_g = OS_ATOMIC_UINT32_INIT(0); +static ddsrt_atomic_uint32_t init_g = DDSRT_ATOMIC_UINT32_INIT(0); static char *ddsi_raweth_to_string (ddsi_tran_factory_t tran, char *dst, size_t sizeof_dst, const nn_locator_t *loc, int with_port) { @@ -65,8 +68,8 @@ static char *ddsi_raweth_to_string (ddsi_tran_factory_t tran, char *dst, size_t static ssize_t ddsi_raweth_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, bool allow_spurious, nn_locator_t *srcloc) { - int err; - ssize_t ret; + dds_retcode_t rc; + ssize_t ret = 0; struct msghdr msghdr; struct sockaddr_ll src; struct iovec msg_iov; @@ -84,9 +87,8 @@ static ssize_t ddsi_raweth_conn_read (ddsi_tran_conn_t conn, unsigned char * buf msghdr.msg_iovlen = 1; do { - ret = recvmsg(((ddsi_raweth_conn_t) conn)->m_sock, &msghdr, 0); - err = (ret == -1) ? os_getErrno() : 0; - } while (err == os_sockEINTR); + rc = ddsrt_recvmsg(((ddsi_raweth_conn_t) conn)->m_sock, &msghdr, 0, &ret); + } while (rc == DDS_RETCODE_INTERRUPTED); if (ret > 0) { @@ -100,7 +102,7 @@ static ssize_t ddsi_raweth_conn_read (ddsi_tran_conn_t conn, unsigned char * buf /* Check for udp packet truncation */ if ((((size_t) ret) > len) -#if OS_MSGHDR_FLAGS +#if DDSRT_MSGHDR_FLAGS || (msghdr.msg_flags & MSG_TRUNC) #endif ) @@ -112,17 +114,19 @@ static ssize_t ddsi_raweth_conn_read (ddsi_tran_conn_t conn, unsigned char * buf DDS_WARNING("%s => %d truncated to %d\n", addrbuf, (int)ret, (int)len); } } - else if (err != os_sockENOTSOCK && err != os_sockECONNRESET) + else if (rc != DDS_RETCODE_OK && + rc != DDS_RETCODE_BAD_PARAMETER && + rc != DDS_RETCODE_NO_CONNECTION) { - DDS_ERROR("UDP recvmsg sock %d: ret %d errno %d\n", (int) ((ddsi_raweth_conn_t) conn)->m_sock, (int) ret, err); + DDS_ERROR("UDP recvmsg sock %d: ret %d retcode %d\n", (int) ((ddsi_raweth_conn_t) conn)->m_sock, (int) ret, rc); } return ret; } -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) +static ssize_t ddsi_raweth_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsrt_iovec_t *iov, uint32_t flags) { ddsi_raweth_conn_t uc = (ddsi_raweth_conn_t) conn; - int err; + dds_retcode_t rc; ssize_t ret; unsigned retry = 2; int sendflags = 0; @@ -139,37 +143,27 @@ 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 = (os_iovec_t *) iov; + msg.msg_iov = (ddsrt_iovec_t *) iov; msg.msg_iovlen = niov; #ifdef MSG_NOSIGNAL sendflags |= MSG_NOSIGNAL; #endif do { - ret = sendmsg (uc->m_sock, &msg, sendflags); - err = (ret == -1) ? os_getErrno() : 0; - } while (err == os_sockEINTR || err == os_sockEWOULDBLOCK || (err == os_sockEPERM && retry-- > 0)); - if (ret == -1) + rc = ddsrt_sendmsg (uc->m_sock, &msg, sendflags, &ret); + } while ((rc == DDS_RETCODE_INTERRUPTED) || + (rc == DDS_RETCODE_TRY_AGAIN) || + (rc == DDS_RETCODE_NOT_ALLOWED && retry-- > 0)); + if (rc != DDS_RETCODE_OK && + rc != DDS_RETCODE_INTERRUPTED && + rc != DDS_RETCODE_NOT_ALLOWED && + rc != DDS_RETCODE_NO_CONNECTION) { - switch (err) - { - case os_sockEINTR: - case os_sockEPERM: - case os_sockECONNRESET: -#ifdef os_sockENETUNREACH - case os_sockENETUNREACH: -#endif -#ifdef os_sockEHOSTUNREACH - case os_sockEHOSTUNREACH: -#endif - break; - default: - DDS_ERROR("ddsi_raweth_conn_write failed with error code %d", err); - } + DDS_ERROR("ddsi_raweth_conn_write failed with retcode %d", rc); } return ret; } -static os_socket ddsi_raweth_conn_handle (ddsi_tran_base_t base) +static ddsrt_socket_t ddsi_raweth_conn_handle (ddsi_tran_base_t base) { return ((ddsi_raweth_conn_t) base)->m_sock; } @@ -183,7 +177,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 != OS_INVALID_SOCKET) + if (uc->m_sock != DDSRT_INVALID_SOCKET) { loc->kind = NN_LOCATOR_KIND_RAWETH; loc->port = uc->m_base.m_base.m_port; @@ -195,8 +189,8 @@ static int ddsi_raweth_conn_locator (ddsi_tran_base_t base, nn_locator_t *loc) static ddsi_tran_conn_t ddsi_raweth_create_conn (uint32_t port, ddsi_tran_qos_t qos) { - os_socket sock; - int rc; + ddsrt_socket_t sock; + dds_retcode_t rc; ddsi_raweth_conn_t uc = NULL; struct sockaddr_ll addr; bool mcast = (bool) (qos ? qos->m_multicast : 0); @@ -209,10 +203,10 @@ static ddsi_tran_conn_t ddsi_raweth_create_conn (uint32_t port, ddsi_tran_qos_t return NULL; } - if ((sock = socket(PF_PACKET, SOCK_DGRAM, htons((uint16_t)port))) == -1) + rc = ddsrt_socket(&sock, PF_PACKET, SOCK_DGRAM, htons((uint16_t)port)); + if (rc != DDS_RETCODE_OK) { - rc = os_getErrno(); - DDS_ERROR("ddsi_raweth_create_conn %s port %u failed ... errno = %d\n", mcast ? "multicast" : "unicast", port, rc); + DDS_ERROR("ddsi_raweth_create_conn %s port %u failed ... retcode = %d\n", mcast ? "multicast" : "unicast", port, rc); return NULL; } @@ -221,15 +215,15 @@ static ddsi_tran_conn_t ddsi_raweth_create_conn (uint32_t port, ddsi_tran_qos_t addr.sll_protocol = htons((uint16_t)port); addr.sll_ifindex = (int)gv.interfaceNo; addr.sll_pkttype = PACKET_HOST | PACKET_BROADCAST | PACKET_MULTICAST; - if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) + rc = ddsrt_bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + if (rc != DDS_RETCODE_OK) { - rc = os_getErrno(); - close(sock); - DDS_ERROR("ddsi_raweth_create_conn %s bind port %u failed ... errno = %d\n", mcast ? "multicast" : "unicast", port, rc); + ddsrt_close(sock); + DDS_ERROR("ddsi_raweth_create_conn %s bind port %u failed ... retcode = %d\n", mcast ? "multicast" : "unicast", port, rc); return NULL; } - uc = (ddsi_raweth_conn_t) os_malloc (sizeof (*uc)); + uc = (ddsi_raweth_conn_t) ddsrt_malloc (sizeof (*uc)); memset (uc, 0, sizeof (*uc)); uc->m_sock = sock; uc->m_ifindex = addr.sll_ifindex; @@ -256,7 +250,7 @@ static int isbroadcast(const nn_locator_t *loc) return 1; } -static int joinleave_asm_mcgroup (os_socket socket, int join, const nn_locator_t *mcloc, const struct nn_interface *interf) +static int joinleave_asm_mcgroup (ddsrt_socket_t socket, int join, const nn_locator_t *mcloc, const struct nn_interface *interf) { int rc; struct packet_mreq mreq; @@ -264,8 +258,8 @@ static int joinleave_asm_mcgroup (os_socket socket, int join, const nn_locator_t mreq.mr_type = PACKET_MR_MULTICAST; mreq.mr_alen = 6; memcpy(mreq.mr_address, mcloc + 10, 6); - rc = setsockopt(socket, SOL_PACKET, join ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); - return (rc == -1) ? os_getErrno() : 0; + rc = ddsrt_setsockopt(socket, SOL_PACKET, join ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); + return (rc == DDS_RETCODE_OK) ? 0 : rc; } static int ddsi_raweth_join_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_locator_t *mcloc, const struct nn_interface *interf) @@ -302,8 +296,8 @@ static void ddsi_raweth_release_conn (ddsi_tran_conn_t conn) uc->m_sock, uc->m_base.m_base.m_port ); - os_sockFree (uc->m_sock); - os_free (conn); + ddsrt_close (uc->m_sock); + ddsrt_free (conn); } static int ddsi_raweth_is_mcaddr (const ddsi_tran_factory_t tran, const nn_locator_t *loc) @@ -357,25 +351,25 @@ static enum ddsi_locator_from_string_result ddsi_raweth_address_from_string (dds static void ddsi_raweth_deinit(void) { - if (os_atomic_dec32_nv(&init_g) == 0) { + if (ddsrt_atomic_dec32_nv(&init_g) == 0) { if (ddsi_raweth_config_g.mship) free_group_membership(ddsi_raweth_config_g.mship); DDS_LOG(DDS_LC_CONFIG, "raweth de-initialized\n"); } } -static int ddsi_raweth_enumerate_interfaces (ddsi_tran_factory_t factory, os_ifaddrs_t **interfs) +static int ddsi_raweth_enumerate_interfaces (ddsi_tran_factory_t factory, ddsrt_ifaddrs_t **interfs) { - int afs[] = { AF_PACKET, OS_AF_NULL }; + int afs[] = { AF_PACKET, DDSRT_AF_TERM }; (void)factory; - return -os_getifaddrs(interfs, afs); + return -ddsrt_getifaddrs(interfs, afs); } int ddsi_raweth_init (void) { - if (os_atomic_inc32_nv(&init_g) == 1) { + if (ddsrt_atomic_inc32_nv(&init_g) == 1) { memset (&ddsi_raweth_factory_g, 0, sizeof (ddsi_raweth_factory_g)); ddsi_raweth_factory_g.m_free_fn = ddsi_raweth_deinit; ddsi_raweth_factory_g.m_kind = NN_LOCATOR_KIND_RAWETH; diff --git a/src/core/ddsi/src/ddsi_rhc_plugin.c b/src/core/ddsi/src/ddsi_rhc_plugin.c index 10dfe83..969c753 100644 --- a/src/core/ddsi/src/ddsi_rhc_plugin.c +++ b/src/core/ddsi/src/ddsi_rhc_plugin.c @@ -9,9 +9,9 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/q_entity.h" -#include "ddsi/q_xqos.h" -#include "ddsi/ddsi_rhc_plugin.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/ddsi_rhc_plugin.h" DDS_EXPORT void make_proxy_writer_info(struct proxy_writer_info *pwr_info, const struct entity_common *e, const struct nn_xqos *xqos) { diff --git a/src/core/ddsi/src/ddsi_serdata.c b/src/core/ddsi/src/ddsi_serdata.c index 0c7520c..524241c 100644 --- a/src/core/ddsi/src/ddsi_serdata.c +++ b/src/core/ddsi/src/ddsi_serdata.c @@ -14,12 +14,11 @@ #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include "ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" +#include "dds/ddsi/ddsi_serdata.h" void ddsi_serdata_init (struct ddsi_serdata *d, const struct ddsi_sertopic *tp, enum ddsi_serdata_kind kind) { @@ -30,7 +29,7 @@ void ddsi_serdata_init (struct ddsi_serdata *d, const struct ddsi_sertopic *tp, d->statusinfo = 0; d->timestamp.v = INT64_MIN; d->twrite.v = INT64_MIN; - os_atomic_st32 (&d->refc, 1); + ddsrt_atomic_st32 (&d->refc, 1); } extern inline struct ddsi_serdata *ddsi_serdata_ref (const struct ddsi_serdata *serdata_const); @@ -41,8 +40,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, os_iovec_t *ref); -extern inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const os_iovec_t *ref); +extern inline struct ddsi_serdata *ddsi_serdata_to_ser_ref (const struct ddsi_serdata *d, size_t off, size_t sz, ddsrt_iovec_t *ref); +extern inline void ddsi_serdata_to_ser_unref (struct ddsi_serdata *d, const ddsrt_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); diff --git a/src/core/ddsi/src/ddsi_serdata_default.c b/src/core/ddsi/src/ddsi_serdata_default.c index f3d80d8..9e938a8 100644 --- a/src/core/ddsi/src/ddsi_serdata_default.c +++ b/src/core/ddsi/src/ddsi_serdata_default.c @@ -9,24 +9,22 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include +#include #include #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include -#include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" #include "dds__key.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__stream.h" -#include "ddsi/q_radmin.h" -#include "ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/ddsi_serdata_default.h" #define MAX_POOL_SIZE 16384 #define CLEAR_PADDING 0 @@ -43,7 +41,7 @@ static size_t alignup_size (size_t x, size_t a); struct serdatapool * ddsi_serdatapool_new (void) { struct serdatapool * pool; - pool = os_malloc (sizeof (*pool)); + pool = ddsrt_malloc (sizeof (*pool)); nn_freelist_init (&pool->freelist, MAX_POOL_SIZE, offsetof (struct ddsi_serdata_default, next)); return pool; } @@ -52,7 +50,7 @@ static void serdata_free_wrap (void *elem) { #ifndef NDEBUG struct ddsi_serdata_default *d = elem; - assert(os_atomic_ld32(&d->c.refc) == 0); + assert(ddsrt_atomic_ld32(&d->c.refc) == 0); #endif dds_free(elem); } @@ -61,7 +59,7 @@ void ddsi_serdatapool_free (struct serdatapool * pool) { DDS_TRACE("ddsi_serdatapool_free(%p)\n", (void *) pool); nn_freelist_fini (&pool->freelist, serdata_free_wrap); - os_free (pool); + ddsrt_free (pool); } static size_t alignup_size (size_t x, size_t a) @@ -77,7 +75,7 @@ static void *serdata_default_append (struct ddsi_serdata_default **d, size_t n) if ((*d)->pos + n > (*d)->size) { size_t size1 = alignup_size ((*d)->pos + n, 128); - *d = os_realloc (*d, offsetof (struct ddsi_serdata_default, data) + size1); + *d = ddsrt_realloc (*d, offsetof (struct ddsi_serdata_default, data) + size1); (*d)->size = (uint32_t)size1; } assert ((*d)->pos + n <= (*d)->size); @@ -205,7 +203,7 @@ static bool serdata_default_eqkey_nokey (const struct ddsi_serdata *acmn, const static void serdata_default_free(struct ddsi_serdata *dcmn) { struct ddsi_serdata_default *d = (struct ddsi_serdata_default *)dcmn; - assert(os_atomic_ld32(&d->c.refc) == 0); + assert(ddsrt_atomic_ld32(&d->c.refc) == 0); if (!nn_freelist_push (&gv.serpool->freelist, d)) dds_free (d); } @@ -227,7 +225,7 @@ static void serdata_default_init(struct ddsi_serdata_default *d, const struct dd static struct ddsi_serdata_default *serdata_default_allocnew(struct serdatapool *pool) { const uint32_t init_size = 128; - struct ddsi_serdata_default *d = os_malloc(offsetof (struct ddsi_serdata_default, data) + init_size); + struct ddsi_serdata_default *d = ddsrt_malloc(offsetof (struct ddsi_serdata_default, data) + init_size); d->size = init_size; d->pool = pool; return d; @@ -239,7 +237,7 @@ static struct ddsi_serdata_default *serdata_default_new(const struct ddsi_sertop if ((d = nn_freelist_pop (&gv.serpool->freelist)) == NULL) d = serdata_default_allocnew(gv.serpool); else - os_atomic_st32(&d->c.refc, 1); + ddsrt_atomic_st32(&d->c.refc, 1); serdata_default_init(d, tp, kind); return d; } @@ -478,17 +476,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, os_iovec_t *ref) +static struct ddsi_serdata *serdata_default_to_ser_ref (const struct ddsi_serdata *serdata_common, size_t off, size_t sz, ddsrt_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 = (os_iov_len_t)sz; + ref->iov_len = (ddsrt_iov_len_t)sz; return ddsi_serdata_ref(serdata_common); } -static void serdata_default_to_ser_unref (struct ddsi_serdata *serdata_common, const os_iovec_t *ref) +static void serdata_default_to_ser_unref (struct ddsi_serdata *serdata_common, const ddsrt_iovec_t *ref) { (void)ref; ddsi_serdata_unref(serdata_common); diff --git a/src/core/ddsi/src/ddsi_sertopic.c b/src/core/ddsi/src/ddsi_sertopic.c index f985e8e..be68930 100644 --- a/src/core/ddsi/src/ddsi_sertopic.c +++ b/src/core/ddsi/src/ddsi_sertopic.c @@ -14,20 +14,20 @@ #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include "ddsi/ddsi_sertopic.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/q_md5.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" +#include "dds/ddsi/ddsi_sertopic.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_md5.h" struct ddsi_sertopic *ddsi_sertopic_ref (const struct ddsi_sertopic *sertopic_const) { struct ddsi_sertopic *sertopic = (struct ddsi_sertopic *)sertopic_const; if (sertopic) - os_atomic_inc32 (&sertopic->refc); + ddsrt_atomic_inc32 (&sertopic->refc); return sertopic; } @@ -35,13 +35,13 @@ void ddsi_sertopic_unref (struct ddsi_sertopic *sertopic) { if (sertopic) { - if (os_atomic_dec32_ov (&sertopic->refc) == 1) + if (ddsrt_atomic_dec32_ov (&sertopic->refc) == 1) { ddsi_sertopic_deinit (sertopic); - os_free (sertopic->name_typename); - os_free (sertopic->name); - os_free (sertopic->typename); - os_free (sertopic); + ddsrt_free (sertopic->name_typename); + ddsrt_free (sertopic->name); + ddsrt_free (sertopic->typename); + ddsrt_free (sertopic); } } } diff --git a/src/core/ddsi/src/ddsi_sertopic_default.c b/src/core/ddsi/src/ddsi_sertopic_default.c index a87f6ed..be90044 100644 --- a/src/core/ddsi/src/ddsi_sertopic_default.c +++ b/src/core/ddsi/src/ddsi_sertopic_default.c @@ -14,13 +14,12 @@ #include #include -#include "os/os.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_config.h" -#include "ddsi/q_freelist.h" -#include "ddsi/ddsi_sertopic.h" -#include "ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_freelist.h" +#include "dds/ddsi/ddsi_sertopic.h" +#include "dds/ddsi/ddsi_serdata_default.h" /* FIXME: sertopic /= ddstopic so a lot of stuff needs to be moved here from dds_topic.c and the free function needs to be implemented properly */ diff --git a/src/core/ddsi/src/ddsi_ssl.c b/src/core/ddsi/src/ddsi_ssl.c index a6b5fdf..8ebb2f0 100644 --- a/src/core/ddsi/src/ddsi_ssl.c +++ b/src/core/ddsi/src/ddsi_ssl.c @@ -9,11 +9,10 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" -#include "ddsi/ddsi_tcp.h" -#include "ddsi/ddsi_ssl.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" +#include "dds/ddsi/ddsi_tcp.h" +#include "dds/ddsi/ddsi_ssl.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsrt/log.h" #ifdef DDSI_INCLUDE_SSL @@ -24,6 +23,11 @@ #include #include +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" + static SSL_CTX *ddsi_ssl_ctx = NULL; static SSL *ddsi_ssl_new (void) @@ -58,64 +62,80 @@ static int ddsi_ssl_verify (int ok, X509_STORE_CTX *store) return ok; } -static ssize_t ddsi_ssl_read (SSL *ssl, void *buf, size_t len, int *err) +static ssize_t ddsi_ssl_read (SSL *ssl, void *buf, size_t len, dds_retcode_t *rc) { assert (len <= INT32_MAX); if (SSL_get_shutdown (ssl) != 0) + { + *rc = DDS_RETCODE_ERROR; return -1; + } /* Returns -1 on error or 0 on shutdown */ - const int ret = SSL_read (ssl, buf, (int) len); - switch (SSL_get_error (ssl, ret)) + int rcvd = SSL_read (ssl, buf, (int) len); + switch (SSL_get_error (ssl, rcvd)) { case SSL_ERROR_NONE: - return ret; + *rc = DDS_RETCODE_OK; + break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: - *err = os_sockEAGAIN; - return -1; + *rc = DDS_RETCODE_TRY_AGAIN; + rcvd = -1; + break; case SSL_ERROR_ZERO_RETURN: default: /* Connection closed or error */ - *err = os_getErrno (); - return -1; + *rc = DDS_RETCODE_ERROR; + rcvd = -1; + break; } + + return rcvd; } -static ssize_t ddsi_ssl_write (SSL *ssl, const void *buf, size_t len, int *err) +static ssize_t ddsi_ssl_write (SSL *ssl, const void *buf, size_t len, dds_retcode_t *rc) { assert(len <= INT32_MAX); if (SSL_get_shutdown (ssl) != 0) + { + *rc = DDS_RETCODE_ERROR; return -1; + } /* Returns -1 on error or 0 on shutdown */ - const int ret = SSL_write (ssl, buf, (int) len); - switch (SSL_get_error (ssl, ret)) + int sent = SSL_write (ssl, buf, (int) len); + switch (SSL_get_error (ssl, sent)) { case SSL_ERROR_NONE: - return ret; + *rc = DDS_RETCODE_OK; + break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: - *err = os_sockEAGAIN; - return -1; + *rc = DDS_RETCODE_TRY_AGAIN; + sent = -1; + break; case SSL_ERROR_ZERO_RETURN: default: /* Connection closed or error */ - *err = os_getErrno (); - return -1; + *rc = DDS_RETCODE_ERROR; + sent = -1; + break; } + + return sent; } /* Standard OpenSSL init and thread support routines. See O'Reilly. */ #if OPENSSL_VERSION_NUMBER < 0x10100000L static unsigned long ddsi_ssl_id (void) { - return (unsigned long) os_threadIdToInteger (os_threadIdSelf ()); + return (unsigned long) ddsrt_gettid (); } typedef struct CRYPTO_dynlock_value { - os_mutex m_mutex; + ddsrt_mutex_t m_mutex; } CRYPTO_dynlock_value; static CRYPTO_dynlock_value *ddsi_ssl_locks = NULL; @@ -125,9 +145,9 @@ static void ddsi_ssl_dynlock_lock (int mode, CRYPTO_dynlock_value *lock, const c (void) file; (void) line; if (mode & CRYPTO_LOCK) - os_mutexLock (&lock->m_mutex); + ddsrt_mutex_lock (&lock->m_mutex); else - os_mutexUnlock (&lock->m_mutex); + ddsrt_mutex_unlock (&lock->m_mutex); } static void ddsi_ssl_lock (int mode, int n, const char *file, int line) @@ -139,8 +159,8 @@ static CRYPTO_dynlock_value *ddsi_ssl_dynlock_create (const char *file, int line { (void) file; (void) line; - CRYPTO_dynlock_value *val = os_malloc (sizeof (*val)); - os_mutexInit (&val->m_mutex); + CRYPTO_dynlock_value *val = ddsrt_malloc (sizeof (*val)); + ddsrt_mutex_init (&val->m_mutex); return val; } @@ -148,8 +168,8 @@ static void ddsi_ssl_dynlock_destroy (CRYPTO_dynlock_value *lock, const char *fi { (void) file; (void) line; - os_mutexDestroy (&lock->m_mutex); - os_free (lock); + ddsrt_mutex_destroy (&lock->m_mutex); + ddsrt_free (lock); } #endif @@ -159,9 +179,9 @@ static int ddsi_ssl_password (char *buf, int num, int rwflag, void *udata) (void) udata; if (num < 0 || (size_t) num < strlen (config.ssl_key_pass) + 1) return 0; - OS_WARNING_MSVC_OFF(4996); + DDSRT_WARNING_MSVC_OFF(4996); strcpy (buf, config.ssl_key_pass); - OS_WARNING_MSVC_ON(4996); + DDSRT_WARNING_MSVC_ON(4996); return (int) strlen (config.ssl_key_pass); } @@ -265,7 +285,7 @@ static void dds_report_tls_version (const SSL *ssl, const char *oper) } } -static SSL *ddsi_ssl_connect (os_socket sock) +static SSL *ddsi_ssl_connect (ddsrt_socket_t sock) { SSL *ssl; int err; @@ -275,9 +295,9 @@ static SSL *ddsi_ssl_connect (os_socket sock) safe to do so, and moreover, that it will remain safe to do so, given Microsoft's track record of maintaining backwards compatibility. The SSL API is in the wrong of course ... */ ssl = ddsi_ssl_new (); - OS_WARNING_MSVC_OFF(4244); + DDSRT_WARNING_MSVC_OFF(4244); SSL_set_fd (ssl, sock); - OS_WARNING_MSVC_ON(4244); + DDSRT_WARNING_MSVC_ON(4244); err = SSL_connect (ssl); if (err != 1) { @@ -289,17 +309,17 @@ static SSL *ddsi_ssl_connect (os_socket sock) return ssl; } -static BIO *ddsi_ssl_listen (os_socket sock) +static BIO *ddsi_ssl_listen (ddsrt_socket_t sock) { /* See comment in ddsi_ssl_connect concerning casting the socket to an int */ BIO * bio = BIO_new (BIO_s_accept ()); - OS_WARNING_MSVC_OFF(4244); + DDSRT_WARNING_MSVC_OFF(4244); BIO_set_fd (bio, sock, BIO_NOCLOSE); - OS_WARNING_MSVC_ON(4244); + DDSRT_WARNING_MSVC_ON(4244); return bio; } -static SSL *ddsi_ssl_accept (BIO *bio, os_socket *sock) +static SSL *ddsi_ssl_accept (BIO *bio, ddsrt_socket_t *sock) { SSL *ssl = NULL; BIO *nbio; @@ -308,14 +328,14 @@ static SSL *ddsi_ssl_accept (BIO *bio, os_socket *sock) if (BIO_do_accept (bio) > 0) { nbio = BIO_pop (bio); - *sock = (os_socket) BIO_get_fd (nbio, NULL); + *sock = (ddsrt_socket_t) BIO_get_fd (nbio, NULL); ssl = ddsi_ssl_new (); SSL_set_bio (ssl, nbio, nbio); err = SSL_accept (ssl); if (err <= 0) { SSL_free (ssl); - *sock = OS_INVALID_SOCKET; + *sock = DDSRT_INVALID_SOCKET; ssl = NULL; } } @@ -334,9 +354,9 @@ static bool ddsi_ssl_init (void) { const int locks = CRYPTO_num_locks (); assert (locks >= 0); - ddsi_ssl_locks = os_malloc (sizeof (CRYPTO_dynlock_value) * (size_t) locks); + ddsi_ssl_locks = ddsrt_malloc (sizeof (CRYPTO_dynlock_value) * (size_t) locks); for (int i = 0; i < locks; i++) - os_mutexInit (&ddsi_ssl_locks[i].m_mutex); + ddsrt_mutex_init (&ddsi_ssl_locks[i].m_mutex); } #endif /* Leave these in place: OpenSSL 1.1 defines them as no-op macros that not even reference the symbol, @@ -367,8 +387,8 @@ static void ddsi_ssl_fini (void) { const int locks = CRYPTO_num_locks (); for (int i = 0; i < locks; i++) - os_mutexDestroy (&ddsi_ssl_locks[i].m_mutex); - os_free (ddsi_ssl_locks); + ddsrt_mutex_destroy (&ddsi_ssl_locks[i].m_mutex); + ddsrt_free (ddsi_ssl_locks); } #endif } diff --git a/src/core/ddsi/src/ddsi_tcp.c b/src/core/ddsi/src/ddsi_tcp.c index 9cbdd0f..da89126 100644 --- a/src/core/ddsi/src/ddsi_tcp.c +++ b/src/core/ddsi/src/ddsi_tcp.c @@ -13,21 +13,23 @@ #include #include +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets.h" #include "ddsi_eth.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_tcp.h" -#include "ddsi/ddsi_ipaddr.h" -#include "util/ut_avl.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_entity.h" -#include "os/os.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tcp.h" +#include "dds/ddsi/ddsi_ipaddr.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_entity.h" #define INVALID_PORT (~0u) typedef struct ddsi_tran_factory * ddsi_tcp_factory_g_t; -static os_atomic_uint32_t ddsi_tcp_init_g = OS_ATOMIC_UINT32_INIT(0); +static ddsrt_atomic_uint32_t ddsi_tcp_init_g = DDSRT_ATOMIC_UINT32_INIT(0); #ifdef DDSI_INCLUDE_SSL static struct ddsi_ssl_plugins ddsi_tcp_ssl_plugin; @@ -49,10 +51,10 @@ static const char * ddsi_name = "tcp"; typedef struct ddsi_tcp_conn { struct ddsi_tran_conn m_base; - os_sockaddr_storage m_peer_addr; + struct sockaddr_storage m_peer_addr; uint32_t m_peer_port; - os_mutex m_mutex; - os_socket m_sock; + ddsrt_mutex_t m_mutex; + ddsrt_socket_t m_sock; #ifdef DDSI_INCLUDE_SSL SSL * m_ssl; #endif @@ -62,7 +64,7 @@ typedef struct ddsi_tcp_conn typedef struct ddsi_tcp_listener { struct ddsi_tran_listener m_base; - os_socket m_sock; + ddsrt_socket_t m_sock; #ifdef DDSI_INCLUDE_SSL BIO * m_bio; #endif @@ -75,8 +77,8 @@ static struct ddsi_tcp_conn ddsi_tcp_conn_client; static int ddsi_tcp_cmp_conn (const struct ddsi_tcp_conn *c1, const struct ddsi_tcp_conn *c2) { - const os_sockaddr *a1s = (os_sockaddr *)&c1->m_peer_addr; - const os_sockaddr *a2s = (os_sockaddr *)&c2->m_peer_addr; + const struct sockaddr *a1s = (struct sockaddr *)&c1->m_peer_addr; + const struct sockaddr *a2s = (struct sockaddr *)&c2->m_peer_addr; if (a1s->sa_family != a2s->sa_family) return (a1s->sa_family < a2s->sa_family) ? -1 : 1; else if (c1->m_peer_port != c2->m_peer_port) @@ -104,13 +106,13 @@ static const ut_avlTreedef_t ddsi_tcp_treedef = UT_AVL_TREEDEF_INITIALIZER_INDKE 0 ); -static os_mutex ddsi_tcp_cache_lock_g; +static ddsrt_mutex_t ddsi_tcp_cache_lock_g; static ut_avlTree_t ddsi_tcp_cache_g; static struct ddsi_tran_factory ddsi_tcp_factory_g; -static ddsi_tcp_conn_t ddsi_tcp_new_conn (os_socket, bool, os_sockaddr *); +static ddsi_tcp_conn_t ddsi_tcp_new_conn (ddsrt_socket_t, bool, struct sockaddr *); -static char *sockaddr_to_string_with_port (char *dst, size_t sizeof_dst, const os_sockaddr *src) +static char *sockaddr_to_string_with_port (char *dst, size_t sizeof_dst, const struct sockaddr *src) { nn_locator_t loc; ddsi_ipaddr_to_loc(&loc, src, src->sa_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6); @@ -143,42 +145,43 @@ static void ddsi_tcp_cache_dump (void) } */ -static unsigned short get_socket_port (os_socket socket) +static unsigned short get_socket_port (ddsrt_socket_t socket) { - os_sockaddr_storage addr; + struct sockaddr_storage addr; socklen_t addrlen = sizeof (addr); - if (getsockname (socket, (os_sockaddr *) &addr, &addrlen) < 0) - { - int err = os_getErrno(); - DDS_ERROR("ddsi_tcp_get_socket_port: getsockname errno %d\n", err); + dds_retcode_t ret; + + ret = ddsrt_getsockname(socket, (struct sockaddr *)&addr, &addrlen); + if (ret != DDS_RETCODE_OK) { + DDS_ERROR("ddsi_tcp_get_socket_port: ddsrt_getsockname retcode %d\n", ret); return 0; } - return os_sockaddr_get_port((os_sockaddr *)&addr); + return ddsrt_sockaddr_get_port((struct sockaddr *)&addr); } -static void ddsi_tcp_conn_set_socket (ddsi_tcp_conn_t conn, os_socket sock) +static void ddsi_tcp_conn_set_socket (ddsi_tcp_conn_t conn, ddsrt_socket_t sock) { conn->m_sock = sock; - conn->m_base.m_base.m_port = (sock == OS_INVALID_SOCKET) ? INVALID_PORT : get_socket_port (sock); + conn->m_base.m_base.m_port = (sock == DDSRT_INVALID_SOCKET) ? INVALID_PORT : get_socket_port (sock); } -static void ddsi_tcp_sock_free (os_socket sock, const char * msg) +static void ddsi_tcp_sock_free (ddsrt_socket_t sock, const char * msg) { - if (sock != OS_INVALID_SOCKET) + if (sock != DDSRT_INVALID_SOCKET) { if (msg) { - DDS_LOG(DDS_LC_TCP, "%s %s free socket %"PRIsock"\n", ddsi_name, msg, sock); + DDS_LOG(DDS_LC_TCP, "%s %s free socket %"PRIdSOCK"\n", ddsi_name, msg, sock); } - os_sockFree (sock); + ddsrt_close (sock); } } -static void ddsi_tcp_sock_new (os_socket * sock, unsigned short port) +static void ddsi_tcp_sock_new (ddsrt_socket_t * sock, unsigned short port) { if (make_socket (sock, port, true, true) != 0) { - *sock = OS_INVALID_SOCKET; + *sock = DDSRT_INVALID_SOCKET; } } @@ -186,27 +189,27 @@ static void ddsi_tcp_node_free (void * ptr) { ddsi_tcp_node_t node = (ddsi_tcp_node_t) ptr; ddsi_conn_free ((ddsi_tran_conn_t) node->m_conn); - os_free (node); + ddsrt_free (node); } -static void ddsi_tcp_conn_connect (ddsi_tcp_conn_t conn, const struct msghdr * msg) +static void ddsi_tcp_conn_connect (ddsi_tcp_conn_t conn, const ddsrt_msghdr_t * msg) { - int ret; char buff[DDSI_LOCSTRLEN]; - os_socket sock; + ddsrt_socket_t sock; + dds_retcode_t ret; ddsi_tcp_sock_new (&sock, 0); - if (sock != OS_INVALID_SOCKET) + if (sock != DDSRT_INVALID_SOCKET) { /* Attempt to connect, expected that may fail */ do { - ret = connect (sock, msg->msg_name, msg->msg_namelen); + ret = ddsrt_connect(sock, msg->msg_name, msg->msg_namelen); } - while ((ret == -1) && (os_getErrno() == os_sockEINTR)); + while (ret == DDS_RETCODE_INTERRUPTED); - if (ret != 0) + if (ret != DDS_RETCODE_OK) { ddsi_tcp_sock_free (sock, NULL); return; @@ -219,18 +222,18 @@ 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, OS_INVALID_SOCKET); + ddsi_tcp_conn_set_socket (conn, DDSRT_INVALID_SOCKET); return; } } #endif - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *) msg->msg_name); - DDS_LOG(DDS_LC_TCP, "%s connect socket %"PRIsock" port %u to %s\n", ddsi_name, sock, get_socket_port (sock), buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *) msg->msg_name); + DDS_LOG(DDS_LC_TCP, "%s connect socket %"PRIdSOCK" port %u to %s\n", ddsi_name, sock, get_socket_port (sock), buff); /* Also may need to receive on connection so add to waitset */ - os_sockSetNonBlocking (conn->m_sock, true); + (void)ddsrt_setsocknonblocking(conn->m_sock, true); assert (gv.n_recv_threads > 0); assert (gv.recv_threads[0].arg.mode == RTM_MANY); @@ -245,12 +248,12 @@ static void ddsi_tcp_cache_add (ddsi_tcp_conn_t conn, ut_avlIPath_t * path) ddsi_tcp_node_t node; char buff[DDSI_LOCSTRLEN]; - os_atomic_inc32 (&conn->m_base.m_count); + ddsrt_atomic_inc32 (&conn->m_base.m_count); /* If path set, then cache does not contain connection */ if (path) { - node = os_malloc (sizeof (*node)); + node = ddsrt_malloc (sizeof (*node)); node->m_conn = conn; ut_avlInsertIPath (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, node, path); } @@ -267,14 +270,14 @@ static void ddsi_tcp_cache_add (ddsi_tcp_conn_t conn, ut_avlIPath_t * path) } else { - node = os_malloc (sizeof (*node)); + node = ddsrt_malloc (sizeof (*node)); node->m_conn = conn; ut_avlInsert (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, node); } } - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&conn->m_peer_addr); - DDS_LOG(DDS_LC_TCP, "%s cache %s %s socket %"PRIsock" to %s\n", ddsi_name, action, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&conn->m_peer_addr); + DDS_LOG(DDS_LC_TCP, "%s cache %s %s socket %"PRIdSOCK" to %s\n", ddsi_name, action, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); } static void ddsi_tcp_cache_remove (ddsi_tcp_conn_t conn) @@ -283,16 +286,16 @@ static void ddsi_tcp_cache_remove (ddsi_tcp_conn_t conn) ddsi_tcp_node_t node; ut_avlDPath_t path; - os_mutexLock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_lock (&ddsi_tcp_cache_lock_g); node = ut_avlLookupDPath (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, conn, &path); if (node) { - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&conn->m_peer_addr); - DDS_LOG(DDS_LC_TCP, "%s cache removed socket %"PRIsock" to %s\n", ddsi_name, conn->m_sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&conn->m_peer_addr); + DDS_LOG(DDS_LC_TCP, "%s cache removed socket %"PRIdSOCK" to %s\n", ddsi_name, conn->m_sock, buff); ut_avlDeleteDPath (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, node, &path); ddsi_tcp_node_free (node); } - os_mutexUnlock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_unlock (&ddsi_tcp_cache_lock_g); } /* @@ -300,7 +303,7 @@ static void ddsi_tcp_cache_remove (ddsi_tcp_conn_t conn) create new connection. */ -static ddsi_tcp_conn_t ddsi_tcp_cache_find (const struct msghdr * msg) +static ddsi_tcp_conn_t ddsi_tcp_cache_find (const ddsrt_msghdr_t * msg) { ut_avlIPath_t path; ddsi_tcp_node_t node; @@ -308,12 +311,12 @@ static ddsi_tcp_conn_t ddsi_tcp_cache_find (const struct msghdr * msg) ddsi_tcp_conn_t ret = NULL; memset (&key, 0, sizeof (key)); - key.m_peer_port = os_sockaddr_get_port (msg->msg_name); + key.m_peer_port = ddsrt_sockaddr_get_port (msg->msg_name); memcpy (&key.m_peer_addr, msg->msg_name, msg->msg_namelen); /* Check cache for existing connection to target */ - os_mutexLock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_lock (&ddsi_tcp_cache_lock_g); node = ut_avlLookupIPath (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, &key, &path); if (node) { @@ -329,52 +332,49 @@ static ddsi_tcp_conn_t ddsi_tcp_cache_find (const struct msghdr * msg) } if (ret == NULL) { - ret = ddsi_tcp_new_conn (OS_INVALID_SOCKET, false, (os_sockaddr *)&key.m_peer_addr); + ret = ddsi_tcp_new_conn (DDSRT_INVALID_SOCKET, false, (struct sockaddr *)&key.m_peer_addr); ddsi_tcp_cache_add (ret, &path); } - os_mutexUnlock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_unlock (&ddsi_tcp_cache_lock_g); return ret; } -static ssize_t ddsi_tcp_conn_read_plain (ddsi_tcp_conn_t tcp, void * buf, size_t len, int * err) +static ssize_t ddsi_tcp_conn_read_plain (ddsi_tcp_conn_t tcp, void * buf, size_t len, dds_retcode_t *rc) { -OS_WARNING_MSVC_OFF(4267); - ssize_t ret = recv (tcp->m_sock, buf, len, 0); - *err = (ret == -1) ? os_getErrno () : 0; - return ret; -OS_WARNING_MSVC_ON(4267); + ssize_t rcvd = -1; + + assert(rc != NULL); + *rc = ddsrt_recv(tcp->m_sock, buf, len, 0, &rcvd); + + return (*rc == DDS_RETCODE_OK ? rcvd : -1); } #ifdef DDSI_INCLUDE_SSL -static ssize_t ddsi_tcp_conn_read_ssl (ddsi_tcp_conn_t tcp, void * buf, size_t len, int * err) +static ssize_t ddsi_tcp_conn_read_ssl (ddsi_tcp_conn_t tcp, void * buf, size_t len, dds_retcode_t *rc) { - return (ddsi_tcp_ssl_plugin.read) (tcp->m_ssl, buf, len, err); + return (ddsi_tcp_ssl_plugin.read) (tcp->m_ssl, buf, len, rc); } #endif -static bool ddsi_tcp_select (os_socket sock, bool read, size_t pos) +static bool ddsi_tcp_select (ddsrt_socket_t sock, bool read, size_t pos) { - int ret; + dds_retcode_t rc; fd_set fds; - os_time timeout; fd_set * rdset = read ? &fds : NULL; fd_set * wrset = read ? NULL : &fds; int64_t tval = read ? config.tcp_read_timeout : config.tcp_write_timeout; + int32_t ready = 0; FD_ZERO (&fds); FD_SET (sock, &fds); - timeout.tv_sec = (int) (tval / T_SECOND); - timeout.tv_nsec = (int) (tval % T_SECOND); DDS_LOG(DDS_LC_TCP, "%s blocked %s: sock %d\n", ddsi_name, read ? "read" : "write", (int) sock); - do - { - ret = os_sockSelect ((int32_t)sock + 1, rdset, wrset, NULL, &timeout); /* The variable "sock" with os_socket type causes the possible loss of data. So type casting done */ - } - while (ret == -1 && os_getErrno () == os_sockEINTR); + do { + rc = ddsrt_select (sock + 1, rdset, wrset, NULL, tval, &ready); + } while (rc == DDS_RETCODE_INTERRUPTED); - if (ret <= 0) + if (rc != DDS_RETCODE_OK) { DDS_WARNING ( @@ -383,25 +383,16 @@ static bool ddsi_tcp_select (os_socket sock, bool read, size_t pos) ); } - return (ret > 0); -} - -static int err_is_AGAIN_or_WOULDBLOCK (int err) -{ - if (err == os_sockEAGAIN) - return 1; - if (err == os_sockEWOULDBLOCK) - return 1; - return 0; + return (ready > 0); } static ssize_t ddsi_tcp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, bool allow_spurious, nn_locator_t *srcloc) { + dds_retcode_t rc; ddsi_tcp_conn_t tcp = (ddsi_tcp_conn_t) conn; ssize_t (*rd) (ddsi_tcp_conn_t, void *, size_t, int * err) = ddsi_tcp_conn_read_plain; size_t pos = 0; ssize_t n; - int err; #ifdef DDSI_INCLUDE_SSL if (ddsi_tcp_ssl_plugin.read) @@ -412,7 +403,7 @@ static ssize_t ddsi_tcp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s while (true) { - n = rd (tcp, (char *) buf + pos, len - pos, &err); + n = rd (tcp, (char *) buf + pos, len - pos, &rc); if (n > 0) { pos += (size_t) n; @@ -420,21 +411,21 @@ static ssize_t ddsi_tcp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s { if (srcloc) { - ddsi_ipaddr_to_loc(srcloc, (os_sockaddr *)&tcp->m_peer_addr, tcp->m_peer_addr.ss_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6); + ddsi_ipaddr_to_loc(srcloc, (struct sockaddr *)&tcp->m_peer_addr, tcp->m_peer_addr.ss_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6); } return (ssize_t) pos; } } else if (n == 0) { - DDS_LOG(DDS_LC_TCP, "%s read: sock %"PRIsock" closed-by-peer\n", ddsi_name, tcp->m_sock); + DDS_LOG(DDS_LC_TCP, "%s read: sock %"PRIdSOCK" closed-by-peer\n", ddsi_name, tcp->m_sock); break; } else { - if (err != os_sockEINTR) + if (rc != DDS_RETCODE_INTERRUPTED) { - if (err_is_AGAIN_or_WOULDBLOCK (err)) + if (rc == DDS_RETCODE_TRY_AGAIN) { if (allow_spurious && pos == 0) return 0; @@ -443,7 +434,7 @@ static ssize_t ddsi_tcp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s } else { - DDS_LOG(DDS_LC_TCP, "%s read: sock %"PRIsock" error %d\n", ddsi_name, tcp->m_sock, err); + DDS_LOG(DDS_LC_TCP, "%s read: sock %"PRIdSOCK" error %d\n", ddsi_name, tcp->m_sock, rc); break; } } @@ -454,25 +445,23 @@ static ssize_t ddsi_tcp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, s return -1; } -static ssize_t ddsi_tcp_conn_write_plain (ddsi_tcp_conn_t conn, const void * buf, size_t len, int * err) +static ssize_t ddsi_tcp_conn_write_plain (ddsi_tcp_conn_t conn, const void * buf, size_t len, dds_retcode_t *rc) { - ssize_t ret; + ssize_t sent = -1; int sendflags = 0; #ifdef MSG_NOSIGNAL sendflags |= MSG_NOSIGNAL; #endif -OS_WARNING_MSVC_OFF(4267); - ret = send (conn->m_sock, buf, len, sendflags); - *err = (ret == -1) ? os_getErrno () : 0; - return ret; - OS_WARNING_MSVC_ON(4267); + *rc = ddsrt_send(conn->m_sock, buf, len, sendflags, &sent); + + return (*rc == DDS_RETCODE_OK ? sent : -1); } #ifdef DDSI_INCLUDE_SSL -static ssize_t ddsi_tcp_conn_write_ssl (ddsi_tcp_conn_t conn, const void * buf, size_t len, int * err) +static ssize_t ddsi_tcp_conn_write_ssl (ddsi_tcp_conn_t conn, const void * buf, size_t len, dds_retcode_t *rc) { - return (ddsi_tcp_ssl_plugin.write) (conn->m_ssl, buf, len, err); + return (ddsi_tcp_ssl_plugin.write) (conn->m_ssl, buf, len, rc); } #endif @@ -486,23 +475,22 @@ static ssize_t ddsi_tcp_block_write { /* Write all bytes of buf even in the presence of signals, partial writes and blocking (typically write buffer full) */ - + dds_retcode_t rc; size_t pos = 0; - ssize_t n; - int err; + ssize_t n = -1; while (pos != sz) { - n = (wr) (conn, (const char *) buf + pos, sz - pos, &err); + n = (wr) (conn, (const char *) buf + pos, sz - pos, &rc); if (n > 0) { pos += (size_t) n; } else if (n == -1) { - if (err != os_sockEINTR) + if (rc != DDS_RETCODE_INTERRUPTED) { - if (err_is_AGAIN_or_WOULDBLOCK (err)) + if (rc == DDS_RETCODE_TRY_AGAIN) { if (ddsi_tcp_select (conn->m_sock, false, pos) == false) { @@ -511,7 +499,7 @@ static ssize_t ddsi_tcp_block_write } else { - DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIsock" error %d\n", ddsi_name, conn->m_sock, err); + DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIdSOCK" error %d\n", ddsi_name, conn->m_sock, rc); break; } } @@ -521,7 +509,7 @@ static ssize_t ddsi_tcp_block_write return (pos == sz) ? (ssize_t) pos : -1; } -static size_t iovlen_sum (size_t niov, const os_iovec_t *iov) +static size_t iovlen_sum (size_t niov, const ddsrt_iovec_t *iov) { size_t tot = 0; while (niov--) { @@ -530,32 +518,32 @@ static size_t iovlen_sum (size_t niov, const os_iovec_t *iov) return tot; } -static void set_msghdr_iov (struct msghdr *mhdr, os_iovec_t *iov, size_t iovlen) +static void set_msghdr_iov (ddsrt_msghdr_t *mhdr, ddsrt_iovec_t *iov, size_t iovlen) { mhdr->msg_iov = iov; - mhdr->msg_iovlen = (os_msg_iovlen_t)iovlen; + mhdr->msg_iovlen = (ddsrt_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 os_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 ddsrt_iovec_t *iov, uint32_t flags) { #ifdef DDSI_INCLUDE_SSL char msgbuf[4096]; /* stack buffer for merging smallish writes without requiring allocations */ - os_iovec_t iovec; /* iovec used for msgbuf */ + ddsrt_iovec_t iovec; /* iovec used for msgbuf */ #endif ssize_t ret; size_t len; ddsi_tcp_conn_t conn; int piecewise; bool connect = false; - struct msghdr msg; - os_sockaddr_storage dstaddr; + ddsrt_msghdr_t msg; + struct sockaddr_storage dstaddr; assert(niov <= INT_MAX); ddsi_ipaddr_from_loc(&dstaddr, dst); memset(&msg, 0, sizeof(msg)); - set_msghdr_iov (&msg, (os_iovec_t *) iov, niov); + set_msghdr_iov (&msg, (ddsrt_iovec_t *) iov, niov); msg.msg_name = &dstaddr; - msg.msg_namelen = (socklen_t) os_sockaddr_get_size((os_sockaddr *) &dstaddr); -#if OS_MSGHDR_FLAGS + msg.msg_namelen = (socklen_t) ddsrt_sockaddr_get_size((struct sockaddr *) &dstaddr); +#if DDSRT_MSGHDR_FLAGS msg.msg_flags = (int) flags; #endif len = iovlen_sum (niov, iov); @@ -567,16 +555,16 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d return -1; } - os_mutexLock (&conn->m_mutex); + ddsrt_mutex_lock (&conn->m_mutex); /* If not connected attempt to conect */ - if ((conn->m_sock == OS_INVALID_SOCKET) && ! conn->m_base.m_server) + if ((conn->m_sock == DDSRT_INVALID_SOCKET) && ! conn->m_base.m_server) { ddsi_tcp_conn_connect (conn, &msg); - if (conn->m_sock == OS_INVALID_SOCKET) + if (conn->m_sock == DDSRT_INVALID_SOCKET) { - os_mutexUnlock (&conn->m_mutex); + ddsrt_mutex_unlock (&conn->m_mutex); return -1; } connect = true; @@ -586,8 +574,8 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d if (!connect && ((flags & DDSI_TRAN_ON_CONNECT) != 0)) { - DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIsock" message filtered\n", ddsi_name, conn->m_sock); - os_mutexUnlock (&conn->m_mutex); + DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIdSOCK" message filtered\n", ddsi_name, conn->m_sock); + ddsrt_mutex_unlock (&conn->m_mutex); return (ssize_t) len; } @@ -602,8 +590,8 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d { int i; char * ptr; - iovec.iov_len = (os_iov_len_t) len; - iovec.iov_base = (len <= sizeof (msgbuf)) ? msgbuf : os_malloc (len); + iovec.iov_len = (ddsrt_iov_len_t) len; + iovec.iov_base = (len <= sizeof (msgbuf)) ? msgbuf : ddsrt_malloc (len); ptr = iovec.iov_base; for (i = 0; i < (int) msg.msg_iovlen; i++) { @@ -620,7 +608,7 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d #endif { int sendflags = 0; - int err; + dds_retcode_t rc; #ifdef MSG_NOSIGNAL sendflags |= MSG_NOSIGNAL; #endif @@ -628,13 +616,12 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d msg.msg_namelen = 0; do { - ret = sendmsg (conn->m_sock, &msg, sendflags); - err = (ret == -1) ? os_getErrno () : 0; + rc = ddsrt_sendmsg (conn->m_sock, &msg, sendflags, &ret); } - while ((ret == -1) && (err == os_sockEINTR)); + while (rc == DDS_RETCODE_INTERRUPTED); if (ret == -1) { - if (err_is_AGAIN_or_WOULDBLOCK (err)) + if (rc == DDS_RETCODE_TRY_AGAIN) { piecewise = 1; ret = 0; @@ -642,17 +629,15 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d else { piecewise = 0; - switch (err) + switch (rc) { - case os_sockECONNRESET: -#ifdef os_sockEPIPE - case os_sockEPIPE: -#endif - DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIsock" ECONNRESET\n", ddsi_name, conn->m_sock); + case DDS_RETCODE_NO_CONNECTION: + case DDS_RETCODE_ILLEGAL_OPERATION: + DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIdSOCK" DDS_RETCODE_NO_CONNECTION\n", ddsi_name, conn->m_sock); break; default: - if (! conn->m_base.m_closed && (conn->m_sock != OS_INVALID_SOCKET)) - DDS_WARNING("%s write failed on socket %"PRIsock" with errno %d\n", ddsi_name, conn->m_sock, err); + if (! conn->m_base.m_closed && (conn->m_sock != DDSRT_INVALID_SOCKET)) + DDS_WARNING("%s write failed on socket %"PRIdSOCK" with errno %d\n", ddsi_name, conn->m_sock, rc); break; } } @@ -661,7 +646,7 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d { if (ret == 0) { - DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIsock" eof\n", ddsi_name, conn->m_sock); + DDS_LOG(DDS_LC_TCP, "%s write: sock %"PRIdSOCK" eof\n", ddsi_name, conn->m_sock); } piecewise = (ret > 0 && (size_t) ret < len); } @@ -695,11 +680,11 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d /* If allocated memory for merging original fragments into a single buffer, free it */ if (msg.msg_iov == &iovec && iovec.iov_base != msgbuf) { - os_free (iovec.iov_base); + ddsrt_free (iovec.iov_base); } #endif - os_mutexUnlock (&conn->m_mutex); + ddsrt_mutex_unlock (&conn->m_mutex); if (ret == -1) { @@ -709,7 +694,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_socket ddsi_tcp_conn_handle (ddsi_tran_base_t base) +static ddsrt_socket_t ddsi_tcp_conn_handle (ddsi_tran_base_t base) { return ((ddsi_tcp_conn_t) base)->m_sock; } @@ -753,55 +738,56 @@ 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 = OS_INVALID_SOCKET; - os_sockaddr_storage addr; + ddsrt_socket_t sock = DDSRT_INVALID_SOCKET; + struct sockaddr_storage addr; socklen_t addrlen = sizeof (addr); char buff[DDSI_LOCSTRLEN]; - int err = 0; + dds_retcode_t rc = DDS_RETCODE_OK; #ifdef DDSI_INCLUDE_SSL SSL * ssl = NULL; #endif memset (&addr, 0, addrlen); - do - { + do { #ifdef DDSI_INCLUDE_SSL if (ddsi_tcp_ssl_plugin.accept) { ssl = (ddsi_tcp_ssl_plugin.accept) (tl->m_bio, &sock); + if (ssl == NULL) { + assert(sock == DDSRT_INVALID_SOCKET); + rc = DDS_RETCODE_ERROR; + } } else #endif { - sock = accept (tl->m_sock, NULL, NULL); + rc = ddsrt_accept(tl->m_sock, NULL, NULL, &sock); } if (! gv.rtps_keepgoing) { ddsi_tcp_sock_free (sock, NULL); return NULL; } - err = (sock == OS_INVALID_SOCKET) ? os_getErrno () : 0; - } - while ((err == os_sockEINTR) || (err == os_sockEAGAIN) || (err == os_sockEWOULDBLOCK)); + } while (rc == DDS_RETCODE_INTERRUPTED || rc == DDS_RETCODE_TRY_AGAIN); - if (sock == OS_INVALID_SOCKET) + if (sock == DDSRT_INVALID_SOCKET) { - getsockname (tl->m_sock, (struct sockaddr *) &addr, &addrlen); - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&addr); - DDS_LOG((err == 0) ? DDS_LC_ERROR : DDS_LC_FATAL, "%s accept failed on socket %"PRIsock" at %s errno %d\n", ddsi_name, tl->m_sock, buff, err); + (void)ddsrt_getsockname (tl->m_sock, (struct sockaddr *) &addr, &addrlen); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&addr); + DDS_LOG((rc == DDS_RETCODE_OK) ? DDS_LC_ERROR : DDS_LC_FATAL, "%s accept failed on socket %"PRIdSOCK" at %s retcode %d\n", ddsi_name, tl->m_sock, buff, rc); } else if (getpeername (sock, (struct sockaddr *) &addr, &addrlen) == -1) { - DDS_WARNING("%s accepted new socket %"PRIsock" on socket %"PRIsock" but no peer address, errno %d\n", ddsi_name, sock, tl->m_sock, os_getErrno()); - os_sockFree (sock); + DDS_WARNING("%s accepted new socket %"PRIdSOCK" on socket %"PRIdSOCK" but no peer address, errno %d\n", ddsi_name, sock, tl->m_sock, rc); + ddsrt_close (sock); } else { - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&addr); - DDS_LOG(DDS_LC_TCP, "%s accept new socket %"PRIsock" on socket %"PRIsock" from %s\n", ddsi_name, sock, tl->m_sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&addr); + DDS_LOG(DDS_LC_TCP, "%s accept new socket %"PRIdSOCK" on socket %"PRIdSOCK" from %s\n", ddsi_name, sock, tl->m_sock, buff); - os_sockSetNonBlocking (sock, true); - tcp = ddsi_tcp_new_conn (sock, true, (os_sockaddr *)&addr); + (void)ddsrt_setsocknonblocking (sock, true); + tcp = ddsi_tcp_new_conn (sock, true, (struct sockaddr *)&addr); #ifdef DDSI_INCLUDE_SSL tcp->m_ssl = ssl; #endif @@ -811,14 +797,14 @@ static ddsi_tran_conn_t ddsi_tcp_accept (ddsi_tran_listener_t listener) /* Add connection to cache for bi-dir */ - os_mutexLock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_lock (&ddsi_tcp_cache_lock_g); ddsi_tcp_cache_add (tcp, NULL); - os_mutexUnlock (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_unlock (&ddsi_tcp_cache_lock_g); } return tcp ? &tcp->m_base : NULL; } -static os_socket ddsi_tcp_listener_handle (ddsi_tran_base_t base) +static ddsrt_socket_t ddsi_tcp_listener_handle (ddsi_tran_base_t base) { return ((ddsi_tcp_listener_t) base)->m_sock; } @@ -833,8 +819,8 @@ 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 != 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); + assert (tc->m_sock != DDSRT_INVALID_SOCKET); + ddsi_ipaddr_to_loc (loc, (struct 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); } @@ -851,16 +837,16 @@ static void ddsi_tcp_base_init (struct ddsi_tran_conn * base) base->m_disable_multiplexing_fn = 0; } -static ddsi_tcp_conn_t ddsi_tcp_new_conn (os_socket sock, bool server, os_sockaddr * peer) +static ddsi_tcp_conn_t ddsi_tcp_new_conn (ddsrt_socket_t sock, bool server, struct sockaddr * peer) { - ddsi_tcp_conn_t conn = (ddsi_tcp_conn_t) os_malloc (sizeof (*conn)); + ddsi_tcp_conn_t conn = (ddsi_tcp_conn_t) ddsrt_malloc (sizeof (*conn)); memset (conn, 0, sizeof (*conn)); ddsi_tcp_base_init (&conn->m_base); - os_mutexInit (&conn->m_mutex); - 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); + ddsrt_mutex_init (&conn->m_mutex); + conn->m_sock = DDSRT_INVALID_SOCKET; + (void)memcpy(&conn->m_peer_addr, peer, ddsrt_sockaddr_get_size(peer)); + conn->m_peer_port = ddsrt_sockaddr_get_port (peer); conn->m_base.m_server = server; conn->m_base.m_base.m_port = INVALID_PORT; ddsi_tcp_conn_set_socket (conn, sock); @@ -871,8 +857,8 @@ static ddsi_tcp_conn_t ddsi_tcp_new_conn (os_socket sock, bool server, os_sockad static ddsi_tran_listener_t ddsi_tcp_create_listener (int port, ddsi_tran_qos_t qos) { char buff[DDSI_LOCSTRLEN]; - os_socket sock; - os_sockaddr_storage addr; + ddsrt_socket_t sock; + struct sockaddr_storage addr; socklen_t addrlen = sizeof (addr); ddsi_tcp_listener_t tl = NULL; @@ -880,9 +866,10 @@ 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 != OS_INVALID_SOCKET) + if (sock != DDSRT_INVALID_SOCKET) { - tl = (ddsi_tcp_listener_t) os_malloc (sizeof (*tl)); + dds_retcode_t ret; + tl = (ddsi_tcp_listener_t) ddsrt_malloc (sizeof (*tl)); memset (tl, 0, sizeof (*tl)); tl->m_sock = sock; @@ -896,17 +883,16 @@ static ddsi_tran_listener_t ddsi_tcp_create_listener (int port, ddsi_tran_qos_t tl->m_base.m_base.m_handle_fn = ddsi_tcp_listener_handle; tl->m_base.m_base.m_locator_fn = ddsi_tcp_locator; - if (getsockname (sock, (os_sockaddr *) &addr, &addrlen) == -1) - { - int err = os_getErrno (); - DDS_ERROR("ddsi_tcp_create_listener: getsockname errno %d\n", err); - ddsi_tcp_sock_free (sock, NULL); - os_free (tl); - return NULL; + ret = ddsrt_getsockname(sock, (struct sockaddr *)&addr, &addrlen); + if (ret != DDS_RETCODE_OK) { + DDS_ERROR("ddsi_tcp_create_listener: ddsrt_getsockname returned %d\n", ret); + ddsi_tcp_sock_free(sock, NULL); + ddsrt_free(tl); + return NULL; } - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&addr); - DDS_LOG(DDS_LC_TCP, "%s create listener socket %"PRIsock" on %s\n", ddsi_name, sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&addr); + DDS_LOG(DDS_LC_TCP, "%s create listener socket %"PRIdSOCK" on %s\n", ddsi_name, sock, buff); } return tl ? &tl->m_base : NULL; @@ -915,8 +901,8 @@ static ddsi_tran_listener_t ddsi_tcp_create_listener (int port, ddsi_tran_qos_t static void ddsi_tcp_conn_delete (ddsi_tcp_conn_t conn) { char buff[DDSI_LOCSTRLEN]; - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&conn->m_peer_addr); - DDS_LOG(DDS_LC_TCP, "%s free %s connnection on socket %"PRIsock" to %s\n", ddsi_name, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&conn->m_peer_addr); + DDS_LOG(DDS_LC_TCP, "%s free %s connnection on socket %"PRIdSOCK" to %s\n", ddsi_name, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); #ifdef DDSI_INCLUDE_SSL if (ddsi_tcp_ssl_plugin.ssl_free) @@ -928,8 +914,8 @@ static void ddsi_tcp_conn_delete (ddsi_tcp_conn_t conn) { ddsi_tcp_sock_free (conn->m_sock, "connection"); } - os_mutexDestroy (&conn->m_mutex); - os_free (conn); + ddsrt_mutex_destroy (&conn->m_mutex); + ddsrt_free (conn); } static void ddsi_tcp_close_conn (ddsi_tran_conn_t tc) @@ -939,10 +925,10 @@ static void ddsi_tcp_close_conn (ddsi_tran_conn_t tc) char buff[DDSI_LOCSTRLEN]; nn_locator_t loc; ddsi_tcp_conn_t conn = (ddsi_tcp_conn_t) tc; - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&conn->m_peer_addr); - DDS_LOG(DDS_LC_TCP, "%s close %s connnection on socket %"PRIsock" to %s\n", ddsi_name, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&conn->m_peer_addr); + DDS_LOG(DDS_LC_TCP, "%s close %s connnection on socket %"PRIdSOCK" to %s\n", ddsi_name, conn->m_base.m_server ? "server" : "client", conn->m_sock, buff); (void) shutdown (conn->m_sock, 2); - ddsi_ipaddr_to_loc(&loc, (os_sockaddr *)&conn->m_peer_addr, conn->m_peer_addr.ss_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6); + ddsi_ipaddr_to_loc(&loc, (struct sockaddr *)&conn->m_peer_addr, conn->m_peer_addr.ss_family == AF_INET ? NN_LOCATOR_KIND_TCPv4 : NN_LOCATOR_KIND_TCPv6); loc.port = conn->m_peer_port; purge_proxy_participants (&loc, conn->m_base.m_server); } @@ -959,34 +945,35 @@ static void ddsi_tcp_release_conn (ddsi_tran_conn_t conn) static void ddsi_tcp_unblock_listener (ddsi_tran_listener_t listener) { ddsi_tcp_listener_t tl = (ddsi_tcp_listener_t) listener; - os_socket sock; - int ret; + ddsrt_socket_t sock; + dds_retcode_t ret; /* Connect to own listener socket to wake listener from blocking 'accept()' */ ddsi_tcp_sock_new (&sock, 0); - if (sock != OS_INVALID_SOCKET) + if (sock != DDSRT_INVALID_SOCKET) { - os_sockaddr_storage addr; + struct sockaddr_storage addr; socklen_t addrlen = sizeof (addr); - if (getsockname (tl->m_sock, (os_sockaddr *) &addr, &addrlen) == -1) - DDS_WARNING("%s failed to get listener address error %d\n", ddsi_name, os_getErrno()); - else - { + + ret = ddsrt_getsockname(tl->m_sock, (struct sockaddr *)&addr, &addrlen); + if (ret != DDS_RETCODE_OK) { + DDS_WARNING("%s failed to get listener address error %d\n", ddsi_name, ret); + } else { switch (addr.ss_family) { case AF_INET: { - os_sockaddr_in *socketname = (os_sockaddr_in*)&addr; + struct sockaddr_in *socketname = (struct sockaddr_in*)&addr; if (socketname->sin_addr.s_addr == htonl (INADDR_ANY)) { socketname->sin_addr.s_addr = htonl (INADDR_LOOPBACK); } } break; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case AF_INET6: { - os_sockaddr_in6 *socketname = (os_sockaddr_in6*)&addr; - if (memcmp(&socketname->sin6_addr, &os_in6addr_any, sizeof(socketname->sin6_addr)) == 0) { - socketname->sin6_addr = os_in6addr_loopback; + struct sockaddr_in6 *socketname = (struct sockaddr_in6*)&addr; + if (memcmp(&socketname->sin6_addr, &ddsrt_in6addr_any, sizeof(socketname->sin6_addr)) == 0) { + socketname->sin6_addr = ddsrt_in6addr_loopback; } } break; @@ -994,14 +981,13 @@ static void ddsi_tcp_unblock_listener (ddsi_tran_listener_t listener) } do { - ret = connect (sock, (struct sockaddr *) &addr, (unsigned) os_sockaddr_get_size((os_sockaddr *)&addr)); - } - while ((ret == -1) && (os_getErrno() == os_sockEINTR)); - if (ret == -1) + ret = ddsrt_connect(sock, (struct sockaddr *)&addr, ddsrt_sockaddr_get_size((struct sockaddr *)&addr)); + } while (ret == DDS_RETCODE_INTERRUPTED); + if (ret != DDS_RETCODE_OK) { char buff[DDSI_LOCSTRLEN]; - sockaddr_to_string_with_port(buff, sizeof(buff), (os_sockaddr *)&addr); - DDS_WARNING("%s failed to connect to own listener (%s) error %d\n", ddsi_name, buff, os_getErrno()); + sockaddr_to_string_with_port(buff, sizeof(buff), (struct sockaddr *)&addr); + DDS_WARNING("%s failed to connect to own listener (%s) error %d\n", ddsi_name, buff, ret); } } ddsi_tcp_sock_free (sock, NULL); @@ -1018,14 +1004,14 @@ static void ddsi_tcp_release_listener (ddsi_tran_listener_t listener) } #endif ddsi_tcp_sock_free (tl->m_sock, "listener"); - os_free (tl); + ddsrt_free (tl); } static void ddsi_tcp_release_factory (void) { - if (os_atomic_dec32_nv (&ddsi_tcp_init_g) == 0) { + if (ddsrt_atomic_dec32_nv (&ddsi_tcp_init_g) == 0) { ut_avlFree (&ddsi_tcp_treedef, &ddsi_tcp_cache_g, ddsi_tcp_node_free); - os_mutexDestroy (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_destroy (&ddsi_tcp_cache_lock_g); #ifdef DDSI_INCLUDE_SSL if (ddsi_tcp_ssl_plugin.fini) { @@ -1062,7 +1048,7 @@ static enum ddsi_nearby_address_result ddsi_tcp_is_nearby_address (ddsi_tran_fac int ddsi_tcp_init (void) { - if (os_atomic_inc32_nv (&ddsi_tcp_init_g) == 1) + if (ddsrt_atomic_inc32_nv (&ddsi_tcp_init_g) == 1) { memset (&ddsi_tcp_factory_g, 0, sizeof (ddsi_tcp_factory_g)); ddsi_tcp_factory_g.m_kind = NN_LOCATOR_KIND_TCPv4; @@ -1085,7 +1071,7 @@ int ddsi_tcp_init (void) ddsi_tcp_factory_g.m_is_nearby_address_fn = ddsi_tcp_is_nearby_address; ddsi_factory_add (&ddsi_tcp_factory_g); -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6) { ddsi_tcp_factory_g.m_kind = NN_LOCATOR_KIND_TCPv6; @@ -1110,7 +1096,7 @@ int ddsi_tcp_init (void) #endif ut_avlInit (&ddsi_tcp_treedef, &ddsi_tcp_cache_g); - os_mutexInit (&ddsi_tcp_cache_lock_g); + ddsrt_mutex_init (&ddsi_tcp_cache_lock_g); DDS_LOG(DDS_LC_CONFIG, "%s initialized\n", ddsi_name); } diff --git a/src/core/ddsi/src/ddsi_tkmap.c b/src/core/ddsi/src/ddsi_tkmap.c index 1818f48..fbc6094 100644 --- a/src/core/ddsi/src/ddsi_tkmap.c +++ b/src/core/ddsi/src/ddsi_tkmap.c @@ -11,17 +11,20 @@ */ #include #include -#include "ddsi/q_thread.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_gc.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_config.h" -#include "ddsi/ddsi_iid.h" -#include "ddsi/ddsi_tkmap.h" -#include "util/ut_hopscotch.h" + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/ddsi_iid.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/util/ut_hopscotch.h" #include "dds__stream.h" -#include "os/os.h" -#include "ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_serdata.h" #define REFC_DELETE 0x80000000 #define REFC_MASK 0x0fffffff @@ -29,13 +32,13 @@ struct ddsi_tkmap { struct ut_chh * m_hh; - os_mutex m_lock; - os_cond m_cond; + ddsrt_mutex_t m_lock; + ddsrt_cond_t m_cond; }; static void gc_buckets_impl (struct gcreq *gcreq) { - os_free (gcreq->arg); + ddsrt_free (gcreq->arg); gcreq_free (gcreq); } @@ -85,8 +88,8 @@ struct ddsi_tkmap *ddsi_tkmap_new (void) { struct ddsi_tkmap *tkmap = dds_alloc (sizeof (*tkmap)); tkmap->m_hh = ut_chhNew (1, dds_tk_hash_void, dds_tk_equals_void, gc_buckets); - os_mutexInit (&tkmap->m_lock); - os_condInit (&tkmap->m_cond, &tkmap->m_lock); + ddsrt_mutex_init (&tkmap->m_lock); + ddsrt_cond_init (&tkmap->m_cond); return tkmap; } @@ -94,19 +97,19 @@ static void free_tkmap_instance (void *vtk, UNUSED_ARG(void *f_arg)) { struct ddsi_tkmap_instance *tk = vtk; ddsi_serdata_unref (tk->m_sample); - os_free (tk); + ddsrt_free (tk); } -void ddsi_tkmap_free (_Inout_ _Post_invalid_ struct ddsi_tkmap * map) +void ddsi_tkmap_free (struct ddsi_tkmap * map) { ut_chhEnumUnsafe (map->m_hh, free_tkmap_instance, NULL); ut_chhFree (map->m_hh); - os_condDestroy (&map->m_cond); - os_mutexDestroy (&map->m_lock); + ddsrt_cond_destroy (&map->m_cond); + ddsrt_mutex_destroy (&map->m_lock); dds_free (map); } -uint64_t ddsi_tkmap_lookup (_In_ struct ddsi_tkmap * map, _In_ const struct ddsi_serdata * sd) +uint64_t ddsi_tkmap_lookup (struct ddsi_tkmap * map, const struct ddsi_serdata * sd) { struct ddsi_tkmap_instance dummy; struct ddsi_tkmap_instance * tk; @@ -116,8 +119,7 @@ uint64_t ddsi_tkmap_lookup (_In_ struct ddsi_tkmap * map, _In_ const struct ddsi return (tk) ? tk->m_iid : DDS_HANDLE_NIL; } -_Check_return_ -struct ddsi_tkmap_instance *ddsi_tkmap_find_by_id (_In_ struct ddsi_tkmap *map, _In_ uint64_t iid) +struct ddsi_tkmap_instance *ddsi_tkmap_find_by_id (struct ddsi_tkmap *map, uint64_t iid) { /* This is not a function that should be used liberally, as it linearly scans the key-to-iid map. */ struct ut_chhIter it; @@ -130,7 +132,7 @@ struct ddsi_tkmap_instance *ddsi_tkmap_find_by_id (_In_ struct ddsi_tkmap *map, if (tk == NULL) /* Common case of it not existing at all */ return NULL; - else if (!((refc = os_atomic_ld32 (&tk->m_refc)) & REFC_DELETE) && os_atomic_cas32 (&tk->m_refc, refc, refc+1)) + else if (!((refc = ddsrt_atomic_ld32 (&tk->m_refc)) & REFC_DELETE) && ddsrt_atomic_cas32 (&tk->m_refc, refc, refc+1)) /* Common case of it existing, not in the process of being deleted and no one else concurrently modifying the refcount */ return tk; else @@ -150,11 +152,11 @@ struct ddsi_tkmap_instance *ddsi_tkmap_find_by_id (_In_ struct ddsi_tkmap *map, #define DDS_DEBUG_KEYHASH 1 #endif -_Check_return_ -struct ddsi_tkmap_instance * ddsi_tkmap_find( - _In_ struct ddsi_serdata * sd, - _In_ const bool rd, - _In_ const bool create) +struct ddsi_tkmap_instance * +ddsi_tkmap_find( + struct ddsi_serdata * sd, + const bool rd, + const bool create) { struct ddsi_tkmap_instance dummy; struct ddsi_tkmap_instance * tk; @@ -166,19 +168,19 @@ retry: if ((tk = ut_chhLookup(map->m_hh, &dummy)) != NULL) { uint32_t new; - new = os_atomic_inc32_nv(&tk->m_refc); + new = ddsrt_atomic_inc32_nv(&tk->m_refc); if (new & REFC_DELETE) { /* for the unlikely case of spinning 2^31 times across all threads ... */ - os_atomic_dec32(&tk->m_refc); + ddsrt_atomic_dec32(&tk->m_refc); /* simplest action would be to just spin, but that can potentially take a long time; we can block until someone signals some entry is removed from the map if we take some lock & wait for some condition */ - os_mutexLock(&map->m_lock); - while ((tk = ut_chhLookup(map->m_hh, &dummy)) != NULL && (os_atomic_ld32(&tk->m_refc) & REFC_DELETE)) - os_condWait(&map->m_cond, &map->m_lock); - os_mutexUnlock(&map->m_lock); + ddsrt_mutex_lock(&map->m_lock); + while ((tk = ut_chhLookup(map->m_hh, &dummy)) != NULL && (ddsrt_atomic_ld32(&tk->m_refc) & REFC_DELETE)) + ddsrt_cond_wait(&map->m_cond, &map->m_lock); + ddsrt_mutex_unlock(&map->m_lock); goto retry; } } @@ -188,7 +190,7 @@ retry: return NULL; tk->m_sample = ddsi_serdata_to_topicless (sd); - os_atomic_st32 (&tk->m_refc, 1); + ddsrt_atomic_st32 (&tk->m_refc, 1); tk->m_iid = ddsi_iid_gen (); if (!ut_chhAdd (map->m_hh, tk)) { @@ -206,23 +208,22 @@ retry: return tk; } -_Check_return_ -struct ddsi_tkmap_instance * ddsi_tkmap_lookup_instance_ref (_In_ struct ddsi_serdata * sd) +struct ddsi_tkmap_instance * ddsi_tkmap_lookup_instance_ref (struct ddsi_serdata * sd) { return ddsi_tkmap_find (sd, true, true); } -void ddsi_tkmap_instance_ref (_In_ struct ddsi_tkmap_instance *tk) +void ddsi_tkmap_instance_ref (struct ddsi_tkmap_instance *tk) { - os_atomic_inc32 (&tk->m_refc); + ddsrt_atomic_inc32 (&tk->m_refc); } -void ddsi_tkmap_instance_unref (_In_ struct ddsi_tkmap_instance * tk) +void ddsi_tkmap_instance_unref (struct ddsi_tkmap_instance * tk) { uint32_t old, new; assert (vtime_awake_p(lookup_thread_state()->vtime)); do { - old = os_atomic_ld32(&tk->m_refc); + old = ddsrt_atomic_ld32(&tk->m_refc); if (old == 1) new = REFC_DELETE; else @@ -230,7 +231,7 @@ void ddsi_tkmap_instance_unref (_In_ struct ddsi_tkmap_instance * tk) assert(!(old & REFC_DELETE)); new = old - 1; } - } while (!os_atomic_cas32(&tk->m_refc, old, new)); + } while (!ddsrt_atomic_cas32(&tk->m_refc, old, new)); if (new == REFC_DELETE) { struct ddsi_tkmap *map = gv.m_tkmap; @@ -241,9 +242,9 @@ void ddsi_tkmap_instance_unref (_In_ struct ddsi_tkmap_instance * tk) (void)removed; /* Signal any threads blocked in their retry loops in lookup */ - os_mutexLock(&map->m_lock); - os_condBroadcast(&map->m_cond); - os_mutexUnlock(&map->m_lock); + ddsrt_mutex_lock(&map->m_lock); + ddsrt_cond_broadcast(&map->m_cond); + ddsrt_mutex_unlock(&map->m_lock); /* Schedule freeing of memory until after all those who may have found a pointer have progressed to where they no longer hold that pointer */ diff --git a/src/core/ddsi/src/ddsi_tran.c b/src/core/ddsi/src/ddsi_tran.c index 31c5276..1d07228 100644 --- a/src/core/ddsi/src/ddsi_tran.c +++ b/src/core/ddsi/src/ddsi_tran.c @@ -10,12 +10,15 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include #include #include -#include "os/os.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" static ddsi_tran_factory_t ddsi_tran_factories = NULL; @@ -23,16 +26,16 @@ extern inline uint32_t ddsi_conn_type (ddsi_tran_conn_t conn); extern inline uint32_t ddsi_conn_port (ddsi_tran_conn_t conn); extern inline ddsi_tran_listener_t ddsi_factory_create_listener (ddsi_tran_factory_t factory, int port, ddsi_tran_qos_t qos); extern inline bool ddsi_factory_supports (ddsi_tran_factory_t factory, int32_t kind); -extern inline os_socket ddsi_conn_handle (ddsi_tran_conn_t conn); +extern inline ddsrt_socket_t ddsi_conn_handle (ddsi_tran_conn_t conn); extern inline int ddsi_conn_locator (ddsi_tran_conn_t conn, nn_locator_t * loc); -extern inline os_socket ddsi_tran_handle (ddsi_tran_base_t base); +extern inline ddsrt_socket_t ddsi_tran_handle (ddsi_tran_base_t base); extern inline ddsi_tran_conn_t ddsi_factory_create_conn (ddsi_tran_factory_t factory, uint32_t port, ddsi_tran_qos_t qos); extern inline int ddsi_tran_locator (ddsi_tran_base_t base, nn_locator_t * loc); extern inline int ddsi_listener_locator (ddsi_tran_listener_t listener, nn_locator_t * loc); extern inline int ddsi_listener_listen (ddsi_tran_listener_t listener); extern inline ddsi_tran_conn_t ddsi_listener_accept (ddsi_tran_listener_t listener); extern inline ssize_t ddsi_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, bool allow_spurious, nn_locator_t *srcloc); -extern inline 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); +extern inline ssize_t ddsi_conn_write (ddsi_tran_conn_t conn, const nn_locator_t *dst, size_t niov, const ddsrt_iovec_t *iov, uint32_t flags); void ddsi_factory_add (ddsi_tran_factory_t factory) { @@ -115,7 +118,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) != OS_INVALID_SOCKET) + if (ddsi_conn_handle (conn) != DDSRT_INVALID_SOCKET) { unsigned i; for (i = 0; i < gv.n_recv_threads; i++) @@ -142,7 +145,7 @@ void ddsi_conn_free (ddsi_tran_conn_t conn) (conn->m_factory->m_close_conn_fn) (conn); } } - if (os_atomic_dec32_ov (&conn->m_count) == 1) + if (ddsrt_atomic_dec32_ov (&conn->m_count) == 1) { (conn->m_factory->m_release_conn_fn) (conn); } @@ -151,12 +154,12 @@ void ddsi_conn_free (ddsi_tran_conn_t conn) void ddsi_conn_add_ref (ddsi_tran_conn_t conn) { - os_atomic_inc32 (&conn->m_count); + ddsrt_atomic_inc32 (&conn->m_count); } void ddsi_factory_conn_init (ddsi_tran_factory_t factory, ddsi_tran_conn_t conn) { - os_atomic_st32 (&conn->m_count, 1); + ddsrt_atomic_st32 (&conn->m_count, 1); conn->m_connless = factory->m_connless; conn->m_stream = factory->m_stream; conn->m_factory = factory; @@ -181,7 +184,7 @@ bool ddsi_conn_peer_locator (ddsi_tran_conn_t conn, nn_locator_t * loc) void ddsi_tran_free_qos (ddsi_tran_qos_t qos) { - os_free (qos); + ddsrt_free (qos); } int ddsi_conn_join_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const nn_locator_t *mcloc, const struct nn_interface *interf) @@ -197,7 +200,7 @@ int ddsi_conn_leave_mc (ddsi_tran_conn_t conn, const nn_locator_t *srcloc, const ddsi_tran_qos_t ddsi_tran_create_qos (void) { ddsi_tran_qos_t qos; - qos = (ddsi_tran_qos_t) os_malloc (sizeof (*qos)); + qos = (ddsi_tran_qos_t) ddsrt_malloc (sizeof (*qos)); memset (qos, 0, sizeof (*qos)); return qos; } @@ -243,7 +246,9 @@ int ddsi_is_mcaddr (const nn_locator_t *loc) int ddsi_is_ssm_mcaddr (const nn_locator_t *loc) { ddsi_tran_factory_t tran = ddsi_factory_find_supported_kind(loc->kind); - return tran ? tran->m_is_ssm_mcaddr_fn (tran, loc) : 0; + if (tran && tran->m_is_ssm_mcaddr_fn != 0) + return tran->m_is_ssm_mcaddr_fn (tran, loc); + return 0; } enum ddsi_nearby_address_result ddsi_is_nearby_address (const nn_locator_t *loc, size_t ninterf, const struct nn_interface interf[]) @@ -300,7 +305,7 @@ char *ddsi_locator_to_string_no_port (char *dst, size_t sizeof_dst, const nn_loc return dst; } -int ddsi_enumerate_interfaces (ddsi_tran_factory_t factory, os_ifaddrs_t **interfs) +int ddsi_enumerate_interfaces (ddsi_tran_factory_t factory, ddsrt_ifaddrs_t **interfs) { return factory->m_enumerate_interfaces_fn (factory, interfs); } diff --git a/src/core/ddsi/src/ddsi_udp.c b/src/core/ddsi/src/ddsi_udp.c index 590c9f8..8c2f925 100644 --- a/src/core/ddsi/src/ddsi_udp.c +++ b/src/core/ddsi/src/ddsi_udp.c @@ -11,17 +11,19 @@ */ #include #include -#include "os/os.h" -#include "os/os_atomics.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets.h" #include "ddsi_eth.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_udp.h" -#include "ddsi/ddsi_ipaddr.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_pcap.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_udp.h" +#include "dds/ddsi/ddsi_ipaddr.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_pcap.h" extern void ddsi_factory_conn_init (ddsi_tran_factory_t factory, ddsi_tran_conn_t conn); @@ -36,8 +38,8 @@ typedef struct ddsi_udp_config typedef struct ddsi_udp_conn { struct ddsi_tran_conn m_base; - os_socket m_sock; -#if defined _WIN32 && !defined WINCE + ddsrt_socket_t m_sock; +#if defined _WIN32 WSAEVENT m_sockEvent; #endif int m_diffserv; @@ -46,134 +48,125 @@ typedef struct ddsi_udp_conn static struct ddsi_udp_config ddsi_udp_config_g; static struct ddsi_tran_factory ddsi_udp_factory_g; -static os_atomic_uint32_t ddsi_udp_init_g = OS_ATOMIC_UINT32_INIT(0); +static ddsrt_atomic_uint32_t ddsi_udp_init_g = DDSRT_ATOMIC_UINT32_INIT(0); static ssize_t ddsi_udp_conn_read (ddsi_tran_conn_t conn, unsigned char * buf, size_t len, bool allow_spurious, nn_locator_t *srcloc) { - int err; - ssize_t ret; - struct msghdr msghdr; - os_sockaddr_storage src; - os_iovec_t msg_iov; + dds_retcode_t rc; + ssize_t ret = 0; + ddsrt_msghdr_t msghdr; + struct sockaddr_storage src; + ddsrt_iovec_t msg_iov; socklen_t srclen = (socklen_t) sizeof (src); (void) allow_spurious; msg_iov.iov_base = (void*) buf; - msg_iov.iov_len = (os_iov_len_t)len; /* Windows uses unsigned, POSIX (except Linux) int */ + msg_iov.iov_len = (ddsrt_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 +#if defined(__sun) && !defined(_XPG4_2) msghdr.msg_accrights = NULL; msghdr.msg_accrightslen = 0; +#else + msghdr.msg_control = NULL; + msghdr.msg_controllen = 0; #endif do { - ret = recvmsg(((ddsi_udp_conn_t) conn)->m_sock, &msghdr, 0); - err = (ret == -1) ? os_getErrno() : 0; - } while (err == os_sockEINTR); + rc = ddsrt_recvmsg(((ddsi_udp_conn_t) conn)->m_sock, &msghdr, 0, &ret); + } while (rc == DDS_RETCODE_INTERRUPTED); if (ret > 0) { if (srcloc) - ddsi_ipaddr_to_loc(srcloc, (os_sockaddr *)&src, src.ss_family == AF_INET ? NN_LOCATOR_KIND_UDPv4 : NN_LOCATOR_KIND_UDPv6); + ddsi_ipaddr_to_loc(srcloc, (struct sockaddr *)&src, src.ss_family == AF_INET ? NN_LOCATOR_KIND_UDPv4 : NN_LOCATOR_KIND_UDPv6); /* Check for udp packet truncation */ if ((((size_t) ret) > len) -#if OS_MSGHDR_FLAGS +#if DDSRT_MSGHDR_FLAGS || (msghdr.msg_flags & MSG_TRUNC) #endif ) { char addrbuf[DDSI_LOCSTRLEN]; nn_locator_t tmp; - ddsi_ipaddr_to_loc(&tmp, (os_sockaddr *)&src, src.ss_family == AF_INET ? NN_LOCATOR_KIND_UDPv4 : NN_LOCATOR_KIND_UDPv6); + ddsi_ipaddr_to_loc(&tmp, (struct sockaddr *)&src, src.ss_family == AF_INET ? NN_LOCATOR_KIND_UDPv4 : NN_LOCATOR_KIND_UDPv6); ddsi_locator_to_string(addrbuf, sizeof(addrbuf), &tmp); DDS_WARNING("%s => %d truncated to %d\n", addrbuf, (int)ret, (int)len); } } - else if (err != os_sockENOTSOCK && err != os_sockECONNRESET) + else if (rc != DDS_RETCODE_BAD_PARAMETER && + rc != DDS_RETCODE_NO_CONNECTION) { - DDS_ERROR("UDP recvmsg sock %d: ret %d errno %d\n", (int) ((ddsi_udp_conn_t) conn)->m_sock, (int) ret, err); + DDS_ERROR("UDP recvmsg sock %d: ret %d retcode %d\n", (int) ((ddsi_udp_conn_t) conn)->m_sock, (int) ret, rc); + ret = -1; } return ret; } -static void set_msghdr_iov (struct msghdr *mhdr, os_iovec_t *iov, size_t iovlen) +static void set_msghdr_iov (ddsrt_msghdr_t *mhdr, ddsrt_iovec_t *iov, size_t iovlen) { mhdr->msg_iov = iov; - mhdr->msg_iovlen = (os_msg_iovlen_t)iovlen; + mhdr->msg_iovlen = (ddsrt_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 os_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 ddsrt_iovec_t *iov, uint32_t flags) { - int err; + dds_retcode_t rc; ssize_t ret; unsigned retry = 2; int sendflags = 0; - struct msghdr msg; - os_sockaddr_storage dstaddr; + ddsrt_msghdr_t msg; + struct sockaddr_storage dstaddr; assert(niov <= INT_MAX); ddsi_ipaddr_from_loc(&dstaddr, dst); - set_msghdr_iov (&msg, (os_iovec_t *) iov, niov); + set_msghdr_iov (&msg, (ddsrt_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_namelen = (socklen_t) ddsrt_sockaddr_get_size((struct sockaddr *) &dstaddr); +#if defined(__sun) && !defined(_XPG4_2) msg.msg_accrights = NULL; msg.msg_accrightslen = 0; +#else + msg.msg_control = NULL; + msg.msg_controllen = 0; #endif -#if OS_MSGHDR_FLAGS +#if DDSRT_MSGHDR_FLAGS msg.msg_flags = (int) flags; #else - OS_UNUSED_ARG(flags); + DDSRT_UNUSED_ARG(flags); #endif #ifdef MSG_NOSIGNAL sendflags |= MSG_NOSIGNAL; #endif do { ddsi_udp_conn_t uc = (ddsi_udp_conn_t) conn; - ret = sendmsg (uc->m_sock, &msg, sendflags); - err = (ret == -1) ? os_getErrno() : 0; + rc = ddsrt_sendmsg (uc->m_sock, &msg, sendflags, &ret); #if defined _WIN32 && !defined WINCE - if (err == os_sockEWOULDBLOCK) { + if (rc == DDS_RETCODE_TRY_AGAIN) { WSANETWORKEVENTS ev; WaitForSingleObject(uc->m_sockEvent, INFINITE); WSAEnumNetworkEvents(uc->m_sock, uc->m_sockEvent, &ev); } #endif - } while (err == os_sockEINTR || err == os_sockEWOULDBLOCK || (err == os_sockEPERM && retry-- > 0)); + } while ((rc == DDS_RETCODE_INTERRUPTED) || + (rc == DDS_RETCODE_TRY_AGAIN) || + (rc == DDS_RETCODE_NOT_ALLOWED && retry-- > 0)); if (ret > 0 && gv.pcap_fp) { - os_sockaddr_storage sa; + struct sockaddr_storage sa; socklen_t alen = sizeof (sa); - if (getsockname (((ddsi_udp_conn_t) conn)->m_sock, (struct sockaddr *) &sa, &alen) == -1) + if (ddsrt_getsockname (((ddsi_udp_conn_t) conn)->m_sock, (struct sockaddr *) &sa, &alen) != DDS_RETCODE_OK) memset(&sa, 0, sizeof(sa)); write_pcap_sent (gv.pcap_fp, now (), &sa, &msg, (size_t) ret); } - else if (ret == -1) + else if (rc != DDS_RETCODE_OK && + rc != DDS_RETCODE_NOT_ALLOWED && + rc != DDS_RETCODE_NO_CONNECTION) { - switch (err) - { - case os_sockEPERM: - case os_sockECONNRESET: -#ifdef os_sockENETUNREACH - case os_sockENETUNREACH: -#endif -#ifdef os_sockEHOSTUNREACH - case os_sockEHOSTUNREACH: -#endif - break; - default: - DDS_ERROR("ddsi_udp_conn_write failed with error code %d", err); - } + DDS_ERROR("ddsi_udp_conn_write failed with retcode %d", rc); } return ret; } @@ -190,7 +183,7 @@ static void ddsi_udp_disable_multiplexing (ddsi_tran_conn_t base) #endif } -static os_socket ddsi_udp_conn_handle (ddsi_tran_base_t base) +static ddsrt_socket_t ddsi_udp_conn_handle (ddsi_tran_base_t base) { return ((ddsi_udp_conn_t) base)->m_sock; } @@ -206,7 +199,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 != OS_INVALID_SOCKET) + if (uc->m_sock != DDSRT_INVALID_SOCKET) { loc->kind = ddsi_udp_factory_g.m_kind; loc->port = uc->m_base.m_base.m_port; @@ -216,18 +209,20 @@ static int ddsi_udp_conn_locator (ddsi_tran_base_t base, nn_locator_t *loc) return ret; } -static unsigned short get_socket_port (os_socket socket) +static unsigned short get_socket_port (ddsrt_socket_t socket) { - os_sockaddr_storage addr; + dds_retcode_t ret; + struct sockaddr_storage addr; socklen_t addrlen = sizeof (addr); - if (getsockname (socket, (os_sockaddr *) &addr, &addrlen) < 0) + + ret = ddsrt_getsockname (socket, (struct sockaddr *)&addr, &addrlen); + if (ret != DDS_RETCODE_OK) { - int err = os_getErrno(); - DDS_ERROR("ddsi_udp_get_socket_port: getsockname errno %d\n", err); + DDS_ERROR("ddsi_udp_get_socket_port: getsockname returned %d\n", ret); return 0; } - return os_sockaddr_get_port((os_sockaddr *)&addr); + return ddsrt_sockaddr_get_port((struct sockaddr *)&addr); } static ddsi_tran_conn_t ddsi_udp_create_conn @@ -237,7 +232,7 @@ static ddsi_tran_conn_t ddsi_udp_create_conn ) { int ret; - os_socket sock; + ddsrt_socket_t sock; ddsi_udp_conn_t uc = NULL; bool mcast = (bool) (qos ? qos->m_multicast : false); @@ -253,7 +248,7 @@ static ddsi_tran_conn_t ddsi_udp_create_conn if (ret == 0) { - uc = (ddsi_udp_conn_t) os_malloc (sizeof (*uc)); + uc = (ddsi_udp_conn_t) ddsrt_malloc (sizeof (*uc)); memset (uc, 0, sizeof (*uc)); uc->m_sock = sock; @@ -276,7 +271,7 @@ static ddsi_tran_conn_t ddsi_udp_create_conn DDS_TRACE ( - "ddsi_udp_create_conn %s socket %"PRIsock" port %u\n", + "ddsi_udp_create_conn %s socket %"PRIdSOCK" port %u\n", mcast ? "multicast" : "unicast", uc->m_sock, uc->m_base.m_base.m_port @@ -284,11 +279,10 @@ static ddsi_tran_conn_t ddsi_udp_create_conn #ifdef DDSI_INCLUDE_NETWORK_CHANNELS if ((uc->m_diffserv != 0) && (ddsi_udp_factory_g.m_kind == NN_LOCATOR_KIND_UDPv4)) { - if (os_sockSetsockopt (sock, IPPROTO_IP, IP_TOS, (char*) &uc->m_diffserv, sizeof (uc->m_diffserv)) != os_resultSuccess) - { - int err = os_getErrno(); - DDS_ERROR("ddsi_udp_create_conn: set diffserv error %d\n", err); - } + dds_retcode_t rc; + rc = ddsrt_setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&uc->m_diffserv, sizeof(uc->m_diffserv)); + if (rc != DDS_RETCODE_OK) + DDS_ERROR("ddsi_udp_create_conn: set diffserv retcode %d\n", rc); } #endif } @@ -308,42 +302,42 @@ static ddsi_tran_conn_t ddsi_udp_create_conn return uc ? &uc->m_base : NULL; } -static int joinleave_asm_mcgroup (os_socket socket, int join, const nn_locator_t *mcloc, const struct nn_interface *interf) +static int joinleave_asm_mcgroup (ddsrt_socket_t socket, int join, const nn_locator_t *mcloc, const struct nn_interface *interf) { - os_result rc; - os_sockaddr_storage mcip; + dds_retcode_t rc; + struct sockaddr_storage mcip; ddsi_ipaddr_from_loc(&mcip, mcloc); -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_UDP6) { - os_ipv6_mreq ipv6mreq; + struct ipv6_mreq ipv6mreq; memset (&ipv6mreq, 0, sizeof (ipv6mreq)); - memcpy (&ipv6mreq.ipv6mr_multiaddr, &((os_sockaddr_in6 *) &mcip)->sin6_addr, sizeof (ipv6mreq.ipv6mr_multiaddr)); + memcpy (&ipv6mreq.ipv6mr_multiaddr, &((struct sockaddr_in6 *) &mcip)->sin6_addr, sizeof (ipv6mreq.ipv6mr_multiaddr)); ipv6mreq.ipv6mr_interface = interf ? interf->if_index : 0; - rc = os_sockSetsockopt (socket, IPPROTO_IPV6, join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP, &ipv6mreq, sizeof (ipv6mreq)); + rc = ddsrt_setsockopt (socket, IPPROTO_IPV6, join ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP, &ipv6mreq, sizeof (ipv6mreq)); } else #endif { struct ip_mreq mreq; - mreq.imr_multiaddr = ((os_sockaddr_in *) &mcip)->sin_addr; + mreq.imr_multiaddr = ((struct sockaddr_in *) &mcip)->sin_addr; if (interf) memcpy (&mreq.imr_interface, interf->loc.address + 12, sizeof (mreq.imr_interface)); else mreq.imr_interface.s_addr = htonl (INADDR_ANY); - rc = os_sockSetsockopt (socket, IPPROTO_IP, join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, (char *) &mreq, sizeof (mreq)); + rc = ddsrt_setsockopt (socket, IPPROTO_IP, join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, (char *) &mreq, sizeof (mreq)); } - return (rc != os_resultSuccess) ? os_getErrno() : 0; + return (rc == DDS_RETCODE_OK) ? 0 : -1; } #ifdef DDSI_INCLUDE_SSM -static int joinleave_ssm_mcgroup (os_socket socket, int join, const nn_locator_t *srcloc, const nn_locator_t *mcloc, const struct nn_interface *interf) +static int joinleave_ssm_mcgroup (ddsrt_socket_t socket, int join, const nn_locator_t *srcloc, const nn_locator_t *mcloc, const struct nn_interface *interf) { - os_result rc; - os_sockaddr_storage mcip, srcip; + dds_retcode_t rc; + struct sockaddr_storage mcip, srcip; ddsi_ipaddr_from_loc(&mcip, mcloc); ddsi_ipaddr_from_loc(&srcip, srcloc); -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_UDP6) { struct group_source_req gsr; @@ -351,22 +345,22 @@ static int joinleave_ssm_mcgroup (os_socket socket, int join, const nn_locator_t gsr.gsr_interface = interf ? interf->if_index : 0; memcpy (&gsr.gsr_group, &mcip, sizeof (gsr.gsr_group)); memcpy (&gsr.gsr_source, &srcip, sizeof (gsr.gsr_source)); - rc = os_sockSetsockopt (socket, IPPROTO_IPV6, join ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof (gsr)); + rc = ddsrt_setsockopt (socket, IPPROTO_IPV6, join ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof (gsr)); } else #endif { struct ip_mreq_source mreq; memset (&mreq, 0, sizeof (mreq)); - mreq.imr_sourceaddr = ((os_sockaddr_in *) &srcip)->sin_addr; - mreq.imr_multiaddr = ((os_sockaddr_in *) &mcip)->sin_addr; + mreq.imr_sourceaddr = ((struct sockaddr_in *) &srcip)->sin_addr; + mreq.imr_multiaddr = ((struct sockaddr_in *) &mcip)->sin_addr; if (interf) memcpy (&mreq.imr_interface, interf->loc.address + 12, sizeof (mreq.imr_interface)); else mreq.imr_interface.s_addr = INADDR_ANY; - rc = os_sockSetsockopt (socket, IPPROTO_IP, join ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP, &mreq, sizeof (mreq)); + rc = ddsrt_setsockopt (socket, IPPROTO_IP, join ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP, &mreq, sizeof (mreq)); } - return (rc != os_resultSuccess) ? os_getErrno() : 0; + return (rc == DDS_RETCODE_OK) ? 0 : -1; } #endif @@ -399,21 +393,21 @@ static void ddsi_udp_release_conn (ddsi_tran_conn_t conn) ddsi_udp_conn_t uc = (ddsi_udp_conn_t) conn; DDS_TRACE ( - "ddsi_udp_release_conn %s socket %"PRIsock" port %u\n", + "ddsi_udp_release_conn %s socket %"PRIdSOCK" port %u\n", conn->m_base.m_multicast ? "multicast" : "unicast", uc->m_sock, uc->m_base.m_base.m_port ); - os_sockFree (uc->m_sock); + ddsrt_close (uc->m_sock); #if defined _WIN32 && !defined WINCE WSACloseEvent(uc->m_sockEvent); #endif - os_free (conn); + ddsrt_free (conn); } void ddsi_udp_fini (void) { - if(os_atomic_dec32_nv (&ddsi_udp_init_g) == 0) { + if(ddsrt_atomic_dec32_nv (&ddsi_udp_init_g) == 0) { free_group_membership(ddsi_udp_config_g.mship); memset (&ddsi_udp_factory_g, 0, sizeof (ddsi_udp_factory_g)); DDS_LOG(DDS_LC_CONFIG, "udp finalized\n"); @@ -433,7 +427,7 @@ static int ddsi_udp_is_mcaddr (const ddsi_tran_factory_t tran, const nn_locator_ const nn_udpv4mcgen_address_t *mcgen = (const nn_udpv4mcgen_address_t *) loc->address; return IN_MULTICAST (ntohl (mcgen->ipv4.s_addr)); } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case NN_LOCATOR_KIND_UDPv6: { const struct in6_addr *ipv6 = (const struct in6_addr *) loc->address; return IN6_IS_ADDR_MULTICAST (ipv6); @@ -455,7 +449,7 @@ static int ddsi_udp_is_ssm_mcaddr (const ddsi_tran_factory_t tran, const nn_loca const struct in_addr *x = (const struct in_addr *) (loc->address + 12); return (((uint32_t) ntohl (x->s_addr)) >> 24) == 232; } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 case NN_LOCATOR_KIND_UDPv6: { const struct in6_addr *x = (const struct in6_addr *) loc->address; return x->s6_addr[0] == 0xff && (x->s6_addr[1] & 0xf0) == 0x30; @@ -478,7 +472,7 @@ static char *ddsi_udp_locator_to_string (ddsi_tran_factory_t tran, char *dst, si if (loc->kind != NN_LOCATOR_KIND_UDPv4MCGEN) { return ddsi_ipaddr_to_string(tran, dst, sizeof_dst, loc, with_port); } else { - os_sockaddr_in src; + struct sockaddr_in src; nn_udpv4mcgen_address_t mcgen; size_t pos; int cnt; @@ -487,7 +481,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_sockaddrtostr ((const os_sockaddr *) &src, dst, sizeof_dst); + ddsrt_sockaddrtostr ((const struct 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); @@ -503,7 +497,7 @@ static char *ddsi_udp_locator_to_string (ddsi_tran_factory_t tran, char *dst, si static void ddsi_udp_deinit(void) { - if (os_atomic_dec32_nv(&ddsi_udp_init_g) == 0) { + if (ddsrt_atomic_dec32_nv(&ddsi_udp_init_g) == 0) { if (ddsi_udp_config_g.mship) free_group_membership(ddsi_udp_config_g.mship); DDS_LOG(DDS_LC_CONFIG, "udp de-initialized\n"); @@ -516,7 +510,7 @@ int ddsi_udp_init (void) * this can be removed. Or the call does, in which case it should be done right. * The lack of locking suggests it isn't needed. */ - if (os_atomic_inc32_nv (&ddsi_udp_init_g) == 1) + if (ddsrt_atomic_inc32_nv (&ddsi_udp_init_g) == 1) { memset (&ddsi_udp_factory_g, 0, sizeof (ddsi_udp_factory_g)); ddsi_udp_factory_g.m_free_fn = ddsi_udp_deinit; @@ -538,7 +532,7 @@ int ddsi_udp_init (void) ddsi_udp_factory_g.m_locator_from_string_fn = ddsi_udp_address_from_string; ddsi_udp_factory_g.m_locator_to_string_fn = ddsi_udp_locator_to_string; ddsi_udp_factory_g.m_enumerate_interfaces_fn = ddsi_eth_enumerate_interfaces; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_UDP6) { ddsi_udp_factory_g.m_kind = NN_LOCATOR_KIND_UDPv6; diff --git a/src/core/ddsi/src/ddsi_vendor.c b/src/core/ddsi/src/ddsi_vendor.c index ddde0fd..2fea95b 100644 --- a/src/core/ddsi/src/ddsi_vendor.c +++ b/src/core/ddsi/src/ddsi_vendor.c @@ -11,7 +11,7 @@ */ #include -#include "ddsi/ddsi_vendor.h" +#include "dds/ddsi/ddsi_vendor.h" extern inline bool vendor_equals (nn_vendorid_t a, nn_vendorid_t b); extern inline bool vendor_is_rti (nn_vendorid_t vendor); diff --git a/src/core/ddsi/src/q_addrset.c b/src/core/ddsi/src/q_addrset.c index a21fba5..92ccbfa 100644 --- a/src/core/ddsi/src/q_addrset.c +++ b/src/core/ddsi/src/q_addrset.c @@ -13,14 +13,15 @@ #include #include -#include "os/os.h" - -#include "util/ut_avl.h" -#include "ddsi/q_log.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_globals.h" /* gv.mattr */ +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_globals.h" /* gv.mattr */ /* So what does one do with const & mutexes? I need to take lock in a pure function just in case some other thread is trying to change @@ -31,9 +32,9 @@ Today, I'm taking the latter interpretation. But all the const-discarding casts get moved into LOCK/UNLOCK macros. */ -#define LOCK(as) (os_mutexLock (&((struct addrset *) (as))->lock)) -#define TRYLOCK(as) (os_mutexTryLock (&((struct addrset *) (as))->lock)) -#define UNLOCK(as) (os_mutexUnlock (&((struct addrset *) (as))->lock)) +#define LOCK(as) (ddsrt_mutex_lock (&((struct addrset *) (as))->lock)) +#define TRYLOCK(as) (ddsrt_mutex_trylock (&((struct addrset *) (as))->lock)) +#define UNLOCK(as) (ddsrt_mutex_unlock (&((struct addrset *) (as))->lock)) static int compare_locators_vwrap (const void *va, const void *vb); @@ -125,7 +126,7 @@ static int add_addresses_to_addrset_1 (struct addrset *as, const char *ip, int p return 0; } -OS_WARNING_MSVC_OFF(4996); +DDSRT_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; @@ -133,10 +134,10 @@ int add_addresses_to_addrset (struct addrset *as, const char *addrs, int port_mo */ char *addrs_copy, *ip, *cursor, *a; int retval = -1; - addrs_copy = os_strdup (addrs); - ip = os_malloc (strlen (addrs) + 1); + addrs_copy = ddsrt_strdup (addrs); + ip = ddsrt_malloc (strlen (addrs) + 1); cursor = addrs_copy; - while ((a = os_strsep (&cursor, ",")) != NULL) + while ((a = ddsrt_strsep (&cursor, ",")) != NULL) { int port = 0, pos; int mcgen_base = -1, mcgen_count = -1, mcgen_idx = -1; @@ -174,11 +175,11 @@ int add_addresses_to_addrset (struct addrset *as, const char *addrs, int port_mo } retval = 0; error: - os_free (ip); - os_free (addrs_copy); + ddsrt_free (ip); + ddsrt_free (addrs_copy); return retval; } -OS_WARNING_MSVC_ON(4996); +DDSRT_WARNING_MSVC_ON(4996); int compare_locators (const nn_locator_t *a, const nn_locator_t *b) { @@ -198,9 +199,9 @@ static int compare_locators_vwrap (const void *va, const void *vb) struct addrset *new_addrset (void) { - struct addrset *as = os_malloc (sizeof (*as)); - os_atomic_st32 (&as->refc, 1); - os_mutexInit (&as->lock); + struct addrset *as = ddsrt_malloc (sizeof (*as)); + ddsrt_atomic_st32 (&as->refc, 1); + ddsrt_mutex_init (&as->lock); ut_avlCInit (&addrset_treedef, &as->ucaddrs); ut_avlCInit (&addrset_treedef, &as->mcaddrs); return as; @@ -210,19 +211,19 @@ struct addrset *ref_addrset (struct addrset *as) { if (as != NULL) { - os_atomic_inc32 (&as->refc); + ddsrt_atomic_inc32 (&as->refc); } return as; } void unref_addrset (struct addrset *as) { - if ((as != NULL) && (os_atomic_dec32_ov (&as->refc) == 1)) + if ((as != NULL) && (ddsrt_atomic_dec32_ov (&as->refc) == 1)) { - ut_avlCFree (&addrset_treedef, &as->ucaddrs, os_free); - ut_avlCFree (&addrset_treedef, &as->mcaddrs, os_free); - os_mutexDestroy (&as->lock); - os_free (as); + ut_avlCFree (&addrset_treedef, &as->ucaddrs, ddsrt_free); + ut_avlCFree (&addrset_treedef, &as->mcaddrs, ddsrt_free); + ddsrt_mutex_destroy (&as->lock); + ddsrt_free (as); } } @@ -299,8 +300,8 @@ int addrset_any_non_ssm_mc (const struct addrset *as, nn_locator_t *dst) int addrset_purge (struct addrset *as) { LOCK (as); - ut_avlCFree (&addrset_treedef, &as->ucaddrs, os_free); - ut_avlCFree (&addrset_treedef, &as->mcaddrs, os_free); + ut_avlCFree (&addrset_treedef, &as->ucaddrs, ddsrt_free); + ut_avlCFree (&addrset_treedef, &as->mcaddrs, ddsrt_free); UNLOCK (as); return 0; } @@ -314,7 +315,7 @@ void add_to_addrset (struct addrset *as, const nn_locator_t *loc) LOCK (as); if (ut_avlCLookupIPath (&addrset_treedef, tree, loc, &path) == NULL) { - struct addrset_node *n = os_malloc (sizeof (*n)); + struct addrset_node *n = ddsrt_malloc (sizeof (*n)); n->loc = *loc; ut_avlCInsertIPath (&addrset_treedef, tree, n, &path); } @@ -331,7 +332,7 @@ void remove_from_addrset (struct addrset *as, const nn_locator_t *loc) if ((n = ut_avlCLookupDPath (&addrset_treedef, tree, loc, &path)) != NULL) { ut_avlCDeleteDPath (&addrset_treedef, tree, n, &path); - os_free (n); + ddsrt_free (n); } UNLOCK (as); } @@ -395,7 +396,7 @@ void addrset_purge_ssm (struct addrset *as) if (ddsi_is_ssm_mcaddr (&n1->loc)) { ut_avlCDelete (&addrset_treedef, &as->mcaddrs, n1); - os_free (n1); + ddsrt_free (n1); } } UNLOCK (as); @@ -608,7 +609,7 @@ int addrset_eq_onesidederr (const struct addrset *a, const struct addrset *b) if (a == NULL || b == NULL) return 0; LOCK (a); - if (TRYLOCK (b) == os_resultSuccess) + if (TRYLOCK (b)) { iseq = addrset_eq_onesidederr1 (&a->ucaddrs, &b->ucaddrs) && diff --git a/src/core/ddsi/src/q_bitset_inlines.c b/src/core/ddsi/src/q_bitset_inlines.c index 501a120..89d4b34 100644 --- a/src/core/ddsi/src/q_bitset_inlines.c +++ b/src/core/ddsi/src/q_bitset_inlines.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/q_bitset.h" +#include "dds/ddsi/q_bitset.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); diff --git a/src/core/ddsi/src/q_bswap.c b/src/core/ddsi/src/q_bswap.c index 88af94a..2899b69 100644 --- a/src/core/ddsi/src/q_bswap.c +++ b/src/core/ddsi/src/q_bswap.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/q_bswap.h" +#include "dds/ddsi/q_bswap.h" nn_guid_prefix_t nn_hton_guid_prefix (nn_guid_prefix_t p) { diff --git a/src/core/ddsi/src/q_bswap_inlines.c b/src/core/ddsi/src/q_bswap_inlines.c index 1ac45d5..7d5f070 100644 --- a/src/core/ddsi/src/q_bswap_inlines.c +++ b/src/core/ddsi/src/q_bswap_inlines.c @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/q_bswap.h" +#include "dds/ddsi/q_bswap.h" extern inline uint16_t bswap2u (uint16_t x); extern inline uint32_t bswap4u (uint32_t x); diff --git a/src/core/ddsi/src/q_config.c b/src/core/ddsi/src/q_config.c index 783d390..333d9c8 100644 --- a/src/core/ddsi/src/q_config.c +++ b/src/core/ddsi/src/q_config.c @@ -17,21 +17,23 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/strtod.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_error.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "util/ut_avl.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_error.h" +#include "dds/util/ut_xmlparser.h" +#include "dds/util/ut_expand_envvars.h" -#include "util/ut_xmlparser.h" -#include "util/ut_expand_envvars.h" - -#include "ddsc/ddsc_project.h" +#include "dds/version.h" #define WARN_DEPRECATED_ALIAS 1 #define WARN_DEPRECATED_UNIT 1 @@ -789,7 +791,7 @@ static const struct cfgelem tracing_cfgelems[] = {
  • finest: finer + trace
  • \n\

    While none prevents any message from being written to a DDSI2 log file.

    \n\

    The categorisation of tracing output is incomplete and hence most of the verbosity levels and categories are not of much use in the current release. This is an ongoing process and here we describe the target situation rather than the current situation. Currently, the most useful verbosity levels are config, fine and finest.

    " }, -{ LEAF("OutputFile"), 1, DDSC_PROJECT_NAME_NOSPACE_SMALL".log", ABSOFF(tracingOutputFileName), 0, uf_tracingOutputFileName, ff_free, pf_string, +{ LEAF("OutputFile"), 1, DDS_PROJECT_NAME_NOSPACE_SMALL".log", ABSOFF(tracingOutputFileName), 0, uf_tracingOutputFileName, ff_free, pf_string, "

    This option specifies where the logging is printed to. Note that stdout and stderr are treated as special values, representing \"standard out\" and \"standard error\" respectively. No file is created unless logging categories are enabled using the Tracing/Verbosity or Tracing/EnabledCategory settings.

    " }, { LEAF_W_ATTRS("Timestamps", timestamp_cfgattrs), 1, "true", ABSOFF(tracingTimestamps), 0, uf_boolean, 0, pf_boolean, "

    This option has no effect.

    " }, @@ -896,7 +898,7 @@ static const struct cfgelem root_cfgelems[] = { static const struct cfgelem cyclonedds_root_cfgelems[] = { - { DDSC_PROJECT_NAME_NOSPACE, root_cfgelems, NULL, NODATA, NULL }, + { DDS_PROJECT_NAME_NOSPACE, root_cfgelems, NULL, NODATA, NULL }, END_MARKER }; @@ -1010,16 +1012,16 @@ struct cfg_note_buf { static size_t cfg_note_vsnprintf(struct cfg_note_buf *bb, const char *fmt, va_list ap) { int x; - x = os_vsnprintf(bb->buf + bb->bufpos, bb->bufsize - bb->bufpos, fmt, ap); + x = vsnprintf(bb->buf + bb->bufpos, bb->bufsize - bb->bufpos, fmt, ap); if ( x >= 0 && (size_t) x >= bb->bufsize - bb->bufpos ) { size_t nbufsize = ((bb->bufsize + (size_t) x + 1) + 1023) & (size_t) (-1024); - char *nbuf = os_realloc(bb->buf, nbufsize); + char *nbuf = ddsrt_realloc(bb->buf, nbufsize); bb->buf = nbuf; bb->bufsize = nbufsize; return nbufsize; } if ( x < 0 ) - DDS_FATAL("cfg_note_vsnprintf: os_vsnprintf failed\n"); + DDS_FATAL("cfg_note_vsnprintf: vsnprintf failed\n"); else bb->bufpos += (size_t) x; return 0; @@ -1038,9 +1040,9 @@ static void cfg_note_snprintf(struct cfg_note_buf *bb, const char *fmt, ...) if ( r > 0 ) { int s; va_start(ap, fmt); - s = os_vsnprintf(bb->buf + bb->bufpos, bb->bufsize - bb->bufpos, fmt, ap); + s = vsnprintf(bb->buf + bb->bufpos, bb->bufsize - bb->bufpos, fmt, ap); if ( s < 0 || (size_t) s >= bb->bufsize - bb->bufpos ) - DDS_FATAL("cfg_note_snprintf: os_vsnprintf failed\n"); + DDS_FATAL("cfg_note_snprintf: vsnprintf failed\n"); va_end(ap); bb->bufpos += (size_t) s; } @@ -1063,7 +1065,7 @@ static size_t cfg_note(struct cfgst *cfgst, uint32_t cat, size_t bsz, const char bb.bufpos = 0; bb.bufsize = (bsz == 0) ? 1024 : bsz; - if ( (bb.buf = os_malloc(bb.bufsize)) == NULL ) + if ( (bb.buf = ddsrt_malloc(bb.bufsize)) == NULL ) DDS_FATAL("cfg_note: out of memory\n"); cfg_note_snprintf(&bb, "config: "); @@ -1092,7 +1094,7 @@ static size_t cfg_note(struct cfgst *cfgst, uint32_t cat, size_t bsz, const char /* Can't reset ap ... and va_copy isn't widely available - so instead abort and hope the caller tries again with a larger initial buffer */ - os_free(bb.buf); + ddsrt_free(bb.buf); return r; } @@ -1111,7 +1113,7 @@ static size_t cfg_note(struct cfgst *cfgst, uint32_t cat, size_t bsz, const char break; } - os_free(bb.buf); + ddsrt_free(bb.buf); return 0; } @@ -1156,7 +1158,7 @@ static int list_index(const char *list[], const char *elem) { int i; for ( i = 0; list[i] != NULL; i++ ) { - if ( os_strcasecmp(list[i], elem) == 0 ) + if ( ddsrt_strcasecmp(list[i], elem) == 0 ) return i; } return -1; @@ -1208,7 +1210,7 @@ static void *cfg_deref_address(UNUSED_ARG(struct cfgst *cfgst), void *parent, st static void *if_common(UNUSED_ARG(struct cfgst *cfgst), void *parent, struct cfgelem const * const cfgelem, unsigned size) { struct config_listelem **current = (struct config_listelem **) ((char *) parent + cfgelem->elem_offset); - struct config_listelem *new = os_malloc(size); + struct config_listelem *new = ddsrt_malloc(size); new->next = *current; *current = new; return new; @@ -1289,7 +1291,7 @@ static int if_peer(struct cfgst *cfgst, void *parent, struct cfgelem const * con static void ff_free(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { void **elem = cfg_address(cfgst, parent, cfgelem); - os_free(*elem); + ddsrt_free(*elem); } static int uf_boolean(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) @@ -1350,17 +1352,17 @@ static int uf_logcat(struct cfgst *cfgst, UNUSED_ARG(void *parent), UNUSED_ARG(s { static const char **vs = logcat_names; static const uint32_t *lc = logcat_codes; - char *copy = os_strdup(value), *cursor = copy, *tok; - while ( (tok = os_strsep(&cursor, ",")) != NULL ) { + char *copy = ddsrt_strdup(value), *cursor = copy, *tok; + while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) { int idx = list_index(vs, tok); if ( idx < 0 ) { int ret = cfg_error(cfgst, "'%s' in '%s' undefined", tok, value); - os_free(copy); + ddsrt_free(copy); return ret; } enabled_logcats |= lc[idx]; } - os_free(copy); + ddsrt_free(copy); return 1; } @@ -1497,11 +1499,11 @@ static void pf_retransmit_merging(struct cfgst *cfgst, void *parent, struct cfge static int uf_string(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { char **elem = cfg_address(cfgst, parent, cfgelem); - *elem = os_strdup(value); + *elem = ddsrt_strdup(value); return 1; } -OS_WARNING_MSVC_OFF(4996); +DDSRT_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; @@ -1531,7 +1533,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); +DDSRT_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) @@ -1589,7 +1591,7 @@ static int uf_tracingOutputFileName(struct cfgst *cfgst, UNUSED_ARG(void *parent { struct config *cfg = cfgst->cfg; { - cfg->tracingOutputFileName = os_strdup(value); + cfg->tracingOutputFileName = ddsrt_strdup(value); } return 1; } @@ -1602,7 +1604,7 @@ static int uf_ipv4(struct cfgst *cfgst, void *parent, struct cfgelem const * con static int uf_networkAddress(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int first, const char *value) { - if ( os_strcasecmp(value, "auto") != 0 ) + if ( ddsrt_strcasecmp(value, "auto") != 0 ) return uf_ipv4(cfgst, parent, cfgelem, first, value); else { char **elem = cfg_address(cfgst, parent, cfgelem); @@ -1616,17 +1618,17 @@ static void ff_networkAddresses(struct cfgst *cfgst, void *parent, struct cfgele char ***elem = cfg_address(cfgst, parent, cfgelem); int i; for ( i = 0; (*elem)[i]; i++ ) - os_free((*elem)[i]); - os_free(*elem); + ddsrt_free((*elem)[i]); + ddsrt_free(*elem); } static int uf_networkAddresses_simple(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { char ***elem = cfg_address(cfgst, parent, cfgelem); - if ( (*elem = os_malloc(2 * sizeof(char *))) == NULL ) + if ( (*elem = ddsrt_malloc(2 * sizeof(char *))) == NULL ) return cfg_error(cfgst, "out of memory"); - if ( ((*elem)[0] = os_strdup(value)) == NULL ) { - os_free(*elem); + if ( ((*elem)[0] = ddsrt_strdup(value)) == NULL ) { + ddsrt_free(*elem); *elem = NULL; return cfg_error(cfgst, "out of memory"); } @@ -1641,7 +1643,7 @@ static int uf_networkAddresses(struct cfgst *cfgst, void *parent, struct cfgelem static const char *keywords[] = { "all", "any", "none" }; int i; for ( i = 0; i < (int) (sizeof(keywords) / sizeof(*keywords)); i++ ) { - if ( os_strcasecmp(value, keywords[i]) == 0 ) + if ( ddsrt_strcasecmp(value, keywords[i]) == 0 ) return uf_networkAddresses_simple(cfgst, parent, cfgelem, first, keywords[i]); } } @@ -1662,23 +1664,23 @@ static int uf_networkAddresses(struct cfgst *cfgst, void *parent, struct cfgelem count += (*scan++ == ','); } - copy = os_strdup(value); + copy = ddsrt_strdup(value); /* Allocate an array of address strings (which may be oversized a bit because of the counting of the commas) */ - *elem = os_malloc((count + 1) * sizeof(char *)); + *elem = ddsrt_malloc((count + 1) * sizeof(char *)); { char *cursor = copy, *tok; unsigned idx = 0; - while ( (tok = os_strsep(&cursor, ",")) != NULL ) { + while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) { assert(idx < count); - (*elem)[idx] = os_strdup(tok); + (*elem)[idx] = ddsrt_strdup(tok); idx++; } (*elem)[idx] = NULL; } - os_free(copy); + ddsrt_free(copy); } return 1; } @@ -1692,21 +1694,21 @@ static int uf_allow_multicast(struct cfgst *cfgst, void *parent, struct cfgelem static const char *vs[] = { "false", "spdp", "asm", "true", NULL }; static const unsigned bs[] = { AMC_FALSE, AMC_SPDP, AMC_ASM, AMC_TRUE }; #endif - char *copy = os_strdup(value), *cursor = copy, *tok; + char *copy = ddsrt_strdup(value), *cursor = copy, *tok; unsigned *elem = cfg_address(cfgst, parent, cfgelem); if ( copy == NULL ) return cfg_error(cfgst, "out of memory"); *elem = 0; - while ( (tok = os_strsep(&cursor, ",")) != NULL ) { + while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) { int idx = list_index(vs, tok); if ( idx < 0 ) { int ret = cfg_error(cfgst, "'%s' in '%s' undefined", tok, value); - os_free(copy); + ddsrt_free(copy); return ret; } *elem |= bs[idx]; } - os_free(copy); + ddsrt_free(copy); return 1; } @@ -1737,10 +1739,10 @@ static int uf_sched_prio_class(struct cfgst *cfgst, void *parent, struct cfgelem prio = cfg_address(cfgst, parent, cfgelem); - if ( os_strcasecmp(value, "relative") == 0 ) { + if ( ddsrt_strcasecmp(value, "relative") == 0 ) { *prio = Q__SCHED_PRIO_RELATIVE; ret = 1; - } else if ( os_strcasecmp(value, "absolute") == 0 ) { + } else if ( ddsrt_strcasecmp(value, "absolute") == 0 ) { *prio = Q__SCHED_PRIO_ABSOLUTE; ret = 1; } else { @@ -1769,9 +1771,9 @@ static void pf_sched_prio_class(struct cfgst *cfgst, void *parent, struct cfgele static int uf_sched_class(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { static const char *vs[] = { "realtime", "timeshare", "default" }; - static const os_schedClass ms[] = { OS_SCHED_REALTIME, OS_SCHED_TIMESHARE, OS_SCHED_DEFAULT }; + static const ddsrt_sched_t ms[] = { DDSRT_SCHED_REALTIME, DDSRT_SCHED_TIMESHARE, DDSRT_SCHED_DEFAULT }; int idx = list_index(vs, value); - os_schedClass *elem = cfg_address(cfgst, parent, cfgelem); + ddsrt_sched_t *elem = cfg_address(cfgst, parent, cfgelem); assert(sizeof(vs) / sizeof(*vs) == sizeof(ms) / sizeof(*ms)); if ( idx < 0 ) return cfg_error(cfgst, "'%s': undefined value", value); @@ -1781,22 +1783,22 @@ static int uf_sched_class(struct cfgst *cfgst, void *parent, struct cfgelem cons static void pf_sched_class(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int is_default) { - os_schedClass *p = cfg_address(cfgst, parent, cfgelem); + ddsrt_sched_t *p = cfg_address(cfgst, parent, cfgelem); const char *str = "INVALID"; switch ( *p ) { - case OS_SCHED_DEFAULT: str = "default"; break; - case OS_SCHED_TIMESHARE: str = "timeshare"; break; - case OS_SCHED_REALTIME: str = "realtime"; break; + case DDSRT_SCHED_DEFAULT: str = "default"; break; + case DDSRT_SCHED_TIMESHARE: str = "timeshare"; break; + case DDSRT_SCHED_REALTIME: str = "realtime"; break; } cfg_log(cfgst, "%s%s", str, is_default ? " [def]" : ""); } -OS_WARNING_MSVC_OFF(4996); +DDSRT_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); int pos; - if ( os_strcasecmp(value, "default") == 0 ) { + if ( ddsrt_strcasecmp(value, "default") == 0 ) { elem->isdefault = 1; elem->value = 0; return 1; @@ -1807,13 +1809,13 @@ 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); +DDSRT_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) { struct config_maybe_uint32 *elem = cfg_address(cfgst, parent, cfgelem); int64_t size = 0; - if ( os_strcasecmp(value, "default") == 0 ) { + if ( ddsrt_strcasecmp(value, "default") == 0 ) { elem->isdefault = 1; elem->value = 0; return 1; @@ -1831,8 +1833,9 @@ static int uf_float(struct cfgst *cfgst, void *parent, struct cfgelem const * co { float *elem = cfg_address(cfgst, parent, cfgelem); char *endptr; - float f = os_strtof(value, &endptr); - if ( *value == 0 || *endptr != 0 ) + float f; + dds_retcode_t rc = ddsrt_strtof(value, &endptr, &f); + if (rc != DDS_RETCODE_OK || *value == 0 || *endptr != 0 ) return cfg_error(cfgst, "%s: not a floating point number", value); *elem = f; return 1; @@ -1858,7 +1861,7 @@ static int uf_duration_gen(struct cfgst *cfgst, void *parent, struct cfgelem con static int uf_duration_inf(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { - if ( os_strcasecmp(value, "inf") == 0 ) { + if ( ddsrt_strcasecmp(value, "inf") == 0 ) { int64_t *elem = cfg_address(cfgst, parent, cfgelem); *elem = T_NEVER; return 1; @@ -1934,12 +1937,12 @@ static int uf_int_min_max(struct cfgst *cfgst, void *parent, struct cfgelem cons return 1; } -OS_WARNING_MSVC_OFF(4996); +DDSRT_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); int pos; - if (os_strcasecmp(value, "any") == 0) { + if (ddsrt_strcasecmp(value, "any") == 0) { elem->isdefault = 1; elem->value = 0; return 1; @@ -1950,15 +1953,15 @@ 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); +DDSRT_WARNING_MSVC_ON(4996); static int uf_participantIndex(struct cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, int first, const char *value) { int *elem = cfg_address(cfgst, parent, cfgelem); - if ( os_strcasecmp(value, "auto") == 0 ) { + if ( ddsrt_strcasecmp(value, "auto") == 0 ) { *elem = PARTICIPANT_INDEX_AUTO; return 1; - } else if ( os_strcasecmp(value, "none") == 0 ) { + } else if ( ddsrt_strcasecmp(value, "none") == 0 ) { *elem = PARTICIPANT_INDEX_NONE; return 1; } else { @@ -2058,7 +2061,7 @@ static int do_update(struct cfgst *cfgst, update_fun_t upd, void *parent, struct int ok; key.e = cfgelem; if ( (n = ut_avlLookupIPath(&cfgst_found_treedef, &cfgst->found, &key, &np)) == NULL ) { - if ( (n = os_malloc(sizeof(*n))) == NULL ) + if ( (n = ddsrt_malloc(sizeof(*n))) == NULL ) return cfg_error(cfgst, "out of memory"); n->key = key; @@ -2107,7 +2110,7 @@ static int set_defaults(struct cfgst *cfgst, void *parent, int isattr, struct cf if ( (n = ut_avlLookup(&cfgst_found_treedef, &cfgst->found, &key)) != NULL ) { if ( clear_found ) { ut_avlDelete(&cfgst_found_treedef, &cfgst->found, n); - os_free(n); + ddsrt_free(n); } } if ( ce->children ) { @@ -2443,7 +2446,7 @@ static void free_all_elements(struct cfgst *cfgst, void *parent, struct cfgelem free_all_elements(cfgst, p, ce->children); r = p; p = p->next; - os_free(r); + ddsrt_free(r); } } } @@ -2478,7 +2481,7 @@ static void free_configured_elements(struct cfgst *cfgst, void *parent, struct c free_all_elements(cfgst, p, ce->children); r = p; p = p->next; - os_free(r); + ddsrt_free(r); } } } @@ -2489,7 +2492,7 @@ static int matching_name_index(const char *name_w_aliases, const char *name) const char *ns = name_w_aliases, *p = strchr(ns, '|'); int idx = 0; while ( p ) { - if ( os_strncasecmp(ns, name, (size_t) (p - ns)) == 0 && name[p - ns] == 0 ) { + if ( ddsrt_strncasecmp(ns, name, (size_t) (p - ns)) == 0 && name[p - ns] == 0 ) { /* ns upto the pipe symbol is a prefix of name, and name is terminated at that point */ return idx; } @@ -2498,13 +2501,13 @@ static int matching_name_index(const char *name_w_aliases, const char *name) p = strchr(ns, '|'); idx++; } - return (os_strcasecmp(ns, name) == 0) ? idx : -1; + return (ddsrt_strcasecmp(ns, name) == 0) ? idx : -1; } static const struct cfgelem *lookup_redirect(const char *target) { const struct cfgelem *cfgelem = ddsi2_cfgelems; - char *target_copy = os_strdup(target), *p1; + char *target_copy = ddsrt_strdup(target), *p1; const char *p = target_copy; while ( p ) { p1 = strchr(p, '/'); @@ -2520,7 +2523,7 @@ static const struct cfgelem *lookup_redirect(const char *target) } p = p1; } - os_free(target_copy); + ddsrt_free(target_copy); return cfgelem; } @@ -2601,7 +2604,7 @@ static int proc_attr(void *varg, UNUSED_ARG(uintptr_t eleminfo), const char *nam if ( cfgelem == NULL ) return 1; for ( cfg_attr = cfgelem->attributes; cfg_attr && cfg_attr->name; cfg_attr++ ) { - if ( os_strcasecmp(cfg_attr->name, name) == 0 ) + if ( ddsrt_strcasecmp(cfg_attr->name, name) == 0 ) break; } if ( cfg_attr == NULL || cfg_attr->name == NULL ) @@ -2613,7 +2616,7 @@ static int proc_attr(void *varg, UNUSED_ARG(uintptr_t eleminfo), const char *nam cfgst_push(cfgst, 1, cfg_attr, parent); ok = do_update(cfgst, cfg_attr->update, parent, cfg_attr, xvalue, 0); cfgst_pop(cfgst); - os_free(xvalue); + ddsrt_free(xvalue); return ok; } } @@ -2633,7 +2636,7 @@ static int proc_elem_data(void *varg, UNUSED_ARG(uintptr_t eleminfo), const char cfgst_push(cfgst, 0, NULL, parent); ok = do_update(cfgst, cfgelem->update, parent, cfgelem, xvalue, 0); cfgst_pop(cfgst); - os_free(xvalue); + ddsrt_free(xvalue); return ok; } } @@ -2673,10 +2676,10 @@ static int set_default_channel(struct config *cfg) if ( cfg->channels == NULL ) { /* create one default channel if none configured */ struct config_channel_listelem *c; - if ( (c = os_malloc(sizeof(*c))) == NULL ) + if ( (c = ddsrt_malloc(sizeof(*c))) == NULL ) return ERR_OUT_OF_MEMORY; c->next = NULL; - c->name = os_strdup("user"); + c->name = ddsrt_strdup("user"); c->priority = 0; c->resolution = 1 * T_MILLISECOND; #ifdef DDSI_INCLUDE_BANDWIDTH_LIMITING @@ -2716,7 +2719,7 @@ static int sort_channels_check_nodups(struct config *cfg) n++; assert(n > 0); - ary = os_malloc(n * sizeof(*ary)); + ary = ddsrt_malloc(n * sizeof(*ary)); i = 0; for ( c = cfg->channels; c; c = c->next ) @@ -2740,15 +2743,12 @@ static int sort_channels_check_nodups(struct config *cfg) cfg->max_channel = ary[i]; } - os_free(ary); + ddsrt_free(ary); return result; } #endif /* DDSI_INCLUDE_NETWORK_CHANNELS */ -struct cfgst * config_init -( - _In_opt_ const char *configfile -) +struct cfgst * config_init (const char *configfile) { int ok = 1; struct cfgst *cfgst; @@ -2764,7 +2764,7 @@ struct cfgst * config_init ends up on the right value */ config.domainId.value = 0; - cfgst = os_malloc(sizeof(*cfgst)); + cfgst = ddsrt_malloc(sizeof(*cfgst)); memset(cfgst, 0, sizeof(*cfgst)); ut_avlInit(&cfgst_found_treedef, &cfgst->found); @@ -2773,22 +2773,22 @@ struct cfgst * config_init /* configfile == NULL will get you the default configuration */ if ( configfile ) { - char *copy = os_strdup(configfile), *cursor = copy, *tok; - while ( (tok = os_strsep(&cursor, ",")) != NULL ) { + char *copy = ddsrt_strdup(configfile), *cursor = copy, *tok; + while ( (tok = ddsrt_strsep(&cursor, ",")) != NULL ) { struct ut_xmlpCallbacks cb; struct ut_xmlpState *qx; FILE *fp; - OS_WARNING_MSVC_OFF(4996); + DDSRT_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); - os_free(copy); - os_free(cfgst); + ddsrt_free(copy); + ddsrt_free(cfgst); return NULL; } } - OS_WARNING_MSVC_ON(4996); + DDSRT_WARNING_MSVC_ON(4996); cb.attr = proc_attr; cb.elem_close = proc_elem_close; @@ -2798,8 +2798,8 @@ struct cfgst * config_init if ( (qx = ut_xmlpNewFile(fp, cfgst, &cb)) == NULL ) { fclose(fp); - os_free(copy); - os_free(cfgst); + ddsrt_free(copy); + ddsrt_free(cfgst); return NULL; } cfgst_push(cfgst, 0, &root_cfgelem, &config); @@ -2812,7 +2812,7 @@ struct cfgst * config_init ut_xmlpFree(qx); fclose(fp); } - os_free(copy); + ddsrt_free(copy); } /* Set defaults for everything not set that we have a default value @@ -2910,11 +2910,11 @@ struct cfgst * config_init config.nof_networkPartitions = 0; while ( p ) { #ifdef DDSI_INCLUDE_ENCRYPTION - if ( os_strcasecmp(p->profileName, "null") == 0 ) + if ( ddsrt_strcasecmp(p->profileName, "null") == 0 ) p->securityProfile = NULL; else { struct config_securityprofile_listelem *s = config.securityProfiles; - while ( s && os_strcasecmp(p->profileName, s->name) != 0 ) + while ( s && ddsrt_strcasecmp(p->profileName, s->name) != 0 ) s = s->next; if ( s ) p->securityProfile = s; @@ -2941,7 +2941,7 @@ struct cfgst * config_init struct config_partitionmapping_listelem * m = config.partitionMappings; while ( m ) { struct config_networkpartition_listelem * p = config.networkPartitions; - while ( p && os_strcasecmp(m->networkPartition, p->name) != 0 ) { + while ( p && ddsrt_strcasecmp(m->networkPartition, p->name) != 0 ) { p = p->next; } if ( p ) { @@ -2966,20 +2966,20 @@ struct cfgst * config_init config.valid = 1; return cfgst; } else { - ut_avlFree(&cfgst_found_treedef, &cfgst->found, os_free); - os_free(cfgst); + ut_avlFree(&cfgst_found_treedef, &cfgst->found, ddsrt_free); + ddsrt_free(cfgst); return NULL; } } -void config_print_cfgst(_In_ struct cfgst *cfgst) +void config_print_cfgst(struct cfgst *cfgst) { if ( cfgst == NULL ) return; print_configitems(cfgst, cfgst->cfg, 0, root_cfgelems, 0); } -void config_fini(_In_ struct cfgst *cfgst) +void config_fini(struct cfgst *cfgst) { assert(cfgst); assert(cfgst->cfg == &config); @@ -2994,15 +2994,15 @@ void config_fini(_In_ struct cfgst *cfgst) memset(&config, 0, sizeof(config)); config.valid = 0; - ut_avlFree(&cfgst_found_treedef, &cfgst->found, os_free); - os_free(cfgst); + ut_avlFree(&cfgst_found_treedef, &cfgst->found, ddsrt_free); + ddsrt_free(cfgst); } #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS static char *get_partition_search_pattern(const char *partition, const char *topic) { size_t sz = strlen(partition) + strlen(topic) + 2; - char *pt = os_malloc(sz); + char *pt = ddsrt_malloc(sz); snprintf(pt, sz, "%s.%s", partition, topic); return pt; } @@ -3014,7 +3014,7 @@ struct config_partitionmapping_listelem *find_partitionmapping(const char *parti for ( pm = config.partitionMappings; pm; pm = pm->next ) if ( WildcardOverlap(pt, pm->DCPSPartitionTopic) ) break; - os_free(pt); + ddsrt_free(pt); return pm; } @@ -3034,7 +3034,7 @@ int is_ignored_partition(const char *partition, const char *topic) for ( ip = config.ignoredPartitions; ip; ip = ip->next ) if ( WildcardOverlap(pt, ip->DCPSPartitionTopic) ) break; - os_free(pt); + ddsrt_free(pt); return ip != NULL; } #endif /* DDSI_INCLUDE_NETWORK_PARTITIONS */ diff --git a/src/core/ddsi/src/q_ddsi_discovery.c b/src/core/ddsi/src/q_ddsi_discovery.c index f089142..ca34713 100644 --- a/src/core/ddsi/src/q_ddsi_discovery.c +++ b/src/core/ddsi/src/q_ddsi_discovery.c @@ -15,31 +15,33 @@ #include #include -#include "os/os.h" - -#include "util/ut_avl.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_ddsi_discovery.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_error.h" -#include "ddsi/ddsi_serdata_default.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_feature_check.h" +#include "dds/version.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sync.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_feature_check.h" static int get_locator (nn_locator_t *loc, const nn_locators_t *locs, int uc_same_subnet) { @@ -95,7 +97,7 @@ static int get_locator (nn_locator_t *loc, const nn_locators_t *locs, int uc_sam } } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if ((l->loc.kind == NN_LOCATOR_KIND_UDPv6) || (l->loc.kind == NN_LOCATOR_KIND_TCPv6)) { /* We (cowardly) refuse to accept advertised link-local @@ -293,16 +295,16 @@ int spdp_write (struct participant *pp) NN_PRISMTECH_FL_SUPPORTS_STATUSINFOX; if (config.besmode == BESMODE_MINIMAL) ps.prismtech_participant_version_info.flags |= NN_PRISMTECH_FL_MINIMAL_BES_MODE; - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); if (pp->is_ddsi2_pp) ps.prismtech_participant_version_info.flags |= NN_PRISMTECH_FL_PARTICIPANT_IS_DDSI2; - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); - os_gethostname(node, sizeof(node)-1); + ddsrt_gethostname(node, sizeof(node)-1); node[sizeof(node)-1] = '\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, OS_VERSION, OS_HOST_NAME, OS_TARGET_NAME); + size = strlen(node) + strlen(DDS_VERSION) + strlen(DDS_HOST_NAME) + strlen(DDS_TARGET_NAME) + 4; /* + ///'\0' */ + ps.prismtech_participant_version_info.internals = ddsrt_malloc(size); + (void) snprintf(ps.prismtech_participant_version_info.internals, size, "%s/%s/%s/%s", node, DDS_VERSION, DDS_HOST_NAME, DDS_TARGET_NAME); DDS_TRACE("spdp_write(%x:%x:%x:%x) - internals: %s\n", PGUID (pp->e.guid), ps.prismtech_participant_version_info.internals); } @@ -471,16 +473,16 @@ static void make_participants_dependent_on_ddsi2 (const nn_guid_t *ddsi2guid, nn struct lease *d2pp_lease; if ((d2pp = ephash_lookup_proxy_participant_guid (ddsi2guid)) == NULL) return; - d2pp_lease = os_atomic_ldvoidp (&d2pp->lease); + d2pp_lease = ddsrt_atomic_ldvoidp (&d2pp->lease); ephash_enum_proxy_participant_init (&it); while ((pp = ephash_enum_proxy_participant_next (&it)) != NULL) { if (vendor_is_eclipse_or_opensplice (pp->vendor) && pp->e.guid.prefix.u[0] == ddsi2guid->prefix.u[0] && !pp->is_ddsi2_pp) { DDS_TRACE("proxy participant %x:%x:%x:%x depends on ddsi2 %x:%x:%x:%x", PGUID (pp->e.guid), PGUID (*ddsi2guid)); - os_mutexLock (&pp->e.lock); + ddsrt_mutex_lock (&pp->e.lock); pp->privileged_pp_guid = *ddsi2guid; - os_mutexUnlock (&pp->e.lock); + ddsrt_mutex_unlock (&pp->e.lock); proxy_participant_reassign_lease (pp, d2pp_lease); DDS_TRACE("\n"); @@ -587,15 +589,15 @@ static int handle_SPDP_alive (const struct receiver_state *rst, nn_wctime_t time regardless of config.arrival_of_data_asserts_pp_and_ep_liveliness. */ DDS_LOG(DDS_LC_TRACE, "SPDP ST0 %x:%x:%x:%x (known)", PGUID (datap->participant_guid)); - lease_renew (os_atomic_ldvoidp (&proxypp->lease), now_et ()); - os_mutexLock (&proxypp->e.lock); + lease_renew (ddsrt_atomic_ldvoidp (&proxypp->lease), now_et ()); + ddsrt_mutex_lock (&proxypp->e.lock); if (proxypp->implicitly_created) { DDS_LOG(DDS_LC_DISCOVERY, " (NEW was-implicitly-created)"); proxypp->implicitly_created = 0; update_proxy_participant_plist_locked (proxypp, datap, UPD_PROXYPP_SPDP, timestamp); } - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); return 0; } @@ -823,7 +825,7 @@ static void handle_SPDP (const struct receiver_state *rst, nn_wctime_t timestamp static void add_locator_to_ps (const nn_locator_t *loc, void *arg) { nn_plist_t *ps = (nn_plist_t *) arg; - struct nn_locators_one *elem = os_malloc (sizeof (struct nn_locators_one)); + struct nn_locators_one *elem = ddsrt_malloc (sizeof (struct nn_locators_one)); struct nn_locators *locs; unsigned present_flag; @@ -1075,7 +1077,7 @@ static struct proxy_participant *implicitly_create_proxypp (const nn_guid_t *ppg DDS_TRACE(" from-ddsi2 %x:%x:%x:%x", PGUID (privguid)); nn_plist_init_empty (&pp_plist); - os_mutexLock (&privpp->e.lock); + ddsrt_mutex_lock (&privpp->e.lock); as_default = ref_addrset(privpp->as_default); as_meta = ref_addrset(privpp->as_meta); /* copy just what we need */ @@ -1083,7 +1085,7 @@ static struct proxy_participant *implicitly_create_proxypp (const nn_guid_t *ppg tmp_plist.present = PP_PARTICIPANT_GUID | PP_PRISMTECH_PARTICIPANT_VERSION_INFO; tmp_plist.participant_guid = *ppguid; nn_plist_mergein_missing (&pp_plist, &tmp_plist); - os_mutexUnlock (&privpp->e.lock); + ddsrt_mutex_unlock (&privpp->e.lock); pp_plist.prismtech_participant_version_info.flags &= ~NN_PRISMTECH_FL_PARTICIPANT_IS_DDSI2; new_proxy_participant (ppguid, 0, 0, &privguid, as_default, as_meta, &pp_plist, T_NEVER, vendorid, CF_IMPLICITLY_CREATED_PROXYPP | CF_PROXYPP_NO_SPDP, timestamp); @@ -1197,10 +1199,10 @@ static void handle_SEDP_alive (const struct receiver_state *rst, nn_plist_t *dat { nn_etime_t never = { T_NEVER }; DDS_LOG(DDS_LC_DISCOVERY, " %x:%x:%x:%x attach-to-DS %x:%x:%x:%x", PGUID(pp->e.guid), PGUIDPREFIX(*src_guid_prefix), pp->privileged_pp_guid.entityid.u); - os_mutexLock (&pp->e.lock); + ddsrt_mutex_lock (&pp->e.lock); pp->privileged_pp_guid.prefix = *src_guid_prefix; - lease_set_expiry(os_atomic_ldvoidp(&pp->lease), never); - os_mutexUnlock (&pp->e.lock); + lease_set_expiry(ddsrt_atomic_ldvoidp(&pp->lease), never); + ddsrt_mutex_unlock (&pp->e.lock); } DDS_LOG(DDS_LC_DISCOVERY, "\n"); } @@ -1666,7 +1668,7 @@ static int defragment (unsigned char **datap, const struct nn_rdata *fragchain, { unsigned char *buf; uint32_t off = 0; - buf = os_malloc (sz); + buf = ddsrt_malloc (sz); while (fragchain) { assert (fragchain->min <= off); @@ -1811,7 +1813,7 @@ int builtins_dqueue_handler (const struct nn_rsample_info *sampleinfo, const str else { nn_parameterid_t pid; - keyhash_payload.cdr.identifier = PLATFORM_IS_LITTLE_ENDIAN ? PL_CDR_LE : PL_CDR_BE; + keyhash_payload.cdr.identifier = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? PL_CDR_LE : PL_CDR_BE); keyhash_payload.cdr.options = 0; switch (srcguid.entityid.u) { @@ -1886,11 +1888,11 @@ int builtins_dqueue_handler (const struct nn_rsample_info *sampleinfo, const str done_upd_deliv: if (needs_free) - os_free (datap); + ddsrt_free (datap); if (pwr) { /* No proxy writer for SPDP */ - os_atomic_st32 (&pwr->next_deliv_seq_lowword, (uint32_t) (sampleinfo->seq + 1)); + ddsrt_atomic_st32 (&pwr->next_deliv_seq_lowword, (uint32_t) (sampleinfo->seq + 1)); } return 0; } diff --git a/src/core/ddsi/src/q_debmon.c b/src/core/ddsi/src/q_debmon.c index 3e5dc53..15a2fc9 100644 --- a/src/core/ddsi/src/q_debmon.c +++ b/src/core/ddsi/src/q_debmon.c @@ -13,28 +13,30 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sync.h" -#include "util/ut_avl.h" +#include "dds/util/ut_avl.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_config.h" -#include "ddsi/q_time.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_ddsi_discovery.h" -#include "ddsi/q_protocol.h" /* NN_ENTITYID_... */ -#include "ddsi/q_unused.h" -#include "ddsi/q_error.h" -#include "ddsi/q_debmon.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_tcp.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/q_protocol.h" /* NN_ENTITYID_... */ +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_debmon.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_tcp.h" #include "dds__whc.h" @@ -48,8 +50,8 @@ struct debug_monitor { struct thread_state1 *servts; ddsi_tran_factory_t tran_factory; ddsi_tran_listener_t servsock; - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; struct plugin *plugins; int stop; }; @@ -62,11 +64,11 @@ static int cpf (ddsi_tran_conn_t conn, const char *fmt, ...) else { va_list ap; - os_iovec_t iov; + ddsrt_iovec_t iov; char buf[4096]; int n; va_start (ap, fmt); - n = os_vsnprintf (buf, sizeof (buf), fmt, ap); + n = vsnprintf (buf, sizeof (buf), fmt, ap); va_end (ap); iov.iov_base = buf; iov.iov_len = (size_t) n; @@ -126,7 +128,7 @@ static int print_any_endpoint_common (ddsi_tran_conn_t conn, const char *label, static int print_endpoint_common (ddsi_tran_conn_t conn, const char *label, const struct entity_common *e, const struct endpoint_common *c, const struct nn_xqos *xqos, const struct ddsi_sertopic *topic) { - OS_UNUSED_ARG (c); + DDSRT_UNUSED_ARG (c); return print_any_endpoint_common (conn, label, e, xqos, topic); } @@ -148,9 +150,9 @@ static int print_participants (struct thread_state1 *self, ddsi_tran_conn_t conn ephash_enum_participant_init (&e); while ((p = ephash_enum_participant_next (&e)) != NULL) { - os_mutexLock (&p->e.lock); + ddsrt_mutex_lock (&p->e.lock); x += cpf (conn, "pp %x:%x:%x:%x %s%s\n", PGUID (p->e.guid), p->e.name, p->is_ddsi2_pp ? " [ddsi2]" : ""); - os_mutexUnlock (&p->e.lock); + ddsrt_mutex_unlock (&p->e.lock); { struct ephash_enum_reader er; @@ -162,14 +164,14 @@ static int print_participants (struct thread_state1 *self, ddsi_tran_conn_t conn struct rd_pwr_match *m; if (r->c.pp != p) continue; - os_mutexLock (&r->e.lock); + ddsrt_mutex_lock (&r->e.lock); print_endpoint_common (conn, "rd", &r->e, &r->c, r->xqos, r->topic); #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS x += print_addrset_if_notempty (conn, " as", r->as, "\n"); #endif for (m = ut_avlIterFirst (&rd_writers_treedef, &r->writers, &writ); m; m = ut_avlIterNext (&writ)) x += cpf (conn, " pwr %x:%x:%x:%x\n", PGUID (m->pwr_guid)); - os_mutexUnlock (&r->e.lock); + ddsrt_mutex_unlock (&r->e.lock); } ephash_enum_reader_fini (&er); } @@ -185,7 +187,7 @@ static int print_participants (struct thread_state1 *self, ddsi_tran_conn_t conn struct whc_state whcst; if (w->c.pp != p) continue; - os_mutexLock (&w->e.lock); + ddsrt_mutex_lock (&w->e.lock); print_endpoint_common (conn, "wr", &w->e, &w->c, w->xqos, w->topic); whc_get_state(w->whc, &whcst); x += cpf (conn, " whc [%lld,%lld] unacked %"PRIuSIZE"%s [%u,%u] seq %lld seq_xmit %lld cs_seq %lld\n", @@ -214,7 +216,7 @@ static int print_participants (struct thread_state1 *self, ddsi_tran_conn_t conn x += cpf (conn, " prd %x:%x:%x:%x %s @ %lld [%lld,%lld] #nacks %u\n", PGUID (m->prd_guid), wr_prd_flags, m->seq, m->min_seq, m->max_seq, m->rexmit_requests); } - os_mutexUnlock (&w->e.lock); + ddsrt_mutex_unlock (&w->e.lock); } ephash_enum_writer_fini (&ew); } @@ -233,9 +235,9 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ ephash_enum_proxy_participant_init (&e); while ((p = ephash_enum_proxy_participant_next (&e)) != NULL) { - os_mutexLock (&p->e.lock); + ddsrt_mutex_lock (&p->e.lock); x += cpf (conn, "proxypp %x:%x:%x:%x%s\n", PGUID (p->e.guid), p->is_ddsi2_pp ? " [ddsi2]" : ""); - os_mutexUnlock (&p->e.lock); + ddsrt_mutex_unlock (&p->e.lock); x += print_addrset (conn, " as data", p->as_default, ""); x += print_addrset (conn, " meta", p->as_default, "\n"); @@ -249,11 +251,11 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ struct prd_wr_match *m; if (r->c.proxypp != p) continue; - os_mutexLock (&r->e.lock); + ddsrt_mutex_lock (&r->e.lock); print_proxy_endpoint_common (conn, "prd", &r->e, &r->c); for (m = ut_avlIterFirst (&rd_writers_treedef, &r->writers, &writ); m; m = ut_avlIterNext (&writ)) x += cpf (conn, " wr %x:%x:%x:%x\n", PGUID (m->wr_guid)); - os_mutexUnlock (&r->e.lock); + ddsrt_mutex_unlock (&r->e.lock); } ephash_enum_proxy_reader_fini (&er); } @@ -268,7 +270,7 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ struct pwr_rd_match *m; if (w->c.proxypp != p) continue; - os_mutexLock (&w->e.lock); + ddsrt_mutex_lock (&w->e.lock); print_proxy_endpoint_common (conn, "pwr", &w->e, &w->c); x += cpf (conn, " last_seq %lld last_fragnum %u\n", w->last_seq, w->last_fragnum); for (m = ut_avlIterFirst (&wr_readers_treedef, &w->readers, &rdit); m; m = ut_avlIterNext (&rdit)) @@ -287,7 +289,7 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ break; } } - os_mutexUnlock (&w->e.lock); + ddsrt_mutex_unlock (&w->e.lock); } ephash_enum_proxy_writer_fini (&ew); } @@ -300,11 +302,11 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ static uint32_t debmon_main (void *vdm) { struct debug_monitor *dm = vdm; - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); while (!dm->stop) { ddsi_tran_conn_t conn; - os_mutexUnlock (&dm->lock); + ddsrt_mutex_unlock (&dm->lock); if ((conn = ddsi_listener_accept (dm->servsock)) != NULL) { struct plugin *p; @@ -314,22 +316,22 @@ static uint32_t debmon_main (void *vdm) r += print_proxy_participants (dm->servts, conn); /* Note: can only add plugins (at the tail) */ - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); p = dm->plugins; while (r == 0 && p != NULL) { - os_mutexUnlock (&dm->lock); + ddsrt_mutex_unlock (&dm->lock); r += p->fn (conn, cpf, p->arg); - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); p = p->next; } - os_mutexUnlock (&dm->lock); + ddsrt_mutex_unlock (&dm->lock); ddsi_conn_free (conn); } - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); } - os_mutexUnlock (&dm->lock); + ddsrt_mutex_unlock (&dm->lock); return 0; } @@ -343,7 +345,7 @@ struct debug_monitor *new_debug_monitor (int port) if (ddsi_tcp_init () < 0) return NULL; - dm = os_malloc (sizeof (*dm)); + dm = ddsrt_malloc (sizeof (*dm)); dm->plugins = NULL; if ((dm->tran_factory = ddsi_factory_find ("tcp")) == NULL) @@ -362,8 +364,8 @@ struct debug_monitor *new_debug_monitor (int port) DDS_LOG(DDS_LC_CONFIG, "debmon at %s\n", ddsi_locator_to_string (buf, sizeof(buf), &loc)); } - os_mutexInit (&dm->lock); - os_condInit (&dm->cond, &dm->lock); + ddsrt_mutex_init (&dm->lock); + ddsrt_cond_init (&dm->cond); if (ddsi_listener_listen (dm->servsock) < 0) goto err_listen; dm->stop = 0; @@ -371,28 +373,28 @@ struct debug_monitor *new_debug_monitor (int port) return dm; err_listen: - os_condDestroy(&dm->cond); - os_mutexDestroy(&dm->lock); + ddsrt_cond_destroy(&dm->cond); + ddsrt_mutex_destroy(&dm->lock); ddsi_listener_free(dm->servsock); err_servsock: - os_free(dm); + ddsrt_free(dm); return NULL; } void add_debug_monitor_plugin (struct debug_monitor *dm, debug_monitor_plugin_t fn, void *arg) { struct plugin *p, **pp; - if (dm != NULL && (p = os_malloc (sizeof (*p))) != NULL) + if (dm != NULL && (p = ddsrt_malloc (sizeof (*p))) != NULL) { p->fn = fn; p->arg = arg; p->next = NULL; - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); pp = &dm->plugins; while (*pp) pp = &(*pp)->next; *pp = p; - os_mutexUnlock (&dm->lock); + ddsrt_mutex_unlock (&dm->lock); } } @@ -401,21 +403,21 @@ void free_debug_monitor (struct debug_monitor *dm) if (dm == NULL) return; - os_mutexLock (&dm->lock); + ddsrt_mutex_lock (&dm->lock); dm->stop = 1; - os_condBroadcast (&dm->cond); - os_mutexUnlock (&dm->lock); + ddsrt_cond_broadcast (&dm->cond); + ddsrt_mutex_unlock (&dm->lock); ddsi_listener_unblock (dm->servsock); join_thread (dm->servts); ddsi_listener_free (dm->servsock); - os_condDestroy (&dm->cond); - os_mutexDestroy (&dm->lock); + ddsrt_cond_destroy (&dm->cond); + ddsrt_mutex_destroy (&dm->lock); while (dm->plugins) { struct plugin *p = dm->plugins; dm->plugins = p->next; - os_free (p); + ddsrt_free (p); } - os_free (dm); + ddsrt_free (dm); } diff --git a/src/core/ddsi/src/q_entity.c b/src/core/ddsi/src/q_entity.c index 755389b..9e20649 100644 --- a/src/core/ddsi/src/q_entity.c +++ b/src/core/ddsi/src/q_entity.c @@ -13,36 +13,39 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_log.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_qosmatch.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_xevent.h" /* qxev_spdp, &c. */ +#include "dds/ddsi/q_ddsi_discovery.h" /* spdp_write, &c. */ +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_protocol.h" /* NN_ENTITYID_... */ +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/q_receive.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_config.h" -#include "ddsi/q_time.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_log.h" -#include "util/ut_avl.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_qosmatch.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_xevent.h" /* qxev_spdp, &c. */ -#include "ddsi/q_ddsi_discovery.h" /* spdp_write, &c. */ -#include "ddsi/q_gc.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_protocol.h" /* NN_ENTITYID_... */ -#include "ddsi/q_unused.h" -#include "ddsi/q_error.h" -#include "ddsi/ddsi_serdata_default.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/q_receive.h" - -#include "ddsi/sysdeps.h" +#include "dds/ddsi/sysdeps.h" #include "dds__whc.h" -#include "ddsi/ddsi_iid.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_iid.h" +#include "dds/ddsi/ddsi_tkmap.h" struct deleted_participant { ut_avlNode_t avlnode; @@ -51,7 +54,7 @@ struct deleted_participant { nn_mtime_t t_prune; }; -static os_mutex deleted_participants_lock; +static ddsrt_mutex_t deleted_participants_lock; static ut_avlTree_t deleted_participants; static int compare_guid (const void *va, const void *vb); @@ -164,9 +167,9 @@ static void entity_common_init (struct entity_common *e, const struct nn_guid *g e->guid = *guid; e->kind = kind; e->tupdate = tcreate; - e->name = os_strdup (name ? name : ""); + e->name = ddsrt_strdup (name ? name : ""); e->onlylocal = onlylocal; - os_mutexInit (&e->lock); + ddsrt_mutex_init (&e->lock); if (ddsi_plugin.builtintopic_is_visible (guid->entityid, onlylocal, vendorid)) { e->tk = ddsi_plugin.builtintopic_get_tkmap_entry (guid); @@ -183,40 +186,40 @@ static void entity_common_fini (struct entity_common *e) { if (e->tk) ddsi_tkmap_instance_unref (e->tk); - os_free (e->name); - os_mutexDestroy (&e->lock); + ddsrt_free (e->name); + ddsrt_mutex_destroy (&e->lock); } void local_reader_ary_init (struct local_reader_ary *x) { - os_mutexInit (&x->rdary_lock); + ddsrt_mutex_init (&x->rdary_lock); x->valid = 1; x->fastpath_ok = 1; x->n_readers = 0; - x->rdary = os_malloc (sizeof (*x->rdary)); + x->rdary = ddsrt_malloc (sizeof (*x->rdary)); x->rdary[0] = NULL; } void local_reader_ary_fini (struct local_reader_ary *x) { - os_free (x->rdary); - os_mutexDestroy (&x->rdary_lock); + ddsrt_free (x->rdary); + ddsrt_mutex_destroy (&x->rdary_lock); } void local_reader_ary_insert (struct local_reader_ary *x, struct reader *rd) { - os_mutexLock (&x->rdary_lock); + ddsrt_mutex_lock (&x->rdary_lock); x->n_readers++; - x->rdary = os_realloc (x->rdary, (x->n_readers + 1) * sizeof (*x->rdary)); + x->rdary = ddsrt_realloc (x->rdary, (x->n_readers + 1) * sizeof (*x->rdary)); x->rdary[x->n_readers - 1] = rd; x->rdary[x->n_readers] = NULL; - os_mutexUnlock (&x->rdary_lock); + ddsrt_mutex_unlock (&x->rdary_lock); } void local_reader_ary_remove (struct local_reader_ary *x, struct reader *rd) { unsigned i; - os_mutexLock (&x->rdary_lock); + ddsrt_mutex_lock (&x->rdary_lock); for (i = 0; i < x->n_readers; i++) { if (x->rdary[i] == rd) @@ -227,16 +230,16 @@ void local_reader_ary_remove (struct local_reader_ary *x, struct reader *rd) x->rdary[i] = x->rdary[x->n_readers-1]; x->n_readers--; x->rdary[x->n_readers] = NULL; - x->rdary = os_realloc (x->rdary, (x->n_readers + 1) * sizeof (*x->rdary)); - os_mutexUnlock (&x->rdary_lock); + x->rdary = ddsrt_realloc (x->rdary, (x->n_readers + 1) * sizeof (*x->rdary)); + ddsrt_mutex_unlock (&x->rdary_lock); } void local_reader_ary_setinvalid (struct local_reader_ary *x) { - os_mutexLock (&x->rdary_lock); + ddsrt_mutex_lock (&x->rdary_lock); x->valid = 0; x->fastpath_ok = 0; - os_mutexUnlock (&x->rdary_lock); + ddsrt_mutex_unlock (&x->rdary_lock); } nn_vendorid_t get_entity_vendorid (const struct entity_common *e) @@ -262,15 +265,15 @@ nn_vendorid_t get_entity_vendorid (const struct entity_common *e) int deleted_participants_admin_init (void) { - os_mutexInit (&deleted_participants_lock); + ddsrt_mutex_init (&deleted_participants_lock); ut_avlInit (&deleted_participants_treedef, &deleted_participants); return 0; } void deleted_participants_admin_fini (void) { - ut_avlFree (&deleted_participants_treedef, &deleted_participants, os_free); - os_mutexDestroy (&deleted_participants_lock); + ut_avlFree (&deleted_participants_treedef, &deleted_participants, ddsrt_free); + ddsrt_mutex_destroy (&deleted_participants_lock); } static void prune_deleted_participant_guids_unlocked (nn_mtime_t tnow) @@ -286,7 +289,7 @@ static void prune_deleted_participant_guids_unlocked (nn_mtime_t tnow) if (dpp->t_prune.v < tnow.v) { ut_avlDelete (&deleted_participants_treedef, &deleted_participants, dpp); - os_free (dpp); + ddsrt_free (dpp); } dpp = dpp1; } @@ -294,19 +297,19 @@ static void prune_deleted_participant_guids_unlocked (nn_mtime_t tnow) static void prune_deleted_participant_guids (nn_mtime_t tnow) { - os_mutexLock (&deleted_participants_lock); + ddsrt_mutex_lock (&deleted_participants_lock); prune_deleted_participant_guids_unlocked (tnow); - os_mutexUnlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&deleted_participants_lock); } static void remember_deleted_participant_guid (const struct nn_guid *guid) { struct deleted_participant *n; ut_avlIPath_t path; - os_mutexLock (&deleted_participants_lock); + ddsrt_mutex_lock (&deleted_participants_lock); if (ut_avlLookupIPath (&deleted_participants_treedef, &deleted_participants, guid, &path) == NULL) { - if ((n = os_malloc (sizeof (*n))) != NULL) + if ((n = ddsrt_malloc (sizeof (*n))) != NULL) { n->guid = *guid; n->t_prune.v = T_NEVER; @@ -314,20 +317,20 @@ static void remember_deleted_participant_guid (const struct nn_guid *guid) ut_avlInsertIPath (&deleted_participants_treedef, &deleted_participants, n, &path); } } - os_mutexUnlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&deleted_participants_lock); } int is_deleted_participant_guid (const struct nn_guid *guid, unsigned for_what) { struct deleted_participant *n; int known; - os_mutexLock (&deleted_participants_lock); + ddsrt_mutex_lock (&deleted_participants_lock); prune_deleted_participant_guids_unlocked (now_mt()); if ((n = ut_avlLookup (&deleted_participants_treedef, &deleted_participants, guid)) == NULL) known = 0; else known = ((n->for_what & for_what) != 0); - os_mutexUnlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&deleted_participants_lock); return known; } @@ -335,7 +338,7 @@ static void remove_deleted_participant_guid (const struct nn_guid *guid, unsigne { struct deleted_participant *n; DDS_LOG(DDS_LC_DISCOVERY, "remove_deleted_participant_guid(%x:%x:%x:%x for_what=%x)\n", PGUID (*guid), for_what); - os_mutexLock (&deleted_participants_lock); + ddsrt_mutex_lock (&deleted_participants_lock); if ((n = ut_avlLookup (&deleted_participants_treedef, &deleted_participants, guid)) != NULL) { if (config.prune_deleted_ppant.enforce_delay) @@ -354,11 +357,11 @@ static void remove_deleted_participant_guid (const struct nn_guid *guid, unsigne else { ut_avlDelete (&deleted_participants_treedef, &deleted_participants, n); - os_free (n); + ddsrt_free (n); } } } - os_mutexUnlock (&deleted_participants_lock); + ddsrt_mutex_unlock (&deleted_participants_lock); } @@ -368,7 +371,7 @@ int pp_allocate_entityid(nn_entityid_t *id, unsigned kind, struct participant *p { uint32_t id1; int ret = 0; - os_mutexLock (&pp->e.lock); + ddsrt_mutex_lock (&pp->e.lock); if (inverse_uint32_set_alloc(&id1, &pp->avail_entityids.x)) { *id = to_entityid (id1 * NN_ENTITYID_ALLOCSTEP + kind); @@ -379,15 +382,15 @@ int pp_allocate_entityid(nn_entityid_t *id, unsigned kind, struct participant *p DDS_ERROR("pp_allocate_entityid(%x:%x:%x:%x): all ids in use\n", PGUID(pp->e.guid)); ret = ERR_OUT_OF_IDS; } - os_mutexUnlock (&pp->e.lock); + ddsrt_mutex_unlock (&pp->e.lock); return ret; } void pp_release_entityid(struct participant *pp, nn_entityid_t id) { - os_mutexLock (&pp->e.lock); + ddsrt_mutex_lock (&pp->e.lock); inverse_uint32_set_free(&pp->avail_entityids.x, id.u / NN_ENTITYID_ALLOCSTEP); - os_mutexUnlock (&pp->e.lock); + ddsrt_mutex_unlock (&pp->e.lock); } int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plist_t *plist) @@ -412,21 +415,21 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis if (config.max_participants == 0) { - os_mutexLock (&gv.participant_set_lock); + ddsrt_mutex_lock (&gv.participant_set_lock); ++gv.nparticipants; - os_mutexUnlock (&gv.participant_set_lock); + ddsrt_mutex_unlock (&gv.participant_set_lock); } else { - os_mutexLock (&gv.participant_set_lock); + ddsrt_mutex_lock (&gv.participant_set_lock); if (gv.nparticipants < config.max_participants) { ++gv.nparticipants; - os_mutexUnlock (&gv.participant_set_lock); + ddsrt_mutex_unlock (&gv.participant_set_lock); } else { - os_mutexUnlock (&gv.participant_set_lock); + ddsrt_mutex_unlock (&gv.participant_set_lock); DDS_ERROR("new_participant(%x:%x:%x:%x, %x) failed: max participants reached\n", PGUID (*ppguid), flags); return ERR_OUT_OF_IDS; } @@ -434,17 +437,17 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis DDS_LOG(DDS_LC_DISCOVERY, "new_participant(%x:%x:%x:%x, %x)\n", PGUID (*ppguid), flags); - pp = os_malloc (sizeof (*pp)); + pp = ddsrt_malloc (sizeof (*pp)); entity_common_init (&pp->e, ppguid, "", EK_PARTICIPANT, now (), NN_VENDORID_ECLIPSE, ((flags & RTPS_PF_ONLY_LOCAL) != 0)); pp->user_refc = 1; pp->builtin_refc = 0; pp->builtins_deleted = 0; pp->is_ddsi2_pp = (flags & (RTPS_PF_PRIVILEGED_PP | RTPS_PF_IS_DDSI2_PP)) ? 1 : 0; - os_mutexInit (&pp->refc_lock); + ddsrt_mutex_init (&pp->refc_lock); inverse_uint32_set_init(&pp->avail_entityids.x, 1, UINT32_MAX / NN_ENTITYID_ALLOCSTEP); pp->lease_duration = config.lease_duration; - pp->plist = os_malloc (sizeof (*pp->plist)); + pp->plist = ddsrt_malloc (sizeof (*pp->plist)); nn_plist_copy (pp->plist, plist); nn_plist_mergein_missing (pp->plist, &gv.default_plist_pp); @@ -490,12 +493,12 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis { struct writer *wr = ephash_lookup_writer_guid (&subguid); assert (wr != NULL); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); unref_addrset (wr->as); unref_addrset (wr->as_group); wr->as = ref_addrset (gv.as_disc); wr->as_group = ref_addrset (gv.as_disc_group); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } pp->bes |= NN_DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER; } @@ -584,7 +587,7 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis pointing to it. Except when the participant is only locally available. */ if (!(flags & RTPS_PF_ONLY_LOCAL)) { - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); if ((pp->bes & builtin_writers_besmask) != builtin_writers_besmask || (pp->prismtech_bes & prismtech_builtin_writers_besmask) != prismtech_builtin_writers_besmask) { @@ -601,7 +604,7 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis assert (gv.privileged_pp == NULL); gv.privileged_pp = pp; } - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); } /* Make it globally visible, then signal receive threads if @@ -610,8 +613,8 @@ int new_participant_guid (const nn_guid_t *ppguid, unsigned flags, const nn_plis if (config.many_sockets_mode == MSM_MANY_UNICAST) { - os_atomic_fence (); - os_atomic_inc32 (&gv.participant_set_generation); + ddsrt_atomic_fence (); + ddsrt_atomic_inc32 (&gv.participant_set_generation); trigger_recv_threads (); } @@ -650,14 +653,14 @@ int new_participant (nn_guid_t *p_ppguid, unsigned flags, const nn_plist_t *plis { nn_guid_t ppguid; - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); ppguid = gv.next_ppguid; if (gv.next_ppguid.prefix.u[2]++ == ~0u) { - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); return ERR_OUT_OF_IDS; } - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); *p_ppguid = ppguid; return new_participant_guid (p_ppguid, flags, plist); @@ -678,7 +681,7 @@ static void delete_builtin_endpoint (const struct nn_guid *ppguid, unsigned enti static struct participant *ref_participant (struct participant *pp, const struct nn_guid *guid_of_refing_entity) { nn_guid_t stguid; - os_mutexLock (&pp->refc_lock); + ddsrt_mutex_lock (&pp->refc_lock); if (guid_of_refing_entity && is_builtin_endpoint (guid_of_refing_entity->entityid, NN_VENDORID_ECLIPSE)) pp->builtin_refc++; else @@ -690,7 +693,7 @@ static struct participant *ref_participant (struct participant *pp, const struct memset (&stguid, 0, sizeof (stguid)); DDS_LOG(DDS_LC_DISCOVERY, "ref_participant(%x:%x:%x:%x @ %p <- %x:%x:%x:%x @ %p) user %d builtin %d\n", PGUID (pp->e.guid), (void*)pp, PGUID (stguid), (void*)guid_of_refing_entity, pp->user_refc, pp->builtin_refc); - os_mutexUnlock (&pp->refc_lock); + ddsrt_mutex_unlock (&pp->refc_lock); return pp; } @@ -717,7 +720,7 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui }; nn_guid_t stguid; - os_mutexLock (&pp->refc_lock); + ddsrt_mutex_lock (&pp->refc_lock); if (guid_of_refing_entity && is_builtin_endpoint (guid_of_refing_entity->entityid, NN_VENDORID_ECLIPSE)) pp->builtin_refc--; else @@ -756,7 +759,7 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui new_participant(). Non-existent built-in endpoints can't be found in guid_hash and are simply ignored. */ pp->builtins_deleted = 1; - os_mutexUnlock (&pp->refc_lock); + ddsrt_mutex_unlock (&pp->refc_lock); if (pp->spdp_xevent) delete_xevent (pp->spdp_xevent); @@ -772,17 +775,17 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui sedp_write_cm_participant (pp, 0); /* If this happens to be the privileged_pp, clear it */ - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); if (pp == gv.privileged_pp) gv.privileged_pp = NULL; - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); for (i = 0; i < (int) (sizeof (builtin_endpoints_tab) / sizeof (builtin_endpoints_tab[0])); i++) delete_builtin_endpoint (&pp->e.guid, builtin_endpoints_tab[i]); } else if (pp->user_refc == 0 && pp->builtin_refc == 0) { - os_mutexUnlock (&pp->refc_lock); + ddsrt_mutex_unlock (&pp->refc_lock); if (!(pp->e.onlylocal)) { @@ -801,23 +804,23 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui the unref_participant, because we may trigger a clean-up of it. */ struct participant *ppp; - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); ppp = gv.privileged_pp; - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); assert (ppp != NULL); unref_participant (ppp, &pp->e.guid); } } - os_mutexLock (&gv.participant_set_lock); + ddsrt_mutex_lock (&gv.participant_set_lock); assert (gv.nparticipants > 0); if (--gv.nparticipants == 0) - os_condBroadcast (&gv.participant_set_cond); - os_mutexUnlock (&gv.participant_set_lock); + ddsrt_cond_broadcast (&gv.participant_set_cond); + ddsrt_mutex_unlock (&gv.participant_set_lock); if (config.many_sockets_mode == MSM_MANY_UNICAST) { - os_atomic_fence_rel (); - os_atomic_inc32 (&gv.participant_set_generation); + ddsrt_atomic_fence_rel (); + ddsrt_atomic_inc32 (&gv.participant_set_generation); /* Deleting the socket will usually suffice to wake up the receiver threads, but in general, no one cares if it takes a @@ -825,16 +828,16 @@ static void unref_participant (struct participant *pp, const struct nn_guid *gui ddsi_conn_free (pp->m_conn); } nn_plist_fini (pp->plist); - os_free (pp->plist); - os_mutexDestroy (&pp->refc_lock); + ddsrt_free (pp->plist); + ddsrt_mutex_destroy (&pp->refc_lock); entity_common_fini (&pp->e); remove_deleted_participant_guid (&pp->e.guid, DPG_LOCAL); inverse_uint32_set_fini(&pp->avail_entityids.x); - os_free (pp); + ddsrt_free (pp); } else { - os_mutexUnlock (&pp->refc_lock); + ddsrt_mutex_unlock (&pp->refc_lock); } } @@ -917,10 +920,10 @@ struct writer *get_builtin_writer (const struct participant *pp, unsigned entity who deletes it early! Lock's not really needed but provides the memory barriers that guarantee visibility of the correct value of privileged_pp. */ - os_mutexLock (&gv.privileged_pp_lock); + ddsrt_mutex_lock (&gv.privileged_pp_lock); assert (gv.privileged_pp != NULL); bwr_guid.prefix = gv.privileged_pp->e.guid.prefix; - os_mutexUnlock (&gv.privileged_pp_lock); + ddsrt_mutex_unlock (&gv.privileged_pp_lock); bwr_guid.entityid.u = entityid; } @@ -999,7 +1002,7 @@ static void rebuild_make_locs(int *p_nlocs, nn_locator_t **p_locs, struct addrse int i, j; nn_locator_t *locs; nlocs = (int)addrset_count(all_addrs); - locs = os_malloc((size_t)nlocs * sizeof(*locs)); + locs = ddsrt_malloc((size_t)nlocs * sizeof(*locs)); flarg.locs = locs; flarg.idx = 0; #ifndef NDEBUG @@ -1028,11 +1031,11 @@ static void rebuild_make_covered(int8_t **covered, const struct writer *wr, int struct wr_prd_match *m; ut_avlIter_t it; int rdidx, i, j; - int8_t *cov = os_malloc((size_t) *nreaders * (size_t) nlocs * sizeof (*cov)); + int8_t *cov = ddsrt_malloc((size_t) *nreaders * (size_t) nlocs * sizeof (*cov)); for (i = 0; i < *nreaders * nlocs; i++) cov[i] = -1; rdidx = 0; - flarg.locs = os_malloc((size_t) nlocs * sizeof(*flarg.locs)); + flarg.locs = ddsrt_malloc((size_t) nlocs * sizeof(*flarg.locs)); #ifndef NDEBUG flarg.size = nlocs; #endif @@ -1072,7 +1075,7 @@ static void rebuild_make_covered(int8_t **covered, const struct writer *wr, int } rdidx++; } - os_free(flarg.locs); + ddsrt_free(flarg.locs); *covered = cov; *nreaders = rdidx; } @@ -1080,7 +1083,7 @@ static void rebuild_make_covered(int8_t **covered, const struct writer *wr, int static void rebuild_make_locs_nrds(int **locs_nrds, int nreaders, int nlocs, const int8_t *covered) { int i, j; - int *ln = os_malloc((size_t) nlocs * sizeof(*ln)); + int *ln = ddsrt_malloc((size_t) nlocs * sizeof(*ln)); for (i = 0; i < nlocs; i++) { int n = 0; @@ -1089,9 +1092,9 @@ static void rebuild_make_locs_nrds(int **locs_nrds, int nreaders, int nlocs, con n++; /* The compiler doesn't realize that ln is large enough. */ -OS_WARNING_MSVC_OFF(6386); +DDSRT_WARNING_MSVC_OFF(6386); ln[i] = n; -OS_WARNING_MSVC_ON(6386); +DDSRT_WARNING_MSVC_ON(6386); } *locs_nrds = ln; } @@ -1208,10 +1211,10 @@ static void rebuild_writer_addrset_setcover(struct addrset *newas, struct writer rebuild_drop(best, nreaders, nlocs, locs_nrds, covered); assert (locs_nrds[best] == 0); } - os_free(locs_nrds); + ddsrt_free(locs_nrds); done: - os_free(locs); - os_free(covered); + ddsrt_free(locs); + ddsrt_free(covered); } static void rebuild_writer_addrset (struct writer *wr) @@ -1243,10 +1246,10 @@ void rebuild_or_clear_writer_addrsets(int rebuild) struct addrset *empty = rebuild ? NULL : new_addrset(); DDS_LOG(DDS_LC_DISCOVERY, "rebuild_or_delete_writer_addrsets(%d)\n", rebuild); ephash_enum_writer_init (&est); - os_rwlockRead (&gv.qoslock); + ddsrt_rwlock_read (&gv.qoslock); while ((wr = ephash_enum_writer_next (&est)) != NULL) { - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if (wr->e.guid.entityid.u != NN_ENTITYID_SPDP_BUILTIN_PARTICIPANT_WRITER) { if (rebuild) @@ -1265,9 +1268,9 @@ void rebuild_or_clear_writer_addrsets(int rebuild) else wr->as = ref_addrset(empty); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } - os_rwlockUnlock (&gv.qoslock); + ddsrt_rwlock_unlock (&gv.qoslock); ephash_enum_writer_fini (&est); unref_addrset(empty); DDS_LOG(DDS_LC_DISCOVERY, "rebuild_or_delete_writer_addrsets(%d) done\n", rebuild); @@ -1278,7 +1281,7 @@ static void free_wr_prd_match (struct wr_prd_match *m) if (m) { nn_lat_estim_fini (&m->hb_to_ack_latency); - os_free (m); + ddsrt_free (m); } } @@ -1295,7 +1298,7 @@ static void free_rd_pwr_match (struct rd_pwr_match *m) DDS_WARNING("failed to leave network partition ssm group\n"); } #endif - os_free (m); + ddsrt_free (m); } } @@ -1306,23 +1309,23 @@ static void free_pwr_rd_match (struct pwr_rd_match *m) if (m->acknack_xevent) delete_xevent (m->acknack_xevent); nn_reorder_free (m->u.not_in_sync.reorder); - os_free (m); + ddsrt_free (m); } } static void free_prd_wr_match (struct prd_wr_match *m) { - if (m) os_free (m); + if (m) ddsrt_free (m); } static void free_rd_wr_match (struct rd_wr_match *m) { - if (m) os_free (m); + if (m) ddsrt_free (m); } static void free_wr_rd_match (struct wr_rd_match *m) { - if (m) os_free (m); + if (m) ddsrt_free (m); } static void writer_drop_connection (const struct nn_guid * wr_guid, const struct proxy_reader * prd) @@ -1332,7 +1335,7 @@ static void writer_drop_connection (const struct nn_guid * wr_guid, const struct { struct whc_node *deferred_free_list = NULL; struct wr_prd_match *m; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if ((m = ut_avlLookup (&wr_readers_treedef, &wr->readers, &prd->e.guid)) != NULL) { struct whc_state whcst; @@ -1341,7 +1344,7 @@ static void writer_drop_connection (const struct nn_guid * wr_guid, const struct remove_acked_messages (wr, &whcst, &deferred_free_list); wr->num_reliable_readers -= m->is_reliable; } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (m != NULL && wr->status_cb) { status_cb_data_t data; @@ -1363,13 +1366,13 @@ static void writer_drop_local_connection (const struct nn_guid *wr_guid, struct { struct wr_rd_match *m; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if ((m = ut_avlLookup (&wr_local_readers_treedef, &wr->local_readers, &rd->e.guid)) != NULL) { ut_avlDelete (&wr_local_readers_treedef, &wr->local_readers, m); } local_reader_ary_remove (&wr->rdary, rd); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (m != NULL && wr->status_cb) { status_cb_data_t data; @@ -1388,10 +1391,10 @@ static void reader_drop_connection (const struct nn_guid *rd_guid, const struct if ((rd = ephash_lookup_reader_guid (rd_guid)) != NULL) { struct rd_pwr_match *m; - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); if ((m = ut_avlLookup (&rd_writers_treedef, &rd->writers, &pwr->e.guid)) != NULL) ut_avlDelete (&rd_writers_treedef, &rd->writers, m); - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); free_rd_pwr_match (m); if (rd->rhc) @@ -1422,10 +1425,10 @@ static void reader_drop_local_connection (const struct nn_guid *rd_guid, const s if ((rd = ephash_lookup_reader_guid (rd_guid)) != NULL) { struct rd_wr_match *m; - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); if ((m = ut_avlLookup (&rd_local_writers_treedef, &rd->local_writers, &wr->e.guid)) != NULL) ut_avlDelete (&rd_local_writers_treedef, &rd->local_writers, m); - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); free_rd_wr_match (m); if (rd->rhc) @@ -1460,12 +1463,12 @@ static void update_reader_init_acknack_count (const struct nn_guid *rd_guid, nn_ DDS_LOG(DDS_LC_DISCOVERY, "update_reader_init_acknack_count (%x:%x:%x:%x, %d): ", PGUID (*rd_guid), count); if ((rd = ephash_lookup_reader_guid (rd_guid)) != NULL) { - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "%d -> ", rd->init_acknack_count); if (count > rd->init_acknack_count) rd->init_acknack_count = count; DDS_LOG(DDS_LC_DISCOVERY, "%d\n", count); - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); } else { @@ -1481,7 +1484,7 @@ static void proxy_writer_drop_connection (const struct nn_guid *pwr_guid, struct { struct pwr_rd_match *m; - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if ((m = ut_avlLookup (&pwr_readers_treedef, &pwr->readers, &rd->e.guid)) != NULL) { ut_avlDelete (&pwr_readers_treedef, &pwr->readers, m); @@ -1495,7 +1498,7 @@ static void proxy_writer_drop_connection (const struct nn_guid *pwr_guid, struct pwr->n_reliable_readers--; } local_reader_ary_remove (&pwr->rdary, rd); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); if (m != NULL) { update_reader_init_acknack_count (&rd->e.guid, m->count); @@ -1511,20 +1514,20 @@ static void proxy_reader_drop_connection if ((prd = ephash_lookup_proxy_reader_guid (prd_guid)) != NULL) { struct prd_wr_match *m; - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); m = ut_avlLookup (&prd_writers_treedef, &prd->writers, &wr->e.guid); if (m) { ut_avlDelete (&prd_writers_treedef, &prd->writers, m); } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); free_prd_wr_match (m); } } static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) { - struct wr_prd_match *m = os_malloc (sizeof (*m)); + struct wr_prd_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; int pretend_everything_acked; m->prd_guid = prd->e.guid; @@ -1535,7 +1538,7 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) m->non_responsive_count = 0; m->rexmit_requests = 0; /* m->demoted: see below */ - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); if (prd->deleting) { DDS_LOG(DDS_LC_DISCOVERY, " writer_add_connection(wr %x:%x:%x:%x prd %x:%x:%x:%x) - prd is being deleted\n", @@ -1552,14 +1555,14 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) { pretend_everything_acked = 0; } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); m->next_acknack = DDSI_COUNT_MIN; m->next_nackfrag = DDSI_COUNT_MIN; nn_lat_estim_init (&m->hb_to_ack_latency); m->hb_to_ack_latency_tlastlog = now (); m->t_acknack_accepted.v = 0; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if (pretend_everything_acked) m->seq = MAX_SEQ_NUMBER; else @@ -1567,9 +1570,9 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) if (ut_avlLookupIPath (&wr_readers_treedef, &wr->readers, &prd->e.guid, &path)) { DDS_LOG(DDS_LC_DISCOVERY, " writer_add_connection(wr %x:%x:%x:%x prd %x:%x:%x:%x) - already connected\n", PGUID (wr->e.guid), PGUID (prd->e.guid)); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); nn_lat_estim_fini (&m->hb_to_ack_latency); - os_free (m); + ddsrt_free (m); } else { @@ -1577,7 +1580,7 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) ut_avlInsertIPath (&wr_readers_treedef, &wr->readers, m, &path); rebuild_writer_addrset (wr); wr->num_reliable_readers += m->is_reliable; - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (wr->status_cb) { @@ -1600,7 +1603,7 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) { const int64_t delta = 1 * T_MILLISECOND; const nn_mtime_t tnext = add_duration_to_mtime (now_mt (), delta); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); /* To make sure that we keep sending heartbeats at a higher rate at the start of this discovery, reset the hbs_since_last_write count to zero. */ @@ -1610,22 +1613,22 @@ static void writer_add_connection (struct writer *wr, struct proxy_reader *prd) wr->hbcontrol.tsched = tnext; resched_xevent_if_earlier (wr->heartbeat_xevent, tnext); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } } } static void writer_add_local_connection (struct writer *wr, struct reader *rd) { - struct wr_rd_match *m = os_malloc (sizeof (*m)); + struct wr_rd_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if (ut_avlLookupIPath (&wr_local_readers_treedef, &wr->local_readers, &rd->e.guid, &path)) { DDS_LOG(DDS_LC_DISCOVERY, " writer_add_local_connection(wr %x:%x:%x:%x rd %x:%x:%x:%x) - already connected\n", PGUID (wr->e.guid), PGUID (rd->e.guid)); - os_mutexUnlock (&wr->e.lock); - os_free (m); + ddsrt_mutex_unlock (&wr->e.lock); + ddsrt_free (m); return; } @@ -1655,7 +1658,7 @@ static void writer_add_local_connection (struct writer *wr, struct reader *rd) } } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "\n"); @@ -1671,12 +1674,12 @@ static void writer_add_local_connection (struct writer *wr, struct reader *rd) static void reader_add_connection (struct reader *rd, struct proxy_writer *pwr, nn_count_t *init_count) { - struct rd_pwr_match *m = os_malloc (sizeof (*m)); + struct rd_pwr_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; m->pwr_guid = pwr->e.guid; - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); /* Initial sequence number of acknacks is the highest stored (+ 1, done when generating the acknack) -- existing connections may be @@ -1691,15 +1694,15 @@ static void reader_add_connection (struct reader *rd, struct proxy_writer *pwr, { DDS_LOG(DDS_LC_DISCOVERY, " reader_add_connection(pwr %x:%x:%x:%x rd %x:%x:%x:%x) - already connected\n", PGUID (pwr->e.guid), PGUID (rd->e.guid)); - os_mutexUnlock (&rd->e.lock); - os_free (m); + ddsrt_mutex_unlock (&rd->e.lock); + ddsrt_free (m); } else { DDS_LOG(DDS_LC_DISCOVERY, " reader_add_connection(pwr %x:%x:%x:%x rd %x:%x:%x:%x)\n", PGUID (pwr->e.guid), PGUID (rd->e.guid)); ut_avlInsertIPath (&rd_writers_treedef, &rd->writers, m, &path); - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); #ifdef DDSI_INCLUDE_SSM if (rd->favours_ssm && pwr->supports_ssm) @@ -1735,24 +1738,24 @@ static void reader_add_connection (struct reader *rd, struct proxy_writer *pwr, static void reader_add_local_connection (struct reader *rd, struct writer *wr) { - struct rd_wr_match *m = os_malloc (sizeof (*m)); + struct rd_wr_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; m->wr_guid = wr->e.guid; - os_mutexLock (&rd->e.lock); + ddsrt_mutex_lock (&rd->e.lock); if (ut_avlLookupIPath (&rd_local_writers_treedef, &rd->local_writers, &wr->e.guid, &path)) { DDS_LOG(DDS_LC_DISCOVERY, " reader_add_local_connection(wr %x:%x:%x:%x rd %x:%x:%x:%x) - already connected\n", PGUID (wr->e.guid), PGUID (rd->e.guid)); - os_mutexUnlock (&rd->e.lock); - os_free (m); + ddsrt_mutex_unlock (&rd->e.lock); + ddsrt_free (m); } else { DDS_LOG(DDS_LC_DISCOVERY, " reader_add_local_connection(wr %x:%x:%x:%x rd %x:%x:%x:%x)\n", PGUID (wr->e.guid), PGUID (rd->e.guid)); ut_avlInsertIPath (&rd_local_writers_treedef, &rd->local_writers, m, &path); - os_mutexUnlock (&rd->e.lock); + ddsrt_mutex_unlock (&rd->e.lock); if (rd->status_cb) { @@ -1771,11 +1774,11 @@ static void reader_add_local_connection (struct reader *rd, struct writer *wr) static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader *rd, nn_mtime_t tnow, nn_count_t init_count) { - struct pwr_rd_match *m = os_malloc (sizeof (*m)); + struct pwr_rd_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; seqno_t last_deliv_seq; - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if (ut_avlLookupIPath (&pwr_readers_treedef, &pwr->readers, &rd->e.guid, &path)) goto already_matched; @@ -1862,7 +1865,7 @@ static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader ut_avlInsertIPath (&pwr_readers_treedef, &pwr->readers, m, &path); local_reader_ary_insert(&pwr->rdary, rd); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); qxev_pwr_entityid (pwr, &rd->e.guid.prefix); DDS_LOG(DDS_LC_DISCOVERY, "\n"); @@ -1882,33 +1885,33 @@ already_matched: assert (is_builtin_entityid (pwr->e.guid.entityid, pwr->c.vendor) ? (pwr->c.topic == NULL) : (pwr->c.topic != NULL)); DDS_LOG(DDS_LC_DISCOVERY, " proxy_writer_add_connection(pwr %x:%x:%x:%x rd %x:%x:%x:%x) - already connected\n", PGUID (pwr->e.guid), PGUID (rd->e.guid)); - os_mutexUnlock (&pwr->e.lock); - os_free (m); + ddsrt_mutex_unlock (&pwr->e.lock); + ddsrt_free (m); return; } static void proxy_reader_add_connection (struct proxy_reader *prd, struct writer *wr) { - struct prd_wr_match *m = os_malloc (sizeof (*m)); + struct prd_wr_match *m = ddsrt_malloc (sizeof (*m)); ut_avlIPath_t path; m->wr_guid = wr->e.guid; - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); if (prd->c.topic == NULL) prd->c.topic = ddsi_sertopic_ref (wr->topic); if (ut_avlLookupIPath (&prd_writers_treedef, &prd->writers, &wr->e.guid, &path)) { DDS_LOG(DDS_LC_DISCOVERY, " proxy_reader_add_connection(wr %x:%x:%x:%x prd %x:%x:%x:%x) - already connected\n", PGUID (wr->e.guid), PGUID (prd->e.guid)); - os_mutexUnlock (&prd->e.lock); - os_free (m); + ddsrt_mutex_unlock (&prd->e.lock); + ddsrt_free (m); } else { DDS_LOG(DDS_LC_DISCOVERY, " proxy_reader_add_connection(wr %x:%x:%x:%x prd %x:%x:%x:%x)\n", PGUID (wr->e.guid), PGUID (prd->e.guid)); ut_avlInsertIPath (&prd_writers_treedef, &prd->writers, m, &path); - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); qxev_prd_entityid (prd, &wr->e.guid.prefix); } } @@ -2025,7 +2028,7 @@ static void connect_writer_with_proxy_reader (struct writer *wr, struct proxy_re const int isb0 = (is_builtin_entityid (wr->e.guid.entityid, NN_VENDORID_ECLIPSE) != 0); const int isb1 = (is_builtin_entityid (prd->e.guid.entityid, prd->c.vendor) != 0); int32_t reason; - OS_UNUSED_ARG(tnow); + DDSRT_UNUSED_ARG(tnow); if (isb0 != isb1) return; if (wr->e.onlylocal) @@ -2242,10 +2245,10 @@ static void generic_do_match (struct entity_common *e, nn_mtime_t tnow) enumerating), but we may visit a single proxy reader multiple times. */ ephash_enum_init (&est, mkind); - os_rwlockRead (&gv.qoslock); + ddsrt_rwlock_read (&gv.qoslock); while ((em = ephash_enum_next (&est)) != NULL) generic_do_match_connect(e, em, tnow); - os_rwlockUnlock (&gv.qoslock); + ddsrt_rwlock_unlock (&gv.qoslock); ephash_enum_fini (&est); } else @@ -2294,10 +2297,10 @@ static void generic_do_local_match (struct entity_common *e, nn_mtime_t tnow) enumerating), but we may visit a single proxy reader multiple times. */ ephash_enum_init (&est, mkind); - os_rwlockRead (&gv.qoslock); + ddsrt_rwlock_read (&gv.qoslock); while ((em = ephash_enum_next (&est)) != NULL) generic_do_local_match_connect(e, em, tnow); - os_rwlockUnlock (&gv.qoslock); + ddsrt_rwlock_unlock (&gv.qoslock); ephash_enum_fini (&est); } @@ -2388,12 +2391,12 @@ static int set_topic_type_name (nn_xqos_t *xqos, const struct ddsi_sertopic * to if (!(xqos->present & QP_TYPE_NAME) && topic) { xqos->present |= QP_TYPE_NAME; - xqos->type_name = os_strdup (topic->typename); + xqos->type_name = ddsrt_strdup (topic->typename); } if (!(xqos->present & QP_TOPIC_NAME) && topic) { xqos->present |= QP_TOPIC_NAME; - xqos->topic_name = os_strdup (topic->name); + xqos->topic_name = ddsrt_strdup (topic->name); } return 0; } @@ -2563,7 +2566,7 @@ void writer_clear_retransmitting (struct writer *wr) { wr->retransmitting = 0; wr->t_whc_high_upd = wr->t_rexmit_end = now_et(); - os_condBroadcast (&wr->throttle_cond); + ddsrt_cond_broadcast (&wr->throttle_cond); } unsigned remove_acked_messages (struct writer *wr, struct whc_state *whcst, struct whc_node **deferred_free_list) @@ -2575,7 +2578,7 @@ unsigned remove_acked_messages (struct writer *wr, struct whc_state *whcst, stru /* when transitioning from >= low-water to < low-water, signal anyone waiting in throttle_writer() */ if (wr->throttling && whcst->unacked_bytes <= wr->whc_low) - os_condBroadcast (&wr->throttle_cond); + ddsrt_cond_broadcast (&wr->throttle_cond); if (wr->retransmitting && whcst->unacked_bytes == 0) writer_clear_retransmitting (wr); if (wr->state == WRST_LINGERING && whcst->unacked_bytes == 0) @@ -2588,7 +2591,7 @@ unsigned remove_acked_messages (struct writer *wr, struct whc_state *whcst, stru static void new_writer_guid_common_init (struct writer *wr, const struct ddsi_sertopic *topic, const struct nn_xqos *xqos, struct whc *whc, status_cb_t status_cb, void * status_entity) { - os_condInit (&wr->throttle_cond, &wr->e.lock); + ddsrt_cond_init (&wr->throttle_cond); wr->seq = 0; wr->cs_seq = 0; INIT_SEQ_XMIT(wr, 0); @@ -2613,7 +2616,7 @@ static void new_writer_guid_common_init (struct writer *wr, const struct ddsi_se /* Copy QoS, merging in defaults */ - wr->xqos = os_malloc (sizeof (*wr->xqos)); + wr->xqos = ddsrt_malloc (sizeof (*wr->xqos)); nn_xqos_copy (wr->xqos, xqos); nn_xqos_mergein_missing (wr->xqos, &gv.default_xqos_wr); assert (wr->xqos->aliased == 0); @@ -2789,7 +2792,7 @@ static struct writer *new_writer_guid (const struct nn_guid *guid, const struct assert (memcmp (&guid->prefix, &pp->e.guid.prefix, sizeof (guid->prefix)) == 0); new_reader_writer_common (guid, topic, xqos); - wr = os_malloc (sizeof (*wr)); + wr = ddsrt_malloc (sizeof (*wr)); /* want a pointer to the participant so that a parallel call to delete_participant won't interfere with our ability to address @@ -2853,7 +2856,7 @@ struct local_orphan_writer *new_local_orphan_writer (nn_entityid_t entityid, str nn_mtime_t tnow = now_mt (); DDS_LOG(DDS_LC_DISCOVERY, "new_local_orphan_writer(%s/%s)\n", topic->name, topic->typename); - lowr = os_malloc (sizeof (*lowr)); + lowr = ddsrt_malloc (sizeof (*lowr)); wr = &lowr->wr; memset (&guid.prefix, 0, sizeof (guid.prefix)); @@ -2918,13 +2921,13 @@ static void gc_delete_writer (struct gcreq *gcreq) #endif unref_addrset (wr->as); /* must remain until readers gone (rebuilding of addrset) */ nn_xqos_fini (wr->xqos); - os_free (wr->xqos); + ddsrt_free (wr->xqos); local_reader_ary_fini (&wr->rdary); - os_condDestroy (&wr->throttle_cond); + ddsrt_cond_destroy (&wr->throttle_cond); ddsi_sertopic_unref ((struct ddsi_sertopic *) wr->topic); endpoint_common_fini (&wr->e, &wr->c); - os_free (wr); + ddsrt_free (wr); } static void gc_delete_writer_throttlewait (struct gcreq *gcreq) @@ -2933,10 +2936,10 @@ static void gc_delete_writer_throttlewait (struct gcreq *gcreq) DDS_LOG(DDS_LC_DISCOVERY, "gc_delete_writer_throttlewait(%p, %x:%x:%x:%x)\n", (void *) gcreq, PGUID (wr->e.guid)); /* We now allow GC while blocked on a full WHC, but we still don't allow deleting a writer while blocked on it. The writer's state must be DELETING by the time we get here, and that means the transmit path is no longer blocked. It doesn't imply that the write thread is no longer in throttle_writer(), just that if it is, it will soon return from there. Therefore, block until it isn't throttling anymore. We can safely lock the writer, as we're on the separate GC thread. */ assert (wr->state == WRST_DELETING); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); while (wr->throttling) - os_condWait (&wr->throttle_cond, &wr->e.lock); - os_mutexUnlock (&wr->e.lock); + ddsrt_cond_wait (&wr->throttle_cond, &wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); gcreq_requeue (gcreq, gc_delete_writer); } @@ -2953,7 +2956,7 @@ static void writer_set_state (struct writer *wr, enum writer_state newstate) write() is a problem because it prevents the gc thread from cleaning up the writer. (Note: late assignment to wr->state is ok, 'tis all protected by the writer lock.) */ - os_condBroadcast (&wr->throttle_cond); + ddsrt_cond_broadcast (&wr->throttle_cond); } wr->state = newstate; } @@ -2986,17 +2989,17 @@ int delete_writer_nolinger (const struct nn_guid *guid) return ERR_UNKNOWN_ENTITY; } DDS_LOG(DDS_LC_DISCOVERY, "delete_writer_nolinger(guid %x:%x:%x:%x) ...\n", PGUID (*guid)); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); delete_writer_nolinger_locked (wr); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); return 0; } void delete_local_orphan_writer (struct local_orphan_writer *lowr) { - os_mutexLock (&lowr->wr.e.lock); + ddsrt_mutex_lock (&lowr->wr.e.lock); delete_writer_nolinger_locked (&lowr->wr); - os_mutexUnlock (&lowr->wr.e.lock); + ddsrt_mutex_unlock (&lowr->wr.e.lock); } int delete_writer (const struct nn_guid *guid) @@ -3009,7 +3012,7 @@ int delete_writer (const struct nn_guid *guid) return ERR_UNKNOWN_ENTITY; } DDS_LOG(DDS_LC_DISCOVERY, "delete_writer(guid %x:%x:%x:%x) ...\n", PGUID (*guid)); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); /* If no unack'ed data, don't waste time or resources (expected to be the usual case), do it immediately. If more data is still @@ -3020,14 +3023,14 @@ int delete_writer (const struct nn_guid *guid) { DDS_LOG(DDS_LC_DISCOVERY, "delete_writer(guid %x:%x:%x:%x) - no unack'ed samples\n", PGUID (*guid)); delete_writer_nolinger_locked (wr); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } else { nn_mtime_t tsched; int tsec, tusec; writer_set_state (wr, WRST_LINGERING); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); tsched = add_duration_to_mtime (now_mt (), config.writer_linger_duration); mtime_to_sec_usec (&tsec, &tusec, tsched); DDS_LOG(DDS_LC_DISCOVERY, "delete_writer(guid %x:%x:%x:%x) - unack'ed samples, will delete when ack'd or at t = %d.%06d\n", @@ -3040,7 +3043,7 @@ int delete_writer (const struct nn_guid *guid) void writer_exit_startup_mode (struct writer *wr) { struct whc_node *deferred_free_list = NULL; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if (wr->startup_mode) { unsigned cnt = 0; @@ -3051,7 +3054,7 @@ void writer_exit_startup_mode (struct writer *wr) writer_clear_retransmitting (wr); DDS_LOG(DDS_LC_DISCOVERY, " %x:%x:%x:%x: dropped %u samples\n", PGUID(wr->e.guid), cnt); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); whc_free_deferred_free_list (wr->whc, deferred_free_list); } @@ -3192,12 +3195,12 @@ static struct reader * new_reader_guid assert (memcmp (&guid->prefix, &pp->e.guid.prefix, sizeof (guid->prefix)) == 0); new_reader_writer_common (guid, topic, xqos); - rd = os_malloc (sizeof (*rd)); + rd = ddsrt_malloc (sizeof (*rd)); endpoint_common_init (&rd->e, &rd->c, EK_READER, guid, group_guid, pp); /* Copy QoS, merging in defaults */ - rd->xqos = os_malloc (sizeof (*rd->xqos)); + rd->xqos = ddsrt_malloc (sizeof (*rd->xqos)); nn_xqos_copy (rd->xqos, xqos); nn_xqos_mergein_missing (rd->xqos, &gv.default_xqos_rd); assert (rd->xqos->aliased == 0); @@ -3368,13 +3371,13 @@ static void gc_delete_reader (struct gcreq *gcreq) ddsi_sertopic_unref ((struct ddsi_sertopic *) rd->topic); nn_xqos_fini (rd->xqos); - os_free (rd->xqos); + ddsrt_free (rd->xqos); #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS unref_addrset (rd->as); #endif endpoint_common_fini (&rd->e, &rd->c); - os_free (rd); + ddsrt_free (rd); } int delete_reader (const struct nn_guid *guid) @@ -3433,19 +3436,19 @@ void proxy_participant_reassign_lease (struct proxy_participant *proxypp, struct The lease_renew(never) call ensures the lease will never expire while we are messing with it. */ - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); if (proxypp->owns_lease) { const nn_etime_t never = { T_NEVER }; struct gcreq *gcreq = gcreq_new (gv.gcreq_queue, gc_proxy_participant_lease); - struct lease *oldlease = os_atomic_ldvoidp (&proxypp->lease); + struct lease *oldlease = ddsrt_atomic_ldvoidp (&proxypp->lease); lease_renew (oldlease, never); gcreq->arg = oldlease; gcreq_enqueue (gcreq); proxypp->owns_lease = 0; } - os_atomic_stvoidp (&proxypp->lease, newlease); - os_mutexUnlock (&proxypp->e.lock); + ddsrt_atomic_stvoidp (&proxypp->lease, newlease); + ddsrt_mutex_unlock (&proxypp->e.lock); } void new_proxy_participant @@ -3474,7 +3477,7 @@ void new_proxy_participant prune_deleted_participant_guids (now_mt ()); - proxypp = os_malloc (sizeof (*proxypp)); + proxypp = ddsrt_malloc (sizeof (*proxypp)); entity_common_init (&proxypp->e, ppguid, "", EK_PROXY_PARTICIPANT, timestamp, vendor, false); proxypp->refc = 1; @@ -3505,7 +3508,7 @@ void new_proxy_participant privpp = ephash_lookup_proxy_participant_guid (&proxypp->privileged_pp_guid); if (privpp != NULL && privpp->is_ddsi2_pp) { - os_atomic_stvoidp (&proxypp->lease, os_atomic_ldvoidp (&privpp->lease)); + ddsrt_atomic_stvoidp (&proxypp->lease, ddsrt_atomic_ldvoidp (&privpp->lease)); proxypp->owns_lease = 0; } else @@ -3513,7 +3516,7 @@ void new_proxy_participant /* Lease duration is meaningless when the lease never expires, but when proxy participants are created implicitly because of endpoint discovery from a cloud service, we do want the lease to expire eventually when the cloud discovery service disappears and never reappears. The normal data path renews the lease, so if the lease expiry is changed after the DS disappears but data continues to flow (even if it is only a single sample) the proxy participant would immediately go back to a non-expiring lease with no further triggers for deleting it. Instead, we take tlease_dur == NEVER as a special value meaning a lease that doesn't expire now and that has a "reasonable" lease duration. That way the lease renewal in the data path is fine, and we only need to do something special in SEDP handling. */ nn_etime_t texp = add_duration_to_etime (now_et(), tlease_dur); int64_t dur = (tlease_dur == T_NEVER) ? config.lease_duration : tlease_dur; - os_atomic_stvoidp (&proxypp->lease, lease_new (texp, dur, &proxypp->e)); + ddsrt_atomic_stvoidp (&proxypp->lease, lease_new (texp, dur, &proxypp->e)); proxypp->owns_lease = 1; } } @@ -3627,13 +3630,13 @@ void new_proxy_participant DDSI2's lease, as we may have become dependent on DDSI2 any time after ephash_insert_proxy_participant_guid even if privileged_pp_guid was NULL originally */ - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); if (proxypp->owns_lease) - lease_register (os_atomic_ldvoidp (&proxypp->lease)); + lease_register (ddsrt_atomic_ldvoidp (&proxypp->lease)); ddsi_plugin.builtintopic_write (&proxypp->e, timestamp, true); - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); } int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, const struct nn_plist *datap, enum update_proxy_participant_source source, nn_wctime_t timestamp) @@ -3644,7 +3647,7 @@ int update_proxy_participant_plist_locked (struct proxy_participant *proxypp, co new_plist = nn_plist_dup (datap); nn_plist_mergein_missing (new_plist, proxypp->plist); nn_plist_fini (proxypp->plist); - os_free (proxypp->plist); + ddsrt_free (proxypp->plist); proxypp->plist = new_plist; switch (source) @@ -3666,7 +3669,7 @@ int update_proxy_participant_plist (struct proxy_participant *proxypp, const str nn_plist_t tmp; /* FIXME: find a better way of restricting which bits can get updated */ - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); switch (source) { case UPD_PROXYPP_SPDP: @@ -3682,13 +3685,13 @@ int update_proxy_participant_plist (struct proxy_participant *proxypp, const str update_proxy_participant_plist_locked (proxypp, &tmp, source, timestamp); break; } - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); return 0; } static void ref_proxy_participant (struct proxy_participant *proxypp, struct proxy_endpoint_common *c) { - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); c->proxypp = proxypp; proxypp->refc++; @@ -3699,7 +3702,7 @@ static void ref_proxy_participant (struct proxy_participant *proxypp, struct pro c->next_ep->prev_ep = c; } proxypp->endpoints = c; - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); } static void unref_proxy_participant (struct proxy_participant *proxypp, struct proxy_endpoint_common *c) @@ -3707,7 +3710,7 @@ static void unref_proxy_participant (struct proxy_participant *proxypp, struct p uint32_t refc; const nn_wctime_t tnow = now(); - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); refc = --proxypp->refc; if (c != NULL) @@ -3723,24 +3726,24 @@ static void unref_proxy_participant (struct proxy_participant *proxypp, struct p if (refc == 0) { assert (proxypp->endpoints == NULL); - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "unref_proxy_participant(%x:%x:%x:%x): refc=0, freeing\n", PGUID (proxypp->e.guid)); unref_addrset (proxypp->as_default); unref_addrset (proxypp->as_meta); nn_plist_fini (proxypp->plist); - os_free (proxypp->plist); + ddsrt_free (proxypp->plist); if (proxypp->owns_lease) - lease_free (os_atomic_ldvoidp (&proxypp->lease)); + lease_free (ddsrt_atomic_ldvoidp (&proxypp->lease)); entity_common_fini (&proxypp->e); remove_deleted_participant_guid (&proxypp->e.guid, DPG_LOCAL | DPG_REMOTE); - os_free (proxypp); + ddsrt_free (proxypp); } else if (proxypp->endpoints == NULL && proxypp->implicitly_created) { assert (refc == 1); - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "unref_proxy_participant(%x:%x:%x:%x): refc=%u, no endpoints, implicitly created, deleting\n", PGUID (proxypp->e.guid), (unsigned) refc); delete_proxy_participant_by_guid(&proxypp->e.guid, tnow, 1); /* Deletion is still (and has to be) asynchronous. A parallel endpoint creation may or may not @@ -3749,7 +3752,7 @@ static void unref_proxy_participant (struct proxy_participant *proxypp, struct p } else { - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "unref_proxy_participant(%x:%x:%x:%x): refc=%u\n", PGUID (proxypp->e.guid), (unsigned) refc); } } @@ -3773,17 +3776,17 @@ static struct entity_common *entity_common_from_proxy_endpoint_common (const str static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct proxy_participant *proxypp, nn_wctime_t timestamp, int isimplicit) { - os_mutexLock (&p->e.lock); + ddsrt_mutex_lock (&p->e.lock); if (memcmp (&p->privileged_pp_guid, &proxypp->e.guid, sizeof (proxypp->e.guid)) != 0) { /* p not dependent on proxypp */ - os_mutexUnlock (&p->e.lock); + ddsrt_mutex_unlock (&p->e.lock); return; } else if (!(vendor_is_cloud(p->vendor) && p->implicitly_created)) { /* DDSI2 minimal participant mode -- but really, anything not discovered via Cloud gets deleted */ - os_mutexUnlock (&p->e.lock); + ddsrt_mutex_unlock (&p->e.lock); (void) delete_proxy_participant_by_guid (&p->e.guid, timestamp, isimplicit); } else @@ -3792,8 +3795,8 @@ static void delete_or_detach_dependent_pp (struct proxy_participant *p, struct p /* Clear dependency (but don't touch entity id, which must be 0x1c1) and set the lease ticking */ DDS_LOG(DDS_LC_DISCOVERY, "%x:%x:%x:%x detach-from-DS %x:%x:%x:%x\n", PGUID(p->e.guid), PGUID(proxypp->e.guid)); memset (&p->privileged_pp_guid.prefix, 0, sizeof (p->privileged_pp_guid.prefix)); - lease_set_expiry (os_atomic_ldvoidp (&p->lease), texp); - os_mutexUnlock (&p->e.lock); + lease_set_expiry (ddsrt_atomic_ldvoidp (&p->lease), texp); + ddsrt_mutex_unlock (&p->e.lock); } } @@ -3816,7 +3819,7 @@ static void delete_ppt (struct proxy_participant * proxypp, nn_wctime_t timestam /* delete_proxy_{reader,writer} merely schedules the actual delete operation, so we can hold the lock -- at least, for now. */ - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); if (isimplicit) proxypp->lease_expired = 1; @@ -3840,7 +3843,7 @@ static void delete_ppt (struct proxy_participant * proxypp, nn_wctime_t timestam (void) ret; c = c->next_ep; } - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); gcreq_proxy_participant (proxypp); } @@ -3890,11 +3893,11 @@ int delete_proxy_participant_by_guid (const struct nn_guid * guid, nn_wctime_t t struct proxy_participant * ppt; DDS_LOG(DDS_LC_DISCOVERY, "delete_proxy_participant_by_guid(%x:%x:%x:%x) ", PGUID (*guid)); - os_mutexLock (&gv.lock); + ddsrt_mutex_lock (&gv.lock); ppt = ephash_lookup_proxy_participant_guid (guid); if (ppt == NULL) { - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); DDS_LOG(DDS_LC_DISCOVERY, "- unknown\n"); return ERR_UNKNOWN_ENTITY; } @@ -3902,7 +3905,7 @@ int delete_proxy_participant_by_guid (const struct nn_guid * guid, nn_wctime_t t ddsi_plugin.builtintopic_write (&ppt->e, timestamp, false); remember_deleted_participant_guid (&ppt->e.guid); ephash_remove_proxy_participant_guid (ppt); - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); delete_ppt (ppt, timestamp, isimplicit); return 0; @@ -3953,7 +3956,7 @@ int new_proxy_group (const struct nn_guid *guid, const char *name, const struct DDS_WARNING("new_proxy_group: unrecognised entityid: %x\n", guid->entityid.u); return ERR_INVALID_DATA; } - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); if ((pgroup = ut_avlLookupIPath (&proxypp_groups_treedef, &proxypp->groups, guid, &ipath)) != NULL) { /* Complete proxy group definition if it was a partial @@ -3966,7 +3969,7 @@ int new_proxy_group (const struct nn_guid *guid, const char *name, const struct { /* Always have a guid, may not have a gid */ DDS_LOG(DDS_LC_DISCOVERY, "new_proxy_group(%x:%x:%x:%x): new\n", PGUID (*guid)); - pgroup = os_malloc (sizeof (*pgroup)); + pgroup = ddsrt_malloc (sizeof (*pgroup)); pgroup->guid = *guid; pgroup->proxypp = proxypp; pgroup->name = NULL; @@ -3977,12 +3980,12 @@ int new_proxy_group (const struct nn_guid *guid, const char *name, const struct { assert (xqos != NULL); DDS_LOG(DDS_LC_DISCOVERY, "new_proxy_group(%x:%x:%x:%x): setting name (%s) and qos\n", PGUID (*guid), name); - pgroup->name = os_strdup (name); + pgroup->name = ddsrt_strdup (name); pgroup->xqos = nn_xqos_dup (xqos); nn_xqos_mergein_missing (pgroup->xqos, is_sub ? &gv.default_xqos_sub : &gv.default_xqos_pub); } out: - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); DDS_LOG(DDS_LC_DISCOVERY, "\n"); return 0; } @@ -4004,10 +4007,10 @@ static void delete_proxy_group_locked (struct proxy_group *pgroup, nn_wctime_t t if (pgroup->name) { nn_xqos_fini (pgroup->xqos); - os_free (pgroup->xqos); - os_free (pgroup->name); + ddsrt_free (pgroup->xqos); + ddsrt_free (pgroup->name); } - os_free (pgroup); + ddsrt_free (pgroup); } void delete_proxy_group (const nn_guid_t *guid, nn_wctime_t timestamp, int isimplicit) @@ -4019,10 +4022,10 @@ void delete_proxy_group (const nn_guid_t *guid, nn_wctime_t timestamp, int isimp if ((proxypp = ephash_lookup_proxy_participant_guid (&ppguid)) != NULL) { struct proxy_group *pgroup; - os_mutexLock (&proxypp->e.lock); + ddsrt_mutex_lock (&proxypp->e.lock); if ((pgroup = ut_avlLookup (&proxypp_groups_treedef, &proxypp->groups, guid)) != NULL) delete_proxy_group_locked (pgroup, timestamp, isimplicit); - os_mutexUnlock (&proxypp->e.lock); + ddsrt_mutex_unlock (&proxypp->e.lock); } } @@ -4059,7 +4062,7 @@ static void proxy_endpoint_common_fini (struct entity_common *e, struct proxy_en ddsi_sertopic_unref (c->topic); nn_xqos_fini (c->xqos); - os_free (c->xqos); + ddsrt_free (c->xqos); unref_addrset (c->as); entity_common_fini (e); @@ -4083,7 +4086,7 @@ int new_proxy_writer (const struct nn_guid *ppguid, const struct nn_guid *guid, return ERR_UNKNOWN_ENTITY; } - pwr = os_malloc (sizeof (*pwr)); + pwr = ddsrt_malloc (sizeof (*pwr)); proxy_endpoint_common_init (&pwr->e, &pwr->c, EK_PROXY_WRITER, guid, timestamp, proxypp, as, plist); ut_avlInit (&pwr_readers_treedef, &pwr->readers); @@ -4093,7 +4096,7 @@ int new_proxy_writer (const struct nn_guid *ppguid, const struct nn_guid *guid, pwr->last_fragnum = ~0u; pwr->nackfragcount = 0; pwr->last_fragnum_reset = 0; - os_atomic_st32 (&pwr->next_deliv_seq_lowword, 1); + ddsrt_atomic_st32 (&pwr->next_deliv_seq_lowword, 1); if (is_builtin_entityid (pwr->e.guid.entityid, pwr->c.vendor)) { /* The DDSI built-in proxy writers always deliver asynchronously */ @@ -4152,9 +4155,9 @@ int new_proxy_writer (const struct nn_guid *ppguid, const struct nn_guid *guid, match_proxy_writer_with_readers (pwr, tnow); ddsi_plugin.builtintopic_write (&pwr->e, timestamp, true); - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); pwr->local_matching_inprogress = 0; - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return 0; } @@ -4167,7 +4170,7 @@ void update_proxy_writer (struct proxy_writer * pwr, struct addrset * as) /* Update proxy writer endpoints (from SEDP alive) */ - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if (! addrset_eq_onesidederr (pwr->c.as, as)) { #ifdef DDSI_INCLUDE_SSM @@ -4187,7 +4190,7 @@ void update_proxy_writer (struct proxy_writer * pwr, struct addrset * as) m = ut_avlIterNext (&iter); } } - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); } void update_proxy_reader (struct proxy_reader * prd, struct addrset * as) @@ -4197,7 +4200,7 @@ void update_proxy_reader (struct proxy_reader * prd, struct addrset * as) memset (&wrguid, 0, sizeof (wrguid)); - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); if (! addrset_eq_onesidederr (prd->c.as, as)) { /* Update proxy reader endpoints (from SEDP alive) */ @@ -4226,20 +4229,20 @@ void update_proxy_reader (struct proxy_reader * prd, struct addrset * as) guid_next.entityid.u = (guid_next.entityid.u & ~(unsigned)0xff) | NN_ENTITYID_KIND_WRITER_NO_KEY; } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); wr = ephash_lookup_writer_guid (&wrguid); if (wr) { - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); rebuild_writer_addrset (wr); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); qxev_prd_entityid (prd, &wr->e.guid.prefix); } wrguid = guid_next; - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); } } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); } static void gc_delete_proxy_writer (struct gcreq *gcreq) @@ -4260,7 +4263,7 @@ static void gc_delete_proxy_writer (struct gcreq *gcreq) proxy_endpoint_common_fini (&pwr->e, &pwr->c); nn_defrag_free (pwr->defrag); nn_reorder_free (pwr->reorder); - os_free (pwr); + ddsrt_free (pwr); } int delete_proxy_writer (const struct nn_guid *guid, nn_wctime_t timestamp, int isimplicit) @@ -4268,10 +4271,10 @@ int delete_proxy_writer (const struct nn_guid *guid, nn_wctime_t timestamp, int struct proxy_writer *pwr; (void)isimplicit; DDS_LOG(DDS_LC_DISCOVERY, "delete_proxy_writer (%x:%x:%x:%x) ", PGUID (*guid)); - os_mutexLock (&gv.lock); + ddsrt_mutex_lock (&gv.lock); if ((pwr = ephash_lookup_proxy_writer_guid (guid)) == NULL) { - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); DDS_LOG(DDS_LC_DISCOVERY, "- unknown\n"); return ERR_UNKNOWN_ENTITY; } @@ -4283,7 +4286,7 @@ int delete_proxy_writer (const struct nn_guid *guid, nn_wctime_t timestamp, int DDS_LOG(DDS_LC_DISCOVERY, "- deleting\n"); ddsi_plugin.builtintopic_write (&pwr->e, timestamp, false); ephash_remove_proxy_writer_guid (pwr); - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); gcreq_proxy_writer (pwr); return 0; } @@ -4309,7 +4312,7 @@ int new_proxy_reader (const struct nn_guid *ppguid, const struct nn_guid *guid, return ERR_UNKNOWN_ENTITY; } - prd = os_malloc (sizeof (*prd)); + prd = ddsrt_malloc (sizeof (*prd)); proxy_endpoint_common_init (&prd->e, &prd->c, EK_PROXY_READER, guid, timestamp, proxypp, as, plist); prd->deleting = 0; @@ -4335,7 +4338,7 @@ static void proxy_reader_set_delete_and_ack_all_messages (struct proxy_reader *p struct prd_wr_match *m; memset (&wrguid, 0, sizeof (wrguid)); - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); prd->deleting = 1; while ((m = ut_avlLookupSuccEq (&prd_writers_treedef, &prd->writers, &wrguid)) != NULL) { @@ -4352,12 +4355,12 @@ static void proxy_reader_set_delete_and_ack_all_messages (struct proxy_reader *p wrguid_next.entityid.u = (wrguid_next.entityid.u & ~(unsigned)0xff) | NN_ENTITYID_KIND_WRITER_NO_KEY; } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); if ((wr = ephash_lookup_writer_guid (&wrguid)) != NULL) { struct whc_node *deferred_free_list = NULL; struct wr_prd_match *m_wr; - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if ((m_wr = ut_avlLookup (&wr_readers_treedef, &wr->readers, &prd->e.guid)) != NULL) { struct whc_state whcst; @@ -4366,14 +4369,14 @@ static void proxy_reader_set_delete_and_ack_all_messages (struct proxy_reader *p (void)remove_acked_messages (wr, &whcst, &deferred_free_list); writer_clear_retransmitting (wr); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); whc_free_deferred_free_list (wr->whc, deferred_free_list); } wrguid = wrguid_next; - os_mutexLock (&prd->e.lock); + ddsrt_mutex_lock (&prd->e.lock); } - os_mutexUnlock (&prd->e.lock); + ddsrt_mutex_unlock (&prd->e.lock); } static void gc_delete_proxy_reader (struct gcreq *gcreq) @@ -4391,7 +4394,7 @@ static void gc_delete_proxy_reader (struct gcreq *gcreq) } proxy_endpoint_common_fini (&prd->e, &prd->c); - os_free (prd); + ddsrt_free (prd); } int delete_proxy_reader (const struct nn_guid *guid, nn_wctime_t timestamp, int isimplicit) @@ -4399,16 +4402,16 @@ int delete_proxy_reader (const struct nn_guid *guid, nn_wctime_t timestamp, int struct proxy_reader *prd; (void)isimplicit; DDS_LOG(DDS_LC_DISCOVERY, "delete_proxy_reader (%x:%x:%x:%x) ", PGUID (*guid)); - os_mutexLock (&gv.lock); + ddsrt_mutex_lock (&gv.lock); if ((prd = ephash_lookup_proxy_reader_guid (guid)) == NULL) { - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); DDS_LOG(DDS_LC_DISCOVERY, "- unknown\n"); return ERR_UNKNOWN_ENTITY; } ddsi_plugin.builtintopic_write (&prd->e, timestamp, false); ephash_remove_proxy_reader_guid (prd); - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); DDS_LOG(DDS_LC_DISCOVERY, "- deleting\n"); /* If the proxy reader is reliable, pretend it has just acked all diff --git a/src/core/ddsi/src/q_ephash.c b/src/core/ddsi/src/q_ephash.c index ba6670d..9413be2 100644 --- a/src/core/ddsi/src/q_ephash.c +++ b/src/core/ddsi/src/q_ephash.c @@ -12,16 +12,15 @@ #include #include -#include "os/os.h" - -#include "util/ut_hopscotch.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_config.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_gc.h" -#include "ddsi/q_rtps.h" /* guid_t */ -#include "ddsi/q_thread.h" /* for assert(thread is awake) */ +#include "dds/ddsrt/heap.h" +#include "dds/util/ut_hopscotch.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_rtps.h" /* guid_t */ +#include "dds/ddsi/q_thread.h" /* for assert(thread is awake) */ struct ephash { struct ut_chh *hash; @@ -65,7 +64,7 @@ static void gc_buckets_cb (struct gcreq *gcreq) { void *bs = gcreq->arg; gcreq_free (gcreq); - os_free (bs); + ddsrt_free (bs); } static void gc_buckets (void *bs) @@ -78,10 +77,10 @@ static void gc_buckets (void *bs) struct ephash *ephash_new (void) { struct ephash *ephash; - ephash = os_malloc (sizeof (*ephash)); + ephash = ddsrt_malloc (sizeof (*ephash)); ephash->hash = ut_chhNew (32, hash_entity_guid_wrapper, entity_guid_eq_wrapper, gc_buckets); if (ephash->hash == NULL) { - os_free (ephash); + ddsrt_free (ephash); return NULL; } else { return ephash; @@ -92,7 +91,7 @@ void ephash_free (struct ephash *ephash) { ut_chhFree (ephash->hash); ephash->hash = NULL; - os_free (ephash); + ddsrt_free (ephash); } static void ephash_guid_insert (struct entity_common *e) @@ -335,7 +334,7 @@ struct proxy_participant *ephash_enum_proxy_participant_next (struct ephash_enum void ephash_enum_fini (struct ephash_enum *st) { - OS_UNUSED_ARG(st); + DDSRT_UNUSED_ARG(st); } void ephash_enum_writer_fini (struct ephash_enum_writer *st) diff --git a/src/core/ddsi/src/q_freelist.c b/src/core/ddsi/src/q_freelist.c index ae82a20..c5259a4 100644 --- a/src/core/ddsi/src/q_freelist.c +++ b/src/core/ddsi/src/q_freelist.c @@ -11,53 +11,56 @@ */ #include -#include "os/os.h" -#include "ddsi/q_freelist.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsi/q_freelist.h" #if FREELIST_TYPE == FREELIST_ATOMIC_LIFO -void nn_freelist_init (_Out_ struct nn_freelist *fl, uint32_t max, off_t linkoff) +void nn_freelist_init (struct nn_freelist *fl, uint32_t max, off_t linkoff) { - os_atomic_lifo_init (&fl->x); - os_atomic_st32(&fl->count, 0); + ddsrt_atomic_lifo_init (&fl->x); + ddsrt_atomic_st32(&fl->count, 0); fl->max = (max == UINT32_MAX) ? max-1 : max; fl->linkoff = linkoff; } -void nn_freelist_fini (_Inout_ _Post_invalid_ struct nn_freelist *fl, _In_ void (*free) (void *elem)) +void nn_freelist_fini (struct nn_freelist *fl, void (*free) (void *elem)) { void *e; - while ((e = os_atomic_lifo_pop (&fl->x, fl->linkoff)) != NULL) + while ((e = ddsrt_atomic_lifo_pop (&fl->x, fl->linkoff)) != NULL) free (e); } -_Check_return_ bool nn_freelist_push (_Inout_ struct nn_freelist *fl, _Inout_ _When_ (return != 0, _Post_invalid_) void *elem) +bool nn_freelist_push (struct nn_freelist *fl, void *elem) { - if (os_atomic_inc32_nv (&fl->count) <= fl->max) + if (ddsrt_atomic_inc32_nv (&fl->count) <= fl->max) { - os_atomic_lifo_push (&fl->x, elem, fl->linkoff); + ddsrt_atomic_lifo_push (&fl->x, elem, fl->linkoff); return true; } else { - os_atomic_dec32 (&fl->count); + ddsrt_atomic_dec32 (&fl->count); return false; } } -_Check_return_ _Ret_maybenull_ void *nn_freelist_pushmany (_Inout_ struct nn_freelist *fl, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *first, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *last, uint32_t n) +void *nn_freelist_pushmany (struct nn_freelist *fl, void *first, void *last, uint32_t n) { - os_atomic_add32 (&fl->count, n); - os_atomic_lifo_pushmany (&fl->x, first, last, fl->linkoff); + ddsrt_atomic_add32 (&fl->count, n); + ddsrt_atomic_lifo_pushmany (&fl->x, first, last, fl->linkoff); return NULL; } -_Check_return_ _Ret_maybenull_ void *nn_freelist_pop (_Inout_ struct nn_freelist *fl) +void *nn_freelist_pop (struct nn_freelist *fl) { void *e; - if ((e = os_atomic_lifo_pop (&fl->x, fl->linkoff)) != NULL) + if ((e = ddsrt_atomic_lifo_pop (&fl->x, fl->linkoff)) != NULL) { - os_atomic_dec32(&fl->count); + ddsrt_atomic_dec32(&fl->count); return e; } else @@ -68,19 +71,19 @@ _Check_return_ _Ret_maybenull_ void *nn_freelist_pop (_Inout_ struct nn_freelist #elif FREELIST_TYPE == FREELIST_DOUBLE -static os_threadLocal int freelist_inner_idx = -1; +static ddsrt_thread_local int freelist_inner_idx = -1; -void nn_freelist_init (_Out_ struct nn_freelist *fl, uint32_t max, off_t linkoff) +void nn_freelist_init (struct nn_freelist *fl, uint32_t max, off_t linkoff) { int i; - os_mutexInit (&fl->lock); + ddsrt_mutex_init (&fl->lock); for (i = 0; i < NN_FREELIST_NPAR; i++) { - os_mutexInit (&fl->inner[i].lock); + ddsrt_mutex_init (&fl->inner[i].lock); fl->inner[i].count = 0; - fl->inner[i].m = os_malloc (sizeof (*fl->inner[i].m)); + fl->inner[i].m = ddsrt_malloc (sizeof (*fl->inner[i].m)); } - os_atomic_st32 (&fl->cc, 0); + ddsrt_atomic_st32 (&fl->cc, 0); fl->mlist = NULL; fl->emlist = NULL; fl->count = 0; @@ -93,38 +96,38 @@ static void *get_next (const struct nn_freelist *fl, const void *e) return *((void **) ((char *)e + fl->linkoff)); } -void nn_freelist_fini (_Inout_ _Post_invalid_ struct nn_freelist *fl, _In_ void (*xfree) (void *)) +void nn_freelist_fini (struct nn_freelist *fl, void (*xfree) (void *)) { int i; uint32_t j; struct nn_freelistM *m; - os_mutexDestroy (&fl->lock); + ddsrt_mutex_destroy (&fl->lock); for (i = 0; i < NN_FREELIST_NPAR; i++) { - os_mutexDestroy (&fl->inner[i].lock); + ddsrt_mutex_destroy (&fl->inner[i].lock); for (j = 0; j < fl->inner[i].count; j++) xfree (fl->inner[i].m->x[j]); - os_free(fl->inner[i].m); + ddsrt_free(fl->inner[i].m); } /* The compiler can't make sense of all these linked lists and doesn't * realize that the next pointers are always initialized here. */ -OS_WARNING_MSVC_OFF(6001); +DDSRT_WARNING_MSVC_OFF(6001); while ((m = fl->mlist) != NULL) { fl->mlist = m->next; for (j = 0; j < NN_FREELIST_MAGSIZE; j++) xfree (m->x[j]); - os_free (m); + ddsrt_free (m); } while ((m = fl->emlist) != NULL) { fl->emlist = m->next; - os_free (m); + ddsrt_free (m); } -OS_WARNING_MSVC_ON(6001); +DDSRT_WARNING_MSVC_ON(6001); } -static os_atomic_uint32_t freelist_inner_idx_off = OS_ATOMIC_UINT32_INIT(0); +static ddsrt_atomic_uint32_t freelist_inner_idx_off = DDSRT_ATOMIC_UINT32_INIT(0); static int get_freelist_inner_idx (void) { @@ -135,7 +138,7 @@ static int get_freelist_inner_idx (void) UINT64_C (10242350189706880077), }; uintptr_t addr; - uint64_t t = (uint64_t) ((uintptr_t) &addr) + os_atomic_ld32 (&freelist_inner_idx_off); + uint64_t t = (uint64_t) ((uintptr_t) &addr) + ddsrt_atomic_ld32 (&freelist_inner_idx_off); freelist_inner_idx = (int) (((((uint32_t) t + unihashconsts[0]) * ((uint32_t) (t >> 32) + unihashconsts[1]))) >> (64 - NN_FREELIST_NPAR_LG2)); } return freelist_inner_idx; @@ -144,36 +147,36 @@ static int get_freelist_inner_idx (void) static int lock_inner (struct nn_freelist *fl) { int k = get_freelist_inner_idx(); - if (os_mutexTryLock (&fl->inner[k].lock) != os_resultSuccess) + if (!ddsrt_mutex_trylock (&fl->inner[k].lock)) { - os_mutexLock (&fl->inner[k].lock); - if (os_atomic_inc32_nv (&fl->cc) == 100) + ddsrt_mutex_lock (&fl->inner[k].lock); + if (ddsrt_atomic_inc32_nv (&fl->cc) == 100) { - os_atomic_st32(&fl->cc, 0); - os_atomic_inc32(&freelist_inner_idx_off); + ddsrt_atomic_st32(&fl->cc, 0); + ddsrt_atomic_inc32(&freelist_inner_idx_off); freelist_inner_idx = -1; } } return k; } -_Check_return_ bool nn_freelist_push (_Inout_ struct nn_freelist *fl, _Inout_ _When_ (return != 0, _Post_invalid_) void *elem) +bool nn_freelist_push (struct nn_freelist *fl, void *elem) { int k = lock_inner (fl); if (fl->inner[k].count < NN_FREELIST_MAGSIZE) { fl->inner[k].m->x[fl->inner[k].count++] = elem; - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return true; } else { struct nn_freelistM *m; - os_mutexLock (&fl->lock); + ddsrt_mutex_lock (&fl->lock); if (fl->count + NN_FREELIST_MAGSIZE >= fl->max) { - os_mutexUnlock (&fl->lock); - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return false; } m = fl->inner[k].m; @@ -182,20 +185,20 @@ _Check_return_ bool nn_freelist_push (_Inout_ struct nn_freelist *fl, _Inout_ _W fl->count += NN_FREELIST_MAGSIZE; fl->inner[k].count = 0; if (fl->emlist == NULL) - fl->inner[k].m = os_malloc (sizeof (*fl->inner[k].m)); + fl->inner[k].m = ddsrt_malloc (sizeof (*fl->inner[k].m)); else { fl->inner[k].m = fl->emlist; fl->emlist = fl->emlist->next; } - os_mutexUnlock (&fl->lock); + ddsrt_mutex_unlock (&fl->lock); fl->inner[k].m->x[fl->inner[k].count++] = elem; - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return true; } } -_Check_return_ _Ret_maybenull_ void *nn_freelist_pushmany (_Inout_ struct nn_freelist *fl, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *first, _Inout_opt_ _When_ (return != 0, _Post_invalid_) void *last, uint32_t n) +void *nn_freelist_pushmany (struct nn_freelist *fl, void *first, void *last, uint32_t n) { void *m = first; (void)last; @@ -211,22 +214,22 @@ _Check_return_ _Ret_maybenull_ void *nn_freelist_pushmany (_Inout_ struct nn_fre return NULL; } -_Check_return_ _Ret_maybenull_ void *nn_freelist_pop (_Inout_ struct nn_freelist *fl) +void *nn_freelist_pop (struct nn_freelist *fl) { int k = lock_inner (fl); if (fl->inner[k].count > 0) { void *e = fl->inner[k].m->x[--fl->inner[k].count]; - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return e; } else { - os_mutexLock (&fl->lock); + ddsrt_mutex_lock (&fl->lock); if (fl->mlist == NULL) { - os_mutexUnlock (&fl->lock); - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return NULL; } else @@ -237,10 +240,10 @@ _Check_return_ _Ret_maybenull_ void *nn_freelist_pop (_Inout_ struct nn_freelist fl->inner[k].m = fl->mlist; fl->mlist = fl->mlist->next; fl->count -= NN_FREELIST_MAGSIZE; - os_mutexUnlock (&fl->lock); + ddsrt_mutex_unlock (&fl->lock); fl->inner[k].count = NN_FREELIST_MAGSIZE; e = fl->inner[k].m->x[--fl->inner[k].count]; - os_mutexUnlock (&fl->inner[k].lock); + ddsrt_mutex_unlock (&fl->inner[k].lock); return e; } } diff --git a/src/core/ddsi/src/q_gc.c b/src/core/ddsi/src/q_gc.c index 4ea9d4f..915c92b 100644 --- a/src/core/ddsi/src/q_gc.c +++ b/src/core/ddsi/src/q_gc.c @@ -13,25 +13,26 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_globals.h" /* for mattr, cattr */ -#include "ddsi/q_gc.h" -#include "ddsi/q_log.h" -#include "ddsi/q_config.h" -#include "ddsi/q_time.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_globals.h" /* for mattr, cattr */ - -#include "ddsi/q_rtps.h" /* for guid_hash */ +#include "dds/ddsi/q_rtps.h" /* for guid_hash */ struct gcreq_queue { struct gcreq *first; struct gcreq *last; - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; int terminate; int32_t count; struct thread_state1 *ts; @@ -80,11 +81,11 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) { struct thread_state1 *self = lookup_thread_state (); nn_mtime_t next_thread_cputime = { 0 }; - struct os_time shortsleep = { 0, 1 * T_MILLISECOND }; + dds_time_t shortsleep = 1 * T_MILLISECOND; int64_t delay = T_MILLISECOND; /* force evaluation after startup */ struct gcreq *gcreq = NULL; int trace_shortsleep = 1; - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); while (!(q->terminate && q->count == 0)) { LOG_THREAD_CPUTIME (next_thread_cputime); @@ -98,17 +99,15 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) assert (trace_shortsleep); if (q->first == NULL) { - /* FIXME: fix os_time and use absolute timeouts */ - struct os_time to; + /* FIXME: use absolute timeouts */ + dds_time_t to; if (delay >= 1000 * T_SECOND) { /* avoid overflow */ - to.tv_sec = 1000; - to.tv_nsec = 0; + to = DDS_SECS(1000); } else { - to.tv_sec = (os_timeSec)(delay / T_SECOND); - to.tv_nsec = (int32_t)(delay % T_SECOND); + to = delay; } - os_condTimedWait (&q->cond, &q->lock, &to); + ddsrt_cond_waitfor(&q->cond, &q->lock, to); } if (q->first) { @@ -116,7 +115,7 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) q->first = q->first->next; } } - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); /* Cleanup dead proxy entities. One can argue this should be an independent thread, but one can also easily argue that an @@ -143,7 +142,7 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) DDS_TRACE("gc %p: not yet, shortsleep\n", (void*)gcreq); trace_shortsleep = 0; } - os_nanoSleep (shortsleep); + dds_sleepfor (shortsleep); } else { @@ -160,21 +159,21 @@ static uint32_t gcreq_queue_thread (struct gcreq_queue *q) } } - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); } - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); return 0; } struct gcreq_queue *gcreq_queue_new (void) { - struct gcreq_queue *q = os_malloc (sizeof (*q)); + struct gcreq_queue *q = ddsrt_malloc (sizeof (*q)); q->first = q->last = NULL; q->terminate = 0; q->count = 0; - os_mutexInit (&q->lock); - os_condInit (&q->cond, &q->lock); + ddsrt_mutex_init (&q->lock); + ddsrt_cond_init (&q->cond); q->ts = create_thread ("gc", (uint32_t (*) (void *)) gcreq_queue_thread, q); assert (q->ts); return q; @@ -182,10 +181,10 @@ struct gcreq_queue *gcreq_queue_new (void) void gcreq_queue_drain (struct gcreq_queue *q) { - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); while (q->count != 0) - os_condWait (&q->cond, &q->lock); - os_mutexUnlock (&q->lock); + ddsrt_cond_wait (&q->cond, &q->lock); + ddsrt_mutex_unlock (&q->lock); } void gcreq_queue_free (struct gcreq_queue *q) @@ -196,14 +195,14 @@ void gcreq_queue_free (struct gcreq_queue *q) gcreq = gcreq_new (q, gcreq_free); gcreq->nvtimes = 0; - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); q->terminate = 1; /* Wait until there is only request in existence, the one we just allocated (this is also why we can't use "drain" here). Then we know the gc system is quiet. */ while (q->count != 1) - os_condWait (&q->cond, &q->lock); - os_mutexUnlock (&q->lock); + ddsrt_cond_wait (&q->cond, &q->lock); + ddsrt_mutex_unlock (&q->lock); /* Force the gc thread to wake up by enqueueing our no-op. The callback, gcreq_free, will be called immediately, which causes @@ -213,40 +212,40 @@ void gcreq_queue_free (struct gcreq_queue *q) join_thread (q->ts); assert (q->first == NULL); - os_condDestroy (&q->cond); - os_mutexDestroy (&q->lock); - os_free (q); + ddsrt_cond_destroy (&q->cond); + ddsrt_mutex_destroy (&q->lock); + ddsrt_free (q); } struct gcreq *gcreq_new (struct gcreq_queue *q, gcreq_cb_t cb) { struct gcreq *gcreq; - gcreq = os_malloc (offsetof (struct gcreq, vtimes) + thread_states.nthreads * sizeof (*gcreq->vtimes)); + gcreq = ddsrt_malloc (offsetof (struct gcreq, vtimes) + thread_states.nthreads * sizeof (*gcreq->vtimes)); gcreq->cb = cb; gcreq->queue = q; threads_vtime_gather_for_wait (&gcreq->nvtimes, gcreq->vtimes); - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); q->count++; - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); return gcreq; } void gcreq_free (struct gcreq *gcreq) { struct gcreq_queue *gcreq_queue = gcreq->queue; - os_mutexLock (&gcreq_queue->lock); + ddsrt_mutex_lock (&gcreq_queue->lock); --gcreq_queue->count; if (gcreq_queue->count <= 1) - os_condBroadcast (&gcreq_queue->cond); - os_mutexUnlock (&gcreq_queue->lock); - os_free (gcreq); + ddsrt_cond_broadcast (&gcreq_queue->cond); + ddsrt_mutex_unlock (&gcreq_queue->lock); + ddsrt_free (gcreq); } static int gcreq_enqueue_common (struct gcreq *gcreq) { struct gcreq_queue *gcreq_queue = gcreq->queue; int isfirst; - os_mutexLock (&gcreq_queue->lock); + ddsrt_mutex_lock (&gcreq_queue->lock); gcreq->next = NULL; if (gcreq_queue->first) { @@ -260,8 +259,8 @@ static int gcreq_enqueue_common (struct gcreq *gcreq) } gcreq_queue->last = gcreq; if (isfirst) - os_condBroadcast (&gcreq_queue->cond); - os_mutexUnlock (&gcreq_queue->lock); + ddsrt_cond_broadcast (&gcreq_queue->cond); + ddsrt_mutex_unlock (&gcreq_queue->lock); return isfirst; } diff --git a/src/core/ddsi/src/q_init.c b/src/core/ddsi/src/q_init.c index b40ce17..d5ca562 100644 --- a/src/core/ddsi/src/q_init.c +++ b/src/core/ddsi/src/q_init.c @@ -12,51 +12,55 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/time.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/sync.h" -#include "util/ut_avl.h" -#include "util/ut_thread_pool.h" +#include "dds/util/ut_avl.h" +#include "dds/util/ut_thread_pool.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_lat_estim.h" -#include "ddsi/q_bitset.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_ddsi_discovery.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_error.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_gc.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_receive.h" -#include "ddsi/q_pcap.h" -#include "ddsi/q_feature_check.h" -#include "ddsi/q_debmon.h" -#include "ddsi/q_init.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_lat_estim.h" +#include "dds/ddsi/q_bitset.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_receive.h" +#include "dds/ddsi/q_pcap.h" +#include "dds/ddsi/q_feature_check.h" +#include "dds/ddsi/q_debmon.h" +#include "dds/ddsi/q_init.h" -#include "ddsi/ddsi_tran.h" -#include "ddsi/ddsi_udp.h" -#include "ddsi/ddsi_tcp.h" -#include "ddsi/ddsi_raweth.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/ddsi_tran.h" +#include "dds/ddsi/ddsi_udp.h" +#include "dds/ddsi/ddsi_tcp.h" +#include "dds/ddsi/ddsi_raweth.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/ddsi_serdata_default.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__whc.h" -#include "ddsi/ddsi_iid.h" +#include "dds/ddsi/ddsi_iid.h" static void add_peer_addresses (struct addrset *as, const struct config_peer_listelem *list) { @@ -142,9 +146,9 @@ static int set_recvips (void) if (config.networkRecvAddressStrings) { - if (os_strcasecmp (config.networkRecvAddressStrings[0], "all") == 0) + if (ddsrt_strcasecmp (config.networkRecvAddressStrings[0], "all") == 0) { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (gv.ipv6_link_local) { DDS_WARNING("DDSI2EService/General/MulticastRecvNetworkInterfaceAddresses: using 'preferred' instead of 'all' because of IPv6 link-local address\n"); @@ -156,9 +160,9 @@ static int set_recvips (void) gv.recvips_mode = RECVIPS_MODE_ALL; } } - else if (os_strcasecmp (config.networkRecvAddressStrings[0], "any") == 0) + else if (ddsrt_strcasecmp (config.networkRecvAddressStrings[0], "any") == 0) { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (gv.ipv6_link_local) { DDS_ERROR("DDSI2EService/General/MulticastRecvNetworkInterfaceAddresses: 'any' is unsupported in combination with an IPv6 link-local address\n"); @@ -167,15 +171,15 @@ static int set_recvips (void) #endif gv.recvips_mode = RECVIPS_MODE_ANY; } - else if (os_strcasecmp (config.networkRecvAddressStrings[0], "preferred") == 0) + else if (ddsrt_strcasecmp (config.networkRecvAddressStrings[0], "preferred") == 0) { gv.recvips_mode = RECVIPS_MODE_PREFERRED; } - else if (os_strcasecmp (config.networkRecvAddressStrings[0], "none") == 0) + else if (ddsrt_strcasecmp (config.networkRecvAddressStrings[0], "none") == 0) { gv.recvips_mode = RECVIPS_MODE_NONE; } -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 else if (gv.ipv6_link_local) { /* If the configuration explicitly includes the selected @@ -225,7 +229,7 @@ static int set_recvips (void) DDS_ERROR("No interface bound to requested address '%s'\n", config.networkRecvAddressStrings[i]); return -1; } - *recvnode = os_malloc (sizeof (struct config_in_addr_node)); + *recvnode = ddsrt_malloc (sizeof (struct config_in_addr_node)); (*recvnode)->loc = loc; recvnode = &(*recvnode)->next; *recvnode = NULL; @@ -422,7 +426,7 @@ static int check_thread_properties (void) return ok; } -OS_WARNING_MSVC_OFF(4996); +DDSRT_WARNING_MSVC_OFF(4996); int rtps_config_open (void) { int status; @@ -433,12 +437,12 @@ int rtps_config_open (void) config.tracingOutputFile = NULL; status = 1; } - else if (os_strcasecmp (config.tracingOutputFileName, "stdout") == 0) + else if (ddsrt_strcasecmp (config.tracingOutputFileName, "stdout") == 0) { config.tracingOutputFile = stdout; status = 1; } - else if (os_strcasecmp (config.tracingOutputFileName, "stderr") == 0) + else if (ddsrt_strcasecmp (config.tracingOutputFileName, "stderr") == 0) { config.tracingOutputFile = stderr; status = 1; @@ -458,7 +462,7 @@ int rtps_config_open (void) return status; } -OS_WARNING_MSVC_ON(4996); +DDSRT_WARNING_MSVC_ON(4996); int rtps_config_prep (struct cfgst *cfgst) { @@ -542,7 +546,7 @@ int rtps_config_prep (struct cfgst *cfgst) while (chptr) { size_t slen = strlen (chptr->name) + 5; - char *thread_name = os_malloc (slen); + char *thread_name = ddsrt_malloc (slen); (void) snprintf (thread_name, slen, "tev.%s", chptr->name); num_channels++; @@ -561,7 +565,7 @@ int rtps_config_prep (struct cfgst *cfgst) lookup_thread_properties (thread_name)) num_channel_threads++; - os_free (thread_name); + ddsrt_free (thread_name); chptr = chptr->next; } if (error) @@ -689,15 +693,15 @@ err_disc: static void rtps_term_prep (void) { /* Stop all I/O */ - os_mutexLock (&gv.lock); + ddsrt_mutex_lock (&gv.lock); if (gv.rtps_keepgoing) { gv.rtps_keepgoing = 0; /* so threads will stop once they get round to checking */ - os_atomic_fence (); + ddsrt_atomic_fence (); /* can't wake up throttle_writer, currently, but it'll check every few seconds */ trigger_recv_threads (); } - os_mutexUnlock (&gv.lock); + ddsrt_mutex_unlock (&gv.lock); } struct wait_for_receive_threads_helper_arg { @@ -751,9 +755,9 @@ static struct ddsi_sertopic *make_special_topic (uint16_t enc_id, const struct d - initialising/freeing them here, in this manner, is not very clean it should be moved to somewhere in the topic implementation (kinda natural if they stop being "default" ones) */ - struct ddsi_sertopic_default *st = os_malloc (sizeof (*st)); + struct ddsi_sertopic_default *st = ddsrt_malloc (sizeof (*st)); memset (st, 0, sizeof (*st)); - os_atomic_st32 (&st->c.refc, 1); + ddsrt_atomic_st32 (&st->c.refc, 1); st->c.ops = &ddsi_sertopic_ops_default; st->c.serdata_ops = ops; st->c.serdata_basehash = ddsi_sertopic_compute_serdata_basehash (st->c.serdata_ops); @@ -765,8 +769,8 @@ static struct ddsi_sertopic *make_special_topic (uint16_t enc_id, const struct d static void make_special_topics (void) { - gv.plist_topic = make_special_topic (PLATFORM_IS_LITTLE_ENDIAN ? PL_CDR_LE : PL_CDR_BE, &ddsi_serdata_ops_plist); - gv.rawcdr_topic = make_special_topic (PLATFORM_IS_LITTLE_ENDIAN ? CDR_LE : CDR_BE, &ddsi_serdata_ops_rawcdr); + gv.plist_topic = make_special_topic (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? PL_CDR_LE : PL_CDR_BE, &ddsi_serdata_ops_plist); + gv.rawcdr_topic = make_special_topic (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? CDR_LE : CDR_BE, &ddsi_serdata_ops_rawcdr); } static void free_special_topics (void) @@ -882,11 +886,8 @@ int rtps_init (void) { int sec = (int) (gv.tstart.v / 1000000000); int usec = (int) (gv.tstart.v % 1000000000) / 1000; - os_time tv; - char str[OS_CTIME_R_BUFSIZE]; - tv.tv_sec = sec; - tv.tv_nsec = usec * 1000; - os_ctime_r (&tv, str, sizeof(str)); + char str[DDSRT_RFC3339STRLEN]; + ddsrt_ctime(gv.tstart.v, str, sizeof(str)); DDS_LOG(DDS_LC_CONFIG, "started at %d.06%d -- %s\n", sec, usec, str); } @@ -989,12 +990,12 @@ int rtps_init (void) { static const char msgtag_fixed[] = ": partition address"; size_t slen = strlen (np->name) + sizeof (msgtag_fixed); - char * msgtag = os_malloc (slen); + char * msgtag = ddsrt_malloc (slen); int rc; snprintf (msgtag, slen, "%s%s", np->name, msgtag_fixed); np->as = new_addrset (); rc = add_addresses_to_addrset (np->as, np->address_string, port, msgtag, 1); - os_free (msgtag); + ddsrt_free (msgtag); if (rc < 0) goto err_network_partition_addrset; } @@ -1031,23 +1032,23 @@ int rtps_init (void) make_special_topics (); - os_mutexInit (&gv.participant_set_lock); - os_condInit (&gv.participant_set_cond, &gv.participant_set_lock); + ddsrt_mutex_init (&gv.participant_set_lock); + ddsrt_cond_init (&gv.participant_set_cond); lease_management_init (); deleted_participants_admin_init (); gv.guid_hash = ephash_new (); - os_mutexInit (&gv.privileged_pp_lock); + ddsrt_mutex_init (&gv.privileged_pp_lock); gv.privileged_pp = NULL; /* 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_getpid (); + gv.next_ppguid.prefix.u[1] = (unsigned) ddsrt_getpid (); gv.next_ppguid.prefix.u[2] = 1; gv.next_ppguid.entityid.u = NN_ENTITYID_PARTICIPANT; - os_mutexInit (&gv.lock); - os_mutexInit (&gv.spdp_lock); + ddsrt_mutex_init (&gv.lock); + ddsrt_mutex_init (&gv.spdp_lock); gv.spdp_defrag = nn_defrag_new (NN_DEFRAG_DROP_OLDEST, config.defrag_unreliable_maxsamples); gv.spdp_reorder = nn_reorder_new (NN_REORDER_MODE_ALWAYS_DELIVER, config.primary_reorder_maxsamples); @@ -1101,7 +1102,7 @@ int rtps_init (void) gv.pcap_fp = new_pcap_file (config.pcap_file); if (gv.pcap_fp) { - os_mutexInit (&gv.pcap_lock); + ddsrt_mutex_init (&gv.pcap_lock); } } else @@ -1176,7 +1177,7 @@ int rtps_init (void) while (chptr) { size_t slen = strlen (chptr->name) + 5; - char * tname = os_malloc (slen); + char * tname = ddsrt_malloc (slen); (void) snprintf (tname, slen, "tev.%s", chptr->name); /* Only actually create new connection if diffserv set */ @@ -1221,7 +1222,7 @@ int rtps_init (void) ); } #endif - os_free (tname); + ddsrt_free (tname); chptr = chptr->next; } } @@ -1272,7 +1273,7 @@ int rtps_init (void) gv.gcreq_queue = gcreq_queue_new (); gv.rtps_keepgoing = 1; - os_rwlockInit (&gv.qoslock); + ddsrt_rwlock_init (&gv.qoslock); { int r; @@ -1337,7 +1338,7 @@ err_mc_conn: if (gv.data_conn_mc && gv.data_conn_mc != gv.disc_conn_mc) ddsi_conn_free (gv.data_conn_mc); if (gv.pcap_fp) - os_mutexDestroy (&gv.pcap_lock); + ddsrt_mutex_destroy (&gv.pcap_lock); if (gv.disc_conn_uc != gv.disc_conn_mc) ddsi_conn_free (gv.disc_conn_uc); if (gv.data_conn_uc != gv.disc_conn_uc) @@ -1347,15 +1348,15 @@ err_unicast_sockets: ddsi_tkmap_free (gv.m_tkmap); nn_reorder_free (gv.spdp_reorder); nn_defrag_free (gv.spdp_defrag); - os_mutexDestroy (&gv.spdp_lock); - os_mutexDestroy (&gv.lock); - os_mutexDestroy (&gv.privileged_pp_lock); + ddsrt_mutex_destroy (&gv.spdp_lock); + ddsrt_mutex_destroy (&gv.lock); + ddsrt_mutex_destroy (&gv.privileged_pp_lock); ephash_free (gv.guid_hash); gv.guid_hash = NULL; deleted_participants_admin_fini (); lease_management_term (); - os_condDestroy (&gv.participant_set_cond); - os_mutexDestroy (&gv.participant_set_lock); + ddsrt_cond_destroy (&gv.participant_set_cond); + ddsrt_mutex_destroy (&gv.participant_set_lock); free_special_topics (); #ifdef DDSI_INCLUDE_ENCRYPTION if (q_security_plugin.free_decoder) @@ -1385,13 +1386,13 @@ err_set_ext_address: { struct config_in_addr_node *n = gv.recvips; gv.recvips = n->next; - os_free (n); + ddsrt_free (n); } err_set_recvips: { int i; for (i = 0; i < gv.n_interfaces; i++) - os_free (gv.interfaces[i].name); + ddsrt_free (gv.interfaces[i].name); } err_find_own_ip: ddsi_tran_factories_fini (); @@ -1402,18 +1403,18 @@ err_udp_tcp_init: } struct dq_builtins_ready_arg { - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; int ready; }; static void builtins_dqueue_ready_cb (void *varg) { struct dq_builtins_ready_arg *arg = varg; - os_mutexLock (&arg->lock); + ddsrt_mutex_lock (&arg->lock); arg->ready = 1; - os_condBroadcast (&arg->cond); - os_mutexUnlock (&arg->lock); + ddsrt_cond_broadcast (&arg->cond); + ddsrt_mutex_unlock (&arg->lock); } void rtps_stop (void) @@ -1454,23 +1455,23 @@ void rtps_stop (void) deleting them */ { struct dq_builtins_ready_arg arg; - os_mutexInit (&arg.lock); - os_condInit (&arg.cond, &arg.lock); + ddsrt_mutex_init (&arg.lock); + ddsrt_cond_init (&arg.cond); arg.ready = 0; nn_dqueue_enqueue_callback(gv.builtins_dqueue, builtins_dqueue_ready_cb, &arg); - os_mutexLock (&arg.lock); + ddsrt_mutex_lock (&arg.lock); while (!arg.ready) - os_condWait (&arg.cond, &arg.lock); - os_mutexUnlock (&arg.lock); - os_condDestroy (&arg.cond); - os_mutexDestroy (&arg.lock); + ddsrt_cond_wait (&arg.cond, &arg.lock); + ddsrt_mutex_unlock (&arg.lock); + ddsrt_cond_destroy (&arg.cond); + ddsrt_mutex_destroy (&arg.lock); } /* Once the receive threads have stopped, defragmentation and reorder state can't change anymore, and can be freed safely. */ nn_reorder_free (gv.spdp_reorder); nn_defrag_free (gv.spdp_defrag); - os_mutexDestroy (&gv.spdp_lock); + ddsrt_mutex_destroy (&gv.spdp_lock); #ifdef DDSI_INCLUDE_ENCRYPTION if (q_security_plugin.free_decoder) { @@ -1536,10 +1537,10 @@ void rtps_stop (void) /* Wait until all participants are really gone => by then we can be certain that no new GC requests will be added, short of what we do here */ - os_mutexLock (&gv.participant_set_lock); + ddsrt_mutex_lock (&gv.participant_set_lock); while (gv.nparticipants > 0) - os_condWait (&gv.participant_set_cond, &gv.participant_set_lock); - os_mutexUnlock (&gv.participant_set_lock); + ddsrt_cond_wait (&gv.participant_set_cond, &gv.participant_set_lock); + ddsrt_mutex_unlock (&gv.participant_set_lock); /* Wait until no more GC requests are outstanding -- not really necessary, but it allows us to claim the stack is quiescent @@ -1549,7 +1550,7 @@ void rtps_stop (void) /* Clean up privileged_pp -- it must be NULL now (all participants are gone), but the lock still needs to be destroyed */ assert (gv.privileged_pp == NULL); - os_mutexDestroy (&gv.privileged_pp_lock); + ddsrt_mutex_destroy (&gv.privileged_pp_lock); } void rtps_fini (void) @@ -1616,7 +1617,7 @@ void rtps_fini (void) if (gv.pcap_fp) { - os_mutexDestroy (&gv.pcap_lock); + ddsrt_mutex_destroy (&gv.pcap_lock); fclose (gv.pcap_fp); } @@ -1647,8 +1648,8 @@ void rtps_fini (void) gv.guid_hash = NULL; deleted_participants_admin_fini (); lease_management_term (); - os_mutexDestroy (&gv.participant_set_lock); - os_condDestroy (&gv.participant_set_cond); + ddsrt_mutex_destroy (&gv.participant_set_lock); + ddsrt_cond_destroy (&gv.participant_set_cond); free_special_topics (); nn_xqos_fini (&gv.builtin_endpoint_xqos_wr); @@ -1662,23 +1663,23 @@ void rtps_fini (void) nn_xqos_fini (&gv.default_xqos_rd); nn_plist_fini (&gv.default_plist_pp); - os_mutexDestroy (&gv.lock); - os_rwlockDestroy (&gv.qoslock); + ddsrt_mutex_destroy (&gv.lock); + ddsrt_rwlock_destroy (&gv.qoslock); while (gv.recvips) { struct config_in_addr_node *n = gv.recvips; /* The compiler doesn't realize that n->next is always initialized. */ -OS_WARNING_MSVC_OFF(6001); +DDSRT_WARNING_MSVC_OFF(6001); gv.recvips = n->next; -OS_WARNING_MSVC_ON(6001); - os_free (n); +DDSRT_WARNING_MSVC_ON(6001); + ddsrt_free (n); } { int i; for (i = 0; i < (int) gv.n_interfaces; i++) - os_free (gv.interfaces[i].name); + ddsrt_free (gv.interfaces[i].name); } ddsi_serdatapool_free (gv.serpool); diff --git a/src/core/ddsi/src/q_inverse_uint32_set.c b/src/core/ddsi/src/q_inverse_uint32_set.c index 7a1af44..99d24ac 100644 --- a/src/core/ddsi/src/q_inverse_uint32_set.c +++ b/src/core/ddsi/src/q_inverse_uint32_set.c @@ -11,11 +11,11 @@ */ #include #include -#include "os/os.h" -#include "util/ut_avl.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_inverse_uint32_set.h" +#include "dds/ddsrt/heap.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_inverse_uint32_set.h" static int uint32_t_cmp(const void *va, const void *vb); @@ -55,7 +55,7 @@ void inverse_uint32_set_init(struct inverse_uint32_set *set, uint32_t min, uint3 set->cursor = min; set->min = min; set->max = max; - n = os_malloc(sizeof(*n)); + n = ddsrt_malloc(sizeof(*n)); n->min = min; n->max = max; ut_avlInsert(&inverse_uint32_set_td, &set->ids, n); @@ -64,7 +64,7 @@ void inverse_uint32_set_init(struct inverse_uint32_set *set, uint32_t min, uint3 void inverse_uint32_set_fini(struct inverse_uint32_set *set) { - ut_avlFree(&inverse_uint32_set_td, &set->ids, os_free); + ut_avlFree(&inverse_uint32_set_td, &set->ids, ddsrt_free); } static uint32_t inverse_uint32_set_alloc_use_min(struct inverse_uint32_set *set, struct inverse_uint32_set_node *n) @@ -73,7 +73,7 @@ static uint32_t inverse_uint32_set_alloc_use_min(struct inverse_uint32_set *set, if (n->min == n->max) { ut_avlDelete(&inverse_uint32_set_td, &set->ids, n); - os_free(n); + ddsrt_free(n); } else { @@ -100,7 +100,7 @@ int inverse_uint32_set_alloc(uint32_t * const id, struct inverse_uint32_set *set } else { - struct inverse_uint32_set_node *n1 = os_malloc(sizeof(*n1)); + struct inverse_uint32_set_node *n1 = ddsrt_malloc(sizeof(*n1)); assert(n->min < set->cursor && set->cursor < n->max); n1->min = set->cursor + 1; n1->max = n->max; @@ -150,7 +150,7 @@ void inverse_uint32_set_free(struct inverse_uint32_set *set, uint32_t id) } else { n->max = n1->max; ut_avlDeleteDPath(&inverse_uint32_set_td, &set->ids, n1, &dp); - os_free(n1); + ddsrt_free(n1); } } } @@ -161,7 +161,7 @@ void inverse_uint32_set_free(struct inverse_uint32_set *set, uint32_t id) else { /* no adjacent interval */ - n = os_malloc(sizeof(*n)); + n = ddsrt_malloc(sizeof(*n)); n->min = n->max = id; ut_avlInsertIPath(&inverse_uint32_set_td, &set->ids, n, &ip); } diff --git a/src/core/ddsi/src/q_lat_estim.c b/src/core/ddsi/src/q_lat_estim.c index c56a482..2302b32 100644 --- a/src/core/ddsi/src/q_lat_estim.c +++ b/src/core/ddsi/src/q_lat_estim.c @@ -12,9 +12,9 @@ #include #include -#include "ddsi/q_log.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_lat_estim.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_lat_estim.h" #include #include diff --git a/src/core/ddsi/src/q_lease.c b/src/core/ddsi/src/q_lease.c index 457de76..438c0bf 100644 --- a/src/core/ddsi/src/q_lease.c +++ b/src/core/ddsi/src/q_lease.c @@ -13,30 +13,31 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" -#include "util/ut_fibheap.h" +#include "dds/util/ut_fibheap.h" -#include "ddsi/ddsi_serdata_default.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_ddsi_discovery.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_gc.h" +#include "dds/ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_gc.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! */ @@ -69,9 +70,9 @@ static int compare_lease_tsched (const void *va, const void *vb) void lease_management_init (void) { int i; - os_mutexInit (&gv.leaseheap_lock); + ddsrt_mutex_init (&gv.leaseheap_lock); for (i = 0; i < N_LEASE_LOCKS; i++) - os_mutexInit (&gv.lease_locks[i]); + ddsrt_mutex_init (&gv.lease_locks[i]); ut_fibheapInit (&lease_fhdef, &gv.leaseheap); } @@ -80,11 +81,11 @@ void lease_management_term (void) int i; assert (ut_fibheapMin (&lease_fhdef, &gv.leaseheap) == NULL); for (i = 0; i < N_LEASE_LOCKS; i++) - os_mutexDestroy (&gv.lease_locks[i]); - os_mutexDestroy (&gv.leaseheap_lock); + ddsrt_mutex_destroy (&gv.lease_locks[i]); + ddsrt_mutex_destroy (&gv.leaseheap_lock); } -static os_mutex *lock_lease_addr (struct lease const * const l) +static ddsrt_mutex_t *lock_lease_addr (struct lease const * const l) { uint32_t u = (uint16_t) ((uintptr_t) l >> 3); uint32_t v = u * 0xb4817365; @@ -94,18 +95,18 @@ static os_mutex *lock_lease_addr (struct lease const * const l) static void lock_lease (const struct lease *l) { - os_mutexLock (lock_lease_addr (l)); + ddsrt_mutex_lock (lock_lease_addr (l)); } static void unlock_lease (const struct lease *l) { - os_mutexUnlock (lock_lease_addr (l)); + ddsrt_mutex_unlock (lock_lease_addr (l)); } struct lease *lease_new (nn_etime_t texpire, int64_t tdur, struct entity_common *e) { struct lease *l; - if ((l = os_malloc (sizeof (*l))) == NULL) + if ((l = ddsrt_malloc (sizeof (*l))) == NULL) return NULL; DDS_TRACE("lease_new(tdur %"PRId64" guid %x:%x:%x:%x) @ %p\n", tdur, PGUID (e->guid), (void *) l); l->tdur = tdur; @@ -118,7 +119,7 @@ struct lease *lease_new (nn_etime_t texpire, int64_t tdur, struct entity_common void lease_register (struct lease *l) { DDS_TRACE("lease_register(l %p guid %x:%x:%x:%x)\n", (void *) l, PGUID (l->entity->guid)); - os_mutexLock (&gv.leaseheap_lock); + ddsrt_mutex_lock (&gv.leaseheap_lock); lock_lease (l); assert (l->tsched.v == TSCHED_NOT_ON_HEAP); if (l->tend.v != T_NEVER) @@ -127,7 +128,7 @@ void lease_register (struct lease *l) ut_fibheapInsert (&lease_fhdef, &gv.leaseheap, l); } unlock_lease (l); - os_mutexUnlock (&gv.leaseheap_lock); + ddsrt_mutex_unlock (&gv.leaseheap_lock); /* check_and_handle_lease_expiration runs on GC thread and the only way to be sure that it wakes up in time is by forcing re-evaluation (strictly speaking only needed if this is the first lease to expire, but this operation is quite rare anyway) */ force_lease_check(); @@ -136,11 +137,11 @@ void lease_register (struct lease *l) void lease_free (struct lease *l) { DDS_TRACE("lease_free(l %p guid %x:%x:%x:%x)\n", (void *) l, PGUID (l->entity->guid)); - os_mutexLock (&gv.leaseheap_lock); + ddsrt_mutex_lock (&gv.leaseheap_lock); if (l->tsched.v != TSCHED_NOT_ON_HEAP) ut_fibheapDelete (&lease_fhdef, &gv.leaseheap, l); - os_mutexUnlock (&gv.leaseheap_lock); - os_free (l); + ddsrt_mutex_unlock (&gv.leaseheap_lock); + ddsrt_free (l); /* see lease_register() */ force_lease_check(); @@ -178,7 +179,7 @@ void lease_set_expiry (struct lease *l, nn_etime_t when) { bool trigger = false; assert (when.v >= 0); - os_mutexLock (&gv.leaseheap_lock); + ddsrt_mutex_lock (&gv.leaseheap_lock); lock_lease (l); l->tend = when; if (l->tend.v < l->tsched.v) @@ -197,7 +198,7 @@ void lease_set_expiry (struct lease *l, nn_etime_t when) trigger = true; } unlock_lease (l); - os_mutexUnlock (&gv.leaseheap_lock); + ddsrt_mutex_unlock (&gv.leaseheap_lock); /* see lease_register() */ if (trigger) @@ -208,7 +209,7 @@ int64_t check_and_handle_lease_expiration (UNUSED_ARG (struct thread_state1 *sel { struct lease *l; int64_t delay; - os_mutexLock (&gv.leaseheap_lock); + ddsrt_mutex_lock (&gv.leaseheap_lock); while ((l = ut_fibheapMin (&lease_fhdef, &gv.leaseheap)) != NULL && l->tsched.v <= tnowE.v) { nn_guid_t g = l->entity->guid; @@ -277,7 +278,7 @@ int64_t check_and_handle_lease_expiration (UNUSED_ARG (struct thread_state1 *sel unlock_lease (l); l->tsched.v = TSCHED_NOT_ON_HEAP; - os_mutexUnlock (&gv.leaseheap_lock); + ddsrt_mutex_unlock (&gv.leaseheap_lock); switch (k) { @@ -301,11 +302,11 @@ int64_t check_and_handle_lease_expiration (UNUSED_ARG (struct thread_state1 *sel break; } - os_mutexLock (&gv.leaseheap_lock); + ddsrt_mutex_lock (&gv.leaseheap_lock); } delay = (l == NULL) ? T_NEVER : (l->tsched.v - tnowE.v); - os_mutexUnlock (&gv.leaseheap_lock); + ddsrt_mutex_unlock (&gv.leaseheap_lock); return delay; } @@ -329,7 +330,7 @@ static void debug_print_rawdata (const char *msg, const void *data, size_t len) void handle_PMD (UNUSED_ARG (const struct receiver_state *rst), nn_wctime_t timestamp, unsigned statusinfo, const void *vdata, unsigned len) { const struct CDRHeader *data = vdata; /* built-ins not deserialized (yet) */ - const int bswap = (data->identifier == CDR_LE) ^ PLATFORM_IS_LITTLE_ENDIAN; + const int bswap = (data->identifier == CDR_LE) ^ (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); struct proxy_participant *pp; nn_guid_t ppguid; DDS_TRACE(" PMD ST%x", statusinfo); @@ -363,7 +364,7 @@ void handle_PMD (UNUSED_ARG (const struct receiver_state *rst), nn_wctime_t time /* Renew lease if arrival of this message didn't already do so, also renew the lease of the virtual participant used for DS-discovered endpoints */ if (!config.arrival_of_data_asserts_pp_and_ep_liveliness) - lease_renew (os_atomic_ldvoidp (&pp->lease), now_et ()); + lease_renew (ddsrt_atomic_ldvoidp (&pp->lease), now_et ()); } } break; diff --git a/src/core/ddsi/src/q_md5.c b/src/core/ddsi/src/q_md5.c index d05d9c2..1a041c2 100644 --- a/src/core/ddsi/src/q_md5.c +++ b/src/core/ddsi/src/q_md5.c @@ -63,18 +63,18 @@ 1999-05-03 lpd Original version. */ -#include "ddsi/q_md5.h" +#include "dds/ddsi/q_md5.h" #include -#include "os/os.h" /* big or little endianness */ +#include "dds/ddsrt/endian.h" /* big or little endianness */ /* Byte order stuff hacked to use OSPL's macros */ #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#if OS_ENDIANNESS == OS_BIG_ENDIAN +#if DDSRT_ENDIAN == DDSRT_BIG_ENDIAN # define BYTE_ORDER 1 -#elif OS_ENDIANNESS == OS_LITTLE_ENDIAN +#elif DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN # define BYTE_ORDER -1 #else -# error "OS_ENDIANNESS not defined" +# error "DDSRT_ENDIAN not defined" #endif #define T_MASK ((md5_word_t)~0) diff --git a/src/core/ddsi/src/q_misc.c b/src/core/ddsi/src/q_misc.c index 2412962..3c97d19 100644 --- a/src/core/ddsi/src/q_misc.c +++ b/src/core/ddsi/src/q_misc.c @@ -11,9 +11,9 @@ */ #include -#include "ddsi/q_misc.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_md5.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_md5.h" extern inline seqno_t fromSN (const nn_sequence_number_t sn); extern inline nn_sequence_number_t toSN (seqno_t n); diff --git a/src/core/ddsi/src/q_nwif.c b/src/core/ddsi/src/q_nwif.c index 605858b..d72cb32 100644 --- a/src/core/ddsi/src/q_nwif.c +++ b/src/core/ddsi/src/q_nwif.c @@ -15,24 +15,26 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/sockets.h" -#include "ddsi/q_log.h" -#include "ddsi/q_nwif.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_config.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_md5.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_addrset.h" /* unspec locator */ -#include "ddsi/q_feature_check.h" -#include "ddsi/ddsi_ipaddr.h" -#include "util/ut_avl.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_nwif.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_md5.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_addrset.h" /* unspec locator */ +#include "dds/ddsi/q_feature_check.h" +#include "dds/ddsi/ddsi_ipaddr.h" +#include "dds/util/ut_avl.h" static void print_sockerror (const char *msg) { - int err = os_getErrno (); - DDS_ERROR("SOCKET %s errno %d\n", msg, err); + DDS_ERROR("SOCKET %s\n", msg); } unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src) @@ -42,11 +44,11 @@ unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src) memcpy (&id, src->address + 12, sizeof (id)); else { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_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_append (&st, (const md5_byte_t *) ((const struct sockaddr_in6 *) src)->sin6_addr.s6_addr, 16); md5_finish (&st, digest); memcpy (&id, digest, sizeof (id)); #else @@ -57,9 +59,9 @@ unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src) } #ifdef DDSI_INCLUDE_NETWORK_CHANNELS -void set_socket_diffserv (os_socket sock, int diffserv) +void set_socket_diffserv (ddsrt_socket_t sock, int diffserv) { - if (os_sockSetsockopt (sock, IPPROTO_IP, IP_TOS, (char*) &diffserv, sizeof (diffserv)) != os_resultSuccess) + if (ddsrt_setsockopt (sock, IPPROTO_IP, IP_TOS, (char*) &diffserv, sizeof (diffserv)) != DDS_RETCODE_OK) { print_sockerror ("IP_TOS"); } @@ -67,10 +69,10 @@ void set_socket_diffserv (os_socket sock, int diffserv) #endif #ifdef SO_NOSIGPIPE -static void set_socket_nosigpipe (os_socket sock) +static void set_socket_nosigpipe (ddsrt_socket_t sock) { int val = 1; - if (os_sockSetsockopt (sock, SOL_SOCKET, SO_NOSIGPIPE, (char*) &val, sizeof (val)) != os_resultSuccess) + if (ddsrt_setsockopt (sock, SOL_SOCKET, SO_NOSIGPIPE, (char*) &val, sizeof (val)) != DDS_RETCODE_OK) { print_sockerror ("SO_NOSIGPIPE"); } @@ -78,17 +80,17 @@ static void set_socket_nosigpipe (os_socket sock) #endif #ifdef TCP_NODELAY -static void set_socket_nodelay (os_socket sock) +static void set_socket_nodelay (ddsrt_socket_t sock) { int val = 1; - if (os_sockSetsockopt (sock, IPPROTO_TCP, TCP_NODELAY, (char*) &val, sizeof (val)) != os_resultSuccess) + if (ddsrt_setsockopt (sock, IPPROTO_TCP, TCP_NODELAY, (char*) &val, sizeof (val)) != DDS_RETCODE_OK) { print_sockerror ("TCP_NODELAY"); } } #endif -static int set_rcvbuf (os_socket socket) +static int set_rcvbuf (ddsrt_socket_t socket) { uint32_t ReceiveBufferSize; uint32_t optlen = (uint32_t) sizeof (ReceiveBufferSize); @@ -97,7 +99,7 @@ static int set_rcvbuf (os_socket socket) socket_min_rcvbuf_size = 1048576; else socket_min_rcvbuf_size = config.socket_min_rcvbuf_size.value; - if (os_sockGetsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen) != os_resultSuccess) + if (ddsrt_getsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen) != DDS_RETCODE_OK) { print_sockerror ("get SO_RCVBUF"); return -2; @@ -106,12 +108,12 @@ static int set_rcvbuf (os_socket socket) { /* make sure the receive buffersize is at least the minimum required */ ReceiveBufferSize = socket_min_rcvbuf_size; - (void) os_sockSetsockopt (socket, SOL_SOCKET, SO_RCVBUF, (const char *) &ReceiveBufferSize, sizeof (ReceiveBufferSize)); + (void) ddsrt_setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (const char *) &ReceiveBufferSize, sizeof (ReceiveBufferSize)); /* We don't check the return code from setsockopt, because some O/Ss tend to silently cap the buffer size. The only way to make sure is to read the option value back and check it is now set correctly. */ - if (os_sockGetsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen) != os_resultSuccess) + if (ddsrt_getsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) &ReceiveBufferSize, &optlen) != DDS_RETCODE_OK) { print_sockerror ("get SO_RCVBUF"); return -2; @@ -132,11 +134,11 @@ static int set_rcvbuf (os_socket socket) return 0; } -static int set_sndbuf (os_socket socket) +static int set_sndbuf (ddsrt_socket_t socket) { unsigned SendBufferSize; uint32_t optlen = (uint32_t) sizeof(SendBufferSize); - if (os_sockGetsockopt(socket, SOL_SOCKET, SO_SNDBUF,(char *)&SendBufferSize, &optlen) != os_resultSuccess) + if (ddsrt_getsockopt(socket, SOL_SOCKET, SO_SNDBUF,(char *)&SendBufferSize, &optlen) != DDS_RETCODE_OK) { print_sockerror ("get SO_SNDBUF"); return -2; @@ -145,7 +147,7 @@ static int set_sndbuf (os_socket socket) { /* make sure the send buffersize is at least the minimum required */ SendBufferSize = config.socket_min_sndbuf_size; - if (os_sockSetsockopt (socket, SOL_SOCKET, SO_SNDBUF, (const char *)&SendBufferSize, sizeof (SendBufferSize)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (const char *)&SendBufferSize, sizeof (SendBufferSize)) != DDS_RETCODE_OK) { print_sockerror ("SO_SNDBUF"); return -2; @@ -154,15 +156,15 @@ static int set_sndbuf (os_socket socket) return 0; } -static int maybe_set_dont_route (os_socket socket) +static int maybe_set_dont_route (ddsrt_socket_t socket) { if (config.dontRoute) { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6 || config.transport_selector == TRANS_UDP6) { unsigned ipv6Flag = 1; - if (os_sockSetsockopt (socket, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ipv6Flag, sizeof (ipv6Flag))) + if (ddsrt_setsockopt (socket, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ipv6Flag, sizeof (ipv6Flag)) != DDS_RETCODE_OK) { print_sockerror ("IPV6_UNICAST_HOPS"); return -2; @@ -173,7 +175,7 @@ static int maybe_set_dont_route (os_socket socket) if (config.transport_selector == TRANS_TCP || config.transport_selector == TRANS_UDP) { int one = 1; - if (os_sockSetsockopt (socket, SOL_SOCKET, SO_DONTROUTE, (char *) &one, sizeof (one)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, SOL_SOCKET, SO_DONTROUTE, (char *) &one, sizeof (one)) != DDS_RETCODE_OK) { print_sockerror ("SO_DONTROUTE"); return -2; @@ -183,13 +185,13 @@ static int maybe_set_dont_route (os_socket socket) return 0; } -static int set_reuse_options (os_socket socket) +static int set_reuse_options (ddsrt_socket_t socket) { /* Set REUSEADDR (if available on platform) for multicast sockets, leave unicast sockets alone. */ int one = 1; - if (os_sockSetsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one)) != DDS_RETCODE_OK) { print_sockerror ("SO_REUSEADDR"); return -2; @@ -197,22 +199,22 @@ static int set_reuse_options (os_socket socket) return 0; } -static int bind_socket (os_socket socket, unsigned short port) +static int bind_socket (ddsrt_socket_t socket, unsigned short port) { - os_result rc; + dds_retcode_t rc = DDS_RETCODE_ERROR; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6 || config.transport_selector == TRANS_UDP6) { - os_sockaddr_in6 socketname; + struct sockaddr_in6 socketname; memset (&socketname, 0, sizeof (socketname)); socketname.sin6_family = AF_INET6; socketname.sin6_port = htons (port); - socketname.sin6_addr = os_in6addr_any; + socketname.sin6_addr = ddsrt_in6addr_any; if (IN6_IS_ADDR_LINKLOCAL (&socketname.sin6_addr)) { socketname.sin6_scope_id = gv.interfaceNo; } - rc = os_sockBind (socket, (struct sockaddr *) &socketname, sizeof (socketname)); + rc = ddsrt_bind (socket, (struct sockaddr *) &socketname, sizeof (socketname)); } else #endif @@ -222,40 +224,33 @@ static int bind_socket (os_socket socket, unsigned short port) socketname.sin_family = AF_INET; socketname.sin_port = htons (port); socketname.sin_addr.s_addr = htonl (INADDR_ANY); - rc = os_sockBind (socket, (struct sockaddr *) &socketname, sizeof (socketname)); + rc = ddsrt_bind (socket, (struct sockaddr *) &socketname, sizeof (socketname)); } - else + if (rc != DDS_RETCODE_OK && rc != DDS_RETCODE_PRECONDITION_NOT_MET) { - rc = os_resultFail; + print_sockerror ("bind"); } - if (rc != os_resultSuccess) - { - if (os_getErrno () != os_sockEADDRINUSE) - { - print_sockerror ("bind"); - } - } - return (rc == os_resultSuccess) ? 0 : -1; + return (rc == DDS_RETCODE_OK) ? 0 : -1; } -#if OS_SOCKET_HAS_IPV6 -static int set_mc_options_transmit_ipv6 (os_socket socket) +#if DDSRT_HAVE_IPV6 +static int set_mc_options_transmit_ipv6 (ddsrt_socket_t socket) { unsigned interfaceNo = gv.interfaceNo; unsigned ttl = (unsigned) config.multicast_ttl; unsigned loop; - if (os_sockSetsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_IF, &interfaceNo, sizeof (interfaceNo)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_IF, &interfaceNo, sizeof (interfaceNo)) != DDS_RETCODE_OK) { print_sockerror ("IPV6_MULTICAST_IF"); return -2; } - if (os_sockSetsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *) &ttl, sizeof (ttl)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *) &ttl, sizeof (ttl)) != DDS_RETCODE_OK) { print_sockerror ("IPV6_MULTICAST_HOPS"); return -2; } loop = (unsigned) !!config.enableMulticastLoopback; - if (os_sockSetsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, sizeof (loop)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, sizeof (loop)) != DDS_RETCODE_OK) { print_sockerror ("IPV6_MULTICAST_LOOP"); return -2; @@ -264,11 +259,11 @@ static int set_mc_options_transmit_ipv6 (os_socket socket) } #endif -static int set_mc_options_transmit_ipv4 (os_socket socket) +static int set_mc_options_transmit_ipv4 (ddsrt_socket_t socket) { unsigned char ttl = (unsigned char) config.multicast_ttl; unsigned char loop; - os_result ret; + dds_retcode_t ret; #if defined __linux || defined __APPLE__ if (config.use_multicast_if_mreqn) @@ -282,26 +277,26 @@ static int set_mc_options_transmit_ipv4 (os_socket socket) else mreqn.imr_address.s_addr = htonl (INADDR_ANY); mreqn.imr_ifindex = (int) gv.interfaceNo; - ret = os_sockSetsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof (mreqn)); + ret = ddsrt_setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof (mreqn)); } else #endif { - ret = os_sockSetsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, gv.ownloc.address + 12, 4); + ret = ddsrt_setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, gv.ownloc.address + 12, 4); } - if (ret != os_resultSuccess) + if (ret != DDS_RETCODE_OK) { print_sockerror ("IP_MULTICAST_IF"); return -2; } - if (os_sockSetsockopt (socket, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &ttl, sizeof (ttl)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &ttl, sizeof (ttl)) != DDS_RETCODE_OK) { print_sockerror ("IP_MULICAST_TTL"); return -2; } loop = (unsigned char) config.enableMulticastLoopback; - if (os_sockSetsockopt (socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof (loop)) != os_resultSuccess) + if (ddsrt_setsockopt (socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof (loop)) != DDS_RETCODE_OK) { print_sockerror ("IP_MULTICAST_LOOP"); return -2; @@ -309,9 +304,9 @@ static int set_mc_options_transmit_ipv4 (os_socket socket) return 0; } -static int set_mc_options_transmit (os_socket socket) +static int set_mc_options_transmit (ddsrt_socket_t socket) { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6 || config.transport_selector == TRANS_UDP6) { return set_mc_options_transmit_ipv6 (socket); @@ -330,31 +325,32 @@ static int set_mc_options_transmit (os_socket socket) int make_socket ( - os_socket * sock, + ddsrt_socket_t * sock, unsigned short port, bool stream, bool reuse ) { int rc = -2; + dds_retcode_t ret; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (config.transport_selector == TRANS_TCP6 || config.transport_selector == TRANS_UDP6) { - *sock = os_sockNew (AF_INET6, stream ? SOCK_STREAM : SOCK_DGRAM); + ret = ddsrt_socket(sock, AF_INET6, stream ? SOCK_STREAM : SOCK_DGRAM, 0); } else #endif if (config.transport_selector == TRANS_TCP || config.transport_selector == TRANS_UDP) { - *sock = os_sockNew (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM); + ret = ddsrt_socket(sock, AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0); } else { return -2; } - if (! OS_VALID_SOCKET (*sock)) + if (ret != DDS_RETCODE_OK) { print_sockerror ("socket"); return rc; @@ -401,24 +397,24 @@ int make_socket fail: - os_sockFree (*sock); - *sock = OS_INVALID_SOCKET; + ddsrt_close(*sock); + *sock = DDSRT_INVALID_SOCKET; return rc; } static int multicast_override(const char *ifname) { - char *copy = os_strdup (config.assumeMulticastCapable), *cursor = copy, *tok; + char *copy = ddsrt_strdup (config.assumeMulticastCapable), *cursor = copy, *tok; int match = 0; if (copy != NULL) { - while ((tok = os_strsep (&cursor, ",")) != NULL) + while ((tok = ddsrt_strsep (&cursor, ",")) != NULL) { if (ddsi2_patmatch (tok, ifname)) match = 1; } } - os_free (copy); + ddsrt_free (copy); return match; } @@ -433,7 +429,7 @@ int find_own_ip (const char *requested_address) char last_if_name[80] = ""; int quality = -1; int i; - os_ifaddrs_t *ifa, *ifa_root = NULL; + ddsrt_ifaddrs_t *ifa, *ifa_root = NULL; int maxq_list[MAX_INTERFACES]; int maxq_count = 0; size_t maxq_strlen = 0; @@ -458,17 +454,17 @@ int find_own_ip (const char *requested_address) char if_name[sizeof (last_if_name)]; int q = 0; - os_strlcpy(if_name, ifa->name, sizeof(if_name)); + ddsrt_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); - os_strlcpy(last_if_name, if_name, sizeof(last_if_name)); + ddsrt_strlcpy(last_if_name, if_name, sizeof(last_if_name)); /* interface must be up */ if ((ifa->flags & IFF_UP) == 0) { DDS_LOG(DDS_LC_CONFIG, " (interface down)"); continue; - } else if (os_sockaddr_is_unspecified(ifa->addr)) { + } else if (ddsrt_sockaddr_isunspecified(ifa->addr)) { DDS_LOG(DDS_LC_CONFIG, " (address unspecified)"); continue; } @@ -503,14 +499,14 @@ int find_own_ip (const char *requested_address) available, because the other interfaces at least in principle allow communicating with other machines. */ q += 0; -#if OS_SOCKET_HAS_IPV6 - if (!(ifa->addr->sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL (&((os_sockaddr_in6 *)ifa->addr)->sin6_addr))) +#if DDSRT_HAVE_IPV6 + if (!(ifa->addr->sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *)ifa->addr)->sin6_addr))) q += 1; #endif } else { -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 /* We accept link-local IPv6 addresses, but an interface with a link-local address will end up lower in the ordering than one with a global address. When forced to use a link-local @@ -521,7 +517,7 @@ int find_own_ip (const char *requested_address) which it was received. But that means proper multi-homing support and has quite an impact in various places, not least of which is the abstraction layer. */ - if (!(ifa->addr->sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL (&((os_sockaddr_in6 *)ifa->addr)->sin6_addr))) + if (!(ifa->addr->sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *)ifa->addr)->sin6_addr))) q += 5; #endif @@ -563,11 +559,11 @@ int find_own_ip (const char *requested_address) gv.interfaces[gv.n_interfaces].mc_capable = ((ifa->flags & IFF_MULTICAST) != 0); gv.interfaces[gv.n_interfaces].point_to_point = ((ifa->flags & IFF_POINTOPOINT) != 0); gv.interfaces[gv.n_interfaces].if_index = ifa->index; - gv.interfaces[gv.n_interfaces].name = os_strdup (if_name); + gv.interfaces[gv.n_interfaces].name = ddsrt_strdup (if_name); gv.n_interfaces++; } DDS_LOG(DDS_LC_CONFIG, "\n"); - os_freeifaddrs (ifa_root); + ddsrt_freeifaddrs (ifa_root); if (requested_address == NULL) { @@ -577,13 +573,13 @@ int find_own_ip (const char *requested_address) char *names; int p; ddsi_locator_to_string_no_port (addrbuf, sizeof(addrbuf), &gv.interfaces[idx].loc); - names = os_malloc (maxq_strlen + 1); + names = ddsrt_malloc (maxq_strlen + 1); p = 0; for (i = 0; i < maxq_count && (size_t) p < maxq_strlen; i++) p += snprintf (names + p, maxq_strlen - (size_t) p, ", %s", gv.interfaces[maxq_list[i]].name); DDS_WARNING("using network interface %s (%s) selected arbitrarily from: %s\n", gv.interfaces[idx].name, addrbuf, names + 2); - os_free (names); + ddsrt_free (names); } if (maxq_count > 0) @@ -646,10 +642,10 @@ int find_own_ip (const char *requested_address) gv.ownloc = gv.interfaces[selected_idx].loc; gv.selected_interface = selected_idx; gv.interfaceNo = gv.interfaces[selected_idx].if_index; -#if OS_SOCKET_HAS_IPV6 +#if DDSRT_HAVE_IPV6 if (gv.extloc.kind == NN_LOCATOR_KIND_TCPv6 || gv.extloc.kind == NN_LOCATOR_KIND_UDPv6) { - os_sockaddr_in6 addr; + struct sockaddr_in6 addr; memcpy(&addr.sin6_addr, gv.ownloc.address, sizeof(addr.sin6_addr)); gv.ipv6_link_local = IN6_IS_ADDR_LINKLOCAL (&addr.sin6_addr) != 0; } diff --git a/src/core/ddsi/src/q_pcap.c b/src/core/ddsi/src/q_pcap.c index 046a3c1..c48e636 100644 --- a/src/core/ddsi/src/q_pcap.c +++ b/src/core/ddsi/src/q_pcap.c @@ -12,14 +12,13 @@ #include #include -#include "os/os.h" - -#include "ddsi/q_log.h" -#include "ddsi/q_time.h" -#include "ddsi/q_config.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_pcap.h" +#include "dds/ddsrt/endian.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_pcap.h" /* pcap format info taken from http://wiki.wireshark.org/Development/LibpcapFileFormat */ @@ -78,7 +77,7 @@ static const ipv4_hdr_t ipv4_hdr_template = { #define IPV4_HDR_SIZE 20 #define UDP_HDR_SIZE 8 -OS_WARNING_MSVC_OFF(4996); +DDSRT_WARNING_MSVC_OFF(4996); FILE *new_pcap_file (const char *name) { FILE *fp; @@ -101,9 +100,9 @@ FILE *new_pcap_file (const char *name) return fp; } -OS_WARNING_MSVC_ON(4996); +DDSRT_WARNING_MSVC_ON(4996); -static void write_data (FILE *fp, const struct msghdr *msghdr, size_t sz) +static void write_data (FILE *fp, const ddsrt_msghdr_t *msghdr, size_t sz) { size_t i, n = 0; for (i = 0; i < (size_t) msghdr->msg_iovlen && n < sz; i++) @@ -132,8 +131,8 @@ void write_pcap_received ( FILE * fp, nn_wctime_t tstamp, - const os_sockaddr_storage * src, - const os_sockaddr_storage * dst, + const struct sockaddr_storage * src, + const struct sockaddr_storage * dst, unsigned char * buf, size_t sz ) @@ -148,24 +147,24 @@ void write_pcap_received udp_hdr_t udp_hdr; size_t sz_ud = sz + UDP_HDR_SIZE; size_t sz_iud = sz_ud + IPV4_HDR_SIZE; - os_mutexLock (&gv.pcap_lock); + ddsrt_mutex_lock (&gv.pcap_lock); wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, fp); u.ipv4_hdr = ipv4_hdr_template; u.ipv4_hdr.totallength = toBE2u ((unsigned short) sz_iud); u.ipv4_hdr.ttl = 128; - u.ipv4_hdr.srcip = ((os_sockaddr_in*) src)->sin_addr.s_addr; - u.ipv4_hdr.dstip = ((os_sockaddr_in*) dst)->sin_addr.s_addr; + u.ipv4_hdr.srcip = ((struct sockaddr_in*) src)->sin_addr.s_addr; + u.ipv4_hdr.dstip = ((struct sockaddr_in*) dst)->sin_addr.s_addr; u.ipv4_hdr.checksum = calc_ipv4_checksum (u.x); fwrite (&u.ipv4_hdr, sizeof (u.ipv4_hdr), 1, fp); - udp_hdr.srcport = ((os_sockaddr_in*) src)->sin_port; - udp_hdr.dstport = ((os_sockaddr_in*) dst)->sin_port; + udp_hdr.srcport = ((struct sockaddr_in*) src)->sin_port; + udp_hdr.dstport = ((struct sockaddr_in*) dst)->sin_port; udp_hdr.length = toBE2u ((unsigned short) sz_ud); udp_hdr.checksum = 0; /* don't have to compute a checksum for UDPv4 */ fwrite (&udp_hdr, sizeof (udp_hdr), 1, fp); fwrite (buf, sz, 1, fp); - os_mutexUnlock (&gv.pcap_lock); + ddsrt_mutex_unlock (&gv.pcap_lock); } } @@ -173,8 +172,8 @@ void write_pcap_sent ( FILE * fp, nn_wctime_t tstamp, - const os_sockaddr_storage * src, - const struct msghdr * hdr, + const struct sockaddr_storage * src, + const ddsrt_msghdr_t * hdr, size_t sz ) { @@ -188,23 +187,23 @@ void write_pcap_sent udp_hdr_t udp_hdr; size_t sz_ud = sz + UDP_HDR_SIZE; size_t sz_iud = sz_ud + IPV4_HDR_SIZE; - os_mutexLock (&gv.pcap_lock); + ddsrt_mutex_lock (&gv.pcap_lock); wctime_to_sec_usec (&pcap_hdr.ts_sec, &pcap_hdr.ts_usec, tstamp); pcap_hdr.incl_len = pcap_hdr.orig_len = (uint32_t) sz_iud; fwrite (&pcap_hdr, sizeof (pcap_hdr), 1, fp); u.ipv4_hdr = ipv4_hdr_template; u.ipv4_hdr.totallength = toBE2u ((unsigned short) sz_iud); u.ipv4_hdr.ttl = 255; - u.ipv4_hdr.srcip = ((os_sockaddr_in*) src)->sin_addr.s_addr; - u.ipv4_hdr.dstip = ((os_sockaddr_in*) hdr->msg_name)->sin_addr.s_addr; + u.ipv4_hdr.srcip = ((struct sockaddr_in*) src)->sin_addr.s_addr; + u.ipv4_hdr.dstip = ((struct sockaddr_in*) hdr->msg_name)->sin_addr.s_addr; u.ipv4_hdr.checksum = calc_ipv4_checksum (u.x); fwrite (&u.ipv4_hdr, sizeof (u.ipv4_hdr), 1, fp); - udp_hdr.srcport = ((os_sockaddr_in*) src)->sin_port; - udp_hdr.dstport = ((os_sockaddr_in*) hdr->msg_name)->sin_port; + udp_hdr.srcport = ((struct sockaddr_in*) src)->sin_port; + udp_hdr.dstport = ((struct sockaddr_in*) hdr->msg_name)->sin_port; udp_hdr.length = toBE2u ((unsigned short) sz_ud); udp_hdr.checksum = 0; /* don't have to compute a checksum for UDPv4 */ fwrite (&udp_hdr, sizeof (udp_hdr), 1, fp); write_data (fp, hdr, sz); - os_mutexUnlock (&gv.pcap_lock); + ddsrt_mutex_unlock (&gv.pcap_lock); } } diff --git a/src/core/ddsi/src/q_plist.c b/src/core/ddsi/src/q_plist.c index f5277b8..99c7f12 100644 --- a/src/core/ddsi/src/q_plist.c +++ b/src/core/ddsi/src/q_plist.c @@ -15,24 +15,25 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/heap.h" -#include "ddsi/q_log.h" +#include "dds/ddsi/q_log.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_error.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_time.h" -#include "ddsi/q_xmsg.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_xmsg.h" -#include "ddsi/q_config.h" -#include "ddsi/q_protocol.h" /* for NN_STATUSINFO_... */ -#include "ddsi/q_radmin.h" /* for nn_plist_quickscan */ -#include "ddsi/q_static_assert.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_protocol.h" /* for NN_STATUSINFO_... */ +#include "dds/ddsi/q_radmin.h" /* for nn_plist_quickscan */ +#include "dds/ddsi/q_static_assert.h" -#include "util/ut_avl.h" -#include "ddsi/q_misc.h" /* for vendor_is_... */ +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_misc.h" /* for vendor_is_... */ /* These are internal to the parameter list processing. We never generate them, and we never want to do see them anywhere outside @@ -133,7 +134,7 @@ static void unalias_string (char **str, int bswap) { len = (unsigned) strlen (alias) + 1; } - *str = os_malloc (len); + *str = ddsrt_malloc (len); memcpy (*str, alias, len); } @@ -177,7 +178,7 @@ static void unalias_octetseq (nn_octetseq_t *oseq, UNUSED_ARG (int bswap)) if (oseq->length != 0) { unsigned char *vs; - vs = os_malloc (oseq->length); + vs = ddsrt_malloc (oseq->length); memcpy (vs, oseq->value, oseq->length); oseq->value = vs; } @@ -264,7 +265,7 @@ static int alias_stringseq (nn_stringseq_t *strseq, const struct dd *dd) } else { - strs = os_malloc (strseq->n * sizeof (*strs)); + strs = ddsrt_malloc (strseq->n * sizeof (*strs)); for (i = 0; i < strseq->n && seq <= seqend; i++) { size_t len1; @@ -290,7 +291,7 @@ static int alias_stringseq (nn_stringseq_t *strseq, const struct dd *dd) } return 0; fail: - os_free (strs); + ddsrt_free (strs); return result; } @@ -301,10 +302,10 @@ static void free_stringseq (nn_stringseq_t *strseq) { if (strseq->strs[i]) { - os_free (strseq->strs[i]); + ddsrt_free (strseq->strs[i]); } } - os_free (strseq->strs); + ddsrt_free (strseq->strs); } static int unalias_stringseq (nn_stringseq_t *strseq, int bswap) @@ -313,13 +314,13 @@ static int unalias_stringseq (nn_stringseq_t *strseq, int bswap) char **strs; if (strseq->n != 0) { - strs = os_malloc (strseq->n * sizeof (*strs)); + strs = ddsrt_malloc (strseq->n * sizeof (*strs)); for (i = 0; i < strseq->n; i++) { strs[i] = strseq->strs[i]; unalias_string (&strs[i], bswap); } - os_free (strseq->strs); + ddsrt_free (strseq->strs); strseq->strs = strs; } return 0; @@ -335,7 +336,7 @@ assert (dest->strs == NULL); dest->strs = NULL; return; } - dest->strs = os_malloc (dest->n * sizeof (*dest->strs)); + dest->strs = ddsrt_malloc (dest->n * sizeof (*dest->strs)); for (i = 0; i < dest->n; i++) { dest->strs[i] = src->strs[i]; @@ -343,513 +344,13 @@ assert (dest->strs == NULL); } } -_Success_(return == 0) -static int validate_property (_In_ const struct dd *dd, _Out_ size_t *len) -{ - struct dd ddV = *dd; - size_t lenN; - size_t lenV; - int rc; - - /* Check name. */ - rc = validate_string(dd, &lenN); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: name validation failed\n"); - return rc; - } - lenN = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(lenN); /* strlen + possible padding */ - - - /* Check value. */ - ddV.buf = dd->buf + lenN; - ddV.bufsz = dd->bufsz - lenN; - rc = validate_string(&ddV, &lenV); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: value validation failed\n"); - return rc; - } - lenV = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(lenV); /* strlen + possible padding */ - - *len = lenN + lenV; - - return 0; -} - -_Success_(return == 0) -static int alias_property (_Out_ nn_property_t *prop, _In_ const struct dd *dd, _Out_ size_t *len) -{ - struct dd ddV = *dd; - size_t lenN; - size_t lenV; - int rc; - - /* Get name */ - rc = alias_string((const unsigned char **)&(prop->name), dd, &lenN); - if (rc != 0) - { - DDS_TRACE("plist/alias_property: invalid name buffer\n"); - return rc; - } - lenN = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(lenN); /* strlen + possible padding */ - - /* Get value */ - ddV.buf = dd->buf + lenN; - ddV.bufsz = dd->bufsz - lenN; - rc = alias_string((const unsigned char **)&(prop->value), &ddV, &lenV); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: invalid value buffer\n"); - return rc; - } - lenV = sizeof(uint32_t) + /* cdr string len arg + */ - align4u (lenV); /* strlen + possible padding */ - - /* We got this from the wire; so it has been propagated. */ - prop->propagate = true; - - *len = lenN + lenV; - - return 0; -} - -static void free_property (_Inout_ nn_property_t *prop) -{ - os_free(prop->name); - prop->name = NULL; - os_free(prop->value); - prop->value = NULL; -} - -static void unalias_property (_Inout_ nn_property_t *prop, _In_ int bswap) -{ - unalias_string(&prop->name, bswap); - unalias_string(&prop->value, bswap); -} - -static void duplicate_property (_Out_ nn_property_t *dest, _In_ const nn_property_t *src) -{ - nn_property_t tmp = *src; - unalias_property(&tmp, -1); - *dest = tmp; -} - -_Success_(return == 0) -static int validate_propertyseq (_In_ const struct dd *dd, _Out_ size_t *len) -{ - const unsigned char *seq = dd->buf; - const unsigned char *seqend = seq + dd->bufsz; - struct dd dd1 = *dd; - int i, n; - if (dd->bufsz < sizeof (int)) - { - DDS_TRACE("plist/validate_propertyseq: buffer too small (header)\n"); - return ERR_INVALID; - } - memcpy (&n, seq, sizeof (n)); - if (dd->bswap) - n = bswap4 (n); - seq += sizeof (int); - if (n < 0) - { - DDS_TRACE("plist/validate_propertyseq: length %d out of range\n", n); - return ERR_INVALID; - } - else if (n == 0) - { - /* nothing to check */ - } - else - { - for (i = 0; i < n && seq <= seqend; i++) - { - size_t len1; - int rc; - dd1.buf = seq; - dd1.bufsz = (size_t) (seqend - seq); - if ((rc = validate_property (&dd1, &len1)) != 0) - { - DDS_TRACE("plist/validate_propertyseq: invalid property\n"); - return rc; - } - seq += len1; - } - if (i < n) - { - DDS_TRACE("plist/validate_propertyseq: buffer too small (contents)\n"); - return ERR_INVALID; - } - } - *len = align4u((size_t)(seq - dd->buf)); - return 0; -} - -_Success_(return == 0) -static int alias_propertyseq (_Out_ nn_propertyseq_t *pseq, _In_ const struct dd *dd, _Out_ size_t *len) -{ - /* Not truly an alias: it allocates an array of pointers that alias - the individual components. Also: see validate_propertyseq */ - const unsigned char *seq = dd->buf; - const unsigned char *seqend = seq + dd->bufsz; - struct dd dd1 = *dd; - nn_property_t *props; - unsigned i; - int result; - if (dd->bufsz < sizeof (int)) - { - DDS_TRACE("plist/alias_propertyseq: buffer too small (header)\n"); - return ERR_INVALID; - } - - memcpy (&pseq->n, seq, sizeof (pseq->n)); - if (dd->bswap) - pseq->n = bswap4u (pseq->n); - seq += sizeof (uint32_t); - if (pseq->n >= UINT_MAX / sizeof(*props)) - { - DDS_TRACE("plist/alias_propertyseq: length %u out of range\n", pseq->n); - return ERR_INVALID; - } - else if (pseq->n == 0) - { - pseq->props = NULL; - } - else - { - props = os_malloc (pseq->n * sizeof (*props)); - for (i = 0; i < pseq->n && seq <= seqend; i++) - { - size_t len1; - dd1.buf = seq; - dd1.bufsz = (size_t) (seqend - seq); - if ((result = alias_property (&props[i], &dd1, &len1)) != 0) - { - DDS_TRACE("plist/alias_propertyseq: invalid property\n"); - goto fail; - } - seq += len1; - } - if (i != pseq->n) - { - DDS_TRACE("plist/alias_propertyseq: buffer too small (contents)\n"); - result = ERR_INVALID; - goto fail; - } - pseq->props = props; - } - *len = align4u((size_t)(seq - dd->buf)); - return 0; - fail: - os_free (props); - return result; -} - -static void free_propertyseq (_Inout_ nn_propertyseq_t *pseq) -{ - unsigned i; - for (i = 0; i < pseq->n; i++) - { - free_property(&(pseq->props[i])); - } - os_free (pseq->props); - pseq->props = NULL; - pseq->n = 0; -} - -static void unalias_propertyseq (_Inout_ nn_propertyseq_t *pseq, _In_ int bswap) -{ - unsigned i; - nn_property_t *props; - if (pseq->n != 0) - { - props = os_malloc (pseq->n * sizeof (*pseq->props)); - for (i = 0; i < pseq->n; i++) - { - props[i] = pseq->props[i]; - unalias_property (&props[i], bswap); - } - os_free (pseq->props); - pseq->props = props; - } -} - -static void duplicate_propertyseq (_Out_ nn_propertyseq_t *dest, _In_ const nn_propertyseq_t *src) -{ - unsigned i; - dest->n = src->n; - if (dest->n == 0) - { - dest->props = NULL; - return; - } - dest->props = os_malloc (dest->n * sizeof (*dest->props)); - for (i = 0; i < dest->n; i++) - { - duplicate_property(&(dest->props[i]), &(src->props[i])); - } -} - -_Success_(return == 0) -static int validate_binaryproperty (_In_ const struct dd *dd, _Out_ size_t *len) -{ - struct dd ddV = *dd; - size_t lenN; - size_t lenV; - int rc; - - /* Check name. */ - rc = validate_string(dd, &lenN); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: name validation failed\n"); - return rc; - } - lenN = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(lenN); /* strlen + possible padding */ - - /* Check value. */ - ddV.buf = dd->buf + lenN; - ddV.bufsz = dd->bufsz - lenN; - rc = validate_octetseq(&ddV, &lenV); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: value validation failed\n"); - return rc; - } - lenV = sizeof(uint32_t) + /* cdr sequence len arg + */ - align4u(lenV); /* seqlen + possible padding */ - - *len = lenN + lenV; - - return 0; -} - -_Success_(return == 0) -static int alias_binaryproperty (_Out_ nn_binaryproperty_t *prop, _In_ const struct dd *dd, _Out_ size_t *len) -{ - struct dd ddV = *dd; - size_t lenN; - size_t lenV; - int rc; - - /* Get name */ - rc = alias_string((const unsigned char **)&(prop->name), dd, &lenN); - if (rc != 0) - { - DDS_TRACE("plist/alias_property: invalid name buffer\n"); - return rc; - } - lenN = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(lenN); /* strlen + possible padding */ - - /* Get value */ - ddV.buf = dd->buf + lenN; - ddV.bufsz = dd->bufsz - lenN; - rc = alias_octetseq(&(prop->value), &ddV); - if (rc != 0) - { - DDS_TRACE("plist/validate_property: invalid value buffer\n"); - return rc; - } - lenV = sizeof(uint32_t) + /* cdr sequence len arg + */ - align4u(prop->value.length); /* seqlen + possible padding */ - - /* We got this from the wire; so it has been propagated. */ - prop->propagate = true; - - *len = lenN + lenV; - - return 0; -} - -static void free_binaryproperty (_Inout_ nn_binaryproperty_t *prop) -{ - os_free(prop->name); - prop->name = NULL; - os_free(prop->value.value); - prop->value.value = NULL; - prop->value.length = 0; -} - -static void unalias_binaryproperty (_Inout_ nn_binaryproperty_t *prop, _In_ int bswap) -{ - unalias_string (&prop->name, bswap); - unalias_octetseq(&prop->value, bswap); -} - -static void duplicate_binaryproperty (_Out_ nn_binaryproperty_t *dest, _In_ const nn_binaryproperty_t *src) -{ - nn_binaryproperty_t tmp = *src; - unalias_binaryproperty(&tmp, -1); - *dest = tmp; -} - -_Success_(return == 0) -static int validate_binarypropertyseq (_In_ const struct dd *dd, _Out_ size_t *len) -{ - const unsigned char *seq = dd->buf; - const unsigned char *seqend = seq + dd->bufsz; - struct dd dd1 = *dd; - int i, n; - if (dd->bufsz < sizeof (int)) - { - DDS_TRACE("plist/validate_binarypropertyseq: buffer too small (header)\n"); - return ERR_INVALID; - } - memcpy (&n, seq, sizeof (n)); - if (dd->bswap) - n = bswap4 (n); - seq += sizeof (int); - if (n < 0) - { - DDS_TRACE("plist/validate_binarypropertyseq: length %d out of range\n", n); - return ERR_INVALID; - } - else if (n == 0) - { - /* nothing to check */ - } - else - { - for (i = 0; i < n && seq <= seqend; i++) - { - size_t len1; - int rc; - dd1.buf = seq; - dd1.bufsz = (size_t) (seqend - seq); - if ((rc = validate_binaryproperty (&dd1, &len1)) != 0) - { - DDS_TRACE("plist/validate_binarypropertyseq: invalid property\n"); - return rc; - } - seq += len1; - } - if (i < n) - { - DDS_TRACE("plist/validate_binarypropertyseq: buffer too small (contents)\n"); - return ERR_INVALID; - } - } - *len = align4u((size_t)(seq - dd->buf)); - return 0; -} - -_Success_(return == 0) -static int alias_binarypropertyseq (_Out_ nn_binarypropertyseq_t *pseq, _In_ const struct dd *dd, _Out_ size_t *len) -{ - /* Not truly an alias: it allocates an array of pointers that alias - the individual components. Also: see validate_binarypropertyseq */ - const unsigned char *seq = dd->buf; - const unsigned char *seqend = seq + dd->bufsz; - struct dd dd1 = *dd; - nn_binaryproperty_t *props; - unsigned i; - int result; - if (dd->bufsz < sizeof (int)) - { - DDS_TRACE("plist/alias_binarypropertyseq: buffer too small (header)\n"); - return ERR_INVALID; - } - - memcpy (&pseq->n, seq, sizeof (pseq->n)); - if (dd->bswap) - pseq->n = bswap4u (pseq->n); - seq += sizeof (uint32_t); - if (pseq->n >= UINT_MAX / sizeof(*props)) - { - DDS_TRACE("plist/alias_binarypropertyseq: length %u out of range\n", pseq->n); - return ERR_INVALID; - } - else if (pseq->n == 0) - { - pseq->props = NULL; - } - else - { - props = os_malloc (pseq->n * sizeof (*props)); - for (i = 0; i < pseq->n && seq <= seqend; i++) - { - size_t len1; - dd1.buf = seq; - dd1.bufsz = (size_t) (seqend - seq); - if ((result = alias_binaryproperty (&props[i], &dd1, &len1)) != 0) - { - DDS_TRACE("plist/alias_binarypropertyseq: invalid property\n"); - goto fail; - } - seq += len1; - } - if (i != pseq->n) - { - DDS_TRACE("plist/alias_binarypropertyseq: buffer too small (contents)\n"); - result = ERR_INVALID; - goto fail; - } - pseq->props = props; - } - *len = align4u((size_t)(seq - dd->buf)); - return 0; - fail: - os_free (props); - return result; -} - -static void free_binarypropertyseq (_Inout_ nn_binarypropertyseq_t *pseq) -{ - unsigned i; - for (i = 0; i < pseq->n; i++) - { - free_binaryproperty(&(pseq->props[i])); - } - os_free (pseq->props); - pseq->props = NULL; - pseq->n = 0; -} - -static void unalias_binarypropertyseq (_Inout_ nn_binarypropertyseq_t *pseq, _In_ int bswap) -{ - unsigned i; - nn_binaryproperty_t *props; - if (pseq->n != 0) - { - props = os_malloc (pseq->n * sizeof (*pseq->props)); - for (i = 0; i < pseq->n; i++) - { - props[i] = pseq->props[i]; - unalias_binaryproperty (&props[i], bswap); - } - os_free (pseq->props); - pseq->props = props; - } -} - -static void duplicate_binarypropertyseq (_Out_ nn_binarypropertyseq_t *dest, _In_ const nn_binarypropertyseq_t *src) -{ - unsigned i; - dest->n = src->n; - if (dest->n == 0) - { - dest->props = NULL; - return; - } - dest->props = os_malloc (dest->n * sizeof (*dest->props)); - for (i = 0; i < dest->n; i++) - { - duplicate_binaryproperty(&(dest->props[i]), &(src->props[i])); - } -} - static void free_locators (nn_locators_t *locs) { while (locs->first) { struct nn_locators_one *l = locs->first; locs->first = l->next; - os_free (l); + ddsrt_free (l); } } @@ -865,7 +366,7 @@ static void unalias_locators (nn_locators_t *locs, UNUSED_ARG (int bswap)) for (lold = locs->first; lold != NULL; lold = lold->next) { struct nn_locators_one *n; - n = os_malloc (sizeof (*n)); + n = ddsrt_malloc (sizeof (*n)); n->next = NULL; n->loc = lold->loc; if (newlocs.first == NULL) @@ -882,33 +383,12 @@ static void unalias_eotinfo (nn_prismtech_eotinfo_t *txnid, UNUSED_ARG (int bswa if (txnid->n > 0) { nn_prismtech_eotgroup_tid_t *vs; - vs = os_malloc (txnid->n * sizeof (*vs)); + vs = ddsrt_malloc (txnid->n * sizeof (*vs)); memcpy (vs, txnid->tids, txnid->n * sizeof (*vs)); txnid->tids = vs; } } -static void free_dataholder (_Inout_ nn_dataholder_t *dh) -{ - os_free(dh->class_id); - dh->class_id = NULL; - free_propertyseq(&(dh->properties)); - free_binarypropertyseq(&(dh->binary_properties)); -} - -static void unalias_dataholder (_Inout_ nn_dataholder_t *holder, _In_ int bswap) -{ - unalias_string(&(holder->class_id), bswap); - unalias_propertyseq(&(holder->properties), bswap); - unalias_binarypropertyseq(&(holder->binary_properties), bswap); -} - -static void duplicate_property_qospolicy (_Out_ nn_property_qospolicy_t *dest, _In_ const nn_property_qospolicy_t *src) -{ - duplicate_propertyseq(&(dest->value), &(src->value)); - duplicate_binarypropertyseq(&(dest->binary_value), &(src->binary_value)); -} - void nn_plist_fini (nn_plist_t *ps) { struct t { uint64_t fl; size_t off; }; @@ -928,21 +408,17 @@ void nn_plist_fini (nn_plist_t *ps) { PP_METATRAFFIC_UNICAST_LOCATOR, offsetof (nn_plist_t, metatraffic_unicast_locators) }, { PP_METATRAFFIC_MULTICAST_LOCATOR, offsetof (nn_plist_t, metatraffic_multicast_locators) } }; - static const struct t tokens[] = { - { PP_IDENTITY_TOKEN, offsetof (nn_plist_t, identity_token) }, - { PP_PERMISSIONS_TOKEN, offsetof (nn_plist_t, permissions_token) } - }; int i; nn_xqos_fini (&ps->qos); /* The compiler doesn't understand how offsetof is used in the arrays. */ -OS_WARNING_MSVC_OFF(6001); +DDSRT_WARNING_MSVC_OFF(6001); for (i = 0; i < (int) (sizeof (simple) / sizeof (*simple)); i++) { if ((ps->present & simple[i].fl) && !(ps->aliased & simple[i].fl)) { void **pp = (void **) ((char *) ps + simple[i].off); - os_free (*pp); + ddsrt_free (*pp); } } for (i = 0; i < (int) (sizeof (locs) / sizeof (*locs)); i++) @@ -950,12 +426,7 @@ OS_WARNING_MSVC_OFF(6001); if ((ps->present & locs[i].fl) && !(ps->aliased & locs[i].fl)) free_locators ((nn_locators_t *) ((char *) ps + locs[i].off)); } - for (i = 0; i < (int) (sizeof (tokens) / sizeof (*tokens)); i++) - { - if ((ps->present & tokens[i].fl) && !(ps->aliased & tokens[i].fl)) - free_dataholder ((nn_token_t *) ((char *) ps + tokens[i].off)); - } -OS_WARNING_MSVC_ON(6001); +DDSRT_WARNING_MSVC_ON(6001); ps->present = 0; } @@ -981,8 +452,6 @@ void nn_plist_unalias (nn_plist_t *ps) P (PRISMTECH_EXEC_NAME, string, exec_name); P (PRISMTECH_TYPE_DESCRIPTION, string, type_description); P (PRISMTECH_EOTINFO, eotinfo, eotinfo); - P (IDENTITY_TOKEN, dataholder, identity_token); - P (PERMISSIONS_TOKEN, dataholder, permissions_token); #undef P if ((ps->present & PP_PRISMTECH_PARTICIPANT_VERSION_INFO) && (ps->aliased & PP_PRISMTECH_PARTICIPANT_VERSION_INFO)) @@ -1070,33 +539,6 @@ static int validate_time (const nn_ddsi_time_t *t) } } -#if DDSI_DURATION_ACCORDING_TO_SPEC -static void bswap_duration (nn_duration_t *d) -{ - /* Why o why is a Duration_t used for some things, and a (DDSI) time - used for other things, where a duration is {sec,nsec} and a time - is {sec,fraction}? */ - d->sec = bswap4 (d->sec); - d->nanosec = bswap4 (d->nanosec); -} - -int validate_duration (const nn_duration_t *d) -{ - /* Accepted are zero, positive, infinite or invalid as defined in - the DDS 1.2 spec. */ - if (d->sec >= 0 && d->nanosec >= 0 && d->nanosec < 1000000000) - return 0; - else if (d->sec == (int) INT32_MAX && d->nanosec == (int) INT32_MAX) - return 0; - else if (d->sec == -1 && d->nanosec == (int) UINT32_MAX) - return 0; - else - { - DDS_TRACE("plist/validate_time: invalid duration (%08x.%08x)\n", d->sec, d->nanosec); - return ERR_INVALID; - } -} -#else static void bswap_duration (nn_duration_t *d) { bswap_time (d); @@ -1106,7 +548,6 @@ int validate_duration (const nn_duration_t *d) { return validate_time (d); } -#endif static int do_duration (nn_duration_t *q, uint64_t *present, uint64_t fl, const struct dd *dd) { @@ -1452,7 +893,7 @@ static int add_locator (nn_locators_t *ls, uint64_t *present, uint64_t wanted, u ls->first = NULL; ls->last = NULL; } - nloc = os_malloc (sizeof (*nloc)); + nloc = ddsrt_malloc (sizeof (*nloc)); nloc->loc = *loc; nloc->next = NULL; if (ls->first == NULL) @@ -2047,87 +1488,6 @@ static int do_reader_data_lifecycle_v1 (nn_reader_data_lifecycle_qospolicy_t *q, return validate_reader_data_lifecycle (q); } -_Success_(return == 0) -static int do_dataholder (_Out_ nn_dataholder_t *dh, _Inout_ uint64_t *present, _Inout_ uint64_t *aliased, _In_ uint64_t wanted, _In_ uint64_t fl, _In_ const struct dd *dd) -{ - struct dd ddtmp = *dd; - size_t len; - int res; - - memset(dh, 0, sizeof(nn_dataholder_t)); - - if (!(wanted & fl)) - { - res = 0; - if (NN_STRICT_P) - { - /* check class_id */ - if ((res = validate_string (&ddtmp, &len)) == 0) - { - len = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(len); /* strlen + possible padding */ - /* check properties */ - ddtmp.buf = &(dd->buf[len]); - ddtmp.bufsz = dd->bufsz - len; - if ((res = validate_propertyseq (&ddtmp, &len)) == 0) - { - /* check binary properties */ - ddtmp.buf = &(ddtmp.buf[len]); - ddtmp.bufsz = ddtmp.bufsz - len; - if ((res = validate_binarypropertyseq (&ddtmp, &len)) != 0) - { - DDS_TRACE("plist/do_dataholder: invalid binary_property_seq\n"); - } - } - else - { - DDS_TRACE("plist/do_dataholder: invalid property_seq\n"); - } - } - else - { - DDS_TRACE("plist/do_dataholder: invalid class_id\n"); - } - } - return res; - } - - /* get class_id */ - res = alias_string((const unsigned char **)&(dh->class_id), dd, &len /* strlen */); - if (res != 0) - { - DDS_TRACE("plist/do_dataholder: invalid class_id\n"); - return res; - } - len = sizeof(uint32_t) + /* cdr string len arg + */ - align4u(len); /* strlen + possible padding */ - - /* get properties */ - ddtmp.buf = &(dd->buf[len]); - ddtmp.bufsz = dd->bufsz - len; - res = alias_propertyseq(&(dh->properties), &ddtmp, &len /* complete length */); - if (res != 0) - { - DDS_TRACE("plist/do_dataholder: invalid property_seq\n"); - return res; - } - - /* get binary properties */ - ddtmp.buf = &(ddtmp.buf[len]); - ddtmp.bufsz = ddtmp.bufsz - len; - res = alias_binarypropertyseq(&(dh->binary_properties), &ddtmp, &len /* complete length */); - if (res != 0) - { - DDS_TRACE("plist/do_dataholder: invalid binary_property_seq\n"); - return res; - } - - *present |= fl; - *aliased |= fl; - - return 0; -} - static int init_one_parameter ( nn_plist_t *dest, @@ -2747,12 +2107,6 @@ static int init_one_parameter } #endif - case PID_IDENTITY_TOKEN: - return do_dataholder (&dest->identity_token, &dest->present, &dest->aliased, pwanted, PP_IDENTITY_TOKEN, dd); - - case PID_PERMISSIONS_TOKEN: - return do_dataholder (&dest->permissions_token, &dest->present, &dest->aliased, pwanted, PP_PERMISSIONS_TOKEN, dd); - /* Deprecated ones (used by RTI, but not relevant to DDSI) */ case PID_PERSISTENCE: case PID_TYPE_CHECKSUM: @@ -2871,8 +2225,6 @@ void nn_plist_mergein_missing (nn_plist_t *a, const nn_plist_t *b) CQ (PRISMTECH_EXEC_NAME, exec_name, string, char *); CQ (PRISMTECH_TYPE_DESCRIPTION, type_description, string, char *); CQ (PRISMTECH_EOTINFO, eotinfo, eotinfo, nn_prismtech_eotinfo_t); - CQ (IDENTITY_TOKEN, identity_token, dataholder, nn_token_t); - CQ (PERMISSIONS_TOKEN, permissions_token, dataholder, nn_token_t); #undef CQ if (!(a->present & PP_PRISMTECH_PARTICIPANT_VERSION_INFO) && (b->present & PP_PRISMTECH_PARTICIPANT_VERSION_INFO)) @@ -2895,7 +2247,7 @@ void nn_plist_copy (nn_plist_t *dst, const nn_plist_t *src) nn_plist_t *nn_plist_dup (const nn_plist_t *src) { nn_plist_t *dst; - dst = os_malloc (sizeof (*dst)); + dst = ddsrt_malloc (sizeof (*dst)); nn_plist_copy (dst, src); assert (dst->aliased == 0); return dst; @@ -2951,14 +2303,14 @@ int nn_plist_init_frommsg switch (src->encoding) { case PL_CDR_LE: -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN dd.bswap = 0; #else dd.bswap = 1; #endif break; case PL_CDR_BE: -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN dd.bswap = 1; #else dd.bswap = 0; @@ -3075,14 +2427,14 @@ unsigned char *nn_plist_quickscan (struct nn_rsample_info *dest, const struct nn switch (src->encoding) { case PL_CDR_LE: -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN dest->bswap = 0; #else dest->bswap = 1; #endif break; case PL_CDR_BE: -#if OS_ENDIANNESS == OS_LITTLE_ENDIAN +#if DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN dest->bswap = 1; #else dest->bswap = 0; @@ -3406,11 +2758,6 @@ void nn_xqos_mergein_missing (nn_xqos_t *a, const nn_xqos_t *b) duplicate_stringseq (&a->partition, &b->partition); a->present |= QP_PARTITION; } - if (!(a->present & QP_PROPERTY) && (b->present & QP_PROPERTY)) - { - duplicate_property_qospolicy (&a->property, &b->property); - a->present |= QP_PROPERTY; - } } void nn_xqos_copy (nn_xqos_t *dst, const nn_xqos_t *src) @@ -3459,7 +2806,7 @@ void nn_xqos_fini (nn_xqos_t *xqos) { void **pp = (void **) ((char *) xqos + qos_simple[i].off); DDS_LOG(DDS_LC_PLIST, "NN_XQOS_FINI free %p\n", *pp); - os_free (*pp); + ddsrt_free (*pp); } } if (xqos->present & QP_PARTITION) @@ -3472,7 +2819,7 @@ void nn_xqos_fini (nn_xqos_t *xqos) { /* until proper message buffers arrive */ DDS_LOG(DDS_LC_PLIST, "NN_XQOS_FINI free %p\n", (void *) xqos->partition.strs); - os_free (xqos->partition.strs); + ddsrt_free (xqos->partition.strs); } } if (xqos->present & QP_PRISMTECH_SUBSCRIPTION_KEYS) @@ -3483,15 +2830,7 @@ void nn_xqos_fini (nn_xqos_t *xqos) { /* until proper message buffers arrive */ DDS_LOG(DDS_LC_PLIST, "NN_XQOS_FINI free %p\n", (void *) xqos->subscription_keys.key_list.strs); - os_free (xqos->subscription_keys.key_list.strs); - } - } - if (xqos->present & QP_PROPERTY) - { - if (!(xqos->aliased & QP_PROPERTY)) - { - free_propertyseq(&xqos->property.value); - free_binarypropertyseq(&xqos->property.binary_value); + ddsrt_free (xqos->subscription_keys.key_list.strs); } } xqos->present = 0; @@ -3499,7 +2838,7 @@ void nn_xqos_fini (nn_xqos_t *xqos) nn_xqos_t * nn_xqos_dup (const nn_xqos_t *src) { - nn_xqos_t *dst = os_malloc (sizeof (*dst)); + nn_xqos_t *dst = ddsrt_malloc (sizeof (*dst)); nn_xqos_copy (dst, src); assert (dst->aliased == 0); return dst; @@ -3512,11 +2851,7 @@ static int octetseqs_differ (const nn_octetseq_t *a, const nn_octetseq_t *b) static int durations_differ (const nn_duration_t *a, const nn_duration_t *b) { -#if DDSI_DURATION_ACCORDING_TO_SPEC - return (a->sec != b->sec || a->nanosec != b->nanosec); -#else return (a->seconds != b->seconds || a->fraction != b->fraction); -#endif } static int stringseqs_differ (const nn_stringseq_t *a, const nn_stringseq_t *b) @@ -3573,19 +2908,19 @@ static int partitions_equal_nlogn (const nn_partition_qospolicy_t *a, const nn_p if (a->n <= (int) (sizeof (statictab) / sizeof (*statictab))) tab = statictab; else - tab = os_malloc (a->n * sizeof (*tab)); + tab = ddsrt_malloc (a->n * sizeof (*tab)); for (i = 0; i < a->n; i++) tab[i] = a->strs[i]; qsort (tab, a->n, sizeof (*tab), (int (*) (const void *, const void *)) strcmp); for (i = 0; i < b->n; i++) - if (os_bsearch (b->strs[i], tab, a->n, sizeof (*tab), (int (*) (const void *, const void *)) strcmp) == NULL) + if (bsearch (b->strs[i], tab, a->n, sizeof (*tab), (int (*) (const void *, const void *)) strcmp) == NULL) { equal = 0; break; } if (tab != statictab) - os_free (tab); + ddsrt_free (tab); return equal; } @@ -3921,8 +3256,6 @@ void nn_plist_addtomsg (struct nn_xmsg *m, const nn_plist_t *ps, uint64_t pwante SIMPLE_TYPE (PRISMTECH_SERVICE_TYPE, service_type, unsigned); FUNC_BY_VAL (PRISMTECH_TYPE_DESCRIPTION, type_description, string); FUNC_BY_REF (PRISMTECH_EOTINFO, eotinfo, eotinfo); - FUNC_BY_REF (IDENTITY_TOKEN, identity_token, dataholder); - FUNC_BY_REF (PERMISSIONS_TOKEN, permissions_token, dataholder); #ifdef DDSI_INCLUDE_SSM SIMPLE_TYPE (READER_FAVOURS_SSM, reader_favours_ssm, nn_reader_favours_ssm_t); #endif @@ -3979,13 +3312,8 @@ void nn_log_xqos (uint32_t cat, const nn_xqos_t *xqos) #define LOGB5(fmt_, arg0_, arg1_, arg2_, arg3_, arg4_) DDS_LOG(cat, "%s" fmt_, prefix, arg0_, arg1_, arg2_, arg3_, arg4_) #define DO(name_, body_) do { if (p & QP_##name_) { { body_ } prefix = ","; } } while (0) -#if DDSI_DURATION_ACCORDING_TO_SPEC -#define FMT_DUR "%d.%09d" -#define PRINTARG_DUR(d) (d).sec, (d).nanosec -#else #define FMT_DUR "%d.%09d" #define PRINTARG_DUR(d) (d).seconds, (int) ((d).fraction/4.294967296) -#endif DO (TOPIC_NAME, { LOGB1 ("topic=%s", xqos->topic_name); }); DO (TYPE_NAME, { LOGB1 ("type=%s", xqos->type_name); }); @@ -4050,25 +3378,6 @@ void nn_log_xqos (uint32_t cat, const nn_xqos_t *xqos) }); DO (PRISMTECH_ENTITY_FACTORY, { LOGB1 ("entity_factory=%u", xqos->entity_factory.autoenable_created_entities); }); DO (PRISMTECH_SYNCHRONOUS_ENDPOINT, { LOGB1 ("synchronous_endpoint=%u", xqos->synchronous_endpoint.value); }); - DO (PROPERTY, { - unsigned i; - LOGB0 ("property={{"); - for (i = 0; i < xqos->property.value.n; i++) { - DDS_LOG(cat, "(\"%s\",\"%s\",%d)", - xqos->property.value.props[i].name ? xqos->property.value.props[i].name : "nil", - xqos->property.value.props[i].value ? xqos->property.value.props[i].value : "nil", - (int)xqos->property.value.props[i].propagate); - } - DDS_LOG(cat, "},{"); - for (i = 0; i < xqos->property.binary_value.n; i++) { - DDS_LOG(cat, "(\"%s\",<", - xqos->property.binary_value.props[i].name ? xqos->property.binary_value.props[i].name : "nil"); - log_octetseq (cat, xqos->property.binary_value.props[i].value.length, xqos->property.binary_value.props[i].value.value); - DDS_LOG(cat, ">,%d)", - (int)xqos->property.binary_value.props[i].propagate); - } - DDS_LOG(cat, "}}"); - }); DO (RTI_TYPECODE, { LOGB1 ("rti_typecode=%u<", xqos->rti_typecode.length); log_octetseq (cat, xqos->rti_typecode.length, xqos->rti_typecode.value); diff --git a/src/core/ddsi/src/q_qosmatch.c b/src/core/ddsi/src/q_qosmatch.c index 0ab9009..abac093 100644 --- a/src/core/ddsi/src/q_qosmatch.c +++ b/src/core/ddsi/src/q_qosmatch.c @@ -12,10 +12,10 @@ #include #include -#include "ddsi/q_time.h" -#include "ddsi/q_xqos.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_qosmatch.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_qosmatch.h" int is_wildcard_partition (const char *str) { diff --git a/src/core/ddsi/src/q_radmin.c b/src/core/ddsi/src/q_radmin.c index 6575a5f..c6f4a22 100644 --- a/src/core/ddsi/src/q_radmin.c +++ b/src/core/ddsi/src/q_radmin.c @@ -22,22 +22,26 @@ #define USE_VALGRIND 0 #endif -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/log.h" -#include "util/ut_avl.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_misc.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_bitset.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_globals.h" /* for mattr, cattr */ +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_bitset.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_globals.h" /* for mattr, cattr */ /* OVERVIEW ------------------------------------------------------------ @@ -276,14 +280,14 @@ struct nn_rbufpool { Could trivially be done lockless, except that it requires compare-and-swap, and we don't have that. But it hardly ever happens anyway. */ - os_mutex lock; + ddsrt_mutex_t lock; struct nn_rbuf *current; uint32_t rbuf_size; uint32_t max_rmsg_size; #ifndef NDEBUG /* Thread that owns this pool, so we can check that no other thread is calling functions only the owner may use. */ - os_threadId owner_tid; + ddsrt_thread_t owner_tid; #endif }; @@ -296,7 +300,7 @@ static uint32_t align8uint32 (uint32_t x) } #ifndef NDEBUG -#define ASSERT_RBUFPOOL_OWNER(rbp) (assert (os_threadEqual (os_threadIdSelf (), (rbp)->owner_tid))) +#define ASSERT_RBUFPOOL_OWNER(rbp) (assert (ddsrt_thread_equal (ddsrt_thread_self (), (rbp)->owner_tid))) #else #define ASSERT_RBUFPOOL_OWNER(rbp) ((void) (0)) #endif @@ -328,13 +332,13 @@ struct nn_rbufpool *nn_rbufpool_new (uint32_t rbuf_size, uint32_t max_rmsg_size) assert (max_rmsg_size > 0); assert (rbuf_size >= max_rmsg_size_w_hdr (max_rmsg_size)); - if ((rbp = os_malloc (sizeof (*rbp))) == NULL) + if ((rbp = ddsrt_malloc (sizeof (*rbp))) == NULL) goto fail_rbp; #ifndef NDEBUG - rbp->owner_tid = os_threadIdSelf (); + rbp->owner_tid = ddsrt_thread_self (); #endif - os_mutexInit (&rbp->lock); + ddsrt_mutex_init (&rbp->lock); rbp->rbuf_size = rbuf_size; rbp->max_rmsg_size = max_rmsg_size; @@ -351,13 +355,13 @@ struct nn_rbufpool *nn_rbufpool_new (uint32_t rbuf_size, uint32_t max_rmsg_size) #if USE_VALGRIND VALGRIND_DESTROY_MEMPOOL (rbp); #endif - os_mutexDestroy (&rbp->lock); - os_free (rbp); + ddsrt_mutex_destroy (&rbp->lock); + ddsrt_free (rbp); fail_rbp: return NULL; } -void nn_rbufpool_setowner (UNUSED_ARG_NDEBUG (struct nn_rbufpool *rbp), UNUSED_ARG_NDEBUG (os_threadId tid)) +void nn_rbufpool_setowner (UNUSED_ARG_NDEBUG (struct nn_rbufpool *rbp), UNUSED_ARG_NDEBUG (ddsrt_thread_t tid)) { #ifndef NDEBUG rbp->owner_tid = tid; @@ -377,14 +381,14 @@ void nn_rbufpool_free (struct nn_rbufpool *rbp) #if USE_VALGRIND VALGRIND_DESTROY_MEMPOOL (rbp); #endif - os_mutexDestroy (&rbp->lock); - os_free (rbp); + ddsrt_mutex_destroy (&rbp->lock); + ddsrt_free (rbp); } /* RBUF ---------------------------------------------------------------- */ struct nn_rbuf { - os_atomic_uint32_t n_live_rmsg_chunks; + ddsrt_atomic_uint32_t n_live_rmsg_chunks; uint32_t size; uint32_t max_rmsg_size; struct nn_rbufpool *rbufpool; @@ -411,14 +415,14 @@ static struct nn_rbuf *nn_rbuf_alloc_new (struct nn_rbufpool *rbufpool) struct nn_rbuf *rb; ASSERT_RBUFPOOL_OWNER (rbufpool); - if ((rb = os_malloc (offsetof (struct nn_rbuf, u.raw) + rbufpool->rbuf_size)) == NULL) + if ((rb = ddsrt_malloc (offsetof (struct nn_rbuf, u.raw) + rbufpool->rbuf_size)) == NULL) return NULL; #if USE_VALGRIND VALGRIND_MAKE_MEM_NOACCESS (rb->u.raw, rbufpool->rbuf_size); #endif rb->rbufpool = rbufpool; - os_atomic_st32 (&rb->n_live_rmsg_chunks, 1); + ddsrt_atomic_st32 (&rb->n_live_rmsg_chunks, 1); rb->size = rbufpool->rbuf_size; rb->max_rmsg_size = rbufpool->max_rmsg_size; rb->freeptr = rb->u.raw; @@ -433,10 +437,10 @@ static struct nn_rbuf *nn_rbuf_new (struct nn_rbufpool *rbufpool) ASSERT_RBUFPOOL_OWNER (rbufpool); if ((rb = nn_rbuf_alloc_new (rbufpool)) != NULL) { - os_mutexLock (&rbufpool->lock); + ddsrt_mutex_lock (&rbufpool->lock); nn_rbuf_release (rbufpool->current); rbufpool->current = rb; - os_mutexUnlock (&rbufpool->lock); + ddsrt_mutex_unlock (&rbufpool->lock); } return rb; } @@ -445,10 +449,10 @@ static void nn_rbuf_release (struct nn_rbuf *rbuf) { struct nn_rbufpool *rbp = rbuf->rbufpool; DDS_LOG(DDS_LC_RADMIN, "rbuf_release(%p) pool %p current %p\n", (void *) rbuf, (void *) rbp, (void *) rbp->current); - if (os_atomic_dec32_ov (&rbuf->n_live_rmsg_chunks) == 1) + if (ddsrt_atomic_dec32_ov (&rbuf->n_live_rmsg_chunks) == 1) { DDS_LOG(DDS_LC_RADMIN, "rbuf_release(%p) free\n", (void *) rbuf); - os_free (rbuf); + ddsrt_free (rbuf); } } @@ -464,7 +468,7 @@ static void nn_rbuf_release (struct nn_rbuf *rbuf) #define RMSG_REFCOUNT_UNCOMMITTED_BIAS (1u << 31) #define RMSG_REFCOUNT_RDATA_BIAS (1u << 20) #ifndef NDEBUG -#define ASSERT_RMSG_UNCOMMITTED(rmsg) (assert (os_atomic_ld32 (&(rmsg)->refcount) >= RMSG_REFCOUNT_UNCOMMITTED_BIAS)) +#define ASSERT_RMSG_UNCOMMITTED(rmsg) (assert (ddsrt_atomic_ld32 (&(rmsg)->refcount) >= RMSG_REFCOUNT_UNCOMMITTED_BIAS)) #else #define ASSERT_RMSG_UNCOMMITTED(rmsg) ((void) 0) #endif @@ -503,7 +507,7 @@ static void init_rmsg_chunk (struct nn_rmsg_chunk *chunk, struct nn_rbuf *rbuf) chunk->rbuf = rbuf; chunk->next = NULL; chunk->size = 0; - os_atomic_inc32 (&rbuf->n_live_rmsg_chunks); + ddsrt_atomic_inc32 (&rbuf->n_live_rmsg_chunks); } struct nn_rmsg *nn_rmsg_new (struct nn_rbufpool *rbufpool) @@ -517,7 +521,7 @@ struct nn_rmsg *nn_rmsg_new (struct nn_rbufpool *rbufpool) return NULL; /* Reference to this rmsg, undone by rmsg_commit(). */ - os_atomic_st32 (&rmsg->refcount, RMSG_REFCOUNT_UNCOMMITTED_BIAS); + ddsrt_atomic_st32 (&rmsg->refcount, RMSG_REFCOUNT_UNCOMMITTED_BIAS); /* Initial chunk */ init_rmsg_chunk (&rmsg->chunk, rbufpool->current); rmsg->lastchunk = &rmsg->chunk; @@ -533,7 +537,7 @@ void nn_rmsg_setsize (struct nn_rmsg *rmsg, uint32_t size) DDS_LOG(DDS_LC_RADMIN, "rmsg_setsize(%p, %u => %u)\n", (void *) rmsg, size, size8); ASSERT_RBUFPOOL_OWNER (rmsg->chunk.rbuf->rbufpool); ASSERT_RMSG_UNCOMMITTED (rmsg); - assert (os_atomic_ld32 (&rmsg->refcount) == RMSG_REFCOUNT_UNCOMMITTED_BIAS); + assert (ddsrt_atomic_ld32 (&rmsg->refcount) == RMSG_REFCOUNT_UNCOMMITTED_BIAS); assert (rmsg->chunk.size == 0); assert (size8 <= rmsg->chunk.rbuf->max_rmsg_size); assert (rmsg->lastchunk == &rmsg->chunk); @@ -554,7 +558,7 @@ void nn_rmsg_free (struct nn_rmsg *rmsg) compare-and-swap for this. */ struct nn_rmsg_chunk *c; DDS_LOG(DDS_LC_RADMIN, "rmsg_free(%p)\n", (void *) rmsg); - assert (os_atomic_ld32 (&rmsg->refcount) == 0); + assert (ddsrt_atomic_ld32 (&rmsg->refcount) == 0); c = &rmsg->chunk; while (c) { @@ -567,7 +571,7 @@ void nn_rmsg_free (struct nn_rmsg *rmsg) VALGRIND_MEMPOOL_FREE (rbuf->rbufpool, c); } #endif - assert (os_atomic_ld32 (&rbuf->n_live_rmsg_chunks) > 0); + assert (ddsrt_atomic_ld32 (&rbuf->n_live_rmsg_chunks) > 0); nn_rbuf_release (rbuf); c = c1; } @@ -597,11 +601,11 @@ void nn_rmsg_commit (struct nn_rmsg *rmsg) ASSERT_RMSG_UNCOMMITTED (rmsg); assert (chunk->size <= chunk->rbuf->max_rmsg_size); assert ((chunk->size % 8) == 0); - assert (os_atomic_ld32 (&rmsg->refcount) >= RMSG_REFCOUNT_UNCOMMITTED_BIAS); - assert (os_atomic_ld32 (&rmsg->chunk.rbuf->n_live_rmsg_chunks) > 0); - assert (os_atomic_ld32 (&chunk->rbuf->n_live_rmsg_chunks) > 0); + assert (ddsrt_atomic_ld32 (&rmsg->refcount) >= RMSG_REFCOUNT_UNCOMMITTED_BIAS); + assert (ddsrt_atomic_ld32 (&rmsg->chunk.rbuf->n_live_rmsg_chunks) > 0); + assert (ddsrt_atomic_ld32 (&chunk->rbuf->n_live_rmsg_chunks) > 0); assert (chunk->rbuf->rbufpool->current == chunk->rbuf); - if (os_atomic_sub32_nv (&rmsg->refcount, RMSG_REFCOUNT_UNCOMMITTED_BIAS) == 0) + if (ddsrt_atomic_sub32_nv (&rmsg->refcount, RMSG_REFCOUNT_UNCOMMITTED_BIAS) == 0) nn_rmsg_free (rmsg); else { @@ -623,7 +627,7 @@ static void nn_rmsg_addbias (struct nn_rmsg *rmsg) DDS_LOG(DDS_LC_RADMIN, "rmsg_addbias(%p)\n", (void *) rmsg); ASSERT_RBUFPOOL_OWNER (rmsg->chunk.rbuf->rbufpool); ASSERT_RMSG_UNCOMMITTED (rmsg); - os_atomic_add32 (&rmsg->refcount, RMSG_REFCOUNT_RDATA_BIAS); + ddsrt_atomic_add32 (&rmsg->refcount, RMSG_REFCOUNT_RDATA_BIAS); } static void nn_rmsg_rmbias_and_adjust (struct nn_rmsg *rmsg, int adjust) @@ -637,8 +641,8 @@ static void nn_rmsg_rmbias_and_adjust (struct nn_rmsg *rmsg, int adjust) assert (adjust >= 0); assert ((uint32_t) adjust < RMSG_REFCOUNT_RDATA_BIAS); sub = RMSG_REFCOUNT_RDATA_BIAS - (uint32_t) adjust; - assert (os_atomic_ld32 (&rmsg->refcount) >= sub); - if (os_atomic_sub32_nv (&rmsg->refcount, sub) == 0) + assert (ddsrt_atomic_ld32 (&rmsg->refcount) >= sub); + if (ddsrt_atomic_sub32_nv (&rmsg->refcount, sub) == 0) nn_rmsg_free (rmsg); } @@ -647,15 +651,15 @@ static void nn_rmsg_rmbias_anythread (struct nn_rmsg *rmsg) /* For removing garbage when freeing a nn_defrag. */ uint32_t sub = RMSG_REFCOUNT_RDATA_BIAS; DDS_LOG(DDS_LC_RADMIN, "rmsg_rmbias_anythread(%p)\n", (void *) rmsg); - assert (os_atomic_ld32 (&rmsg->refcount) >= sub); - if (os_atomic_sub32_nv (&rmsg->refcount, sub) == 0) + assert (ddsrt_atomic_ld32 (&rmsg->refcount) >= sub); + if (ddsrt_atomic_sub32_nv (&rmsg->refcount, sub) == 0) nn_rmsg_free (rmsg); } static void nn_rmsg_unref (struct nn_rmsg *rmsg) { DDS_LOG(DDS_LC_RADMIN, "rmsg_unref(%p)\n", (void *) rmsg); - assert (os_atomic_ld32 (&rmsg->refcount) > 0); - if (os_atomic_dec32_ov (&rmsg->refcount) == 1) + assert (ddsrt_atomic_ld32 (&rmsg->refcount) > 0); + if (ddsrt_atomic_dec32_ov (&rmsg->refcount) == 1) nn_rmsg_free (rmsg); } @@ -715,7 +719,7 @@ struct nn_rdata *nn_rdata_new (struct nn_rmsg *rmsg, uint32_t start, uint32_t en d->submsg_zoff = (uint16_t) NN_OFF_TO_ZOFF (submsg_offset); d->payload_zoff = (uint16_t) NN_OFF_TO_ZOFF (payload_offset); #ifndef NDEBUG - os_atomic_st32 (&d->refcount_bias_added, 0); + ddsrt_atomic_st32 (&d->refcount_bias_added, 0); #endif DDS_LOG(DDS_LC_RADMIN, "rdata_new(%p, bytes [%u,%u), submsg @ %u, payload @ %u) = %p\n", (void *) rmsg, start, endp1, NN_RDATA_SUBMSG_OFF (d), NN_RDATA_PAYLOAD_OFF (d), (void *) d); return d; @@ -726,7 +730,7 @@ static void nn_rdata_addbias (struct nn_rdata *rdata) DDS_LOG(DDS_LC_RADMIN, "rdata_addbias(%p)\n", (void *) rdata); #ifndef NDEBUG ASSERT_RBUFPOOL_OWNER (rdata->rmsg->chunk.rbuf->rbufpool); - if (os_atomic_inc32_nv (&rdata->refcount_bias_added) != 1) + if (ddsrt_atomic_inc32_nv (&rdata->refcount_bias_added) != 1) abort (); #endif nn_rmsg_addbias (rdata->rmsg); @@ -736,7 +740,7 @@ static void nn_rdata_rmbias_and_adjust (struct nn_rdata *rdata, int adjust) { DDS_LOG(DDS_LC_RADMIN, "rdata_rmbias_and_adjust(%p, %d)\n", (void *) rdata, adjust); #ifndef NDEBUG - if (os_atomic_dec32_ov (&rdata->refcount_bias_added) != 1) + if (ddsrt_atomic_dec32_ov (&rdata->refcount_bias_added) != 1) abort (); #endif nn_rmsg_rmbias_and_adjust (rdata->rmsg, adjust); @@ -746,7 +750,7 @@ static void nn_rdata_rmbias_anythread (struct nn_rdata *rdata) { DDS_LOG(DDS_LC_RADMIN, "rdata_rmbias_anythread(%p)\n", (void *) rdata); #ifndef NDEBUG - if (os_atomic_dec32_ov (&rdata->refcount_bias_added) != 1) + if (ddsrt_atomic_dec32_ov (&rdata->refcount_bias_added) != 1) abort (); #endif nn_rmsg_rmbias_anythread (rdata->rmsg); @@ -878,7 +882,7 @@ struct nn_defrag *nn_defrag_new (enum nn_defrag_drop_mode drop_mode, uint32_t ma { struct nn_defrag *d; assert (max_samples >= 1); - if ((d = os_malloc (sizeof (*d))) == NULL) + if ((d = ddsrt_malloc (sizeof (*d))) == NULL) return NULL; ut_avlInit (&defrag_sampletree_treedef, &d->sampletree); d->drop_mode = drop_mode; @@ -942,7 +946,7 @@ void nn_defrag_free (struct nn_defrag *defrag) s = ut_avlFindMin (&defrag_sampletree_treedef, &defrag->sampletree); } assert (defrag->n_samples == 0); - os_free (defrag); + ddsrt_free (defrag); } static int defrag_try_merge_with_succ (struct nn_rsample_defrag *sample, struct nn_defrag_iv *node) @@ -1635,7 +1639,7 @@ static const ut_avlTreedef_t reorder_sampleivtree_treedef = struct nn_reorder *nn_reorder_new (enum nn_reorder_mode mode, uint32_t max_samples) { struct nn_reorder *r; - if ((r = os_malloc (sizeof (*r))) == NULL) + if ((r = ddsrt_malloc (sizeof (*r))) == NULL) return NULL; ut_avlInit (&reorder_sampleivtree_treedef, &r->sampleivtree); r->max_sampleiv = NULL; @@ -1675,7 +1679,7 @@ void nn_reorder_free (struct nn_reorder *r) } iv = ut_avlFindMin (&reorder_sampleivtree_treedef, &r->sampleivtree); } - os_free (r); + ddsrt_free (r); } static void reorder_add_rsampleiv (struct nn_reorder *reorder, struct nn_rsample *rsample) @@ -2359,8 +2363,8 @@ seqno_t nn_reorder_next_seq (const struct nn_reorder *reorder) /* DQUEUE -------------------------------------------------------------- */ struct nn_dqueue { - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; nn_dqueue_handler_t handler; void *handler_arg; @@ -2369,7 +2373,7 @@ struct nn_dqueue { struct thread_state1 *ts; char *name; uint32_t max_samples; - os_atomic_uint32_t nof_samples; + ddsrt_atomic_uint32_t nof_samples; }; enum dqueue_elem_kind { @@ -2379,7 +2383,7 @@ enum dqueue_elem_kind { }; enum nn_dqueue_bubble_kind { - NN_DQBK_STOP, /* _not_ os_malloc()ed! */ + NN_DQBK_STOP, /* _not_ ddsrt_malloc()ed! */ NN_DQBK_CALLBACK, NN_DQBK_RDGUID }; @@ -2421,7 +2425,7 @@ static uint32_t dqueue_thread (struct nn_dqueue *q) nn_guid_t rdguid, *prdguid = NULL; uint32_t rdguid_count = 0; - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); while (keepgoing) { struct nn_rsample_chain sc; @@ -2429,18 +2433,18 @@ static uint32_t dqueue_thread (struct nn_dqueue *q) LOG_THREAD_CPUTIME (next_thread_cputime); if (q->sc.first == NULL) - os_condWait (&q->cond, &q->lock); + ddsrt_cond_wait (&q->cond, &q->lock); sc = q->sc; q->sc.first = q->sc.last = NULL; - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); while (sc.first) { struct nn_rsample_chain_elem *e = sc.first; int ret; sc.first = e->next; - if (os_atomic_dec32_ov (&q->nof_samples) == 1) { - os_condBroadcast (&q->cond); + if (ddsrt_atomic_dec32_ov (&q->nof_samples) == 1) { + ddsrt_cond_broadcast (&q->cond); } thread_state_awake (self); switch (dqueue_elem_kind (e)) @@ -2487,7 +2491,7 @@ static uint32_t dqueue_thread (struct nn_dqueue *q) prdguid = &rdguid; break; } - os_free (b); + ddsrt_free (b); } break; } @@ -2495,9 +2499,9 @@ static uint32_t dqueue_thread (struct nn_dqueue *q) thread_state_asleep (self); } - os_mutexLock (&q->lock); + ddsrt_mutex_lock (&q->lock); } - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); return 0; } @@ -2507,36 +2511,36 @@ struct nn_dqueue *nn_dqueue_new (const char *name, uint32_t max_samples, nn_dque char *thrname; size_t thrnamesz; - if ((q = os_malloc (sizeof (*q))) == NULL) + if ((q = ddsrt_malloc (sizeof (*q))) == NULL) goto fail_q; - if ((q->name = os_strdup (name)) == NULL) + if ((q->name = ddsrt_strdup (name)) == NULL) goto fail_name; q->max_samples = max_samples; - os_atomic_st32 (&q->nof_samples, 0); + ddsrt_atomic_st32 (&q->nof_samples, 0); q->handler = handler; q->handler_arg = arg; q->sc.first = q->sc.last = NULL; - os_mutexInit (&q->lock); - os_condInit (&q->cond, &q->lock); + ddsrt_mutex_init (&q->lock); + ddsrt_cond_init (&q->cond); thrnamesz = 3 + strlen (name) + 1; - if ((thrname = os_malloc (thrnamesz)) == NULL) + if ((thrname = ddsrt_malloc (thrnamesz)) == NULL) goto fail_thrname; 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); + ddsrt_free (thrname); return q; fail_thread: - os_free (thrname); + ddsrt_free (thrname); fail_thrname: - os_condDestroy (&q->cond); - os_mutexDestroy (&q->lock); - os_free (q->name); + ddsrt_cond_destroy (&q->cond); + ddsrt_mutex_destroy (&q->lock); + ddsrt_free (q->name); fail_name: - os_free (q); + ddsrt_free (q); fail_q: return NULL; } @@ -2563,11 +2567,11 @@ void nn_dqueue_enqueue (struct nn_dqueue *q, struct nn_rsample_chain *sc, nn_reo assert (rres > 0); assert (sc->first); assert (sc->last->next == NULL); - os_mutexLock (&q->lock); - os_atomic_add32 (&q->nof_samples, (uint32_t) rres); + ddsrt_mutex_lock (&q->lock); + ddsrt_atomic_add32 (&q->nof_samples, (uint32_t) rres); if (nn_dqueue_enqueue_locked (q, sc)) - os_condBroadcast (&q->cond); - os_mutexUnlock (&q->lock); + ddsrt_cond_broadcast (&q->cond); + ddsrt_mutex_unlock (&q->lock); } static int nn_dqueue_enqueue_bubble_locked (struct nn_dqueue *q, struct nn_dqueue_bubble *b) @@ -2582,17 +2586,17 @@ static int nn_dqueue_enqueue_bubble_locked (struct nn_dqueue *q, struct nn_dqueu static void nn_dqueue_enqueue_bubble (struct nn_dqueue *q, struct nn_dqueue_bubble *b) { - os_mutexLock (&q->lock); - os_atomic_inc32 (&q->nof_samples); + ddsrt_mutex_lock (&q->lock); + ddsrt_atomic_inc32 (&q->nof_samples); if (nn_dqueue_enqueue_bubble_locked (q, b)) - os_condBroadcast (&q->cond); - os_mutexUnlock (&q->lock); + ddsrt_cond_broadcast (&q->cond); + ddsrt_mutex_unlock (&q->lock); } void nn_dqueue_enqueue_callback (struct nn_dqueue *q, nn_dqueue_callback_t cb, void *arg) { struct nn_dqueue_bubble *b; - b = os_malloc (sizeof (*b)); + b = ddsrt_malloc (sizeof (*b)); b->kind = NN_DQBK_CALLBACK; b->u.cb.cb = cb; b->u.cb.arg = arg; @@ -2603,7 +2607,7 @@ void nn_dqueue_enqueue1 (struct nn_dqueue *q, const nn_guid_t *rdguid, struct nn { struct nn_dqueue_bubble *b; - b = os_malloc (sizeof (*b)); + b = ddsrt_malloc (sizeof (*b)); b->kind = NN_DQBK_RDGUID; b->u.rdguid.rdguid = *rdguid; b->u.rdguid.count = (uint32_t) rres; @@ -2612,12 +2616,12 @@ void nn_dqueue_enqueue1 (struct nn_dqueue *q, const nn_guid_t *rdguid, struct nn assert (rdguid != NULL); assert (sc->first); assert (sc->last->next == NULL); - os_mutexLock (&q->lock); - os_atomic_add32 (&q->nof_samples, 1 + (uint32_t) rres); + ddsrt_mutex_lock (&q->lock); + ddsrt_atomic_add32 (&q->nof_samples, 1 + (uint32_t) rres); if (nn_dqueue_enqueue_bubble_locked (q, b)) - os_condBroadcast (&q->cond); + ddsrt_cond_broadcast (&q->cond); nn_dqueue_enqueue_locked (q, sc); - os_mutexUnlock (&q->lock); + ddsrt_mutex_unlock (&q->lock); } int nn_dqueue_is_full (struct nn_dqueue *q) @@ -2629,19 +2633,19 @@ int nn_dqueue_is_full (struct nn_dqueue *q) don't mind the occasional extra sample in the queue (we don't), and survive the occasional decision to not queue when it could've been queued (we do), it should be ok. */ - const uint32_t count = os_atomic_ld32 (&q->nof_samples); + const uint32_t count = ddsrt_atomic_ld32 (&q->nof_samples); return (count >= q->max_samples); } void nn_dqueue_wait_until_empty_if_full (struct nn_dqueue *q) { - const uint32_t count = os_atomic_ld32 (&q->nof_samples); + const uint32_t count = ddsrt_atomic_ld32 (&q->nof_samples); if (count >= q->max_samples) { - os_mutexLock (&q->lock); - while (os_atomic_ld32 (&q->nof_samples) > 0) - os_condWait (&q->cond, &q->lock); - os_mutexUnlock (&q->lock); + ddsrt_mutex_lock (&q->lock); + while (ddsrt_atomic_ld32 (&q->nof_samples) > 0) + ddsrt_cond_wait (&q->cond, &q->lock); + ddsrt_mutex_unlock (&q->lock); } } @@ -2658,8 +2662,8 @@ void nn_dqueue_free (struct nn_dqueue *q) join_thread (q->ts); assert (q->sc.first == NULL); - os_condDestroy (&q->cond); - os_mutexDestroy (&q->lock); - os_free (q->name); - os_free (q); + ddsrt_cond_destroy (&q->cond); + ddsrt_mutex_destroy (&q->lock); + ddsrt_free (q->name); + ddsrt_free (q); } diff --git a/src/core/ddsi/src/q_receive.c b/src/core/ddsi/src/q_receive.c index 8ce3321..7de04a6 100644 --- a/src/core/ddsi/src/q_receive.c +++ b/src/core/ddsi/src/q_receive.c @@ -14,43 +14,46 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/log.h" -#include "ddsi/q_md5.h" -#include "util/ut_avl.h" +#include "dds/ddsi/q_md5.h" +#include "dds/util/ut_avl.h" #include "dds__stream.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_plist.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_lat_estim.h" -#include "ddsi/q_bitset.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_ddsi_discovery.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_error.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_gc.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_receive.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_static_assert.h" -#include "ddsi/q_init.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/ddsi_mcgroup.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_serdata_default.h" /* FIXME: get rid of this */ +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_plist.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_lat_estim.h" +#include "dds/ddsi/q_bitset.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_ddsi_discovery.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_receive.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_static_assert.h" +#include "dds/ddsi/q_init.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_mcgroup.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_serdata_default.h" /* FIXME: get rid of this */ -#include "ddsi/sysdeps.h" +#include "dds/ddsi/sysdeps.h" #include "dds__whc.h" /* @@ -415,13 +418,13 @@ static int valid_Data (const struct receiver_state *rst, struct nn_rmsg *rmsg, D case CDR_BE: case PL_CDR_BE: { - sampleinfo->bswap = PLATFORM_IS_LITTLE_ENDIAN ? 1 : 0; + sampleinfo->bswap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? 1 : 0); break; } case CDR_LE: case PL_CDR_LE: { - sampleinfo->bswap = PLATFORM_IS_LITTLE_ENDIAN ? 0 : 1; + sampleinfo->bswap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? 0 : 1); break; } default: @@ -554,13 +557,13 @@ static int valid_DataFrag (const struct receiver_state *rst, struct nn_rmsg *rms case CDR_BE: case PL_CDR_BE: { - sampleinfo->bswap = PLATFORM_IS_LITTLE_ENDIAN ? 1 : 0; + sampleinfo->bswap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? 1 : 0); break; } case CDR_LE: case PL_CDR_LE: { - sampleinfo->bswap = PLATFORM_IS_LITTLE_ENDIAN ? 0 : 1; + sampleinfo->bswap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? 0 : 1); break; } default: @@ -754,7 +757,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac /* liveliness is still only implemented partially (with all set to AUTOMATIC, BY_PARTICIPANT, &c.), so we simply renew the proxy participant's lease. */ if (prd->assert_pp_lease) - lease_renew (os_atomic_ldvoidp (&prd->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&prd->c.proxypp->lease), tnow); if (!wr->reliable) /* note: reliability can't be changed */ { @@ -762,7 +765,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac return 1; } - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if ((rn = ut_avlLookup (&wr_readers_treedef, &wr->readers, &src)) == NULL) { DDS_TRACE(" %x:%x:%x:%x -> %x:%x:%x:%x not a connection)", PGUID (src), PGUID (dst)); @@ -1066,7 +1069,7 @@ static int handle_AckNack (struct receiver_state *rst, nn_etime_t tnow, const Ac force_heartbeat_to_peer (wr, &whcst, prd, 0); DDS_TRACE(")"); out: - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); whc_free_deferred_free_list (wr->whc, deferred_free_list); return 1; } @@ -1226,11 +1229,11 @@ static int handle_Heartbeat (struct receiver_state *rst, nn_etime_t tnow, struct /* liveliness is still only implemented partially (with all set to AUTOMATIC, BY_PARTICIPANT, &c.), so we simply renew the proxy participant's lease. */ if (pwr->assert_pp_lease) - lease_renew (os_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); DDS_TRACE("%x:%x:%x:%x -> %x:%x:%x:%x:", PGUID (src), PGUID (dst)); - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if (!pwr->have_seen_heartbeat) { @@ -1323,7 +1326,7 @@ static int handle_Heartbeat (struct receiver_state *rst, nn_etime_t tnow, struct handle_forall_destinations (&dst, pwr, (ut_avlWalk_t) handle_Heartbeat_helper, &arg); DDS_TRACE(")"); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return 1; } @@ -1354,10 +1357,10 @@ static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(nn_etime /* liveliness is still only implemented partially (with all set to AUTOMATIC, BY_PARTICIPANT, &c.), so we simply renew the proxy participant's lease. */ if (pwr->assert_pp_lease) - lease_renew (os_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); DDS_TRACE(" %x:%x:%x:%x -> %x:%x:%x:%x", PGUID (src), PGUID (dst)); - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if (seq > pwr->last_seq) { @@ -1434,7 +1437,7 @@ static int handle_HeartbeatFrag (struct receiver_state *rst, UNUSED_ARG(nn_etime } } DDS_TRACE(")"); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return 1; } @@ -1482,7 +1485,7 @@ static int handle_NackFrag (struct receiver_state *rst, nn_etime_t tnow, const N /* liveliness is still only implemented partially (with all set to AUTOMATIC, BY_PARTICIPANT, &c.), so we simply renew the proxy participant's lease. */ if (prd->assert_pp_lease) - lease_renew (os_atomic_ldvoidp (&prd->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&prd->c.proxypp->lease), tnow); if (!wr->reliable) /* note: reliability can't be changed */ { @@ -1490,7 +1493,7 @@ static int handle_NackFrag (struct receiver_state *rst, nn_etime_t tnow, const N return 1; } - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if ((rn = ut_avlLookup (&wr_readers_treedef, &wr->readers, &src)) == NULL) { DDS_TRACE(" %x:%x:%x:%x -> %x:%x:%x:%x not a connection", PGUID (src), PGUID (dst)); @@ -1557,7 +1560,7 @@ static int handle_NackFrag (struct receiver_state *rst, nn_etime_t tnow, const N } out: - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); DDS_TRACE(")"); return 1; } @@ -1730,13 +1733,13 @@ static int handle_Gap (struct receiver_state *rst, nn_etime_t tnow, struct nn_rm /* liveliness is still only implemented partially (with all set to AUTOMATIC, BY_PARTICIPANT, &c.), so we simply renew the proxy participant's lease. */ if (pwr->assert_pp_lease) - lease_renew (os_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if ((wn = ut_avlLookup (&pwr_readers_treedef, &pwr->readers, &dst)) == NULL) { DDS_TRACE("%x:%x:%x:%x -> %x:%x:%x:%x not a connection)", PGUID (src), PGUID (dst)); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return 1; } DDS_TRACE("%x:%x:%x:%x -> %x:%x:%x:%x", PGUID (src), PGUID (dst)); @@ -1790,7 +1793,7 @@ static int handle_Gap (struct receiver_state *rst, nn_etime_t tnow, struct nn_rm pwr->last_fragnum_reset = 0; } DDS_TRACE(")"); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return 1; } @@ -2029,7 +2032,7 @@ static int deliver_user_data (const struct nn_rsample_info *sampleinfo, const st (with late acknowledgement of sample and nack). */ retry: - os_mutexLock (&pwr->rdary.rdary_lock); + ddsrt_mutex_lock (&pwr->rdary.rdary_lock); if (pwr->rdary.fastpath_ok) { struct reader ** const rdary = pwr->rdary.rdary; @@ -2039,14 +2042,14 @@ retry: DDS_TRACE("reader %x:%x:%x:%x\n", PGUID (rdary[i]->e.guid)); if (! (ddsi_plugin.rhc_plugin.rhc_store_fn) (rdary[i]->rhc, &pwr_info, payload, tk)) { - if (pwr_locked) os_mutexUnlock (&pwr->e.lock); - os_mutexUnlock (&pwr->rdary.rdary_lock); + if (pwr_locked) ddsrt_mutex_unlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->rdary.rdary_lock); dds_sleepfor (DDS_MSECS (10)); - if (pwr_locked) os_mutexLock (&pwr->e.lock); + if (pwr_locked) ddsrt_mutex_lock (&pwr->e.lock); goto retry; } } - os_mutexUnlock (&pwr->rdary.rdary_lock); + ddsrt_mutex_unlock (&pwr->rdary.rdary_lock); } else { @@ -2060,8 +2063,8 @@ retry: reliable samples that are rejected are simply discarded. */ ut_avlIter_t it; struct pwr_rd_match *m; - os_mutexUnlock (&pwr->rdary.rdary_lock); - if (!pwr_locked) os_mutexLock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->rdary.rdary_lock); + if (!pwr_locked) ddsrt_mutex_lock (&pwr->e.lock); for (m = ut_avlIterFirst (&pwr_readers_treedef, &pwr->readers, &it); m != NULL; m = ut_avlIterNext (&it)) { struct reader *rd; @@ -2071,10 +2074,10 @@ retry: (void) (ddsi_plugin.rhc_plugin.rhc_store_fn) (rd->rhc, &pwr_info, payload, tk); } } - if (!pwr_locked) os_mutexUnlock (&pwr->e.lock); + if (!pwr_locked) ddsrt_mutex_unlock (&pwr->e.lock); } - os_atomic_st32 (&pwr->next_deliv_seq_lowword, (uint32_t) (sampleinfo->seq + 1)); + ddsrt_atomic_st32 (&pwr->next_deliv_seq_lowword, (uint32_t) (sampleinfo->seq + 1)); } else { @@ -2082,9 +2085,9 @@ retry: DDS_TRACE(" %"PRId64"=>%x:%x:%x:%x%s\n", sampleinfo->seq, PGUID (*rdguid), rd ? "" : "?"); while (rd && ! (ddsi_plugin.rhc_plugin.rhc_store_fn) (rd->rhc, &pwr_info, payload, tk) && ephash_lookup_proxy_writer_guid (&pwr->e.guid)) { - if (pwr_locked) os_mutexUnlock (&pwr->e.lock); + if (pwr_locked) ddsrt_mutex_unlock (&pwr->e.lock); dds_sleepfor (DDS_MSECS (1)); - if (pwr_locked) os_mutexLock (&pwr->e.lock); + if (pwr_locked) ddsrt_mutex_lock (&pwr->e.lock); } } ddsi_tkmap_instance_unref (tk); @@ -2164,14 +2167,14 @@ static void handle_regular (struct receiver_state *rst, nn_etime_t tnow, struct participant's lease. */ if (pwr->assert_pp_lease) { - lease_renew (os_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); + lease_renew (ddsrt_atomic_ldvoidp (&pwr->c.proxypp->lease), tnow); } /* Shouldn't lock the full writer, but will do so for now */ - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if (ut_avlIsEmpty (&pwr->readers) || pwr->local_matching_inprogress) { - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); DDS_TRACE(" %x:%x:%x:%x -> %x:%x:%x:%x: no readers", PGUID (pwr->e.guid), PGUID (dst)); return; } @@ -2285,7 +2288,7 @@ static void handle_regular (struct receiver_state *rst, nn_etime_t tnow, struct #endif nn_fragchain_adjust_refcount (fragchain, refc_adjust); } - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); nn_dqueue_wait_until_empty_if_full (pwr->dqueue); } @@ -2296,12 +2299,12 @@ static int handle_SPDP (const struct nn_rsample_info *sampleinfo, struct nn_rdat struct nn_rdata *fragchain; nn_reorder_result_t rres; int refc_adjust = 0; - os_mutexLock (&gv.spdp_lock); + ddsrt_mutex_lock (&gv.spdp_lock); rsample = nn_defrag_rsample (gv.spdp_defrag, rdata, sampleinfo); fragchain = nn_rsample_fragchain (rsample); if ((rres = nn_reorder_rsample (&sc, gv.spdp_reorder, rsample, &refc_adjust, nn_dqueue_is_full (gv.builtins_dqueue))) > 0) nn_dqueue_enqueue (gv.builtins_dqueue, &sc, rres); - os_mutexUnlock (&gv.spdp_lock); + ddsrt_mutex_unlock (&gv.spdp_lock); nn_fragchain_adjust_refcount (fragchain, refc_adjust); return 0; } @@ -2336,10 +2339,10 @@ static void drop_oversize (struct receiver_state *rst, struct nn_rmsg *rmsg, con dst.prefix = rst->dst_guid_prefix; dst.entityid = msg->readerId; - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); wn = ut_avlLookup (&pwr_readers_treedef, &pwr->readers, &dst); gap_was_valuable = handle_one_gap (pwr, wn, sampleinfo->seq, sampleinfo->seq+1, gap, &refc_adjust); - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); nn_fragchain_adjust_refcount (gap, refc_adjust); if (gap_was_valuable) @@ -2687,11 +2690,11 @@ static int handle_submsg_sequence if (sm->smhdr.flags & SMFLAG_ENDIANNESS) { - byteswap = ! PLATFORM_IS_LITTLE_ENDIAN; + byteswap = !(DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); } else { - byteswap = PLATFORM_IS_LITTLE_ENDIAN; + byteswap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); } if (byteswap) { @@ -2986,11 +2989,11 @@ static bool do_packet if (ml->smhdr.flags & SMFLAG_ENDIANNESS) { - swap = ! PLATFORM_IS_LITTLE_ENDIAN; + swap = !(DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); } else { - swap = PLATFORM_IS_LITTLE_ENDIAN; + swap = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN); } if (swap) { @@ -3066,8 +3069,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_socket h1 = ddsi_conn_handle (a->m_conn); - os_socket h2 = ddsi_conn_handle (b->m_conn); + ddsrt_socket_t h1 = ddsi_conn_handle (a->m_conn); + ddsrt_socket_t h2 = ddsi_conn_handle (b->m_conn); return (h1 == h2) ? 0 : (h1 < h2) ? -1 : 1; } @@ -3106,12 +3109,12 @@ static void local_participant_set_init (struct local_participant_set *lps) { lps->ps = NULL; lps->nps = 0; - lps->gen = os_atomic_ld32 (&gv.participant_set_generation) - 1; + lps->gen = ddsrt_atomic_ld32 (&gv.participant_set_generation) - 1; } static void local_participant_set_fini (struct local_participant_set *lps) { - os_free (lps->ps); + ddsrt_free (lps->ps); } static void rebuild_local_participant_set (struct thread_state1 *self, struct local_participant_set *lps) @@ -3119,17 +3122,17 @@ static void rebuild_local_participant_set (struct thread_state1 *self, struct lo struct ephash_enum_participant est; struct participant *pp; unsigned nps_alloc; - DDS_TRACE("pp set gen changed: local %u global %"PRIu32"\n", lps->gen, os_atomic_ld32(&gv.participant_set_generation)); + DDS_TRACE("pp set gen changed: local %u global %"PRIu32"\n", lps->gen, ddsrt_atomic_ld32(&gv.participant_set_generation)); thread_state_awake (self); restart: - lps->gen = os_atomic_ld32 (&gv.participant_set_generation); + lps->gen = ddsrt_atomic_ld32 (&gv.participant_set_generation); /* Actual local set of participants may never be older than the local generation count => membar to guarantee the ordering */ - os_atomic_fence_acq (); + ddsrt_atomic_fence_acq (); nps_alloc = gv.nparticipants; - os_free (lps->ps); + ddsrt_free (lps->ps); lps->nps = 0; - lps->ps = (nps_alloc == 0) ? NULL : os_malloc (nps_alloc * sizeof (*lps->ps)); + lps->ps = (nps_alloc == 0) ? NULL : ddsrt_malloc (nps_alloc * sizeof (*lps->ps)); ephash_enum_participant_init (&est); while ((pp = ephash_enum_participant_next (&est)) != NULL) { @@ -3147,7 +3150,7 @@ static void rebuild_local_participant_set (struct thread_state1 *self, struct lo { lps->ps[lps->nps].m_conn = pp->m_conn; lps->ps[lps->nps].guid_prefix = pp->e.guid.prefix; - DDS_TRACE(" pp %x:%x:%x:%x handle %"PRIsock"\n", PGUID (pp->e.guid), ddsi_conn_handle (pp->m_conn)); + DDS_TRACE(" pp %x:%x:%x:%x handle %"PRIdSOCK"\n", PGUID (pp->e.guid), ddsi_conn_handle (pp->m_conn)); lps->nps++; } } @@ -3159,8 +3162,8 @@ static void rebuild_local_participant_set (struct thread_state1 *self, struct lo participant guid prefix for a directed packet without an explicit destination. Membar because we must have completed the loop before testing the generation again. */ - os_atomic_fence_acq (); - if (lps->gen != os_atomic_ld32 (&gv.participant_set_generation)) + ddsrt_atomic_fence_acq (); + if (lps->gen != ddsrt_atomic_ld32 (&gv.participant_set_generation)) { DDS_TRACE(" set changed - restarting\n"); goto restart; @@ -3313,7 +3316,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; - os_iovec_t iov; + ddsrt_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)); @@ -3337,7 +3340,7 @@ uint32_t recv_thread (void *vrecv_thread_arg) os_sockWaitset waitset = recv_thread_arg->mode == RTM_MANY ? recv_thread_arg->u.many.ws : NULL; nn_mtime_t next_thread_cputime = { 0 }; - nn_rbufpool_setowner (rbpool, os_threadIdSelf ()); + nn_rbufpool_setowner (rbpool, ddsrt_thread_self ()); if (waitset == NULL) { while (gv.rtps_keepgoing) @@ -3383,7 +3386,7 @@ uint32_t recv_thread (void *vrecv_thread_arg) { /* no other sockets to check */ } - else if (os_atomic_ld32 (&gv.participant_set_generation) != lps.gen) + else if (ddsrt_atomic_ld32 (&gv.participant_set_generation) != lps.gen) { rebuildws = 1; } diff --git a/src/core/ddsi/src/q_security.c b/src/core/ddsi/src/q_security.c index 58642cb..b6ba901 100644 --- a/src/core/ddsi/src/q_security.c +++ b/src/core/ddsi/src/q_security.c @@ -11,10 +11,10 @@ */ #ifdef DDSI_INCLUDE_ENCRYPTION -#include "ddsi/q_security.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_error.h" +#include "dds/ddsi/q_security.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_error.h" #include "os/os_stdlib.h" #include "os/os_process.h" #include "os/os_thread.h" @@ -539,7 +539,7 @@ static c_bool q_securityResolveCipherKeyFromUri const char *justPath = (char *)(uriStr + strlen(URI_FILESCHEMA)); - filename = os_strdup (justPath); + filename = ddsrt_strdup (justPath); file = fopen(filename, "r"); if (file) { /* read at most 255 chars from file, this should suffice if the @@ -561,7 +561,7 @@ static c_bool q_securityResolveCipherKeyFromUri DDS_ERROR("q_securityResolveCipherKeyFromUri: Could not open %s",uriStr); } - os_free(filename); + ddsrt_free(filename); } else if (uriStr != NULL) { /* seems to be a hex string */ @@ -600,34 +600,34 @@ static c_bool q_securityCipherTypeFromString(const char* cipherName, return FALSE; } - if (os_strcasecmp(cipherName, "null") == 0) { + if (ddsrt_strcasecmp(cipherName, "null") == 0) { *cipherType = Q_CIPHER_NULL; - } else if (os_strcasecmp(cipherName, "blowfish") == 0 || - os_strcasecmp(cipherName, "blowfish-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "blowfish") == 0 || + ddsrt_strcasecmp(cipherName, "blowfish-sha1") == 0) { *cipherType = Q_CIPHER_BLOWFISH; - } else if (os_strcasecmp(cipherName, "aes128") == 0 || - os_strcasecmp(cipherName, "aes128-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "aes128") == 0 || + ddsrt_strcasecmp(cipherName, "aes128-sha1") == 0) { *cipherType = Q_CIPHER_AES128; - } else if (os_strcasecmp(cipherName, "aes192") == 0 || - os_strcasecmp(cipherName, "aes192-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "aes192") == 0 || + ddsrt_strcasecmp(cipherName, "aes192-sha1") == 0) { *cipherType = Q_CIPHER_AES192; - } else if (os_strcasecmp(cipherName, "aes256") == 0 || - os_strcasecmp(cipherName, "aes256-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "aes256") == 0 || + ddsrt_strcasecmp(cipherName, "aes256-sha1") == 0) { *cipherType = Q_CIPHER_AES256; #if 0 - } else if (os_strcasecmp(cipherName, "rsa-null") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "rsa-null") == 0) { *cipherType = Q_CIPHER_RSA_WITH_NULL; - } else if (os_strcasecmp(cipherName, "rsa-blowfish") == 0 || - os_strcasecmp(cipherName, "rsa-blowfish-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "rsa-blowfish") == 0 || + ddsrt_strcasecmp(cipherName, "rsa-blowfish-sha1") == 0) { *cipherType = Q_CIPHER_RSA_WITH_BLOWFISH; - } else if (os_strcasecmp(cipherName, "rsa-aes128") == 0 || - os_strcasecmp(cipherName, "rsa-aes128-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "rsa-aes128") == 0 || + ddsrt_strcasecmp(cipherName, "rsa-aes128-sha1") == 0) { *cipherType = Q_CIPHER_RSA_WITH_AES128; - } else if (os_strcasecmp(cipherName, "rsa-aes192") == 0 || - os_strcasecmp(cipherName, "rsa-aes192-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "rsa-aes192") == 0 || + ddsrt_strcasecmp(cipherName, "rsa-aes192-sha1") == 0) { *cipherType = Q_CIPHER_RSA_WITH_AES192; - } else if (os_strcasecmp(cipherName, "rsa-aes256") == 0 || - os_strcasecmp(cipherName, "rsa-aes256-sha1") == 0) { + } else if (ddsrt_strcasecmp(cipherName, "rsa-aes256") == 0 || + ddsrt_strcasecmp(cipherName, "rsa-aes256-sha1") == 0) { *cipherType = Q_CIPHER_RSA_WITH_AES256; #endif } else { @@ -668,8 +668,10 @@ static os_uint32 cipherTypeToHeaderSize(q_cipherType cipherType) { static void q_securityRNGSeed (void) { - os_time time=os_timeGetMonotonic(); - RAND_seed((const void *)&time.tv_nsec,sizeof(time.tv_nsec)); + int32_t nsec; + dds_time_t time = ddsrt_time_monotonic(); + nsec = time % DDS_NSECS_IN_SEC; + RAND_seed(nsec,sizeof(nsec)); } static @@ -947,7 +949,7 @@ static q_securityEncoderSet q_securityEncoderSetNew (void) const os_uint32 nofPartitions = config.nof_networkPartitions; q_securityEncoderSet result = - os_malloc(sizeof(C_STRUCT(q_securityEncoderSet))); + ddsrt_malloc(sizeof(C_STRUCT(q_securityEncoderSet))); if (!result) { return NULL; @@ -958,7 +960,7 @@ static q_securityEncoderSet q_securityEncoderSetNew (void) if (nofPartitions == 0) { result->encoders = NULL; } else { - result->encoders = os_malloc(sizeof(C_STRUCT(q_securityPartitionEncoder)) * nofPartitions); + result->encoders = ddsrt_malloc(sizeof(C_STRUCT(q_securityPartitionEncoder)) * nofPartitions); memset(result->encoders, 0, sizeof(C_STRUCT(q_securityPartitionEncoder)) * @@ -1037,11 +1039,11 @@ static q_securityDecoderSet q_securityDecoderSetNew (void) return NULL; } - result = os_malloc (sizeof(C_STRUCT(q_securityDecoderSet))); + result = ddsrt_malloc (sizeof(C_STRUCT(q_securityDecoderSet))); result->nofPartitions = 0; result->decoders = - os_malloc(sizeof(C_STRUCT(q_securityPartitionDecoder)) * nofPartitions); + ddsrt_malloc(sizeof(C_STRUCT(q_securityPartitionDecoder)) * nofPartitions); /* init the memory region */ memset(result->decoders, @@ -1115,8 +1117,8 @@ static c_bool q_securityEncoderSetFree (q_securityEncoderSet codec) q_securityPartitionEncoderFini(currentEncoder); } - os_free(codec->encoders); - os_free(codec); + ddsrt_free(codec->encoders); + ddsrt_free(codec); return 1; /* true */ } @@ -1137,8 +1139,8 @@ static c_bool q_securityDecoderSetFree (q_securityDecoderSet codec) q_securityPartitionDecoderFini(currentDecoder); } - os_free(codec->decoders); - os_free(codec); + ddsrt_free(codec->decoders); + ddsrt_free(codec); return TRUE; /* true */ } @@ -1674,7 +1676,7 @@ static os_ssize_t q_security_sendmsg } else { - buf = os_malloc (sz); + buf = ddsrt_malloc (sz); } /* ... then copy data into buffer */ data_size = 0; @@ -1715,7 +1717,7 @@ static os_ssize_t q_security_sendmsg if (buf != stbuf) { - os_free (buf); + ddsrt_free (buf); } return ret; } diff --git a/src/core/ddsi/src/q_servicelease.c b/src/core/ddsi/src/q_servicelease.c index e1d5967..4c7fa87 100644 --- a/src/core/ddsi/src/q_servicelease.c +++ b/src/core/ddsi/src/q_servicelease.c @@ -11,24 +11,24 @@ */ #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" -#include "ddsi/q_servicelease.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_time.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_error.h" -#include "ddsi/q_globals.h" /* for mattr, cattr */ -#include "ddsi/q_receive.h" +#include "dds/ddsi/q_servicelease.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_globals.h" /* for mattr, cattr */ +#include "dds/ddsi/q_receive.h" -#include "ddsi/sysdeps.h" /* for getrusage() */ - -static void nn_retrieve_lease_settings (os_time *sleepTime) +static dds_time_t nn_retrieve_lease_settings (void) { - const float leaseSec = config.servicelease_expiry_time; - float sleepSec = leaseSec * config.servicelease_update_factor; + const double leaseSec = config.servicelease_expiry_time; + double sleepSec = leaseSec * config.servicelease_update_factor; /* Run at no less than 1Hz: internal liveliness monitoring is slaved to this interval as well. 1Hz lease renewals and liveliness @@ -36,10 +36,10 @@ static void nn_retrieve_lease_settings (os_time *sleepTime) a second is a lot more useful than doing it once every few seconds. Besides -- we're now also gathering CPU statistics. */ if (sleepSec > 1.0f) - sleepSec = 1.0f; + return DDS_NSECS_IN_SEC; - sleepTime->tv_sec = (int32_t) sleepSec; - sleepTime->tv_nsec = (int32_t) ((sleepSec - (float) sleepTime->tv_sec) * 1e9f); + return ((dds_time_t)(sleepSec * DDS_NSECS_IN_SEC)) + + ((dds_time_t)(sleepSec * (double)DDS_NSECS_IN_SEC) % DDS_NSECS_IN_SEC); } struct alive_wd { @@ -48,14 +48,14 @@ struct alive_wd { }; struct nn_servicelease { - os_time sleepTime; + dds_time_t sleepTime; int keepgoing; struct alive_wd *av_ary; void (*renew_cb) (void *arg); void *renew_arg; - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; struct thread_state1 *ts; }; @@ -76,7 +76,7 @@ static uint32_t lease_renewal_thread (struct nn_servicelease *sl) sl->av_ary[i].alive = 1; sl->av_ary[i].wd = thread_states.ts[i].watchdog - 1; } - os_mutexLock (&sl->lock); + ddsrt_mutex_lock (&sl->lock); while (sl->keepgoing) { unsigned n_alive = 0; @@ -144,26 +144,22 @@ static uint32_t lease_renewal_thread (struct nn_servicelease *sl) was_alive = 0; } -#if SYSDEPS_HAVE_GETRUSAGE - /* If getrusage() is available, use it to log CPU and memory - statistics to the trace. Getrusage() can't fail if the - parameters are valid, and these are by the book. Still we - check. */ if (dds_get_log_mask() & DDS_LC_TIMING) { - struct rusage u; - if (getrusage (RUSAGE_SELF, &u) == 0) + ddsrt_rusage_t u; + if (ddsrt_getrusage (DDSRT_RUSAGE_SELF, &u) == DDS_RETCODE_OK) { DDS_LOG(DDS_LC_TIMING, - "rusage: utime %d.%06d stime %d.%06d maxrss %ld data %ld vcsw %ld ivcsw %ld\n", - (int) u.ru_utime.tv_sec, (int) u.ru_utime.tv_usec, - (int) u.ru_stime.tv_sec, (int) u.ru_stime.tv_usec, - u.ru_maxrss, u.ru_idrss, u.ru_nvcsw, u.ru_nivcsw); + "rusage: utime %d.%09d stime %d.%09d maxrss %ld data %ld vcsw %ld ivcsw %ld\n", + (int) u.utime / DDS_NSECS_IN_SEC, + (int) u.utime % DDS_NSECS_IN_SEC, + (int) u.stime / DDS_NSECS_IN_SEC, + (int) u.stime % DDS_NSECS_IN_SEC, + u.maxrss, u.idrss, u.nvcsw, u.nivcsw); } } -#endif - os_condTimedWait (&sl->cond, &sl->lock, &sl->sleepTime); + ddsrt_cond_waitfor (&sl->cond, &sl->lock, sl->sleepTime); /* We are never active in a way that matters for the garbage collection of old writers, &c. */ @@ -175,7 +171,7 @@ static uint32_t lease_renewal_thread (struct nn_servicelease *sl) if (gv.deaf) trigger_recv_threads (); } - os_mutexUnlock (&sl->lock); + ddsrt_mutex_unlock (&sl->lock); return 0; } @@ -187,32 +183,32 @@ struct nn_servicelease *nn_servicelease_new (void (*renew_cb) (void *arg), void { struct nn_servicelease *sl; - sl = os_malloc (sizeof (*sl)); - nn_retrieve_lease_settings (&sl->sleepTime); + sl = ddsrt_malloc (sizeof (*sl)); + sl->sleepTime = nn_retrieve_lease_settings (); sl->keepgoing = -1; sl->renew_cb = renew_cb ? renew_cb : dummy_renew_cb; sl->renew_arg = renew_arg; sl->ts = NULL; - if ((sl->av_ary = os_malloc (thread_states.nthreads * sizeof (*sl->av_ary))) == NULL) + if ((sl->av_ary = ddsrt_malloc (thread_states.nthreads * sizeof (*sl->av_ary))) == NULL) goto fail_vtimes; /* service lease update thread initializes av_ary */ - os_mutexInit (&sl->lock); - os_condInit (&sl->cond, &sl->lock); + ddsrt_mutex_init (&sl->lock); + ddsrt_cond_init (&sl->cond); return sl; fail_vtimes: - os_free (sl); + ddsrt_free (sl); return NULL; } int nn_servicelease_start_renewing (struct nn_servicelease *sl) { - os_mutexLock (&sl->lock); + ddsrt_mutex_lock (&sl->lock); assert (sl->keepgoing == -1); sl->keepgoing = 1; - os_mutexUnlock (&sl->lock); + ddsrt_mutex_unlock (&sl->lock); sl->ts = create_thread ("lease", (uint32_t (*) (void *)) lease_renewal_thread, sl); if (sl->ts == NULL) @@ -226,26 +222,27 @@ int nn_servicelease_start_renewing (struct nn_servicelease *sl) void nn_servicelease_statechange_barrier (struct nn_servicelease *sl) { - os_mutexLock (&sl->lock); - os_mutexUnlock (&sl->lock); + ddsrt_mutex_lock (&sl->lock); + ddsrt_mutex_unlock (&sl->lock); } void nn_servicelease_stop_renewing (struct nn_servicelease *sl) { if (sl->keepgoing != -1) { - os_mutexLock (&sl->lock); + ddsrt_mutex_lock (&sl->lock); sl->keepgoing = 0; - os_condSignal (&sl->cond); - os_mutexUnlock (&sl->lock); + ddsrt_cond_signal (&sl->cond); + ddsrt_mutex_unlock (&sl->lock); join_thread (sl->ts); } } void nn_servicelease_free (struct nn_servicelease *sl) { - os_condDestroy (&sl->cond); - os_mutexDestroy (&sl->lock); - os_free (sl->av_ary); - os_free (sl); + ddsrt_cond_destroy (&sl->cond); + ddsrt_mutex_destroy (&sl->lock); + ddsrt_free (sl->av_ary); + ddsrt_free (sl); } + diff --git a/src/core/ddsi/src/q_sockwaitset.c b/src/core/ddsi/src/q_sockwaitset.c index 7dfe534..f0187b1 100644 --- a/src/core/ddsi/src/q_sockwaitset.c +++ b/src/core/ddsi/src/q_sockwaitset.c @@ -13,12 +13,14 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/sync.h" -#include "ddsi/q_sockwaitset.h" -#include "ddsi/q_config.h" -#include "ddsi/q_log.h" -#include "ddsi/ddsi_tran.h" +#include "dds/ddsi/q_sockwaitset.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/ddsi_tran.h" #define WAITSET_DELTA 8 @@ -37,6 +39,7 @@ #if MODE_SEL == MODE_KQUEUE #include +#include #include #include #include @@ -48,7 +51,7 @@ struct os_sockWaitsetCtx struct kevent *evs; uint32_t nevs; uint32_t evs_sz; - uint32_t index; /* cursor for enumerating */ + uint32_t index; /* cursor for enumerating */ }; struct entry { @@ -60,11 +63,11 @@ struct entry { struct os_sockWaitset { int kqueue; - os_socket pipe[2]; /* pipe used for triggering */ - os_atomic_uint32_t sz; + int pipe[2]; /* pipe used for triggering */ + ddsrt_atomic_uint32_t sz; struct entry *entries; - struct os_sockWaitsetCtx ctx; /* set of descriptors being handled */ - os_mutex lock; /* for add/delete */ + struct os_sockWaitsetCtx ctx; /* set of descriptors being handled */ + ddsrt_mutex_t lock; /* for add/delete */ }; static int add_entry_locked (os_sockWaitset ws, ddsi_tran_conn_t conn, int fd) @@ -72,7 +75,7 @@ static int add_entry_locked (os_sockWaitset ws, ddsi_tran_conn_t conn, int fd) uint32_t idx, fidx, sz, n; struct kevent kev; assert (fd >= 0); - sz = os_atomic_ld32 (&ws->sz); + sz = ddsrt_atomic_ld32 (&ws->sz); for (idx = 0, fidx = UINT32_MAX, n = 0; idx < sz; idx++) { if (ws->entries[idx].fd == -1) @@ -85,8 +88,8 @@ static int add_entry_locked (os_sockWaitset ws, ddsi_tran_conn_t conn, int fd) if (fidx == UINT32_MAX) { - const uint32_t newsz = os_atomic_add32_nv (&ws->sz, WAITSET_DELTA); - ws->entries = os_realloc (ws->entries, newsz * sizeof (*ws->entries)); + const uint32_t newsz = ddsrt_atomic_add32_nv (&ws->sz, WAITSET_DELTA); + ws->entries = ddsrt_realloc (ws->entries, newsz * sizeof (*ws->entries)); for (idx = sz; idx < newsz; idx++) ws->entries[idx].fd = -1; fidx = sz; @@ -105,10 +108,10 @@ os_sockWaitset os_sockWaitsetNew (void) const uint32_t sz = WAITSET_DELTA; os_sockWaitset ws; uint32_t i; - if ((ws = os_malloc (sizeof (*ws))) == NULL) + if ((ws = ddsrt_malloc (sizeof (*ws))) == NULL) goto fail_waitset; - os_atomic_st32 (&ws->sz, sz); - if ((ws->entries = os_malloc (sz * sizeof (*ws->entries))) == NULL) + ddsrt_atomic_st32 (&ws->sz, sz); + if ((ws->entries = ddsrt_malloc (sz * sizeof (*ws->entries))) == NULL) goto fail_entries; for (i = 0; i < sz; i++) ws->entries[i].fd = -1; @@ -130,7 +133,7 @@ os_sockWaitset os_sockWaitsetNew (void) goto fail_fcntl; if (fcntl (ws->pipe[1], F_SETFD, fcntl (ws->pipe[1], F_GETFD) | FD_CLOEXEC) == -1) goto fail_fcntl; - os_mutexInit (&ws->lock); + ddsrt_mutex_init (&ws->lock); return ws; fail_fcntl: @@ -140,45 +143,43 @@ fail_add_trigger: fail_pipe: close (ws->kqueue); fail_kqueue: - os_free (ws->ctx.evs); + ddsrt_free (ws->ctx.evs); fail_ctx_evs: - os_free (ws->entries); + ddsrt_free (ws->entries); fail_entries: - os_free (ws); + ddsrt_free (ws); fail_waitset: return NULL; } void os_sockWaitsetFree (os_sockWaitset ws) { - os_mutexDestroy (&ws->lock); + ddsrt_mutex_destroy (&ws->lock); close (ws->pipe[0]); close (ws->pipe[1]); close (ws->kqueue); - os_free (ws->entries); - os_free (ws->ctx.evs); - os_free (ws); + ddsrt_free (ws->entries); + ddsrt_free (ws->ctx.evs); + ddsrt_free (ws); } void os_sockWaitsetTrigger (os_sockWaitset ws) { char buf = 0; int n; - int err; n = (int)write (ws->pipe[1], &buf, 1); if (n != 1) { - err = os_getErrno (); - DDS_WARNING("os_sockWaitsetTrigger: read failed on trigger pipe, errno = %d\n", err); + DDS_WARNING("os_sockWaitsetTrigger: read failed on trigger pipe, errno = %d\n", errno); } } int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) { int ret; - os_mutexLock (&ws->lock); + ddsrt_mutex_lock (&ws->lock); ret = add_entry_locked (ws, conn, ddsi_conn_handle (conn)); - os_mutexUnlock (&ws->lock); + ddsrt_mutex_unlock (&ws->lock); return ret; } @@ -190,8 +191,8 @@ void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) entries */ uint32_t i, sz; struct kevent kev; - os_mutexLock (&ws->lock); - sz = os_atomic_ld32 (&ws->sz); + ddsrt_mutex_lock (&ws->lock); + sz = ddsrt_atomic_ld32 (&ws->sz); close (ws->kqueue); if ((ws->kqueue = kqueue()) == -1) abort (); /* FIXME */ @@ -207,7 +208,7 @@ void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) ws->entries[i].conn = NULL; ws->entries[i].fd = -1; } - os_mutexUnlock (&ws->lock); + ddsrt_mutex_unlock (&ws->lock); } void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) @@ -215,8 +216,8 @@ void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) const int fd = ddsi_conn_handle (conn); uint32_t i, sz; assert (fd >= 0); - os_mutexLock (&ws->lock); - sz = os_atomic_ld32 (&ws->sz); + ddsrt_mutex_lock (&ws->lock); + sz = ddsrt_atomic_ld32 (&ws->sz); for (i = 1; i < sz; i++) if (ws->entries[i].fd == fd) break; @@ -228,7 +229,7 @@ void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) abort (); /* FIXME */ ws->entries[i].fd = -1; } - os_mutexUnlock (&ws->lock); + ddsrt_mutex_unlock (&ws->lock); } os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) @@ -236,12 +237,12 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) /* if the array of events is smaller than the number of file descriptors in the kqueue, things will still work fine, as the kernel will just return what can be stored, and the set will be grown on the next call */ - uint32_t ws_sz = os_atomic_ld32 (&ws->sz); + uint32_t ws_sz = ddsrt_atomic_ld32 (&ws->sz); int nevs; if (ws->ctx.evs_sz < ws_sz) { ws->ctx.evs_sz = ws_sz; - ws->ctx.evs = os_realloc (ws->ctx.evs, ws_sz * sizeof(*ws->ctx.evs)); + ws->ctx.evs = ddsrt_realloc (ws->ctx.evs, ws_sz * sizeof(*ws->ctx.evs)); } nevs = kevent (ws->kqueue, NULL, 0, ws->ctx.evs, (int)ws->ctx.evs_sz, NULL); if (nevs < 0) @@ -250,7 +251,7 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) nevs = 0; else { - DDS_WARNING("os_sockWaitsetWait: kevent failed, errno = %d\n", os_getErrno()); + DDS_WARNING("os_sockWaitsetWait: kevent failed, errno = %d\n", errno); return NULL; } } @@ -292,19 +293,19 @@ struct os_sockWaitsetCtx struct os_sockWaitset { - os_mutex mutex; /* concurrency guard */ + ddsrt_mutex_t mutex; /* concurrency guard */ struct os_sockWaitsetCtx ctx; struct os_sockWaitsetCtx ctx0; }; os_sockWaitset os_sockWaitsetNew (void) { - os_sockWaitset ws = os_malloc (sizeof (*ws)); + os_sockWaitset ws = ddsrt_malloc (sizeof (*ws)); ws->ctx.conns[0] = NULL; ws->ctx.events[0] = WSACreateEvent (); ws->ctx.n = 1; ws->ctx.index = -1; - os_mutexInit (&ws->mutex); + ddsrt_mutex_init (&ws->mutex); return ws; } @@ -316,15 +317,15 @@ void os_sockWaitsetFree (os_sockWaitset ws) { WSACloseEvent (ws->ctx.events[i]); } - os_mutexDestroy (&ws->mutex); - os_free (ws); + ddsrt_mutex_destroy (&ws->mutex); + ddsrt_free (ws); } void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) { unsigned i; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); for (i = index + 1; i < ws->ctx.n; i++) { ws->ctx.conns[i] = NULL; @@ -334,14 +335,14 @@ void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) } } ws->ctx.n = index + 1; - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); } void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) { unsigned i; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); for (i = 0; i < ws->ctx.n; i++) { if (conn == ws->ctx.conns[i]) @@ -356,7 +357,7 @@ void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) break; } } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); } void os_sockWaitsetTrigger (os_sockWaitset ws) @@ -374,7 +375,7 @@ int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) unsigned idx; int ret; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); for (idx = 0; idx < ws->ctx.n; idx++) { @@ -406,7 +407,7 @@ int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) } } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); return ret; } @@ -416,9 +417,9 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) assert (ws->index == -1); - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); ws->ctx0 = ws->ctx; - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); if ((idx = WSAWaitForMultipleEvents (ws->ctx0.n, ws->ctx0.events, FALSE, WSA_INFINITE, FALSE)) == WSA_WAIT_FAILED) { @@ -528,7 +529,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_socket * fds; /* file descriptors in set */ + ddsrt_socket_t * fds; /* file descriptors in set */ unsigned sz; /* max number of fds in context */ unsigned n; /* actual number of fds in context */ } os_sockWaitsetSet; @@ -542,21 +543,21 @@ struct os_sockWaitsetCtx struct os_sockWaitset { - os_socket pipe[2]; /* pipe used for triggering */ - os_mutex mutex; /* concurrency guard */ + ddsrt_socket_t pipe[2]; /* pipe used for triggering */ + ddsrt_mutex_t mutex; /* concurrency guard */ int fdmax_plus_1; /* value for first parameter of select() */ os_sockWaitsetSet set; /* set of descriptors handled next */ struct os_sockWaitsetCtx ctx; /* set of descriptors being handled */ }; #if defined (_WIN32) -static int make_pipe (os_socket fd[2]) +static int make_pipe (ddsrt_socket_t 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 = OS_INVALID_SOCKET; + ddsrt_socket_t listener = socket (AF_INET, SOCK_STREAM, 0); + ddsrt_socket_t s1 = socket (AF_INET, SOCK_STREAM, 0); + ddsrt_socket_t s2 = DDSRT_INVALID_SOCKET; addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); @@ -617,8 +618,8 @@ static int make_pipe (int pfd[2]) static void os_sockWaitsetNewSet (os_sockWaitsetSet * set) { - set->fds = os_malloc (WAITSET_DELTA * sizeof (*set->fds)); - set->conns = os_malloc (WAITSET_DELTA * sizeof (*set->conns)); + set->fds = ddsrt_malloc (WAITSET_DELTA * sizeof (*set->fds)); + set->conns = ddsrt_malloc (WAITSET_DELTA * sizeof (*set->conns)); set->sz = WAITSET_DELTA; set->n = 1; } @@ -632,7 +633,7 @@ static void os_sockWaitsetNewCtx (os_sockWaitsetCtx ctx) os_sockWaitset os_sockWaitsetNew (void) { int result; - os_sockWaitset ws = os_malloc (sizeof (*ws)); + os_sockWaitset ws = ddsrt_malloc (sizeof (*ws)); os_sockWaitsetNewSet (&ws->set); os_sockWaitsetNewCtx (&ws->ctx); @@ -690,7 +691,7 @@ os_sockWaitset os_sockWaitsetNew (void) ws->fdmax_plus_1 = ws->set.fds[0] + 1; #endif - os_mutexInit (&ws->mutex); + ddsrt_mutex_init (&ws->mutex); return ws; } @@ -698,14 +699,14 @@ os_sockWaitset os_sockWaitsetNew (void) static void os_sockWaitsetGrow (os_sockWaitsetSet * set) { set->sz += WAITSET_DELTA; - set->conns = os_realloc (set->conns, set->sz * sizeof (*set->conns)); - set->fds = os_realloc (set->fds, set->sz * sizeof (*set->fds)); + set->conns = ddsrt_realloc (set->conns, set->sz * sizeof (*set->conns)); + set->fds = ddsrt_realloc (set->fds, set->sz * sizeof (*set->fds)); } static void os_sockWaitsetFreeSet (os_sockWaitsetSet * set) { - os_free (set->fds); - os_free (set->conns); + ddsrt_free (set->fds); + ddsrt_free (set->conns); } static void os_sockWaitsetFreeCtx (os_sockWaitsetCtx ctx) @@ -731,15 +732,14 @@ void os_sockWaitsetFree (os_sockWaitset ws) #endif os_sockWaitsetFreeSet (&ws->set); os_sockWaitsetFreeCtx (&ws->ctx); - os_mutexDestroy (&ws->mutex); - os_free (ws); + ddsrt_mutex_destroy (&ws->mutex); + ddsrt_free (ws); } void os_sockWaitsetTrigger (os_sockWaitset ws) { char buf = 0; int n; - int err; #if defined (_WIN32) n = send (ws->pipe[1], &buf, 1, 0); @@ -748,14 +748,13 @@ void os_sockWaitsetTrigger (os_sockWaitset ws) #endif if (n != 1) { - err = os_getErrno (); - DDS_WARNING("os_sockWaitsetTrigger: read failed on trigger pipe, errno = %d", err); + DDS_WARNING("os_sockWaitsetTrigger: write failed on trigger pipe\n"); } } int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) { - os_socket handle = ddsi_conn_handle (conn); + ddsrt_socket_t handle = ddsi_conn_handle (conn); os_sockWaitsetSet * set = &ws->set; unsigned idx; int ret; @@ -765,7 +764,7 @@ int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) assert (handle < FD_SETSIZE); #endif - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); for (idx = 0; idx < set->n; idx++) { if (set->conns[idx] == conn) @@ -786,7 +785,7 @@ int os_sockWaitsetAdd (os_sockWaitset ws, ddsi_tran_conn_t conn) set->n++; ret = 1; } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); return ret; } @@ -795,7 +794,7 @@ void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) unsigned i; os_sockWaitsetSet * set = &ws->set; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); if (index + 1 <= set->n) { for (i = index + 1; i < set->n; i++) @@ -805,7 +804,7 @@ void os_sockWaitsetPurge (os_sockWaitset ws, unsigned index) } set->n = index + 1; } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); } void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) @@ -813,7 +812,7 @@ void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) unsigned i; os_sockWaitsetSet * set = &ws->set; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); for (i = 0; i < set->n; i++) { if (conn == set->conns[i]) @@ -827,21 +826,20 @@ void os_sockWaitsetRemove (os_sockWaitset ws, ddsi_tran_conn_t conn) break; } } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); } os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) { - int n; + int n = -1; unsigned u; - int err; int fdmax; fd_set * rdset = NULL; os_sockWaitsetCtx ctx = &ws->ctx; os_sockWaitsetSet * dst = &ctx->set; os_sockWaitsetSet * src = &ws->set; - os_mutexLock (&ws->mutex); + ddsrt_mutex_lock (&ws->mutex); fdmax = ws->fdmax_plus_1; @@ -859,7 +857,7 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) dst->fds[u] = src->fds[u]; } - os_mutexUnlock (&ws->mutex); + ddsrt_mutex_unlock (&ws->mutex); /* Copy file descriptors into select read set */ @@ -872,15 +870,11 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) do { - n = select (fdmax, rdset, NULL, NULL, NULL); - if (n < 0) + dds_retcode_t rc = ddsrt_select (fdmax, rdset, NULL, NULL, DDS_INFINITY, &n); + if (rc != DDS_RETCODE_OK && rc != DDS_RETCODE_INTERRUPTED && rc != DDS_RETCODE_TRY_AGAIN) { - err = os_getErrno (); - if ((err != os_sockEINTR) && (err != os_sockEAGAIN)) - { - DDS_WARNING("os_sockWaitsetWait: select failed, errno = %d", err); - break; - } + DDS_WARNING("os_sockWaitsetWait: select failed, retcode = %d", rc); + break; } } while (n == -1); @@ -900,8 +894,7 @@ os_sockWaitsetCtx os_sockWaitsetWait (os_sockWaitset ws) #endif if (n1 != 1) { - err = os_getErrno (); - DDS_WARNING("os_sockWaitsetWait: read failed on trigger pipe, errno = %d", err); + DDS_WARNING("os_sockWaitsetWait: read failed on trigger pipe\n"); assert (0); } } @@ -916,7 +909,7 @@ int os_sockWaitsetNextEvent (os_sockWaitsetCtx ctx, ddsi_tran_conn_t * conn) while (ctx->index < ctx->set.n) { unsigned idx = ctx->index++; - os_socket fd = ctx->set.fds[idx]; + ddsrt_socket_t fd = ctx->set.fds[idx]; assert(idx > 0); if (FD_ISSET (fd, &ctx->rdset)) { diff --git a/src/core/ddsi/src/q_thread.c b/src/core/ddsi/src/q_thread.c index 3662d7e..0254062 100644 --- a/src/core/ddsi/src/q_thread.c +++ b/src/core/ddsi/src/q_thread.c @@ -13,24 +13,28 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_servicelease.h" -#include "ddsi/q_error.h" -#include "ddsi/q_log.h" -#include "ddsi/q_config.h" -#include "ddsi/q_globals.h" -#include "ddsi/sysdeps.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_servicelease.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/sysdeps.h" static char main_thread_name[] = "main"; struct thread_states thread_states; -os_threadLocal struct thread_state1 *tsd_thread_state; +ddsrt_thread_local struct thread_state1 *tsd_thread_state; -_Ret_bytecap_(size) -void * os_malloc_aligned_cacheline (_In_ size_t size) +void *ddsrt_malloc_aligned_cacheline (size_t size) { /* This wastes some space, but we use it only once and it isn't a huge amount of memory, just a little over a cache line. @@ -41,18 +45,18 @@ void * os_malloc_aligned_cacheline (_In_ size_t size) uintptr_t ptrA; void **pptr; void *ptr; - ptr = os_malloc (size + CACHE_LINE_SIZE + sizeof (void *)); + ptr = ddsrt_malloc (size + CACHE_LINE_SIZE + sizeof (void *)); ptrA = ((uintptr_t) ptr + sizeof (void *) + clm1) & ~clm1; pptr = (void **) ptrA; pptr[-1] = ptr; return (void *) ptrA; } -static void os_free_aligned ( _Pre_maybenull_ _Post_invalid_ void *ptr) +static void ddsrt_free_aligned (void *ptr) { if (ptr) { void **pptr = ptr; - os_free (pptr[-1]); + ddsrt_free (pptr[-1]); } } @@ -63,17 +67,17 @@ void thread_states_init_static (void) tsd_thread_state = &ts; } -void thread_states_init (_In_ unsigned maxthreads) +void thread_states_init (unsigned maxthreads) { unsigned i; - os_mutexInit (&thread_states.lock); + ddsrt_mutex_init (&thread_states.lock); thread_states.nthreads = maxthreads; thread_states.ts = - os_malloc_aligned_cacheline (maxthreads * sizeof (*thread_states.ts)); + ddsrt_malloc_aligned_cacheline (maxthreads * sizeof (*thread_states.ts)); memset (thread_states.ts, 0, maxthreads * sizeof (*thread_states.ts)); /* The compiler doesn't realize that ts is large enough. */ -OS_WARNING_MSVC_OFF(6386); +DDSRT_WARNING_MSVC_OFF(6386); for (i = 0; i < thread_states.nthreads; i++) { thread_states.ts[i].state = THREAD_STATE_ZERO; @@ -81,7 +85,7 @@ OS_WARNING_MSVC_OFF(6386); thread_states.ts[i].watchdog = 1; thread_states.ts[i].name = NULL; } -OS_WARNING_MSVC_ON(6386); +DDSRT_WARNING_MSVC_ON(6386); } void thread_states_fini (void) @@ -89,8 +93,8 @@ void thread_states_fini (void) unsigned i; for (i = 0; i < thread_states.nthreads; i++) assert (thread_states.ts[i].state != THREAD_STATE_ALIVE); - os_mutexDestroy (&thread_states.lock); - os_free_aligned (thread_states.ts); + ddsrt_mutex_destroy (&thread_states.lock); + ddsrt_free_aligned (thread_states.ts); /* All spawned threads are gone, but the main thread is still alive, downgraded to an ordinary thread (we're on it right now). We @@ -100,63 +104,56 @@ void thread_states_fini (void) thread_states.ts = NULL; } -static void -cleanup_thread_state( - _In_opt_ void *data) +static void cleanup_thread_state (void *data) { - struct thread_state1 *ts = get_thread_state(os_threadIdSelf()); - (void)data; - assert(ts->state == THREAD_STATE_ALIVE); - assert(vtime_asleep_p(ts->vtime)); - reset_thread_state(ts); - os_osExit(); + struct thread_state1 *ts = get_thread_state(ddsrt_thread_self()); + (void)data; + assert(ts->state == THREAD_STATE_ALIVE); + assert(vtime_asleep_p(ts->vtime)); + reset_thread_state(ts); + ddsrt_fini(); } -_Ret_valid_ struct thread_state1 * -lookup_thread_state( - void) +struct thread_state1 *lookup_thread_state (void) { - struct thread_state1 *ts1 = NULL; - char tname[128]; - os_threadId tid; + struct thread_state1 *ts1 = NULL; + char name[128]; + ddsrt_thread_t thr; - if ((ts1 = tsd_thread_state) == NULL) { - if ((ts1 = lookup_thread_state_real()) == NULL) { - /* this situation only arises for threads that were not created - using create_thread, aka application threads. since registering - thread state should be fully automatic the name will simply be - the identifier */ - tid = os_threadIdSelf(); - (void)snprintf( - tname, sizeof(tname), "0x%"PRIxMAX, os_threadIdToInteger(tid)); - os_mutexLock(&thread_states.lock); - ts1 = init_thread_state(tname); - if (ts1 != NULL) { - os_osInit(); - ts1->extTid = tid; - ts1->tid = tid; - DDS_LOG(DDS_LC_TRACE, "started application thread %s\n", tname); - os_threadCleanupPush(&cleanup_thread_state, NULL); - } - os_mutexUnlock(&thread_states.lock); - } - - tsd_thread_state = ts1; + if ((ts1 = tsd_thread_state) == NULL) { + if ((ts1 = lookup_thread_state_real()) == NULL) { + /* This situation only arises for threads that were not created using + create_thread, aka application threads. Since registering thread + state should be fully automatic the name is simply the identifier. */ + thr = ddsrt_thread_self(); + ddsrt_thread_getname(name, sizeof(name)); + ddsrt_mutex_lock(&thread_states.lock); + ts1 = init_thread_state(name); + if (ts1 != NULL) { + ddsrt_init(); + ts1->extTid = thr; + ts1->tid = thr; + DDS_TRACE("started application thread %s\n", name); + ddsrt_thread_cleanup_push(&cleanup_thread_state, NULL); + } + ddsrt_mutex_unlock(&thread_states.lock); } - assert(ts1 != NULL); + tsd_thread_state = ts1; + } - return ts1; + assert(ts1 != NULL); + + return ts1; } -_Success_(return != NULL) _Ret_maybenull_ struct thread_state1 *lookup_thread_state_real (void) { if (thread_states.ts) { - os_threadId tid = os_threadIdSelf (); + ddsrt_thread_t tid = ddsrt_thread_self (); unsigned i; for (i = 0; i < thread_states.nthreads; i++) { - if (os_threadEqual (thread_states.ts[i].tid, tid)) { + if (ddsrt_thread_equal (thread_states.ts[i].tid, tid)) { return &thread_states.ts[i]; } } @@ -166,20 +163,21 @@ struct thread_state1 *lookup_thread_state_real (void) struct thread_context { struct thread_state1 *self; - uint32_t (*f) (_In_opt_ void *arg); + uint32_t (*f) (void *arg); void *arg; }; -static uint32_t create_thread_wrapper (_In_ _Post_invalid_ struct thread_context *ctxt) +static uint32_t create_thread_wrapper (void *ptr) { uint32_t ret; - ctxt->self->tid = os_threadIdSelf (); - ret = ctxt->f (ctxt->arg); - os_free (ctxt); + struct thread_context *ctx = ptr; + ctx->self->tid = ddsrt_thread_self (); + ret = ctx->f (ctx->arg); + ddsrt_free (ctx); return ret; } -static int find_free_slot (_In_z_ const char *name) +static int find_free_slot (const char *name) { unsigned i; int cand; @@ -199,20 +197,20 @@ void upgrade_main_thread (void) { int cand; struct thread_state1 *ts1; - os_mutexLock (&thread_states.lock); + ddsrt_mutex_lock (&thread_states.lock); if ((cand = find_free_slot ("name")) < 0) abort (); ts1 = &thread_states.ts[cand]; if (ts1->state == THREAD_STATE_ZERO) assert (vtime_asleep_p (ts1->vtime)); ts1->state = THREAD_STATE_ALIVE; - ts1->tid = os_threadIdSelf (); + ts1->tid = ddsrt_thread_self (); ts1->name = main_thread_name; - os_mutexUnlock (&thread_states.lock); + ddsrt_mutex_unlock (&thread_states.lock); tsd_thread_state = ts1; } -const struct config_thread_properties_listelem *lookup_thread_properties (_In_z_ const char *name) +const struct config_thread_properties_listelem *lookup_thread_properties (const char *name) { const struct config_thread_properties_listelem *e; for (e = config.thread_properties; e != NULL; e = e->next) @@ -221,7 +219,7 @@ const struct config_thread_properties_listelem *lookup_thread_properties (_In_z_ return e; } -struct thread_state1 * init_thread_state (_In_z_ const char *tname) +struct thread_state1 * init_thread_state (const char *tname) { int cand; struct thread_state1 *ts; @@ -232,23 +230,21 @@ struct thread_state1 * init_thread_state (_In_z_ const char *tname) ts = &thread_states.ts[cand]; if (ts->state == THREAD_STATE_ZERO) assert (vtime_asleep_p (ts->vtime)); - ts->name = os_strdup (tname); + ts->name = ddsrt_strdup (tname); ts->state = THREAD_STATE_ALIVE; return ts; } -_Success_(return != NULL) -_Ret_maybenull_ -struct thread_state1 *create_thread (_In_z_ const char *name, _In_ uint32_t (*f) (void *arg), _In_opt_ void *arg) +struct thread_state1 *create_thread (const char *name, uint32_t (*f) (void *arg), void *arg) { struct config_thread_properties_listelem const * const tprops = lookup_thread_properties (name); - os_threadAttr tattr; + ddsrt_threadattr_t tattr; struct thread_state1 *ts1; - os_threadId tid; + ddsrt_thread_t tid; struct thread_context *ctxt; - ctxt = os_malloc (sizeof (*ctxt)); - os_mutexLock (&thread_states.lock); + ctxt = ddsrt_malloc (sizeof (*ctxt)); + ddsrt_mutex_lock (&thread_states.lock); ts1 = init_thread_state (name); @@ -258,7 +254,7 @@ struct thread_state1 *create_thread (_In_z_ const char *name, _In_ uint32_t (*f) ctxt->self = ts1; ctxt->f = f; ctxt->arg = arg; - os_threadAttrInit (&tattr); + ddsrt_threadattr_init (&tattr); if (tprops != NULL) { if (!tprops->sched_priority.isdefault) @@ -269,40 +265,39 @@ struct thread_state1 *create_thread (_In_z_ const char *name, _In_ uint32_t (*f) } DDS_TRACE("create_thread: %s: class %d priority %d stack %u\n", name, (int) tattr.schedClass, tattr.schedPriority, tattr.stackSize); - if (os_threadCreate (&tid, name, &tattr, (os_threadRoutine)&create_thread_wrapper, ctxt) != os_resultSuccess) + if (ddsrt_thread_create (&tid, name, &tattr, &create_thread_wrapper, ctxt) != DDS_RETCODE_OK) { ts1->state = THREAD_STATE_ZERO; - DDS_FATAL("create_thread: %s: os_threadCreate failed\n", name); + DDS_FATAL("create_thread: %s: ddsrt_thread_create failed\n", name); goto fatal; } - DDS_LOG(DDS_LC_TRACE, "started new thread 0x%"PRIxMAX" : %s\n", os_threadIdToInteger (tid), name); + DDS_TRACE("started new thread %"PRIdTID" : %s\n", ddsrt_gettid(), name); ts1->extTid = tid; /* overwrite the temporary value with the correct external one */ - os_mutexUnlock (&thread_states.lock); + ddsrt_mutex_unlock (&thread_states.lock); return ts1; fatal: - os_mutexUnlock (&thread_states.lock); - os_free (ctxt); + ddsrt_mutex_unlock (&thread_states.lock); + ddsrt_free (ctxt); abort (); return NULL; } -static void reap_thread_state (_Inout_ struct thread_state1 *ts1, _In_ int sync_with_servicelease) +static void reap_thread_state (struct thread_state1 *ts1, int sync_with_servicelease) { - os_mutexLock (&thread_states.lock); + ddsrt_mutex_lock (&thread_states.lock); ts1->state = THREAD_STATE_ZERO; if (sync_with_servicelease && gv.servicelease) nn_servicelease_statechange_barrier (gv.servicelease); if (ts1->name != main_thread_name) - os_free (ts1->name); - os_mutexUnlock (&thread_states.lock); + ddsrt_free (ts1->name); + ddsrt_mutex_unlock (&thread_states.lock); } -_Success_(return == 0) -int join_thread (_Inout_ struct thread_state1 *ts1) +int join_thread (struct thread_state1 *ts1) { int ret; assert (ts1->state == THREAD_STATE_ALIVE); - if (os_threadWaitExit (ts1->extTid, NULL) == os_resultSuccess) + if (ddsrt_thread_join (ts1->extTid, NULL) == DDS_RETCODE_OK) ret = 0; else ret = ERR_UNSPECIFIED; @@ -311,7 +306,7 @@ int join_thread (_Inout_ struct thread_state1 *ts1) return ret; } -void reset_thread_state (_Inout_opt_ struct thread_state1 *ts1) +void reset_thread_state (struct thread_state1 *ts1) { if (ts1) { @@ -329,14 +324,14 @@ void downgrade_main_thread (void) thread_states_init_static (); } -struct thread_state1 *get_thread_state (_In_ os_threadId id) +struct thread_state1 *get_thread_state (ddsrt_thread_t id) { unsigned i; struct thread_state1 *ts = NULL; for (i = 0; i < thread_states.nthreads; i++) { - if (os_threadEqual (thread_states.ts[i].extTid, id)) + if (ddsrt_thread_equal (thread_states.ts[i].extTid, id)) { ts = &thread_states.ts[i]; break; diff --git a/src/core/ddsi/src/q_thread_inlines.c b/src/core/ddsi/src/q_thread_inlines.c index b1c2a19..4d26a63 100644 --- a/src/core/ddsi/src/q_thread_inlines.c +++ b/src/core/ddsi/src/q_thread_inlines.c @@ -9,14 +9,14 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "ddsi/q_thread.h" +#include "dds/ddsi/q_thread.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 int vtime_awake_p (vtime_t vtime); +extern inline int vtime_asleep_p (vtime_t vtime); +extern inline int vtime_gt (vtime_t vtime1, 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); +extern inline void thread_state_asleep (struct thread_state1 *ts1); +extern inline void thread_state_awake (struct thread_state1 *ts1); +extern inline void thread_state_blocked (struct thread_state1 *ts1); +extern inline void thread_state_unblocked (struct thread_state1 *ts1); diff --git a/src/core/ddsi/src/q_time.c b/src/core/ddsi/src/q_time.c index e602ec0..add0d0b 100644 --- a/src/core/ddsi/src/q_time.c +++ b/src/core/ddsi/src/q_time.c @@ -11,17 +11,12 @@ */ #include -#include "os/os.h" - -#include "ddsi/q_time.h" +#include "dds/ddsrt/time.h" +#include "dds/ddsi/q_time.h" const nn_ddsi_time_t invalid_ddsi_timestamp = { -1, UINT32_MAX }; const nn_ddsi_time_t ddsi_time_infinite = { INT32_MAX, UINT32_MAX }; -#if DDSI_DURATION_ACCORDING_TO_SPEC -const nn_duration_t duration_infinite = { INT32_MAX, INT32_MAX }; -#else const nn_duration_t duration_infinite = { INT32_MAX, UINT32_MAX }; -#endif nn_wctime_t now (void) { @@ -29,10 +24,8 @@ nn_wctime_t now (void) * This clock is not affected by time spent in suspend mode. * This clock is affected when the real time system clock jumps * forwards/backwards */ - os_time tv; nn_wctime_t t; - tv = os_timeGet (); - t.v = ((int64_t) tv.tv_sec * T_SECOND + tv.tv_nsec); + t.v = dds_time(); return t; } @@ -41,10 +34,8 @@ nn_mtime_t now_mt (void) /* This function uses the monotonic clock. * This clock stops while the system is in suspend mode. * This clock is not affected by any jumps of the realtime clock. */ - os_time tv; nn_mtime_t t; - tv = os_timeGetMonotonic (); - t.v = ((int64_t) tv.tv_sec * T_SECOND + tv.tv_nsec); + t.v = ddsrt_time_monotonic(); return t; } @@ -55,30 +46,28 @@ nn_etime_t now_et (void) * This clock does NOT stop when the system is in suspend mode. * This clock stops when the system is shut down, and starts when the system is restarted. * When restarted, there are no assumptions about the initial value of clock. */ - os_time tv; nn_etime_t t; - tv = os_timeGetElapsed (); - t.v = ((int64_t) tv.tv_sec * T_SECOND + tv.tv_nsec); + t.v = ddsrt_time_elapsed(); return t; } -static void time_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ int64_t t) +static void time_to_sec_usec (int * __restrict sec, int * __restrict usec, int64_t t) { *sec = (int) (t / T_SECOND); *usec = (int) (t % T_SECOND) / 1000; } -void mtime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_mtime_t t) +void mtime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_mtime_t t) { time_to_sec_usec (sec, usec, t.v); } -void wctime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_wctime_t t) +void wctime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_wctime_t t) { time_to_sec_usec (sec, usec, t.v); } -void etime_to_sec_usec (_Out_ int * __restrict sec, _Out_ int * __restrict usec, _In_ nn_etime_t t) +void etime_to_sec_usec (int * __restrict sec, int * __restrict usec, nn_etime_t t) { time_to_sec_usec (sec, usec, t.v); } @@ -188,30 +177,6 @@ nn_wctime_t nn_wctime_from_ddsi_time (nn_ddsi_time_t x) return t; } -#if DDSI_DURATION_ACCORDING_TO_SPEC -nn_duration_t nn_to_ddsi_duration (int64_t t) -{ - if (t == T_NEVER) - return duration_infinite; - else - { - nn_duration_t x; - x.sec = (int) (t / T_SECOND); - x.nanosec = (int) (t % T_SECOND); - return x; - } -} - -int64_t nn_from_ddsi_duration (nn_duration_t x) -{ - int64_t t; - if (x.sec == duration_infinite.sec && x.nanosec == duration_infinite.nanosec) - t = T_NEVER; - else - t = x.sec * T_SECOND + x.nanosec; - return t; -} -#else nn_duration_t nn_to_ddsi_duration (int64_t x) { return nn_to_ddsi_time (x); @@ -221,4 +186,4 @@ int64_t nn_from_ddsi_duration (nn_duration_t x) { return nn_from_ddsi_time (x); } -#endif + diff --git a/src/core/ddsi/src/q_transmit.c b/src/core/ddsi/src/q_transmit.c index 1cbad3c..85d1874 100644 --- a/src/core/ddsi/src/q_transmit.c +++ b/src/core/ddsi/src/q_transmit.c @@ -12,30 +12,31 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" -#include "util/ut_avl.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_time.h" -#include "ddsi/q_config.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_error.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_hbcontrol.h" -#include "ddsi/q_static_assert.h" -#include "ddsi/ddsi_tkmap.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_sertopic.h" +#include "dds/util/ut_avl.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_hbcontrol.h" +#include "dds/ddsi/q_static_assert.h" +#include "dds/ddsi/ddsi_tkmap.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_sertopic.h" -#include "ddsi/sysdeps.h" +#include "dds/ddsi/sysdeps.h" #include "dds__whc.h" #if __STDC_VERSION__ >= 199901L @@ -723,14 +724,14 @@ static void transmit_sample_lgmsg_unlocked (struct nn_xpack *xp, struct writer * eventually we'll have to retry. But if a packet went out and we haven't yet completed transmitting a fragmented message, add a HeartbeatFrag. */ - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); ret = create_fragment_message (wr, seq, plist, serdata, i, prd, &fmsg, isnew); if (ret >= 0) { if (nfrags > 1 && i + 1 < nfrags) create_HeartbeatFrag (wr, seq, i, prd, &hmsg); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if(fmsg) nn_xpack_addmsg (xp, fmsg, 0); if(hmsg) nn_xpack_addmsg (xp, hmsg, 0); @@ -747,9 +748,9 @@ static void transmit_sample_lgmsg_unlocked (struct nn_xpack *xp, struct writer * struct nn_xmsg *msg = NULL; int hbansreq; assert (whcst != NULL); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); msg = writer_hbcontrol_piggyback (wr, whcst, serdata->twrite, nn_xpack_packetid (xp), &hbansreq); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (msg) { nn_xpack_addmsg (xp, msg, 0); @@ -771,14 +772,14 @@ static void transmit_sample_unlocks_wr (struct nn_xpack *xp, struct writer *wr, if (sz > config.fragment_size || !isnew || plist != NULL || prd != NULL) { uint32_t nfrags; - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); nfrags = (sz + config.fragment_size - 1) / config.fragment_size; transmit_sample_lgmsg_unlocked (xp, wr, whcst, seq, plist, serdata, prd, isnew, nfrags); return; } else if (create_fragment_message_simple (wr, seq, serdata, &fmsg) < 0) { - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); return; } else @@ -792,7 +793,7 @@ static void transmit_sample_unlocks_wr (struct nn_xpack *xp, struct writer *wr, else hmsg = NULL; - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); nn_xpack_addmsg (xp, fmsg, 0); if(hmsg) nn_xpack_addmsg (xp, hmsg, 0); @@ -910,7 +911,7 @@ static int writer_may_continue (const struct writer *wr, const struct whc_state } -static os_result throttle_writer (struct nn_xpack *xp, struct writer *wr) +static dds_retcode_t throttle_writer (struct nn_xpack *xp, struct writer *wr) { /* Sleep (cond_wait) without updating the thread's vtime: the garbage collector won't free the writer while we leave it @@ -946,7 +947,7 @@ static os_result throttle_writer (struct nn_xpack *xp, struct writer *wr) reader. This implicitly clears the whc and unblocks the writer. */ - os_result result = os_resultSuccess; + dds_retcode_t result = DDS_RETCODE_OK; nn_mtime_t tnow = now_mt (); const nn_mtime_t abstimeout = add_duration_to_mtime (tnow, nn_from_ddsi_duration (wr->xqos->reliability.max_blocking_time)); struct whc_state whcst; @@ -969,13 +970,13 @@ static os_result throttle_writer (struct nn_xpack *xp, struct writer *wr) if (xp) { struct nn_xmsg *hbmsg = writer_hbcontrol_create_heartbeat (wr, &whcst, tnow, 1, 1); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (hbmsg) { nn_xpack_addmsg (xp, hbmsg, 0); } nn_xpack_send (xp, true); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); whc_get_state (wr->whc, &whcst); } @@ -984,18 +985,16 @@ static os_result throttle_writer (struct nn_xpack *xp, struct writer *wr) int64_t reltimeout; tnow = now_mt (); reltimeout = abstimeout.v - tnow.v; - result = os_resultTimeout; + result = DDS_RETCODE_TIMEOUT; if (reltimeout > 0) { - os_time timeout; - timeout.tv_sec = (int32_t) (reltimeout / T_SECOND); - timeout.tv_nsec = (int32_t) (reltimeout % T_SECOND); thread_state_asleep (lookup_thread_state()); - result = os_condTimedWait (&wr->throttle_cond, &wr->e.lock, &timeout); + if (ddsrt_cond_waitfor (&wr->throttle_cond, &wr->e.lock, reltimeout)) + result = DDS_RETCODE_OK; thread_state_awake (lookup_thread_state()); whc_get_state(wr->whc, &whcst); } - if (result == os_resultTimeout) + if (result == DDS_RETCODE_TIMEOUT) { break; } @@ -1005,7 +1004,7 @@ static os_result throttle_writer (struct nn_xpack *xp, struct writer *wr) if (wr->state != WRST_OPERATIONAL) { /* gc_delete_writer may be waiting */ - os_condBroadcast (&wr->throttle_cond); + ddsrt_cond_broadcast (&wr->throttle_cond); } DDS_LOG(DDS_LC_THROTTLE, "writer %x:%x:%x:%x done waiting for whc to shrink below low-water mark (whc %"PRIuSIZE" low=%u high=%u)\n", PGUID (wr->e.guid), whcst.unacked_bytes, wr->whc_low, wr->whc_high); @@ -1055,7 +1054,7 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p goto drop; } - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); if (end_of_txn) { @@ -1068,7 +1067,7 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p whc_get_state(wr->whc, &whcst); if (whcst.unacked_bytes > wr->whc_high) { - os_result ores; + dds_retcode_t ores; assert(gc_allowed); /* also see beginning of the function */ if (config.prioritize_retransmit && wr->retransmitting) ores = throttle_writer (xp, wr); @@ -1076,13 +1075,13 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p { maybe_grow_whc (wr); if (whcst.unacked_bytes <= wr->whc_high) - ores = os_resultSuccess; + ores = DDS_RETCODE_OK; else ores = throttle_writer (xp, wr); } - if (ores == os_resultTimeout) + if (ores == DDS_RETCODE_TIMEOUT) { - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); r = ERR_TIMEOUT; goto drop; } @@ -1098,7 +1097,7 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p { if (plist == NULL) { - plist = os_malloc (sizeof (*plist)); + plist = ddsrt_malloc (sizeof (*plist)); nn_plist_init_empty (plist); } assert (!(plist->present & PP_COHERENT_SET)); @@ -1109,11 +1108,11 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p if ((r = insert_sample_in_whc (wr, seq, plist, serdata, tk)) < 0) { /* Failure of some kind */ - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); if (plist != NULL) { nn_plist_fini (plist); - os_free (plist); + ddsrt_free (plist); } } else @@ -1152,14 +1151,14 @@ static int write_sample_eot (struct nn_xpack *xp, struct writer *wr, struct nn_p if (wr->heartbeat_xevent) writer_hbcontrol_note_asyncwrite (wr, tnow); enqueue_sample_wrlock_held (wr, seq, plist, serdata, NULL, 1); - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); } /* If not actually inserted, WHC didn't take ownership of plist */ if (r == 0 && plist != NULL) { nn_plist_fini (plist); - os_free (plist); + ddsrt_free (plist); } } diff --git a/src/core/ddsi/src/q_whc.c b/src/core/ddsi/src/q_whc.c index 3be0df2..6ec4a1a 100644 --- a/src/core/ddsi/src/q_whc.c +++ b/src/core/ddsi/src/q_whc.c @@ -9,10 +9,9 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_time.h" -#include "ddsi/q_whc.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_whc.h" extern inline seqno_t whc_next_seq (const struct whc *whc, seqno_t seq); extern inline void whc_get_state (const struct whc *whc, struct whc_state *st); diff --git a/src/core/ddsi/src/q_xevent.c b/src/core/ddsi/src/q_xevent.c index e9313a4..8189c77 100644 --- a/src/core/ddsi/src/q_xevent.c +++ b/src/core/ddsi/src/q_xevent.c @@ -12,36 +12,38 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" -#include "util/ut_avl.h" -#include "util/ut_fibheap.h" +#include "dds/util/ut_avl.h" +#include "dds/util/ut_fibheap.h" -#include "ddsi/q_time.h" -#include "ddsi/q_log.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_xevent.h" -#include "ddsi/q_thread.h" -#include "ddsi/q_config.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_transmit.h" -#include "ddsi/q_error.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_bitset.h" -#include "ddsi/q_lease.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/ddsi_serdata.h" -#include "ddsi/ddsi_serdata_default.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsi/q_time.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_xevent.h" +#include "dds/ddsi/q_thread.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_transmit.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_bitset.h" +#include "dds/ddsi/q_lease.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/ddsi_serdata.h" +#include "dds/ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__whc.h" -#include "ddsi/sysdeps.h" +#include "dds/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! */ @@ -151,8 +153,8 @@ struct xeventq { size_t max_queued_rexmit_msgs; int terminate; struct thread_state1 *ts; - os_mutex lock; - os_cond cond; + ddsrt_mutex_t lock; + ddsrt_cond_t cond; ddsi_tran_conn_t tev_conn; uint32_t auxiliary_bandwidth_limit; }; @@ -238,7 +240,7 @@ static void add_to_non_timed_xmit_list (struct xeventq *evq, struct xevent_nt *e if (ev->kind == XEVK_MSG_REXMIT) remember_msg (evq, ev); - os_condSignal (&evq->cond); + ddsrt_cond_signal (&evq->cond); } static struct xevent_nt *getnext_from_non_timed_xmit_list (struct xeventq *evq) @@ -285,16 +287,16 @@ static int compute_non_timed_xmit_list_size (struct xeventq *evq) static int nontimed_xevent_in_queue (struct xeventq *evq, struct xevent_nt *ev) { struct xevent_nt *x; - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); for (x = evq->non_timed_xmit_list_oldest; x; x = x->listnode.next) { if (x == ev) { - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return 1; } } - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return 0; } #endif @@ -316,7 +318,7 @@ static void free_xevent (struct xeventq *evq, struct xevent *ev) break; } } - os_free (ev); + ddsrt_free (ev); } static void free_xevent_nt (struct xeventq *evq, struct xevent_nt *ev) @@ -336,13 +338,13 @@ static void free_xevent_nt (struct xeventq *evq, struct xevent_nt *ev) nn_xmsg_free (ev->u.entityid.msg); break; } - os_free (ev); + ddsrt_free (ev); } void delete_xevent (struct xevent *ev) { struct xeventq *evq = ev->evq; - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); /* Can delete it only once, no matter how we implement it internally */ assert (ev->tsched.v != TSCHED_DELETE); assert (TSCHED_DELETE < ev->tsched.v); @@ -358,15 +360,15 @@ void delete_xevent (struct xevent *ev) } /* TSCHED_DELETE is absolute minimum time, so chances are we need to wake up the thread. The superfluous signal is harmless. */ - os_condSignal (&evq->cond); - os_mutexUnlock (&evq->lock); + ddsrt_cond_signal (&evq->cond); + ddsrt_mutex_unlock (&evq->lock); } int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched) { struct xeventq *evq = ev->evq; int is_resched; - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); assert (tsched.v != TSCHED_DELETE); /* If you want to delete it, you to say so by calling the right function. Don't want to reschedule an event marked for deletion, @@ -391,9 +393,9 @@ int resched_xevent_if_earlier (struct xevent *ev, nn_mtime_t tsched) } is_resched = 1; if (tsched.v < tbefore.v) - os_condSignal (&evq->cond); + ddsrt_cond_signal (&evq->cond); } - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return is_resched; } @@ -401,7 +403,7 @@ static struct xevent * qxev_common (struct xeventq *evq, nn_mtime_t tsched, enum { /* qxev_common is the route by which all timed xevents are created. */ - struct xevent *ev = os_malloc (sizeof (*ev)); + struct xevent *ev = ddsrt_malloc (sizeof (*ev)); assert (tsched.v != TSCHED_DELETE); ASSERT_MUTEX_HELD (&evq->lock); @@ -423,7 +425,7 @@ static struct xevent * qxev_common (struct xeventq *evq, nn_mtime_t tsched, enum static struct xevent_nt *qxev_common_nt (struct xeventq *evq, enum xeventkind_nt kind) { /* qxev_common_nt is the route by which all non-timed xevents are created. */ - struct xevent_nt *ev = os_malloc (sizeof (*ev)); + struct xevent_nt *ev = ddsrt_malloc (sizeof (*ev)); ev->evq = evq; ev->kind = kind; return ev; @@ -453,7 +455,7 @@ static void qxev_insert (struct xevent *ev) nn_mtime_t tbefore = earliest_in_xeventq (evq); ut_fibheapInsert (&evq_xevents_fhdef, &evq->xevents, ev); if (ev->tsched.v < tbefore.v) - os_condSignal (&evq->cond); + ddsrt_cond_signal (&evq->cond); } } @@ -479,7 +481,7 @@ struct xeventq * xeventq_new uint32_t auxiliary_bandwidth_limit ) { - struct xeventq *evq = os_malloc (sizeof (*evq)); + struct xeventq *evq = ddsrt_malloc (sizeof (*evq)); /* limit to 2GB to prevent overflow (4GB - 64kB should be ok, too) */ if (max_queued_rexmit_bytes > 2147483648u) max_queued_rexmit_bytes = 2147483648u; @@ -495,8 +497,8 @@ struct xeventq * xeventq_new evq->queued_rexmit_bytes = 0; evq->queued_rexmit_msgs = 0; evq->tev_conn = conn; - os_mutexInit (&evq->lock); - os_condInit (&evq->cond, &evq->lock); + ddsrt_mutex_init (&evq->lock); + ddsrt_cond_init (&evq->cond); return evq; } @@ -508,7 +510,7 @@ int xeventq_start (struct xeventq *evq, const char *name) if (name) { size_t slen = strlen (name) + 5; - evqname = os_malloc (slen); + evqname = ddsrt_malloc (slen); (void) snprintf (evqname, slen, "tev.%s", name); } @@ -517,7 +519,7 @@ int xeventq_start (struct xeventq *evq, const char *name) if (name) { - os_free (evqname); + ddsrt_free (evqname); } return (evq->ts == NULL) ? ERR_UNSPECIFIED : 0; } @@ -525,10 +527,10 @@ int xeventq_start (struct xeventq *evq, const char *name) void xeventq_stop (struct xeventq *evq) { assert (evq->ts != NULL); - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); evq->terminate = 1; - os_condSignal (&evq->cond); - os_mutexUnlock (&evq->lock); + ddsrt_cond_signal (&evq->cond); + ddsrt_mutex_unlock (&evq->lock); join_thread (evq->ts); evq->ts = NULL; } @@ -557,9 +559,9 @@ void xeventq_free (struct xeventq *evq) while (!non_timed_xmit_list_is_empty(evq)) free_xevent_nt (evq, getnext_from_non_timed_xmit_list (evq)); assert (ut_avlIsEmpty (&evq->msg_xevents)); - os_condDestroy (&evq->cond); - os_mutexDestroy (&evq->lock); - os_free (evq); + ddsrt_cond_destroy (&evq->cond); + ddsrt_mutex_destroy (&evq->lock); + ddsrt_free (evq); } /* EVENT QUEUE EVENT HANDLERS ******************************************************/ @@ -580,9 +582,9 @@ static void handle_xevk_msg_rexmit (struct nn_xpack *xp, struct xevent_nt *ev) /* FIXME: less than happy about having to relock the queue for a little while here */ - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); update_rexmit_counts (evq, ev); - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); } static void handle_xevk_entityid (struct nn_xpack *xp, struct xevent_nt *ev) @@ -607,7 +609,7 @@ static void handle_xevk_heartbeat (struct nn_xpack *xp, struct xevent *ev, nn_mt } assert (wr->reliable); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); whc_get_state(wr->whc, &whcst); if (!writer_must_have_hb_scheduled (wr, &whcst)) { @@ -638,7 +640,7 @@ static void handle_xevk_heartbeat (struct nn_xpack *xp, struct xevent *ev, nn_mt whcst.max_seq, READ_SEQ_XMIT(wr)); resched_xevent_if_earlier (ev, t_next); wr->hbcontrol.tsched = t_next; - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); /* Can't transmit synchronously with writer lock held: trying to add the heartbeat to the xp may cause xp to be sent out, which may @@ -691,7 +693,7 @@ static seqno_t next_deliv_seq (const struct proxy_writer *pwr, const seqno_t nex FIXME: next_seq - #dqueue could probably be used instead, provided #dqueue is decremented after delivery, rather than before delivery. */ - const uint32_t lw = os_atomic_ld32 (&pwr->next_deliv_seq_lowword); + const uint32_t lw = ddsrt_atomic_ld32 (&pwr->next_deliv_seq_lowword); seqno_t next_deliv_seq; next_deliv_seq = (next_seq & ~(seqno_t) UINT32_MAX) | lw; if (next_deliv_seq > next_seq) @@ -884,10 +886,10 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent return; } - os_mutexLock (&pwr->e.lock); + ddsrt_mutex_lock (&pwr->e.lock); if ((rwn = ut_avlLookup (&pwr_readers_treedef, &pwr->readers, &ev->u.acknack.rd_guid)) == NULL) { - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); return; } @@ -945,7 +947,7 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent intv = 10; resched_xevent_if_earlier (ev, add_duration_to_mtime (tnow, intv * T_SECOND)); } - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); /* nn_xpack_addmsg may sleep (for bandwidth-limited channels), so must be outside the lock */ @@ -955,7 +957,7 @@ static void handle_xevk_acknack (UNUSED_ARG (struct nn_xpack *xp), struct xevent outofmem: /* What to do if out of memory? Crash or burn? */ - os_mutexUnlock (&pwr->e.lock); + ddsrt_mutex_unlock (&pwr->e.lock); resched_xevent_if_earlier (ev, add_duration_to_mtime (tnow, 100 * T_MILLISECOND)); } @@ -979,7 +981,7 @@ static bool resend_spdp_sample_by_guid_key (struct writer *wr, const nn_guid_t * struct whc_borrowed_sample sample; nn_xmsg_free (mpayload); - os_mutexLock (&wr->e.lock); + ddsrt_mutex_lock (&wr->e.lock); sample_found = whc_borrow_sample_key (wr->whc, sd, &sample); if (sample_found) { @@ -991,7 +993,7 @@ static bool resend_spdp_sample_by_guid_key (struct writer *wr, const nn_guid_t * enqueue_sample_wrlock_held (wr, sample.seq, sample.plist, sample.serdata, prd, 1); whc_return_sample(wr->whc, &sample, false); } - os_mutexUnlock (&wr->e.lock); + ddsrt_mutex_unlock (&wr->e.lock); ddsi_serdata_unref (sd); return sample_found; } @@ -1054,11 +1056,11 @@ static void handle_xevk_spdp (UNUSED_ARG (struct nn_xpack *xp), struct xevent *e happen shortly. */ if (!ev->u.spdp.directed) { - os_mutexLock (&pp->e.lock); - os_mutexLock (&ev->evq->lock); + ddsrt_mutex_lock (&pp->e.lock); + ddsrt_mutex_lock (&ev->evq->lock); assert (ev->tsched.v == TSCHED_DELETE); - os_mutexUnlock (&ev->evq->lock); - os_mutexUnlock (&pp->e.lock); + ddsrt_mutex_unlock (&ev->evq->lock); + ddsrt_mutex_unlock (&pp->e.lock); } else { @@ -1168,7 +1170,7 @@ static void handle_xevk_pmd_update (struct nn_xpack *xp, struct xevent *ev, nn_m lock pp for reading out the lease duration we are guaranteed a consistent value (can't assume 64-bit atomic reads on all support platforms!) */ - os_mutexLock (&pp->e.lock); + ddsrt_mutex_lock (&pp->e.lock); intv = pp->lease_duration; /* FIXME: need to use smallest liveliness duration of all automatic-liveliness writers */ @@ -1189,7 +1191,7 @@ static void handle_xevk_pmd_update (struct nn_xpack *xp, struct xevent *ev, nn_m } resched_xevent_if_earlier (ev, tnext); - os_mutexUnlock (&pp->e.lock); + ddsrt_mutex_unlock (&pp->e.lock); } static void handle_xevk_end_startup_mode (UNUSED_ARG (struct nn_xpack *xp), struct xevent *ev, UNUSED_ARG (nn_mtime_t tnow)) @@ -1257,7 +1259,7 @@ static void handle_individual_xevent_nt (struct xevent_nt *xev, struct nn_xpack handle_xevk_entityid (xp, xev); break; } - os_free (xev); + ddsrt_free (xev); } static void handle_timed_xevent (struct thread_state1 *self, struct xevent *xev, struct nn_xpack *xp, nn_mtime_t tnow /* monotonic */) @@ -1273,10 +1275,10 @@ static void handle_timed_xevent (struct thread_state1 *self, struct xevent *xev, assert (xev->evq == xevq); assert (xev->tsched.v != TSCHED_DELETE); - os_mutexUnlock (&xevq->lock); + ddsrt_mutex_unlock (&xevq->lock); thread_state_awake (self); handle_individual_xevent (xev, xp, tnow /* monotonic */); - os_mutexLock (&xevq->lock); + ddsrt_mutex_lock (&xevq->lock); ASSERT_MUTEX_HELD (&xevq->lock); } @@ -1293,11 +1295,11 @@ static void handle_nontimed_xevent (struct thread_state1 *self, struct xevent_nt assert (xev->evq == xevq); - os_mutexUnlock (&xevq->lock); + ddsrt_mutex_unlock (&xevq->lock); thread_state_awake (self); handle_individual_xevent_nt (xev, xp); /* non-timed xevents are freed by the handlers */ - os_mutexLock (&xevq->lock); + ddsrt_mutex_lock (&xevq->lock); ASSERT_MUTEX_HELD (&xevq->lock); } @@ -1363,7 +1365,7 @@ static uint32_t xevent_thread (struct xeventq * xevq) xp = nn_xpack_new (xevq->tev_conn, xevq->auxiliary_bandwidth_limit, config.xpack_send_async); - os_mutexLock (&xevq->lock); + ddsrt_mutex_lock (&xevq->lock); while (!xevq->terminate) { nn_mtime_t tnow = now_mt (); @@ -1374,9 +1376,9 @@ static uint32_t xevent_thread (struct xeventq * xevq) /* Send to the network unlocked, as it may sleep due to bandwidth limitation */ - os_mutexUnlock (&xevq->lock); + ddsrt_mutex_unlock (&xevq->lock); nn_xpack_send (xp, false); - os_mutexLock (&xevq->lock); + ddsrt_mutex_lock (&xevq->lock); thread_state_asleep (self); @@ -1390,7 +1392,7 @@ static uint32_t xevent_thread (struct xeventq * xevq) if (twakeup.v == T_NEVER) { /* no scheduled events nor any non-timed events */ - os_condWait (&xevq->cond, &xevq->lock); + ddsrt_cond_wait (&xevq->cond, &xevq->lock); } else { @@ -1401,16 +1403,13 @@ static uint32_t xevent_thread (struct xeventq * xevq) tnow = now_mt (); if (twakeup.v > tnow.v) { - os_time to; - twakeup.v -= tnow.v; /* os_condTimedWait: relative timeout */ - to.tv_sec = (int) (twakeup.v / 1000000000); - to.tv_nsec = (int32_t) (twakeup.v % 1000000000); - os_condTimedWait (&xevq->cond, &xevq->lock, &to); + twakeup.v -= tnow.v; /* ddsrt_cond_waitfor: relative timeout */ + ddsrt_cond_waitfor (&xevq->cond, &xevq->lock, twakeup.v); } } } } - os_mutexUnlock (&xevq->lock); + ddsrt_mutex_unlock (&xevq->lock); nn_xpack_send (xp, false); nn_xpack_free (xp); return 0; @@ -1421,11 +1420,11 @@ void qxev_msg (struct xeventq *evq, struct nn_xmsg *msg) struct xevent_nt *ev; assert (evq); assert (nn_xmsg_kind (msg) != NN_XMSG_KIND_DATA_REXMIT); - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); ev = qxev_common_nt (evq, XEVK_MSG); ev->u.msg.msg = msg; qxev_insert_nt (ev); - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); } void qxev_prd_entityid (struct proxy_reader * prd, nn_guid_prefix_t * id) @@ -1442,11 +1441,11 @@ void qxev_prd_entityid (struct proxy_reader * prd, nn_guid_prefix_t * id) { DDS_TRACE(" qxev_prd_entityid (%x:%x:%x)\n", PGUIDPREFIX (*id)); nn_xmsg_add_entityid (msg); - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common_nt (gv.xevents, XEVK_ENTITYID); ev->u.entityid.msg = msg; qxev_insert_nt (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); } else { @@ -1469,11 +1468,11 @@ void qxev_pwr_entityid (struct proxy_writer * pwr, nn_guid_prefix_t * id) { DDS_TRACE(" qxev_pwr_entityid (%x:%x:%x)\n", PGUIDPREFIX (*id)); nn_xmsg_add_entityid (msg); - os_mutexLock (&pwr->evq->lock); + ddsrt_mutex_lock (&pwr->evq->lock); ev = qxev_common_nt (pwr->evq, XEVK_ENTITYID); ev->u.entityid.msg = msg; qxev_insert_nt (ev); - os_mutexUnlock (&pwr->evq->lock); + ddsrt_mutex_unlock (&pwr->evq->lock); } else { @@ -1489,11 +1488,11 @@ int qxev_msg_rexmit_wrlock_held (struct xeventq *evq, struct nn_xmsg *msg, int f assert (evq); assert (nn_xmsg_kind (msg) == NN_XMSG_KIND_DATA_REXMIT); - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); if ((ev = lookup_msg (evq, msg)) != NULL && nn_xmsg_merge_rexmit_destinations_wrlock_held (ev->u.msg_rexmit.msg, msg)) { /* MSG got merged with a pending retransmit, so it has effectively been queued */ - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); nn_xmsg_free (msg); return 1; } @@ -1502,7 +1501,7 @@ int qxev_msg_rexmit_wrlock_held (struct xeventq *evq, struct nn_xmsg *msg, int f !force) { /* drop it if insufficient resources available */ - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); nn_xmsg_free (msg); #if 0 DDS_TRACE(" qxev_msg_rexmit%s drop (sz %"PA_PRIuSIZE" qb %"PA_PRIuSIZE" qm %"PA_PRIuSIZE")", force ? "!" : "", @@ -1521,7 +1520,7 @@ int qxev_msg_rexmit_wrlock_held (struct xeventq *evq, struct nn_xmsg *msg, int f #if 0 DDS_TRACE("AAA(%p,%"PA_PRIuSIZE")", (void *) ev, msg_size); #endif - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return 2; } } @@ -1533,11 +1532,11 @@ struct xevent *qxev_heartbeat (struct xeventq *evq, nn_mtime_t tsched, const nn_ wr->heartbeat_xevent. */ struct xevent *ev; assert(evq); - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); ev = qxev_common (evq, tsched, XEVK_HEARTBEAT); ev->u.heartbeat.wr_guid = *wr_guid; qxev_insert (ev); - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return ev; } @@ -1545,19 +1544,19 @@ struct xevent *qxev_acknack (struct xeventq *evq, nn_mtime_t tsched, const nn_gu { struct xevent *ev; assert(evq); - os_mutexLock (&evq->lock); + ddsrt_mutex_lock (&evq->lock); ev = qxev_common (evq, tsched, XEVK_ACKNACK); ev->u.acknack.pwr_guid = *pwr_guid; ev->u.acknack.rd_guid = *rd_guid; qxev_insert (ev); - os_mutexUnlock (&evq->lock); + ddsrt_mutex_unlock (&evq->lock); return ev; } struct xevent *qxev_spdp (nn_mtime_t tsched, const nn_guid_t *pp_guid, const nn_guid_t *dest_proxypp_guid) { struct xevent *ev; - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common (gv.xevents, tsched, XEVK_SPDP); ev->u.spdp.pp_guid = *pp_guid; if (dest_proxypp_guid == NULL) @@ -1568,50 +1567,50 @@ struct xevent *qxev_spdp (nn_mtime_t tsched, const nn_guid_t *pp_guid, const nn_ ev->u.spdp.directed = 4; } qxev_insert (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); return ev; } struct xevent *qxev_pmd_update (nn_mtime_t tsched, const nn_guid_t *pp_guid) { struct xevent *ev; - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common (gv.xevents, tsched, XEVK_PMD_UPDATE); ev->u.pmd_update.pp_guid = *pp_guid; qxev_insert (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); return ev; } struct xevent *qxev_end_startup_mode (nn_mtime_t tsched) { struct xevent *ev; - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common (gv.xevents, tsched, XEVK_END_STARTUP_MODE); qxev_insert (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); return ev; } struct xevent *qxev_delete_writer (nn_mtime_t tsched, const nn_guid_t *guid) { struct xevent *ev; - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common (gv.xevents, tsched, XEVK_DELETE_WRITER); ev->u.delete_writer.guid = *guid; qxev_insert (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); return ev; } struct xevent *qxev_callback (nn_mtime_t tsched, void (*cb) (struct xevent *ev, void *arg, nn_mtime_t tnow), void *arg) { struct xevent *ev; - os_mutexLock (&gv.xevents->lock); + ddsrt_mutex_lock (&gv.xevents->lock); ev = qxev_common (gv.xevents, tsched, XEVK_CALLBACK); ev->u.callback.cb = cb; ev->u.callback.arg = arg; qxev_insert (ev); - os_mutexUnlock (&gv.xevents->lock); + ddsrt_mutex_unlock (&gv.xevents->lock); return ev; } diff --git a/src/core/ddsi/src/q_xmsg.c b/src/core/ddsi/src/q_xmsg.c index 9946ed3..6f6d11d 100644 --- a/src/core/ddsi/src/q_xmsg.c +++ b/src/core/ddsi/src/q_xmsg.c @@ -19,27 +19,29 @@ #include /* for IOV_MAX */ #endif -#include "os/os.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/random.h" -#include "util/ut_avl.h" -#include "util/ut_thread_pool.h" +#include "dds/util/ut_avl.h" +#include "dds/util/ut_thread_pool.h" -#include "ddsi/q_protocol.h" -#include "ddsi/q_xqos.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_rtps.h" -#include "ddsi/q_addrset.h" -#include "ddsi/q_error.h" -#include "ddsi/q_misc.h" -#include "ddsi/q_log.h" -#include "ddsi/q_unused.h" -#include "ddsi/q_xmsg.h" -#include "ddsi/q_config.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_ephash.h" -#include "ddsi/q_freelist.h" -#include "ddsi/ddsi_serdata_default.h" +#include "dds/ddsi/q_protocol.h" +#include "dds/ddsi/q_xqos.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_rtps.h" +#include "dds/ddsi/q_addrset.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_misc.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_unused.h" +#include "dds/ddsi/q_xmsg.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_ephash.h" +#include "dds/ddsi/q_freelist.h" +#include "dds/ddsi/ddsi_serdata_default.h" #define NN_XMSG_MAX_ALIGN 8 #define NN_XMSG_CHUNK_SIZE 128 @@ -70,7 +72,7 @@ struct nn_xmsg { size_t sz; int have_params; struct ddsi_serdata *refd_payload; - os_iovec_t refd_payload_iov; + ddsrt_iovec_t refd_payload_iov; int64_t maxdelay; #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS uint32_t encoderid; @@ -140,43 +142,47 @@ struct nn_bw_limiter { #endif /////////////////////////// -typedef struct os_sem { - os_mutex mtx; +typedef struct { + ddsrt_mutex_t mtx; uint32_t value; - os_cond cv; -} os_sem_t; + ddsrt_cond_t cv; +} ddsi_sem_t; -static os_result os_sem_init (os_sem_t * sem, uint32_t value) +dds_retcode_t +ddsi_sem_init (ddsi_sem_t *sem, uint32_t value) { sem->value = value; - os_mutexInit (&sem->mtx); - os_condInit (&sem->cv, &sem->mtx); - return os_resultSuccess; + ddsrt_mutex_init (&sem->mtx); + ddsrt_cond_init (&sem->cv); + return DDS_RETCODE_OK; } -static os_result os_sem_destroy (os_sem_t *sem) +dds_retcode_t +ddsi_sem_destroy (ddsi_sem_t *sem) { - os_condDestroy (&sem->cv); - os_mutexDestroy (&sem->mtx); - return os_resultSuccess; + ddsrt_cond_destroy (&sem->cv); + ddsrt_mutex_destroy (&sem->mtx); + return DDS_RETCODE_OK; } -static os_result os_sem_post (os_sem_t *sem) +dds_retcode_t +ddsi_sem_post (ddsi_sem_t *sem) { - os_mutexLock (&sem->mtx); + ddsrt_mutex_lock (&sem->mtx); if (sem->value++ == 0) - os_condSignal (&sem->cv); - os_mutexUnlock (&sem->mtx); - return os_resultSuccess; + ddsrt_cond_signal (&sem->cv); + ddsrt_mutex_unlock (&sem->mtx); + return DDS_RETCODE_OK; } -static os_result os_sem_wait (os_sem_t *sem) +dds_retcode_t +ddsi_sem_wait (ddsi_sem_t *sem) { - os_mutexLock (&sem->mtx); + ddsrt_mutex_lock (&sem->mtx); while (sem->value == 0) - os_condWait (&sem->cv, &sem->mtx); - os_mutexUnlock (&sem->mtx); - return os_resultSuccess; + ddsrt_cond_wait (&sem->cv, &sem->mtx); + ddsrt_mutex_unlock (&sem->mtx); + return DDS_RETCODE_OK; } /////////////////////////// @@ -190,12 +196,12 @@ struct nn_xpack InfoDST_t *last_dst; int64_t maxdelay; unsigned packetid; - os_atomic_uint32_t calls; + ddsrt_atomic_uint32_t calls; uint32_t call_flags; ddsi_tran_conn_t conn; - os_sem_t sem; + ddsi_sem_t sem; size_t niov; - os_iovec_t iov[NN_XMSG_MAX_MESSAGE_IOVECS]; + ddsrt_iovec_t iov[NN_XMSG_MAX_MESSAGE_IOVECS]; enum nn_xmsg_dstmode dstmode; union @@ -240,7 +246,7 @@ static void nn_xmsg_realfree (struct nn_xmsg *m); struct nn_xmsgpool *nn_xmsgpool_new (void) { struct nn_xmsgpool *pool; - pool = os_malloc (sizeof (*pool)); + pool = ddsrt_malloc (sizeof (*pool)); nn_freelist_init (&pool->freelist, UINT32_MAX, offsetof (struct nn_xmsg, link.older)); return pool; } @@ -254,7 +260,7 @@ void nn_xmsgpool_free (struct nn_xmsgpool *pool) { nn_freelist_fini (&pool->freelist, nn_xmsg_realfree_wrap); DDS_TRACE("xmsgpool_free(%p)\n", (void *)pool); - os_free (pool); + ddsrt_free (pool); } /* XMSG ---------------------------------------------------------------- @@ -294,26 +300,26 @@ static struct nn_xmsg *nn_xmsg_allocnew (struct nn_xmsgpool *pool, size_t expect if (expected_size == 0) expected_size = NN_XMSG_CHUNK_SIZE; - if ((m = os_malloc (sizeof (*m))) == NULL) + if ((m = ddsrt_malloc (sizeof (*m))) == NULL) return NULL; m->pool = pool; m->maxsz = (expected_size + NN_XMSG_CHUNK_SIZE - 1) & (unsigned)-NN_XMSG_CHUNK_SIZE; - if ((d = m->data = os_malloc (offsetof (struct nn_xmsg_data, payload) + m->maxsz)) == NULL) + if ((d = m->data = ddsrt_malloc (offsetof (struct nn_xmsg_data, payload) + m->maxsz)) == NULL) { - os_free (m); + ddsrt_free (m); return NULL; } d->src.smhdr.submessageId = SMID_INFO_SRC; - d->src.smhdr.flags = (PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); + d->src.smhdr.flags = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); d->src.smhdr.octetsToNextHeader = sizeof (d->src) - (offsetof (InfoSRC_t, smhdr.octetsToNextHeader) + 2); d->src.unused = 0; d->src.version.major = RTPS_MAJOR; d->src.version.minor = RTPS_MINOR; d->src.vendorid = NN_VENDORID_ECLIPSE; d->dst.smhdr.submessageId = SMID_INFO_DST; - d->dst.smhdr.flags = (PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); + d->dst.smhdr.flags = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); d->dst.smhdr.octetsToNextHeader = sizeof (d->dst.guid_prefix); nn_xmsg_reinit (m, kind); return m; @@ -332,8 +338,8 @@ struct nn_xmsg *nn_xmsg_new (struct nn_xmsgpool *pool, const nn_guid_prefix_t *s static void nn_xmsg_realfree (struct nn_xmsg *m) { - os_free (m->data); - os_free (m); + ddsrt_free (m->data); + ddsrt_free (m); } void nn_xmsg_free (struct nn_xmsg *m) @@ -475,7 +481,7 @@ void nn_xmsg_submsg_init (struct nn_xmsg *msg, struct nn_xmsg_marker marker, Sub SubmessageHeader_t *hdr = (SubmessageHeader_t *) (msg->data->payload + marker.offset); assert (submsg_is_compatible (msg, smkind)); hdr->submessageId = (unsigned char)smkind; - hdr->flags = PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0; + hdr->flags = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); hdr->octetsToNextHeader = 0; } @@ -515,7 +521,7 @@ void * nn_xmsg_append (struct nn_xmsg *m, struct nn_xmsg_marker *marker, size_t if (m->sz + sz > m->maxsz) { size_t nmax = (m->maxsz + sz + NN_XMSG_CHUNK_SIZE - 1) & (size_t)-NN_XMSG_CHUNK_SIZE; - struct nn_xmsg_data *ndata = os_realloc (m->data, offsetof (struct nn_xmsg_data, payload) + nmax); + struct nn_xmsg_data *ndata = ddsrt_realloc (m->data, offsetof (struct nn_xmsg_data, payload) + nmax); m->maxsz = nmax; m->data = ndata; } @@ -752,7 +758,7 @@ void nn_xmsg_setwriterseq_fragid (struct nn_xmsg *msg, const nn_guid_t *wrguid, msg->kindspecific.data.wrfragid = wrfragid; } -size_t nn_xmsg_add_string_padded(_Inout_opt_ unsigned char *buf, _In_ char *str) +size_t nn_xmsg_add_string_padded(unsigned char *buf, char *str) { size_t len = strlen (str) + 1; assert (len <= UINT32_MAX); @@ -771,7 +777,7 @@ size_t nn_xmsg_add_string_padded(_Inout_opt_ unsigned char *buf, _In_ char *str) return len; } -size_t nn_xmsg_add_octseq_padded(_Inout_opt_ unsigned char *buf, _In_ nn_octetseq_t *seq) +size_t nn_xmsg_add_octseq_padded(unsigned char *buf, nn_octetseq_t *seq) { unsigned len = seq->length; if (buf) { @@ -788,50 +794,6 @@ size_t nn_xmsg_add_octseq_padded(_Inout_opt_ unsigned char *buf, _In_ nn_octetse align4u(len); /* seqlen + possible padding */ } - -size_t nn_xmsg_add_dataholder_padded (_Inout_opt_ unsigned char *buf, const struct nn_dataholder *dh) -{ - unsigned i; - size_t len; - unsigned dummy = 0; - unsigned *cnt = &dummy; - - len = nn_xmsg_add_string_padded(buf, dh->class_id); - - if (buf) { - cnt = ((unsigned *)&(buf[len])); - *cnt = 0; - } - len += sizeof(int); - for (i = 0; i < dh->properties.n; i++) { - nn_property_t *p = &(dh->properties.props[i]); - if (p->propagate) { - len += nn_xmsg_add_string_padded(buf ? &(buf[len]) : NULL, p->name); - len += nn_xmsg_add_string_padded(buf ? &(buf[len]) : NULL, p->value); - (*cnt)++; - } - /* p->propagate is not propagated over the wire. */ - } - - if (buf) { - cnt = ((unsigned *)&(buf[len])); - *cnt = 0; - } - len += sizeof(int); - for (i = 0; i < dh->binary_properties.n; i++) { - nn_binaryproperty_t *p = &(dh->binary_properties.props[i]); - if (p->propagate) { - len += nn_xmsg_add_string_padded(buf ? &(buf[len]) : NULL, p->name ); - len += nn_xmsg_add_octseq_padded(buf ? &(buf[len]) : NULL, &(p->value)); - (*cnt)++; - } - /* p->propagate is not propagated over the wire. */ - } - - return len; -} - - void * nn_xmsg_addpar (struct nn_xmsg *m, unsigned pid, size_t len) { const size_t len4 = (len + 3) & (size_t)-4; /* must alloc a multiple of 4 */ @@ -1079,21 +1041,6 @@ void nn_xmsg_addpar_eotinfo (struct nn_xmsg *m, unsigned pid, const struct nn_pr } } -void nn_xmsg_addpar_dataholder (_In_ struct nn_xmsg *m, _In_ unsigned pid, _In_ const struct nn_dataholder *dh) -{ - unsigned char *tmp; - size_t len; - - /* Get total payload length. */ - len = nn_xmsg_add_dataholder_padded(NULL, dh); - - /* Prepare parameter header and get payload pointer. */ - tmp = nn_xmsg_addpar (m, pid, 4 + len); - - /* Insert dataholder. */ - nn_xmsg_add_dataholder_padded(tmp, dh); -} - /* XMSG_CHAIN ---------------------------------------------------------- Xpacks refer to xmsgs and need to release these after having been @@ -1188,12 +1135,9 @@ static void nn_bw_limit_sleep_if_needed(struct nn_bw_limiter* this, ssize_t size else if ( this->balance > NN_BW_LIMIT_MIN_SLEEP ) { /* We're over the bandwidth limit far enough, to warrent a sleep. */ - os_time delay; DDS_TRACE(":%"PRId64":sleep",this->balance/1000); - delay.tv_sec = (int32_t) (this->balance / T_SECOND); - delay.tv_nsec = (int32_t) (this->balance % T_SECOND); thread_state_blocked (lookup_thread_state ()); - os_nanoSleep (delay); + dds_sleepfor (this->balance); thread_state_unblocked (lookup_thread_state ()); } else @@ -1244,7 +1188,7 @@ struct nn_xpack * nn_xpack_new (ddsi_tran_conn_t conn, uint32_t bw_limit, bool a can avoid starting the async send thread altogether */ assert (!async_mode || config.xpack_send_async); - xp = os_malloc (sizeof (*xp)); + xp = ddsrt_malloc (sizeof (*xp)); memset (xp, 0, sizeof (*xp)); xp->async_mode = async_mode; @@ -1260,21 +1204,21 @@ struct nn_xpack * nn_xpack_new (ddsi_tran_conn_t conn, uint32_t bw_limit, bool a /* MSG_LEN first sub message for stream based connections */ xp->msg_len.smhdr.submessageId = SMID_PT_MSG_LEN; - xp->msg_len.smhdr.flags = (PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); + xp->msg_len.smhdr.flags = (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); xp->msg_len.smhdr.octetsToNextHeader = 4; xp->conn = conn; nn_xpack_reinit (xp); if (gv.thread_pool) - os_sem_init (&xp->sem, 0); + ddsi_sem_init (&xp->sem, 0); #ifdef DDSI_INCLUDE_ENCRYPTION if (q_security_plugin.new_encoder) { xp->codec = (q_security_plugin.new_encoder) (); xp->SecurityHeader.smhdr.submessageId = SMID_PT_INFO_CONTAINER; - xp->SecurityHeader.smhdr.flags = PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0;; + xp->SecurityHeader.smhdr.flags = (DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0); xp->SecurityHeader.smhdr.octetsToNextHeader = 4; xp->SecurityHeader.id = PTINFO_ID_ENCRYPT; } @@ -1298,8 +1242,8 @@ void nn_xpack_free (struct nn_xpack *xp) } #endif if (gv.thread_pool) - os_sem_destroy (&xp->sem); - os_free (xp); + ddsi_sem_destroy (&xp->sem); + ddsrt_free (xp); } static ssize_t nn_xpack_send1 (const nn_locator_t *loc, void * varg) @@ -1317,7 +1261,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 ((os_random () % 1000) < config.xmit_lossiness) + if ((ddsrt_random () % 1000) < config.xmit_lossiness) { DDS_TRACE("(dropped)"); xp->call_flags = 0; @@ -1383,19 +1327,19 @@ static void nn_xpack_send1_thread (void * varg) { nn_xpack_send1_thread_arg_t arg = varg; (void) nn_xpack_send1 (arg->loc, arg->xp); - if (os_atomic_dec32_ov (&arg->xp->calls) == 1) + if (ddsrt_atomic_dec32_ov (&arg->xp->calls) == 1) { - os_sem_post (&arg->xp->sem); + ddsi_sem_post (&arg->xp->sem); } - os_free (varg); + ddsrt_free (varg); } static void nn_xpack_send1_threaded (const nn_locator_t *loc, void * varg) { - nn_xpack_send1_thread_arg_t arg = os_malloc (sizeof (*arg)); + nn_xpack_send1_thread_arg_t arg = ddsrt_malloc (sizeof (*arg)); arg->xp = (struct nn_xpack *) varg; arg->loc = loc; - os_atomic_inc32 (&arg->xp->calls); + ddsrt_atomic_inc32 (&arg->xp->calls); ut_thread_pool_submit (gv.thread_pool, nn_xpack_send1_thread, arg); } @@ -1442,14 +1386,14 @@ static void nn_xpack_send_real (struct nn_xpack * xp) } else { - os_atomic_st32 (&xp->calls, 1); + ddsrt_atomic_st32 (&xp->calls, 1); calls = addrset_forall_count (xp->dstaddr.all.as, nn_xpack_send1_threaded, xp); /* Wait for the thread pool to complete the write; if we're the one decrementing "calls" to 0, all of the work has been completed and none of the threads will be posting; else some thread will be posting it and we had better wait for it */ - if (os_atomic_dec32_ov (&xp->calls) != 1) - os_sem_wait (&xp->sem); + if (ddsrt_atomic_dec32_ov (&xp->calls) != 1) + ddsi_sem_wait (&xp->sem); } unref_addrset (xp->dstaddr.all.as); } @@ -1480,27 +1424,26 @@ static void nn_xpack_send_real (struct nn_xpack * xp) static uint32_t nn_xpack_sendq_thread (UNUSED_ARG (void *arg)) { - os_mutexLock (&gv.sendq_lock); + ddsrt_mutex_lock (&gv.sendq_lock); while (!(gv.sendq_stop && gv.sendq_head == NULL)) { struct nn_xpack *xp; if ((xp = gv.sendq_head) == NULL) { - os_time to = { 0, 1000000 }; - os_condTimedWait (&gv.sendq_cond, &gv.sendq_lock, &to); + ddsrt_cond_waitfor (&gv.sendq_cond, &gv.sendq_lock, 1000000); } else { gv.sendq_head = xp->sendq_next; if (--gv.sendq_length == SENDQ_LW) - os_condBroadcast (&gv.sendq_cond); - os_mutexUnlock (&gv.sendq_lock); + ddsrt_cond_broadcast (&gv.sendq_cond); + ddsrt_mutex_unlock (&gv.sendq_lock); nn_xpack_send_real (xp); nn_xpack_free (xp); - os_mutexLock (&gv.sendq_lock); + ddsrt_mutex_lock (&gv.sendq_lock); } } - os_mutexUnlock (&gv.sendq_lock); + ddsrt_mutex_unlock (&gv.sendq_lock); return 0; } @@ -1510,8 +1453,8 @@ void nn_xpack_sendq_init (void) gv.sendq_head = NULL; gv.sendq_tail = NULL; gv.sendq_length = 0; - os_mutexInit (&gv.sendq_lock); - os_condInit (&gv.sendq_cond, &gv.sendq_lock); + ddsrt_mutex_init (&gv.sendq_lock); + ddsrt_cond_init (&gv.sendq_cond); } void nn_xpack_sendq_start (void) @@ -1521,18 +1464,18 @@ void nn_xpack_sendq_start (void) void nn_xpack_sendq_stop (void) { - os_mutexLock (&gv.sendq_lock); + ddsrt_mutex_lock (&gv.sendq_lock); gv.sendq_stop = 1; - os_condBroadcast (&gv.sendq_cond); - os_mutexUnlock (&gv.sendq_lock); + ddsrt_cond_broadcast (&gv.sendq_cond); + ddsrt_mutex_unlock (&gv.sendq_lock); } void nn_xpack_sendq_fini (void) { assert (gv.sendq_head == NULL); join_thread(gv.sendq_ts); - os_condDestroy(&gv.sendq_cond); - os_mutexDestroy(&gv.sendq_lock); + ddsrt_cond_destroy(&gv.sendq_cond); + ddsrt_mutex_destroy(&gv.sendq_lock); } void nn_xpack_send (struct nn_xpack *xp, bool immediately) @@ -1543,17 +1486,17 @@ void nn_xpack_send (struct nn_xpack *xp, bool immediately) } else { - struct nn_xpack *xp1 = os_malloc (sizeof (*xp)); + struct nn_xpack *xp1 = ddsrt_malloc (sizeof (*xp)); memcpy (xp1, xp, sizeof (*xp1)); nn_xpack_reinit (xp); xp1->sendq_next = NULL; - os_mutexLock (&gv.sendq_lock); + ddsrt_mutex_lock (&gv.sendq_lock); if (immediately || gv.sendq_length == SENDQ_HW) - os_condBroadcast (&gv.sendq_cond); + ddsrt_cond_broadcast (&gv.sendq_cond); if (gv.sendq_length >= SENDQ_MAX) { while (gv.sendq_length > SENDQ_LW) - os_condWait (&gv.sendq_cond, &gv.sendq_lock); + ddsrt_cond_wait (&gv.sendq_cond, &gv.sendq_lock); } if (gv.sendq_head) gv.sendq_tail->sendq_next = xp1; @@ -1563,7 +1506,7 @@ void nn_xpack_send (struct nn_xpack *xp, bool immediately) } gv.sendq_tail = xp1; gv.sendq_length++; - os_mutexUnlock (&gv.sendq_lock); + ddsrt_mutex_unlock (&gv.sendq_lock); } } @@ -1659,7 +1602,7 @@ int nn_xpack_addmsg (struct nn_xpack *xp, struct nn_xmsg *m, const uint32_t flag /* Returns > 0 if pack got sent out before adding m */ static InfoDST_t static_zero_dst = { - { SMID_INFO_DST, (PLATFORM_IS_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0), sizeof (nn_guid_prefix_t) }, + { SMID_INFO_DST, (DDSRT_ENDIAN == DDSRT_LITTLE_ENDIAN ? SMFLAG_ENDIANNESS : 0), sizeof (nn_guid_prefix_t) }, { { 0,0,0,0, 0,0,0,0, 0,0,0,0 } } }; InfoDST_t *dst; @@ -1809,11 +1752,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 += (os_iov_len_t)m->sz; + xp->iov[niov-1].iov_len += (ddsrt_iov_len_t)m->sz; else { xp->iov[niov].iov_base = m->data->payload; - xp->iov[niov].iov_len = (os_iov_len_t)m->sz; + xp->iov[niov].iov_len = (ddsrt_iov_len_t)m->sz; niov++; } sz += m->sz; diff --git a/src/core/ddsi/src/sysdeps.c b/src/core/ddsi/src/sysdeps.c index 96de141..251b781 100644 --- a/src/core/ddsi/src/sysdeps.c +++ b/src/core/ddsi/src/sysdeps.c @@ -12,24 +12,25 @@ #include #include -#include "os/os.h" +#include "dds/ddsrt/atomics.h" -#include "ddsi/q_error.h" -#include "ddsi/q_log.h" -#include "ddsi/q_config.h" -#include "ddsi/sysdeps.h" +#include "dds/ddsi/q_error.h" +#include "dds/ddsi/q_log.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/sysdeps.h" #if !(defined __APPLE__ || defined __linux) || (__GNUC__ > 0 && (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40100) -void log_stacktrace (const char *name, os_threadId tid) +void log_stacktrace (const char *name, ddsrt_thread_t tid) { - OS_UNUSED_ARG (name); - OS_UNUSED_ARG (tid); + DDSRT_UNUSED_ARG (name); + DDSRT_UNUSED_ARG (tid); } #else +#include #include #include -static os_atomic_uint32_t log_stacktrace_flag = OS_ATOMIC_UINT32_INIT(0); +static ddsrt_atomic_uint32_t log_stacktrace_flag = DDSRT_ATOMIC_UINT32_INIT(0); static struct { int depth; void *stk[64]; @@ -38,13 +39,13 @@ static struct { static void log_stacktrace_sigh (int sig __attribute__ ((unused))) { - int e = os_getErrno(); + int e = errno; log_stacktrace_stk.depth = backtrace (log_stacktrace_stk.stk, (int) (sizeof (log_stacktrace_stk.stk) / sizeof (*log_stacktrace_stk.stk))); - os_atomic_inc32 (&log_stacktrace_flag); - os_setErrno(e); + ddsrt_atomic_inc32 (&log_stacktrace_flag); + errno = e; } -void log_stacktrace (const char *name, os_threadId tid) +void log_stacktrace (const char *name, ddsrt_thread_t tid) { if (dds_get_log_mask() == 0) ; /* no op if nothing logged */ @@ -52,7 +53,7 @@ void log_stacktrace (const char *name, os_threadId tid) DDS_LOG(~0u, "-- stack trace of %s requested, but traces disabled --\n", name); else { - const os_time d = { 0, 1000000 }; + const dds_time_t d = 1000000; struct sigaction act, oact; char **strs; int i; @@ -60,12 +61,12 @@ void log_stacktrace (const char *name, os_threadId tid) act.sa_handler = log_stacktrace_sigh; act.sa_flags = 0; sigfillset (&act.sa_mask); - while (!os_atomic_cas32 (&log_stacktrace_flag, 0, 1)) - os_nanoSleep (d); + while (!ddsrt_atomic_cas32 (&log_stacktrace_flag, 0, 1)) + dds_sleepfor (d); sigaction (SIGXCPU, &act, &oact); pthread_kill (tid.v, SIGXCPU); - while (!os_atomic_cas32 (&log_stacktrace_flag, 2, 3) && pthread_kill (tid.v, 0) == 0) - os_nanoSleep (d); + while (!ddsrt_atomic_cas32 (&log_stacktrace_flag, 2, 3) && pthread_kill (tid.v, 0) == 0) + dds_sleepfor (d); sigaction (SIGXCPU, &oact, NULL); if (pthread_kill (tid.v, 0) != 0) DDS_LOG(~0u, "-- thread exited --\n"); @@ -78,7 +79,7 @@ void log_stacktrace (const char *name, os_threadId tid) free (strs); DDS_LOG(~0u, "-- end of stack trace --\n"); } - os_atomic_st32 (&log_stacktrace_flag, 0); + ddsrt_atomic_st32 (&log_stacktrace_flag, 0); } } #endif diff --git a/src/core/xtests/CMakeLists.txt b/src/core/xtests/CMakeLists.txt index 6815c89..9a67a6c 100644 --- a/src/core/xtests/CMakeLists.txt +++ b/src/core/xtests/CMakeLists.txt @@ -18,7 +18,7 @@ target_include_directories( "$" "$") -target_link_libraries(rhc_torture RhcTypes ddsc util OSAPI) +target_link_libraries(rhc_torture RhcTypes ddsc util) add_test( NAME rhc_torture diff --git a/src/core/xtests/rhc_torture.c b/src/core/xtests/rhc_torture.c index 8bc2808..9d66de1 100644 --- a/src/core/xtests/rhc_torture.c +++ b/src/core/xtests/rhc_torture.c @@ -15,21 +15,22 @@ #include #include -#include "os/os.h" - -#include "ddsc/dds.h" -#include "ddsi/ddsi_tkmap.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/sync.h" +#include "dds/dds.h" +#include "dds/ddsi/ddsi_tkmap.h" #include "dds__entity.h" -#include "ddsi/q_config.h" -#include "ddsi/q_bswap.h" -#include "ddsi/q_globals.h" -#include "ddsi/q_radmin.h" -#include "ddsi/q_entity.h" -#include "ddsi/q_gc.h" -#include "ddsi/ddsi_serdata.h" +#include "dds/ddsi/q_config.h" +#include "dds/ddsi/q_bswap.h" +#include "dds/ddsi/q_globals.h" +#include "dds/ddsi/q_radmin.h" +#include "dds/ddsi/q_entity.h" +#include "dds/ddsi/q_gc.h" +#include "dds/ddsi/ddsi_serdata.h" #include "dds__topic.h" #include "dds__rhc.h" -#include "ddsi/ddsi_iid.h" +#include "dds/ddsi/ddsi_iid.h" #include "mt19937ar.h" #include "RhcTypes.h" @@ -45,8 +46,8 @@ static struct thread_state1 *mainthread; static dds_time_t tref_dds; static uint32_t seq; -static os_mutex wait_gc_cycle_lock; -static os_cond wait_gc_cycle_cond; +static ddsrt_mutex_t wait_gc_cycle_lock; +static ddsrt_cond_t wait_gc_cycle_cond; static int wait_gc_cycle_trig; /* these are used to get a sufficiently large result buffer when takeing/reading everying */ @@ -139,8 +140,8 @@ static struct proxy_writer *mkwr (bool auto_dispose) struct proxy_writer *pwr; struct nn_xqos *xqos; uint64_t wr_iid; - pwr = os_malloc (sizeof (*pwr)); - xqos = os_malloc (sizeof (*xqos)); + pwr = ddsrt_malloc (sizeof (*pwr)); + xqos = ddsrt_malloc (sizeof (*xqos)); wr_iid = ddsi_iid_gen (); memset (pwr, 0, sizeof (*pwr)); nn_xqos_init_empty (xqos); @@ -457,10 +458,10 @@ static void tkcond (struct rhc *rhc, dds_readcond *cond, const struct check *chk static void wait_gc_cycle_impl (struct gcreq *gcreq) { - os_mutexLock (&wait_gc_cycle_lock); + ddsrt_mutex_lock (&wait_gc_cycle_lock); wait_gc_cycle_trig = 1; - os_condBroadcast (&wait_gc_cycle_cond); - os_mutexUnlock (&wait_gc_cycle_lock); + ddsrt_cond_broadcast (&wait_gc_cycle_cond); + ddsrt_mutex_unlock (&wait_gc_cycle_lock); gcreq_free (gcreq); } @@ -469,16 +470,16 @@ static void wait_gc_cycle (void) /* only single-threaded for now */ struct gcreq *gcreq = gcreq_new (gv.gcreq_queue, wait_gc_cycle_impl); #ifndef NDEBUG - os_mutexLock (&wait_gc_cycle_lock); + ddsrt_mutex_lock (&wait_gc_cycle_lock); assert (wait_gc_cycle_trig == 0); - os_mutexUnlock (&wait_gc_cycle_lock); + ddsrt_mutex_unlock (&wait_gc_cycle_lock); #endif gcreq_enqueue (gcreq); - os_mutexLock (&wait_gc_cycle_lock); + ddsrt_mutex_lock (&wait_gc_cycle_lock); while (!wait_gc_cycle_trig) - os_condWait (&wait_gc_cycle_cond, &wait_gc_cycle_lock); + ddsrt_cond_wait (&wait_gc_cycle_cond, &wait_gc_cycle_lock); wait_gc_cycle_trig = 0; - os_mutexUnlock (&wait_gc_cycle_lock); + ddsrt_mutex_unlock (&wait_gc_cycle_lock); } static bool qcpred_key (const void *vx) @@ -810,13 +811,13 @@ int main (int argc, char **argv) bool print = false; int first = 0, count = 10000; - os_mutexInit (&wait_gc_cycle_lock); - os_condInit (&wait_gc_cycle_cond, &wait_gc_cycle_lock); + ddsrt_mutex_init (&wait_gc_cycle_lock); + ddsrt_cond_init (&wait_gc_cycle_cond); if (argc > 1) seed = (unsigned) atoi (argv[1]); if (seed == 0) - seed = (unsigned) os_getpid (); + seed = (unsigned) ddsrt_getpid (); if (argc > 2) first = atoi (argv[2]); if (argc > 3) @@ -972,8 +973,8 @@ int main (int argc, char **argv) } } - os_condDestroy (&wait_gc_cycle_cond); - os_mutexDestroy (&wait_gc_cycle_lock); + ddsrt_cond_destroy (&wait_gc_cycle_cond); + ddsrt_mutex_destroy (&wait_gc_cycle_lock); for (size_t i = 0; i < sizeof (rres_iseq) / sizeof (rres_iseq[0]); i++) RhcTypes_T_free (&rres_mseq[i], DDS_FREE_CONTENTS); diff --git a/src/ddsrt/CMakeLists.txt b/src/ddsrt/CMakeLists.txt new file mode 100644 index 0000000..e8b62a6 --- /dev/null +++ b/src/ddsrt/CMakeLists.txt @@ -0,0 +1,210 @@ +# +# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License +# v. 1.0 which is available at +# http://www.eclipse.org/org/documents/edl-v10.php. +# +# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause +# +include(CheckCSourceCompiles) +include(CheckLibraryExists) + +function(check_runtime_feature SOURCE_FILE) + set(expr "cmake_([_a-zA-Z0-9]+)=([_a-zA-Z0-9]+)") + try_compile( + foo "${CMAKE_BINARY_DIR}" + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}" + OUTPUT_VARIABLE output) + string(REGEX MATCHALL "${expr}" matches "${output}") + foreach(match ${matches}) + string(REGEX REPLACE "${expr}" "\\1" option "${match}") + string(REGEX REPLACE "${expr}" "\\2" value "${match}") + set(${option} ${value} PARENT_SCOPE) + endforeach() +endfunction() + +if(APPLE) + set(system_name darwin) +else() + string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name) +endif() + +# A better choice is to use a so-called object library for ddsrt, but it was +# not possible to use target_link_libraries with object libraries until CMake +# 3.12. At the time of this writing most long-term stable distributions still +# ship an older version, so an interface library with public sources is used +# as a workaround for now. +add_library(ddsrt INTERFACE) +target_include_directories( + ddsrt INTERFACE + "$" + "$") + +# Generate version header. +configure_file("include/dds/version.h.in" "include/dds/version.h") +target_sources( + ddsrt INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/dds/version.h") + +if(WIN32) + configure_file("include/getopt.h.in" "include/getopt.h" COPYONLY) + list(APPEND headers "${CMAKE_CURRENT_BINARY_DIR}/include/getopt.h") + list(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/src/getopt.c") +endif() + +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include") +set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/src") + +list(APPEND headers + "${include_path}/dds/ddsrt/log.h" + "${include_path}/dds/ddsrt/retcode.h" + "${include_path}/dds/ddsrt/attributes.h" + "${include_path}/dds/ddsrt/endian.h" + "${include_path}/dds/ddsrt/arch.h" + "${include_path}/dds/ddsrt/misc.h" + "${include_path}/dds/ddsrt/io.h" + "${include_path}/dds/ddsrt/process.h" + "${include_path}/dds/ddsrt/strtod.h" + "${include_path}/dds/ddsrt/strtol.h" + "${include_path}/dds/ddsrt/types.h") + +list(APPEND sources + "${source_path}/io.c" + "${source_path}/log.c" + "${source_path}/retcode.c" + "${source_path}/process.c" + "${source_path}/strtod.c" + "${source_path}/strtol.c") + +# Not every target offers the same set of features. For embedded targets the +# set of features may even be different between builds. e.g. a FreeRTOS build +# could use the lightweight IP stack, but later change to FreeRTOS+TCP. +# +# Most features and target specific settings can be determined at compile time +# by a combination of pre-defined macros. However, some features require input +# from the build system. e.g. that the target operating system is FreeRTOS or +# that the network stack to be used is lwIP as opposed to the target native +# network stack. In order to mix-and-match various compilers, architectures, +# operating systems, etc input from the build system is required. +foreach(feature atomics cdtors environ heap ifaddrs random rusage + sockets string sync threads time) + if(EXISTS "${include_path}/dds/ddsrt/${feature}.h") + list(APPEND headers "${include_path}/dds/ddsrt/${feature}.h") + file(GLOB + files + CONFIGURE_DEPENDS + "${include_path}/dds/ddsrt/${feature}/**.h") + list(APPEND headers ${files}) + + # Do not add any sources if a feature is not offered by the target. The + # headers will define any macros needed by the source code by combining + # build system exports and pre-defined macros. To determine if a certain + # feature is offered by the target and whether or not to compile any + # source files, that information must be made available to CMake. + # + # Tests that export the required information can be written in + # cmake/${feature}.c. A test consists of a source file that includes the + # required header files and results in a specifically crafted compiler + # error that is picked up by CMake. By default, if a file named after the + # feature does not exist in cmake, the feature is expected to be + # implemented for all targets. + string(TOUPPER "${feature}" feature_uc) + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${feature}.c") + check_runtime_feature(cmake/${feature}.c) + else() + set(HAVE_${feature_uc} TRUE) + endif() + + if(HAVE_${feature_uc}) + # Code that is more-or-less the same for all targets can placed in + # src/.c. An example would be ddsrt_freeifaddrs. + if(EXISTS "${source_path}/${feature}.c") + list(APPEND sources "${source_path}/${feature}.c") + endif() + set(system_exists FALSE) + foreach(system ${system_name} posix) + # Headers that must remain private but are required by other runtime + # source files must be located in src//dds/ddsrt. + if(IS_DIRECTORY "${source_path}/${feature}/include") + file(GLOB + files + CONFIGURE_DEPENDS + "${source_path}/${feature}/include/**.h") + list(APPEND sources ${files}) + target_include_directories( + ddsrt INTERFACE + "$") + endif() + if(IS_DIRECTORY "${source_path}/${feature}/${system}") + file(GLOB + files + CONFIGURE_DEPENDS + "${source_path}/${feature}/${system}/**.c") + list(APPEND sources ${files}) + set(system_exists TRUE) + endif() + # Break as soon a system-specific headers or sources are found. + if(system_exists) + break() + endif() + endforeach() + else() + message(STATUS "Feature ${feature} disabled") + endif() + else() + message(FATAL_ERROR "Feature ${feature} does not exist") + endif() +endforeach() + +target_sources(ddsrt INTERFACE ${sources}) + +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads REQUIRED) +target_link_libraries(ddsrt INTERFACE Threads::Threads) + +if(WIN32) + target_link_libraries(ddsrt INTERFACE wsock32 ws2_32 iphlpapi) +elseif(UNIX) + 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_RT) + if(HAVE_CLOCK_GETTIME_RT) + set(HAVE_CLOCK_GETTIME TRUE) + target_link_libraries(ddsrt 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(ddsrt INTERFACE socket nsl) +endif() + +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + +install( + DIRECTORY "include/dds" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT dev + FILES_MATCHING PATTERN "*.h") + +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/include/dds/version.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dds" + COMPONENT dev) + +if(WIN32) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/include/getopt.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT dev) +endif() + diff --git a/src/os/include/os/posix/os_platform_public.h b/src/ddsrt/include/dds/ddsrt/arch.h similarity index 64% rename from src/os/include/os/posix/os_platform_public.h rename to src/ddsrt/include/dds/ddsrt/arch.h index 6c52fa8..c2f1875 100644 --- a/src/os/include/os/posix/os_platform_public.h +++ b/src/ddsrt/include/dds/ddsrt/arch.h @@ -9,17 +9,21 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_PUBLIC_POSIX_H -#define OS_PLATFORM_PUBLIC_POSIX_H +#ifndef DDSRT_ARCH_H +#define DDSRT_ARCH_H -#include - -#if defined (__cplusplus) -extern "C" { +#if _WIN32 +# if _WIN64 +# define DDSRT_64BIT 1 +# else +# define DDSRT_64BIT 0 +# endif +#else +# if defined(_LP64) +# define DDSRT_64BIT 1 +# else +# define DDSRT_64BIT 0 +# endif #endif -#if defined (__cplusplus) -} -#endif - -#endif +#endif /* DDSRT_ARCH_H */ diff --git a/src/ddsrt/include/dds/ddsrt/atomics.h b/src/ddsrt/include/dds/ddsrt/atomics.h new file mode 100644 index 0000000..5acbed4 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/atomics.h @@ -0,0 +1,66 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ATOMICS_H +#define DDSRT_ATOMICS_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/arch.h" +#include "dds/ddsrt/endian.h" +#include "dds/ddsrt/types.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +/** + * @brief Types on which atomic operations are defined. + * + * @note 64-bit types are defined even if atomic operations on them are not + * really supported. atomic + */ +typedef struct { uint32_t v; } ddsrt_atomic_uint32_t; +typedef struct { uint64_t v; } ddsrt_atomic_uint64_t; +typedef struct { uintptr_t v; } ddsrt_atomic_uintptr_t; +typedef ddsrt_atomic_uintptr_t ddsrt_atomic_voidp_t; + +#if DDSRT_64BIT +# define DDSRT_HAVE_ATOMIC64 1 +#endif + +/** + * @brief Initializers for the types on which atomic operations are defined. + */ +#define DDSRT_ATOMIC_UINT32_INIT(v) { (v) } +#define DDSRT_ATOMIC_UINT64_INIT(v) { (v) } +#define DDSRT_ATOMIC_UINTPTR_INIT(v) { (v) } +#define DDSRT_ATOMIC_VOIDP_INIT(v) { (uintptr_t) (v) } + + +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40100 +#include "dds/ddsrt/atomics/gcc.h" +#elif defined(_WIN32) +#include "dds/ddsrt/atomics/msvc.h" +#elif defined(__sun) +#include "dds/ddsrt/atomics/sun.h" +#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) +#include "dds/ddsrt/atomics/arm.h" +#else +#error "Atomic operations are not supported" +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_ATOMICS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/atomics/arm.h b/src/ddsrt/include/dds/ddsrt/atomics/arm.h new file mode 100644 index 0000000..e0b0d1c --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/atomics/arm.h @@ -0,0 +1,213 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ATOMICS_ARM_H +#define DDSRT_ATOMICS_ARM_H + +#if !defined(__arm__) +#define __arm__ +#endif + +/* IAR documentation states that __CPU_MODE__ is a predefined preprocessor + symbol reflecting the selected CPU mode and is defined to 1 for Thumb and + 2 for ARM. */ +#if !defined(__thumb__) && __CPU_MODE__ == 1 +#define __thumb__ +#endif + +/* LD, ST */ + +inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; } +inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; } +inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); } + +inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; } +inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; } +inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); } + +/* CAS */ + +inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) { + register int result; + asm volatile ("ldrex r0, [%1]\n\t" /*exclusive load of ptr */ + "cmp r0, %2\n\t" /*compare the oldval == *ptr */ +#if defined(__thumb__) + "ite eq\n\t" +#endif + "strexeq %0, %3, [%1]\n\t" /*store if eq, strex+eq*/ +#if defined(__thumb__) + "clrexne" +#endif + : "=&r" (result) + : "r"(&x->v), "r"(exp),"r"(des) + : "r0"); + return result == 0; +} +inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) { + return ddsrt_atomic_cas32 ((volatile ddsrt_atomic_uint32_t *) x, exp, des); +} +inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) { + return ddsrt_atomic_casptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) exp, (uintptr_t) des); +} + +/* ADD */ + +inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + register unsigned int result; + asm volatile ("1: ldrex %0, [%1]\n\t" + "add %0, %0, %2\n\t" + "strex r1, %0, [%1]\n\t" + "cmp r1, #0\n\t" + "bne 1b" + : "=&r" (result) + : "r"(&x->v), "r"(v) + : "r1"); + return result; +} +inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return ddsrt_atomic_add32_nv ((volatile ddsrt_atomic_uint32_t *) x, v); +} +inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return (void *) ddsrt_atomic_addptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} +inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + (void) ddsrt_atomic_add32_nv (x, v); +} +inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + (void) ddsrt_atomic_addptr_nv (x, v); +} +inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + (void) ddsrt_atomic_addvoidp_nv (x, v); +} + +/* SUB */ + +inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return ddsrt_atomic_add32_nv (x, -v); +} +inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return ddsrt_atomic_addptr_nv (x, -v); +} +inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return ddsrt_atomic_addvoidp_nv (x, -v); +} +inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + ddsrt_atomic_add32 (x, -v); +} +inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + ddsrt_atomic_subptr (x, -v); +} +inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + ddsrt_atomic_subvoidp (x, -v); +} + +/* INC */ + +inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) { + return ddsrt_atomic_add32_nv (x, 1); +} +inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return ddsrt_atomic_addptr_nv (x, 1); +} +inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) { + (void) ddsrt_atomic_inc32_nv (x); +} +inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) { + (void) ddsrt_atomic_incptr_nv (x); +} + +/* DEC */ + +inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) { + return ddsrt_atomic_sub32_nv (x, 1); +} +inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return ddsrt_atomic_subptr_nv (x, 1); +} +inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) { + (void) ddsrt_atomic_dec32_nv (x); +} +inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) { + (void) ddsrt_atomic_decptr_nv (x); +} + +/* AND */ + +inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_cas32 (x, oldval, newval)); + return oldval; +} +inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_casptr (x, oldval, newval)); + return oldval; +} +inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_cas32 (x, oldval, newval)); + return newval; +} +inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (!ddsrt_atomic_casptr (x, oldval, newval)); + return newval; +} +inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + (void) ddsrt_atomic_and32_nv (x, v); +} +inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + (void) ddsrt_atomic_andptr_nv (x, v); +} + +/* OR */ + +inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_cas32 (x, oldval, newval)); + return oldval; +} +inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_casptr (x, oldval, newval)); + return oldval; +} +inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_cas32 (x, oldval, newval)); + return newval; +} +inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (!ddsrt_atomic_casptr (x, oldval, newval)); + return newval; +} +inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + (void) ddsrt_atomic_or32_nv (x, v); +} +inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + (void) ddsrt_atomic_orptr_nv (x, v); +} + +/* FENCES */ + +inline void ddsrt_atomic_fence (void) { + __asm volatile ("dmb" : : : "memory"); +} +inline void ddsrt_atomic_fence_acq (void) { + ddsrt_atomic_fence (); +} +inline void ddsrt_atomic_fence_rel (void) { + ddsrt_atomic_fence (); +} + +#endif /* DDSRT_ATOMICS_ARM_H */ + diff --git a/src/ddsrt/include/dds/ddsrt/atomics/gcc.h b/src/ddsrt/include/dds/ddsrt/atomics/gcc.h new file mode 100644 index 0000000..0c62272 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/atomics/gcc.h @@ -0,0 +1,291 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ATOMICS_GCC_H +#define DDSRT_ATOMICS_GCC_H + +#include "dds/ddsrt/misc.h" + +#if ( DDSRT_HAVE_ATOMIC64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || \ + (!DDSRT_HAVE_ATOMIC64 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) +# define DDSRT_HAVE_ATOMIC_LIFO 1 +#endif + +/* LD, ST */ + +inline uint32_t ddsrt_atomic_ld32(const volatile ddsrt_atomic_uint32_t *x) { return x->v; } +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_ld64(const volatile ddsrt_atomic_uint64_t *x) { return x->v; } +#endif +inline uintptr_t ddsrt_atomic_ldptr(const volatile ddsrt_atomic_uintptr_t *x) { return x->v; } +inline void *ddsrt_atomic_ldvoidp(const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr(x); } + +inline void ddsrt_atomic_st32(volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; } +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_st64(volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; } +#endif +inline void ddsrt_atomic_stptr(volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; } +inline void ddsrt_atomic_stvoidp(volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr(x, (uintptr_t)v); } + +/* INC */ + +inline void ddsrt_atomic_inc32(volatile ddsrt_atomic_uint32_t *x) { + __sync_fetch_and_add (&x->v, 1); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) { + __sync_fetch_and_add (&x->v, 1); +} +#endif +inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) { + __sync_fetch_and_add (&x->v, 1); +} +inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) { + return __sync_add_and_fetch (&x->v, 1); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) { + return __sync_add_and_fetch (&x->v, 1); +} +#endif +inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return __sync_add_and_fetch (&x->v, 1); +} + +/* DEC */ + +inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) { + __sync_fetch_and_sub (&x->v, 1); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) { + __sync_fetch_and_sub (&x->v, 1); +} +#endif +inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) { + __sync_fetch_and_sub (&x->v, 1); +} +inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) { + return __sync_sub_and_fetch (&x->v, 1); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) { + return __sync_sub_and_fetch (&x->v, 1); +} +#endif +inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return __sync_sub_and_fetch (&x->v, 1); +} +inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) { + return __sync_fetch_and_sub (&x->v, 1); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) { + return __sync_fetch_and_sub (&x->v, 1); +} +#endif +inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) { + return __sync_fetch_and_sub (&x->v, 1); +} + +/* ADD */ + +inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + __sync_fetch_and_add (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + __sync_fetch_and_add (&x->v, v); +} +#endif +inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + __sync_fetch_and_add (&x->v, v); +} +inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + ddsrt_atomic_addptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} +inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_add_and_fetch (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_add_and_fetch (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_add_and_fetch (&x->v, v); +} +inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return (void *) ddsrt_atomic_addptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} + +/* SUB */ + +inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + __sync_fetch_and_sub (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + __sync_fetch_and_sub (&x->v, v); +} +#endif +inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + __sync_fetch_and_sub (&x->v, v); +} +inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + ddsrt_atomic_subptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} +inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_sub_and_fetch (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_sub_and_fetch (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_sub_and_fetch (&x->v, v); +} +inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return (void *) ddsrt_atomic_subptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} + +/* AND */ + +inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + __sync_fetch_and_and (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + __sync_fetch_and_and (&x->v, v); +} +#endif +inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + __sync_fetch_and_and (&x->v, v); +} +inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_fetch_and_and (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_fetch_and_and (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_fetch_and_and (&x->v, v); +} +inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_and_and_fetch (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_and_and_fetch (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_and_and_fetch (&x->v, v); +} + +/* OR */ + +inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + __sync_fetch_and_or (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + __sync_fetch_and_or (&x->v, v); +} +#endif +inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + __sync_fetch_and_or (&x->v, v); +} +inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_fetch_and_or (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_fetch_and_or (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_fetch_and_or (&x->v, v); +} +inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return __sync_or_and_fetch (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return __sync_or_and_fetch (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return __sync_or_and_fetch (&x->v, v); +} + +/* CAS */ + +inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) { + return __sync_bool_compare_and_swap (&x->v, exp, des); +} +#if DDSRT_HAVE_ATOMIC64 +inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) { + return __sync_bool_compare_and_swap (&x->v, exp, des); +} +#endif +inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) { + return __sync_bool_compare_and_swap (&x->v, exp, des); +} +inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) { + return ddsrt_atomic_casptr (x, (uintptr_t) exp, (uintptr_t) des); +} +#if DDSRT_HAVE_ATOMIC_LIFO +#if DDSRT_HAVE_ATOMIC64 +typedef union { __int128_t x; struct { uintptr_t a, b; } s; } ddsrt_atomic_uintptr2_t; +#else +typedef union { uint64_t x; struct { uintptr_t a, b; } s; } ddsrt_atomic_uintptr2_t; +#endif + +typedef struct { + ddsrt_atomic_uintptr2_t aba_head; +} ddsrt_atomic_lifo_t; + +DDS_EXPORT void ddsrt_atomic_lifo_init(ddsrt_atomic_lifo_t *head); +DDS_EXPORT void ddsrt_atomic_lifo_push(ddsrt_atomic_lifo_t *head, void *elem, size_t linkoff); +DDS_EXPORT void *ddsrt_atomic_lifo_pop(ddsrt_atomic_lifo_t *head, size_t linkoff); +DDS_EXPORT void ddsrt_atomic_lifo_pushmany(ddsrt_atomic_lifo_t *head, void *first, void *last, size_t linkoff); + +inline int ddsrt_atomic_casvoidp2 (volatile ddsrt_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1) { + ddsrt_atomic_uintptr2_t o, n; + o.s.a = a0; o.s.b = b0; + n.s.a = a1; n.s.b = b1; + return __sync_bool_compare_and_swap (&x->x, o.x, n.x); +} +#endif + +/* FENCES */ + +inline void ddsrt_atomic_fence (void) { + __sync_synchronize (); +} +inline void ddsrt_atomic_fence_ldld (void) { +#if !(defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64) + __sync_synchronize (); +#endif +} +inline void ddsrt_atomic_fence_acq (void) { + ddsrt_atomic_fence (); +} +inline void ddsrt_atomic_fence_rel (void) { + ddsrt_atomic_fence (); +} + +#endif /* DDSRT_ATOMICS_GCC_H */ + diff --git a/src/ddsrt/include/dds/ddsrt/atomics/msvc.h b/src/ddsrt/include/dds/ddsrt/atomics/msvc.h new file mode 100644 index 0000000..01260aa --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/atomics/msvc.h @@ -0,0 +1,299 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ATOMICS_MSVC_H +#define DDSRT_ATOMICS_MSVC_H + +#include "dds/ddsrt/misc.h" + +/* x86 has supported 64-bit CAS for a long time, so Windows ought to + provide all the interlocked operations for 64-bit operands on x86 + platforms, but it doesn't. */ + +#if DDSRT_HAVE_ATOMIC64 +#define DDSRT_ATOMIC_PTROP(name) name##64 +#else +#define DDSRT_ATOMIC_PTROP(name) name +#endif + +/* LD, ST */ + +inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; } +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_ld64 (const volatile ddsrt_atomic_uint64_t *x) { return x->v; } +#endif +inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; } +inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); } + +inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; } +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_st64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; } +#endif +inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; } +inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); } + +/* CAS */ + +inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) { + return InterlockedCompareExchange (&x->v, des, exp) == exp; +} +#if DDSRT_HAVE_ATOMIC64 +inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) { + return InterlockedCompareExchange64 (&x->v, des, exp) == exp; +} +#endif +inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) { + return DDSRT_ATOMIC_PTROP (InterlockedCompareExchange) (&x->v, des, exp) == exp; +} +inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) { + return ddsrt_atomic_casptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) exp, (uintptr_t) des); +} + +/* INC */ + +inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) { + InterlockedIncrement (&x->v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) { + InterlockedIncrement64 (&x->v); +} +#endif +inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) { + DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v); +} +inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) { + return InterlockedIncrement (&x->v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) { + return InterlockedIncrement64 (&x->v); +} +#endif +inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return DDSRT_ATOMIC_PTROP (InterlockedIncrement) (&x->v); +} + +/* DEC */ + +inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) { + InterlockedDecrement (&x->v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) { + InterlockedDecrement64 (&x->v); +} +#endif +inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) { + DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v); +} +inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) { + return InterlockedDecrement (&x->v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) { + return InterlockedDecrement64 (&x->v); +} +#endif +inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v); +} +inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) { + return InterlockedDecrement (&x->v) + 1; +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) { + return InterlockedDecrement64 (&x->v) + 1; +} +#endif +inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) { + return DDSRT_ATOMIC_PTROP (InterlockedDecrement) (&x->v) + 1; +} + +/* ADD */ + +inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + InterlockedExchangeAdd (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + InterlockedExchangeAdd64 (&x->v, v); +} +#endif +inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v); +} +inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + ddsrt_atomic_addptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} +inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return InterlockedExchangeAdd (&x->v, v) + v; +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return InterlockedExchangeAdd64 (&x->v, v) + v; +} +#endif +inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, v) + v; +} +inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return (void *) ddsrt_atomic_addptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} + +/* SUB */ + +inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + InterlockedExchangeAdd (&x->v, -v); +DDSRT_WARNING_MSVC_ON(4146) +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + InterlockedExchangeAdd64 (&x->v, -v); +DDSRT_WARNING_MSVC_ON(4146) +} +#endif +inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v); +DDSRT_WARNING_MSVC_ON(4146) +} +inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + ddsrt_atomic_subptr ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} +inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + return InterlockedExchangeAdd (&x->v, -v) - v; +DDSRT_WARNING_MSVC_ON(4146) +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + return InterlockedExchangeAdd64 (&x->v, -v) - v; +DDSRT_WARNING_MSVC_ON(4146) +} +#endif +inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + /* disable unary minus applied to unsigned type, result still unsigned */ +DDSRT_WARNING_MSVC_OFF(4146) + return DDSRT_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, -v) - v; +DDSRT_WARNING_MSVC_ON(4146) +} +inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return (void *) ddsrt_atomic_subptr_nv ((volatile ddsrt_atomic_uintptr_t *) x, (uintptr_t) v); +} + +/* AND */ + +inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + InterlockedAnd (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + InterlockedAnd64 (&x->v, v); +} +#endif +inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v); +} +inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return InterlockedAnd (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return InterlockedAnd64 (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v); +} +inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return InterlockedAnd (&x->v, v) & v; +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return InterlockedAnd64 (&x->v, v) & v; +} +#endif +inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return DDSRT_ATOMIC_PTROP (InterlockedAnd) (&x->v, v) & v; +} + +/* OR */ + +inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + InterlockedOr (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + InterlockedOr64 (&x->v, v); +} +#endif +inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v); +} +inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return InterlockedOr (&x->v, v); +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return InterlockedOr64 (&x->v, v); +} +#endif +inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v); +} +inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return InterlockedOr (&x->v, v) | v; +} +#if DDSRT_HAVE_ATOMIC64 +inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return InterlockedOr64 (&x->v, v) | v; +} +#endif +inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return DDSRT_ATOMIC_PTROP (InterlockedOr) (&x->v, v) | v; +} + +/* FENCES */ + +inline void ddsrt_atomic_fence (void) { + /* 28113: accessing a local variable tmp via an Interlocked + function: This is an unusual usage which could be reconsidered. + It is too heavyweight, true, but it does the trick. */ +DDSRT_WARNING_MSVC_OFF(28113) + volatile LONG tmp = 0; + InterlockedExchange (&tmp, 0); +DDSRT_WARNING_MSVC_ON(28113) +} +inline void ddsrt_atomic_fence_ldld (void) { +#if !(defined _M_IX86 || defined _M_X64) + ddsrt_atomic_fence (); +#endif +} +inline void ddsrt_atomic_fence_acq (void) { + ddsrt_atomic_fence (); +} +inline void ddsrt_atomic_fence_rel (void) { + ddsrt_atomic_fence (); +} + +#undef DDSRT_ATOMIC_PTROP + +#endif /* DDSRT_ATOMICS_MSVC_H */ + diff --git a/src/ddsrt/include/dds/ddsrt/atomics/sun.h b/src/ddsrt/include/dds/ddsrt/atomics/sun.h new file mode 100644 index 0000000..bd364d4 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/atomics/sun.h @@ -0,0 +1,241 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#define DDSRT_ATOMIC64_SUPPORT 1 + +/* LD, ST */ + +inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x) { return x->v; } +inline uint64_t ddsrt_atomic_ld64 (const volatile ddsrt_atomic_uint64_t *x) { return x->v; } +inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x) { return x->v; } +inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x) { return (void *) ddsrt_atomic_ldptr (x); } + +inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { x->v = v; } +inline void ddsrt_atomic_st64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { x->v = v; } +inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { x->v = v; } +inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v) { ddsrt_atomic_stptr (x, (uintptr_t) v); } + +/* INC */ + +inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x) { + atomic_inc_32 (&x->v); +} +inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x) { + atomic_inc_64 (&x->v); +} +inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x) { + atomic_inc_ulong (&x->v); +} +inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x) { + return atomic_inc_32_nv (&x->v); +} +inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x) { + return atomic_inc_64_nv (&x->v); +} +inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return atomic_inc_ulong_nv (&x->v); +} + +/* DEC */ + +inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x) { + atomic_dec_32 (&x->v); +} +inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x) { + atomic_dec_64 (&x->v); +} +inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x) { + atomic_dec_ulong (&x->v); +} +inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x) { + return atomic_dec_32_nv (&x->v); +} +inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x) { + return atomic_dec_64_nv (&x->v); +} +inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x) { + return atomic_dec_ulong_nv (&x->v); +} +inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x) { + uint64_t oldval, newval; + do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval - 1; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval); + return oldval; +} + +/* ADD */ + +inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + atomic_add_32 (&x->v, v); +} +inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + atomic_add_64 (&x->v, v); +} +inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + atomic_add_long (&x->v, v); +} +inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + atomic_add_ptr (&x->v, v); +} +inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return atomic_add_32_nv (&x->v, v); +} +inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return atomic_add_64_nv (&x->v, v); +} +inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return atomic_add_long_nv (&x->v, v); +} +inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return atomic_add_ptr_nv (&x->v, v); +} + +/* SUB */ + +inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + atomic_add_32 (&x->v, -v); +} +inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + atomic_add_64 (&x->v, -v); +} +inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + atomic_add_long (&x->v, -v); +} +inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + atomic_add_ptr (&x->v, -v); +} +inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return atomic_add_32_nv (&x->v, -v); +} +inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return atomic_add_64_nv (&x->v, -v); +} +inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return atomic_add_long_nv (&x->v, -v); +} +inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v) { + return atomic_add_ptr_nv (&x->v, -v); +} + +/* AND */ + +inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + atomic_and_32 (&x->v, v); +} +inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + atomic_and_64 (&x->v, v); +} +inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + atomic_and_ulong (&x->v, v); +} +inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + uint64_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval & v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return atomic_and_32_nv (&x->v, v); +} +inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return atomic_and_64_nv (&x->v, v); +} +inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return atomic_and_ulong_nv (&x->v, v); +} + +/* OR */ + +inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + atomic_or_32 (&x->v, v); +} +inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + atomic_or_64 (&x->v, v); +} +inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + atomic_or_ulong (&x->v, v); +} +inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + uint32_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (atomic_cas_32 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + uint64_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (atomic_cas_64 (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + uintptr_t oldval, newval; + do { oldval = x->v; newval = oldval | v; } while (atomic_cas_ulong (&x->v, oldval, newval) != oldval); + return oldval; +} +inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v) { + return atomic_or_32_nv (&x->v, v); +} +inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v) { + return atomic_or_64_nv (&x->v, v); +} +inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v) { + return atomic_or_ulong_nv (&x->v, v); +} + +/* CAS */ + +inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des) { + return atomic_cas_32 (&x->v, exp, des) == exp; +} +inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des) { + return atomic_cas_64 (&x->v, exp, des) == exp; +} +inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des) { + return atomic_cas_ulong (&x->v, exp, des) == exp; +} +inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des) { + return atomic_cas_ptr (&x->v, exp, des) == exp; +} + +/* FENCES */ + +inline void ddsrt_atomic_fence (void) { + membar_exit (); + membar_enter (); +} +inline void ddsrt_atomic_fence_ldld (void) { + membar_enter (); +} +inline void ddsrt_atomic_fence_acq (void) { + membar_enter (); +} +inline void ddsrt_atomic_fence_rel (void) { + membar_exit (); +} + diff --git a/src/ddsrt/include/dds/ddsrt/attributes.h b/src/ddsrt/include/dds/ddsrt/attributes.h new file mode 100644 index 0000000..4850777 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/attributes.h @@ -0,0 +1,104 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ATTRIBUTES_H +#define DDSRT_ATTRIBUTES_H + +#if __clang__ +# define ddsrt_gnuc (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#else +# define ddsrt_gnuc (0) +#endif + +#if __GNUC__ +# define ddsrt_clang (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) +#else +# define ddsrt_clang (0) +#endif + +#if defined(__has_attribute) +# define ddsrt_has_attribute(params) __has_attribute(params) +#elif ddsrt_gnuc +# define ddsrt_has_attribute(params) (1) /* GCC < 5 */ +#else +# define ddsrt_has_attribute(params) (0) +#endif + +#if ddsrt_has_attribute(malloc) +# define ddsrt_attribute_malloc __attribute__ ((__malloc__)) +#else +# define ddsrt_attribute_malloc +#endif + +#if ddsrt_has_attribute(unused) +# define ddsrt_attribute_unused __attribute__((__unused__)) +#else +# define ddsrt_attribute_unused +#endif + +#if ddsrt_has_attribute(noreturn) +# define ddsrt_attribute_noreturn __attribute__ ((__noreturn__)) +#else +# define ddsrt_attribute_noreturn +#endif + +#if ddsrt_has_attribute(nonnull) +# define ddsrt_nonnull(params) __attribute__ ((__nonnull__ params)) +# define ddsrt_nonnull_all __attribute__ ((__nonnull__)) +#else +# define ddsrt_nonnull(params) +# define ddsrt_nonnull_all +#endif + +#if ddsrt_has_attribute(returns_nonnull) && (ddsrt_clang || ddsrt_gnuc >= 40900) +# define ddsrt_attribute_returns_nonnull __attribute__ ((__returns_nonnull__)) +#else +# define ddsrt_attribute_returns_nonnull +#endif + +/* GCC <= 4.2.4 has the attribute, but warns that it ignores it. */ +#if !ddsrt_has_attribute(alloc_size) || (ddsrt_gnuc <= 40204) +# define ddsrt_attribute_alloc_size(params) +#else +# define ddsrt_attribute_alloc_size(params) __attribute__ ((__alloc_size__ params)) +#endif + +#if ddsrt_has_attribute(const) +# define ddsrt_attribute_const __attribute__ ((__const__)) +#else +# define ddsrt_attribute_const +#endif + +#if ddsrt_has_attribute(pure) +# define ddsrt_attribute_pure __attribute__ ((__pure__)) +#else +# define ddsrt_attribute_pure +#endif + +#if ddsrt_has_attribute(format) +# define ddsrt_attribute_format(params) __attribute__ ((__format__ params)) +#else +# define ddsrt_attribute_format(params) +#endif + +#if ddsrt_has_attribute(warn_unused_result) +# define ddsrt_attribute_warn_unused_result __attribute__ ((__warn_unused_result__)) +#else +# define ddsrt_attribute_warn_unused_result +#endif + +#if ddsrt_has_attribute(assume_aligned) +# define ddsrt_attribute_assume_aligned(params) __attribute__ ((__assume_aligned__ params)) +#else +# define ddsrt_attribute_assume_aligned(params) +#endif + +#endif /* DDSRT_ATTRIBUTES_H */ diff --git a/src/ddsrt/include/dds/ddsrt/cdtors.h b/src/ddsrt/include/dds/ddsrt/cdtors.h new file mode 100644 index 0000000..0b3e733 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/cdtors.h @@ -0,0 +1,24 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_CDTORS_H +#define DDSRT_CDTORS_H + +#include "dds/export.h" +#include "dds/ddsrt/sync.h" + +DDS_EXPORT void ddsrt_init(void); + +DDS_EXPORT void ddsrt_fini(void); + +DDS_EXPORT ddsrt_mutex_t *ddsrt_get_singleton_mutex(void); + +#endif /* DDSRT_CDTORS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/endian.h b/src/ddsrt/include/dds/ddsrt/endian.h new file mode 100644 index 0000000..a6a2358 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/endian.h @@ -0,0 +1,47 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ENDIAN_H +#define DDSRT_ENDIAN_H + +#if defined(__cplusplus) +extern "C" { +#endif + +#define DDSRT_LITTLE_ENDIAN 1 +#define DDSRT_BIG_ENDIAN 2 + +#if _WIN32 +# if defined(__BIG_ENDIAN) +# define DDSRT_ENDIAN DDSRT_BIG_ENDIAN +# else +# define DDSRT_ENDIAN DDSRT_LITTLE_ENDIAN +# endif +#else /* _WIN32 */ +# if defined(__BYTE_ORDER__) +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define DDSRT_ENDIAN DDSRT_BIG_ENDIAN +# elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define DDSRT_ENDIAN DDSRT_LITTLE_ENDIAN +# endif +# endif +#endif /* _WIN32 */ + +#if (DDSRT_ENDIAN != DDSRT_LITTLE_ENDIAN) && \ + (DDSRT_ENDIAN != DDSRT_BIG_ENDIAN) +# error "Endianness cannot be determined" +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_ENDIAN_H */ diff --git a/src/ddsrt/include/dds/ddsrt/environ.h b/src/ddsrt/include/dds/ddsrt/environ.h new file mode 100644 index 0000000..48953c2 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/environ.h @@ -0,0 +1,103 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_ENVIRON_H +#define DDSRT_ENVIRON_H + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/retcode.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * @brief Get value for environment variable. + * + * @param[in] name Environment variable name. + * @param[in] buf Buffer to write value to. + * @param[in] sz Size of buffer. + * @param[out] reqsz Number of bytes written (excluding the terminating null + * byte), or would have been written would @buf have been + * sufficiently large enough. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Environment variable written to @buf. + * @retval DDS_RETCODE_NOT_FOUND + * Environment variable not found. + * @retval DDS_RETCODE_BAD_PARAMETER + * FIXME: document + * @retval DDS_RETCODE_OUT_OF_RESOURCES + * FIXME: document + * @retval DDS_RETCODE_ERROR + * Unspecified error. + */ +DDS_EXPORT dds_retcode_t +ddsrt_getenv( + const char *name, + char **value) +ddsrt_nonnull_all; + +/** + * @brief Set environment variable value. + * + * Sets the environment variable to the value specified in value, or + * alternatively, unsets the environment variable if value is an empty string. + * + * @param[in] name Environment variable name. + * @param[in] value Value to set environment variable to. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Environment variable successfully set to @value. + * @retval DDS_RETCODE_BAD_PARAMETER + * Invalid environment variable name. + * @retval DDS_RETCODE_OUT_OF_RESOURCES + * Not enough system resources to set environment variable. + * @retval DDS_RETCODE_ERROR + * Unspecified system error. + */ +DDS_EXPORT dds_retcode_t +ddsrt_setenv( + const char *name, + const char *value) +ddsrt_nonnull_all; + +/** + * @brief Unset environment variable value. + * + * @param[in] name Environment variable name. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Environment variable successfully unset. + * @retval DDS_RETCODE_BAD_PARAMETER + * Invalid environment variable name. + * @retval DDS_RETCODE_OUT_OF_RESOURCES + * Not enough system resources to unset environment variable. + * @retval DDS_RETCODE_ERROR + * Unspecified system error. + */ +DDS_EXPORT dds_retcode_t +ddsrt_unsetenv( + const char *name) +ddsrt_nonnull_all; + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_ENVIRON_H */ diff --git a/src/ddsrt/include/dds/ddsrt/heap.h b/src/ddsrt/include/dds/ddsrt/heap.h new file mode 100644 index 0000000..796124a --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/heap.h @@ -0,0 +1,155 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +/** + * @file heap.h + * @brief Heap memory management. + * + * Platform independent interface to heap memory management. + */ +#ifndef DDSRT_HEAP_H +#define DDSRT_HEAP_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +/** + * @brief Allocate memory from heap. + * + * The allocated block of memory must be freed by calling @ddsrt_free when no + * longer used. + * + * @param[in] size The size, in bytes, of the block of memory to allocate. + * + * @returns A pointer to the allocated block of memory. abort() is called if + * not enough free memory was available. + */ +DDS_EXPORT void * +ddsrt_malloc( + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((1)); + +/** + * @brief Allocate memory from heap. + * + * Allocate a block of memory from heap with the given size. The allocated + * block of memory must be freed by calling @ddsrt_free when no longer used. + * + * @param[in] size The size, in bytes, of memory to allocate. + * + * @returns A pointer to the allocated block of memory, NULL if not enough + * memory was available. + */ +DDS_EXPORT void * +ddsrt_malloc_s( + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((1)); + +/** + * @brief Allocate memory from heap for an array of @count elements of @size + * bytes. + * + * The allocated memory is initialized to zero. The allocated memory must be + * freed by calling @ddsrt_free when no longer used. + * + * A non-NULL pointer, that must be freed is always returned, even if the sum + * @count and @size equals zero. + * + * @returns A pointer to the allocated memory. abort() is called if not enough + * free memory was available. + */ +DDS_EXPORT void * +ddsrt_calloc( + size_t count, + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((1,2)); + +/** + * @brief Allocate memory from heap for an array of @count elements of @size + * bytes. + * + * The allocated memory is initialized to zero. The allocated memory must be + * freed by calling @ddsrt_free when no longer used. + * + * A non-NULL pointer, that must be freed is always returned, even if the sum + * @count and @size equals zero. + * + * @returns A pointer to the allocated memory, or NULL if not enough memory was + * available. + */ +DDS_EXPORT void * +ddsrt_calloc_s( + size_t count, + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((1,2)); + +/** + * @brief Reallocate memory from heap. + * + * Reallocate memory from heap. If memblk is NULL the function returns + * ddsrt_malloc_s(size). If size is 0, ddsrt_realloc_s free's the memory + * pointed to by memblk and returns a pointer as if ddsrt_malloc_s(0) was + * invoked. The returned pointer must be free'd with ddsrt_free. + * + * @returns A pointer to reallocated memory. Calls abort() if not enough free + * memory was available. + */ +DDS_EXPORT void * +ddsrt_realloc( + void *memblk, + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((2)); + +/** + * @brief Reallocate memory from heap. + * + * Reallocate memory from heap. If memblk is NULL the function returns + * ddsrt_malloc_s(size). If size is 0, ddsrt_realloc_s free's the memory + * pointed to by memblk and returns a pointer as if ddsrt_malloc_s(0) was + * invoked. The returned pointer must be free'd with ddsrt_free. + * + * @returns A pointer to reallocated memory, or NULL if not enough free memory + * was available. + */ +DDS_EXPORT void * +ddsrt_realloc_s( + void *memblk, + size_t size) +ddsrt_attribute_malloc +ddsrt_attribute_alloc_size((2)); + +/** + * @brief Free a previously allocated block of memory and return it to heap. + * + * Free the allocated memory pointed to by @ptr and release it to the heap. No + * action will be taken if @ptr is NULL. + * + * @param[in] ptr Pointer to previously allocated block of memory. + */ +DDS_EXPORT void +ddsrt_free(void *ptr); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_HEAP_H */ diff --git a/src/os/include/os/windows/os_platform_sync.h b/src/ddsrt/include/dds/ddsrt/ifaddrs.h similarity index 51% rename from src/os/include/os/windows/os_platform_sync.h rename to src/ddsrt/include/dds/ddsrt/ifaddrs.h index aad344a..b98d5b8 100644 --- a/src/os/include/os/windows/os_platform_sync.h +++ b/src/ddsrt/include/dds/ddsrt/ifaddrs.h @@ -9,31 +9,38 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_SYNC_H -#define OS_PLATFORM_SYNC_H +#ifndef DDSRT_IFADDRS_H +#define DDSRT_IFADDRS_H + +#include "dds/ddsrt/sockets.h" #if defined (__cplusplus) extern "C" { #endif - typedef struct os_cond { - CONDITION_VARIABLE cond; - } os_cond; +struct ddsrt_ifaddrs { + struct ddsrt_ifaddrs *next; + char *name; + uint32_t index; + uint32_t flags; + struct sockaddr *addr; + struct sockaddr *netmask; + struct sockaddr *broadaddr; +}; - typedef struct os_mutex { - SRWLOCK lock; - } os_mutex; +typedef struct ddsrt_ifaddrs ddsrt_ifaddrs_t; - typedef struct os_rwlock { - SRWLOCK lock; - int state; /* -1: exclusive, 0: free, 1: shared */ - } os_rwlock; +DDS_EXPORT dds_retcode_t +ddsrt_getifaddrs( + ddsrt_ifaddrs_t **ifap, + const int *afs); - typedef INIT_ONCE os_once_t; - #define OS_ONCE_T_STATIC_INIT INIT_ONCE_STATIC_INIT +DDS_EXPORT void +ddsrt_freeifaddrs( + ddsrt_ifaddrs_t *ifa); #if defined (__cplusplus) } #endif -#endif +#endif /* DDSRT_IFADDRS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/io.h b/src/ddsrt/include/dds/ddsrt/io.h new file mode 100644 index 0000000..8c50011 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/io.h @@ -0,0 +1,41 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_IO_H +#define DDSRT_IO_H + +#include +#include + +#include "dds/export.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * @brief Write a formatted string to a newly allocated buffer. + */ +DDS_EXPORT int +ddsrt_asprintf( + char **strp, + const char *fmt, + ...); + +#if defined(_MSC_VER) && (_MSC_VER < 1900) +extern int snprintf(char *s, size_t n, const char *format, ...); +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_IO_H */ diff --git a/src/os/include/os/os_log.h b/src/ddsrt/include/dds/ddsrt/log.h similarity index 69% rename from src/os/include/os/os_log.h rename to src/ddsrt/include/dds/ddsrt/log.h index 9c87df5..b6450c0 100644 --- a/src/os/include/os/os_log.h +++ b/src/ddsrt/include/dds/ddsrt/log.h @@ -20,7 +20,11 @@ #ifndef DDS_LOG_H #define DDS_LOG_H -#include "os/os_defs.h" +#include +#include +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -120,23 +124,23 @@ dds_get_log_mask(void) * * @param[in] cats Log and trace categories to enable. */ -OSAPI_EXPORT void +DDS_EXPORT void dds_set_log_mask( - _In_ uint32_t cats); + uint32_t cats); /** * @private */ -OSAPI_EXPORT void +DDS_EXPORT void dds_set_log_file( - _In_ FILE *file); + FILE *file); /** * @private */ -OSAPI_EXPORT void +DDS_EXPORT void dds_set_trace_file( - _In_ FILE *file); + FILE *file); /** * @brief Register callback to receive log messages @@ -154,10 +158,10 @@ dds_set_trace_file( * @param[in] userdata User specified data passed along with each invocation * of callback. */ -OSAPI_EXPORT void +DDS_EXPORT void dds_set_log_sink( - _In_opt_ dds_log_write_fn_t callback, - _In_opt_ void *userdata); + dds_log_write_fn_t callback, + void *userdata); /** * @brief Register callback to receive trace messages @@ -175,10 +179,10 @@ dds_set_log_sink( * @param[in] userdata User specified data passed along with each invocation * of callback. */ -OSAPI_EXPORT void +DDS_EXPORT void dds_set_trace_sink( - _In_opt_ dds_log_write_fn_t callback, - _In_opt_ void *userdata); + dds_log_write_fn_t callback, + void *userdata); /** * @brief Write a log or trace message. @@ -188,14 +192,76 @@ dds_set_trace_sink( * Direct use of #dds_log is discouraged. Use #DDS_INFO, #DDS_WARNING, * #DDS_ERROR, #DDS_FATAL or #DDS_LOG instead. */ -OSAPI_EXPORT int +DDS_EXPORT int dds_log( - _In_ uint32_t prio, - _In_z_ const char *file, - _In_ uint32_t line, - _In_z_ const char *func, - _In_z_ _Printf_format_string_ const char *fmt, - ...) __attribute_format__((printf,5,6)); + uint32_t prio, + const char *file, + uint32_t line, + const char *func, + const char *fmt, + ...); + +/** + * @brief Undecorated function name of the current function. + * + * Behavior of DDS_FUNCTION outside a function is undefined. Note that + * implementations differ across compilers and compiler versions. It might be + * implemented as either a string literal or a constant variable. + */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) +# define DDS_FUNCTION __func__ +#elif defined(__cplusplus) && (__cplusplus >= 201103) +# define DDS_FUNCTION __func__ +#elif defined(__GNUC__) +# define DDS_FUNCTION __FUNCTION__ +#elif defined(__clang__) +# define DDS_FUNCTION __FUNCTION__ +#elif defined(__ghs__) +# define DDS_FUNCTION __FUNCTION__ +#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) +/* Solaris Studio had support for __func__ before it supported __FUNCTION__. + Compiler flag -features=extensions is required on older versions. */ +# define DDS_FUNCTION __func__ +#elif defined(__FUNCTION__) +/* Visual Studio */ +# define DDS_FUNCTION __FUNCTION__ +#elif defined(__vxworks) +/* At least versions 2.9.6 and 3.3.4 of the GNU C Preprocessor only define + __GNUC__ if the entire GNU C compiler is in use. VxWorks 5.5 targets invoke + the preprocessor separately resulting in __GNUC__ not being defined. */ +# define DDS_FUNCTION __FUNCTION__ +#else +# warning "DDS_FUNCTION is not supported" +# define DDS_FUNCTION "" +#endif + +/** + * @brief Function signature of the current function. + * + * See comments on DDS_FUNCTION for details. + */ +#if defined(__GNUC__) +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#elif defined(__clang__) +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#elif defined(__ghs__) +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#elif (defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100) +/* Solaris Studio supports __PRETTY_FUNCTION__ in C since version 12.1 */ +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5120) +/* Solaris Studio supports __PRETTY_FUNCTION__ in C++ since version 12.3 */ +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#elif defined(__FUNCSIG__) +/* Visual Studio */ +# define DDS_PRETTY_FUNCTION __FUNCSIG__ +#elif defined(__vxworks) +/* See comments on __vxworks macro above. */ +# define DDS_PRETTY_FUNCTION __PRETTY_FUNCTION__ +#else +/* Fall back to DDS_FUNCTION. */ +# define DDS_PRETTY_FUNCTION DDS_FUNCTION +#endif /** * @brief Write a log message. @@ -211,7 +277,7 @@ dds_log( */ #define DDS_LOG(cat, ...) \ ((dds_get_log_mask() & (cat)) ? \ - dds_log(cat, __FILE__, __LINE__, OS_FUNCTION, __VA_ARGS__) : 0) + dds_log(cat, __FILE__, __LINE__, DDS_FUNCTION, __VA_ARGS__) : 0) /** Write a log message of type #DDS_LC_INFO. */ #define DDS_INFO(...) \ @@ -224,7 +290,7 @@ dds_log( DDS_LOG(DDS_LC_ERROR, __VA_ARGS__) /** Write a log message of type #DDS_LC_ERROR and abort. */ #define DDS_FATAL(...) \ - dds_log(DDS_LC_FATAL, __FILE__, __LINE__, OS_FUNCTION, __VA_ARGS__) + dds_log(DDS_LC_FATAL, __FILE__, __LINE__, DDS_FUNCTION, __VA_ARGS__) /** Write a #DDS_LC_TRACE message. */ #define DDS_TRACE(...) \ DDS_LOG(DDS_LC_TRACE, __VA_ARGS__) diff --git a/src/ddsrt/include/dds/ddsrt/misc.h b/src/ddsrt/include/dds/ddsrt/misc.h new file mode 100644 index 0000000..f01b397 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/misc.h @@ -0,0 +1,81 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_MISC_H +#define DDSRT_MISC_H + +#include + +#if defined (__cplusplus) +extern "C" { +#endif + +#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 +# define DDSRT_GNUC_STR(s) #s +# define DDSRT_GNUC_JOINSTR(x,y) DDSRT_GNUC_DIAG_STR(x ## y) +# define DDSRT_GNUC_DO_PRAGMA(x) _Pragma (#x) +# define DDSRT_GNUC_PRAGMA(x) DDSRT_GNUC_DO_PRAGMA(GCC diagnostic x) +# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 +# define DDSRT_WARNING_GNUC_OFF(x) \ + DDSRT_GNUC_PRAGMA(push) \ + DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x)) +# define DDSRT_WARNING_GNUC_ON(x) \ + DDSRT_GNUC_PRAGMA(pop) +# else +# define DDSRT_WARNING_GNUC_OFF(x) \ + DDSRT_GNUC_PRAGMA(ignored DDSRT_GNUC_JOINSTR(-W,x)) +# define DDSRT_WARNING_GNUC_ON(x) \ + DDSRT_GNUC_PRAGMA(warning DDSRT_GNUC_JOINSTR(-W,x)) +# endif +#else +# define DDSRT_WARNING_GNUC_OFF(x) +# define DDSRT_WARNING_GNUC_ON(x) +#endif + + +#if defined(_MSC_VER) +# define DDSRT_WARNING_MSVC_OFF(x) \ + __pragma (warning(push)) \ + __pragma (warning(disable: ## x)) +# define DDSRT_WARNING_MSVC_ON(x) \ + __pragma (warning(pop)) +#else +# define DDSRT_WARNING_MSVC_OFF(x) +# define DDSRT_WARNING_MSVC_ON(x) +#endif + +/** + * @brief Calculate maximum value of an integer type + * + * A somewhat complex, but efficient way to calculate the maximum value of an + * integer type at compile time. + * + * For unsigned numerical types the first part up to XOR is enough. The second + * part is to make up for signed numerical types. + */ +#define DDSRT_MAX_INTEGER(T) \ + ((T)(((T)~0) ^ ((T)!((T)~0 > 0) << (CHAR_BIT * sizeof(T) - 1)))) +/** + * @brief Calculate minimum value of an integer type + */ +#define DDSRT_MIN_INTEGER(T) \ + ((-DDSRT_MAX_INTEGER(T)) - 1) + +/** + * @brief Macro to disable unused argument warnings + */ +#define DDSRT_UNUSED_ARG(a) (void)(a) + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_MISC_H */ diff --git a/src/ddsrt/include/dds/ddsrt/process.h b/src/ddsrt/include/dds/ddsrt/process.h new file mode 100644 index 0000000..b2be585 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/process.h @@ -0,0 +1,48 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_PROCESS_H +#define DDSRT_PROCESS_H + +#include "dds/export.h" +#include "dds/ddsrt/types.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +#if defined(_WIN32) +typedef DWORD ddsrt_pid_t; +#define PRIdPID "u" +#else /* _WIN32 */ +#include +#if defined(_WRS_KERNEL) +typedef RTP_ID ddsrt_pid_t; /* typedef struct wind_rtp *RTP_ID */ +#define PRIdPID PRIuPTR +#else +typedef pid_t ddsrt_pid_t; +#define PRIdPID "d" +#endif +#endif /* _WIN32 */ + +/** + * @brief Return process ID (PID) of the calling process. + * + * @returns The process ID of the calling process. + */ +DDS_EXPORT ddsrt_pid_t +ddsrt_getpid(void); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_PROCESS_H */ diff --git a/src/os/include/os/windows/os_platform_time.h b/src/ddsrt/include/dds/ddsrt/random.h similarity index 79% rename from src/os/include/os/windows/os_platform_time.h rename to src/ddsrt/include/dds/ddsrt/random.h index e9f21b2..4e44c82 100644 --- a/src/os/include/os/windows/os_platform_time.h +++ b/src/ddsrt/include/dds/ddsrt/random.h @@ -9,19 +9,19 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_TIME_H -#define OS_PLATFORM_TIME_H +#ifndef DDSRT_RANDOM_H +#define DDSRT_RANDOM_H + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { #endif - void os_timeModuleInit(void); - void os_timeModuleExit(void); +DDS_EXPORT long ddsrt_random(void); #if defined (__cplusplus) } #endif -#endif - +#endif /* DDSRT_RANDOM_H */ diff --git a/src/ddsrt/include/dds/ddsrt/retcode.h b/src/ddsrt/include/dds/ddsrt/retcode.h new file mode 100644 index 0000000..8651e22 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/retcode.h @@ -0,0 +1,89 @@ +#ifndef DDS_RETCODE_H +#define DDS_RETCODE_H + +#include + +#include "dds/export.h" + +typedef int32_t dds_retcode_t; + +/* + State is unchanged following a function call returning an error + other than UNSPECIFIED, OUT_OF_RESOURCES and ALREADY_DELETED. + + Error handling functions. Three components to returned int status value. + + 1 - The DDS_ERR_xxx error number + 2 - The file identifier + 3 - The line number + + All functions return >= 0 on success, < 0 on error +*/ + +/** + * @name DDS_Error_Type + * @{ + */ +#define DDS_RETCODE_OK 0 /**< Success */ +#define DDS_RETCODE_ERROR 1 /**< Non specific error */ +#define DDS_RETCODE_UNSUPPORTED 2 /**< Feature unsupported */ +#define DDS_RETCODE_BAD_PARAMETER 3 /**< Bad parameter value */ +#define DDS_RETCODE_PRECONDITION_NOT_MET 4 /**< Precondition for operation not met */ +#define DDS_RETCODE_OUT_OF_RESOURCES 5 /**< When an operation fails because of a lack of resources */ +#define DDS_RETCODE_NOT_ENABLED 6 /**< When a configurable feature is not enabled */ +#define DDS_RETCODE_IMMUTABLE_POLICY 7 /**< When an attempt is made to modify an immutable policy */ +#define DDS_RETCODE_INCONSISTENT_POLICY 8 /**< When a policy is used with inconsistent values */ +#define DDS_RETCODE_ALREADY_DELETED 9 /**< When an attempt is made to delete something more than once */ +#define DDS_RETCODE_TIMEOUT 10 /**< When a timeout has occurred */ +#define DDS_RETCODE_NO_DATA 11 /**< When expected data is not provided */ +#define DDS_RETCODE_ILLEGAL_OPERATION 12 /**< When a function is called when it should not be */ +#define DDS_RETCODE_NOT_ALLOWED_BY_SECURITY 13 /**< When credentials are not enough to use the function */ + + +/* Extended return codes are not in the DDS specification and are meant + exclusively for internal use and must not be returned by the C API. */ +#define DDS_XRETCODE_BASE (50) +#define DDS_XRETCODE(x) (DDS_XRETCODE_BASE + (x)) + +/** Requested resource is busy */ +#define DDS_RETCODE_IN_PROGRESS DDS_XRETCODE(1) +/** Resource unavailable, try again */ +#define DDS_RETCODE_TRY_AGAIN DDS_XRETCODE(2) +/** Operation was interrupted */ +#define DDS_RETCODE_INTERRUPTED DDS_XRETCODE(3) +/** Permission denied */ +#define DDS_RETCODE_NOT_ALLOWED DDS_XRETCODE(4) +/** Host not found */ +#define DDS_RETCODE_HOST_NOT_FOUND DDS_XRETCODE(5) +/** Network is not available */ +#define DDS_RETCODE_NO_NETWORK DDS_XRETCODE(6) +/** Connection is not available */ +#define DDS_RETCODE_NO_CONNECTION DDS_XRETCODE(7) +/* Host not reachable is used to indicate that a connection was refused + (ECONNREFUSED), reset by peer (ECONNRESET) or that a host or network cannot + be reached (EHOSTUNREACH, ENETUNREACH). Generally all system errors that + indicate a connection cannot be made or that a message cannot be delivered, + map onto host not reachable. */ +/** Not enough space available */ +#define DDS_RETCODE_NOT_ENOUGH_SPACE DDS_XRETCODE(8) +/* Not enough space is used to indicate there is not enough buffer space to + read a message from the network (i.e. EMSGSIZE), but is also used to + indicate there is not enough space left on a device, etc. */ +/** Result too large */ +#define DDS_RETCODE_OUT_OF_RANGE DDS_XRETCODE(9) +/** Not found */ +#define DDS_RETCODE_NOT_FOUND DDS_XRETCODE(10) +/** + * @} + */ + +/** + * @brief Takes the error value and outputs a string corresponding to it. + * + * @param[in] err Error value to be converted to a string + * + * @returns String corresponding to the error value + */ +DDS_EXPORT const char *dds_strretcode(dds_retcode_t ret); + +#endif /* DDS_RETCODE_H */ diff --git a/src/ddsrt/include/dds/ddsrt/rusage.h b/src/ddsrt/include/dds/ddsrt/rusage.h new file mode 100644 index 0000000..2147876 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/rusage.h @@ -0,0 +1,50 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_RUSAGE_H +#define DDSRT_RUSAGE_H + +#include + +#include "dds/ddsrt/time.h" +#include "dds/ddsrt/retcode.h" + +typedef struct { + dds_time_t utime; /* User CPU time used. */ + dds_time_t stime; /* System CPU time used. */ + size_t maxrss; /* Maximum resident set size in bytes. */ + size_t idrss; /* Integral unshared data size. Not maintained on (at least) + Linux and Windows. */ + size_t nvcsw; /* Voluntary context switches. Not maintained on Windows. */ + size_t nivcsw; /* Involuntary context switches. Not maintained on Windows. */ +} ddsrt_rusage_t; + +#define DDSRT_RUSAGE_SELF (0) +#define DDSRT_RUSAGE_THREAD (1) + +/** + * @brief Get resource usage for the current thread or process. + * + * @param[in] who DDSRT_RUSAGE_SELF or DDSRT_RUSAGE_THREAD. + * @param[in] usage Structure where resource usage is returned. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Resource usage successfully returned in @usage. + * @retval DDS_RETCODE_OUT_OF_RESOURCES + * There were not enough resources to get resource usage. + * @retval DDS_RETCODE_ERROR + * An unidentified error occurred. + */ +DDS_EXPORT dds_retcode_t ddsrt_getrusage(int who, ddsrt_rusage_t *usage); + +#endif /* DDSRT_RUSAGE_H */ diff --git a/src/ddsrt/include/dds/ddsrt/sockets.h b/src/ddsrt/include/dds/ddsrt/sockets.h new file mode 100644 index 0000000..4d25387 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/sockets.h @@ -0,0 +1,262 @@ +#ifndef DDSRT_SOCKETS_H +#define DDSRT_SOCKETS_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/types.h" +#include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/time.h" +#if !defined(_WIN32) +#include "dds/ddsrt/sockets/posix.h" +#else +#include "dds/ddsrt/sockets/windows.h" +#endif + +#if DDSRT_HAVE_IPV6 +#define INET6_ADDRSTRLEN_EXTENDED (INET6_ADDRSTRLEN + 8) /* "[]:12345" */ +extern const struct in6_addr ddsrt_in6addr_any; +extern const struct in6_addr ddsrt_in6addr_loopback; +#endif /* DDSRT_HAVE_IPV6 */ + +#define DDSRT_AF_TERM (-1) + +DDS_EXPORT dds_retcode_t +ddsrt_gethostname( + char *hostname, + size_t buffersize); + +DDS_EXPORT dds_retcode_t +ddsrt_socket( + ddsrt_socket_t *sockptr, + int domain, + int type, + int protocol); + +DDS_EXPORT dds_retcode_t +ddsrt_close( + ddsrt_socket_t sock); + +DDS_EXPORT dds_retcode_t +ddsrt_connect( + ddsrt_socket_t sock, + const struct sockaddr *addr, + socklen_t addrlen); + +DDS_EXPORT dds_retcode_t +ddsrt_accept( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen, + ddsrt_socket_t *connptr); + +DDS_EXPORT dds_retcode_t +ddsrt_listen( + ddsrt_socket_t sock, + int backlog); + +DDS_EXPORT dds_retcode_t +ddsrt_bind( + ddsrt_socket_t sock, + const struct sockaddr *addr, + socklen_t addrlen); + +DDS_EXPORT dds_retcode_t +ddsrt_getsockname( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen); + +DDS_EXPORT dds_retcode_t +ddsrt_send( + ddsrt_socket_t sock, + const void *buf, + size_t len, + int flags, + ssize_t *sent); + +DDS_EXPORT dds_retcode_t +ddsrt_sendmsg( + ddsrt_socket_t sock, + const ddsrt_msghdr_t *msg, + int flags, + ssize_t *sent); + +DDS_EXPORT dds_retcode_t +ddsrt_recv( + ddsrt_socket_t sock, + void *buf, + size_t len, + int flags, + ssize_t *rcvd); + +DDS_EXPORT dds_retcode_t +ddsrt_recvmsg( + ddsrt_socket_t sock, + ddsrt_msghdr_t *msg, + int flags, + ssize_t *rcvd); + +DDS_EXPORT dds_retcode_t +ddsrt_getsockopt( + ddsrt_socket_t sock, + int32_t level, /* SOL_SOCKET */ + int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */ + void *optval, + socklen_t *optlen); + +DDS_EXPORT dds_retcode_t +ddsrt_setsockopt( + ddsrt_socket_t sock, + int32_t level, /* SOL_SOCKET */ + int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */ + const void *optval, + socklen_t optlen); + +/** + * @brief Set the I/O on the socket to blocking or non-nonblocking. + * + * @param[in] sock Socket to set I/O mode for. + * @param[in] nonblock true for nonblocking, or false for blocking I/O. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * I/O mode successfully set to (non)blocking. + * @retval DDS_RETCODE_TRY_AGAIN + * A blocking call is in progress. + * @retval DDS_RETCODE_BAD_PARAMETER + * @sock is not a valid socket. + * @retval DDS_RETCODE_ERROR + * An unknown error error occurred. + */ +DDS_EXPORT dds_retcode_t +ddsrt_setsocknonblocking( + ddsrt_socket_t sock, + bool nonblock); + +DDS_EXPORT int32_t +ddsrt_select( + int32_t nfds, + fd_set *readfds, + fd_set *writefds, + fd_set *errorfds, + dds_duration_t reltime, + int32_t *ready); + +#if _WIN32 +/* SOCKETs on Windows are NOT integers. The nfds parameter is only there for + compatibility, the implementation ignores it. Implicit casts will generate + warnings though, therefore ddsrt_select is redefined to discard the + parameter on Windows. */ +#define ddsrt_select(nfds, readfds, writefds, errorfds, timeout, ready) \ + ddsrt_select(-1, readfds, writefds, errorfds, timeout, ready) +#endif /* _WIN32 */ + +/** + * @brief Get the size of a socket address. + * + * @param[in] sa Socket address to return the size for. + * + * @returns Size of the socket address based on the address family, or 0 if + * the address family is unknown. + */ +DDS_EXPORT socklen_t +ddsrt_sockaddr_get_size( + const struct sockaddr *const sa) ddsrt_nonnull_all; + +/** + * @brief Get the port number from a socket address. + * + * @param[in] sa Socket address to retrieve the port from. + * + * @return Port number in host order. + */ +DDS_EXPORT uint16_t +ddsrt_sockaddr_get_port( + const struct sockaddr *const sa) ddsrt_nonnull_all; + +/** + * @brief Check if the given address is unspecified. + * + * @param[in] sa Socket address to check. + * + * @return true if the address is unspecified, false otherwise. + */ +DDS_EXPORT bool +ddsrt_sockaddr_isunspecified( + const struct sockaddr *__restrict sa) ddsrt_nonnull_all; + +/** + * @brief Check if the given address is a loopback address. + * + * @param[in] sa Socket address to check. + * + * @return true if the address is a loopback address, false otherwise. + */ +DDS_EXPORT bool +ddsrt_sockaddr_isloopback( + const struct sockaddr *__restrict sa) ddsrt_nonnull_all; + +/** + * @brief Check if given socket IP addresses reside in the same subnet. + * + * Checks if two socket IP addresses reside in the same subnet, considering the + * given subnetmask. IPv6 mapped IPv4 addresses are not taken in account. + * + * @param[in] sa1 First address + * @param[in] sa2 Second address. + * @param[in] mask Subnetmask. + * + * @returns true if both addresses reside in the same subnet, false otherwise. + */ +DDS_EXPORT bool +ddsrt_sockaddr_insamesubnet( + const struct sockaddr *sa1, + const struct sockaddr *sa2, + const struct sockaddr *mask) +ddsrt_nonnull_all; + +DDS_EXPORT dds_retcode_t +ddsrt_sockaddrfromstr( + int af, const char *str, void *sa); + +DDS_EXPORT dds_retcode_t +ddsrt_sockaddrtostr( + const void *sa, char *buf, size_t size); + +#if DDSRT_HAVE_DNS +typedef struct { + size_t naddrs; + struct sockaddr_storage addrs[]; +} ddsrt_hostent_t; + +/** + * @brief Lookup addresses for given host name. + * + * @param[in] name Host name to resolve. + * @param[in] af Address family, either AF_INET, AF_INET6 or AF_UNSPEC. + * @param[out] hent Structure of type ddsrt_hostent_t. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Host name successfully resolved to address(es). + * @retval DDS_RETCODE_HOST_NOT_FOUND + * Host not found. + * @retval DDS_RETCODE_NO_DATA + * Valid name, no data record of requested type. + * @retval DDS_RETCODE_ERROR + * Nonrecoverable error. + * @retval DDS_RETCODE_TRY_AGAIN + * Nonauthoratitative host not found. + */ +DDS_EXPORT dds_retcode_t +ddsrt_gethostbyname( + const char *name, + int af, + ddsrt_hostent_t **hentp); +#endif + +#endif /* DDSRT_SOCKETS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/sockets/posix.h b/src/ddsrt/include/dds/ddsrt/sockets/posix.h new file mode 100644 index 0000000..a9697af --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/sockets/posix.h @@ -0,0 +1,54 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_SOCKETS_POSIX_H +#define DDSRT_SOCKETS_POSIX_H + +#include +#include +#include +#include +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +typedef int ddsrt_socket_t; +#define DDSRT_INVALID_SOCKET (-1) +#define PRIdSOCK "d" + +#define DDSRT_HAVE_IPV6 1 +#define DDSRT_HAVE_DNS 1 +#define DDSRT_HAVE_SSM 1 + +typedef struct iovec ddsrt_iovec_t; +typedef size_t ddsrt_iov_len_t; + +#if defined(__linux) +typedef size_t ddsrt_msg_iovlen_t; +#else /* POSIX says int (which macOS, FreeBSD, Solaris do) */ +typedef int ddsrt_msg_iovlen_t; +#endif +typedef struct msghdr ddsrt_msghdr_t; + +#if defined(__sun) && !defined(_XPG4_2) +# define DDSRT_MSGHDR_FLAGS 0 +#else +# define DDSRT_MSGHDR_FLAGS 1 +#endif + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_SOCKETS_POSIX_H */ diff --git a/src/ddsrt/include/dds/ddsrt/sockets/windows.h b/src/ddsrt/include/dds/ddsrt/sockets/windows.h new file mode 100644 index 0000000..277dfe7 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/sockets/windows.h @@ -0,0 +1,52 @@ +#ifndef DDSRT_WINDOWS_SOCKET_H +#define DDSRT_WINDOWS_SOCKET_H + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +typedef SOCKET ddsrt_socket_t; +#define DDSRT_INVALID_SOCKET (INVALID_SOCKET) +#define PRIdSOCK PRIuPTR + +#define DDSRT_HAVE_IPV6 1 +#define DDSRT_HAVE_DNS 1 + +#if defined(NTDDI_VERSION) && \ + defined(_WIN32_WINNT_WS03) && \ + (NTDDI_VERSION >= _WIN32_WINNT_WS03) +#define DDSRT_HAVE_SSM 1 +#else +#define DDSRT_HAVE_SSM 0 +#endif + +#define IFF_POINTOPOINT IFF_POINTTOPOINT + +typedef unsigned ddsrt_iov_len_t; +typedef struct ddsrt_iovec { + ddsrt_iov_len_t iov_len; + void *iov_base; +} ddsrt_iovec_t; + +typedef DWORD ddsrt_msg_iovlen_t; + +typedef struct ddsrt_msghdr { + void *msg_name; + socklen_t msg_namelen; + ddsrt_iovec_t *msg_iov; + ddsrt_msg_iovlen_t msg_iovlen; + void *msg_control; + size_t msg_controllen; + int msg_flags; +} ddsrt_msghdr_t; + +#define DDSRT_MSGHDR_FLAGS 1 + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_WINDOWS_SOCKET_H */ diff --git a/src/ddsrt/include/dds/ddsrt/string.h b/src/ddsrt/include/dds/ddsrt/string.h new file mode 100644 index 0000000..0023d12 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/string.h @@ -0,0 +1,198 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_STRING_H +#define DDSRT_STRING_H + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/retcode.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +/** + * @brief Compare two strings ignoring case. + * + * @param[in] s1 String to compare. + * @param[in] s2 String to compare. + * + * @returns Zero if @s1 and @s2 match, a negative integer if @s1 is less than + * @s2 or a positive integer if @s1 is greater than @s2. + */ +DDS_EXPORT int +ddsrt_strcasecmp( + const char *s1, + const char *s2) +ddsrt_nonnull_all; + +/** + * @brief Compare two strings ignoring case, but no more than @n bytes. + * + * @param[in] s1 String to compare. + * @param[in] s2 String to compare. + * @param[in] n Maximum number of bytes to compare. + * + * @returns Zero if @s1 and @s2 match, a negative integer if @s1 is less than + * @s2 or a positive integer if @s1 is greater than @s2. + */ +DDS_EXPORT int +ddsrt_strncasecmp( + const char *s1, + const char *s2, + size_t n) +ddsrt_nonnull((1,2)); + +/** + * @brief Split string into tokens. + * + * @param[in] str String to split into tokens. + * @param[in] delim Characters that delimit a token. + * @param[inout] saveptr Pointer to a char * used internally. + * + * @returns The next token or NULL if there are no more tokens. + */ +DDS_EXPORT char * +ddsrt_strtok_r( + char *str, + const char *delim, + char **saveptr); + +/** + * @brief Extract token from string. + * + * Finds the first token in @stringp delimited by one of the characters in + * @delim. The delimiter is overwritten with a null byte, terminating the + * token and @stringp is updated to point past the delimiter. + * + * @param[inout] stringp String to extract token from. + * @param[in] delim Characters that delimit a token. + * + * @returns The original value of @stringp. + */ +DDS_EXPORT char * +ddsrt_strsep( + char **stringp, + const char *delim); + +/** + * @brief Duplicate block of memory. + * + * Copy a block of memory into a newly allocated block of memory. The memory + * is obtained with @ddsrt_malloc and must be freed with @ddsrt_free when it + * is no longer used. + * + * @param[in] ptr Pointer to block of memory to duplicate. + * @param[in] len Number of bytes to copy into newly allocated buffer. + * + * @returns A new block of memory that is a duplicate of the block pointed to + * by @ptr or NULL if not enough memory was available. + */ +DDS_EXPORT void * +ddsrt_memdup( + const void *ptr, + size_t len) +ddsrt_nonnull((1)) +ddsrt_attribute_malloc; + +/** + * @brief Duplicate string. + * + * Copy string into a newly allocated block of memory. The memory is obtained + * with @ddsrt_malloc and must freed with @ddsrt_free when it is no longer + * used. + * + * @param[in] str String to duplicate. + * + * @returns A new string that is a duplicate of @str or NULL if not enough + * memory was available. + */ +DDS_EXPORT char * +ddsrt_strdup( + const char *str) +ddsrt_nonnull_all +ddsrt_attribute_malloc; + +/** + * @brief Copy string. + * + * Copy string to buffer with specified size. The string is truncated if there + * is not enough space. The resulting string is guaranteed to be null + * terminated if there is space. + * + * @param[out] dest Destination buffer. + * @param[in] src Null terminated string to copy to dest. + * @param[in] size Number of bytes available in dest. + * + * @returns Number of characters copied to dest (excluding the null byte), or + * the number of characters that would have been copied if dest is not + * sufficiently large enough. + */ +DDS_EXPORT +size_t +ddsrt_strlcpy( + char * __restrict dest, + const char * __restrict src, + size_t size) +ddsrt_nonnull((1,2)); + +/** + * @brief Concatenate strings. + * + * Append the string specified by src to the string specified by dest. The + * terminating null byte at the end of dest is overwritten. The resulting + * string is truncated if there is not enough space. The resulting string + * guaranteed to be null terminated if there is space. + * + * @param[inout] dest Destination buffer. + * @param[in] src Null terminated string to append to dest. + * @param[in] size Number of bytes available in dest. + * + * @returns Number of characters copied to dest (excluding the null byte), or + * the number of characters that would have been copied if dest is not + * sufficiently large enough. + */ +DDS_EXPORT +size_t +ddsrt_strlcat( + char * __restrict dest, + const char * __restrict src, + size_t size) +ddsrt_nonnull((1,2)); + +/** + * @brief Get description for specified system error number. + * + * @param[in] errnum System error number. + * @param[in] buf Buffer where description is copied to. + * @param[in] buflen Number of bytes available in @buf. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Description for @errnum was successfully copied to @buf. + * @retval DDS_RETCODE_BAD_PARAMETER + * Unknown error number. + * @retval DDS_RETCODE_NOT_ENOUGH_SPACE + * Buffer was not large enough to hold the description. + */ +DDS_EXPORT dds_retcode_t +ddsrt_strerror_r( + int errnum, + char *buf, + size_t buflen); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_STRING_H */ diff --git a/src/ddsrt/include/dds/ddsrt/strtod.h b/src/ddsrt/include/dds/ddsrt/strtod.h new file mode 100644 index 0000000..739ee94 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/strtod.h @@ -0,0 +1,75 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +/** + * @file strtod.h + * @brief Floating-point number to/from string conversion functions. + * + * Locale independent versions of the floating-point number conversion + * functions found in the standard library. + */ +#ifndef DDSRT_STRTOD_H +#define DDSRT_STRTOD_H + +#include "dds/export.h" +#include "dds/ddsrt/retcode.h" + +/** + * @brief Convert a string to a double precision floating point number. + * + * @param[in] nptr A string to convert into a double. + * @param[out] endptr If not NULL, a char* where the address of first invalid + * character is stored. + * @param[out] dblptr A double where the result is stored. + * + * @returns A dds_retcode_t indicating success or failure. + */ +DDS_EXPORT dds_retcode_t +ddsrt_strtod(const char *nptr, char **endptr, double *dblptr); + +/** + * @brief Convert a string to a floating point number. + * + * @param[in] nptr A string to convert into a float. + * @param[in] endptr If not NULL, a char* where the address of first invalid + * character is stored. + * @param[out] fltptr A float where the floating-point number is stored. + * + * @returns A dds_retcode_t indicating success or failure. + */ +DDS_EXPORT dds_retcode_t +ddsrt_strtof(const char *nptr, char **endptr, float *fltptr); + +/** + * @brief Convert a double-precision floating-point number to a string. + * + * @param[in] src Double-precision floating-point number to convert. + * @param[in] str Buffer where string representation is written. + * @param[in] size Number of bytes available in @str. + * + * @returns The number of bytes written (excluding the null terminating byte). + */ +DDS_EXPORT int +ddsrt_dtostr(double src, char *str, size_t size); + +/** + * @brief convert a floating-point number to a string. + * + * @param[in] src Floating-point number to conver. + * @param[in] str Buffer where string representation is written. + * @param[in] size Number of bytes available in @str. + * + * @returns The number of bytes written (exluding the null terminating byte). + */ +DDS_EXPORT int +ddsrt_ftostr(float src, char *str, size_t size); + +#endif /* DDSRT_STRTOD_H */ diff --git a/src/ddsrt/include/dds/ddsrt/strtol.h b/src/ddsrt/include/dds/ddsrt/strtol.h new file mode 100644 index 0000000..a862c06 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/strtol.h @@ -0,0 +1,168 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_STRTOL_H +#define DDSRT_STRTOL_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/retcode.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * @brief Convert a string to a long long integer. + * + * Translate @str to a long long integer considering base, and sign. If @base + * is 0, base is determined from @str. A prefix of "0x" or "0X" will cause the + * number be read in base 16 (hexadecimal), otherwise base 10 (decimal) is + * used, unless the first character is '0', in which case the number will be + * read in base 8 (octal). + * + * @param[in] str String to convert into a number. + * @param[out] endptr If not NULL, a char* where the address of first invalid + * character is stored. + * @param[in] base Base to use. Must be a base between 2 and 36, or 0 to + * determine from @str. + * @param[out] llng A long long integer where the number is stored. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * String successfully converted to an integer. + * @retval DDS_RETCODE_BAD_PARAMETER + * Base is invalid. + * @retval DDS_RETCODE_OUT_OF_RANGE + * String converted to an integer, but was out of range. + */ +DDS_EXPORT dds_retcode_t +ddsrt_strtoll( + const char *str, + char **endptr, + int32_t base, + long long *llng); + +/** + * @brief Convert a string to an unsigned long long integer. + * + * Translate @str to an unsigned long long integer considering base, and sign. + * If @base is 0, base is determined from @str. A prefix of "0x" or "0X" will + * cause the number be read in base 16 (hexadecimal), otherwise base 10 + * (decimal) is used, unless the first character is '0', in which case the + * number will be read in base 8 (octal). + * + * @param[in] str String to convert into a number. + * @param[out] endptr If not NULL, a char* where the address of first invalid + * character is stored. + * @param[in] base Base to use. Must be a base between 2 and 36, or 0 to + * determine from @str. + * @param[out] ullng A long long integer where the number is stored. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * String successfully converted to an integer. + * @retval DDS_RETCODE_BAD_PARAMETER + * Base is invalid. + * @retval DDS_RETCODE_OUT_OF_RANGE + * String converted to an integer, but was out of range. + */ +DDS_EXPORT dds_retcode_t +ddsrt_strtoull( + const char *str, + char **endptr, + int32_t base, + unsigned long long *ullng); + +/** + * @brief Convert a string to a long long integer. + * + * @param[in] str String to convert into a long long integer. + * @param[in] llng A long long integer where the number is stored. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * String successfully converted to an integer. + * @retval DDS_RETCODE_BAD_PARAMETER + * Base is invalid. + * @retval DDS_RETCODE_OUT_OF_RANGE + * String converted to an integer, but was out of range. + */ +DDS_EXPORT dds_retcode_t +ddsrt_atoll( + const char *str, + long long *llng); + +/** + * @brief Convert a string to an unsigned long long integer. + * + * @param[in] str String to conver into an unsigned long long integer. + * @param[out] ullng An unsigned long long integer where the number is stored. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * String successfully converted to an integer. + * @retval DDS_RETCODE_BAD_PARAMETER + * Base is invalid. + * @retval DDS_RETCODE_OUT_OF_RANGE + * String converted to an integer, but was out of range. + */ +DDS_EXPORT dds_retcode_t +ddsrt_atoull( + const char *str, + unsigned long long *ullng); + +/** + * @brief Convert a long long integer into a string. + * + * @param[in] num Long long integer to convert into a string. + * @param[in] str Buffer where string representation is written. + * @param[in] len Number of bytes available in buffer. + * @param[out] endptr A char* where the address of the null terminating byte + * is stored. + * + * @returns The value of @str on success, otherwise NULL. + */ +DDS_EXPORT char * +ddsrt_lltostr( + long long num, + char *str, + size_t len, + char **endptr); + +/** + * @brief Convert an unsigned long long integer into a string. + * + * @param[in] num Unsigned long long integer to covert into a string. + * @param[in] str Buffer where string representation is stored. + * @param[in] len Number of bytes available in buffer. + * @param[out] endptr A char* where the adress of the null terminating byte + * is stored. + * + * @returns The value of @str on success, otherwise NULL. + */ +DDS_EXPORT char * +ddsrt_ulltostr( + unsigned long long num, + char *str, + size_t len, + char **endptr); + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_STRTOL_H */ diff --git a/src/ddsrt/include/dds/ddsrt/sync.h b/src/ddsrt/include/dds/ddsrt/sync.h new file mode 100644 index 0000000..8228aab --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/sync.h @@ -0,0 +1,298 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_SYNC_H +#define DDSRT_SYNC_H + +#include + +#include "dds/ddsrt/time.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/attributes.h" + +#if _WIN32 +#include "dds/ddsrt/sync/windows.h" +#else +#include "dds/ddsrt/sync/posix.h" +#endif + +#if defined (__cplusplus) +extern "C" { +#endif + +/** + * @brief Initialize a mutex. + * + * @param[in] mutex Mutex to itialize. + */ +DDS_EXPORT void +ddsrt_mutex_init( + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all; + +/** + * @brief Destroy a mutex. + * + * @param[in] mutex Mutex to destroy. + */ +DDS_EXPORT void +ddsrt_mutex_destroy( + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all; + +/** + * @brief Acquire a mutex. + * + * @param[in] mutex Mutex to acquire. + */ +DDS_EXPORT void +ddsrt_mutex_lock( + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all; + +/** + * @brief Acquire a mutex if it is not already acquired. + * + * @param[in] mutex Mutex to acquire. + * + * @returns true if the mutex was acquired, false otherwise. + */ +DDS_EXPORT bool +ddsrt_mutex_trylock( + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all +ddsrt_attribute_warn_unused_result; + +/** + * @brief Release an acquired mutex. + * + * @param[in] mutex Mutex to release. + */ +DDS_EXPORT void +ddsrt_mutex_unlock ( + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all; + +/** + * @brief Initialize a condition variable. + * + * @param[in] cond Condition variable to initialize. + */ +DDS_EXPORT void +ddsrt_cond_init( + ddsrt_cond_t *cond) +ddsrt_nonnull_all; + +/** + * @brief Destroy a condition variable. + * + * @param[in] cond Condition variable to destroy. + */ +DDS_EXPORT void +ddsrt_cond_destroy( + ddsrt_cond_t *cond) +ddsrt_nonnull_all; + +/** + * @brief Wait for a condition variable to be signalled. + * + * @param[in] cond Condition variable to block on. + * @param[in] mutex Mutex to associate with condition variable. + * + * @pre The calling thread must hold the mutex specified by @mutex. + * + * @post The calling thread will hold the mutex specified by @mutex. + */ +DDS_EXPORT void +ddsrt_cond_wait( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex) +ddsrt_nonnull_all; + +/** + * @brief Wait until @abstime for a condition variable to be signalled. + * + * @param[in] cond Condition variable to block on. + * @param[in] mutex Mutex to associate with condition variable. + * @param[in] abstime Time in nanoseconds since UNIX Epoch. + * + * @pre The calling thread must hold the mutex specified by @mutex. + * + * @post The calling thread will hold the mutex specified by @mutex. + * + * @returns false if the condition variable was not signalled before the + * absolute time specified by @abstime passed, otherwise true. + */ +DDS_EXPORT bool +ddsrt_cond_waituntil( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_time_t abstime) +ddsrt_nonnull((1,2)); + +/** + * @brief Wait for @reltime for a condition variable to be signalled. + * + * @param[in] cond Condition variable to block on. + * @param[in] mutex Mutex to associate with condition variable. + * @param[in] reltime Time in nanoseconds since UNIX Epoch. + * + * @pre The calling thread must hold the mutex specified by @mutex. + * + * @post The calling thread will hold the mutex specified by @mutex. + * + * @returns false if the condition variable was not signalled before the + * relative time specified by @reltime passed, otherwise true. + */ +DDS_EXPORT bool +ddsrt_cond_waitfor( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_duration_t reltime) +ddsrt_nonnull((1,2)); + +/** + * @brief Signal a condition variable and unblock at least one thread. + * + * @param[in] cond Condition variable to signal. + * + * @pre The mutex associated with the condition in general should be acquired + * by the calling thread before setting the condition state and + * signalling. + */ +DDS_EXPORT void +ddsrt_cond_signal( + ddsrt_cond_t *cond) +ddsrt_nonnull_all; + +/** + * @brief Signal a condition variable and unblock all threads. + * + * @param[in] cond Condition variable to signal. + * + * @pre The mutex associated with the condition in general should be acquired + * by the calling thread before setting the condition state and + * signalling + */ +DDS_EXPORT void +ddsrt_cond_broadcast( + ddsrt_cond_t *cond) +ddsrt_nonnull_all; + +/** + * @brief Initialize a read-write lock. + * + * @param[in] rwlock Read-write lock to initialize. + */ +DDS_EXPORT void +ddsrt_rwlock_init( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all; + +/** + * @brief Destroy a read-write lock. + * + * @param[in] rwlock Read-write lock to destroy. + */ +DDS_EXPORT void +ddsrt_rwlock_destroy( + ddsrt_rwlock_t *rwlock); + +/** + * @brief Acquire a read-write lock for reading. + * + * @param[in] rwlock Read-write lock to acquire. + * + * @post Data related to the critical section must not be changed by the + * calling thread. + */ +DDS_EXPORT void +ddsrt_rwlock_read( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all; + +/** + * @brief Acquire a read-write lock for writing. + * + * @param[in] rwlock Read-write lock to acquire. + */ +DDS_EXPORT void +ddsrt_rwlock_write( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all; + +/** + * @brief Try to acquire a read-write lock for reading. + * + * Try to acquire a read-write lock while for reading, immediately return if + * the lock is already exclusively acquired by another thread. + * + * @param[in] rwlock Read-write lock to aqcuire. + * + * @post Data related to the critical section must not changed by the + * calling thread. + * + * @returns true if the lock was acquired, otherwise false. + */ +DDS_EXPORT bool +ddsrt_rwlock_tryread( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all +ddsrt_attribute_warn_unused_result; + +/** + * @brief Try to acquire a read-write lock for writing. + * + * Try to acquire a read-write lock for writing, immediately return if the + * lock is already acquired, either for reading or writing, by another thread. + * + * @param[in] rwlock Read-write lock to acquire. + * + * @returns true if the lock was acquired, otherwise false. + */ +DDS_EXPORT bool +ddsrt_rwlock_trywrite( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all +ddsrt_attribute_warn_unused_result; + +/** + * @brief Release a previously acquired read-write lock. + * + * @param[in] rwlock Read-write lock to release. + */ +DDS_EXPORT void +ddsrt_rwlock_unlock( + ddsrt_rwlock_t *rwlock) +ddsrt_nonnull_all; + +/* Initialization callback used by ddsrt_once */ +typedef void (*ddsrt_once_fn)(void); + +/** + * @brief Invoke init_fn exactly once for a given control. + * + * The first thread to call this function with a given control will call the + * function specified by @init_fn with no arguments. All following calls with + * the same control will not call the specified function. + * + * @pre The control parameter is properly initialized with DDSRT_ONCE_INIT. + */ +DDS_EXPORT void +ddsrt_once( + ddsrt_once_t *control, + ddsrt_once_fn init_fn); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_SYNC_H */ diff --git a/src/os/include/os/posix/os_platform_thread.h b/src/ddsrt/include/dds/ddsrt/sync/posix.h similarity index 57% rename from src/os/include/os/posix/os_platform_thread.h rename to src/ddsrt/include/dds/ddsrt/sync/posix.h index 563bc72..c13d8e7 100644 --- a/src/os/include/os/posix/os_platform_thread.h +++ b/src/ddsrt/include/dds/ddsrt/sync/posix.h @@ -9,25 +9,36 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_THREAD_H -#define OS_PLATFORM_THREAD_H +#ifndef DDSRT_POSIX_SYNC_H +#define DDSRT_POSIX_SYNC_H +#include #include +#if HAVE_LKST +#include "lkst.h" +#endif #if defined (__cplusplus) extern "C" { #endif - /* Wrapped in a struct to help programmers conform to the abstraction. */ - typedef struct os_threadId_s { - pthread_t v; /* Don't touch directly (except for maybe a test or the os-abstraction implementation itself). */ - } os_threadId; +typedef struct { + pthread_cond_t cond; +} ddsrt_cond_t; - void os_threadModuleInit (void); - void os_threadModuleExit (void); +typedef struct { + pthread_mutex_t mutex; +} ddsrt_mutex_t; + +typedef struct { + pthread_rwlock_t rwlock; +} ddsrt_rwlock_t; + +typedef pthread_once_t ddsrt_once_t; +#define DDSRT_ONCE_INIT PTHREAD_ONCE_INIT #if defined (__cplusplus) } #endif -#endif +#endif /* DDSRT_POSIX_SYNC_H */ diff --git a/src/os/include/os/windows/os_platform_thread.h b/src/ddsrt/include/dds/ddsrt/sync/windows.h similarity index 56% rename from src/os/include/os/windows/os_platform_thread.h rename to src/ddsrt/include/dds/ddsrt/sync/windows.h index d3f6664..a0696e0 100644 --- a/src/os/include/os/windows/os_platform_thread.h +++ b/src/ddsrt/include/dds/ddsrt/sync/windows.h @@ -9,25 +9,31 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_THREAD_H -#define OS_PLATFORM_THREAD_H - -#include "os_defs.h" +#ifndef DDSRT_WINDOWS_SYNC_H +#define DDSRT_WINDOWS_SYNC_H #if defined (__cplusplus) extern "C" { #endif - typedef struct os_threadInfo_s { - DWORD threadId; - HANDLE handle; - } os_threadId; +typedef struct { + CONDITION_VARIABLE cond; +} ddsrt_cond_t; - os_result os_threadModuleInit (void); - void os_threadModuleExit (void); +typedef struct { + SRWLOCK lock; +} ddsrt_mutex_t; + +typedef struct os_rwlock { + SRWLOCK lock; + int state; /* -1: exclusive, 0: free, 1: shared */ +} ddsrt_rwlock_t; + +typedef INIT_ONCE ddsrt_once_t; +#define DDSRT_ONCE_INIT INIT_ONCE_STATIC_INIT #if defined (__cplusplus) } #endif -#endif +#endif /* DDSRT_WINDOWS_SYNC_H */ diff --git a/src/ddsrt/include/dds/ddsrt/threads.h b/src/ddsrt/include/dds/ddsrt/threads.h new file mode 100644 index 0000000..7497002 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/threads.h @@ -0,0 +1,262 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +/** + * @file threads.h + * @brief Thread management and creation. + * + * Platform independent interface for managing and creating execution threads. + */ +#ifndef DDSRT_THREADS_H +#define DDSRT_THREADS_H + +#include +#include + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/retcode.h" + +#if _WIN32 +#include "dds/ddsrt/threads/windows.h" +#else +#include "dds/ddsrt/threads/posix.h" +#endif + +#if defined (__cplusplus) +extern "C" { +#endif + +#if defined(_MSC_VER) + /* Thread-local storage using __declspec(thread) on Windows versions before + Vista and Server 2008 works in DLLs if they are bound to the executable, + it does not work if the library is loaded using LoadLibrary. */ +#define ddsrt_thread_local __declspec(thread) +#elif defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 2) + /* GCC supports Thread-local storage for x86 since version 3.3. Clang + supports Thread-local storage since version 2.0. */ + /* VxWorks 7 supports __thread for both GCC and DIAB, older versions may + support it as well, but that is not verified. */ +#define ddsrt_thread_local __thread +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) +#define ddsrt_thread_local __thread +#else +#error "Thread-local storage is not supported" +#endif + +/** + * @brief Definition for a thread routine invoked on thread create. + */ +typedef uint32_t (*ddsrt_thread_routine_t)(void*); + +/** + * @brief Thread scheduling classes + * @{ + */ +typedef enum { + /** Schedule processes and threads according a platform default. + * DDSRT_SCHED_REALTIME for timesharing platforms and + * DDSRT_SCHED_TIMESHARE for realtime platforms + */ + DDSRT_SCHED_DEFAULT, + /** Schedule processes and threads on realtime basis, + * on most platforms implying: + * - Fixed Priority + * - Preemption + * - Either "First In First Out" or "Round Robin" + */ + DDSRT_SCHED_REALTIME, + /** Schedule processes and threads on timesharing basis, + * on most platforms implying: + * - Dynamic Priority to guarantee fair share + * - Preemption + */ + DDSRT_SCHED_TIMESHARE +} ddsrt_sched_t; +/** @} */ + +/** + * @brief Definition of the thread attributes + */ +typedef struct { + /** Specifies the scheduling class */ + ddsrt_sched_t schedClass; + /** Specifies the thread priority */ + int32_t schedPriority; + /** Specifies the thread stack size */ + uint32_t stackSize; +} ddsrt_threadattr_t; + +/** + * @brief Initialize thread attributes to platform defaults. + */ +DDS_EXPORT void +ddsrt_threadattr_init( + ddsrt_threadattr_t *attr) +ddsrt_nonnull_all; + +/** + * @brief Create a new thread. + * + * Creates a new thread of control that executes concurrently with + * the calling thread. The new thread applies the function start_routine + * passing it arg as first argument. + * + * The new thread terminates by returning from the start_routine function. + * The created thread is identified by the returned threadId. + * + * @param[out] thread Location where thread id is stored. + * @param[in] name Name assigned to created thread. + * @param[in] attr Attributes to create thread with. + * @param[in] start_routine Function to execute in created thread. + * @param[in] arg Argument passed to @start_routine. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Thread successfully created. + * @retval DDS_RETCODE_ERROR + * Thread could not be created. + */ +DDS_EXPORT dds_retcode_t +ddsrt_thread_create( + ddsrt_thread_t *thread, + const char *name, + const ddsrt_threadattr_t *attr, + ddsrt_thread_routine_t start_routine, + void *arg) +ddsrt_nonnull((1,2,3,4)); + +/** + * @brief Retrieve integer representation of the given thread id. + * + * @returns The integer representation of the given thread. + */ +DDS_EXPORT ddsrt_tid_t +ddsrt_gettid(void); + +/** + * @brief Return thread ID of the calling thread. + * + * @returns Thread ID of the calling thread. + */ +DDS_EXPORT ddsrt_thread_t +ddsrt_thread_self(void); + +/** + * @brief Compare thread identifiers. + * + * @returns true if thread ids match, otherwise false. + */ +DDS_EXPORT bool +ddsrt_thread_equal(ddsrt_thread_t t1, ddsrt_thread_t t2); + +/** + * @brief Wait for termination of the specified thread. + * + * If the specified thread is still running, wait for its termination + * else return immediately. In thread_result it returns the exit status + * of the thread. If NULL is passed for @thread_result, no exit status is + * returned, but ddsrt_thread_join still waits for the thread to terminate. + * + * @param[in] thread Id of thread to wait for. + * @param[out] thread_result Location where thread result is stored. + * + * @returns A dds_retcode_t indicating success or failure. + * + * @retval DDS_RETCODE_OK + * Target thread terminated. + * @retval DDS_RETCODE_ERROR + * An error occurred while waiting for the thread to terminate. + */ +DDS_EXPORT dds_retcode_t +ddsrt_thread_join( + ddsrt_thread_t thread, + uint32_t *thread_result); + +/** + * @brief Get name of current thread. + * + * @param[in] name Buffer where the name is copied to. + * @param[in] size Number of bytes available in the buffer. + * + * @returns The number of bytes (excluding the null terminating bytes) that + * are written. If the buffer is not sufficiently large enough, the + * name is truncated and the number of bytes that would have been + * written is returned. + */ +DDS_EXPORT size_t +ddsrt_thread_getname( + char *__restrict name, + size_t size); + +/** + * @brief Set name of current thread. + * + * Set name of the current thread to @name. If the name is longer than the + * platform maximum, it is silently truncated. + * + * @param[in] name Name for current thread. + */ +DDS_EXPORT void +ddsrt_thread_setname( + const char *__restrict name); + +/** + * @brief Push cleanup handler onto the cleanup stack + * + * Push a cleanup handler onto the top of the calling thread's cleanup + * stack. The cleanup handler will be popped of the thread's cleanup stack + * and invoked with the specified argument when the thread exits. + * + * @param[in] routine Cleanup handler to push onto the thread cleanup stack. + * @param[in] arg Argument that will be passed to the cleanup handler. + */ +DDS_EXPORT dds_retcode_t +ddsrt_thread_cleanup_push( + void (*routine)(void*), + void *arg); + +/** + * @brief Pop cleanup handler from the top of the cleanup stack + * + * Remove routine at the top of the calling thread's cleanup stack and + * optionally invoke it (if execute is non-zero). + */ +DDS_EXPORT dds_retcode_t +ddsrt_thread_cleanup_pop( + int execute); + +/** + * @brief Initialize thread internals. + * + * Initialize internals for threads not created with @ddsrt_create_thread. By + * default initialization is done automatically. + */ +DDS_EXPORT void +ddsrt_thread_init(void); + +/** + * @brief Free thread resources and execute cleanup handlers. + * + * Platforms that support it, automatically free resources claimed by the + * current thread and call any registered cleanup routines. This function only + * needs to be called on platforms that do not support thread destructors and + * only for threads that were not created with @ddsrt_thread_create. + */ +DDS_EXPORT void +ddsrt_thread_fini(void); + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_THREADS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/threads/posix.h b/src/ddsrt/include/dds/ddsrt/threads/posix.h new file mode 100644 index 0000000..63d193d --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/threads/posix.h @@ -0,0 +1,59 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_POSIX_THREAD_H +#define DDSRT_POSIX_THREAD_H + +#include + +#if defined (__cplusplus) +extern "C" { +#endif + +#if defined(__linux) +typedef long int ddsrt_tid_t; +#define PRIdTID "ld" +/* __linux */ +#elif defined(__FreeBSD__) && (__FreeBSD_version >= 900031) +/* FreeBSD >= 9.0 */ +typedef int ddsrt_tid_t; +#define PRIdTID "d" +/* __FreeBSD__ */ +#elif defined(__APPLE__) && !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ + __MAC_OS_X_VERSION_MIN_REQUIRED < 1060) +/* macOS X >= 10.6 */ +typedef uint64_t ddsrt_tid_t; +#define PRIdTID PRIu64 +/* __APPLE__ */ +#elif defined(__VXWORKS__) +/* TODO: Verify taskIdSelf is the right function to use on VxWorks */ +typedef TASK_ID ddsrt_tid_t; +# if defined(_WRS_CONFIG_LP64) +# define PRIdPID PRIuPTR /* typedef struct windTcb *TASK_ID */ +# else +# define PRIdPID "d" /* typedef int TASK_ID */ +# endif +/* __VXWORKS__ */ +#else +typedef uintmax_t ddsrt_tid_t; +#define PRIdTID PRIuPTR +#endif + +/* Wrapped in a struct to force conformation to abstraction. */ +typedef struct { + pthread_t v; +} ddsrt_thread_t; + +#if defined (__cplusplus) +} +#endif + +#endif /* DDSRT_POSIX_THREAD_H */ diff --git a/src/os/include/os/os_random.h b/src/ddsrt/include/dds/ddsrt/threads/windows.h similarity index 68% rename from src/os/include/os/os_random.h rename to src/ddsrt/include/dds/ddsrt/threads/windows.h index 542f548..e7eda64 100644 --- a/src/os/include/os/os_random.h +++ b/src/ddsrt/include/dds/ddsrt/threads/windows.h @@ -9,19 +9,25 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_RANDOM_H -#define OS_RANDOM_H +#ifndef DDSRT_WINDOWS_THREADS_H +#define DDSRT_WINDOWS_THREADS_H -#include "os/os_defs.h" +#include "dds/ddsrt/types.h" #if defined (__cplusplus) extern "C" { #endif -OSAPI_EXPORT long os_random(void); +typedef struct { + DWORD tid; + HANDLE handle; +} ddsrt_thread_t; + +typedef DWORD ddsrt_tid_t; +#define PRIdTID "u" #if defined (__cplusplus) } #endif -#endif /* OS_RANDOM_H */ +#endif /* DDSRT_WINDOWS_THREADS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/time.h b/src/ddsrt/include/dds/ddsrt/time.h new file mode 100644 index 0000000..37fcfa3 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/time.h @@ -0,0 +1,149 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +/** + * @file + * @brief DDS C Time support API + * + * This header file defines the public API of the in the + * CycloneDDS C language binding. + */ +#ifndef DDS_TIME_H +#define DDS_TIME_H + +#include + +#include "dds/export.h" +#include "dds/ddsrt/types.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +/* + Times are represented using a 64-bit signed integer, encoding + nanoseconds since the epoch. Considering the nature of these + systems, one would best use TAI, International Atomic Time, rather + than something UTC, but availability may be limited. + + Valid times are non-negative and times up to 2**63-2 can be + represented. 2**63-1 is defined to represent, essentially, "never". + This is good enough for a couple of centuries. +*/ + +/** Absolute Time definition */ +typedef int64_t dds_time_t; + +/** Relative Time definition */ +typedef int64_t dds_duration_t; + +/** @name Macro definition for time units in nanoseconds. + @{**/ +#define DDS_NSECS_IN_SEC INT64_C(1000000000) +#define DDS_NSECS_IN_MSEC INT64_C(1000000) +#define DDS_NSECS_IN_USEC INT64_C(1000) +/** @}*/ + +/** @name Infinite timeout for indicate absolute time */ +#define DDS_NEVER ((dds_time_t) INT64_MAX) + +/** @name Infinite timeout for relative time */ +#define DDS_INFINITY ((dds_duration_t) INT64_MAX) + +/** @name Macro definition for time conversion to nanoseconds + @{**/ +#define DDS_SECS(n) ((n) * DDS_NSECS_IN_SEC) +#define DDS_MSECS(n) ((n) * DDS_NSECS_IN_MSEC) +#define DDS_USECS(n) ((n) * DDS_NSECS_IN_USEC) +/** @}*/ + +/** + * @brief Get the current time in nanoseconds since the UNIX Epoch. + * + * @returns Current time. + */ +DDS_EXPORT dds_time_t dds_time(void); + +/** + * @brief Suspend execution of calling thread until relative time n elapsed. + * + * Execution is suspended for n nanoseconds. Should the call be interrupted, + * the call is re-entered with the remaining time. + * + * @param[in] reltime Relative time in nanoseconds. + */ +DDS_EXPORT void dds_sleepfor (dds_duration_t reltime); + +/** + * @brief Suspend execution of calling thread until absolute time n elapsed. + * + * Execution is suspended until the given absolute time elapsed. Should the + * call be interrupted, it is re-entered with the remaining time. + * + * @param[in] abstime Absolute time in nanoseconds since UNIX Epoch. + */ +DDS_EXPORT void dds_sleepuntil (dds_time_t abstime); + +/** + * @brief Get high resolution, monotonic time. + * + * The monotonic clock is a clock with near real-time progression and can be + * used when a high-resolution time is needed without the need for it to be + * related to the wall-clock. The resolution of the clock is typically the + * highest available on the platform. + * + * The clock is not guaranteed to be strictly monotonic, but on most common + * platforms it will be (based on performance-counters or HPET's). + * + * @returns Monotonic time if available, otherwise real time. + */ +DDS_EXPORT dds_time_t ddsrt_time_monotonic(void); + +/** + * @brief Get high resolution, elapsed (and thus monotonic) time since some + * fixed unspecified past time. + * + * The elapsed time clock is a clock with near real-time progression and can be + * used when a high-resolution suspend-aware monotonic clock is needed, without + * having to deal with the complications of discontinuities if for example the + * time is changed. The fixed point from which the elapsed time is returned is + * not guaranteed to be fixed over reboots of the system. + * + * @returns Elapsed time if available, otherwise return monotonic time. + */ +DDS_EXPORT dds_time_t ddsrt_time_elapsed(void); + +/** + * @brief Convert time into a human readable string in RFC 3339 format. + * + * Converts the calender time into a null-terminated string in RFC 3339 format. + * e.g. "2014-10-24 15:32:27-04:00". + * + * UTC offset is omitted if time-zone information is unknown. + * + * @param[in] abstime Time in nanoseconds since UNIX Epoch. + * @param[in] str String to write human readable timestamp to. + * @param[in] size Number of bytes available in @str. + * + * @returns Number of bytes written (excluding terminating null byte). The + * string is truncated if str is not sufficiently large enough. Thus, + * a return value of size or more means the output was truncated. + */ +#define DDSRT_RFC3339STRLEN (25) + +DDS_EXPORT size_t ddsrt_ctime(dds_time_t abstime, char *str, size_t size); + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_TIME_H */ diff --git a/src/ddsrt/include/dds/ddsrt/types.h b/src/ddsrt/include/dds/ddsrt/types.h new file mode 100644 index 0000000..012b43a --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/types.h @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_TYPES_H +#define DDSRT_TYPES_H + +#include +#include + +#if _WIN32 +# include "dds/ddsrt/types/windows.h" +#elif __VXWORKS__ +# include "dds/ddsrt/types/vxworks.h" +#else +# include "dds/ddsrt/types/posix.h" +#endif + +#define PRIdSIZE "zd" +#define PRIuSIZE "zu" +#define PRIxSIZE "zx" + +#endif /* DDSRT_TYPES_H */ diff --git a/src/os/include/os/windows/os_platform_public.h b/src/ddsrt/include/dds/ddsrt/types/posix.h similarity index 74% rename from src/os/include/os/windows/os_platform_public.h rename to src/ddsrt/include/dds/ddsrt/types/posix.h index e488177..6088737 100644 --- a/src/os/include/os/windows/os_platform_public.h +++ b/src/ddsrt/include/dds/ddsrt/types/posix.h @@ -9,17 +9,11 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef OS_PLATFORM_PUBLIC_WIN_H -#define OS_PLATFORM_PUBLIC_WIN_H +#ifndef DDSRT_TYPES_POSIX_H +#define DDSRT_TYPES_POSIX_H #include +#include +#include -#if defined (__cplusplus) -extern "C" { -#endif - -#if defined (__cplusplus) -} -#endif - -#endif +#endif /* DDSRT_TYPES_POSIX_H */ diff --git a/src/ddsrt/include/dds/ddsrt/types/vxworks.h b/src/ddsrt/include/dds/ddsrt/types/vxworks.h new file mode 100644 index 0000000..95989bc --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/types/vxworks.h @@ -0,0 +1,74 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_TYPES_VXWORKS_H +#define DDSRT_TYPES_VXWORKS_H + +#if defined(_WRS_KERNEL) +/* inttypes.h does not exist in VxWorks DKM. */ +#include +#include +/* The above inttypes includes don't seem to define uintmax_t &c. */ +#ifdef _WRS_CONFIG_LP64 /* Used in cafe/inttypes.h too. */ +#define _PFX_64 "l" +typedef unsigned long int uintmax_t; +#else +#define _PFX_64 "ll" +typedef unsigned long long int uintmax_t; +#endif + +/* Not a complete replacement for inttypes.h (yet); No SCN/PRI?LEAST/FAST/etc. */ +#define PRId8 "d" +#define PRId16 "d" +#define PRId32 "d" +#define PRId64 _PFX_64 "d" + +#define PRIi8 "i" +#define PRIi16 "i" +#define PRIi32 "i" +#define PRIi64 _PFX_64 "i" + +#define PRIo8 "o" +#define PRIo16 "o" +#define PRIo32 "o" +#define PRIo64 _PFX_64 "o" + +#define PRIu8 "u" +#define PRIu16 "u" +#define PRIu32 "u" +#define PRIu64 _PFX_64 "u" + +#define PRIx8 "x" +#define PRIx16 "x" +#define PRIx32 "x" + +#define PRIX8 "X" +#define PRIX16 "X" +#define PRIX32 "X" +#define PRIX64 _PFX_64 "X" + +#define PRIdMAX _PFX_64 "d" +#define PRIiMAX _PFX_64 "i" +#define PRIoMAX _PFX_64 "o" +#define PRIuMAX _PFX_64 "u" +#define PRIxMAX _PFX_64 "x" +#define PRIXMAX _PFX_64 "X" + +#define PRIdPTR _PFX_64 "d" +#define PRIiPTR _PFX_64 "i" +#define PRIoPTR _PFX_64 "o" +#define PRIXPTR _PFX_64 "X" + +#else /* _WRS_KERNEL */ +#include +#endif /* _WRS_KERNEL */ + +#endif /* DDSRT_TYPES_VXWORKS_H */ diff --git a/src/ddsrt/include/dds/ddsrt/types/windows.h b/src/ddsrt/include/dds/ddsrt/types/windows.h new file mode 100644 index 0000000..7e81bf8 --- /dev/null +++ b/src/ddsrt/include/dds/ddsrt/types/windows.h @@ -0,0 +1,27 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_TYPES_WINDOWS_H +#define DDSRT_TYPES_WINDOWS_H + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include +#include +#include +#include +#include + +typedef SSIZE_T ssize_t; + +#endif /* DDSRT_TYPES_WINDOWS_H */ diff --git a/src/ddsrt/include/dds/version.h.in b/src/ddsrt/include/dds/version.h.in new file mode 100644 index 0000000..3bab290 --- /dev/null +++ b/src/ddsrt/include/dds/version.h.in @@ -0,0 +1,28 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDS_VERSION_H +#define DDS_VERSION_H + +#define DDS_VERSION "@CycloneDDS_VERSION@" +#define DDS_VERSION_MAJOR @CycloneDDS_VERSION_MAJOR@ +#define DDS_VERSION_MINOR @CycloneDDS_VERSION_MINOR@ +#define DDS_VERSION_PATCH @CycloneDDS_VERSION_PATCH@ +#define DDS_VERSION_TWEAK @CycloneDDS_VERSION_TWEAK@ +#define DDS_PROJECT_NAME_NOSPACE_CAPS "@CMAKE_PROJECT_NAME_CAPS@" +#define DDS_PROJECT_NAME_NOSPACE_SMALL "@CMAKE_PROJECT_NAME_SMALL@" +#define DDS_PROJECT_NAME_NOSPACE "@CMAKE_PROJECT_NAME@" +#define DDS_PROJECT_NAME "@CMAKE_PROJECT_NAME@" + +#define DDS_HOST_NAME "@CMAKE_HOST_SYSTEM_NAME@" +#define DDS_TARGET_NAME "@CMAKE_SYSTEM_NAME@" + +#endif /* DDS_VERSION_H */ diff --git a/src/ddsrt/include/getopt.h.in b/src/ddsrt/include/getopt.h.in new file mode 100644 index 0000000..287a3df --- /dev/null +++ b/src/ddsrt/include/getopt.h.in @@ -0,0 +1,24 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef GETOPT_H +#define GETOPT_H + +#include "dds/export.h" + +DDS_EXPORT extern int opterr; +DDS_EXPORT extern int optind; +DDS_EXPORT extern int optopt; +DDS_EXPORT extern char *optarg; + +DDS_EXPORT int getopt(int argc, char **argv, const char *opts); + +#endif /* GETOPT_H */ diff --git a/src/ddsrt/src/atomics.c b/src/ddsrt/src/atomics.c new file mode 100644 index 0000000..bc87a7b --- /dev/null +++ b/src/ddsrt/src/atomics.c @@ -0,0 +1,163 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "dds/ddsrt/atomics.h" + +/* LD, ST */ +extern inline uint32_t ddsrt_atomic_ld32 (const volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_ld64 (const volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline uintptr_t ddsrt_atomic_ldptr (const volatile ddsrt_atomic_uintptr_t *x); +extern inline void *ddsrt_atomic_ldvoidp (const volatile ddsrt_atomic_voidp_t *x); +extern inline void ddsrt_atomic_st32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_st64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline void ddsrt_atomic_stptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline void ddsrt_atomic_stvoidp (volatile ddsrt_atomic_voidp_t *x, void *v); +/* INC */ +extern inline void ddsrt_atomic_inc32 (volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_inc64 (volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline void ddsrt_atomic_incptr (volatile ddsrt_atomic_uintptr_t *x); +extern inline uint32_t ddsrt_atomic_inc32_nv (volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_inc64_nv (volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline uintptr_t ddsrt_atomic_incptr_nv (volatile ddsrt_atomic_uintptr_t *x); +/* DEC */ +extern inline void ddsrt_atomic_dec32 (volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_dec64 (volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline void ddsrt_atomic_decptr (volatile ddsrt_atomic_uintptr_t *x); +extern inline uint32_t ddsrt_atomic_dec32_nv (volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_dec64_nv (volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline uintptr_t ddsrt_atomic_decptr_nv (volatile ddsrt_atomic_uintptr_t *x); +extern inline uint32_t ddsrt_atomic_dec32_ov (volatile ddsrt_atomic_uint32_t *x); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_dec64_ov (volatile ddsrt_atomic_uint64_t *x); +#endif +extern inline uintptr_t ddsrt_atomic_decptr_ov (volatile ddsrt_atomic_uintptr_t *x); +/* ADD */ +extern inline void ddsrt_atomic_add32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_add64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline void ddsrt_atomic_addptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline void ddsrt_atomic_addvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v); +extern inline uint32_t ddsrt_atomic_add32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_add64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_addptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline void *ddsrt_atomic_addvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v); +/* SUB */ +extern inline void ddsrt_atomic_sub32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_sub64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline void ddsrt_atomic_subptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline void ddsrt_atomic_subvoidp (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v); +extern inline uint32_t ddsrt_atomic_sub32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_sub64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_subptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline void *ddsrt_atomic_subvoidp_nv (volatile ddsrt_atomic_voidp_t *x, ptrdiff_t v); +/* AND */ +extern inline void ddsrt_atomic_and32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_and64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline void ddsrt_atomic_andptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline uint32_t ddsrt_atomic_and32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_and64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_andptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline uint32_t ddsrt_atomic_and32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_and64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_andptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +/* OR */ +extern inline void ddsrt_atomic_or32 (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline void ddsrt_atomic_or64 (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline void ddsrt_atomic_orptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline uint32_t ddsrt_atomic_or32_ov (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_or64_ov (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_orptr_ov (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +extern inline uint32_t ddsrt_atomic_or32_nv (volatile ddsrt_atomic_uint32_t *x, uint32_t v); +#if DDSRT_HAVE_ATOMIC64 +extern inline uint64_t ddsrt_atomic_or64_nv (volatile ddsrt_atomic_uint64_t *x, uint64_t v); +#endif +extern inline uintptr_t ddsrt_atomic_orptr_nv (volatile ddsrt_atomic_uintptr_t *x, uintptr_t v); +/* CAS */ +extern inline int ddsrt_atomic_cas32 (volatile ddsrt_atomic_uint32_t *x, uint32_t exp, uint32_t des); +#if DDSRT_HAVE_ATOMIC64 +extern inline int ddsrt_atomic_cas64 (volatile ddsrt_atomic_uint64_t *x, uint64_t exp, uint64_t des); +#endif +extern inline int ddsrt_atomic_casptr (volatile ddsrt_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des); +extern inline int ddsrt_atomic_casvoidp (volatile ddsrt_atomic_voidp_t *x, void *exp, void *des); +#if DDSRT_ATOMIC_LIFO_SUPPORT +extern inline int ddsrt_atomic_casvoidp2 (volatile ddsrt_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1); +#endif +/* FENCES */ +extern inline void ddsrt_atomic_fence (void); +extern inline void ddsrt_atomic_fence_ldld (void); +extern inline void ddsrt_atomic_fence_acq (void); +extern inline void ddsrt_atomic_fence_rel (void); + +#if DDSRT_ATOMIC_LIFO_SUPPORT +void ddsrt_atomic_lifo_init (ddsrt_atomic_lifo_t *head) +{ + head->aba_head.s.a = head->aba_head.s.b = 0; +} +void ddsrt_atomic_lifo_push (ddsrt_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 (!ddsrt_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, (uintptr_t)elem)); +} +void *ddsrt_atomic_lifo_pop (ddsrt_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 (!ddsrt_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, b1)); + return (void *) b0; +} +void ddsrt_atomic_lifo_pushmany (ddsrt_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 (!ddsrt_atomic_casvoidp2 (&head->aba_head, a0, b0, a0+1, (uintptr_t)first)); +} +#endif diff --git a/src/ddsrt/src/cdtors.c b/src/ddsrt/src/cdtors.c new file mode 100644 index 0000000..a3088fb --- /dev/null +++ b/src/ddsrt/src/cdtors.c @@ -0,0 +1,149 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/time.h" + +#if _WIN32 +/* Sockets API initialization is only necessary on Microsoft Windows. The + overly correct approach would be to abstract this a little further, but for + now a pragmatic approach will suffice. */ +extern void ddsrt_winsock_init(void); +extern void ddsrt_winsock_fini(void); +extern void ddsrt_time_init(void); +extern void ddsrt_time_fini(void); +#endif + +#define INIT_STATUS_OK 0x80000000u +static ddsrt_atomic_uint32_t init_status = DDSRT_ATOMIC_UINT32_INIT(0); +static ddsrt_mutex_t init_mutex; + +void ddsrt_init (void) +{ + uint32_t v; + v = ddsrt_atomic_inc32_nv(&init_status); +retry: + if (v > INIT_STATUS_OK) + return; + else if (v == 1) { + ddsrt_mutex_init(&init_mutex); +#if _WIN32 + ddsrt_winsock_init(); + ddsrt_time_init(); +#endif + ddsrt_atomic_or32(&init_status, INIT_STATUS_OK); + } else { + while (v > 1 && !(v & INIT_STATUS_OK)) { + dds_sleepfor(10000000); + v = ddsrt_atomic_ld32(&init_status); + } + goto retry; + } +} + +void ddsrt_fini (void) +{ + uint32_t v, nv; + do { + v = ddsrt_atomic_ld32(&init_status); + if (v == (INIT_STATUS_OK | 1)) { + nv = 1; + } else { + nv = v - 1; + } + } while (!ddsrt_atomic_cas32(&init_status, v, nv)); + if (nv == 1) + { + ddsrt_mutex_destroy(&init_mutex); +#if _WIN32 + ddsrt_winsock_fini(); + ddsrt_time_fini(); +#endif + ddsrt_atomic_dec32(&init_status); + } +} + +ddsrt_mutex_t *ddsrt_get_singleton_mutex(void) +{ + return &init_mutex; +} + +#ifdef _WIN32 +#include "dds/ddsrt/threads.h" + +/* Executed before DllMain within the context of the thread. Located here too + avoid removal due to link time optimization. */ +void WINAPI +ddsrt_cdtor( + PVOID handle, + DWORD reason, + PVOID reserved) +{ + switch (reason) { + case DLL_PROCESS_ATTACH: + ddsrt_init(); + /* fall through */ + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: /* Specified when thread exits. */ + ddsrt_thread_fini(); + break; + case DLL_PROCESS_DETACH: /* Specified when main thread exits. */ + ddsrt_thread_fini(); + ddsrt_fini(); + break; + default: + break; + } +} + +/* These instructions are very specific to the Windows platform. They register + a function (or multiple) as a TLS initialization function. TLS initializers + are executed when a thread (or program) attaches or detaches. In contrast to + DllMain, a TLS initializer is also executed when the library is linked + statically. TLS initializers are always executed before DllMain (both when + the library is attached and detached). See http://www.nynaeve.net/?p=190, + for a detailed explanation on TLS initializers. Boost and/or POSIX Threads + for Windows code bases may also form good sources of information on this + subject. + + These instructions could theoretically be hidden in the build system, but + doing so would be going a bit overboard as only Windows offers (and + requires) this type of functionality/initialization. Apart from that the + logic isn't exactly as trivial as for example determining the endianness of + a platform, so keeping this close to the implementation is probably wise. */ +#ifdef _WIN64 + #pragma comment (linker, "/INCLUDE:_tls_used") + #pragma comment (linker, "/INCLUDE:tls_callback_func") + #pragma const_seg(".CRT$XLZ") + EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = ddsrt_cdtor; + #pragma const_seg() +#else + #pragma comment (linker, "/INCLUDE:__tls_used") + #pragma comment (linker, "/INCLUDE:_tls_callback_func") + #pragma data_seg(".CRT$XLZ") + EXTERN_C PIMAGE_TLS_CALLBACK tls_callback_func = ddsrt_cdtor; + #pragma data_seg() + #endif +#else /* _WIN32 */ +void __attribute__((constructor)) ddsrt_ctor(void) +{ + ddsrt_init(); +} + +void __attribute__((destructor)) ddsrt_dtor(void) +{ + ddsrt_fini(); +} +#endif /* _WIN32 */ + diff --git a/src/ddsrt/src/environ/posix/environ.c b/src/ddsrt/src/environ/posix/environ.c new file mode 100644 index 0000000..b05769c --- /dev/null +++ b/src/ddsrt/src/environ/posix/environ.c @@ -0,0 +1,88 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/retcode.h" + +static int +isenvvar(const char *name) +{ + return (*name == '\0' || strchr(name, '=') != NULL) == 0; +} + +dds_retcode_t +ddsrt_getenv(const char *name, char **value) +{ + char *env; + + assert(name != NULL); + assert(value != NULL); + + if (!isenvvar(name)) + return DDS_RETCODE_BAD_PARAMETER; + if ((env = getenv(name)) != NULL) { + *value = env; + return DDS_RETCODE_OK; + } + return DDS_RETCODE_NOT_FOUND; +} + +dds_retcode_t +ddsrt_setenv(const char *name, const char *value) +{ + assert(name != NULL); + assert(value != NULL); + + if (strlen(value) == 0) + return ddsrt_unsetenv(name); + if (!isenvvar(name)) + return DDS_RETCODE_BAD_PARAMETER; + if (setenv(name, value, 1) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_unsetenv(const char *name) +{ + assert(name != NULL); + + if (!isenvvar(name)) + return DDS_RETCODE_BAD_PARAMETER; + if (unsetenv(name) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} diff --git a/src/ddsrt/src/environ/windows/environ.c b/src/ddsrt/src/environ/windows/environ.c new file mode 100644 index 0000000..076aea1 --- /dev/null +++ b/src/ddsrt/src/environ/windows/environ.c @@ -0,0 +1,73 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/retcode.h" + +static int +isenvvar(const char *name) +{ + return (*name == '\0' || strchr(name, '=') != NULL) == 0; +} + +DDSRT_WARNING_MSVC_OFF(4996) +dds_retcode_t +ddsrt_getenv(const char *name, char **value) +{ + char *env; + + assert(name != NULL); + assert(value != NULL); + + if (!isenvvar(name)) + return DDS_RETCODE_BAD_PARAMETER; + if ((env = getenv(name)) != NULL) { + *value = env; + return DDS_RETCODE_OK; + } + return DDS_RETCODE_NOT_FOUND; +} +DDSRT_WARNING_MSVC_ON(4996) + +dds_retcode_t +ddsrt_setenv(const char *name, const char *value) +{ + assert(name != NULL); + assert(value != NULL); + + if (!isenvvar(name)) + return DDS_RETCODE_BAD_PARAMETER; + switch (_putenv_s(name, value)) { + case 0: + return DDS_RETCODE_OK; + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_unsetenv(const char *name) +{ + assert(name != NULL); + return ddsrt_setenv(name, ""); +} diff --git a/src/os/src/snippets/code/os_stdlib_getopt.c b/src/ddsrt/src/getopt.c similarity index 97% rename from src/os/src/snippets/code/os_stdlib_getopt.c rename to src/ddsrt/src/getopt.c index 130e0a8..0d2c807 100644 --- a/src/os/src/snippets/code/os_stdlib_getopt.c +++ b/src/ddsrt/src/getopt.c @@ -1,3 +1,7 @@ +#include +#include +#include + /* ::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]:: */ #ifndef LINT static const char Id[] = "$Id: os_stdlib_getopt.c,v 1.2 2008-11-17 09:53:45 hansv Exp $"; diff --git a/src/ddsrt/src/heap/posix/heap.c b/src/ddsrt/src/heap/posix/heap.c new file mode 100644 index 0000000..597f03a --- /dev/null +++ b/src/ddsrt/src/heap/posix/heap.c @@ -0,0 +1,91 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "dds/ddsrt/attributes.h" +#include "dds/ddsrt/heap.h" + +void * +ddsrt_malloc_s(size_t size) +{ + return malloc(size ? size : 1); /* Allocate memory even if size == 0 */ +} + +void * +ddsrt_malloc(size_t size) +{ + void *ptr = ddsrt_malloc_s(size); + + if (ptr == NULL) { + /* Heap exhausted */ + abort(); + } + + return ptr; +} + +void * +ddsrt_calloc(size_t count, size_t size) +{ + char *ptr; + + ptr = ddsrt_calloc_s(count, size); + + if (ptr == NULL) { + /* Heap exhausted */ + abort(); + } + + return ptr; +} + +void * +ddsrt_calloc_s(size_t count, size_t size) +{ + if (count == 0 || size == 0) { + count = size = 1; + } + return calloc(count, size); +} + +void * +ddsrt_realloc(void *memblk, size_t size) +{ + void *ptr; + + ptr = ddsrt_realloc_s(memblk, size); + + if (ptr == NULL){ + /* Heap exhausted */ + abort(); + } + + return ptr; +} + +void * +ddsrt_realloc_s(void *memblk, size_t size) +{ + /* Even though newmem = realloc(mem, 0) is equivalent to calling free(mem), + not all platforms will return newmem == NULL. We consistently do, so the + result of a non-failing ddsrt_realloc_s always needs to be free'd, like + ddsrt_malloc_s(0). */ + return realloc(memblk, size ? size : 1); +} + +void +ddsrt_free(void *ptr) +{ + if (ptr) { + free (ptr); + } +} diff --git a/src/os/src/vxworks/os_platform_heap.c b/src/ddsrt/src/heap/vxworks/heap.c similarity index 97% rename from src/os/src/vxworks/os_platform_heap.c rename to src/ddsrt/src/heap/vxworks/heap.c index 5c307bc..142f25d 100644 --- a/src/os/src/vxworks/os_platform_heap.c +++ b/src/ddsrt/src/heap/vxworks/heap.c @@ -25,7 +25,7 @@ atomic_t os__reallocdoublecopycount = 0; #endif void * -os_malloc( +ddsrt_malloc( size_t size) { void *ptr; @@ -60,7 +60,7 @@ os_malloc( return ptr; } -void *os_realloc( +void *ddsrt_realloc( void *ptr, size_t size) { @@ -72,7 +72,7 @@ void *os_realloc( if ( ptr == NULL ) { - return (os_malloc(size)); + return (ddsrt_malloc(size)); } assert ( ((char *)ptr - (char *)0) % 8 == 0 ); @@ -133,7 +133,7 @@ void *os_realloc( } void -os_free( +ddsrt_free( void *ptr) { assert ( ((char *)ptr - (char *)0) % 8 == 0 ); diff --git a/src/os/src/os_ifaddrs.c b/src/ddsrt/src/ifaddrs.c similarity index 57% rename from src/os/src/os_ifaddrs.c rename to src/ddsrt/src/ifaddrs.c index 77e92e9..d50a2e4 100644 --- a/src/os/src/os_ifaddrs.c +++ b/src/ddsrt/src/ifaddrs.c @@ -9,21 +9,22 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/ifaddrs.h" void -os_freeifaddrs(os_ifaddrs_t *ifa) +ddsrt_freeifaddrs(ddsrt_ifaddrs_t *ifa) { - os_ifaddrs_t *next; + ddsrt_ifaddrs_t *next; - while (ifa != NULL) { - next = ifa->next; - os_free(ifa->name); - os_free(ifa->addr); - os_free(ifa->netmask); - os_free(ifa->broadaddr); - os_free(ifa); - ifa = next; - } + while (ifa != NULL) { + next = ifa->next; + ddsrt_free(ifa->name); + ddsrt_free(ifa->addr); + ddsrt_free(ifa->netmask); + ddsrt_free(ifa->broadaddr); + ddsrt_free(ifa); + ifa = next; + } } diff --git a/src/ddsrt/src/ifaddrs/posix/ifaddrs.c b/src/ddsrt/src/ifaddrs/posix/ifaddrs.c new file mode 100644 index 0000000..88606b1 --- /dev/null +++ b/src/ddsrt/src/ifaddrs/posix/ifaddrs.c @@ -0,0 +1,135 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/string.h" + +extern const int *const os_supp_afs; + +static dds_retcode_t +copyaddr(ddsrt_ifaddrs_t **ifap, const struct ifaddrs *sys_ifa) +{ + dds_retcode_t err = DDS_RETCODE_OK; + ddsrt_ifaddrs_t *ifa; + size_t sz; + + assert(ifap != NULL); + assert(sys_ifa != NULL); + + sz = ddsrt_sockaddr_get_size(sys_ifa->ifa_addr); + ifa = ddsrt_calloc_s(1, sizeof(*ifa)); + if (ifa == NULL) { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } else { + ifa->index = if_nametoindex(sys_ifa->ifa_name); + ifa->flags = sys_ifa->ifa_flags; + if ((ifa->name = ddsrt_strdup(sys_ifa->ifa_name)) == NULL || + (ifa->addr = ddsrt_memdup(sys_ifa->ifa_addr, sz)) == NULL || + (sys_ifa->ifa_netmask != NULL && + (ifa->netmask = ddsrt_memdup(sys_ifa->ifa_netmask, sz)) == NULL) || + (sys_ifa->ifa_broadaddr != NULL && + (sys_ifa->ifa_flags & IFF_BROADCAST) && + (ifa->broadaddr = ddsrt_memdup(sys_ifa->ifa_broadaddr, sz)) == NULL)) + { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } + /* Seen on macOS using OpenVPN: netmask without an address family, + in which case copy it from the interface address */ + if (ifa->addr && ifa->netmask && ifa->netmask->sa_family == 0) { + ifa->netmask->sa_family = ifa->addr->sa_family; + } + } + + if (err == 0) { + *ifap = ifa; + } else { + ddsrt_freeifaddrs(ifa); + } + + return err; +} + +dds_retcode_t +ddsrt_getifaddrs( + ddsrt_ifaddrs_t **ifap, + const int *afs) +{ + dds_retcode_t err = DDS_RETCODE_OK; + int use; + ddsrt_ifaddrs_t *ifa, *ifa_root, *ifa_next; + struct ifaddrs *sys_ifa, *sys_ifa_root; + struct sockaddr *sa; + + assert(ifap != NULL); + + if (afs == NULL) { + afs = os_supp_afs; + } + + if (getifaddrs(&sys_ifa_root) == -1) { + switch (errno) { + case EACCES: + err = DDS_RETCODE_NOT_ALLOWED; + break; + case ENOMEM: + case ENOBUFS: + err = DDS_RETCODE_OUT_OF_RESOURCES; + break; + default: + err = DDS_RETCODE_ERROR; + break; + } + } else { + ifa = ifa_root = NULL; + + for (sys_ifa = sys_ifa_root; + sys_ifa != NULL && err == 0; + sys_ifa = sys_ifa->ifa_next) + { + sa = sys_ifa->ifa_addr; + if (sa != NULL) { + use = 0; + for (int i = 0; !use && afs[i] != DDSRT_AF_TERM; i++) { + use = (sa->sa_family == afs[i]); + } + + if (use) { + err = copyaddr(&ifa_next, sys_ifa); + if (err == DDS_RETCODE_OK) { + if (ifa == NULL) { + ifa = ifa_root = ifa_next; + } else { + ifa->next = ifa_next; + ifa = ifa_next; + } + } + } + } + } + + freeifaddrs(sys_ifa_root); + + if (err == 0) { + *ifap = ifa_root; + } else { + ddsrt_freeifaddrs(ifa_root); + } + } + + return err; +} diff --git a/src/ddsrt/src/ifaddrs/windows/ifaddrs.c b/src/ddsrt/src/ifaddrs/windows/ifaddrs.c new file mode 100644 index 0000000..1bd41da --- /dev/null +++ b/src/ddsrt/src/ifaddrs/windows/ifaddrs.c @@ -0,0 +1,283 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "dds/ddsrt/sockets.h" + +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsrt/io.h" +#include "dds/ddsrt/string.h" + +extern const int *const os_supp_afs; + +static dds_retcode_t +getifaces(PIP_ADAPTER_ADDRESSES *ptr) +{ + dds_retcode_t err = DDS_RETCODE_NOT_ENOUGH_SPACE; + PIP_ADAPTER_ADDRESSES buf = NULL; + ULONG bufsz = 0; /* Size is determined on first iteration. */ + ULONG ret; + size_t i; + + static const size_t max = 2; + static const ULONG filter = GAA_FLAG_INCLUDE_PREFIX | + GAA_FLAG_SKIP_ANYCAST | + GAA_FLAG_SKIP_MULTICAST | + GAA_FLAG_SKIP_DNS_SERVER; + + assert(ptr != NULL); + + for (i = 0; err == DDS_RETCODE_NOT_ENOUGH_SPACE && i < max; i++) { + ret = GetAdaptersAddresses(AF_UNSPEC, filter, NULL, buf, &bufsz); + assert(ret != ERROR_INVALID_PARAMETER); + switch (ret) { + case ERROR_BUFFER_OVERFLOW: + err = DDS_RETCODE_NOT_ENOUGH_SPACE; + ddsrt_free(buf); + if ((buf = (IP_ADAPTER_ADDRESSES *)ddsrt_malloc(bufsz)) == NULL) { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } + break; + case ERROR_NOT_ENOUGH_MEMORY: + err = DDS_RETCODE_OUT_OF_RESOURCES; + break; + case ERROR_SUCCESS: + case ERROR_ADDRESS_NOT_ASSOCIATED: /* No address associated yet. */ + case ERROR_NO_DATA: /* No adapters that match the filter. */ + default: + err = DDS_RETCODE_OK; + break; + } + } + + if (err == DDS_RETCODE_OK) { + *ptr = buf; + } else { + ddsrt_free(buf); + } + + return err; +} + +static dds_retcode_t +getaddrtable(PMIB_IPADDRTABLE *ptr) +{ + dds_retcode_t err = DDS_RETCODE_NOT_ENOUGH_SPACE; + PMIB_IPADDRTABLE buf = NULL; + ULONG bufsz = 0; + DWORD ret; + size_t i; + + static const size_t max = 2; + + assert(ptr != NULL); + + for (i = 0; err == DDS_RETCODE_NOT_ENOUGH_SPACE && i < max; i++) { + ret = GetIpAddrTable(buf, &bufsz, 0); + assert(ret != ERROR_INVALID_PARAMETER && + ret != ERROR_NOT_SUPPORTED); + switch (ret) { + case ERROR_INSUFFICIENT_BUFFER: + err = DDS_RETCODE_NOT_ENOUGH_SPACE; + ddsrt_free(buf); + if ((buf = (PMIB_IPADDRTABLE)ddsrt_malloc(bufsz)) == NULL) { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } + break; + case NO_ERROR: + err = DDS_RETCODE_OK; + break; + default: + err = DDS_RETCODE_ERROR; + break; + } + } + + if (err == 0) { + *ptr = buf; + } else { + ddsrt_free(buf); + } + + return err; +} + +static uint32_t +getflags(const PIP_ADAPTER_ADDRESSES iface) +{ + uint32_t flags = 0; + + if (iface->OperStatus == IfOperStatusUp) { + flags |= IFF_UP; + } + if (!(iface->Flags & IP_ADAPTER_NO_MULTICAST) && + (iface->IfType != IF_TYPE_SOFTWARE_LOOPBACK)) + { + /* multicast over loopback doesn't seem to work despite the NO_MULTICAST + flag being clear assuming an interface is multicast-capable when in fact + it isn't is disastrous, so it makes more sense to err by assuming it + won't work as there is always the AssumeMulticastCapable setting to + overrule it */ + flags |= IFF_MULTICAST; + } + + switch (iface->IfType) { + case IF_TYPE_SOFTWARE_LOOPBACK: + flags |= IFF_LOOPBACK; + break; + case IF_TYPE_ETHERNET_CSMACD: + case IF_TYPE_IEEE80211: + case IF_TYPE_IEEE1394: + case IF_TYPE_ISO88025_TOKENRING: + flags |= IFF_BROADCAST; + break; + default: + flags |= IFF_POINTTOPOINT; + break; + } + + return flags; +} + +static int +copyaddr( + ddsrt_ifaddrs_t **ifap, + const PIP_ADAPTER_ADDRESSES iface, + const PMIB_IPADDRTABLE addrtable, + const PIP_ADAPTER_UNICAST_ADDRESS addr) +{ + dds_retcode_t err = DDS_RETCODE_OK; + ddsrt_ifaddrs_t *ifa; + struct sockaddr *sa; + size_t sz; + + assert(iface != NULL); + assert(addrtable != NULL); + assert(addr != NULL); + + sa = (struct sockaddr *)addr->Address.lpSockaddr; + sz = (size_t)addr->Address.iSockaddrLength; + + if ((ifa = ddsrt_calloc_s(1, sizeof(*ifa))) == NULL) { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } else { + ifa->flags = getflags(iface); + ifa->addr = ddsrt_memdup(sa, sz); + (void)ddsrt_asprintf(&ifa->name, "%wS", iface->FriendlyName); + if (ifa->addr == NULL || ifa->name == NULL) { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } else if (ifa->addr->sa_family == AF_INET6) { + ifa->index = iface->Ipv6IfIndex; + + /* Address is not in addrtable if the interface is not connected. */ + } else if (ifa->addr->sa_family == AF_INET && (ifa->flags & IFF_UP)) { + DWORD i = 0; + struct sockaddr_in nm, bc, *sin = (struct sockaddr_in *)sa; + + assert(sz == sizeof(nm)); + memset(&nm, 0, sz); + memset(&bc, 0, sz); + nm.sin_family = bc.sin_family = AF_INET; + + for (; i < addrtable->dwNumEntries; i++) { + if (sin->sin_addr.s_addr == addrtable->table[i].dwAddr) { + ifa->index = addrtable->table[i].dwIndex; + nm.sin_addr.s_addr = addrtable->table[i].dwMask; + bc.sin_addr.s_addr = sin->sin_addr.s_addr | ~(nm.sin_addr.s_addr); + break; + } + } + + assert(i < addrtable->dwNumEntries); + + if ((ifa->netmask = ddsrt_memdup(&nm, sz)) == NULL || + (ifa->broadaddr = ddsrt_memdup(&bc, sz)) == NULL) + { + err = DDS_RETCODE_OUT_OF_RESOURCES; + } + } + } + + if (err == 0) { + *ifap = ifa; + } else { + ddsrt_freeifaddrs(ifa); + } + + return err; +} + +dds_retcode_t +ddsrt_getifaddrs( + ddsrt_ifaddrs_t **ifap, + const int *afs) +{ + int err = 0; + int use; + PIP_ADAPTER_ADDRESSES ifaces = NULL, iface; + PIP_ADAPTER_UNICAST_ADDRESS addr = NULL; + PMIB_IPADDRTABLE addrtable = NULL; + ddsrt_ifaddrs_t *ifa, *ifa_root, *ifa_next; + struct sockaddr *sa; + + assert(ifap != NULL); + + if (afs == NULL) { + afs = os_supp_afs; + } + + ifa = ifa_root = ifa_next = NULL; + + if ((err = getifaces(&ifaces)) == DDS_RETCODE_OK && + (err = getaddrtable(&addrtable)) == DDS_RETCODE_OK) + { + for (iface = ifaces; !err && iface != NULL; iface = iface->Next) { + for (addr = iface->FirstUnicastAddress; + addr != NULL; + addr = addr->Next) + { + sa = (struct sockaddr *)addr->Address.lpSockaddr; + use = 0; + for (int i = 0; !use && afs[i] != DDSRT_AF_TERM; i++) { + use = (afs[i] == sa->sa_family); + } + + if (use) { + err = copyaddr(&ifa_next, iface, addrtable, addr); + if (err == DDS_RETCODE_OK) { + if (ifa == NULL) { + ifa = ifa_root = ifa_next; + } else { + ifa->next = ifa_next; + ifa = ifa_next; + } + } + } + } + } + } + + ddsrt_free(ifaces); + ddsrt_free(addrtable); + + if (err == DDS_RETCODE_OK) { + *ifap = ifa_root; + } else { + ddsrt_freeifaddrs(ifa_root); + } + + return err; +} diff --git a/src/ddsrt/src/io.c b/src/ddsrt/src/io.c new file mode 100644 index 0000000..4ac55af --- /dev/null +++ b/src/ddsrt/src/io.c @@ -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 + */ +#include +#include +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/io.h" + +int +ddsrt_asprintf( + char **strp, + const char *fmt, + ...) +{ + int ret; + unsigned int len; + char buf[1] = { '\0' }; + char *str = NULL; + va_list args1, args2; + + assert(strp != NULL); + assert(fmt != NULL); + + va_start(args1, fmt); + va_copy(args2, args1); /* va_list cannot be reused */ + + if ((ret = vsnprintf(buf, sizeof(buf), fmt, args1)) >= 0) { + len = (unsigned int)ret; /* +1 for null byte */ + if ((str = ddsrt_malloc(len + 1)) == NULL) { + ret = -1; + } else if ((ret = vsnprintf(str, len + 1, fmt, args2)) >= 0) { + assert(((unsigned int)ret) == len); + *strp = str; + } else { + ddsrt_free(str); + } + } + + va_end(args1); + va_end(args2); + + return ret; +} + +#if defined(_MSC_VER) && (_MSC_VER < 1900) +int +snprintf( + char *str, + size_t size, + const char *fmt, + ...) +{ + int cnt; + va_list args; + + va_start(args, fmt); + cnt = vsnprintf(str, size, fmt, args); + va_end(args); + + return cnt; +} +#endif diff --git a/src/ddsrt/src/log.c b/src/ddsrt/src/log.c new file mode 100644 index 0000000..558f56e --- /dev/null +++ b/src/ddsrt/src/log.c @@ -0,0 +1,302 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include +#include + +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" + +#define MAX_TIMESTAMP_LEN (10 + 1 + 6) +#define MAX_TID_LEN (10) +#define HDR_LEN (MAX_TIMESTAMP_LEN + 1 + MAX_TID_LEN + 2) + +#define BUF_OFFSET HDR_LEN + +typedef struct { + char buf[2048]; + size_t pos; +} log_buffer_t; + +typedef struct { + dds_log_write_fn_t funcs[2]; + void *ptr; + FILE *out; +} log_sink_t; + +static ddsrt_thread_local log_buffer_t log_buffer; + +static ddsrt_once_t lock_inited = DDSRT_ONCE_INIT; +static ddsrt_rwlock_t lock; + +static uint32_t log_mask = DDS_LC_ERROR | DDS_LC_WARNING; + +static void default_sink(void *ptr, const dds_log_data_t *data) +{ + fwrite(data->message - HDR_LEN, 1, HDR_LEN + data->size + 1, (FILE *)ptr); + fflush((FILE *)ptr); +} + +static void nop_sink(void *ptr, const dds_log_data_t *data) +{ + (void)ptr; + (void)data; + return; +} + +#define LOG (0) +#define TRACE (1) +#define USE (0) +#define SET (1) + +static log_sink_t sinks[] = { + /* Log */ + { .funcs = { default_sink, default_sink }, .ptr = NULL, .out = NULL }, + /* Trace */ + { .funcs = { nop_sink, default_sink }, .ptr = NULL, .out = NULL } +}; + +uint32_t *const dds_log_mask = &log_mask; + +#define RDLOCK (1) +#define WRLOCK (2) + +static void init_lock(void) +{ + ddsrt_rwlock_init(&lock); + sinks[LOG].ptr = sinks[TRACE].ptr = stderr; + sinks[LOG].out = sinks[TRACE].out = stderr; +} + +static void lock_sink(int type) +{ + assert(type == RDLOCK || type == WRLOCK); + ddsrt_once(&lock_inited, &init_lock); + + if (type == RDLOCK) { + ddsrt_rwlock_read(&lock); + } else { + ddsrt_rwlock_write(&lock); + } +} + +static void unlock_sink(void) +{ + ddsrt_rwlock_unlock(&lock); +} + +static void set_active_log_sinks(void) +{ + if (dds_get_log_mask() & DDS_LOG_MASK) { + sinks[LOG].funcs[USE] = sinks[LOG].funcs[SET]; + } else { + sinks[LOG].funcs[USE] = nop_sink; + } + if (dds_get_log_mask() & DDS_TRACE_MASK) { + sinks[TRACE].funcs[USE] = sinks[TRACE].funcs[SET]; + } else { + sinks[TRACE].funcs[USE] = nop_sink; + } + if (sinks[LOG].funcs[USE] == sinks[TRACE].funcs[USE] && + sinks[LOG].ptr == sinks[TRACE].ptr) + { + sinks[LOG].funcs[USE] = nop_sink; + } +} + +static void +set_log_sink( + log_sink_t *sink, + dds_log_write_fn_t func, + void *ptr) +{ + assert(sink != NULL); + + /* No life cycle management is done for log sinks, the caller is + responsible for that. Ensure this operation is deterministic and that on + return, no thread in the DDS stack still uses the deprecated sink. */ + lock_sink(WRLOCK); + + if (func == 0) { + sink->funcs[SET] = default_sink; + sink->ptr = sink->out; + } else { + sink->funcs[SET] = func; + sink->ptr = ptr; + } + + set_active_log_sinks(); + unlock_sink(); +} + +/* dds_set_log_file must be considered private. */ +void dds_set_log_file(FILE *file) +{ + lock_sink(WRLOCK); + sinks[LOG].out = (file == NULL ? stderr : file); + if (sinks[LOG].funcs[SET] == default_sink) { + sinks[LOG].ptr = sinks[LOG].out; + } + set_active_log_sinks(); + unlock_sink(); +} + +void dds_set_trace_file(FILE *file) +{ + lock_sink(WRLOCK); + sinks[TRACE].out = (file == NULL ? stderr : file); + if (sinks[TRACE].funcs[SET] == default_sink) { + sinks[TRACE].ptr = sinks[TRACE].out; + } + set_active_log_sinks(); + unlock_sink(); +} + +void dds_set_log_sink( + dds_log_write_fn_t callback, + void *userdata) +{ + set_log_sink(&sinks[LOG], callback, userdata); +} + +void dds_set_trace_sink( + dds_log_write_fn_t callback, + void *userdata) +{ + set_log_sink(&sinks[TRACE], callback, userdata); +} + +extern inline uint32_t +dds_get_log_mask(void); + +void +dds_set_log_mask(uint32_t cats) +{ + lock_sink(WRLOCK); + *dds_log_mask = (cats & (DDS_LOG_MASK | DDS_TRACE_MASK)); + set_active_log_sinks(); + unlock_sink(); +} + +static void print_header(char *str) +{ + int cnt; + char *tid, buf[MAX_TID_LEN+1] = { 0 }; + static const char fmt[] = "%10u.%06d/%*.*s:"; + dds_time_t time; + unsigned sec; + int usec; + + (void)ddsrt_thread_getname(buf, sizeof(buf)); + tid = (buf[0] == '\0' ? "(anon)" : buf); + time = dds_time(); + sec = (unsigned)(time / DDS_NSECS_IN_SEC); + usec = (int)((time % DDS_NSECS_IN_SEC) / DDS_NSECS_IN_USEC); + + cnt = snprintf( + str, HDR_LEN, fmt, sec, usec, MAX_TID_LEN, MAX_TID_LEN, tid); + assert(cnt == (HDR_LEN - 1)); + str[cnt] = ' '; /* Replace snprintf null byte by space. */ +} + +static void vlog( + uint32_t cat, + const char *file, + uint32_t line, + const char *func, + const char *fmt, + va_list ap) +{ + int n, trunc = 0; + size_t nrem; + log_buffer_t *lb; + dds_log_data_t data; + + if (*fmt == 0) { + return; + } + + lock_sink(RDLOCK); + lb = &log_buffer; + + /* Thread-local buffer is always initialized with all zeroes. The pos + member must always be greater or equal to BUF_OFFSET. */ + if (lb->pos < BUF_OFFSET) { + lb->pos = BUF_OFFSET; + lb->buf[lb->pos] = 0; + } + nrem = sizeof (lb->buf) - lb->pos; + if (nrem > 0) { + n = vsnprintf(lb->buf + lb->pos, nrem, fmt, ap); + if (n >= 0 && (size_t) n < nrem) { + lb->pos += (size_t) n; + } else { + lb->pos += nrem; + trunc = 1; + } + if (trunc) { + static const char msg[] = "(trunc)\n"; + const size_t msglen = sizeof (msg) - 1; + assert(lb->pos <= sizeof (lb->buf)); + assert(lb->pos >= msglen); + memcpy(lb->buf + lb->pos - msglen, msg, msglen); + } + } + + if (fmt[strlen (fmt) - 1] == '\n') { + print_header(lb->buf); + + data.priority = cat; + data.file = file; + data.function = func; + data.line = line; + data.message = lb->buf + BUF_OFFSET; + data.size = strlen(data.message) - 1; + + for (size_t i = (cat & DDS_LOG_MASK) ? LOG : TRACE; + i < sizeof(sinks) / sizeof(sinks[0]); + i++) + { + sinks[i].funcs[USE](sinks[i].ptr, &data); + } + + lb->pos = BUF_OFFSET; + lb->buf[lb->pos] = 0; + } + + unlock_sink(); +} + +int +dds_log( + uint32_t cat, + const char *file, + uint32_t line, + const char *func, + const char *fmt, + ...) +{ + if ((dds_get_log_mask() & cat) || (cat & DDS_LC_FATAL)) { + va_list ap; + va_start(ap, fmt); + vlog(cat, file, line, func, fmt, ap); + va_end(ap); + } + if (cat & DDS_LC_FATAL) { + abort(); + } + + return 0; +} diff --git a/src/os/src/os_process.c b/src/ddsrt/src/process.c similarity index 81% rename from src/os/src/os_process.c rename to src/ddsrt/src/process.c index 67e0cd6..4aed282 100644 --- a/src/os/src/os_process.c +++ b/src/ddsrt/src/process.c @@ -9,12 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" +#include "dds/ddsrt/process.h" -os_procId -os_getpid(void) +#if !defined(_WIN32) +# include +#endif + +ddsrt_pid_t +ddsrt_getpid(void) { -#if defined(WIN32) +#if defined(_WIN32) return GetCurrentProcessId(); #else /* Mapped to taskIdSelf() in VxWorks kernel mode. */ diff --git a/src/os/src/os_random.c b/src/ddsrt/src/random.c similarity index 60% rename from src/os/src/os_random.c rename to src/ddsrt/src/random.c index ea6ed76..582cb48 100644 --- a/src/os/src/os_random.c +++ b/src/ddsrt/src/random.c @@ -12,22 +12,24 @@ #include #include -#if WIN32 +#include "dds/ddsrt/random.h" + +#if _WIN32 #define _CRT_RAND_S #include long random (void) { - /* rand() is a really terribly bad PRNG */ - /* FIXME: Indeed (especially if not seeded), use rand_s instead. */ - union { long x; unsigned char c[4]; } t; - int i; - for (i = 0; i < 4; i++) - t.c[i] = (unsigned char) ((rand () >> 4) & 0xff); + /* rand() is a really terribly bad PRNG */ + /* FIXME: Indeed (especially if not seeded), use rand_s instead. */ + 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; + t.x &= RAND_MAX; #elif RAND_MAX <= 0x7ffffffe - t.x %= (RAND_MAX+1); + t.x %= (RAND_MAX+1); #else #error "RAND_MAX out of range" #endif @@ -35,8 +37,8 @@ long random (void) } #endif -long os_random(void) +long ddsrt_random(void) { - /* FIXME: Not MT-safe, should use random_r (or a real PRNG) instead. */ - return random(); + /* FIXME: Not MT-safe, should use random_r (or a real PRNG) instead. */ + return random(); } diff --git a/src/ddsrt/src/retcode.c b/src/ddsrt/src/retcode.c new file mode 100644 index 0000000..6484f23 --- /dev/null +++ b/src/ddsrt/src/retcode.c @@ -0,0 +1,60 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "dds/ddsrt/retcode.h" + +static const char *retcodes[] = +{ + "Success", + "Error", + "Unsupported", + "Bad Parameter", + "Precondition Not Met", + "Out Of Resources", + "Not Enabled", + "Immutable Policy", + "Inconsistent Policy", + "Already Deleted", + "Timeout", + "No Data", + "Illegal Operation", + "Not Allowed By Security" +}; + +static const char *xretcodes[] = { + "Operation in progress", + "Try again", + "Interrupted", + "Not allowed", + "Host not found", + "Network not available", + "Connection not available", + "No space left", + "Result too large", + "Not found" +}; + +const char * +dds_strretcode (dds_retcode_t rc) +{ + if (rc >= 0 && + rc < (dds_retcode_t)(sizeof(retcodes) / sizeof(retcodes[0]))) + { + return retcodes[rc]; + } else if (rc >= (DDS_XRETCODE_BASE) && + rc < (dds_retcode_t)(DDS_XRETCODE_BASE + (sizeof(xretcodes) / sizeof(xretcodes[0])))) + { + return xretcodes[rc - DDS_XRETCODE_BASE]; + } + + return "Unknown return code"; +} + diff --git a/src/ddsrt/src/rusage/posix/rusage.c b/src/ddsrt/src/rusage/posix/rusage.c new file mode 100644 index 0000000..878bd1d --- /dev/null +++ b/src/ddsrt/src/rusage/posix/rusage.c @@ -0,0 +1,101 @@ +/* + * 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 + */ +#define _GNU_SOURCE /* Required for RUSAGE_THREAD. */ +#include +#include +#include +#include + +#if defined(__APPLE__) +#include +#include +#include +#endif + +#include "dds/ddsrt/rusage.h" + +dds_retcode_t +ddsrt_getrusage(int who, ddsrt_rusage_t *usage) +{ + int err = 0; + struct rusage buf; + dds_retcode_t rc; + + assert(who == DDSRT_RUSAGE_SELF || who == DDSRT_RUSAGE_THREAD); + assert(usage != NULL); + + memset(&buf, 0, sizeof(buf)); + +#if defined(__linux) + if ((who == DDSRT_RUSAGE_SELF && getrusage(RUSAGE_SELF, &buf) == -1) || + (who == DDSRT_RUSAGE_THREAD && getrusage(RUSAGE_THREAD, &buf) == -1)) + { + err = errno; + } else { + buf.ru_maxrss *= 1024; + } +#else + if (getrusage(RUSAGE_SELF, &buf) == -1) { + err = errno; + } else if (who == DDSRT_RUSAGE_THREAD) { + memset(&buf.ru_utime, 0, sizeof(buf.ru_utime)); + memset(&buf.ru_stime, 0, sizeof(buf.ru_stime)); + buf.ru_nvcsw = 0; + buf.ru_nivcsw = 0; + +#if defined(__APPLE__) + kern_return_t ret; + mach_port_t thr; + mach_msg_type_number_t cnt; + thread_basic_info_data_t info; + + thr = mach_thread_self(); + assert(thr != MACH_PORT_DEAD); + if (thr == MACH_PORT_NULL) { + /* Resource shortage prevented reception of send right. */ + err = ENOMEM; + } else { + cnt = THREAD_BASIC_INFO_COUNT; + ret = thread_info( + thr, THREAD_BASIC_INFO, (thread_info_t)&info, &cnt); + assert(ret != KERN_INVALID_ARGUMENT); + /* Assume MIG_ARRAY_TOO_LARGE will not happen. */ + buf.ru_utime.tv_sec = info.user_time.seconds; + buf.ru_utime.tv_usec = info.user_time.microseconds; + buf.ru_stime.tv_sec = info.system_time.seconds; + buf.ru_stime.tv_usec = info.system_time.microseconds; + mach_port_deallocate(mach_task_self(), thr); + } +#endif /* __APPLE__ */ + } +#endif /* __linux */ + + if (err == 0) { + rc = DDS_RETCODE_OK; + usage->utime = + (buf.ru_utime.tv_sec * DDS_NSECS_IN_SEC) + + (buf.ru_utime.tv_usec * DDS_NSECS_IN_USEC); + usage->stime = + (buf.ru_stime.tv_sec * DDS_NSECS_IN_SEC) + + (buf.ru_stime.tv_usec * DDS_NSECS_IN_USEC); + usage->maxrss = (size_t)buf.ru_maxrss; + usage->idrss = (size_t)buf.ru_idrss; + usage->nvcsw = (size_t)buf.ru_nvcsw; + usage->nivcsw = (size_t)buf.ru_nivcsw; + } else if (err == ENOMEM) { + rc = DDS_RETCODE_OUT_OF_RESOURCES; + } else { + rc = DDS_RETCODE_ERROR; + } + + return rc; +} diff --git a/src/os/src/windows/os_platform_rusage.c b/src/ddsrt/src/rusage/windows/rusage.c similarity index 63% rename from src/os/src/windows/os_platform_rusage.c rename to src/ddsrt/src/rusage/windows/rusage.c index cada12f..71d763d 100644 --- a/src/os/src/windows/os_platform_rusage.c +++ b/src/ddsrt/src/rusage/windows/rusage.c @@ -11,46 +11,43 @@ */ #include #include +#include -#include "os/os.h" +#include "dds/ddsrt/rusage.h" #include -static void -filetime_to_time(_In_ const FILETIME *ft, _Out_ os_time *t) +dds_time_t +filetime_to_time(const FILETIME *ft) { /* FILETIME structures express times in 100-nanosecond time units. */ - uint64_t ns = ((ft->dwHighDateTime << 31) + (ft->dwLowDateTime)); - t->tv_sec = (os_timeSec)(ns / (1000 * 1000 * 10)); - t->tv_nsec = (int32_t)(ns % (1000 * 1000 * 10)) * 100; + return ((ft->dwHighDateTime << 31) + (ft->dwLowDateTime)) * 100; } -_Pre_satisfies_((who == OS_RUSAGE_SELF) || \ - (who == OS_RUSAGE_THREAD)) -_Success_(return == 0) -int os_getrusage(_In_ int who, _Out_ os_rusage_t *usage) +dds_retcode_t +ddsrt_getrusage(int who, ddsrt_rusage_t *usage) { FILETIME stime, utime, ctime, etime; PROCESS_MEMORY_COUNTERS pmctrs; - assert(who == OS_RUSAGE_SELF || who == OS_RUSAGE_THREAD); + assert(who == DDSRT_RUSAGE_SELF || who == DDSRT_RUSAGE_THREAD); assert(usage != NULL); /* Memory counters are per process, but populate them if thread resource usage is requested to keep in sync with Linux. */ if ((!GetProcessMemoryInfo(GetCurrentProcess(), &pmctrs, sizeof(pmctrs))) - || (who == OS_RUSAGE_SELF && + || (who == DDSRT_RUSAGE_SELF && !GetProcessTimes(GetCurrentProcess(), &ctime, &etime, &stime, &utime)) - || (who == OS_RUSAGE_THREAD && + || (who == DDSRT_RUSAGE_THREAD && !GetThreadTimes(GetCurrentThread(), &ctime, &etime, &stime, &utime))) { return GetLastError(); } memset(usage, 0, sizeof(*usage)); - filetime_to_time(&stime, &usage->stime); - filetime_to_time(&utime, &usage->utime); + usage->stime = filetime_to_time(&stime); + usage->utime = filetime_to_time(&utime); usage->maxrss = pmctrs.PeakWorkingSetSize; - return 0; + return DDS_RETCODE_OK; } diff --git a/src/ddsrt/src/sockets.c b/src/ddsrt/src/sockets.c new file mode 100644 index 0000000..d559a80 --- /dev/null +++ b/src/ddsrt/src/sockets.c @@ -0,0 +1,354 @@ +/* + * 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 + */ +#define _GNU_SOURCE + +#include +#include +#include + +#if !defined(_WIN32) +#include +#include +#include +# if defined(__linux) +# include /* sockaddr_ll */ +# endif /* __linux */ +#endif /* _WIN32 */ + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/sockets_priv.h" + +extern inline struct timeval * +ddsrt_duration_to_timeval_ceil(dds_duration_t reltime, struct timeval *tv); + +#if DDSRT_HAVE_IPV6 +const struct in6_addr ddsrt_in6addr_any = IN6ADDR_ANY_INIT; +const struct in6_addr ddsrt_in6addr_loopback = IN6ADDR_LOOPBACK_INIT; +#endif + +const int afs[] = { +#ifdef __linux + AF_PACKET, +#endif /* __linux */ +#if DDSRT_HAVE_IPV6 + AF_INET6, +#endif /* DDSRT_HAVE_IPV6 */ + AF_INET, + DDSRT_AF_TERM /* Terminator */ +}; + +const int *const os_supp_afs = afs; + +socklen_t +ddsrt_sockaddr_get_size(const struct sockaddr *const sa) +{ + socklen_t sz; + + assert(sa != NULL); + + switch(sa->sa_family) { +#if DDSRT_HAVE_IPV6 + case AF_INET6: + sz = sizeof(struct sockaddr_in6); + break; +#endif /* DDSRT_HAVE_IPV6 */ +#ifdef __linux + case AF_PACKET: + sz = sizeof(struct sockaddr_ll); + break; +#endif /* __linux */ + default: + assert(sa->sa_family == AF_INET); + sz = sizeof(struct sockaddr_in); + break; + } + + return sz; +} + +uint16_t ddsrt_sockaddr_get_port(const struct sockaddr *const sa) +{ + unsigned short port = 0; + + switch(sa->sa_family) { +#if DDSRT_HAVE_IPV6 + case AF_INET6: + port = ntohs(((struct sockaddr_in6 *)sa)->sin6_port); + break; +#endif /* DDSRT_HAVE_IPV6 */ + default: + assert(sa->sa_family == AF_INET); + port = ntohs(((struct sockaddr_in *)sa)->sin_port); + break; + } + + return port; +} + +bool +ddsrt_sockaddr_isunspecified(const struct sockaddr *__restrict sa) +{ + assert(sa != NULL); + + switch(sa->sa_family) { +#if DDSRT_HAVE_IPV6 + case AF_INET6: + return IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6*)sa)->sin6_addr); +#endif + case AF_INET: + return (((struct sockaddr_in *)sa)->sin_addr.s_addr == 0); + } + + return false; +} + +bool +ddsrt_sockaddr_isloopback(const struct sockaddr *__restrict sa) +{ + assert(sa != NULL); + + switch (sa->sa_family) { +#if DDSRT_HAVE_IPV6 + case AF_INET6: + return IN6_IS_ADDR_LOOPBACK( + &((const struct sockaddr_in6 *)sa)->sin6_addr); +#endif /* DDSRT_HAVE_IPV6 */ + case AF_INET: + return (((const struct sockaddr_in *)sa)->sin_addr.s_addr + == htonl(INADDR_LOOPBACK)); + } + + return false; +} + +bool +ddsrt_sockaddr_insamesubnet( + const struct sockaddr *sa1, + const struct sockaddr *sa2, + const struct sockaddr *mask) +{ + bool eq = false; + + if (sa1->sa_family != sa2->sa_family || + sa1->sa_family != mask->sa_family) + { + return false; + } + + switch (sa1->sa_family) { + case AF_INET: { + eq = ((((struct sockaddr_in *)sa1)->sin_addr.s_addr & + ((struct sockaddr_in *)mask)->sin_addr.s_addr) + == + (((struct sockaddr_in *)sa2)->sin_addr.s_addr & + ((struct sockaddr_in *)mask)->sin_addr.s_addr)); + } break; +#if DDSRT_HAVE_IPV6 + case AF_INET6: { + struct sockaddr_in6 *sin61, *sin62, *mask6; + size_t i, n = sizeof(sin61->sin6_addr.s6_addr); + sin61 = (struct sockaddr_in6 *)sa1; + sin62 = (struct sockaddr_in6 *)sa2; + mask6 = (struct sockaddr_in6 *)mask; + eq = true; + for (i = 0; eq && i < n; i++) { + eq = ((sin61->sin6_addr.s6_addr[i] & + mask6->sin6_addr.s6_addr[i]) + == + (sin62->sin6_addr.s6_addr[i] & + mask6->sin6_addr.s6_addr[i])); + } + } break; +#endif + } + + return eq; +} + +dds_retcode_t +ddsrt_sockaddrfromstr(int af, const char *str, void *sa) +{ + assert(str != NULL); + assert(sa != NULL); + + switch (af) { + case AF_INET: { + struct in_addr buf; + if (inet_pton(af, str, &buf) != 1) { + return DDS_RETCODE_BAD_PARAMETER; + } else { + memset(sa, 0, sizeof(struct sockaddr_in)); + ((struct sockaddr_in *)sa)->sin_family = AF_INET; + memcpy(&((struct sockaddr_in *)sa)->sin_addr, &buf, sizeof(buf)); + } + } break; +#if DDSRT_HAVE_IPV6 + case AF_INET6: { + struct in6_addr buf; + if (inet_pton(af, str, &buf) != 1) { + return DDS_RETCODE_BAD_PARAMETER; + } else { + memset(sa, 0, sizeof(struct sockaddr_in6)); + ((struct sockaddr_in6 *)sa)->sin6_family = AF_INET6; + memcpy(&((struct sockaddr_in6 *)sa)->sin6_addr, &buf, sizeof(buf)); + } + } break; +#endif + default: + return DDS_RETCODE_BAD_PARAMETER; + } + + return DDS_RETCODE_OK; +} + +dds_retcode_t ddsrt_sockaddrtostr(const void *sa, char *buf, size_t size) +{ + const char *ptr; + + assert(sa != NULL); + assert(buf != NULL); + + switch (((struct sockaddr *)sa)->sa_family) { + case AF_INET: + ptr = inet_ntop( + AF_INET, &((struct sockaddr_in *)sa)->sin_addr, buf, (socklen_t)size); + break; +#if DDSRT_HAVE_IPV6 + case AF_INET6: + ptr = inet_ntop( + AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, buf, (socklen_t)size); + break; +#endif + default: + return DDS_RETCODE_BAD_PARAMETER; + } + + if (ptr == NULL) { + return DDS_RETCODE_NOT_ENOUGH_SPACE; + } + + return DDS_RETCODE_OK; +} + +#if DDSRT_HAVE_DNS +dds_retcode_t +ddsrt_gethostbyname(const char *name, int af, ddsrt_hostent_t **hentp) +{ + int gai_err = 0; + struct addrinfo hints, *res = NULL; + ddsrt_hostent_t *hent = NULL; + + assert(name != NULL); + assert(hentp != NULL); + + switch (af) { +#if DDSRT_HAVE_IPV6 + case AF_INET6: +#endif + case AF_INET: + case AF_UNSPEC: + break; + default: + return DDS_RETCODE_BAD_PARAMETER; + } + + /* Windows returns all registered addresses on the local computer if the + "nodename" parameter is an empty string. *NIX return HOST_NOT_FOUND. + Deny empty hostnames to keep behavior across platforms consistent. */ + if (strlen(name) == 0) { + return DDS_RETCODE_HOST_NOT_FOUND; + } + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = af; + + gai_err = getaddrinfo(name, NULL, &hints, &res); + /* gai_strerror cannot be used because Windows does not offer a thread-safe + implementation and lwIP (there maybe others as well) does not offer an + implementation at all. + + NOTE: Error codes returned by getaddrinfo map directly onto Windows + Socket error codes and WSAGetLastError can be used instead. */ + DDS_TRACE("getaddrinfo for %s returned %d\n", name, gai_err); + switch (gai_err) { +#if defined(EAI_AGAIN) + case EAI_AGAIN: + /* Name server returned a temporary failure indication. */ + return DDS_RETCODE_TRY_AGAIN; +#endif + case EAI_FAIL: + /* Name server returned a permanent failure indication. */ + return DDS_RETCODE_ERROR; +/* Windows defines EAI_NODATA to EAI_NONAME. */ +#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) + case EAI_NODATA: + /* Host exists, but does not have any network addresses defined. */ + return DDS_RETCODE_NO_DATA; +#endif +#if defined(EAI_ADDRFAMILY) + case EAI_ADDRFAMILY: /* Host has no addresses in requested family. */ +#endif +#if defined(EAI_NOSECURENAME) /* Windows */ + case EAI_NOSECURENAME: +#endif + case EAI_NONAME: + /* Host does not exist. */ + return DDS_RETCODE_HOST_NOT_FOUND; + case EAI_MEMORY: + /* Out of memory. */ + return DDS_RETCODE_OUT_OF_RESOURCES; +#if defined(EAI_SYSTEM) + case EAI_SYSTEM: + /* Other system error. */ + return DDS_RETCODE_ERROR; +#endif + case EAI_BADFLAGS: /* Invalid flags in hints.ai_flags. */ + case EAI_FAMILY: /* Address family not supported. */ + case EAI_SERVICE: /* Service not available for socket type. */ + case EAI_SOCKTYPE: /* Socket type not supported. */ + case 0: { + struct addrinfo *ai; + size_t addrno, naddrs, size; + + assert(gai_err == 0); + assert(res != NULL); + + naddrs = 0; + for (ai = res; ai != NULL; ai = ai->ai_next) { + naddrs++; + } + + size = sizeof(*hent) + (naddrs * sizeof(hent->addrs[0])); + if ((hent = ddsrt_calloc_s(1, size)) != NULL) { + hent->naddrs = naddrs; + for (addrno = 0, ai = res; + addrno < naddrs && ai != NULL; + addrno++, ai = ai->ai_next) + { + memcpy(&hent->addrs[addrno], res->ai_addr, res->ai_addrlen); + } + } else { + return DDS_RETCODE_OUT_OF_RESOURCES; + } + + freeaddrinfo(res); + } break; + default: + DDS_ERROR("getaddrinfo returned unkown error %d\n", gai_err); + return DDS_RETCODE_ERROR; + } + + *hentp = hent; + return DDS_RETCODE_OK; +} +#endif /* DDSRT_HAVE_DNS */ diff --git a/src/ddsrt/src/sockets/include/dds/ddsrt/sockets_priv.h b/src/ddsrt/src/sockets/include/dds/ddsrt/sockets_priv.h new file mode 100644 index 0000000..8a41203 --- /dev/null +++ b/src/ddsrt/src/sockets/include/dds/ddsrt/sockets_priv.h @@ -0,0 +1,82 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_SOCKETS_PRIV_H +#define DDSRT_SOCKETS_PRIV_H + +#include + +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/time.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +#if _WIN32 +typedef long ddsrt_tv_sec_t; +typedef long ddsrt_tv_usec_t; +#else +typedef time_t ddsrt_tv_sec_t; +typedef suseconds_t ddsrt_tv_usec_t; +#endif + +#define DDSRT_TIME_T_MAX \ + (DDSRT_MAX_INTEGER(ddsrt_tv_sec_t)) + +/** + * @brief Convert a relative time to a timeval rounding up. + * + * @param[in] reltime Relative time to convert. + * @param[out] tv struct timeval* where timeout is stored. + * + * @returns NULL if @reltime was @DDS_INFINITY, the value of @tv otherwise. + */ +inline struct timeval * +ddsrt_duration_to_timeval_ceil(dds_duration_t reltime, struct timeval *tv) +{ + assert(tv != NULL); + + if (reltime == DDS_INFINITY) { + tv->tv_sec = 0; + tv->tv_usec = 0; + return NULL; + } else if (reltime > 0) { + dds_duration_t max_nsecs; + if (DDS_INFINITY > DDSRT_TIME_T_MAX) { + assert(DDSRT_TIME_T_MAX == INT32_MAX); + max_nsecs = INT32_MAX * DDS_NSECS_IN_SEC; + } else { + max_nsecs = DDSRT_TIME_T_MAX / DDS_NSECS_IN_SEC; + } + + if (reltime < (max_nsecs - DDS_NSECS_IN_USEC - 1)) { + reltime += (DDS_NSECS_IN_USEC - 1); + tv->tv_sec = (ddsrt_tv_sec_t)(reltime / DDS_NSECS_IN_SEC); + tv->tv_usec = (ddsrt_tv_usec_t)((reltime % DDS_NSECS_IN_SEC) / DDS_NSECS_IN_USEC); + } else { + tv->tv_sec = DDSRT_TIME_T_MAX; + tv->tv_usec = 999999; + } + } else { + tv->tv_sec = 0; + tv->tv_usec = 0; + } + + return tv; +} + +#if defined(__cplusplus) +} +#endif + +#endif /* DDSRT_SOCKETS_PRIV_H */ diff --git a/src/ddsrt/src/sockets/posix/gethostname.c b/src/ddsrt/src/sockets/posix/gethostname.c new file mode 100644 index 0000000..de71a44 --- /dev/null +++ b/src/ddsrt/src/sockets/posix/gethostname.c @@ -0,0 +1,61 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#if defined(__VXWORKS__) +#include +#endif /* __VXWORKS__ */ + +#if !defined(HOST_NAME_MAX) && defined(_POSIX_HOST_NAME_MAX) +# define HOST_NAME_MAX _POSIX_HOST_NAME_MAX +#endif + +#include "dds/ddsrt/sockets.h" +#include "dds/ddsrt/string.h" + +dds_retcode_t +ddsrt_gethostname( + char *name, + size_t len) +{ + char buf[HOST_NAME_MAX + 1 /* '\0' */]; + + memset(buf, 0, sizeof(buf)); + + if (gethostname(buf, HOST_NAME_MAX) == 0) { + /* If truncation occurrs, no error is returned whether or not the buffer + is null-terminated. */ + if (buf[HOST_NAME_MAX - 1] != '\0' || + ddsrt_strlcpy(name, buf, len) >= len) + { + return DDS_RETCODE_NOT_ENOUGH_SPACE; + } + + return DDS_RETCODE_OK; + } else { + switch (errno) { + case EFAULT: /* Invalid address (cannot happen). */ + return DDS_RETCODE_ERROR; + case EINVAL: /* Negative length (cannot happen). */ + return DDS_RETCODE_ERROR; + case ENAMETOOLONG: + return DDS_RETCODE_NOT_ENOUGH_SPACE; + default: + break; + } + } + + return DDS_RETCODE_ERROR; +} diff --git a/src/ddsrt/src/sockets/posix/socket.c b/src/ddsrt/src/sockets/posix/socket.c new file mode 100644 index 0000000..67d805e --- /dev/null +++ b/src/ddsrt/src/sockets/posix/socket.c @@ -0,0 +1,530 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#if defined(__VXWORKS__) +#include +#include +#include +#else +#include +#endif /* __VXWORKS__ */ +#include +#include + +#ifdef __APPLE__ +#include +#endif /* __APPLE__ */ + +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/sockets_priv.h" + +dds_retcode_t +ddsrt_socket(ddsrt_socket_t *sockptr, int domain, int type, int protocol) +{ + ddsrt_socket_t sock; + + assert(sockptr != NULL); + + sock = socket(domain, type, protocol); + if (sock != -1) { + *sockptr = sock; + return DDS_RETCODE_OK; + } + + switch (errno) { + case EACCES: + return DDS_RETCODE_NOT_ALLOWED; + case EAFNOSUPPORT: + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case EMFILE: + case ENFILE: + case ENOBUFS: + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_close( + ddsrt_socket_t sock) +{ + if (close(sock) != -1) + return DDS_RETCODE_OK; + + switch (errno) { + case EBADF: + return DDS_RETCODE_BAD_PARAMETER; + case EINTR: + return DDS_RETCODE_INTERRUPTED; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_bind( + ddsrt_socket_t sock, + const struct sockaddr *addr, + socklen_t addrlen) +{ + if (bind(sock, addr, addrlen) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EACCES: + return DDS_RETCODE_NOT_ALLOWED; + case EADDRINUSE: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case EBADF: + case EINVAL: + case ENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_listen( + ddsrt_socket_t sock, + int backlog) +{ + if (listen(sock, backlog) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EADDRINUSE: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case EBADF: + return DDS_RETCODE_BAD_PARAMETER; + case ENOTSOCK: + case EOPNOTSUPP: + return DDS_RETCODE_ILLEGAL_OPERATION; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_connect( + ddsrt_socket_t sock, + const struct sockaddr *addr, + socklen_t addrlen) +{ + if (connect(sock, addr, addrlen) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EACCES: + case EPERM: + case EISCONN: + return DDS_RETCODE_NOT_ALLOWED; + case EADDRINUSE: + case EADDRNOTAVAIL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case EAFNOSUPPORT: + case EBADF: + case ENOTSOCK: + case EPROTOTYPE: + return DDS_RETCODE_BAD_PARAMETER; + case EAGAIN: + return DDS_RETCODE_OUT_OF_RESOURCES; + case EALREADY: + return DDS_RETCODE_TRY_AGAIN; + case ECONNREFUSED: + case ENETUNREACH: + return DDS_RETCODE_NO_CONNECTION; + case EINPROGRESS: + return DDS_RETCODE_IN_PROGRESS; + case EINTR: + return DDS_RETCODE_INTERRUPTED; + case ETIMEDOUT: + return DDS_RETCODE_TIMEOUT; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_accept( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen, + ddsrt_socket_t *connptr) +{ + ddsrt_socket_t conn; + + if ((conn = accept(sock, addr, addrlen)) != -1) { + *connptr = conn; + return DDS_RETCODE_OK; + } + + switch (errno) { + case EAGAIN: +#if EAGAIN != EWOULDBLOCK + case EWOULDBLOCK: +#endif + return DDS_RETCODE_TRY_AGAIN; + case EBADF: + case EFAULT: + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ECONNABORTED: + return DDS_RETCODE_NO_CONNECTION; + case EINTR: + return DDS_RETCODE_INTERRUPTED; + case EMFILE: + case ENFILE: + case ENOBUFS: + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + case ENOTSOCK: + case EOPNOTSUPP: + return DDS_RETCODE_ILLEGAL_OPERATION; + case EPROTO: + return DDS_RETCODE_ERROR; + case EPERM: + return DDS_RETCODE_NOT_ALLOWED; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_getsockname( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen) +{ + if (getsockname(sock, addr, addrlen) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EBADF: + case EFAULT: + case EINVAL: + case ENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case ENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_getsockopt( + ddsrt_socket_t sock, + int32_t level, + int32_t optname, + void *optval, + socklen_t *optlen) +{ + if (getsockopt(sock, level, optname, optval, optlen) == 0) + return DDS_RETCODE_OK; + + switch (errno) { + case EBADF: + case EFAULT: + case EINVAL: + case ENOPROTOOPT: + case ENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_setsockopt( + ddsrt_socket_t sock, + int32_t level, + int32_t optname, + const void *optval, + socklen_t optlen) +{ + switch (optname) { + case SO_SNDBUF: + case SO_RCVBUF: + /* optlen == 4 && optval == 0 does not work. */ + if (!(optlen == 4 && *((unsigned *)optval) == 0)) { + break; + } + /* falls through */ + case SO_DONTROUTE: + /* SO_DONTROUTE causes problems on macOS (e.g. no multicasting). */ + return DDS_RETCODE_OK; + } + + if (setsockopt(sock, level, optname, optval, optlen) == -1) { + goto err_setsockopt; + } + +#if defined(__APPLE__) + if (level == SOL_SOCKET && optname == SO_REUSEADDR && + setsockopt(sock, level, SO_REUSEPORT, optval, optlen) == -1) + { + goto err_setsockopt; + } +#endif /* __APPLE__ */ + + return DDS_RETCODE_OK; +err_setsockopt: + switch (errno) { + case EBADF: + case EINVAL: + case ENOPROTOOPT: + case ENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_setsocknonblocking( + ddsrt_socket_t sock, + bool nonblock) +{ + int flags; + + flags = fcntl(sock, F_GETFL, 0); + if (flags == -1) { + goto err_fcntl; + } else { + if (nonblock) { + flags |= O_NONBLOCK; + } else { + flags &= ~O_NONBLOCK; + } + if (fcntl(sock, F_SETFL, flags) == -1) { + goto err_fcntl; + } + } + + return DDS_RETCODE_OK; +err_fcntl: + switch (errno) { + case EACCES: + case EAGAIN: + case EPERM: + return DDS_RETCODE_ERROR; + case EBADF: + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +static inline dds_retcode_t +recv_error_to_retcode(int errnum) +{ + switch (errnum) { + case EAGAIN: +#if EAGAIN != EWOULDBLOCK + case EWOULDBLOCK: +#endif + return DDS_RETCODE_TRY_AGAIN; + case EBADF: + case EFAULT: + case EINVAL: + case ENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case ECONNREFUSED: + return DDS_RETCODE_NO_CONNECTION; + case EINTR: + return DDS_RETCODE_INTERRUPTED; + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + case ENOTCONN: + return DDS_RETCODE_ILLEGAL_OPERATION; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_recv( + ddsrt_socket_t sock, + void *buf, + size_t len, + int flags, + ssize_t *rcvd) +{ + ssize_t n; + + if ((n = recv(sock, buf, len, flags)) != -1) { + assert(n >= 0); + *rcvd = n; + return DDS_RETCODE_OK; + } + + return recv_error_to_retcode(errno); +} + +dds_retcode_t +ddsrt_recvmsg( + ddsrt_socket_t sock, + ddsrt_msghdr_t *msg, + int flags, + ssize_t *rcvd) +{ + ssize_t n; + + if ((n = recvmsg(sock, msg, flags)) != -1) { + assert(n >= 0); + *rcvd = n; + return DDS_RETCODE_OK; + } + + return recv_error_to_retcode(errno); +} + +static inline dds_retcode_t +send_error_to_retcode(int errnum) +{ + switch (errnum) { + case EACCES: + return DDS_RETCODE_NOT_ALLOWED; + case EAGAIN: +#if EAGAIN != EWOULDBLOCK + case EWOULDBLOCK: +#endif + case EALREADY: + return DDS_RETCODE_TRY_AGAIN; + case EBADF: + case EFAULT: + case EINVAL: + case ENOTSOCK: + case EOPNOTSUPP: + return DDS_RETCODE_BAD_PARAMETER; + case ECONNRESET: + return DDS_RETCODE_NO_CONNECTION; + case EDESTADDRREQ: + case EISCONN: + case ENOTCONN: + case EPIPE: + return DDS_RETCODE_ILLEGAL_OPERATION; + case EINTR: + return DDS_RETCODE_INTERRUPTED; + case EMSGSIZE: + return DDS_RETCODE_NOT_ENOUGH_SPACE; + case ENOBUFS: + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_send( + ddsrt_socket_t sock, + const void *buf, + size_t len, + int flags, + ssize_t *sent) +{ + ssize_t n; + + if ((n = send(sock, buf, len, flags)) != -1) { + assert(n >= 0); + *sent = n; + return DDS_RETCODE_OK; + } + + return send_error_to_retcode(errno); +} + +dds_retcode_t +ddsrt_sendmsg( + ddsrt_socket_t sock, + const ddsrt_msghdr_t *msg, + int flags, + ssize_t *sent) +{ + ssize_t n; + + if ((n = sendmsg(sock, msg, flags)) != -1) { + assert(n >= 0); + *sent = n; + return DDS_RETCODE_OK; + } + + return send_error_to_retcode(errno); +} + +dds_retcode_t +ddsrt_select( + int32_t nfds, + fd_set *readfds, + fd_set *writefds, + fd_set *errorfds, + dds_duration_t reltime, + int32_t *ready) +{ + int n; + struct timeval tv, *tvp = NULL; + + tvp = ddsrt_duration_to_timeval_ceil(reltime, &tv); + if ((n = select(nfds, readfds, writefds, errorfds, tvp)) != -1) { + *ready = n; + return (n == 0 ? DDS_RETCODE_TIMEOUT : DDS_RETCODE_OK); + } + + switch (errno) { + case EINTR: + return DDS_RETCODE_INTERRUPTED; + case EBADF: + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ENOMEM: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} diff --git a/src/ddsrt/src/sockets/windows/gethostname.c b/src/ddsrt/src/sockets/windows/gethostname.c new file mode 100644 index 0000000..c31664c --- /dev/null +++ b/src/ddsrt/src/sockets/windows/gethostname.c @@ -0,0 +1,42 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "dds/ddsrt/sockets.h" + +ddsrt_gethostname( + char *name, + size_t len) +{ + assert(name != NULL); + assert(len <= INT_MAX); + + if (len == 0) { + return DDS_RETCODE_BAD_PARAMETER; + } else if (gethostname(name, (int)len) == 0) { + return DDS_RETCODE_OK; + } + + switch(WSAGetLastError()) { + case WSAEFAULT: + return DDS_RETCODE_NOT_ENOUGH_SPACE; + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEINPROGRESS: + return DDS_RETCODE_IN_PROGRESS; + default: + break; + } + + return DDS_RETCODE_ERROR; +} diff --git a/src/ddsrt/src/sockets/windows/socket.c b/src/ddsrt/src/sockets/windows/socket.c new file mode 100644 index 0000000..bc96301 --- /dev/null +++ b/src/ddsrt/src/sockets/windows/socket.c @@ -0,0 +1,680 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/sockets_priv.h" +#include "dds/ddsrt/time.h" + +#ifdef ddsrt_select +#undef ddsrt_select /* See sockets.h for details. */ +#endif + +void +ddsrt_winsock_init(void) +{ + int err; + WSADATA wsa_data; + + err = WSAStartup(MAKEWORD(2,0), &wsa_data); + if (err != 0) { + DDS_FATAL("WSAStartup(2.0, ...) failed with %d\n", err); + } + + /* Confirm Windows Socket version 2.0 is supported. If versions greater + than 2.0 in addition to 2.0 are supported, 2.0 will still be returned as + that is the requested version. */ + if (LOBYTE(wsa_data.wVersion) != 2 || + HIBYTE(wsa_data.wVersion) != 0) + { + WSACleanup(); + DDS_FATAL("WSAStartup(2.0, ...) failed\n"); + } +} + +void +ddsrt_winsock_fini(void) +{ + WSACleanup(); +} + +dds_retcode_t +ddsrt_socket(ddsrt_socket_t *sockptr, int domain, int type, int protocol) +{ + int err; + dds_retcode_t ret = DDS_RETCODE_OK; + ddsrt_socket_t sock = DDSRT_INVALID_SOCKET; + + assert(sockptr != NULL); + + sock = socket(domain, type, protocol); + if (sock != INVALID_SOCKET) { + *sockptr = sock; + return DDS_RETCODE_OK; + } + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + assert(err != WSAEINVALIDPROCTABLE); + assert(err != WSAEINVALIDPROVIDER); + assert(err != WSAEPROVIDERFAILEDINIT); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEINVAL: + case WSAEAFNOSUPPORT: + case WSAEPROTONOSUPPORT: + case WSAEPROTOTYPE: + case WSAESOCKTNOSUPPORT: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + case WSAEMFILE: + case WSAENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_close(ddsrt_socket_t sock) +{ + int err; + + if (closesocket(sock) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + case WSAEWOULDBLOCK: + return DDS_RETCODE_TRY_AGAIN; + case WSAEINTR: + return DDS_RETCODE_INTERRUPTED; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_accept( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen, + ddsrt_socket_t *connptr) +{ + int err; + ddsrt_socket_t conn; + + if ((conn = accept(sock, addr, addrlen)) != INVALID_SOCKET) { + *connptr = conn; + return DDS_RETCODE_OK; + } + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAECONNRESET: + return DDS_RETCODE_NO_CONNECTION; + case WSAEFAULT: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINTR: + return DDS_RETCODE_INTERRUPTED; + case WSAEINVAL: + case WSAENOTSOCK: + case WSAEOPNOTSUPP: + return DDS_RETCODE_ILLEGAL_OPERATION; + case WSAEINPROGRESS: + return DDS_RETCODE_IN_PROGRESS; + case WSAEMFILE: + case WSAENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAEWOULDBLOCK: + return DDS_RETCODE_TRY_AGAIN; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_bind(ddsrt_socket_t sock, const struct sockaddr *addr, socklen_t addrlen) +{ + int err; + + if (bind(sock, addr, addrlen) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEACCES: + return DDS_RETCODE_NOT_ALLOWED; + case WSAEADDRINUSE: + case WSAEADDRNOTAVAIL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case WSAEFAULT: + case WSAEINVAL: + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + case WSAENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_listen( + ddsrt_socket_t sock, + int backlog) +{ + int err; + + if (listen(sock, backlog) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEADDRINUSE: + case WSAEINVAL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + case WSAEMFILE: + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAENOTSOCK: + case WSAEOPNOTSUPP: + return DDS_RETCODE_ILLEGAL_OPERATION; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_connect( + ddsrt_socket_t sock, + const struct sockaddr *addr, + socklen_t addrlen) +{ + int err; + + if (connect(sock, addr, addrlen) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEADDRINUSE: + case WSAEADDRNOTAVAIL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case WSAEINTR: + return DDS_RETCODE_INTERRUPTED; + case WSAEINPROGRESS: + case WSAEALREADY: + case WSAEWOULDBLOCK: + return DDS_RETCODE_TRY_AGAIN; + case WSAEAFNOSUPPORT: + case WSAEFAULT: + case WSAEINVAL: + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAECONNREFUSED: + case WSAENETUNREACH: + case WSAEHOSTUNREACH: + return DDS_RETCODE_NO_CONNECTION; + case WSAEISCONN: + case WSAEACCES: + return DDS_RETCODE_NOT_ALLOWED; + case WSAENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAETIMEDOUT: + return DDS_RETCODE_TIMEOUT; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_getsockname( + ddsrt_socket_t sock, + struct sockaddr *addr, + socklen_t *addrlen) +{ + int err; + + assert(sock != INVALID_SOCKET); + assert(addr != NULL); + + if (getsockname(sock, addr, addrlen) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEFAULT: /* addrlen parameter is too small. */ + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINVAL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_getsockopt( + ddsrt_socket_t sock, + int32_t level, + int32_t optname, + void *optval, + socklen_t *optlen) +{ + int err, ret; + + if (level == IPPROTO_IP && (optname == IP_MULTICAST_TTL || + optname == IP_MULTICAST_LOOP)) + { + /* IP_MULTICAST_TTL and IP_MULTICAST_LOOP take a DWORD* rather than a + char* on Windows. */ + int dwoptlen = sizeof(DWORD); + DWORD dwoptval = *((unsigned char *)optval); + ret = getsockopt(sock, level, optname, (char *)&dwoptval, &dwoptlen); + if (ret != SOCKET_ERROR) { + assert(dwoptlen == sizeof(DWORD)); + *((unsigned char *)optval) = (unsigned char)dwoptval; + *optlen = sizeof( unsigned char ); + } + } else { + ret = getsockopt(sock, level, optname, optval, (int *)optlen); + } + + if (ret != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEFAULT: + case WSAEINVAL: + case WSAENOPROTOOPT: + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_setsockopt( + ddsrt_socket_t sock, + int32_t level, + int32_t optname, + const void *optval, + socklen_t optlen) +{ + int err, ret; + DWORD dwoptval; + + if (level == IPPROTO_IP && (optname == IP_MULTICAST_TTL || + optname == IP_MULTICAST_LOOP)) + { + /* On win32 IP_MULTICAST_TTL and IP_MULTICAST_LOOP take DWORD * param + rather than char * */ + dwoptval = *((unsigned char *)optval); + optval = &dwoptval; + optlen = sizeof(DWORD); + ret = setsockopt(sock, level, optname, optval, (int)optlen); + } else { + ret = setsockopt(sock, level, optname, optval, (int)optlen); + } + + if (ret != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEFAULT: + case WSAEINVAL: + case WSAENOPROTOOPT: + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + return DDS_RETCODE_IN_PROGRESS; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_setsocknonblocking( + ddsrt_socket_t sock, + bool nonblock) +{ + int err; + u_long mode; + + /* If mode = 0, blocking is enabled, + * if mode != 0, non-blocking is enabled. */ + mode = nonblock ? 1 : 0; + + if (ioctlsocket(sock, FIONBIO, &mode) != SOCKET_ERROR) + return DDS_RETCODE_OK; + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +static dds_retcode_t recv_error_to_retcode(int errnum) +{ + assert(errnum != WSANOTINITIALISED); + switch (errnum) { + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEFAULT: + return DDS_RETCODE_BAD_PARAMETER; + case WSAENOTCONN: + case WSAEINVAL: + return DDS_RETCODE_PRECONDITION_NOT_MET; + case WSAEINTR: + return DDS_RETCODE_INTERRUPTED; + case WSAEINPROGRESS: + case WSAEWOULDBLOCK: + return DDS_RETCODE_TRY_AGAIN; + case WSAENETRESET: + case WSAECONNABORTED: + case WSAECONNRESET: + case WSAETIMEDOUT: + return DDS_RETCODE_NO_CONNECTION; + case WSAEISCONN: + case WSAENOTSOCK: + case WSAEOPNOTSUPP: + case WSAESHUTDOWN: + return DDS_RETCODE_ILLEGAL_OPERATION; + case WSAEMSGSIZE: + return DDS_RETCODE_NOT_ENOUGH_SPACE; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_recv( + ddsrt_socket_t sock, + void *buf, + size_t len, + int flags, + ssize_t *rcvd) +{ + ssize_t n; + + assert(len < INT_MAX); + + if ((n = recv(sock, (char *)buf, (int)len, flags)) != SOCKET_ERROR) { + *rcvd = n; + return DDS_RETCODE_OK; + } + + return recv_error_to_retcode(WSAGetLastError()); +} + +dds_retcode_t +ddsrt_recvmsg( + ddsrt_socket_t sock, + ddsrt_msghdr_t *msg, + int flags, + ssize_t *rcvd) +{ + int err, n; + + assert(msg != NULL); + assert(msg->msg_iovlen == 1); + assert(msg->msg_controllen == 0); + + msg->msg_flags = 0; + n = recvfrom( + sock, + msg->msg_iov[0].iov_base, + msg->msg_iov[0].iov_len, + flags, + msg->msg_name, + &msg->msg_namelen); + + if (n != -1) { + *rcvd = n; + return DDS_RETCODE_OK; + } + + err = WSAGetLastError(); + if (err == WSAEMSGSIZE) { + /* Windows returns an error for too-large messages, UNIX expects the + original size and the MSG_TRUNC flag. MSDN states it is truncated, which + presumably means it returned as much of the message as it could. Return + that the message was one byte larger than the available space and set + MSG_TRUNC. */ + *rcvd = msg->msg_iov[0].iov_len + 1; + msg->msg_flags |= MSG_TRUNC; + } + + return recv_error_to_retcode(err); +} + +static dds_retcode_t +send_error_to_retcode(int errnum) +{ + assert(errnum != WSANOTINITIALISED); + switch (errnum) { + case WSAENETDOWN: /* Network subsystem failed. */ + return DDS_RETCODE_NO_NETWORK; + case WSAEACCES: /* Remote address is a broadcast address. */ + return DDS_RETCODE_NOT_ALLOWED; + case WSAEINTR: /* Blocking sockets call was cancelled. */ + return DDS_RETCODE_INTERRUPTED; + case WSAEINPROGRESS: /* Blocking sockets call in progress. */ + case WSA_IO_PENDING: /* Operation pending (WSASentTo). */ + return DDS_RETCODE_IN_PROGRESS; + case WSAEFAULT: /* A parameter was not part of the user address space or + destination address was to small (WSASendTo). */ + case WSAEADDRNOTAVAIL: /* Remote address is not valid (WSASentTo). */ + case WSAEAFNOSUPPORT: /* Remote address is in wrong family (WSASentTo). */ + return DDS_RETCODE_BAD_PARAMETER; + case WSAENETRESET: /* Time to live expired. */ + case WSAEHOSTUNREACH: /* Host is unreachable. */ + case WSAECONNABORTED: /* Time-out or other failure (send). */ + case WSAETIMEDOUT: /* Network or remote host failure (send). */ + case WSAENETUNREACH: /* Network is unreachable. (WSASentTo). */ + case WSA_OPERATION_ABORTED: /* Socket was closed (WSASentTo). */ + return DDS_RETCODE_NO_CONNECTION; + case WSAENOBUFS: + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAENOTCONN: /* Socket is not connected. */ + case WSAEINVAL: /* Socket has not been bound. */ + return DDS_RETCODE_PRECONDITION_NOT_MET; + case WSAENOTSOCK: /* Descriptor is not a socket. */ + case WSAEOPNOTSUPP: /* Operation not supported (send). */ + case WSAESHUTDOWN: /* Socket shut down. */ + return DDS_RETCODE_ILLEGAL_OPERATION; + case WSAEWOULDBLOCK: /* Socket is nonblocking and call would block. */ + return DDS_RETCODE_TRY_AGAIN; + case WSAEMSGSIZE: /* Message is larger than transport maximum. */ + return DDS_RETCODE_NOT_ENOUGH_SPACE; + default: + break; + } + + return DDS_RETCODE_ERROR; +} + +dds_retcode_t +ddsrt_send( + ddsrt_socket_t sock, + const void *buf, + size_t len, + int flags, + ssize_t *sent) +{ + int n; + + assert(buf != NULL); + assert(len <= INT_MAX); + assert(sent != NULL); + + if ((n = send(sock, buf, (int)len, flags)) != SOCKET_ERROR) { + *sent = n; + return DDS_RETCODE_OK; + } + + return send_error_to_retcode(WSAGetLastError()); +} + +/* Compile time check to ensure iovec matches WSABUF. */ +struct iovec_matches_WSABUF { + char sizeof_matches[sizeof(ddsrt_iovec_t) == sizeof(WSABUF) ? 1 : -1]; + char base_off_matches[offsetof(ddsrt_iovec_t, iov_base) == offsetof(WSABUF, buf) ? 1 : -1]; + char base_size_matches[sizeof(((ddsrt_iovec_t *)8)->iov_base) == sizeof(((WSABUF *)8)->buf) ? 1 : -1]; + char len_off_matches[offsetof(ddsrt_iovec_t, iov_len) == offsetof(WSABUF, len) ? 1 : -1]; + char len_size_matches[sizeof(((ddsrt_iovec_t *)8)->iov_len) == sizeof(((WSABUF *)8)->len) ? 1 : -1]; +}; + +dds_retcode_t +ddsrt_sendmsg( + ddsrt_socket_t sock, + const ddsrt_msghdr_t *msg, + int flags, + ssize_t *sent) +{ + int ret; + DWORD n; + + assert(msg != NULL); + assert(msg->msg_controllen == 0); + + ret = WSASendTo( + sock, + (WSABUF *)msg->msg_iov, + (DWORD)msg->msg_iovlen, + &n, + flags, + (SOCKADDR *)msg->msg_name, + msg->msg_namelen, + NULL, + NULL); + if (ret != SOCKET_ERROR) { + *sent = (ssize_t)n; + return DDS_RETCODE_OK; + } + + return send_error_to_retcode(WSAGetLastError()); +} + +dds_retcode_t +ddsrt_select( + int32_t nfds, + fd_set *readfds, + fd_set *writefds, + fd_set *errorfds, + dds_duration_t reltime, + int32_t *ready) +{ + int err; + int32_t n; + struct timeval tv = { .tv_sec = 0, .tv_usec = 0 }, *tvp = NULL; + + (void)nfds; + + tvp = ddsrt_duration_to_timeval_ceil(reltime, &tv); + if ((n = select(-1, readfds, writefds, errorfds, tvp)) != SOCKET_ERROR) { + *ready = n; + return (n == 0 ? DDS_RETCODE_TIMEOUT : DDS_RETCODE_OK); + } + + err = WSAGetLastError(); + assert(err != WSANOTINITIALISED); + switch (err) { + case WSAEFAULT: + return DDS_RETCODE_OUT_OF_RESOURCES; + case WSAENETDOWN: + return DDS_RETCODE_NO_NETWORK; + case WSAEINVAL: + case WSAENOTSOCK: + return DDS_RETCODE_BAD_PARAMETER; + case WSAEINPROGRESS: + return DDS_RETCODE_TRY_AGAIN; + default: + break; + } + + return DDS_RETCODE_ERROR; +} diff --git a/src/ddsrt/src/string.c b/src/ddsrt/src/string.c new file mode 100644 index 0000000..24d2631 --- /dev/null +++ b/src/ddsrt/src/string.c @@ -0,0 +1,180 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#if defined(__IAR_SYSTEMS_ICC__) +#define _DLIB_ADD_EXTRA_SYMBOLS /* Export strtok_r. */ +#endif +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/string.h" + +int +ddsrt_strcasecmp( + const char *s1, + const char *s2) +{ + int cr; + + while (*s1 && *s2) { + cr = tolower((unsigned char)*s1) - tolower((unsigned char)*s2); + if (cr) { + return cr; + } + s1++; + s2++; + } + cr = tolower((unsigned char)*s1) - tolower((unsigned char)*s2); + return cr; +} + +int +ddsrt_strncasecmp( + const char *s1, + const char *s2, + size_t n) +{ + int cr = 0; + + assert(s1 != NULL); + assert(s2 != NULL); + + while (*s1 && *s2 && n) { + cr = tolower((unsigned char)*s1) - tolower((unsigned char)*s2); + if (cr) { + return cr; + } + s1++; + s2++; + n--; + } + if (n) { + cr = tolower((unsigned char)*s1) - tolower((unsigned char)*s2); + } + return cr; +} + +char * +ddsrt_strtok_r( + char *str, + const char *delim, + char **saveptr) +{ +#if _WIN32 + return strtok_s(str, delim, saveptr); +#else + return strtok_r(str, delim, saveptr); +#endif +} + +char * +ddsrt_strsep(char **str, const char *sep) +{ + char *ret; + if (**str == '\0') + return 0; + ret = *str; + while (**str && strchr (sep, **str) == 0) + (*str)++; + if (**str != '\0') + { + **str = '\0'; + (*str)++; + } + return ret; +} + +size_t +ddsrt_strlcpy( + char * __restrict dest, + const char * __restrict src, + size_t size) +{ + size_t srclen = 0; + + assert(dest != NULL); + assert(src != NULL); + + /* strlcpy must return the number of bytes that (would) have been written, + i.e. the length of src. */ + srclen = strlen(src); + if (size > 0) { + size_t len = srclen; + if (size <= srclen) { + len = size - 1; + } + memcpy(dest, src, len); + dest[len] = '\0'; + } + + return srclen; +} + +/* NOTE: ddsrt_strlcat does not forward to strlcat too avoid a bug in the macOS + implementation where it does not return the right result if dest + contains more characters than the size specified if size is either + 0 or 1. */ +size_t +ddsrt_strlcat( + char * __restrict dest, + const char * __restrict src, + size_t size) +{ + size_t destlen, srclen; + + assert(dest != NULL); + assert(src != NULL); + + /* strlcat must return the number of bytes that (would) have been written, + i.e. the length of dest plus the length of src. */ + destlen = strlen(dest); + srclen = strlen(src); + if (SIZE_MAX == destlen) { + srclen = 0; + } else if ((SIZE_MAX - destlen) <= srclen) { + srclen = (SIZE_MAX - destlen) - 1; + } + if (size > 0 && --size > destlen) { + size_t len = srclen; + size -= destlen; + if (size <= srclen) { + len = size; + } + memcpy(dest + destlen, src, len); + dest[destlen + len] = '\0'; + } + + return destlen + srclen; +} + +void * +ddsrt_memdup(const void *src, size_t n) +{ + void *dest = NULL; + + if (n != 0 && (dest = ddsrt_malloc_s(n)) != NULL) { + memcpy(dest, src, n); + } + + return dest; +} + +char * +ddsrt_strdup( + const char *str) +{ + assert(str != NULL); + + return ddsrt_memdup(str, strlen(str) + 1); +} diff --git a/src/os/src/snippets/code/os_posix_errno.c b/src/ddsrt/src/string/posix/strerror.c similarity index 55% rename from src/os/src/snippets/code/os_posix_errno.c rename to src/ddsrt/src/string/posix/strerror.c index fa14408..f467e30 100644 --- a/src/os/src/snippets/code/os_posix_errno.c +++ b/src/ddsrt/src/string/posix/strerror.c @@ -15,36 +15,29 @@ #undef _GNU_SOURCE #define _POSIX_C_SOURCE 200112L -#include #include +#include +#include -#include "os/os.h" +#include "dds/ddsrt/string.h" -int -os_getErrno (void) +dds_retcode_t +ddsrt_strerror_r(int errnum, char *buf, size_t buflen) { - return errno; -} - -void -os_setErrno (int err) -{ - errno = err; -} - -int -os_strerror_r (int errnum, char *buf, size_t buflen) -{ - int err; - - assert(buf != NULL); - assert(buflen > 0); - - if ((err = os_errstr(errnum, buf, buflen)) == EINVAL) { - buf[0] = '\0'; /* null-terminate in case nothing is written */ - err = strerror_r(errnum, buf, buflen); - buf[buflen - 1] = '\0'; /* always null-terminate, just to be safe */ - } - - return err; + assert(buf != NULL); + assert(buflen > 0); + + switch (strerror_r(errnum, buf, buflen)) { + case 0: /* Success */ + buf[buflen - 1] = '\0'; /* Always null-terminate, just to be safe. */ + return DDS_RETCODE_OK; + case EINVAL: + return DDS_RETCODE_BAD_PARAMETER; + case ERANGE: + return DDS_RETCODE_NOT_ENOUGH_SPACE; + default: + break; + } + + return DDS_RETCODE_ERROR; } diff --git a/src/ddsrt/src/string/vxworks/strerror.c b/src/ddsrt/src/string/vxworks/strerror.c new file mode 100644 index 0000000..977422e --- /dev/null +++ b/src/ddsrt/src/string/vxworks/strerror.c @@ -0,0 +1,69 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include + +#include "dds/ddsrt/retcode.h" + +#ifdef _WRS_KERNEL + +extern char *strerrorIf(int errcode); + +/* VxWorks has a non-compliant strerror_r in kernel mode which only takes a + buffer and an error number. Providing a buffer smaller than NAME_MAX + 1 + (256) may result in a buffer overflow. See target/src/libc/strerror.c for + details. NAME_MAX is defined in limits.h. */ + +int +ddsrt_strerror_r(int errnum, char *buf, size_t buflen) +{ + const char *str; + + assert(buf != NULL); + assert(buflen > 0); + + if (buflen < (NAME_MAX + 1)) + return DDS_RETCODE_NOT_ENOUGH_SPACE; + if (strerrorIf(errnum) == NULL) + return DDS_RETCODE_BAD_PARAMETER; + + (void)strerror_r(errnum, buf); + return DDS_RETCODE_OK; +} + +#else + +int +ddsrt_strerror_r(int errnum, char *buf, size_t buflen) +{ + int err; + const char *str; + + assert(buf != NULL); + assert(buflen > 0); + + /* VxWorks's strerror_r always returns 0 (zero), so the only way to decide + if the error was truncated is to check if the last position in the buffer + is overwritten by strerror_r. */ + err = 0; + buf[buflen - 1] = 'x'; + (void)strerror_r(errnum, buf, buflen); + if (buf[buflen - 1] != 'x') + return DDS_RETCODE_NOT_ENOUGH_SPACE; + + buf[buflen - 1] = '\0'; /* Always null terminate, just to be safe. */ + + return DDS_RETCODE_OK; +} + +#endif /* _WRS_KERNEL */ diff --git a/src/ddsrt/src/string/windows/strerror.c b/src/ddsrt/src/string/windows/strerror.c new file mode 100644 index 0000000..08a6f41 --- /dev/null +++ b/src/ddsrt/src/string/windows/strerror.c @@ -0,0 +1,71 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "dds/ddsrt/types.h" +#include "dds/ddsrt/string.h" + +/* WSAGetLastError, GetLastError and errno + + Windows supports errno (The Microsoft c Run-Time Library for Windows CE + does so since version 15 (Visual Studio 2008)). Error codes set by the + Windows Sockets implementation, however, are NOT made available via the + errno variable. + + WSAGetLastError used to be the thread-safe version of GetLastError, but + nowadays is just an an alias for GetLastError as intended by Microsoft: + http://www.sockets.com/winsock.htm#Deviation_ErrorCodes + + There is no relationship between GetLastError and errno. + GetLastError returns the last error that occurred in a Windows API function + (for the current thread). errno contains the last error that occurred in the C + runtime library. Normally if a WinAPI call fails, e.g. CreateFile, GetLastError + should be used to retrieve the error. If a C runtime library function fails, + e.g. fopen, errno contains the error number. */ + +int +ddsrt_strerror_r( + int errnum, + char *buf, + size_t buflen) +{ + int orig_err; + DWORD cnt; + + assert(buf != NULL); + assert(buflen > 0); + + orig_err = GetLastError(); + cnt = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + errnum, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)buf, + (DWORD)buflen, + NULL); + + if (cnt == 0) { + if (GetLastError() == ERROR_MORE_DATA) { + return DDS_RETCODE_NOT_ENOUGH_SPACE; + } else { + return DDS_RETCODE_BAD_PARAMETER; + } + } + + /* ddsrt_strerror_r should not modify errno itself. */ + SetLastError(orig_err); + buf[buflen - 1] = '\0'; /* Always null-terminate, just to be safe. */ + + return DDS_RETCODE_OK; +} diff --git a/src/ddsrt/src/strtod.c b/src/ddsrt/src/strtod.c new file mode 100644 index 0000000..99e4f05 --- /dev/null +++ b/src/ddsrt/src/strtod.c @@ -0,0 +1,208 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include +#include +#include + +#include "dds/ddsrt/io.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/strtod.h" + +/* + * Determine the maximum size that a string should have to be + * able to contain a double. + * See the following site for the calculation explanation: + * http://stackoverflow.com/questions/1701055/what-is-the-maximum-length-in-chars-needed-to-represent-any-double-value + */ +#include +#define DOUBLE_STRING_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP) + +/* + * VALID_DOUBLE_CHAR(c) is used to determine if the given char + * can be valid when it appears in a string that should represent + * a double. + * It is used to detect the end of a double string representation. + * Because it doesn't consider context, it is possible that more + * characters are detected after the double (fi. when a few white + * spaces tail the double). This isn't that bad, because the call + * to strtod itself will handle these extra characters properly. + */ +#define VALID_DOUBLE_CHAR(c) ( (isspace((unsigned char)(c))) || /* (leading) whitespaces */ \ + (isxdigit((unsigned char)(c))) || /* (hexa)decimal digits */ \ + ((c) == '.') || /* ospl LC_NUMERIC */ \ + ((c) == os_lcNumericGet()) || /* locale LC_NUMERIC */ \ + ((c) == '+') || ((c) == '-') || /* signs */ \ + ((c) == 'x') || ((c) == 'X') || /* hexadecimal indication */ \ + ((c) == 'e') || ((c) == 'E') || /* exponent chars */ \ + ((c) == 'p') || ((c) == 'P') || /* binary exponent chars */ \ + ((c) == 'a') || ((c) == 'A') || /* char for NaN */ \ + ((c) == 'n') || ((c) == 'N') || /* char for NaN & INFINITY */ \ + ((c) == 'i') || ((c) == 'I') || /* char for INFINITY */ \ + ((c) == 'f') || ((c) == 'F') || /* char for INFINITY */ \ + ((c) == 't') || ((c) == 'T') || /* char for INFINITY */ \ + ((c) == 'y') || ((c) == 'Y')) /* char for INFINITY */ + + + +/** \brief Detect and return the LC_NUMERIC char of the locale. + */ +static char +os_lcNumericGet(void) +{ + static char lcNumeric = ' '; + + /* Detect lcNumeric only once. */ + if (lcNumeric == ' ') { + /* There could be multiple threads here, but it is still save and works. + * Only side effect is that possibly multiple os_reports are traced. */ + char num[] = { '\0', '\0', '\0', '\0' }; + (void) snprintf(num, 4, "%3.1f", 2.2); + lcNumeric = num [1]; + if (lcNumeric != '.') { + DDS_WARNING("Locale with LC_NUMERIC \'%c\' detected, which is not '.'. " + "This can decrease performance.", lcNumeric); + } + } + + return lcNumeric; +} + + +/** \brief Replace lcNumeric char with '.' in floating point string when locale dependent + * functions use a non '.' LC_NUMERIC, while we want locale indepenent '.'. + */ +static void +os_lcNumericReplace(char *str) { + /* We only need to replace when standard functions + * did not put a '.' in the result string. */ + char lcNumeric = os_lcNumericGet(); + if (lcNumeric != '.') { + str = strchr(str, lcNumeric); + if (str != NULL) { + *str = '.'; + } + } +} + +dds_retcode_t +ddsrt_strtod(const char *nptr, char **endptr, double *dblptr) +{ + double dbl; + int orig_errno; + dds_retcode_t ret = DDS_RETCODE_OK; + + assert(nptr != NULL); + assert(dblptr != NULL); + + orig_errno = errno; + errno = 0; + + if (os_lcNumericGet() == '.') { + /* The current locale uses '.', so strtod can be used as is. */ + dbl = strtod(nptr, endptr); + } else { + /* The current locale uses ',', so we can not use the standard functions as + is, but have to do extra work because ospl uses "x.x" doubles (notice + the dot). Just copy the string and replace the LC_NUMERIC. */ + char nptrCopy[DOUBLE_STRING_MAX_LENGTH]; + char *nptrCopyIdx; + char *nptrCopyEnd; + char *nptrIdx; + + /* It is possible that the given nptr just starts with a double + representation but continues with other data. To be able to copy not too + much and not too little, we have to scan across nptr until we detect the + doubles' end. */ + nptrIdx = (char*)nptr; + nptrCopyIdx = nptrCopy; + nptrCopyEnd = nptrCopyIdx + DOUBLE_STRING_MAX_LENGTH - 1; + while (VALID_DOUBLE_CHAR(*nptrIdx) && (nptrCopyIdx < nptrCopyEnd)) { + if (*nptrIdx == '.') { + /* Replace '.' with locale LC_NUMERIC to get strtod to work. */ + *nptrCopyIdx = os_lcNumericGet(); + } else { + *nptrCopyIdx = *nptrIdx; + } + nptrIdx++; + nptrCopyIdx++; + } + *nptrCopyIdx = '\0'; + + /* Now that we have a copy with the proper locale LC_NUMERIC, we can use + strtod() for the conversion. */ + dbl = strtod(nptrCopy, &nptrCopyEnd); + + /* Calculate the proper end char when needed. */ + if (endptr != NULL) { + *endptr = (char*)nptr + (nptrCopyEnd - nptrCopy); + } + } + + if ((dbl == HUGE_VALF || dbl == HUGE_VALL || dbl == 0) && errno == ERANGE) { + ret = DDS_RETCODE_OUT_OF_RANGE; + } else { + errno = orig_errno; + } + + *dblptr = dbl; + + return ret; +} + +dds_retcode_t +ddsrt_strtof(const char *nptr, char **endptr, float *fltptr) +{ + /* Just use os_strtod(). */ + /* FIXME: This will have to do for now, but a single-precision floating + point number is definitely not a double-precision floating point + number. */ + double dbl = 0.0; + dds_retcode_t ret; + + assert(nptr != NULL); + assert(fltptr != NULL); + + ret = ddsrt_strtod(nptr, endptr, &dbl); + *fltptr = (float)dbl; + return ret; +} + +int +ddsrt_dtostr(double src, char *str, size_t size) +{ + int i; + + assert(str != NULL); + + /* Use locale dependent standard function. */ + i = snprintf(str, size, "%0.15g", src); + /* Make sure the result is a locale independent "x.x" double. */ + os_lcNumericReplace(str); + return i; +} + +int +ddsrt_ftostr(float src, char *str, size_t size) +{ + int i; + + assert(str != NULL); + + /* Use locale dependent standard function. */ + i = snprintf(str, size, "%0.7g", src); + /* Make sure the result is a locale independent "x.x" float. */ + os_lcNumericReplace(str); + return i; +} diff --git a/src/ddsrt/src/strtol.c b/src/ddsrt/src/strtol.c new file mode 100644 index 0000000..c6b6a5f --- /dev/null +++ b/src/ddsrt/src/strtol.c @@ -0,0 +1,276 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "dds/ddsrt/strtol.h" + +int ddsrt_todigit(const int chr) +{ + if (chr >= '0' && chr <= '9') { + return chr - '0'; + } else if (chr >= 'a' && chr <= 'z') { + return 10 + (chr - 'a'); + } else if (chr >= 'A' && chr <= 'Z') { + return 10 + (chr - 'A'); + } + + return -1; +} + +static dds_retcode_t +ullfstr( + const char *str, + char **endptr, + int32_t base, + unsigned long long *ullng, + unsigned long long max) +{ + dds_retcode_t rc = DDS_RETCODE_OK; + int num; + size_t cnt = 0; + unsigned long long tot = 0; + + assert(str != NULL); + assert(ullng != NULL); + + if (base == 0) { + if (str[0] == '0') { + if ((str[1] == 'x' || str[1] == 'X') && ddsrt_todigit(str[2]) < 16) { + base = 16; + cnt = 2; + } else { + base = 8; + } + } else { + base = 10; + } + } else if (base == 16) { + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { + cnt = 2; + } + } else if (base < 2 || base > 36) { + return DDS_RETCODE_BAD_PARAMETER; + } + + while ((rc == DDS_RETCODE_OK) && + (num = ddsrt_todigit(str[cnt])) >= 0 && num < base) + { + if (tot <= (max / (unsigned) base)) { + tot *= (unsigned) base; + tot += (unsigned) num; + cnt++; + } else { + rc = DDS_RETCODE_OUT_OF_RANGE; + tot = max; + } + } + + if (endptr != NULL) { + *endptr = (char *)str + cnt; + } + + *ullng = tot; + + return rc; +} + +dds_retcode_t +ddsrt_strtoll( + const char *str, + char **endptr, + int32_t base, + long long *llng) +{ + dds_retcode_t rc = DDS_RETCODE_OK; + size_t cnt = 0; + long long tot = 1; + unsigned long long ullng = 0, max = INT64_MAX; + + assert(str != NULL); + assert(llng != NULL); + + for (; isspace((unsigned char)str[cnt]); cnt++) { + /* Ignore leading whitespace. */ + } + + if (str[cnt] == '-') { + tot = -1; + max++; + cnt++; + } else if (str[cnt] == '+') { + cnt++; + } + + rc = ullfstr(str + cnt, endptr, base, &ullng, max); + if (endptr && *endptr == (str + cnt)) + *endptr = (char *)str; + if (rc != DDS_RETCODE_BAD_PARAMETER) + *llng = tot * (long long)ullng; + + return rc; +} + +dds_retcode_t +ddsrt_strtoull( + const char *str, + char **endptr, + int32_t base, + unsigned long long *ullng) +{ + dds_retcode_t rc = DDS_RETCODE_OK; + size_t cnt = 0; + unsigned long long tot = 1; + unsigned long long max = UINT64_MAX; + + assert(str != NULL); + assert(ullng != NULL); + + for (; isspace((unsigned char)str[cnt]); cnt++) { + /* ignore leading whitespace */ + } + + if (str[cnt] == '-') { + tot = (unsigned long long) -1; + cnt++; + } else if (str[cnt] == '+') { + cnt++; + } + + rc = ullfstr(str + cnt, endptr, base, ullng, max); + if (endptr && *endptr == (str + cnt)) + *endptr = (char *)str; + if (rc != DDS_RETCODE_BAD_PARAMETER) + *ullng *= tot; + + return rc; +} + +dds_retcode_t +ddsrt_atoll( + const char *str, + long long *llng) +{ + return ddsrt_strtoll(str, NULL, 10, llng); +} + +dds_retcode_t +ddsrt_atoull( + const char *str, + unsigned long long *ullng) +{ + return ddsrt_strtoull(str, NULL, 10, ullng); +} + +char * +ddsrt_ulltostr( + unsigned long long num, + char *str, + size_t len, + char **endptr) +{ + char chr, *ptr; + size_t cnt; + size_t lim = 0; + size_t tot = 0; + + assert (str != NULL); + + if (len > 1) { + lim = len - 1; + + do { + str[tot] = (char)('0' + (int)(num % 10)); + num /= 10; + + if (tot == (lim - 1)) { + if (num > 0ULL) { + /* Simply using memmove would have been easier, but the function is + safe to use in asynchronous code like this. Normally this code + should not affect performance, because ideally the buffer is + sufficiently large enough. */ + for (cnt = 0; cnt < tot; cnt++) { + str[cnt] = str[cnt + 1]; + } + } + } else if (num > 0ULL) { + tot++; + } + } while (num > 0ULL); + + lim = tot + 1; + } + + for (cnt = 0; cnt < (tot - cnt); cnt++) { + chr = str[tot - cnt]; + str[tot - cnt] = str[cnt]; + str[cnt] = chr; + } + + if (len == 0) { + str = NULL; + ptr = NULL; + } else { + str[lim] = '\0'; + ptr = str + lim; + } + + if (endptr != NULL) { + *endptr = ptr; + } + + return str; +} + +char * +ddsrt_lltostr( + long long num, + char *str, + size_t len, + char **endptr) +{ + unsigned long long pos; + char *ptr; + size_t cnt = 0; + + assert (str != NULL); + + if (len == 0) { + str = NULL; + ptr = NULL; + } else if (len == 1) { + str[0] = '\0'; + ptr = str; + } else { + if (num < 0LL) { + if (num == INT64_MIN) { + pos = (unsigned long long)INT64_MAX + 1; + } else { + pos = (unsigned long long) -num; + } + + str[cnt++] = '-'; + } else { + pos = (unsigned long long) num; + } + + (void)ddsrt_ulltostr(pos, str + cnt, len - cnt, &ptr); + } + + if (endptr != NULL) { + *endptr = ptr; + } + + return str; +} diff --git a/src/ddsrt/src/sync/posix/sync.c b/src/ddsrt/src/sync/posix/sync.c new file mode 100644 index 0000000..929da08 --- /dev/null +++ b/src/ddsrt/src/sync/posix/sync.c @@ -0,0 +1,236 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include +#include +#include +#include + +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/timeconv.h" + +void ddsrt_mutex_init (ddsrt_mutex_t *mutex) +{ + int shared; + assert (mutex != NULL); + + pthread_mutex_init (&mutex->mutex, NULL); + (void)shared; +} + +void ddsrt_mutex_destroy (ddsrt_mutex_t *mutex) +{ + assert (mutex != NULL); + + if (pthread_mutex_destroy (&mutex->mutex) != 0) + abort(); +} + +void ddsrt_mutex_lock (ddsrt_mutex_t *mutex) +{ + assert (mutex != NULL); + + if (pthread_mutex_lock (&mutex->mutex) != 0) + abort(); +} + +bool +ddsrt_mutex_trylock (ddsrt_mutex_t *mutex) +{ + int err; + assert (mutex != NULL); + + err = pthread_mutex_trylock (&mutex->mutex); + if (err != 0 && err != EBUSY) + abort(); + return (err == 0); +} + +void +ddsrt_mutex_unlock (ddsrt_mutex_t *mutex) +{ + assert (mutex != NULL); + + if (pthread_mutex_unlock (&mutex->mutex) != 0) + abort(); +} + +void +ddsrt_cond_init (ddsrt_cond_t *cond) +{ + assert (cond != NULL); + + pthread_cond_init (&cond->cond, NULL); +} + +void +ddsrt_cond_destroy (ddsrt_cond_t *cond) +{ + assert (cond != NULL); + + if (pthread_cond_destroy (&cond->cond) != 0) + abort(); +} + +void +ddsrt_cond_wait (ddsrt_cond_t *cond, ddsrt_mutex_t *mutex) +{ + assert (cond != NULL); + assert (mutex != NULL); + + if (pthread_cond_wait (&cond->cond, &mutex->mutex) != 0) + abort(); +} + +bool +ddsrt_cond_waituntil( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_time_t abstime) +{ + struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 }; + + assert(cond != NULL); + assert(mutex != NULL); + + if (abstime == DDS_NEVER) { + ddsrt_cond_wait(cond, mutex); + return true; + } + if (abstime > 0) { + ts.tv_sec = abstime / DDS_NSECS_IN_SEC; + ts.tv_nsec = abstime % DDS_NSECS_IN_SEC; + } + + switch (pthread_cond_timedwait(&cond->cond, &mutex->mutex, &ts)) { + case 0: + return true; + case ETIMEDOUT: + return false; + default: + break; + } + + abort(); +} + +bool +ddsrt_cond_waitfor( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_duration_t reltime) +{ + assert(cond != NULL); + assert(mutex != NULL); + + return ddsrt_cond_waituntil( + cond, mutex, ddsrt_time_add_duration(dds_time(), reltime)); +} + +void +ddsrt_cond_signal (ddsrt_cond_t *cond) +{ + assert (cond != NULL); + + if (pthread_cond_signal (&cond->cond) != 0) + abort(); +} + +void +ddsrt_cond_broadcast (ddsrt_cond_t *cond) +{ + assert (cond != NULL); + + if (pthread_cond_broadcast (&cond->cond) != 0) + abort(); +} + +void +ddsrt_rwlock_init (ddsrt_rwlock_t *rwlock) +{ + int err = 0; + + assert(rwlock != NULL); + + /* process-shared attribute is set to PTHREAD_PROCESS_PRIVATE by default */ + if ((err = pthread_rwlock_init(&rwlock->rwlock, NULL)) != 0) + abort(); +} + +void +ddsrt_rwlock_destroy (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + if ((err = pthread_rwlock_destroy (&rwlock->rwlock)) != 0) + abort(); +} + +void ddsrt_rwlock_read (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + err = pthread_rwlock_rdlock(&rwlock->rwlock); + assert(err == 0); + (void)err; +} + +void ddsrt_rwlock_write (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + err = pthread_rwlock_wrlock(&rwlock->rwlock); + assert(err == 0); + (void)err; +} + +bool ddsrt_rwlock_tryread (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + err = pthread_rwlock_tryrdlock(&rwlock->rwlock); + assert(err == 0 || err == EBUSY); + return err == 0; +} + +bool ddsrt_rwlock_trywrite (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + err = pthread_rwlock_trywrlock(&rwlock->rwlock); + assert(err == 0 || err == EBUSY); + + return err == 0; +} + +void ddsrt_rwlock_unlock (ddsrt_rwlock_t *rwlock) +{ + int err; + + assert(rwlock != NULL); + err = pthread_rwlock_unlock(&rwlock->rwlock); + assert(err == 0); + (void)err; +} + +void ddsrt_once (ddsrt_once_t *control, ddsrt_once_fn init_fn) +{ + /* There are no defined errors that can be returned by pthread_once */ + (void)pthread_once(control, init_fn); +} diff --git a/src/ddsrt/src/sync/windows/sync.c b/src/ddsrt/src/sync/windows/sync.c new file mode 100644 index 0000000..b069239 --- /dev/null +++ b/src/ddsrt/src/sync/windows/sync.c @@ -0,0 +1,214 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/timeconv.h" + +void ddsrt_mutex_init(ddsrt_mutex_t *mutex) +{ + assert(mutex != NULL); + InitializeSRWLock(&mutex->lock); +} + +void ddsrt_mutex_destroy(ddsrt_mutex_t *mutex) +{ + assert(mutex != NULL); +} + +void ddsrt_mutex_lock(ddsrt_mutex_t *mutex) +{ + assert(mutex != NULL); + AcquireSRWLockExclusive(&mutex->lock); +} + +bool ddsrt_mutex_trylock(ddsrt_mutex_t *mutex) +{ + assert(mutex != NULL); + return TryAcquireSRWLockExclusive(&mutex->lock); +} + +void ddsrt_mutex_unlock(ddsrt_mutex_t *mutex) +{ + assert(mutex != NULL); + ReleaseSRWLockExclusive(&mutex->lock); +} + +void ddsrt_cond_init (ddsrt_cond_t *cond) +{ + assert(cond != NULL); + InitializeConditionVariable(&cond->cond); +} + +void ddsrt_cond_destroy(ddsrt_cond_t *cond) +{ + assert(cond != NULL); +} + +void +ddsrt_cond_wait(ddsrt_cond_t *cond, ddsrt_mutex_t *mutex) +{ + assert(cond != NULL); + assert(mutex != NULL); + + if (!SleepConditionVariableSRW(&cond->cond, &mutex->lock, INFINITE, 0)) { + abort(); + } +} + +bool +ddsrt_cond_waituntil( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_time_t abstime) +{ + dds_duration_t reltime; + + assert(cond != NULL); + assert(mutex != NULL); + + if (abstime == DDS_NEVER) { + reltime = DDS_INFINITY; + } else { + dds_time_t time = dds_time(); + reltime = (abstime > time ? abstime - time : 0); + } + + return ddsrt_cond_waitfor(cond, mutex, reltime); +} + +bool +ddsrt_cond_waitfor( + ddsrt_cond_t *cond, + ddsrt_mutex_t *mutex, + dds_duration_t reltime) +{ + dds_time_t abstime; + DWORD msecs; + + assert(cond != NULL); + assert(mutex != NULL); + + if (reltime == DDS_INFINITY) { + ddsrt_cond_wait(cond, mutex); + return true; + } + + abstime = ddsrt_time_add_duration(dds_time(), reltime); + msecs = ddsrt_duration_to_msecs_ceil(reltime); + if (SleepConditionVariableSRW(&cond->cond, &mutex->lock, msecs, 0)) { + return true; + } else if (GetLastError() != ERROR_TIMEOUT) { + abort(); + } + + return (dds_time() >= abstime) ? false : true; +} + +void ddsrt_cond_signal (ddsrt_cond_t *cond) +{ + assert(cond != NULL); + WakeConditionVariable(&cond->cond); +} + +void ddsrt_cond_broadcast (ddsrt_cond_t *cond) +{ + assert(cond != NULL); + WakeAllConditionVariable(&cond->cond); +} + +void ddsrt_rwlock_init (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + InitializeSRWLock(&rwlock->lock); + rwlock->state = 0; +} + +void ddsrt_rwlock_destroy (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); +} + +void ddsrt_rwlock_read (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + AcquireSRWLockShared(&rwlock->lock); + rwlock->state = 1; +} + +void ddsrt_rwlock_write(ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + AcquireSRWLockExclusive(&rwlock->lock); + rwlock->state = -1; +} + +bool ddsrt_rwlock_tryread (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + if (TryAcquireSRWLockShared(&rwlock->lock)) { + rwlock->state = 1; + return true; + } + return false; +} + +bool ddsrt_rwlock_trywrite (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + if (TryAcquireSRWLockExclusive(&rwlock->lock)) { + rwlock->state = -1; + return true; + } + return false; +} + +void ddsrt_rwlock_unlock (ddsrt_rwlock_t *rwlock) +{ + assert(rwlock); + assert(rwlock->state != 0); + if (rwlock->state > 0) { + ReleaseSRWLockShared(&rwlock->lock); + } else { + ReleaseSRWLockExclusive(&rwlock->lock); + } +} + +typedef struct { + ddsrt_once_fn init_fn; +} once_arg_t; + +static BOOL WINAPI +once_wrapper( + PINIT_ONCE InitOnce, + PVOID Parameter, + PVOID *Context) +{ + once_arg_t *wrap = (once_arg_t *)Parameter; + + assert(Parameter != NULL); + assert(Context == NULL); + + wrap->init_fn(); + + return TRUE; +} + +void +ddsrt_once( + ddsrt_once_t *control, + ddsrt_once_fn init_fn) +{ + once_arg_t wrap = { .init_fn = init_fn }; + (void) InitOnceExecuteOnce(control, &once_wrapper, &wrap, NULL); +} diff --git a/src/os/src/snippets/code/os_stdlib_memdup.c b/src/ddsrt/src/threads.c similarity index 65% rename from src/os/src/snippets/code/os_stdlib_memdup.c rename to src/ddsrt/src/threads.c index e2abb47..40cc646 100644 --- a/src/os/src/snippets/code/os_stdlib_memdup.c +++ b/src/ddsrt/src/threads.c @@ -9,16 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" +#include -void * -os_memdup(const void *src, size_t n) +#include "dds/ddsrt/threads.h" + +void +ddsrt_threadattr_init ( + ddsrt_threadattr_t *tattr) { - void *dest = NULL; - - if (n != 0 && (dest = os_malloc_s(n)) != NULL) { - memcpy(dest, src, n); - } - - return dest; + assert(tattr != NULL); + tattr->schedClass = DDSRT_SCHED_DEFAULT; + tattr->schedPriority = 0; + tattr->stackSize = 0; } diff --git a/src/ddsrt/src/threads/include/dds/ddsrt/threads_priv.h b/src/ddsrt/src/threads/include/dds/ddsrt/threads_priv.h new file mode 100644 index 0000000..b10118c --- /dev/null +++ b/src/ddsrt/src/threads/include/dds/ddsrt/threads_priv.h @@ -0,0 +1,30 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#ifndef DDSRT_THREAD_TYPES_H +#define DDSRT_THREAD_TYPES_H + +#include "dds/ddsrt/threads.h" + +typedef struct { + char *name; + ddsrt_thread_routine_t routine; + void *arg; +} thread_context_t; + +/** \brief Internal structure used to store cleanup handlers (private) */ +typedef struct { + void *prev; + void (*routine)(void *); + void *arg; +} thread_cleanup_t; + +#endif /* DDSRT_THREAD_TYPES_H */ diff --git a/src/ddsrt/src/threads/posix/threads.c b/src/ddsrt/src/threads/posix/threads.c new file mode 100644 index 0000000..278d796 --- /dev/null +++ b/src/ddsrt/src/threads/posix/threads.c @@ -0,0 +1,447 @@ +/* + * 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 + */ + +/* _GNU_SOURCE is required for pthread_getname_np and pthread_setname_np. */ +#define _GNU_SOURCE +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/threads_priv.h" +#include "dds/ddsrt/types.h" + +#if defined(__linux) +#include +#define MAXTHREADNAMESIZE (15) /* 16 bytes including null-terminating byte. */ +#elif defined(__APPLE__) +#include /* MAXTHREADNAMESIZE */ +#elif defined(__sun) +#define MAXTHREADNAMESIZE (31) +#elif defined(__FreeBSD__) +/* Required for pthread_get_name_np and pthread_set_name_np. */ +#include +#include +#define MAXTHREADNAMESIZE (MAXCOMLEN) +#elif defined(__VXWORKS__) +#include +/* VX_TASK_NAME_LENGTH is the maximum number of bytes, excluding + null-terminating byte, for a thread name. */ +#define MAXTHREADNAMESIZE (VX_TASK_NAME_LENGTH) +#endif /* __APPLE__ */ + +size_t +ddsrt_thread_getname(char *str, size_t size) +{ + char buf[MAXTHREADNAMESIZE + 1] = ""; + size_t cnt = 0; + + assert(str != NULL); + assert(size > 0); + +#if defined(__linux) + /* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the + buffer is smaller than 16 bytes. Use an intermediate buffer. */ + (void)pthread_getname_np(pthread_self(), buf, sizeof(buf)); + cnt = ddsrt_strlcpy(str, buf, size); +#elif defined(__APPLE__) + /* pthread_getname_np on APPLE uses strlcpy to copy the thread name, but + does not return the number of bytes (that would have been) written. Use + an intermediate buffer. */ + (void)pthread_getname_np(pthread_self(), buf, sizeof(buf)); + cnt = ddsrt_strlcpy(str, buf, size); +#elif defined(__FreeBSD__) + (void)pthread_get_name_np(pthread_self(), buf, sizeof(buf)); + cnt = ddsrt_strlcpy(str, buf, size); +#elif defined(__sun) + (void)pthread_getname_np(pthread_self(), buf, sizeof(buf)); + cnt = ddsrt_strlcpy(str, buf, size); +#elif defined(__VXWORKS__) + { + char *ptr; + /* VxWorks does not support retrieving the name of a task through the + POSIX thread API, but the task API offers it through taskName. */ + /* Do not free the pointer returned by taskName. See + src/wind/taskInfo.c for details. */ + ptr = taskName(taskIdSelf()); + if (ptr == NULL) { + ptr = buf; + } + cnt = ddsrt_strlcpy(str, ptr, size); + } +#endif + + /* Thread identifier is used as fall back if thread name lookup is not + supported or the thread name is empty. */ + if (cnt == 0) { + ddsrt_tid_t tid = ddsrt_gettid(); + cnt = (size_t)snprintf(str, size, "%"PRIdTID, tid); + } + + return cnt; +} + +void +ddsrt_thread_setname(const char *__restrict name) +{ + assert(name != NULL); + +#if defined(__linux) + /* Thread names are limited to 16 bytes on Linux. ERANGE is returned if the + name exceeds the limit, so silently truncate. */ + char buf[MAXTHREADNAMESIZE + 1] = ""; + ddsrt_strlcpy(buf, name, sizeof(buf)); + (void)pthread_setname_np(pthread_self(), name); +#elif defined(__APPLE__) + (void)pthread_setname_np(name); +#elif defined(__FreeBSD__) + (void)pthread_set_name_np(pthread_self(), name); +#elif defined(__sun) + /* Thread names are limited to 31 bytes on Solaris. Excess bytes are + silently truncated. */ + (void)pthread_setname_np(pthread_self(), name); +#else + /* VxWorks does not support the task name to be set after a task is created. + Setting the name of a task can be done through pthread_attr_setname. */ +#warning "ddsrt_thread_setname is not supported" +#endif +} + +/** \brief Wrap thread start routine + * + * \b os_startRoutineWrapper wraps a threads starting routine. + * before calling the user routine, it sets the threads name + * in the context of the thread. With \b pthread_getspecific, + * the name can be retreived for different purposes. + */ +static void *os_startRoutineWrapper (void *threadContext) +{ + thread_context_t *context = threadContext; + uintptr_t resultValue; + + ddsrt_thread_setname(context->name); + + /* Call the user routine */ + resultValue = context->routine (context->arg); + + /* Free the thread context resources, arguments is responsibility */ + /* for the caller of os_procCreate */ + ddsrt_free(context->name); + ddsrt_free(context); + +#if defined(__VXWORKS__) && !defined(_WRS_KERNEL) + struct sched_param sched_param; + int max, policy = 0; + + /* There is a known issue in pthread_join on VxWorks 6.x RTP mode. + + WindRiver: When pthread_join returns, it does not indicate end of a + thread in 100% of the situations. If the thread that calls pthread_join + has a higher priority than the thread that is currently terminating, + pthread_join could return before pthread_exit has finished. This + conflicts with the POSIX specification that dictates that pthread_join + must only return when the thread is really terminated. The workaround + suggested by WindRiver support is to increase the priority of the thread + (task) to be terminated before handing back the semaphore to ensure the + thread exits before pthread_join returns. + + This bug was submitted to WindRiver as TSR 815826. */ + + /* Note that any possible errors raised here are not terminal since the + thread may have exited at this point anyway. */ + if (pthread_getschedparam(thread.v, &policy, &sched_param) == 0) { + max = sched_get_priority_max(policy); + if (max != -1) { + (void)pthread_setschedprio(thread.v, max); + } + } +#endif + + /* return the result of the user routine */ + return (void *)resultValue; +} + +dds_retcode_t +ddsrt_thread_create ( + ddsrt_thread_t *threadptr, + const char *name, + const ddsrt_threadattr_t *threadAttr, + uint32_t (*start_routine) (void *), + void *arg) +{ + pthread_attr_t attr; + thread_context_t *ctx; + ddsrt_threadattr_t tattr; + int result, create_ret; + + assert (threadptr != NULL); + assert (name != NULL); + assert (threadAttr != NULL); + assert (start_routine != NULL); + tattr = *threadAttr; + + if (pthread_attr_init (&attr) != 0) + return DDS_RETCODE_ERROR; + +#if defined(__VXWORKS__) + /* pthread_setname_np is not available on VxWorks. Use pthread_attr_setname + instead (proprietary VxWorks extension). */ + (void)pthread_attr_setname (&attr, name); +#endif + + if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM) != 0 || + pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE) != 0) + goto err; + + if (tattr.stackSize != 0) + { +#ifdef PTHREAD_STACK_MIN + if (tattr.stackSize < PTHREAD_STACK_MIN) + tattr.stackSize = PTHREAD_STACK_MIN; +#endif + if ((result = pthread_attr_setstacksize (&attr, tattr.stackSize)) != 0) + { + DDS_ERROR ("ddsrt_thread_create(%s): pthread_attr_setstacksize(%"PRIu32") failed with error %d\n", name, tattr.stackSize, result); + goto err; + } + } + + if (tattr.schedClass == DDSRT_SCHED_DEFAULT) + { + if (tattr.schedPriority != 0) + { + /* If caller doesn't set the class, he must not try to set the priority, which we + approximate by expecting a 0. FIXME: should do this as part of config validation */ + DDS_ERROR("ddsrt_thread_create(%s): schedClass DEFAULT but priority != 0 is unsupported\n", name); + goto err; + } + } + else + { + int policy; + struct sched_param sched_param; + if ((result = pthread_getschedparam (pthread_self (), &policy, &sched_param) != 0) != 0) + { + DDS_ERROR("ddsrt_thread_create(%s): pthread_attr_getschedparam(self) failed with error %d\n", name, result); + goto err; + } + switch (tattr.schedClass) + { + case DDSRT_SCHED_DEFAULT: + assert (0); + break; + case DDSRT_SCHED_REALTIME: + policy = SCHED_FIFO; + break; + case DDSRT_SCHED_TIMESHARE: + policy = SCHED_OTHER; + break; + } + if ((result = pthread_attr_setschedpolicy (&attr, policy)) != 0) + { + DDS_ERROR("ddsrt_thread_create(%s): pthread_attr_setschedpolicy(%d) failed with error %d\n", name, policy, result); + goto err; + } + sched_param.sched_priority = tattr.schedPriority; + if ((result = pthread_attr_setschedparam (&attr, &sched_param)) != 0) + { + DDS_ERROR("ddsrt_thread_create(%s): pthread_attr_setschedparam(priority = %d) failed with error %d\n", name, tattr.schedPriority, result); + goto err; + } + if ((result = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED)) != 0) + { + DDS_ERROR("ddsrt_thread_create(%s): pthread_attr_setinheritsched(EXPLICIT) failed with error %d\n", name, result); + goto err; + } + } + + /* Construct context structure & start thread */ + ctx = ddsrt_malloc (sizeof (thread_context_t)); + ctx->name = ddsrt_malloc (strlen (name) + 1); + strcpy (ctx->name, name); + ctx->routine = start_routine; + ctx->arg = arg; + if ((create_ret = pthread_create (&threadptr->v, &attr, os_startRoutineWrapper, ctx)) != 0) + { + DDS_ERROR ("os_threadCreate(%s): pthread_create failed with error %d\n", name, create_ret); + goto err_create; + } + pthread_attr_destroy (&attr); + return DDS_RETCODE_OK; + +err_create: + ddsrt_free (ctx->name); + ddsrt_free (ctx); +err: + pthread_attr_destroy (&attr); + return DDS_RETCODE_ERROR; +} + +ddsrt_tid_t +ddsrt_gettid(void) +{ + ddsrt_tid_t tid; + +#if defined(__linux) + tid = syscall(SYS_gettid); +#elif defined(__FreeBSD__) && (__FreeBSD_version >= 900031) + /* FreeBSD >= 9.0 */ + tid = pthread_getthreadid_np(); +#elif defined(__APPLE__) && !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \ + __MAC_OS_X_VERSION_MIN_REQUIRED < 1060) + /* macOS >= 10.6 */ + pthread_threadid_np(NULL, &tid); +#elif defined(__VXWORKS__) + tid = taskIdSelf(); +#else + tid = (uintmax_t)((uintptr_t)pthread_self()); +#endif + + return tid; +} + +ddsrt_thread_t +ddsrt_thread_self(void) +{ + ddsrt_thread_t id = {.v = pthread_self ()}; + return id; +} + +bool ddsrt_thread_equal(ddsrt_thread_t a, ddsrt_thread_t b) +{ + return (pthread_equal(a.v, b.v) != 0); +} + +dds_retcode_t +ddsrt_thread_join(ddsrt_thread_t thread, uint32_t *thread_result) +{ + int err; + void *vthread_result; + + assert (thread.v); + + + if ((err = pthread_join (thread.v, &vthread_result)) != 0) + { + DDS_TRACE ("pthread_join(0x%"PRIxMAX") failed with error %d\n", (uintmax_t)((uintptr_t)thread.v), err); + return DDS_RETCODE_ERROR; + } + + if (thread_result) + *thread_result = (uint32_t) ((uintptr_t) vthread_result); + return DDS_RETCODE_OK; +} + + +static pthread_key_t thread_cleanup_key; +static pthread_once_t thread_once = PTHREAD_ONCE_INIT; + +static void thread_cleanup_fini(void *arg); + +static void thread_init_once(void) +{ + int err; + + err = pthread_key_create(&thread_cleanup_key, &thread_cleanup_fini); + assert(err == 0); + (void)err; +} + +static void thread_init(void) +{ + (void)pthread_once(&thread_once, &thread_init_once); +} + +dds_retcode_t ddsrt_thread_cleanup_push (void (*routine) (void *), void *arg) +{ + int err; + thread_cleanup_t *prev, *tail; + + assert(routine != NULL); + + thread_init(); + if ((tail = ddsrt_calloc(1, sizeof(*tail))) != NULL) { + prev = pthread_getspecific(thread_cleanup_key); + tail->prev = prev; + tail->routine = routine; + tail->arg = arg; + if ((err = pthread_setspecific(thread_cleanup_key, tail)) != 0) { + assert(err != EINVAL); + return DDS_RETCODE_OUT_OF_RESOURCES; + } + return DDS_RETCODE_OK; + } + return DDS_RETCODE_OUT_OF_RESOURCES; +} + +dds_retcode_t ddsrt_thread_cleanup_pop (int execute) +{ + int err; + thread_cleanup_t *tail; + + thread_init(); + if ((tail = pthread_getspecific(thread_cleanup_key)) != NULL) { + if ((err = pthread_setspecific(thread_cleanup_key, tail->prev)) != 0) { + assert(err != EINVAL); + return DDS_RETCODE_OUT_OF_RESOURCES; + } + if (execute) { + tail->routine(tail->arg); + } + ddsrt_free(tail); + } + return DDS_RETCODE_OK; +} + +static void thread_cleanup_fini(void *arg) +{ + thread_cleanup_t *tail, *prev; + + tail = (thread_cleanup_t *)arg; + while (tail != NULL) { + prev = tail->prev; + assert(tail->routine != NULL); + tail->routine(tail->arg); + ddsrt_free(tail); + tail = prev; + } + + /* Thread-specific value associated with thread_cleanup_key will already be + nullified if invoked as destructor, i.e. not from ddsrt_thread_fini. */ +} + +void ddsrt_thread_init(void) +{ + thread_init(); +} + +void ddsrt_thread_fini(void) +{ + thread_cleanup_t *tail; + + thread_init(); + if ((tail = pthread_getspecific(thread_cleanup_key)) != NULL) { + thread_cleanup_fini(tail); + (void)pthread_setspecific(thread_cleanup_key, NULL); + } +} diff --git a/src/ddsrt/src/threads/windows/threads.c b/src/ddsrt/src/threads/windows/threads.c new file mode 100644 index 0000000..ffba453 --- /dev/null +++ b/src/ddsrt/src/threads/windows/threads.c @@ -0,0 +1,303 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/threads_priv.h" + +static uint32_t +os_startRoutineWrapper( + void *threadContext) +{ + thread_context_t *context = threadContext; + uint32_t resultValue = 0; + + ddsrt_thread_setname(context->name); + + /* Call the user routine */ + resultValue = context->routine(context->arg); + + /* Free the thread context resources, arguments is responsibility */ + /* for the caller of os_threadCreate */ + ddsrt_free(context->name); + ddsrt_free(context); + + /* return the result of the user routine */ + return resultValue; +} + +dds_retcode_t +ddsrt_thread_create( + ddsrt_thread_t *thrptr, + const char *name, + const ddsrt_threadattr_t *attr, + ddsrt_thread_routine_t start_routine, + void *arg) +{ + ddsrt_thread_t thr; + thread_context_t *ctx; + int32_t prio; + + assert(thrptr != NULL); + assert(name != NULL); + assert(attr != NULL); + assert(start_routine != NULL); + + if ((ctx = ddsrt_malloc(sizeof(*ctx))) == NULL || + (ctx->name = ddsrt_strdup(name)) == NULL) + return DDS_RETCODE_OUT_OF_RESOURCES; + + ctx->routine = start_routine; + ctx->arg = arg; + thr.handle = CreateThread(NULL, + (SIZE_T)attr->stackSize, + (LPTHREAD_START_ROUTINE)os_startRoutineWrapper, + (LPVOID)ctx, + (DWORD)0, + &thr.tid); + + if (thr.handle == NULL) + return DDS_RETCODE_ERROR; + + *thrptr = thr; + + /* Windows thread priorities are in the range below: + -15 : THREAD_PRIORITY_IDLE + -2 : THREAD_PRIORITY_LOWEST + -1 : THREAD_PRIORITY_BELOW_NORMAL + 0 : THREAD_PRIORITY_NORMAL + 1 : THREAD_PRIORITY_ABOVE_NORMAL + 2 : THREAD_PRIORITY_HIGHEST + 15 : THREAD_PRIORITY_TIME_CRITICAL + For realtime threads additional values are allowed: */ + + /* PROCESS_QUERY_INFORMATION rights required to call GetPriorityClass + Ensure that priorities are effectively in the allowed range depending + on GetPriorityClass result. */ + /* FIXME: The logic here might be incorrect. + https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreadpriority */ + prio = attr->schedPriority; + if (GetPriorityClass(GetCurrentProcess()) == REALTIME_PRIORITY_CLASS) { + if (attr->schedPriority < -7) + prio = THREAD_PRIORITY_IDLE; + else if (attr->schedPriority > 6) + prio = THREAD_PRIORITY_TIME_CRITICAL; + } else { + if (attr->schedPriority < THREAD_PRIORITY_LOWEST) + prio = THREAD_PRIORITY_IDLE; + else if (attr->schedPriority > THREAD_PRIORITY_HIGHEST) + prio = THREAD_PRIORITY_TIME_CRITICAL; + } + + if (SetThreadPriority(thr.handle, prio) == 0) { + DDS_WARNING("SetThreadPriority failed with %i\n", GetLastError()); + } + + return DDS_RETCODE_OK; +} + +ddsrt_tid_t +ddsrt_gettid(void) +{ + return GetCurrentThreadId(); +} + +ddsrt_thread_t +ddsrt_thread_self( + void) +{ + ddsrt_thread_t thr; + thr.tid = GetCurrentThreadId(); + thr.handle = GetCurrentThread(); /* pseudo HANDLE, no need to close it */ + + return thr; +} + +bool ddsrt_thread_equal(ddsrt_thread_t a, ddsrt_thread_t b) +{ + return a.tid == b.tid; +} + +/* ES: dds2086: Close handle should not be performed here. Instead the handle + * should not be closed until the os_threadWaitExit(...) call is called. + * CloseHandle (threadHandle); + */ +dds_retcode_t +ddsrt_thread_join( + ddsrt_thread_t thread, + uint32_t *thread_result) +{ + DWORD tr; + DWORD waitres; + BOOL status; + + if (thread.handle == NULL) { + return DDS_RETCODE_BAD_PARAMETER; + } + + waitres = WaitForSingleObject(thread.handle, INFINITE); + if (waitres != WAIT_OBJECT_0) { + //err = GetLastError(); + //OS_DEBUG_1("os_threadWaitExit", "WaitForSingleObject Failed %d", err); + return DDS_RETCODE_ERROR; + } + + status = GetExitCodeThread(thread.handle, &tr); + if (!status) { + //err = GetLastError(); + //OS_DEBUG_1("os_threadWaitExit", "GetExitCodeThread Failed %d", err); + return DDS_RETCODE_ERROR; + } + + assert(tr != STILL_ACTIVE); + if (thread_result) { + *thread_result = tr; + } + CloseHandle(thread.handle); + + return DDS_RETCODE_OK; +} + +/* Thread names on Linux are limited to 16 bytes, no reason to provide + more storage than that as internal threads must adhere to that limit. */ +static ddsrt_thread_local char thread_name[16] = ""; + +size_t +ddsrt_thread_getname( + char *__restrict str, + size_t size) +{ + size_t cnt; + + assert(str != NULL); + + if ((cnt = ddsrt_strlcpy(str, thread_name, size)) == 0) { + ddsrt_tid_t tid = ddsrt_gettid(); + cnt = (size_t)snprintf(str, size, "%"PRIdTID, tid); + assert(cnt >= 0); + } + + return cnt; +} + +static const DWORD MS_VC_EXCEPTION=0x406D1388; + +#pragma pack(push,8) +typedef struct tagTHREADNAME_INFO +{ + DWORD dwType; /** Must be 0x1000. */ + LPCSTR szName; /** Pointer to name (in user addr space). */ + DWORD dwThreadID; /** Thread ID (-1=caller thread). */ + DWORD dwFlags; /** Reserved for future use, must be zero. */ +} THREADNAME_INFO; +#pragma pack(pop) + +/** \brief Wrap thread start routine + * + * \b os_startRoutineWrapper wraps a threads starting routine. + * before calling the user routine. It tries to set a thread name + * that will be visible if the process is running under the MS + * debugger. + */ +void +ddsrt_thread_setname( + const char *__restrict name) +{ + assert(name != NULL); + + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = name; + info.dwThreadID = -1; + info.dwFlags = 0; + + /* Empty try/except that catches everything on purpose to set the thread + name. See: http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx. */ +#pragma warning(push) +#pragma warning(disable: 6320 6322) + __try + { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + /* Suppress warnings. */ + } +#pragma warning(pop) + + ddsrt_strlcpy(thread_name, name, sizeof(thread_name)); +} + + +static ddsrt_thread_local thread_cleanup_t *thread_cleanup = NULL; + +dds_retcode_t ddsrt_thread_cleanup_push(void (*routine)(void *), void *arg) +{ + thread_cleanup_t *tail; + + assert(routine != NULL); + + if ((tail = ddsrt_malloc(sizeof(thread_cleanup_t))) != NULL) { + tail->prev = thread_cleanup; + thread_cleanup = tail; + assert(tail != NULL); + tail->routine = routine; + tail->arg = arg; + return DDS_RETCODE_OK; + } + return DDS_RETCODE_OUT_OF_RESOURCES; +} + +dds_retcode_t ddsrt_thread_cleanup_pop(int execute) +{ + thread_cleanup_t *tail; + + if ((tail = thread_cleanup) != NULL) { + thread_cleanup = tail->prev; + if (execute) { + tail->routine(tail->arg); + } + ddsrt_free(tail); + } + return DDS_RETCODE_OK; +} + +static void +thread_cleanup_fini(void) +{ + thread_cleanup_t *tail, *prev; + + tail = thread_cleanup; + while (tail != NULL) { + prev = tail->prev; + assert(tail->routine != NULL); + tail->routine(tail->arg); + ddsrt_free(tail); + tail = prev; + } + + thread_cleanup = NULL; +} + +void +ddsrt_thread_init(void) +{ + return; +} + +void +ddsrt_thread_fini(void) +{ + thread_cleanup_fini(); +} diff --git a/src/ddsrt/src/time.c b/src/ddsrt/src/time.c new file mode 100644 index 0000000..01e4033 --- /dev/null +++ b/src/ddsrt/src/time.c @@ -0,0 +1,74 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "dds/ddsrt/timeconv.h" +#include "dds/ddsrt/string.h" + +extern inline dds_time_t +ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime); + +#if !defined(_WIN32) +#include + +void dds_sleepfor(dds_duration_t n) +{ + struct timespec t, r; + + if (n >= 0) { + t.tv_sec = n / DDS_NSECS_IN_SEC; + t.tv_nsec = n % DDS_NSECS_IN_SEC; + while (nanosleep(&t, &r) == -1 && errno == EINTR) { + t = r; + } + } +} +#endif + +void dds_sleepuntil(dds_time_t abstime) +{ + dds_time_t now = dds_time(); + + if (abstime > now) + dds_sleepfor (abstime - now); +} + +size_t +ddsrt_ctime(dds_time_t n, char *str, size_t size) +{ + struct tm tm; + static const char fmt[] = "%Y-%m-%d %H:%M:%S%z"; + char buf[] = "YYYY-mm-dd HH:MM:SS.hh:mm"; /* RFC 3339 */ + size_t cnt; + time_t sec = (time_t)(n / DDS_NSECS_IN_SEC); + + assert(str != NULL); + +#if _WIN32 + (void)localtime_s(&tm, &sec); +#else + (void)localtime_r(&sec, &tm); +#endif /* _WIN32 */ + + cnt = strftime(buf, sizeof(buf), fmt, &tm); + assert(cnt == (sizeof(buf) - 2 /* ':' + '\0' */)); + buf[sizeof(buf) - 1] = '\0'; + buf[sizeof(buf) - 2] = buf[sizeof(buf) - 3]; + buf[sizeof(buf) - 3] = buf[sizeof(buf) - 4]; + buf[sizeof(buf) - 4] = ':'; + + (void)cnt; + + return ddsrt_strlcpy(str, buf, size); +} + diff --git a/src/ddsrt/src/time/darwin/time.c b/src/ddsrt/src/time/darwin/time.c new file mode 100644 index 0000000..a8a35c4 --- /dev/null +++ b/src/ddsrt/src/time/darwin/time.c @@ -0,0 +1,58 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include +#include + +#include "dds/ddsrt/time.h" + +dds_time_t dds_time(void) +{ + struct timeval tv; + + (void)gettimeofday(&tv, NULL); + + return ((tv.tv_sec * DDS_NSECS_IN_SEC) + (tv.tv_usec * DDS_NSECS_IN_USEC)); +} + +dds_time_t ddsrt_time_monotonic(void) +{ + static mach_timebase_info_data_t timeInfo; + uint64_t mt; + + /* The Mach absolute time returned by mach_absolute_time is very similar to + * the QueryPerformanceCounter on Windows. The update-rate isn't fixed, so + * that information needs to be resolved to provide a clock with real-time + * progression. + * + * The mach_absolute_time does include time spent during sleep (on Intel + * CPU's, not on PPC), but not the time spent during suspend. + * + * The result is not adjusted based on NTP, so long-term progression by + * this clock may not match the time progression made by the real-time + * clock. */ + mt = mach_absolute_time(); + + if (timeInfo.denom == 0) { + (void)mach_timebase_info(&timeInfo); + } + + return (dds_time_t)(mt * timeInfo.numer / timeInfo.denom); +} + +dds_time_t ddsrt_time_elapsed(void) +{ + /* Elapsed time clock not (yet) supported on this platform. */ + return ddsrt_time_monotonic(); +} diff --git a/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h b/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h new file mode 100644 index 0000000..7ee22d3 --- /dev/null +++ b/src/ddsrt/src/time/include/dds/ddsrt/timeconv.h @@ -0,0 +1,68 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/time.h" + +/** + * @brief Calculate a time given an offset time and a duration. + * + * Negative time can become positive by adding a large enough duration, of + * course a positive time can become negative given a large enough negative + * duration. + * + * @param[in] abstime Timestamp in nanoseconds since UNIX Epoch. + * @param[in] reltime Relative time in nanoseconds. + * + * @returns A timestamp in nanoseconds since UNIX Epoch. + */ +inline dds_time_t +ddsrt_time_add_duration(dds_time_t abstime, dds_duration_t reltime) +{ + assert(abstime >= 0); + assert(reltime >= 0); + + return (reltime >= DDS_NEVER - abstime ? DDS_NEVER : abstime + reltime); +} + +#if _WIN32 +/** + * @brief Convert a relative time to microseconds rounding up. + * + * @param[in] reltime Relative time to convert. + * + * @returns INFINITE if @reltime was @DDS_INIFINITY, relative time converted to + * microseconds otherwise. + */ +inline DWORD +ddsrt_duration_to_msecs_ceil(dds_duration_t reltime) +{ + if (reltime == DDS_INFINITY) { + return INFINITE; + } else if (reltime > 0) { + assert(INFINITE < (DDS_INFINITY / DDS_NSECS_IN_MSEC)); + dds_duration_t max_nsecs = (INFINITE - 1) * DDS_NSECS_IN_MSEC; + + if (reltime < (max_nsecs - (DDS_NSECS_IN_MSEC - 1))) { + reltime += (DDS_NSECS_IN_MSEC - 1); + } else { + reltime = max_nsecs; + } + + return (DWORD)(reltime / DDS_NSECS_IN_MSEC); + } + + return 0; +} +#endif diff --git a/src/ddsrt/src/time/posix/time.c b/src/ddsrt/src/time/posix/time.c new file mode 100644 index 0000000..cfc98f5 --- /dev/null +++ b/src/ddsrt/src/time/posix/time.c @@ -0,0 +1,41 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include +#include +#include + +#include "dds/ddsrt/time.h" + +dds_time_t dds_time(void) +{ + struct timespec ts; + + (void)clock_gettime(CLOCK_REALTIME, &ts); + return (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec; +} + +dds_time_t ddsrt_time_monotonic(void) +{ + struct timespec ts; + + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + return (ts.tv_sec * DDS_NSECS_IN_SEC) + ts.tv_nsec; +} + +dds_time_t ddsrt_time_elapsed(void) +{ + /* Elapsed time clock not worth the bother for now. */ + return ddsrt_time_monotonic(); +} diff --git a/src/ddsrt/src/time/windows/time.c b/src/ddsrt/src/time/windows/time.c new file mode 100644 index 0000000..e4c9c87 --- /dev/null +++ b/src/ddsrt/src/time/windows/time.c @@ -0,0 +1,161 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include + +#include "dds/ddsrt/timeconv.h" + +extern inline DWORD +ddsrt_duration_to_msecs_ceil(dds_duration_t reltime); + +/* GetSystemTimePreciseAsFileTime was introduced with Windows 8, so + starting from _WIN32_WINNET = 0x0602. When building for an older + version we can still check dynamically. */ +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 +#define UseGetSystemTimePreciseAsFileTime +#else +static VOID (WINAPI *GetSystemTimeAsFileTimeFunc)(LPFILTETIME) = GetSystemTimeAsFileTime; +static HANDLE Kernel32ModuleHandle; +#endif + +/* GetSystemTimeAsFileTime returns the number of 100ns intervals that have elapsed + * since January 1, 1601 (UTC). There are 11,644,473,600 seconds between 1601 and + * the Unix epoch (January 1, 1970 (UTC)), which is the reference that is used for + * dds_time. + */ +#define FILETIME_EPOCH_OFFSET_SECS (11644473600) +#define SECS_IN_100_NSECS (1000 * 1000 * 10) + +dds_time_t dds_time(void) +{ + FILETIME ft; + ULARGE_INTEGER ns100; + + /* GetSystemTime(Precise)AsFileTime returns the number of 100-nanosecond + * intervals since January 1, 1601 (UTC). + * GetSystemTimeAsFileTime has a resolution of approximately the + * TimerResolution (~15.6ms) on Windows XP. On Windows 7 it appears to have + * sub-millisecond resolution. GetSystemTimePreciseAsFileTime (available on + * Windows 8) has sub-microsecond resolution. + * + * This call appears to be significantly (factor 8) cheaper than the + * QueryPerformanceCounter (on the systems performance was measured on). + * + * TODO: When the API is extended to support retrieval of clock-properties, + * then the actual resolution of this clock can be retrieved using the + * GetSystemTimeAdjustment. + */ +#ifdef UseGetSystemTimePreciseAsFileTime + GetSystemTimePreciseAsFileTime(&ft); +#else + GetSystemTimeAsFileTimeFunc(&ft); +#endif + ns100.LowPart = ft.dwLowDateTime; + ns100.HighPart = ft.dwHighDateTime; + ns100.QuadPart -= (FILETIME_EPOCH_OFFSET_SECS * SECS_IN_100_NSECS); + + return (dds_time_t)(ns100.QuadPart * 100); +} + +void ddsrt_time_init(void) +{ +#ifndef UseGetSystemTimePreciseAsFileTime + /* Resolve the time-functions from the Kernel32-library. */ + VOID (WINAPI *f) (LPFILTETIME); + + /* This os_timeModuleInit is currently called from DllMain. This means + * we're not allowed to do LoadLibrary. One exception is "Kernel32.DLL", + * since that library is per definition loaded (LoadLibrary itself + * lives there). And since we're only resolving stuff, not actually + * invoking, this is considered safe. + */ + Kernel32ModuleHandle = LoadLibrary("Kernel32.DLL"); + assert(Kernel32ModuleHandle); + + f = GetProcAddress(Kernel32ModuleHandle, "GetSystemTimePreciseAsFileTime"); + if (f != 0) { + GetSystemTimeAsFileTimeFunc = f; + } +#endif +} + +void ddsrt_time_fini(void) +{ +#ifndef UseGetSystemTimePreciseAsFileTime + if (Kernel32ModuleHandle) { + GetSystemTimeAsFileTimeFunc = GetSystemTimeAsFileTime; + FreeLibrary(Kernel32ModuleHandle); + Kernel32ModuleHandle = NULL; + } +#endif +} + +dds_time_t ddsrt_time_monotonic(void) +{ + ULONGLONG ubit; + + (void)QueryUnbiasedInterruptTime(&ubit); /* 100ns ticks */ + + return (dds_time_t)(ubit * 100); +} + +dds_time_t ddsrt_time_elapsed(void) +{ + LARGE_INTEGER qpc; + static LONGLONG qpc_freq; /* Counts per nanosecond. */ + + /* The QueryPerformanceCounter has a bad reputation, since it didn't behave + * very well on older hardware. On recent OS's (Windows XP SP2 and later) + * things have become much better, especially when combined with new hard- + * ware. + * + * There is currently one bug which is not fixed, which may cause forward + * jumps. This is currently not really important, since a forward jump may + * be observed anyway due to the system going to standby. There is a work- + * around available (comparing the progress with the progress made by + * GetTickCount), but for now we live with a risk of a forward jump on buggy + * hardware. Since Microsoft does maintain a list of hardware which exhibits + * the behaviour, it is possible to only have the workaround in place only + * on the faulty hardware (see KB274323 for a list and more info). + * + * TODO: When the API is extended to support retrieval of clock-properties, + * then the discontinuous nature (when sleeping/hibernating) of this + * clock and the drift tendency should be reported. */ + + if (qpc_freq == 0){ + /* This block is idempotent, so don't bother with synchronisation. */ + LARGE_INTEGER frequency; + + if (QueryPerformanceFrequency(&frequency)) { + /* Performance-counter frequency is in counts per second. */ + qpc_freq = DDS_NSECS_IN_SEC / frequency.QuadPart; + } + /* Since Windows XP SP2 the QueryPerformanceCounter is abstracted, + * so QueryPerformanceFrequency is not expected to ever return 0. + * That't why there is no fall-back for the case when no + * QueryPerformanceCounter is available. */ + } + assert(qpc_freq); + + /* The QueryPerformanceCounter tends to drift quite a bit, so in order to + * accurately measure longer periods with it, there may be a need to sync + * the time progression to actual time progression. */ + QueryPerformanceCounter(&qpc); + + return (dds_time_t)(qpc.QuadPart * qpc_freq); +} + +void dds_sleepfor(dds_duration_t reltime) +{ + Sleep(ddsrt_duration_to_msecs_ceil(reltime)); +} diff --git a/src/ddsrt/tests/CMakeLists.txt b/src/ddsrt/tests/CMakeLists.txt new file mode 100644 index 0000000..2b3483d --- /dev/null +++ b/src/ddsrt/tests/CMakeLists.txt @@ -0,0 +1,43 @@ +# +# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License +# v. 1.0 which is available at +# http://www.eclipse.org/org/documents/edl-v10.php. +# +# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause +# +include(CUnit) + +set(sources + "atomics.c" + "environ.c" + "heap.c" + "ifaddrs.c" + "sync.c" + "strtoll.c" + "thread.c" + "thread_cleanup.c" + "string.c" + "log.c" + "strlcpy.c" + "socket.c" + "select.c") + +add_cunit_executable(cunit_ddsrt ${sources}) +target_link_libraries(cunit_ddsrt PRIVATE ddsrt) + +# Create a dummy export header. generate_export_header can only be used with +# library targets, but since the targets are linked statically, +# __declspec(dllimport) is not required anyway. +set(export_dir "${CMAKE_CURRENT_BINARY_DIR}/include/dds") +set(export_header "${export_dir}/export.h") +if(NOT EXISTS "${export_header}") + file(MAKE_DIRECTORY "${export_dir}") + file(WRITE "${export_header}" "#define DDS_EXPORT\n") +endif() + +target_include_directories( + cunit_ddsrt PRIVATE "$") diff --git a/src/ddsrt/tests/atomics.c b/src/ddsrt/tests/atomics.c new file mode 100644 index 0000000..a791844 --- /dev/null +++ b/src/ddsrt/tests/atomics.c @@ -0,0 +1,393 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "CUnit/Test.h" +#include "dds/ddsrt/atomics.h" + +uint32_t _osuint32 = 0; +uint64_t _osuint64 = 0; +uintptr_t _osaddress = 0; +ptrdiff_t _ptrdiff = 0; +void * _osvoidp = (uintptr_t *)0; + +CU_Test(ddsrt_atomics, load_store) +{ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(5); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(5); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(5); + volatile ddsrt_atomic_voidp_t voidp = DDSRT_ATOMIC_VOIDP_INIT((uintptr_t)5); + + /* Test uint32 LD-ST */ + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 5); /* Returns contents of uint32 */ + ddsrt_atomic_st32 (&uint32, _osuint32); /* Writes os_uint32 into uint32 */ + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == _osuint32); + + /* Test uint64 LD-ST */ +#if DDSRT_HAVE_ATOMIC64 + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 5); + ddsrt_atomic_st64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == _osuint64); +#endif + + /* Test uintptr LD-ST */ + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 5); + ddsrt_atomic_stptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == _osaddress); + + /* Test uintvoidp LD-ST */ + CU_ASSERT (ddsrt_atomic_ldvoidp (&voidp) == (uintptr_t*)5); + ddsrt_atomic_stvoidp (&voidp, _osvoidp); + CU_ASSERT (ddsrt_atomic_ldvoidp (&voidp) == (uintptr_t*)_osvoidp); +} + +CU_Test(ddsrt_atomics, compare_and_swap) +{ + /* Compare and Swap if (ptr == expected) { ptr = newval; } */ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(0); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(0); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(0); + volatile ddsrt_atomic_voidp_t uintvoidp = DDSRT_ATOMIC_VOIDP_INIT((uintptr_t)0); + _osuint32 = 1; + _osuint64 = 1; + _osaddress = 1; + _osvoidp = (uintptr_t *)1; + uint32_t expected = 0, newval = 5; + uintptr_t addr_expected = 0, addr_newval = 5; + void *void_expected = (uintptr_t*)0; + void *void_newval = (uintptr_t*)5; + int ret = 0; + + /* Test ddsrt_atomic_cas32 */ + ret = ddsrt_atomic_cas32 (&uint32, expected, newval); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == newval && ret == 1); + ddsrt_atomic_st32 (&uint32, _osuint32); + ret = ddsrt_atomic_cas32 (&uint32, expected, newval); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) != newval && ret == 0); + + /* Test ddsrt_atomic_cas64 */ +#if DDSRT_HAVE_ATOMIC64 + ret = ddsrt_atomic_cas64 (&uint64, expected, newval); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == newval && ret == 1); + ddsrt_atomic_st64 (&uint64, _osuint64); + ret = ddsrt_atomic_cas64 (&uint64, expected, newval); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) != newval && ret == 0); +#endif + + /* Test ddsrt_atomic_casptr */ + ret = ddsrt_atomic_casptr (&uintptr, addr_expected, addr_newval); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == addr_newval && ret == 1); + ddsrt_atomic_stptr (&uintptr, _osaddress); + ret = ddsrt_atomic_casptr (&uintptr, addr_expected, addr_newval); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) != addr_newval && ret == 0); + + /* Test ddsrt_atomic_casvoidp */ + ret = ddsrt_atomic_casvoidp (&uintvoidp, void_expected, void_newval); + CU_ASSERT (ddsrt_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)void_newval && ret == 1); + ddsrt_atomic_stvoidp (&uintvoidp, _osvoidp); + ret = ddsrt_atomic_casvoidp (&uintvoidp, void_expected, void_newval); + CU_ASSERT (ddsrt_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)1 && ret == 0); +} + +CU_Test(ddsrt_atomics, increment) +{ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(0); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(0); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(0); + _osuint32 = 0; + _osuint64 = 0; + _osaddress = 0; + _osvoidp = (uintptr_t *)0; + + /* Test os_inc32 */ + ddsrt_atomic_inc32 (&uint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 1); + + /* Test os_inc64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_inc64 (&uint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 1); +#endif + + /* Test os_incptr */ + ddsrt_atomic_incptr (&uintptr); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 1); + + /* Test ddsrt_atomic_inc32_nv */ + ddsrt_atomic_st32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_inc32_nv (&uint32) == 1); + + /* Test ddsrt_atomic_inc64_nv */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_st64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_inc64_nv (&uint64) == 1); +#endif + + /* Test ddsrt_atomic_incptr_nv */ + ddsrt_atomic_stptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_incptr_nv(&uintptr) == 1); +} + +CU_Test(ddsrt_atomics, decrement) +{ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(1); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(1); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(1); + _osuint32 = 1; + _osuint64 = 1; + _osaddress = 1; + _osvoidp = (uintptr_t *)1; + + /* Test ddsrt_atomic_dec32 */ + ddsrt_atomic_dec32 (&uint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 0); + + /* Test ddsrt_atomic_dec64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_dec64 (&uint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 0); +#endif + + /* Test ddsrt_atomic_decptr */ + ddsrt_atomic_decptr (&uintptr); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 0); + + /* Test ddsrt_atomic_dec32_nv */ + ddsrt_atomic_st32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_dec32_nv (&uint32) == 0); + + /* Test ddsrt_atomic_dec64_nv */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_st64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_dec64_nv (&uint64) == 0); +#endif + + /* Test ddsrt_atomic_decptr_nv */ + ddsrt_atomic_stptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_decptr_nv(&uintptr) == 0); +} + +CU_Test(ddsrt_atomics, add) +{ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(1); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(1); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(1); + volatile ddsrt_atomic_voidp_t uintvoidp = DDSRT_ATOMIC_VOIDP_INIT((uintptr_t)1); + _osuint32 = 2; + _osuint64 = 2; + _osaddress = 2; + _ptrdiff = 2; + + /* Test ddsrt_atomic_add32 */ + ddsrt_atomic_add32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 3); + + /* Test ddsrt_atomic_add64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_add64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 3); +#endif + + /* Test ddsrt_atomic_addptr */ + ddsrt_atomic_addptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 3); + + /* Test ddsrt_atomic_addvoidp */ + ddsrt_atomic_addvoidp (&uintvoidp, _ptrdiff); + CU_ASSERT (ddsrt_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)3); + + /* Test ddsrt_atomic_add32_nv */ + ddsrt_atomic_st32 (&uint32, 1); + CU_ASSERT (ddsrt_atomic_add32_nv (&uint32, _osuint32) == 3); + + /* Test ddsrt_atomic_add64_nv */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_st64 (&uint64, 1); + CU_ASSERT (ddsrt_atomic_add64_nv (&uint64, _osuint64) == 3); +#endif + + /* Test ddsrt_atomic_addptr_nv */ + ddsrt_atomic_stptr (&uintptr, 1); + CU_ASSERT (ddsrt_atomic_addptr_nv (&uintptr, _osaddress) == 3); + + /* Test ddsrt_atomic_addvoidp_nv */ + ddsrt_atomic_stvoidp (&uintvoidp, (uintptr_t*)1); + CU_ASSERT (ddsrt_atomic_addvoidp_nv (&uintvoidp, _ptrdiff) == (uintptr_t*)3); +} + +CU_Test(ddsrt_atomics, subtract) +{ + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(5); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(5); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(5); + volatile ddsrt_atomic_voidp_t uintvoidp = DDSRT_ATOMIC_VOIDP_INIT((uintptr_t)5); + _osuint32 = 2; + _osuint64 = 2; + _osaddress = 2; + _ptrdiff = 2; + + /* Test ddsrt_atomic_sub32 */ + ddsrt_atomic_sub32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 3); + + /* Test ddsrt_atomic_sub64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_sub64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 3); +#endif + + /* Test ddsrt_atomic_subptr */ + ddsrt_atomic_subptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 3); + + /* Test ddsrt_atomic_subvoidp */ + ddsrt_atomic_subvoidp (&uintvoidp, _ptrdiff); + CU_ASSERT (ddsrt_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)3); + + /* Test ddsrt_atomic_sub32_nv */ + ddsrt_atomic_st32 (&uint32, 5); + CU_ASSERT (ddsrt_atomic_sub32_nv (&uint32, _osuint32) == 3); + + /* Test ddsrt_atomic_sub64_nv */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_st64 (&uint64, 5); + CU_ASSERT (ddsrt_atomic_sub64_nv (&uint64, _osuint64) == 3); +#endif + + /* Test ddsrt_atomic_subptr_nv */ + ddsrt_atomic_stptr (&uintptr, 5); + CU_ASSERT (ddsrt_atomic_subptr_nv (&uintptr, _osaddress) == 3); + + /* Test ddsrt_atomic_subvoidp_nv */ + ddsrt_atomic_stvoidp (&uintvoidp, (uintptr_t*)5); + CU_ASSERT (ddsrt_atomic_subvoidp_nv (&uintvoidp, _ptrdiff) == (void *)3); +} + +CU_Test(ddsrt_atomics, and) +{ + /* AND Operation: + + 150 010010110 + 500 111110100 + + 148 010010100 */ + + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(150); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(150); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(150); + _osuint32 = 500; + _osuint64 = 500; + _osaddress = 500; + + /* Test ddsrt_atomic_and32 */ + ddsrt_atomic_and32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 148); + + /* Test ddsrt_atomic_and64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_and64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 148); +#endif + + /* Test ddsrt_atomic_andptr */ + ddsrt_atomic_andptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 148); + + /* Test ddsrt_atomic_and32_ov */ + CU_ASSERT (ddsrt_atomic_and32_ov (&uint32, _osuint32) == 148); + + /* Test ddsrt_atomic_and64_ov */ +#if DDSRT_HAVE_ATOMIC64 + CU_ASSERT (ddsrt_atomic_and64_ov (&uint64, _osuint64) == 148); +#endif + + /* Test ddsrt_atomic_andptr_ov */ + CU_ASSERT (ddsrt_atomic_andptr_ov (&uintptr, _osaddress) == 148); + + /* Test ddsrt_atomic_and32_nv */ + CU_ASSERT (ddsrt_atomic_and32_nv (&uint32, _osuint32) == 148); + + /* Test ddsrt_atomic_and64_nv */ +#if DDSRT_HAVE_ATOMIC64 + CU_ASSERT (ddsrt_atomic_and64_nv (&uint64, _osuint64) == 148); + #endif + + /* Test ddsrt_atomic_andptr_nv */ + CU_ASSERT (ddsrt_atomic_andptr_nv (&uintptr, _osaddress) == 148); +} + +CU_Test(ddsrt_atomics, or) +{ + /* OR Operation: + + 150 010010110 + 500 111110100 + + 502 111110110 */ + + volatile ddsrt_atomic_uint32_t uint32 = DDSRT_ATOMIC_UINT32_INIT(150); +#if DDSRT_HAVE_ATOMIC64 + volatile ddsrt_atomic_uint64_t uint64 = DDSRT_ATOMIC_UINT64_INIT(150); +#endif + volatile ddsrt_atomic_uintptr_t uintptr = DDSRT_ATOMIC_UINTPTR_INIT(150); + _osuint32 = 500; + _osuint64 = 500; + _osaddress = 500; + + /* Test ddsrt_atomic_or32 */ + ddsrt_atomic_or32 (&uint32, _osuint32); + CU_ASSERT (ddsrt_atomic_ld32 (&uint32) == 502); + + /* Test ddsrt_atomic_or64 */ +#if DDSRT_HAVE_ATOMIC64 + ddsrt_atomic_or64 (&uint64, _osuint64); + CU_ASSERT (ddsrt_atomic_ld64 (&uint64) == 502); +#endif + + /* Test ddsrt_atomic_orptr */ + ddsrt_atomic_orptr (&uintptr, _osaddress); + CU_ASSERT (ddsrt_atomic_ldptr (&uintptr) == 502); + + /* Test ddsrt_atomic_or32_ov */ + CU_ASSERT (ddsrt_atomic_or32_ov (&uint32, _osuint32) == 502); + + /* Test ddsrt_atomic_or64_ov */ +#if DDSRT_HAVE_ATOMIC64 + CU_ASSERT (ddsrt_atomic_or64_ov (&uint64, _osuint64) == 502); +#endif + + /* Test ddsrt_atomic_orptr_ov */ + CU_ASSERT (ddsrt_atomic_orptr_ov (&uintptr, _osaddress) == 502); + + /* Test ddsrt_atomic_or32_nv */ + CU_ASSERT (ddsrt_atomic_or32_nv (&uint32, _osuint32) == 502); + + /* Test ddsrt_atomic_or64_nv */ +#if DDSRT_HAVE_ATOMIC64 + CU_ASSERT (ddsrt_atomic_or64_nv (&uint64, _osuint64) == 502); +#endif + + /* Test ddsrt_atomic_orptr_nv */ + CU_ASSERT (ddsrt_atomic_orptr_nv (&uintptr, _osaddress) == 502); +} diff --git a/src/ddsrt/tests/environ.c b/src/ddsrt/tests/environ.c new file mode 100644 index 0000000..56f7468 --- /dev/null +++ b/src/ddsrt/tests/environ.c @@ -0,0 +1,98 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "CUnit/Theory.h" +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/misc.h" + +CU_TheoryDataPoints(ddsrt_environ, bad_name) = { + CU_DataPoints(const char *, "", "foo=") +}; + +CU_Theory((const char *name), ddsrt_environ, bad_name) +{ + dds_retcode_t rc; + static const char value[] = "bar"; + static char dummy[] = "foobar"; + char *ptr; + + rc = ddsrt_setenv(name, value); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER); + rc = ddsrt_unsetenv(name); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER); + ptr = dummy; + rc = ddsrt_getenv(name, &ptr); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER); + CU_ASSERT_PTR_EQUAL(ptr, dummy); +} + +DDSRT_WARNING_MSVC_OFF(4996) +CU_Test(ddsrt_environ, setenv) +{ + dds_retcode_t rc; + static const char name[] = "foo"; + static char value[] = "bar"; + char *ptr; + + rc = ddsrt_setenv(name, value); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + ptr = getenv(name); + CU_ASSERT_PTR_NOT_NULL(ptr); + CU_ASSERT_STRING_EQUAL(ptr, "bar"); + /* Ensure value is copied into the environment. */ + value[2] = 'z'; + ptr = getenv(name); + CU_ASSERT_PTR_NOT_NULL(ptr); + CU_ASSERT_STRING_EQUAL(ptr, "bar"); + rc = ddsrt_setenv(name, ""); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + ptr = getenv(name); + CU_ASSERT_PTR_NULL(ptr); +} +DDSRT_WARNING_MSVC_ON(4996) + +CU_Test(ddsrt_environ, getenv) +{ + dds_retcode_t rc; + static const char name[] = "foo"; + static const char value[] = "bar"; + static char dummy[] = "foobar"; + char *ptr; + + /* Ensure "not found" is returned. */ + rc = ddsrt_unsetenv(name); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + + ptr = dummy; + rc = ddsrt_getenv(name, &ptr); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_NOT_FOUND); + CU_ASSERT_PTR_EQUAL(ptr, dummy); + + /* Ensure "ok" is returned and value is what it should be. */ + rc = ddsrt_setenv(name, value); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + + ptr = dummy; + rc = ddsrt_getenv(name, &ptr); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_PTR_NOT_EQUAL(ptr, dummy); + CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); + if (ptr != NULL) { + CU_ASSERT_STRING_EQUAL(ptr, "bar"); + } + + /* Ensure environement is as it was. */ + rc = ddsrt_unsetenv(name); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); +} + diff --git a/src/ddsrt/tests/heap.c b/src/ddsrt/tests/heap.c new file mode 100644 index 0000000..e0bd4d7 --- /dev/null +++ b/src/ddsrt/tests/heap.c @@ -0,0 +1,156 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include "CUnit/Test.h" + +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/heap.h" + +CU_Init(ddsrt_heap) +{ + ddsrt_init(); + return 0; +} + +CU_Clean(ddsrt_heap) +{ + ddsrt_fini(); + return 0; +} + +static const size_t allocsizes[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024}; +static const size_t nof_allocsizes = sizeof allocsizes / sizeof *allocsizes; + +CU_Test(ddsrt_heap, malloc) +{ + for(size_t i = 0; i < nof_allocsizes; i++) { + for(size_t j = 0; j < nof_allocsizes; j++) { + size_t s = allocsizes[i] * allocsizes[j]; /* Allocates up to 1MB */ + void *ptr = ddsrt_malloc(s); + CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* ddsrt_malloc is supposed to abort on failure */ + memset(ptr, 0, s); /* This potentially segfaults if the actual allocated block is too small */ + ddsrt_free(ptr); + } + } + CU_PASS("ddsrt_malloc"); +} + +CU_Test(ddsrt_heap, calloc) +{ + for(size_t i = 0; i < nof_allocsizes; i++) { + for(size_t j = 0; j < nof_allocsizes; j++) { + char *ptr = ddsrt_calloc(allocsizes[i], allocsizes[j]); + CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* ddsrt_calloc is supposed to abort on failure */ + if(allocsizes[i] * allocsizes[j] > 0) { + CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, (allocsizes[i] * allocsizes[j]) - 1)); /* ddsrt_calloc should memset properly */ + } + ddsrt_free(ptr); + } + } + CU_PASS("ddsrt_calloc"); +} + +CU_Test(ddsrt_heap, realloc) +{ + char *ptr = NULL; + size_t unchanged, s, prevs = 0; + + for(size_t i = 0; i < nof_allocsizes; i++) { + for(size_t j = 0; j < nof_allocsizes; j++) { + s = allocsizes[i] * allocsizes[j]; /* Allocates up to 1MB */ + printf("ddsrt_realloc(%p) %zu -> %zu\n", ptr, prevs, s); + ptr = ddsrt_realloc(ptr, s); + CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* ddsrt_realloc is supposed to abort on failure */ + unchanged = (prevs < s) ? prevs : s; + if(unchanged) { + CU_ASSERT (ptr[0] == 1 && !memcmp(ptr, ptr + 1, unchanged - 1)); /* ddsrt_realloc shouldn't change memory */ + } + memset(ptr, 1, s); /* This potentially segfaults if the actual allocated block is too small */ + prevs = s; + } + } + ddsrt_free(ptr); + CU_PASS("ddsrt_realloc"); +} + +static const size_t allocsizes_s[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024, 8192}; +static const size_t nof_allocsizes_s = sizeof allocsizes_s / sizeof *allocsizes_s; + +CU_Test(ddsrt_heap, malloc_s) +{ + for(size_t i = 0; i < nof_allocsizes_s; i++) { + for(size_t j = 0; j < nof_allocsizes_s; j++) { + size_t s = allocsizes_s[i] * allocsizes_s[j]; /* Allocates up to 8MB */ + void *ptr = ddsrt_malloc_s(s); /* If s == 0, ddsrt_malloc_s should still return a pointer */ + if(ptr) { + memset(ptr, 0, s); /* This potentially segfaults if the actual allocated block is too small */ + } else if (s <= 16) { + /* Failure to allocate can't be considered a test fault really, + * except that a malloc(<=16) would fail is unlikely. */ + CU_FAIL("ddsrt_malloc_s(<=16) returned NULL"); + } + ddsrt_free(ptr); + } + } + CU_PASS("ddsrt_malloc_s"); +} + +CU_Test(ddsrt_heap, calloc_s) +{ + for(size_t i = 0; i < nof_allocsizes_s; i++) { + for(size_t j = 0; j < nof_allocsizes_s; j++) { + size_t s = allocsizes_s[i] * allocsizes_s[j]; + char *ptr = ddsrt_calloc_s(allocsizes_s[i], allocsizes_s[j]); /* If either one is 0, ddsrt_calloc_s should still return a pointer */ + if(ptr) { + if(s) { + CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, s - 1)); /* malloc_0_s should memset properly */ + } + } else if (s <= 16) { + /* Failure to allocate can't be considered a test fault really, + * except that a calloc(<=16) would fail is unlikely. */ + CU_FAIL("ddsrt_calloc_s(<=16) returned NULL"); + } + ddsrt_free(ptr); + } + } + CU_PASS("ddsrt_calloc_s"); +} + +CU_Test(ddsrt_heap, ddsrt_realloc_s) +{ + char *newptr, *ptr = NULL; + size_t unchanged, s, prevs = 0; + + for(size_t i = 0; i < nof_allocsizes_s; i++) { + for(size_t j = 0; j < nof_allocsizes_s; j++) { + s = allocsizes_s[i] * allocsizes_s[j]; /* Allocates up to 8MB */ + newptr = ddsrt_realloc_s(ptr, s); + printf("%p = ddsrt_realloc_s(%p) %zu -> %zu\n", newptr, ptr, prevs, s); + if (s <= 16) { + /* Failure to allocate can't be considered a test fault really, + * except that a ddsrt_realloc_s(0 < s <=16) would fail is unlikely. */ + CU_ASSERT_PTR_NOT_EQUAL(newptr, NULL); + } + if(newptr){ + unchanged = (prevs < s) ? prevs : s; + if(unchanged) { + CU_ASSERT (newptr[0] == 1 && !memcmp(newptr, newptr + 1, unchanged - 1)); /* ddsrt_realloc_s shouldn't change memory */ + } + memset(newptr, 1, s); /* This potentially segfaults if the actual allocated block is too small */ + } + prevs = s; + ptr = newptr; + } + } + ddsrt_free(ptr); + CU_PASS("ddsrt_realloc_s"); +} diff --git a/src/ddsrt/tests/ifaddrs.c b/src/ddsrt/tests/ifaddrs.c new file mode 100644 index 0000000..ae8ea0b --- /dev/null +++ b/src/ddsrt/tests/ifaddrs.c @@ -0,0 +1,187 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "CUnit/Test.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/ifaddrs.h" +#include "dds/ddsrt/retcode.h" + +/* FIXME: It's not possible to predict what network interfaces are available + on a given host. To properly test all combinations the abstracted + operating system functions must be mocked. */ + +/* FIXME: It's possible that IPv6 is available in the network stack, but + disabled in the kernel. Travis CI for example has build environments + that do not have IPv6 enabled. */ + +#ifdef DDSRT_HAVE_IPV6 +static int ipv6_enabled = 1; +#endif + +CU_Init(ddsrt_getifaddrs) +{ + ddsrt_init(); + +#ifdef DDSRT_HAVE_IPV6 +#ifdef __linux + FILE *fh; + const char *const *path; + static const char *const paths[] = { + "/proc/sys/net/ipv6/conf/all/disable_ipv6", + "/proc/sys/net/ipv6/conf/default/disable_ipv6", + NULL + }; + + for (path = paths; ipv6_enabled == 1 && *path != NULL; path++) { + if ((fh = fopen(*path, "r")) != NULL) { + ipv6_enabled = (fgetc(fh) == '0'); + fclose(fh); + fh = NULL; + } + } +#endif /* __linux */ +#endif /* DDSRT_HAVE_IPV6 */ + + return 0; +} + +CU_Clean(ddsrt_getifaddrs) +{ + ddsrt_fini(); + return 0; +} + +/* Assume every test machine has at least one IPv4 enabled interface. This + simple test verifies an interface can at least be found and that the + IFF_LOOPBACK flags are properly set. */ +CU_Test(ddsrt_getifaddrs, ipv4) +{ + dds_retcode_t ret; + int seen = 0; + ddsrt_ifaddrs_t *ifa_root, *ifa; + const int afs[] = { AF_INET, DDSRT_AF_TERM }; + + ret = ddsrt_getifaddrs(&ifa_root, afs); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + for (ifa = ifa_root; ifa; ifa = ifa->next) { + CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET); + if (ifa->addr->sa_family == AF_INET) { + if (ifa->flags & IFF_LOOPBACK) { + CU_ASSERT(ddsrt_sockaddr_isloopback(ifa->addr)); + } else { + CU_ASSERT(!ddsrt_sockaddr_isloopback(ifa->addr)); + } + seen = 1; + } + } + + CU_ASSERT_EQUAL(seen, 1); + ddsrt_freeifaddrs(ifa_root); +} + +CU_Test(ddsrt_getifaddrs, null_filter) +{ + dds_retcode_t ret; + int cnt = 0; + ddsrt_ifaddrs_t *ifa_root, *ifa; + + ret = ddsrt_getifaddrs(&ifa_root, NULL); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + for (ifa = ifa_root; ifa; ifa = ifa->next) { + CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + cnt++; + } + + CU_ASSERT(cnt > 0); + ddsrt_freeifaddrs(ifa_root); +} + +CU_Test(ddsrt_getifaddrs, empty_filter) +{ + dds_retcode_t ret; + ddsrt_ifaddrs_t *ifa_root; + const int afs[] = { DDSRT_AF_TERM }; + + ret = ddsrt_getifaddrs(&ifa_root, afs); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + CU_ASSERT_PTR_EQUAL(ifa_root, NULL); + ddsrt_freeifaddrs(ifa_root); +} + +#ifdef DDSRT_HAVE_IPV6 +CU_Test(ddsrt_getifaddrs, ipv6) +{ + if (ipv6_enabled == 1) { + dds_retcode_t ret; + int have_ipv6 = 0; + ddsrt_ifaddrs_t *ifa_root, *ifa; + const int afs[] = { AF_INET6, DDSRT_AF_TERM }; + + ret = ddsrt_getifaddrs(&ifa_root, afs); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + for (ifa = ifa_root; ifa; ifa = ifa->next) { + CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6); + if (ifa->addr->sa_family == AF_INET6) { + have_ipv6 = 1; + /* macOS assigns a link-local address to the loopback interface, so + the loopback address must be assigned to the loopback interface, + but the loopback interface can have addresses other than the + loopback address assigned. */ + if (ddsrt_sockaddr_isloopback(ifa->addr)) { + CU_ASSERT(ifa->flags & IFF_LOOPBACK); + } + } + } + + CU_ASSERT_EQUAL(have_ipv6, 1); + ddsrt_freeifaddrs(ifa_root); + CU_PASS("IPv6 enabled in test environment"); + } else { + CU_PASS("IPv6 disabled in test environment"); + } +} + +/* Assume at least one IPv4 and one IPv6 interface are available when IPv6 is + available on the platform. */ +CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6) +{ + if (ipv6_enabled == 1) { + dds_retcode_t ret; + int have_ipv4 = 0; + int have_ipv6 = 0; + ddsrt_ifaddrs_t *ifa_root, *ifa; + const int afs[] = { AF_INET, AF_INET6, DDSRT_AF_TERM }; + + ret = ddsrt_getifaddrs(&ifa_root, afs); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + for (ifa = ifa_root; ifa; ifa = ifa->next) { + CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + CU_ASSERT(ifa->addr->sa_family == AF_INET || + ifa->addr->sa_family == AF_INET6); + if (ifa->addr->sa_family == AF_INET) { + have_ipv4 = 1; + } else if (ifa->addr->sa_family == AF_INET6) { + have_ipv6 = 1; + } + } + + CU_ASSERT_EQUAL(have_ipv4, 1); + CU_ASSERT_EQUAL(have_ipv6, 1); + ddsrt_freeifaddrs(ifa_root); + CU_PASS("IPv6 enabled in test environment"); + } else { + CU_PASS("IPv6 disabled in test environment"); + } +} + +#endif /* DDSRT_HAVE_IPV6 */ diff --git a/src/ddsrt/tests/log.c b/src/ddsrt/tests/log.c new file mode 100644 index 0000000..ab5fcc6 --- /dev/null +++ b/src/ddsrt/tests/log.c @@ -0,0 +1,366 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#ifdef __APPLE__ +#include +#endif /* __APPLE__ */ + +#include "CUnit/Test.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsrt/time.h" + +static FILE *fh = NULL; + +#ifdef _WIN32 +#include +#include + +/* Windows does not support opening a stream to a buffer like fmemopen on + * Linux does. A temporary file that will never be flushed to disk is created + * instead. See the link below for more detail. + * + * https://blogs.msdn.microsoft.com/larryosterman/2004/04/19/its-only-temporary/ + */ + +FILE *fmemopen(void *buf, size_t size, const char *mode) +{ + int err = 0; + int fd = -1; + DWORD ret; + FILE *fh = NULL; + HANDLE hdl = INVALID_HANDLE_VALUE; + /* GetTempFileName will fail if the directory is be longer than MAX_PATH-14 + characters */ + char tmpdir[(MAX_PATH + 1) - 14]; + char tmpfile[MAX_PATH + 1]; + static const int max = 1000; + static const char pfx[] = "cyclone"; /* Up to first three are used. */ + + (void)buf; + (void)size; + + ret = GetTempPath(sizeof(tmpdir), tmpdir); + if (ret == 0) { + err = GetLastError(); + } else if (ret > sizeof(tmpdir)) { + err = ENOMEM; + } + + if (GetTempFileName(tmpdir, pfx, 0, tmpfile) == 0) { + err = GetLastError(); + assert(err != ERROR_BUFFER_OVERFLOW); + } else { + /* The combination of FILE_ATTRIBUTE_TEMPORARY and + FILE_FLAG_DELETE_ON_CLOSE hints to the filesystem that the file should + never be flushed to disk. */ + hdl = CreateFile( + tmpfile, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY, + NULL); + if (hdl == INVALID_HANDLE_VALUE) { + err = GetLastError(); + } + } + + if (err) { + errno = err; + } else { + DDSRT_WARNING_MSVC_OFF(4996); + if ((fd = _open_osfhandle((intptr_t)hdl, _O_APPEND)) == -1) { + /* errno set by _open_osfhandle. */ + CloseHandle(hdl); + } else if ((fh = fdopen(fd, mode)) == NULL) { + /* errno set by fdopen. */ + _close(fd); /* Automatically closes underlying handle. */ + } else { + return fh; + } + DDSRT_WARNING_MSVC_ON(4996); + } + + return NULL; +} +#endif /* _WIN32 */ + +static void count(void *ptr, const dds_log_data_t *data) +{ + (void)data; + *(int *)ptr += 1; +} + +static void copy(void *ptr, const dds_log_data_t *data) +{ + *(char **)ptr = ddsrt_strdup(data->message); +} + +static void setup(void) +{ + fh = fmemopen(NULL, 1024, "wb+"); + CU_ASSERT_PTR_NOT_NULL_FATAL(fh); +} + +static void teardown(void) +{ + (void)fclose(fh); +} + +/* By default only DDS_LC_FATAL and DDS_LC_ERROR are set. This means setting a + trace sink should not have any effect, because no trace categories are + enabled. The message should end up in the log file. */ +CU_Test(dds_log, only_log_file, .init=setup, .fini=teardown) +{ + char buf[1024], *ptr; + int cnt = 0; + size_t nbytes; + + dds_set_log_file(fh); + dds_set_trace_sink(&count, &cnt); + DDS_ERROR("foo%s\n", "bar"); + (void)fseek(fh, 0L, SEEK_SET); + nbytes = fread(buf, 1, sizeof(buf) - 1, fh); + /* At least foobar should have been printed to the log file. */ + CU_ASSERT_FATAL(nbytes > 6); + buf[nbytes] = '\0'; + ptr = strstr(buf, "foobar\n"); + CU_ASSERT_PTR_NOT_NULL(ptr); + /* No trace categories are enabled by default, verify trace callback was + not invoked. */ + CU_ASSERT_EQUAL(cnt, 0); +} + +/* Messages must be printed to the trace file if at least one trace category + is enabled. Messages must not be written twice if the trace file is the + same as the log file. */ +CU_Test(dds_log, same_file, .init=setup, .fini=teardown) +{ + char buf[1024], *ptr; + size_t nbytes; + + dds_set_log_mask(DDS_LC_ALL); + dds_set_log_file(fh); + dds_set_trace_file(fh); + DDS_ERROR("foo%s\n", "bar"); + (void)fseek(fh, 0L, SEEK_SET); + nbytes = fread(buf, 1, sizeof(buf) - 1, fh); + /* At least foobar should have been written to the trace file. */ + CU_ASSERT_FATAL(nbytes > 6); + buf[nbytes] = '\0'; + ptr = strstr(buf, "foobar\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); + /* The message should only have been printed once, verify foobar does not + occur again. */ + ptr = strstr(ptr + 1, "foobar\n"); + CU_ASSERT_PTR_NULL(ptr); +} + +/* The sinks are considered to be the same only if the callback and userdata + both are an exact match. If the userdata is different, the function should + be called twice for log messages. */ +CU_Test(dds_log, same_sink_function) +{ + int log_cnt = 0, trace_cnt = 0; + + dds_set_log_mask(DDS_LC_ALL); + dds_set_log_sink(&count, &log_cnt); + dds_set_trace_sink(&count, &trace_cnt); + DDS_ERROR("foo%s\n", "bar"); + CU_ASSERT_EQUAL(log_cnt, 1); + CU_ASSERT_EQUAL(trace_cnt, 1); +} + +CU_Test(dds_log, exact_same_sink) +{ + int cnt = 0; + + dds_set_log_mask(DDS_LC_ALL); + dds_set_log_sink(&count, &cnt); + dds_set_trace_sink(&count, &cnt); + DDS_ERROR("foo%s\n", "bar"); + CU_ASSERT_EQUAL(cnt, 1); +} + +/* The log file must be restored if the sink is unregistered, verify the log + file is not used while the sink is registered. Verify use of the log file is + restored again when the sink is unregistered. */ +CU_Test(dds_log, no_sink, .init=setup, .fini=teardown) +{ + int ret; + char buf[1024], *ptr = NULL; + size_t cnt[2] = {0, 0}; + + /* Set the destination log file and verify the message is written. */ + dds_set_log_file(fh); + DDS_ERROR("foobar\n"); + ret = fseek(fh, 0L, SEEK_SET); + CU_ASSERT_EQUAL_FATAL(ret, 0); + buf[0] = '\0'; + cnt[0] = fread(buf, 1, sizeof(buf) - 1, fh); + buf[cnt[0]] = '\0'; + ptr = strstr(buf, "foobar\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); + + /* Register a custom sink and verify it receives the message. */ + ptr = NULL; + dds_set_log_sink(©, &ptr); + DDS_ERROR("foobaz\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); + CU_ASSERT(strcmp(ptr, "foobaz\n") == 0); + ddsrt_free(ptr); + ptr = NULL; + /* Verify it has not been written to the stream. */ + ret = fseek(fh, 0L, SEEK_SET); + CU_ASSERT_EQUAL_FATAL(ret, 0); + buf[0] = '\0'; + cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh); + buf[cnt[1]] = '\0'; + ptr = strstr(buf, "foobaz\n"); + CU_ASSERT_PTR_NULL_FATAL(ptr); + + /* Unregister the custom sink and verify the default is restored. */ + dds_set_log_sink(0, NULL); + ret = fseek(fh, 0, SEEK_SET); + CU_ASSERT_EQUAL_FATAL(ret, 0); + ptr = NULL; + DDS_ERROR("foobaz\n"); + ret = fseek(fh, 0, SEEK_SET); + CU_ASSERT_PTR_NULL(ptr); + if (ptr != NULL) { + ddsrt_free(ptr); + ptr = NULL; + } + buf[0]= '\0'; + cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh); +#ifdef _WIN32 + /* Write on Windows appends. */ + CU_ASSERT_EQUAL(cnt[1], cnt[0] * 2); +#else + CU_ASSERT_EQUAL(cnt[1], cnt[0]); +#endif + buf[cnt[1]] = '\0'; + ptr = strstr(buf, "foobaz\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); +} + +/* A newline terminates the message. Until that a newline is encountered, the + messages must be concatenated in the buffer. The newline is replaced by a + NULL byte if it is flushed to a sink. */ +CU_Test(dds_log, newline_terminates) +{ + char *msg = NULL; + + dds_set_log_sink(©, &msg); + DDS_ERROR("foo"); + CU_ASSERT_PTR_NULL_FATAL(msg); + DDS_ERROR("bar"); + CU_ASSERT_PTR_NULL_FATAL(msg); + DDS_ERROR("baz\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(msg); + CU_ASSERT(strcmp(msg, "foobarbaz\n") == 0); + ddsrt_free(msg); +} + +/* Nothing must be written unless a category is enabled. */ +CU_Test(dds_log, disabled_categories_discarded) +{ + char *msg = NULL; + + dds_set_log_sink(©, &msg); + DDS_INFO("foobar\n"); + CU_ASSERT_PTR_NULL_FATAL(msg); + dds_set_log_mask(DDS_LC_FATAL | DDS_LC_ERROR | DDS_LC_INFO); + DDS_INFO("foobar\n"); + CU_ASSERT_PTR_NOT_NULL_FATAL(msg); + CU_ASSERT(strcmp(msg, "foobar\n") == 0); + ddsrt_free(msg); +} + + +static ddsrt_cond_t cond; +static ddsrt_mutex_t mutex; + +struct arg { + ddsrt_cond_t *cond; + ddsrt_mutex_t *mutex; + dds_time_t stamp; + dds_duration_t pause; +}; + +static void dummy(void *ptr, const dds_log_data_t *data) +{ + (void)ptr; + (void)data; +} + +static void block(void *ptr, const dds_log_data_t *data) +{ + (void)data; + struct arg *arg = (struct arg *)ptr; + ddsrt_mutex_lock(arg->mutex); + arg->stamp = dds_time(); + ddsrt_cond_broadcast(arg->cond); + ddsrt_mutex_unlock(arg->mutex); + dds_sleepfor(arg->pause); +} + +static uint32_t run(void *ptr) +{ + (void)ptr; + + DDS_ERROR("foobar\n"); + + return 0; +} + +/* Log and trace sinks can be changed at runtime. However, the operation must + be synchronous! Verify the dds_set_log_sink blocks while other threads + reside in the log or trace sinks. */ +CU_Test(dds_log, synchronous_sink_changes) +{ + struct arg arg; + dds_time_t diff, stamp; + ddsrt_thread_t tid; + ddsrt_threadattr_t tattr; + dds_retcode_t ret; + + ddsrt_mutex_init(&mutex); + ddsrt_cond_init(&cond); + (void)memset(&arg, 0, sizeof(arg)); + arg.mutex = &mutex; + arg.cond = &cond; + arg.pause = 1000000; + + ddsrt_mutex_lock(&mutex); + dds_set_log_sink(&block, &arg); + ddsrt_threadattr_init(&tattr); + ret = ddsrt_thread_create(&tid, "foobar", &tattr, &run, &arg); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + ddsrt_cond_wait(&cond, &mutex); + dds_set_log_sink(dummy, NULL); + stamp = dds_time(); + + CU_ASSERT(arg.stamp < stamp); + diff = stamp - arg.stamp; + CU_ASSERT(arg.pause < diff); +} diff --git a/src/ddsrt/tests/select.c b/src/ddsrt/tests/select.c new file mode 100644 index 0000000..ab7bf0e --- /dev/null +++ b/src/ddsrt/tests/select.c @@ -0,0 +1,325 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "CUnit/Theory.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/sockets_priv.h" +#include "dds/ddsrt/threads.h" + +CU_Init(ddsrt_select) +{ + ddsrt_init(); + return 0; +} + +CU_Clean(ddsrt_select) +{ + ddsrt_fini(); + return 0; +} + +static struct timeval tv_init = { .tv_sec = -2, .tv_usec = -2 }; + +#define CU_ASSERT_TIMEVAL_EQUAL(tv, secs, usecs) \ + CU_ASSERT((tv.tv_sec == secs) && (tv.tv_usec == usecs)) + +/* Simple test to validate that duration to timeval conversion is correct. */ +CU_Test(ddsrt_select, duration_to_timeval) +{ + struct timeval tv, *tvptr; + dds_duration_t nsecs_max; + dds_duration_t secs_max = DDSRT_MAX_INTEGER(ddsrt_tv_sec_t); + dds_duration_t usecs_max = 999999; + + if (DDS_INFINITY > secs_max) { + CU_ASSERT_EQUAL_FATAL(secs_max, INT32_MAX); + nsecs_max = DDS_INFINITY * secs_max; + } else { + CU_ASSERT_EQUAL_FATAL(secs_max, DDS_INFINITY); + nsecs_max = DDS_INFINITY / DDS_NSECS_IN_SEC; + } + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(INT64_MIN, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(INT64_MIN + 1, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(-2, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(-1, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(0, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(nsecs_max - 1, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, secs_max, usecs_max); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(nsecs_max, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, secs_max, usecs_max); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(nsecs_max + 1, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, secs_max, usecs_max); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(DDS_INFINITY - 1, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, &tv); + CU_ASSERT_TIMEVAL_EQUAL(tv, secs_max, usecs_max); + + tv = tv_init; + tvptr = ddsrt_duration_to_timeval_ceil(DDS_INFINITY, &tv); + CU_ASSERT_PTR_EQUAL(tvptr, NULL); + CU_ASSERT_TIMEVAL_EQUAL(tv, 0, 0); +} + +typedef struct { + dds_duration_t delay; + dds_duration_t skew; + ddsrt_socket_t sock; +} thread_arg_t; + +static void +sockets_pipe(ddsrt_socket_t socks[2]) +{ + dds_retcode_t rc; + ddsrt_socket_t sock; + int reuseaddr = 1; + + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(54321); + + CU_ASSERT_PTR_NOT_NULL_FATAL(socks); + rc = ddsrt_socket(&sock, AF_INET, SOCK_STREAM, 0); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_setsockopt( + sock, SOL_SOCKET, SO_REUSEADDR, (void*)&reuseaddr, sizeof(reuseaddr)); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_socket(&socks[1], AF_INET, SOCK_STREAM, 0); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_listen(sock, 1); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_connect(socks[1], (struct sockaddr *)&addr, sizeof(addr)); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_accept(sock, NULL, NULL, &socks[0]); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + ddsrt_close(sock); +} + +static const char mesg[] = "foobar"; + +static uint32_t select_timeout_routine(void *ptr) +{ + int cnt = -1; + dds_retcode_t rc; + dds_time_t before, after; + dds_duration_t delay; + fd_set rdset; + thread_arg_t *arg = (thread_arg_t *)ptr; + uint32_t res = 0; + + FD_ZERO(&rdset); + FD_SET(arg->sock, &rdset); + + before = dds_time(); + rc = ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &cnt); + after = dds_time(); + delay = after - before; + + fprintf(stderr, "Waited for %"PRId64" (nanoseconds)\n", delay); + fprintf(stderr, "Expected to wait %"PRId64" (nanoseconds)\n", arg->delay); + fprintf(stderr, "ddsrt_select returned %d\n", rc); + fprintf(stderr, "ddsrt_select reported %d ready\n", cnt); + + if (rc == DDS_RETCODE_TIMEOUT) { + res = (((after - delay) >= (arg->delay - arg->skew)) && (cnt == 0)); + } + + return res; +} + +CU_Test(ddsrt_select, timeout) +{ + dds_retcode_t rc; + ddsrt_socket_t socks[2]; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg; + uint32_t res = 0; + + sockets_pipe(socks); + + arg.delay = DDS_MSECS(100); + /* Allow the delay to be off by x microseconds (arbitrarily chosen) for + systems with a really poor clock. This test is just to get some + confidence that time calculation is not completely broken, it is by + no means proof that time calculation is entirely correct! */ + arg.skew = DDS_MSECS(20); + arg.sock = socks[0]; + + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "select_timeout", &attr, &select_timeout_routine, &arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + /* Allow the thread some time to get ready. */ + dds_sleepfor(arg.delay * 2); + /* Send data to the read socket to avoid blocking indefinitely. */ + ssize_t sent = 0; + rc = ddsrt_send(socks[1], mesg, sizeof(mesg), 0, &sent); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); + + (void)ddsrt_close(socks[0]); + (void)ddsrt_close(socks[1]); +} + +static uint32_t recv_routine(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t*)ptr; + + int nfds = 0; + fd_set rdset; + ssize_t rcvd = -1; + char buf[sizeof(mesg)]; + + FD_ZERO(&rdset); + FD_SET(arg->sock, &rdset); + + (void)ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &nfds); + + if (ddsrt_recv(arg->sock, buf, sizeof(buf), 0, &rcvd) == DDS_RETCODE_OK) { + return (rcvd == sizeof(mesg) && strcmp(buf, mesg) == 0); + } + + return 0; +} + +CU_Test(ddsrt_select, send_recv) +{ + dds_retcode_t rc; + ddsrt_socket_t socks[2]; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg; + uint32_t res = 0; + + sockets_pipe(socks); + + arg.delay = DDS_SECS(1); + arg.skew = 0; + arg.sock = socks[0]; + + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "recv", &attr, &recv_routine, &arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + + ssize_t sent = 0; + rc = ddsrt_send(socks[1], mesg, sizeof(mesg), 0, &sent); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(sent, sizeof(mesg)); + + rc = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); + + (void)ddsrt_close(socks[0]); + (void)ddsrt_close(socks[1]); +} + +static uint32_t recvmsg_routine(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t*)ptr; + + int nfds = 0; + fd_set rdset; + ssize_t rcvd = -1; + char buf[sizeof(mesg)]; + ddsrt_msghdr_t msg; + ddsrt_iovec_t iov; + memset(&msg, 0, sizeof(msg)); + + iov.iov_base = buf; + iov.iov_len = sizeof(buf); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + FD_ZERO(&rdset); + FD_SET(arg->sock, &rdset); + + (void)ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &nfds); + + if (ddsrt_recvmsg(arg->sock, &msg, 0, &rcvd) == DDS_RETCODE_OK) { + return (rcvd == sizeof(mesg) && strcmp(buf, mesg) == 0); + } + + return 0; +} + +CU_Test(ddsrt_select, sendmsg_recvmsg) +{ + dds_retcode_t rc; + ddsrt_socket_t socks[2]; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg; + uint32_t res = 0; + + sockets_pipe(socks); + + memset(&arg, 0, sizeof(arg)); + arg.sock = socks[0]; + + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "recvmsg", &attr, &recvmsg_routine, &arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + + ssize_t sent = 0; + ddsrt_msghdr_t msg; + ddsrt_iovec_t iov; + memset(&msg, 0, sizeof(msg)); + iov.iov_base = (void*)mesg; + iov.iov_len = (ddsrt_iov_len_t)sizeof(mesg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + rc = ddsrt_sendmsg(socks[1], &msg, 0, &sent); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(sent, sizeof(mesg)); + + rc = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); + + (void)ddsrt_close(socks[0]); + (void)ddsrt_close(socks[1]); +} diff --git a/src/ddsrt/tests/socket.c b/src/ddsrt/tests/socket.c new file mode 100644 index 0000000..db89e2a --- /dev/null +++ b/src/ddsrt/tests/socket.c @@ -0,0 +1,198 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#include +#include + +#include "CUnit/Theory.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/endian.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/sockets.h" + +DDSRT_WARNING_MSVC_OFF(4305) +#if DDSRT_ENDIAN == DDSRT_BIG_ENDIAN +static const struct sockaddr_in ipv4_loopback = + { .sin_family = AF_INET, .sin_addr = { .s_addr = 0x7f000001 } }; +#else +static const struct sockaddr_in ipv4_loopback = + { .sin_family = AF_INET, .sin_addr = { .s_addr = 0x0100007f } }; +#endif /* DDSRT_ENDIAN */ +DDSRT_WARNING_MSVC_ON(4305) + +#if DDSRT_HAVE_IPV6 +static const struct sockaddr_in6 ipv6_loopback = + { .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_LOOPBACK_INIT }; +#endif + +static void setup(void) +{ + ddsrt_init(); +} + +static void teardown(void) +{ + ddsrt_fini(); +} + +CU_Test(ddsrt_sockaddrfromstr, bad_family) +{ + dds_retcode_t rc; + struct sockaddr_storage sa; + rc = ddsrt_sockaddrfromstr(AF_UNSPEC, "127.0.0.1", &sa); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER); +} + +static void sockaddrfromstr_test(char *str, int af, dds_retcode_t exp) +{ + dds_retcode_t rc; + struct sockaddr_storage ss; + rc = ddsrt_sockaddrfromstr(af, str, &ss); + CU_ASSERT_EQUAL(rc, exp); + if (rc == DDS_RETCODE_OK) { + CU_ASSERT_EQUAL(ss.ss_family, af); + } +} + +CU_TheoryDataPoints(ddsrt_sockaddrfromstr, ipv4) = { + CU_DataPoints(char *, "127.0.0.1", "0.0.0.0", + "nip"), + CU_DataPoints(int, AF_INET, AF_INET, + AF_INET), + CU_DataPoints(dds_retcode_t, DDS_RETCODE_OK, DDS_RETCODE_OK, + DDS_RETCODE_BAD_PARAMETER) +}; + +CU_Theory((char *str, int af, dds_retcode_t exp), ddsrt_sockaddrfromstr, ipv4, .init=setup, .fini=teardown) +{ + sockaddrfromstr_test(str, af, exp); +} + +#if DDSRT_HAVE_IPV6 +CU_TheoryDataPoints(ddsrt_sockaddrfromstr, ipv6) = { + CU_DataPoints(char *, "127.0.0.1", "::1", + "::1", "::", + "nip"), + CU_DataPoints(int, AF_INET6, AF_INET6, + AF_INET, AF_INET6, + AF_INET6), + CU_DataPoints(dds_retcode_t, DDS_RETCODE_BAD_PARAMETER, DDS_RETCODE_OK, + DDS_RETCODE_BAD_PARAMETER, DDS_RETCODE_OK, + DDS_RETCODE_BAD_PARAMETER) +}; + +CU_Theory((char *str, int af, dds_retcode_t exp), ddsrt_sockaddrfromstr, ipv6, .init=setup, .fini=teardown) +{ + sockaddrfromstr_test(str, af, exp); +} +#endif /* DDSRT_HAVE_IPV6 */ + +CU_Test(ddsrt_sockaddrtostr, bad_sockaddr, .init=setup, .fini=teardown) +{ + dds_retcode_t rc; + char buf[128] = { 0 }; + struct sockaddr_in sa; + memcpy(&sa, &ipv4_loopback, sizeof(ipv4_loopback)); + sa.sin_family = AF_UNSPEC; + rc = ddsrt_sockaddrtostr(&sa, buf, sizeof(buf)); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER); +} + +CU_Test(ddsrt_sockaddrtostr, no_space, .init=setup, .fini=teardown) +{ + dds_retcode_t rc; + char buf[1] = { 0 }; + rc = ddsrt_sockaddrtostr(&ipv4_loopback, buf, sizeof(buf)); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_NOT_ENOUGH_SPACE); +} + +CU_Test(ddsrt_sockaddrtostr, ipv4) +{ + dds_retcode_t rc; + char buf[128] = { 0 }; + rc = ddsrt_sockaddrtostr(&ipv4_loopback, buf, sizeof(buf)); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_STRING_EQUAL(buf, "127.0.0.1"); +} + +CU_Test(ddsrt_sockaddrtostr, ipv6) +{ + dds_retcode_t rc; + char buf[128] = { 0 }; + rc = ddsrt_sockaddrtostr(&ipv6_loopback, buf, sizeof(buf)); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT_STRING_EQUAL(buf, "::1"); +} + +CU_Test(ddsrt_sockets, gethostname) +{ + int ret; + dds_retcode_t rc; + char sysbuf[200], buf[200]; + + buf[0] = '\0'; + rc = ddsrt_gethostname(buf, sizeof(buf)); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + + sysbuf[0] = '\0'; + ret = gethostname(sysbuf, sizeof(sysbuf)); + CU_ASSERT_EQUAL(ret, 0); + CU_ASSERT(strcmp(buf, sysbuf) == 0); + + rc = ddsrt_gethostname(buf, strlen(buf) - 1); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_NOT_ENOUGH_SPACE); +} + +#if DDSRT_HAVE_DNS +static void gethostbyname_test(char *name, int af, dds_retcode_t exp) +{ + dds_retcode_t rc; + ddsrt_hostent_t *hent = NULL; + rc = ddsrt_gethostbyname(name, af, &hent); + CU_ASSERT_EQUAL(rc, exp); + if (rc == DDS_RETCODE_OK) { + CU_ASSERT_FATAL(hent->naddrs > 0); + if (af != AF_UNSPEC) { + CU_ASSERT_EQUAL(hent->addrs[0].ss_family, af); + } + } + ddsrt_free(hent); +} + +CU_TheoryDataPoints(ddsrt_gethostbyname, ipv4) = { + CU_DataPoints(char *, "", "127.0.0.1", "127.0.0.1"), + CU_DataPoints(int, AF_UNSPEC, AF_INET, AF_UNSPEC), + CU_DataPoints(dds_retcode_t, DDS_RETCODE_HOST_NOT_FOUND, DDS_RETCODE_OK, DDS_RETCODE_OK) +}; + +CU_Theory((char *name, int af, dds_retcode_t exp), ddsrt_gethostbyname, ipv4, .init=setup, .fini=teardown) +{ + gethostbyname_test(name, af, exp); +} + +#if DDSRT_HAVE_IPV6 +/* Lookup of IPv4 address and specifying AF_INET6 is not invalid as it may + return an IPV4-mapped IPv6 address. */ +CU_TheoryDataPoints(ddsrt_gethostbyname, ipv6) = { + CU_DataPoints(char *, "::1", "::1", "::1"), + CU_DataPoints(int, AF_INET, AF_INET6, AF_UNSPEC), + CU_DataPoints(dds_retcode_t, DDS_RETCODE_HOST_NOT_FOUND, DDS_RETCODE_OK, DDS_RETCODE_OK) +}; + +CU_Theory((char *name, int af, dds_retcode_t exp), ddsrt_gethostbyname, ipv6, .init=setup, .fini=teardown) +{ + gethostbyname_test(name, af, exp); +} +#endif /* DDSRT_HAVE_IPV6 */ +#endif /* DDSRT_HAVE_DNS */ diff --git a/src/ddsrt/tests/string.c b/src/ddsrt/tests/string.c new file mode 100644 index 0000000..cd3ffbf --- /dev/null +++ b/src/ddsrt/tests/string.c @@ -0,0 +1,101 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "CUnit/Theory.h" +#include "dds/ddsrt/string.h" + +typedef enum { eq, lt, gt } eq_t; + +CU_TheoryDataPoints(ddsrt_strcasecmp, basic) = { + CU_DataPoints(const char *, "a", "aa", "a", "a", "A", "a", "b", "a", "B", "A", "", "a"), + CU_DataPoints(const char *, "a", "a", "aa", "A", "a", "b", "a", "b", "A", "B", "a", ""), + CU_DataPoints(eq_t, eq, gt, lt, eq, eq, lt, gt, lt, gt, lt, lt, gt) +}; + +CU_Theory((const char *s1, const char *s2, eq_t e), ddsrt_strcasecmp, basic) +{ + int r = ddsrt_strcasecmp(s1, s2); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(ddsrt_strncasecmp, basic) = { + CU_DataPoints(const char *, "a", "aa", "a", "A", "a", "b", "a", "B", "A", "", "a"), + CU_DataPoints(const char *, "a", "a", "aa", "a", "A", "a", "b", "A", "B", "a", ""), + CU_DataPoints(size_t, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1), + CU_DataPoints(eq_t, eq, gt, lt, eq, eq, gt, lt, gt, lt, lt, gt) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, basic) +{ + int r = ddsrt_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(ddsrt_strncasecmp, empty) = { + CU_DataPoints(const char *, "a", "", "a", "", "a", ""), + CU_DataPoints(const char *, "", "a", "", "a", "", "a"), + CU_DataPoints(size_t, 1, 1, 0, 0, 2, 2), + CU_DataPoints(eq_t, gt, lt, eq, eq, gt, lt) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, empty) +{ + int r = ddsrt_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_TheoryDataPoints(ddsrt_strncasecmp, length) = { + CU_DataPoints(const char *, "aBcD", "AbCX", "aBcD", "AbCX", "aBcD"), + CU_DataPoints(const char *, "AbCX", "aBcD", "AbCX", "aBcD", "AbCd"), + CU_DataPoints(size_t, 3, 3, 4, 4, 5, 5), + CU_DataPoints(eq_t, eq, eq, lt, gt, eq, eq) +}; + +CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), ddsrt_strncasecmp, length) +{ + int r = ddsrt_strncasecmp(s1, s2, n); + CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); +} + +CU_Test(ddsrt_string, strtok_r) +{ + char *res; + char *saveptr; + char ts1[] = "123,234"; + char ts2[] = ",;,123abc,,456,:,"; + char ts3[] = ",,,123,,456,789,,,"; + + res = ddsrt_strtok_r(ts1, ",", &saveptr); + CU_ASSERT(strcmp(res, "123") == 0); + res = ddsrt_strtok_r( NULL, ",", &saveptr); + CU_ASSERT(strcmp(res, "234") == 0); + res = ddsrt_strtok_r( NULL, ",", &saveptr); + CU_ASSERT(res == NULL); + + res = ddsrt_strtok_r(ts2, ",;", &saveptr); + CU_ASSERT(strcmp(res, "123abc") == 0); + res = ddsrt_strtok_r( NULL, ",", &saveptr); + CU_ASSERT(strcmp(res, "456") == 0); + res = ddsrt_strtok_r( NULL, ",:", &saveptr); + CU_ASSERT(res == NULL); + + res = ddsrt_strtok_r(ts3, ",", &saveptr); + CU_ASSERT(strcmp(res, "123") == 0); + res = ddsrt_strtok_r( NULL, ",", &saveptr); + CU_ASSERT(strcmp(res, "456") == 0); + res = ddsrt_strtok_r( NULL, ",", &saveptr); + CU_ASSERT(strcmp(res, "789") == 0); + res = ddsrt_strtok_r( NULL, ",:", &saveptr); + CU_ASSERT(res == NULL); +} + diff --git a/src/ddsrt/tests/strlcpy.c b/src/ddsrt/tests/strlcpy.c new file mode 100644 index 0000000..143640e --- /dev/null +++ b/src/ddsrt/tests/strlcpy.c @@ -0,0 +1,80 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "CUnit/Theory.h" +#include "dds/ddsrt/string.h" + +CU_TheoryDataPoints(ddsrt_strlcpy, dest_size) = { + CU_DataPoints(char *, "foo", "foo", "foo", "foo", "foo", "", "", ""), + CU_DataPoints(size_t, 0, 1, 3, 4, 5, 0, 1, 2) +}; + +CU_Theory((char *src, size_t size), ddsrt_strlcpy, dest_size) +{ + char dest[] = "................"; + size_t len, srclen; + + srclen = strlen(src); + len = ddsrt_strlcpy(dest, src, size); + CU_ASSERT_EQUAL(len, srclen); + if (size > 0) { + if ((size - 1) < len) { + len = size - 1; + } + CU_ASSERT_EQUAL(dest[len], '\0'); + CU_ASSERT_EQUAL(dest[len+1], '.'); + CU_ASSERT((strncmp(dest, src, len) == 0)); + } else { + CU_ASSERT_EQUAL(dest[0], '.'); + } +} + +CU_TheoryDataPoints(ddsrt_strlcat, dest_size) = { + CU_DataPoints(char *, "", "", "", "", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "", "", "foo", "foo", "foo"), + CU_DataPoints(char *, "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "", "", "", "", ""), + CU_DataPoints(size_t, 0, 1, 3, 4, 0, 1, 3, 4, 5, 6, 7, 0, 1, 3, 4, 5) +}; + +CU_Theory((char *seed, char *src, size_t size), ddsrt_strlcat, dest_size) +{ + char dest[] = "................"; + size_t len, seedlen, srclen; + seedlen = strlen(seed); + srclen = strlen(src); + memcpy(dest, seed, seedlen); + dest[seedlen] = '\0'; + + len = ddsrt_strlcat(dest, src, size); + CU_ASSERT_EQUAL(len, (seedlen + srclen)); + if (size > 0) { + char foobar[sizeof(dest)]; + + if ((size - 1) <= seedlen) { + len = seedlen; + } else if ((size - 1) <= len) { + len = size - 1; + } + + CU_ASSERT_EQUAL(dest[len], '\0'); + + if (seedlen < (size - 1)) { + CU_ASSERT_EQUAL(dest[len+1], '.'); + } + + (void)snprintf(foobar, len+1, "%s%s", seed, src); + CU_ASSERT((strncmp(dest, foobar, len) == 0)); + } else { + CU_ASSERT((strcmp(dest, seed) == 0)); + } +} diff --git a/src/ddsrt/tests/strtoll.c b/src/ddsrt/tests/strtoll.c new file mode 100644 index 0000000..d22e813 --- /dev/null +++ b/src/ddsrt/tests/strtoll.c @@ -0,0 +1,343 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include "CUnit/Test.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/strtol.h" + +const char *str; +char *ptr; +char buf[100]; +char str_llmin[100]; +char str_llmax[100]; +char str_ullmax[100]; +char str_llrange[100]; +char str_ullrange[100]; + +char str_xllmin[99], str_xllmax[99]; + +/* Really test with the maximum values supported on a platform, not some + made up number. */ +long long llmin = DDSRT_MIN_INTEGER(long long); +long long llmax = DDSRT_MAX_INTEGER(long long); +unsigned long long ullmax = DDSRT_MAX_INTEGER(unsigned long long); + +CU_Init(ddsrt_strtoll) +{ + ddsrt_init(); + (void)snprintf (str_llmin, sizeof(str_llmin), "%lld", llmin); + (void)snprintf (str_llmax, sizeof(str_llmax), "%lld", llmax); + (void)snprintf (str_llrange, sizeof(str_llrange), "%lld1", llmax); + (void)snprintf (str_ullmax, sizeof(str_ullmax), "%llu", ullmax); + (void)snprintf (str_ullrange, sizeof(str_ullrange), "%llu1", ullmax); + (void)snprintf (str_xllmin, sizeof(str_xllmin), "-%llx", llmin); + (void)snprintf (str_xllmax, sizeof(str_xllmax), "+%llx", llmax); + return 0; +} + +CU_Clean(ddstr_strtoll) +{ + ddsrt_fini(); + return 0; +} + +CU_Test(ddsrt_strtoll, strtoll) +{ + dds_retcode_t rc; + long long ll; + static char dummy[] = "dummy"; + + str = "gibberish"; + ll = -1; + rc = ddsrt_strtoll(str, &ptr, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0 && ptr == str); + + str = "+gibberish"; + ll = -2; + rc = ddsrt_strtoll(str, &ptr, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0 && ptr == str); + + str = "-gibberish"; + ll = -3; + rc = ddsrt_strtoll(str, &ptr, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0 && ptr == str); + + str = "gibberish"; + ptr = NULL; + ll = -4; + rc = ddsrt_strtoll(str, &ptr, 36, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 46572948005345 && ptr && *ptr == '\0'); + + str = "1050505055"; + ptr = dummy; + ll = -5; + rc = ddsrt_strtoll(str, &ptr, 37, &ll); + CU_ASSERT (rc == DDS_RETCODE_BAD_PARAMETER); + CU_ASSERT (ll == -5 && ptr == dummy); + + str = " \t \n 1050505055"; + ll = -6; + rc = ddsrt_strtoll(str, NULL, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 1050505055LL); + + str = " \t \n -1050505055"; + ptr = NULL; + ll = -7; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == -1050505055LL); + + str = " \t \n - \t \n 1050505055"; + ptr = NULL; + ll = -8; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0LL && ptr == str); + + str = "10x"; + ptr = NULL; + ll = -9; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 10LL && ptr && *ptr == 'x'); + + str = "+10x"; + ll = -10; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 10LL && ptr && *ptr == 'x'); + + str = "-10x"; + ll = -11; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == -10LL && ptr && *ptr == 'x'); + + str = (const char *)str_llmax; + ll = -12; + rc = ddsrt_strtoll(str, NULL, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == llmax); + + str = (const char *)str_llmin; + ll = -13; + rc = ddsrt_strtoll(str, NULL, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == llmin); + + str = (const char *)str_llrange; + ll = -14; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OUT_OF_RANGE); + CU_ASSERT (ll == llmax && *ptr == '1'); + + str = "0x100"; + ll = -15; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x100LL); + + str = "0X100"; + ll = -16; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x100LL); + + str = "0x1DEFCAB"; + ll = -17; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x1DEFCABLL); + + str = "0x1defcab"; + ll = -18; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x1DEFCABLL); + + str = (char *)str_xllmin; + ll = -19; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == llmin); + + str = (char *)str_xllmax; + ll = -20; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == llmax); + + str = "0x100"; + ll = -21; + rc = ddsrt_strtoll(str, NULL, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x100LL); + + str = "100"; + ll = -22; + rc = ddsrt_strtoll(str, NULL, 16, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0x100LL); + + /* calling os_strtoll with \"%s\" and base 10, expected result 0 */ + str = "0x100"; + ll = -23; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 0 && ptr && *ptr == 'x'); + + /* calling os_strtoll with \"%s\" and base 0, expected result 256 */ + str = "0x100g"; + ll = -24; + rc = ddsrt_strtoll(str, &ptr, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 256 && ptr && *ptr == 'g'); + + str = "0100"; + ll = -25; + rc = ddsrt_strtoll(str, NULL, 0, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 64LL); + + str = "0100"; + ll = -26; + rc = ddsrt_strtoll(str, NULL, 8, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 64LL); + + str = "100"; + ll = -27; + rc = ddsrt_strtoll(str, NULL, 8, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 64LL); + + /* calling os_strtoll with \"%s\" and base 10, expected result 100 */ + str = "0100"; + ll = -28; + rc = ddsrt_strtoll(str, &ptr, 10, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 100); + + /* calling os_strtoll with \"%s\" and base 0, expected result 64 */ + str = "01008"; + ll = -29; + rc = ddsrt_strtoll(str, &ptr, 8, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 64LL && ptr && *ptr == '8'); + + str = "00001010"; + ll = -30; + rc = ddsrt_strtoll(str, NULL, 2, &ll); + CU_ASSERT (rc == DDS_RETCODE_OK); + CU_ASSERT (ll == 10LL); +} + +CU_Test(ddsrt_strtoll, strtoull) +{ + dds_retcode_t rc; + unsigned long long ull; + + str = "0xffffffffffffffff"; + ull = 1; + rc = ddsrt_strtoull(str, NULL, 0, &ull); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT(ull == ullmax); + + str = "-1"; + ull = 2; + rc = ddsrt_strtoull(str, NULL, 0, &ull); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT(ull == ullmax); + + str = "-2"; + ull = 3; + rc = ddsrt_strtoull(str, NULL, 0, &ull); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT(ull == (ullmax - 1)); +} + +CU_Test(ddsrt_strtoll, atoll) +{ + dds_retcode_t rc; + long long ll; + + str = "10"; + ll = -1; + rc = ddsrt_atoll(str, &ll); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT(ll == 10); +} + +CU_Test(ddsrt_strtoll, atoull) +{ + dds_retcode_t rc; + unsigned long long ull; + + str = "10"; + ull = 1; + rc = ddsrt_atoull(str, &ull); + CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); + CU_ASSERT(ull == 10); +} + +CU_Test(ddsrt_strtoll, lltostr) +{ + long long ll; + + ll = llmax; + ptr = ddsrt_lltostr(ll, buf, 0, NULL); + CU_ASSERT(ptr == NULL); + + /* calling os_lltostr with %lld with buffer size of 5, expected result \"5432\" */ + ll = 54321; + ptr = ddsrt_lltostr(ll, buf, 5, NULL); + CU_ASSERT(strcmp(ptr, "5432") == 0); + + ll = llmax; + ptr = ddsrt_lltostr(ll, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, str_llmax) == 0); + + ll = llmin; + ptr = ddsrt_lltostr(ll, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, str_llmin) == 0); + + ll = 1; + ptr = ddsrt_lltostr(ll, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, "1") == 0); + + ll = 0; + ptr = ddsrt_lltostr(ll, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, "0") == 0); + + ll = -1; + ptr = ddsrt_lltostr(ll, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, "-1") == 0); +} + +CU_Test(ddsrt_strtoll, ulltostr) +{ + unsigned long long ull; + + ull = ullmax; + ptr = ddsrt_ulltostr(ull, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, str_ullmax) == 0); + + ull = 0ULL; + ptr = ddsrt_ulltostr(ull, buf, sizeof(buf), NULL); + CU_ASSERT(strcmp(ptr, "0") == 0); +} + diff --git a/src/ddsrt/tests/sync.c b/src/ddsrt/tests/sync.c new file mode 100644 index 0000000..1f8031c --- /dev/null +++ b/src/ddsrt/tests/sync.c @@ -0,0 +1,357 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include + +#include "CUnit/Theory.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsrt/time.h" + +CU_Init(ddsrt_sync) +{ + ddsrt_init(); + return 0; +} + +CU_Clean(ddsrt_sync) +{ + ddsrt_fini(); + return 0; +} + +typedef struct { + ddsrt_atomic_uint32_t cnt; + ddsrt_mutex_t lock; + ddsrt_rwlock_t rwlock; + ddsrt_cond_t cond; + dds_time_t abstime; + dds_time_t reltime; +} thread_arg_t; + +static uint32_t mutex_lock_routine(void *ptr) +{ + int res; + thread_arg_t *arg = (thread_arg_t *)ptr; + + ddsrt_atomic_inc32(&arg->cnt); + ddsrt_mutex_lock(&arg->lock); + res = ddsrt_atomic_cas32(&arg->cnt, 2UL, 4UL); + ddsrt_mutex_unlock(&arg->lock); + return (uint32_t)res; +} + +/* This test is merely best-effort, the scheduler might schedule the main + main thread before a lock operation is attempted by the second thread. */ +CU_Test(ddsrt_sync, mutex_lock_conc) +{ + dds_retcode_t ret; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg = { .cnt = DDSRT_ATOMIC_UINT32_INIT(0) }; + uint32_t res = 0; + + ddsrt_mutex_init(&arg.lock); + ddsrt_mutex_lock(&arg.lock); + ddsrt_threadattr_init(&attr); + ret = ddsrt_thread_create(&thr, "mutex_lock_conc", &attr, &mutex_lock_routine, &arg); + CU_ASSERT_EQUAL(ret, DDS_RETCODE_OK); + while (ddsrt_atomic_ld32(&arg.cnt) == 0) + /* Wait for thread to be scheduled. */ ; + ddsrt_atomic_inc32(&arg.cnt); + ddsrt_mutex_unlock(&arg.lock); + ret = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); + CU_ASSERT_EQUAL(ddsrt_atomic_ld32(&arg.cnt), 4UL); + ddsrt_mutex_destroy(&arg.lock); +} + +static uint32_t mutex_trylock_routine(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t *)ptr; + + if (ddsrt_mutex_trylock(&arg->lock)) { + ddsrt_atomic_inc32(&arg->cnt); + } + + return ddsrt_atomic_ld32(&arg->cnt); +} + +CU_Test(ddsrt_sync, mutex_trylock) +{ + bool locked; + ddsrt_mutex_t lock; + + ddsrt_mutex_init(&lock); + locked = ddsrt_mutex_trylock(&lock); + CU_ASSERT(locked == true); + locked = ddsrt_mutex_trylock (&lock); + /* NOTE: On VxWorks RTP mutexes seemingly can be locked recursively. Still, + behavior should be consistent across targets. If this fails, fix + the implementation instead. */ + CU_ASSERT(locked == false); + ddsrt_mutex_unlock(&lock); + ddsrt_mutex_destroy(&lock); +} + +static uint32_t rwlock_tryread_routine(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t *)ptr; + + if (ddsrt_rwlock_tryread(&arg->rwlock)) { + ddsrt_atomic_inc32(&arg->cnt); + ddsrt_rwlock_unlock(&arg->rwlock); + } + + return ddsrt_atomic_ld32(&arg->cnt); +} + +static uint32_t rwlock_trywrite_routine(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t *)ptr; + + /* This operation should never succeed in the test, but if it does the + result must reflect it. */ + if (ddsrt_rwlock_trywrite(&arg->rwlock)) { + ddsrt_atomic_inc32(&arg->cnt); + ddsrt_rwlock_unlock(&arg->rwlock); + } + + return ddsrt_atomic_ld32(&arg->cnt); +} + +CU_Test(ddsrt_sync, mutex_trylock_conc) +{ + dds_retcode_t ret; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg = { .cnt = DDSRT_ATOMIC_UINT32_INIT(1) }; + uint32_t res = 0; + + ddsrt_mutex_init(&arg.lock); + ddsrt_mutex_lock(&arg.lock); + ddsrt_threadattr_init(&attr); + ret = ddsrt_thread_create(&thr, "mutex_trylock_conc", &attr, &mutex_trylock_routine, &arg); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + ret = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); + ddsrt_mutex_unlock(&arg.lock); + ddsrt_mutex_destroy(&arg.lock); +} + +#define READ (1) +#define TRYREAD (2) +#define WRITE (3) +#define TRYWRITE (4) + +CU_TheoryDataPoints(ddsrt_sync, rwlock_trylock_conc) = { + CU_DataPoints(uint32_t, READ, READ, WRITE, WRITE), + CU_DataPoints(uint32_t, TRYREAD, TRYWRITE, TRYREAD, TRYWRITE), + CU_DataPoints(uint32_t, 2, 1, 1, 1) +}; + +CU_Theory((uint32_t lock, uint32_t trylock, uint32_t exp), ddsrt_sync, rwlock_trylock_conc) +{ + dds_retcode_t ret; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + ddsrt_thread_routine_t func; + thread_arg_t arg = { .cnt = DDSRT_ATOMIC_UINT32_INIT(1) }; + uint32_t res = 0; + + ddsrt_rwlock_init(&arg.rwlock); + if (lock == READ) { + ddsrt_rwlock_read(&arg.rwlock); + } else { + ddsrt_rwlock_write(&arg.rwlock); + } + + if (trylock == TRYREAD) { + func = &rwlock_tryread_routine; + } else { + func = &rwlock_trywrite_routine; + } + + ddsrt_threadattr_init(&attr); + ret = ddsrt_thread_create(&thr, "rwlock_trylock_conc", &attr, func, &arg); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + ret = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + ddsrt_rwlock_unlock(&arg.rwlock); + CU_ASSERT_EQUAL(res, exp); + ddsrt_rwlock_destroy(&arg.rwlock); +} + +/* An atomic read is used for synchronization because it is important that the + threads try to access the once control concurrently as much as possible. Of + course, this is only best-effort as there is no guarantee that + initialization is actually tried concurrently. */ +static ddsrt_atomic_uint32_t once_count = DDSRT_ATOMIC_UINT32_INIT(0); +static ddsrt_once_t once_control = DDSRT_ONCE_INIT; + +#define ONCE_THREADS (8) + +static void do_once(void) +{ + ddsrt_atomic_inc32(&once_count); +} + +static uint32_t once_routine(void *ptr) +{ + (void)ptr; + while (ddsrt_atomic_ld32(&once_count) == 0) + /* Wait for the go-ahead. */ ; + ddsrt_once(&once_control, &do_once); + return ddsrt_atomic_ld32(&once_count); +} + +CU_Test(ddsrt_sync, once_conc) +{ + dds_retcode_t ret; + ddsrt_thread_t thrs[ONCE_THREADS]; + ddsrt_threadattr_t attr; + uint32_t res; + char buf[32]; + + ddsrt_threadattr_init(&attr); + for (int i = 0; i < ONCE_THREADS; i++) { + (void)snprintf(buf, sizeof(buf), "once_conc%d", i + 1); + ret = ddsrt_thread_create(&thrs[i], buf, &attr, &once_routine, NULL); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + } + + ddsrt_atomic_st32(&once_count, 1); + + for (int i = 0; i < ONCE_THREADS; i++) { + res = 0; + ret = ddsrt_thread_join(thrs[i], &res); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 2); + } + + ddsrt_once(&once_control, &do_once); + CU_ASSERT_EQUAL(ddsrt_atomic_ld32(&once_count), 2); +} + +static uint32_t waitfor_routine(void *ptr) +{ + dds_time_t before, after; + dds_duration_t reltime; + thread_arg_t *arg = (thread_arg_t *)ptr; + uint32_t cnt = 0, res = 0; + + while (ddsrt_atomic_ld32(&arg->cnt) == 0) + /* Wait for go-ahead. */ ; + ddsrt_mutex_lock(&arg->lock); + before = dds_time(); + reltime = arg->reltime; + while (ddsrt_cond_waitfor(&arg->cond, &arg->lock, reltime)) { + after = dds_time(); + if ((after - before) < arg->reltime && (after - before) > 0) { + reltime = arg->reltime - (after - before); + } else { + reltime = 0; + } + cnt++; + } + after = dds_time(); + reltime = after - before; + fprintf(stderr, "waited for %"PRId64" (nanoseconds)\n", reltime); + fprintf(stderr, "expected to wait %"PRId64" (nanoseconds)\n", arg->reltime); + fprintf(stderr, "woke up %u times\n", cnt); + ddsrt_mutex_unlock(&arg->lock); + if (reltime >= arg->reltime) { + /* Ensure that the condition variable at least waited for the amount of + time so that time calculation is not (too) broken.*/ + res = cnt < 3; /* An arbitrary number to ensure the implementation + did not just spin, aka is completely broken. */ + } + + return res; +} + +CU_Test(ddsrt_sync, cond_waitfor) +{ + dds_retcode_t rc; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg = { .cnt = DDSRT_ATOMIC_UINT32_INIT(0), .reltime = DDS_MSECS(100) }; + uint32_t res = 0; + + ddsrt_mutex_init(&arg.lock); + ddsrt_cond_init(&arg.cond); + ddsrt_mutex_lock(&arg.lock); + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "cond_waitfor", &attr, &waitfor_routine, &arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + ddsrt_mutex_unlock(&arg.lock); + /* Give go-ahead. */ + ddsrt_atomic_inc32(&arg.cnt); + /* Wait a little longer than the waiting thread. */ + dds_sleepfor(arg.reltime * 2); + /* Send a signal too avoid blocking indefinitely. */ + ddsrt_cond_signal(&arg.cond); + rc = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); +} + +static uint32_t waituntil_routine(void *ptr) +{ + dds_time_t after; + thread_arg_t *arg = (thread_arg_t *)ptr; + uint32_t cnt = 0, res = 0; + + ddsrt_mutex_lock(&arg->lock); + while(ddsrt_cond_waituntil(&arg->cond, &arg->lock, arg->abstime)) { + cnt++; + } + after = dds_time(); + ddsrt_mutex_unlock(&arg->lock); + fprintf(stderr, "waited until %"PRId64" (nanoseconds)\n", after); + fprintf(stderr, "expected to wait until %"PRId64" (nanoseconds)\n", arg->abstime); + fprintf(stderr, "woke up %u times\n", cnt); + if (after > arg->abstime) { + res = cnt < 3; /* An arbitrary number to ensure the implementation + did not just spin, aka is completely broken. */ + } + + return res; +} + +CU_Test(ddsrt_sync, cond_waituntil) +{ + dds_retcode_t rc; + dds_duration_t delay = DDS_MSECS(100); + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg = { .cnt = DDSRT_ATOMIC_UINT32_INIT(0) }; + uint32_t res = 0; + + arg.abstime = dds_time() + delay; + ddsrt_mutex_init(&arg.lock); + ddsrt_cond_init(&arg.cond); + ddsrt_mutex_lock(&arg.lock); + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "cond_waituntil", &attr, &waituntil_routine, &arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + ddsrt_mutex_unlock(&arg.lock); + dds_sleepfor(delay * 2); + /* Send a signal too avoid blocking indefinitely. */ + ddsrt_cond_signal(&arg.cond); + rc = ddsrt_thread_join(thr, &res); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, 1); +} diff --git a/src/ddsrt/tests/thread.c b/src/ddsrt/tests/thread.c new file mode 100644 index 0000000..8b3ff5d --- /dev/null +++ b/src/ddsrt/tests/thread.c @@ -0,0 +1,233 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include +#if !defined(_WIN32) +#include +#include +#endif + +#include "CUnit/Theory.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" + +static int32_t min_fifo_prio = 250; +static int32_t max_fifo_prio = 250; +static int32_t max_other_prio = 60; +static int32_t min_other_prio = 250; + +CU_Init(ddsrt_thread) +{ + ddsrt_init(); +#if defined(WIN32) + max_fifo_prio = THREAD_PRIORITY_HIGHEST; + min_fifo_prio = THREAD_PRIORITY_LOWEST; + max_other_prio = THREAD_PRIORITY_HIGHEST; + min_other_prio = THREAD_PRIORITY_LOWEST; +#else + min_fifo_prio = sched_get_priority_min(SCHED_FIFO); + max_fifo_prio = sched_get_priority_max(SCHED_FIFO); +# if !defined(_WRS_KERNEL) + max_other_prio = sched_get_priority_max(SCHED_OTHER); + min_other_prio = sched_get_priority_min(SCHED_OTHER); +# endif +#endif + + return 0; +} + +CU_Clean(ddsrt_thread) +{ + ddsrt_fini(); + return 0; +} + +typedef struct { + int res; + int ret; + ddsrt_threadattr_t *attr; +} thread_arg_t; + +uint32_t thread_main(void *ptr) +{ + thread_arg_t *arg = (thread_arg_t *)ptr; + ddsrt_threadattr_t *attr; + + assert(arg != NULL); + + attr = arg->attr; + +#if _WIN32 + int prio = GetThreadPriority(GetCurrentThread()); + if (prio == THREAD_PRIORITY_ERROR_RETURN) + abort(); + if (prio == attr->schedPriority) { + arg->res = 1; + } +#else + int err; + int policy; + struct sched_param sched; + + err = pthread_getschedparam(pthread_self(), &policy, &sched); + if (err != 0) { + abort(); + } + if (((policy == SCHED_OTHER && attr->schedClass == DDSRT_SCHED_TIMESHARE) || + (policy == SCHED_FIFO && attr->schedClass == DDSRT_SCHED_REALTIME)) + && (sched.sched_priority == attr->schedPriority)) + { + arg->res = 1; + } +#endif + + return (uint32_t)arg->ret; +} + +CU_TheoryDataPoints(ddsrt_thread, create_and_join) = { + CU_DataPoints(ddsrt_sched_t, DDSRT_SCHED_TIMESHARE, DDSRT_SCHED_TIMESHARE, + DDSRT_SCHED_REALTIME, DDSRT_SCHED_REALTIME), + CU_DataPoints(int32_t *, &min_other_prio, &max_other_prio, + &min_fifo_prio, &max_fifo_prio), + CU_DataPoints(uint32_t, 10101, 20202, + 30303, 40404) +}; + +CU_Theory((ddsrt_sched_t sched, int32_t *prio, uint32_t exp), ddsrt_thread, create_and_join) +{ + int skip = 0; + uint32_t res = 50505; + dds_retcode_t ret; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + thread_arg_t arg; + +#if defined(__VXWORKS__) +# if defined(_WRS_KERNEL) + if (sched == DDSRT_SCHED_TIMESHARE) { + skip = 1; + CU_PASS("VxWorks DKM only supports SCHED_FIFO"); + } +# endif +#elif !defined(_WIN32) + if (sched == DDSRT_SCHED_REALTIME && (getuid() != 0 && geteuid() != 0)) { + skip = 1; + CU_PASS("SCHED_FIFO requires root privileges"); + } +#endif + if (!skip) { + ddsrt_threadattr_init(&attr); + attr.schedClass = sched; + attr.schedPriority = *prio; + memset(&arg, 0, sizeof(arg)); + arg.ret = (int32_t)exp; + arg.attr = &attr; + ret = ddsrt_thread_create(&thr, "thread", &attr, &thread_main, &arg); + CU_ASSERT_EQUAL(ret, DDS_RETCODE_OK); + if (ret == DDS_RETCODE_OK) { + ret = ddsrt_thread_join (thr, &res); + CU_ASSERT_EQUAL(ret, DDS_RETCODE_OK); + CU_ASSERT_EQUAL(res, exp); + if (ret == DDS_RETCODE_OK) { + CU_ASSERT_EQUAL(arg.res, 1); + } + } + } +} + +CU_Test(ddsrt_thread, thread_id) +{ + int eq = 0; + ddsrt_thread_t thr; +#if defined(_WIN32) + DWORD _tid; +#else + pthread_t _thr; +#endif + + thr = ddsrt_thread_self(); + +#if defined(_WIN32) + _tid = GetCurrentThreadId(); + eq = (thr.tid == _tid); +#else + _thr = pthread_self(); + eq = pthread_equal(thr.v, _thr); +#endif + + CU_ASSERT_NOT_EQUAL(eq, 0); +} + + +static ddsrt_mutex_t locks[2]; + +uint32_t thread_main_waitforme(void *ptr) +{ + uint32_t ret = 0; + (void)ptr; + ddsrt_mutex_lock(&locks[0]); + ret = 10101; + ddsrt_mutex_unlock(&locks[0]); + return ret; +} + +uint32_t thread_main_waitforit(void *ptr) +{ + uint32_t res = 0; + ddsrt_thread_t *thr = (ddsrt_thread_t *)ptr; + ddsrt_mutex_lock(&locks[1]); + (void)ddsrt_thread_join(*thr, &res); + ddsrt_mutex_unlock(&locks[1]); + return res + 20202; +} + +CU_Test(ddsrt_thread, stacked_join) +{ + dds_retcode_t ret; + ddsrt_thread_t thrs[2]; + ddsrt_threadattr_t attr; + uint32_t res = 0; + + ddsrt_mutex_init(&locks[0]); + ddsrt_mutex_init(&locks[1]); + ddsrt_mutex_lock(&locks[0]); + ddsrt_mutex_lock(&locks[1]); + ddsrt_threadattr_init(&attr); + ret = ddsrt_thread_create(&thrs[0], "", &attr, &thread_main_waitforme, NULL); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + ret = ddsrt_thread_create(&thrs[1], "", &attr, &thread_main_waitforit, &thrs[0]); + CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); + + ddsrt_mutex_unlock(&locks[1]); + dds_sleepfor(DDS_MSECS(100)); /* 100ms */ + ddsrt_mutex_unlock(&locks[0]); + + ddsrt_thread_join(thrs[1], &res); + + CU_ASSERT_EQUAL(res, 30303); + + ddsrt_mutex_destroy(&locks[0]); + ddsrt_mutex_destroy(&locks[1]); +} + +CU_Test(ddsrt_thread, attribute) +{ + ddsrt_threadattr_t attr; + + ddsrt_threadattr_init(&attr); + CU_ASSERT_EQUAL(attr.schedClass, DDSRT_SCHED_DEFAULT); + CU_ASSERT_EQUAL(attr.schedPriority, 0); + CU_ASSERT_EQUAL(attr.stackSize, 0); +} + diff --git a/src/ddsrt/tests/thread_cleanup.c b/src/ddsrt/tests/thread_cleanup.c new file mode 100644 index 0000000..4e9bf24 --- /dev/null +++ b/src/ddsrt/tests/thread_cleanup.c @@ -0,0 +1,286 @@ +/* + * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License + * v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +#include +#include + +#include "CUnit/Test.h" +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" + +CU_Init(ddsrt_thread_cleanup) +{ + ddsrt_init(); + return 0; +} + +CU_Clean(ddsrt_thread_cleanup) +{ + ddsrt_fini(); + return 0; +} + +#define THREAD_RESET_1 (1<<0) +#define THREAD_RESET_2 (1<<1) +#define THREAD_RUN_OFFSET (4) +#define THREAD_RUN_1 (1<<(THREAD_RUN_OFFSET)) +#define THREAD_RUN_2 (1<<(THREAD_RUN_OFFSET + 1)) + +struct thread_argument { + int flags; + int pop; + int one; + int two; + int executed; + int cancelled; + int block; + ddsrt_mutex_t *mutex; + ddsrt_thread_t thread; +}; + +static struct thread_argument * +make_thread_argument( + int flags, int pop, int one, int two) +{ + struct thread_argument *targ = ddsrt_malloc(sizeof(*targ)); + memset(targ, 0, sizeof(*targ)); + targ->flags = flags; + targ->pop = pop; + targ->one = one; + targ->two = two; + + return targ; +} + +static void +reset_one( + void *arg) +{ + struct thread_argument *targ = (struct thread_argument *)arg; + targ->one = 0; + targ->executed++; +} + +static void +reset_two( + void *arg) +{ + struct thread_argument *targ = (struct thread_argument *)arg; + targ->two = 0; + targ->executed++; +} + +static uint32_t +thread_main( + void *arg) +{ + int pushed = 0; + int popped = 0; + int execute = 0; + struct thread_argument *targ = (struct thread_argument *)arg; + + if (targ->flags & THREAD_RESET_1) { + ddsrt_thread_cleanup_push(&reset_one, arg); + pushed++; + } + if (targ->flags & THREAD_RESET_2) { + ddsrt_thread_cleanup_push(&reset_two, arg); + pushed++; + } + + assert(targ->pop <= pushed); + + if (targ->block) { + ddsrt_mutex_lock(targ->mutex); + } + + while (popped < targ->pop) { + execute = 1 << (THREAD_RUN_OFFSET + (targ->pop - (popped + 1))); + ddsrt_thread_cleanup_pop(targ->flags & execute); + targ->cancelled++; + popped++; + } + + if (targ->block) { + ddsrt_mutex_unlock(targ->mutex); + } + + return 0; +} + +static void +setup( + struct thread_argument *arg) +{ + dds_retcode_t rc; + ddsrt_thread_t thr; + ddsrt_threadattr_t attr; + + uint32_t tres = 0; + + ddsrt_threadattr_init(&attr); + rc = ddsrt_thread_create(&thr, "", &attr, &thread_main, (void *)arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + + arg->thread = thr; + if (!arg->block) { + rc = ddsrt_thread_join(thr, &tres); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + } +} + +/* verify the cleanup routine is called */ +CU_Test(ddsrt_thread_cleanup, push_one) +{ + int flags = THREAD_RESET_1; + struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 2); + CU_ASSERT_EQUAL(targ->executed, 1); + CU_ASSERT_EQUAL(targ->cancelled, 0); + + ddsrt_free(targ); +} + +/* verify all cleanup routines are called if multiple are registered */ +CU_Test(ddsrt_thread_cleanup, push_two) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2; + struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 0); + CU_ASSERT_EQUAL(targ->executed, 2); + CU_ASSERT_EQUAL(targ->cancelled, 0); + + ddsrt_free(targ); +} + +/* verify the first cleanup routine is still called if second got popped */ +CU_Test(ddsrt_thread_cleanup, push_two_pop_one_no_exec) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2; + struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 2); + CU_ASSERT_EQUAL(targ->executed, 1); + CU_ASSERT_EQUAL(targ->cancelled, 1); + + ddsrt_free(targ); +} + +CU_Test(ddsrt_thread_cleanup, push_two_pop_one_exec) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; + struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 0); + CU_ASSERT_EQUAL(targ->executed, 2); + CU_ASSERT_EQUAL(targ->cancelled, 1); + + ddsrt_free(targ); +} + +/* verify no cleanup routines are called if all got popped */ +CU_Test(ddsrt_thread_cleanup, push_two_pop_two_no_exec) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2; + struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 1); + CU_ASSERT_EQUAL(targ->two, 2); + CU_ASSERT_EQUAL(targ->executed, 0); + CU_ASSERT_EQUAL(targ->cancelled, 2); + + ddsrt_free(targ); +} + +CU_Test(ddsrt_thread_cleanup, push_two_pop_two_exec_one) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; + struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 2); + CU_ASSERT_EQUAL(targ->executed, 1); + CU_ASSERT_EQUAL(targ->cancelled, 2); + + ddsrt_free(targ); +} + +CU_Test(ddsrt_thread_cleanup, push_two_pop_two_exec_both) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1 | THREAD_RUN_2; + struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); + setup(targ); + + CU_ASSERT_EQUAL(targ->one, 0); + CU_ASSERT_EQUAL(targ->two, 0); + CU_ASSERT_EQUAL(targ->executed, 2); + CU_ASSERT_EQUAL(targ->cancelled, 2); + + ddsrt_free(targ); +} + +CU_Test(ddsrt_thread_cleanup, no_interference) +{ + int flags = THREAD_RESET_1 | THREAD_RESET_2; + struct thread_argument *targ1 = make_thread_argument(flags, 0, 1, 2); + struct thread_argument *targ2 = make_thread_argument(flags, 2, 1, 2); + ddsrt_mutex_t mutex1, mutex2; + + ddsrt_mutex_init(&mutex1); + ddsrt_mutex_init(&mutex2); + ddsrt_mutex_lock(&mutex1); + ddsrt_mutex_lock(&mutex2); + + targ1->mutex = &mutex1; + targ1->block = 1; + targ2->mutex = &mutex2; + targ2->block = 1; + + setup(targ1); + setup(targ2); + + /* ensure thread 2 pops it's cleanup routines while thread 1 blocks */ + ddsrt_mutex_unlock(&mutex2); + ddsrt_thread_join(targ2->thread, NULL); + + CU_ASSERT_EQUAL(targ2->one, 1); + CU_ASSERT_EQUAL(targ2->two, 2); + CU_ASSERT_EQUAL(targ2->executed, 0); + CU_ASSERT_EQUAL(targ2->cancelled, 2); + + /* instruct thread 1 to continue */ + ddsrt_mutex_unlock(&mutex1); + ddsrt_thread_join(targ1->thread, NULL); + + CU_ASSERT_EQUAL(targ1->one, 0); + CU_ASSERT_EQUAL(targ1->two, 0); + CU_ASSERT_EQUAL(targ1->executed, 2); + CU_ASSERT_EQUAL(targ1->cancelled, 0); + + ddsrt_mutex_destroy(&mutex1); + ddsrt_mutex_destroy(&mutex2); + ddsrt_free(targ1); + ddsrt_free(targ2); +} diff --git a/src/docs/CMakeLists.txt b/src/docs/CMakeLists.txt index 0ce07fd..6b95a4d 100644 --- a/src/docs/CMakeLists.txt +++ b/src/docs/CMakeLists.txt @@ -108,7 +108,7 @@ elseif(BUILD_DOCS) # Process doxygen configuration file, for ddsc set(doxy_conf_project "${CMAKE_PROJECT_NAME_FULL} C API Documentation") set(doxy_conf_outputdir "ddsc_api") - set(doxy_conf_input "${PROJECT_SOURCE_DIR}/core/ddsc/include/ddsc/dds.h ${PROJECT_SOURCE_DIR}/core/ddsc/include/ddsc") + set(doxy_conf_input "${PROJECT_SOURCE_DIR}/core/ddsc/include/dds/dds.h ${PROJECT_SOURCE_DIR}/core/ddsc/include/dds") configure_file(Doxyfile.in Doxyfile @ONLY) add_custom_target(ddsc_docs diff --git a/src/docs/GettingStartedGuide/helloworld_indepth.rst b/src/docs/GettingStartedGuide/helloworld_indepth.rst index 858cfab..94a4575 100644 --- a/src/docs/GettingStartedGuide/helloworld_indepth.rst +++ b/src/docs/GettingStartedGuide/helloworld_indepth.rst @@ -212,7 +212,7 @@ to receive data. For that, we need to include the appropriate header files. :: - #include "ddsc/dds.h" + #include "dds/dds.h" #include "HelloWorldData.h" The main starts with defining a few variables that will be used for @@ -341,7 +341,7 @@ to sent data. For that, we need to include the appropriate header files. :: - #include "ddsc/dds.h" + #include "dds/dds.h" #include "HelloWorldData.h" Just like with the diff --git a/src/examples/helloworld/publisher.c b/src/examples/helloworld/publisher.c index a7ff051..9b7527b 100644 --- a/src/examples/helloworld/publisher.c +++ b/src/examples/helloworld/publisher.c @@ -1,61 +1,66 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "HelloWorldData.h" #include #include int main (int argc, char ** argv) { - dds_entity_t participant; - dds_entity_t topic; - dds_entity_t writer; - dds_return_t ret; - HelloWorldData_Msg msg; - (void)argc; - (void)argv; + dds_entity_t participant; + dds_entity_t topic; + dds_entity_t writer; + dds_return_t rc; + HelloWorldData_Msg msg; + uint32_t status = 0; + (void)argc; + (void)argv; - /* Create a Participant. */ - participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Create a Participant. */ + participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); + if (participant < 0) + DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant)); - /* Create a Topic. */ - topic = dds_create_topic (participant, &HelloWorldData_Msg_desc, - "HelloWorldData_Msg", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Create a Topic. */ + topic = dds_create_topic ( + participant, &HelloWorldData_Msg_desc, "HelloWorldData_Msg", NULL, NULL); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); - /* Create a Writer. */ - writer = dds_create_writer (participant, topic, NULL, NULL); + /* Create a Writer. */ + writer = dds_create_writer (participant, topic, NULL, NULL); + if (writer < 0) + DDS_FATAL("dds_create_write: %s\n", dds_strretcode(-writer)); - printf("=== [Publisher] Waiting for a reader to be discovered ...\n"); + printf("=== [Publisher] Waiting for a reader to be discovered ...\n"); - ret = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS); + if (rc != DDS_RETCODE_OK) + DDS_FATAL("dds_set_status_mask: %s\n", dds_strretcode(-rc)); - while(true) - { - uint32_t status; - ret = dds_get_status_changes (writer, &status); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + while(!(status & DDS_PUBLICATION_MATCHED_STATUS)) + { + rc = dds_get_status_changes (writer, &status); + if (rc != DDS_RETCODE_OK) + DDS_FATAL("dds_get_status_changes: %s\n", dds_strretcode(-rc)); - if (status == DDS_PUBLICATION_MATCHED_STATUS) { - break; - } - /* Polling sleep. */ - dds_sleepfor (DDS_MSECS (20)); - } + /* Polling sleep. */ + dds_sleepfor (DDS_MSECS (20)); + } - /* Create a message to write. */ - msg.userID = 1; - msg.message = "Hello World"; + /* Create a message to write. */ + msg.userID = 1; + msg.message = "Hello World"; - printf ("=== [Publisher] Writing : "); - printf ("Message (%d, %s)\n", msg.userID, msg.message); + printf ("=== [Publisher] Writing : "); + printf ("Message (%d, %s)\n", msg.userID, msg.message); - ret = dds_write (writer, &msg); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_write (writer, &msg); + if (rc != DDS_RETCODE_OK) + DDS_FATAL("dds_write: %s\n", dds_strretcode(-rc)); - /* Deleting the participant will delete all its children recursively as well. */ - ret = dds_delete (participant); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Deleting the participant will delete all its children recursively as well. */ + rc = dds_delete (participant); + if (rc != DDS_RETCODE_OK) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc)); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/src/examples/helloworld/subscriber.c b/src/examples/helloworld/subscriber.c index 7775abb..bf4c0f4 100644 --- a/src/examples/helloworld/subscriber.c +++ b/src/examples/helloworld/subscriber.c @@ -1,4 +1,4 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "HelloWorldData.h" #include #include @@ -9,69 +9,74 @@ int main (int argc, char ** argv) { - dds_entity_t participant; - dds_entity_t topic; - dds_entity_t reader; - HelloWorldData_Msg *msg; - void *samples[MAX_SAMPLES]; - dds_sample_info_t infos[MAX_SAMPLES]; - dds_return_t ret; - dds_qos_t *qos; - (void)argc; - (void)argv; + dds_entity_t participant; + dds_entity_t topic; + dds_entity_t reader; + HelloWorldData_Msg *msg; + void *samples[MAX_SAMPLES]; + dds_sample_info_t infos[MAX_SAMPLES]; + dds_return_t rc; + dds_qos_t *qos; + (void)argc; + (void)argv; - /* Create a Participant. */ - participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Create a Participant. */ + participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); + if (participant < 0) + DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant)); - /* Create a Topic. */ - topic = dds_create_topic (participant, &HelloWorldData_Msg_desc, - "HelloWorldData_Msg", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Create a Topic. */ + topic = dds_create_topic ( + participant, &HelloWorldData_Msg_desc, "HelloWorldData_Msg", NULL, NULL); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); - /* Create a reliable Reader. */ - qos = dds_create_qos (); - dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10)); - reader = dds_create_reader (participant, topic, qos, NULL); - DDS_ERR_CHECK (reader, DDS_CHECK_REPORT | DDS_CHECK_EXIT); - dds_delete_qos(qos); + /* Create a reliable Reader. */ + qos = dds_create_qos (); + dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10)); + reader = dds_create_reader (participant, topic, qos, NULL); + if (reader < 0) + DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-reader)); + dds_delete_qos(qos); - printf ("\n=== [Subscriber] Waiting for a sample ...\n"); + printf ("\n=== [Subscriber] Waiting for a sample ...\n"); - /* Initialize sample buffer, by pointing the void pointer within - * the buffer array to a valid sample memory location. */ - samples[0] = HelloWorldData_Msg__alloc (); + /* Initialize sample buffer, by pointing the void pointer within + * the buffer array to a valid sample memory location. */ + samples[0] = HelloWorldData_Msg__alloc (); - /* Poll until data has been read. */ - while (true) + /* Poll until data has been read. */ + while (true) + { + /* Do the actual read. + * The return value contains the number of read samples. */ + rc = dds_read (reader, samples, infos, MAX_SAMPLES, MAX_SAMPLES); + if (rc < 0) + DDS_FATAL("dds_read: %s\n", dds_strretcode(-rc)); + + /* Check if we read some data and it is valid. */ + if ((rc > 0) && (infos[0].valid_data)) { - /* Do the actual read. - * The return value contains the number of read samples. */ - ret = dds_read (reader, samples, infos, MAX_SAMPLES, MAX_SAMPLES); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); - - /* Check if we read some data and it is valid. */ - if ((ret > 0) && (infos[0].valid_data)) - { - /* Print Message. */ - msg = (HelloWorldData_Msg*) samples[0]; - printf ("=== [Subscriber] Received : "); - printf ("Message (%d, %s)\n", msg->userID, msg->message); - break; - } - else - { - /* Polling sleep. */ - dds_sleepfor (DDS_MSECS (20)); - } + /* Print Message. */ + msg = (HelloWorldData_Msg*) samples[0]; + printf ("=== [Subscriber] Received : "); + printf ("Message (%d, %s)\n", msg->userID, msg->message); + break; } + else + { + /* Polling sleep. */ + dds_sleepfor (DDS_MSECS (20)); + } + } - /* Free the data location. */ - HelloWorldData_Msg_free (samples[0], DDS_FREE_ALL); + /* Free the data location. */ + HelloWorldData_Msg_free (samples[0], DDS_FREE_ALL); - /* Deleting the participant will delete all its children recursively as well. */ - ret = dds_delete (participant); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + /* Deleting the participant will delete all its children recursively as well. */ + rc = dds_delete (participant); + if (rc != DDS_RETCODE_OK) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc)); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } diff --git a/src/examples/roundtrip/ping.c b/src/examples/roundtrip/ping.c index 2caff20..32ca63c 100644 --- a/src/examples/roundtrip/ping.c +++ b/src/examples/roundtrip/ping.c @@ -1,4 +1,4 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" #include #include @@ -158,7 +158,8 @@ static void data_available(dds_entity_t rd, void *arg) /* Take sample and check that it is valid */ preTakeTime = dds_time (); status = dds_take (rd, samples, info, MAX_SAMPLES, MAX_SAMPLES); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_take: %s\n", dds_strretcode(-status)); postTakeTime = dds_time (); /* Update stats */ @@ -203,7 +204,8 @@ static void data_available(dds_entity_t rd, void *arg) preWriteTime = dds_time(); status = dds_write_ts (writer, &pub_data, preWriteTime); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_write_ts: %s\n", dds_strretcode(-status)); postWriteTime = dds_time(); } @@ -270,7 +272,8 @@ int main (int argc, char *argv[]) } participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (participant < 0) + DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant)); if (use_listener) { @@ -292,7 +295,8 @@ int main (int argc, char *argv[]) pub_data.payload._release = true; pub_data.payload._maximum = 0; status = dds_writedispose (writer, &pub_data); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_writedispose: %s\n", dds_strretcode(-status)); dds_sleepfor (DDS_SECS (1)); goto done; } @@ -337,11 +341,14 @@ int main (int argc, char *argv[]) while (!dds_triggered (waitSet) && difference < DDS_SECS(5)) { status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status)); + if (status > 0 && listener == NULL) /* data */ { status = dds_take (reader, samples, info, MAX_SAMPLES, MAX_SAMPLES); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_take: %s\n", dds_strretcode(-status)); } time = dds_time (); @@ -365,12 +372,14 @@ int main (int argc, char *argv[]) /* Write a sample that pong can send back */ preWriteTime = dds_time (); status = dds_write_ts (writer, &pub_data, preWriteTime); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_write_ts: %s\n", dds_strretcode(-status)); postWriteTime = dds_time (); for (i = 0; !dds_triggered (waitSet) && (!numSamples || i < numSamples); i++) { status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status)); if (status != 0 && listener == NULL) { data_available(reader, NULL); } @@ -439,14 +448,16 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t /* A DDS_Topic is created for our sample type on the domain participant. */ topic = dds_create_topic (participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); /* A DDS_Publisher is created on the domain participant. */ pubQos = dds_create_qos (); dds_qset_partition (pubQos, 1, pubPartitions); publisher = dds_create_publisher (participant, pubQos, NULL); - DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (publisher < 0) + DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher)); dds_delete_qos (pubQos); /* A DDS_DataWriter is created on the Publisher & Topic with a modified Qos. */ @@ -454,7 +465,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t dds_qset_reliability (dwQos, DDS_RELIABILITY_RELIABLE, DDS_SECS (10)); dds_qset_writer_data_lifecycle (dwQos, false); *wr = dds_create_writer (publisher, topic, dwQos, NULL); - DDS_ERR_CHECK (*wr, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*wr < 0) + DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*wr)); dds_delete_qos (dwQos); /* A DDS_Subscriber is created on the domain participant. */ @@ -463,25 +475,29 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t dds_qset_partition (subQos, 1, subPartitions); subscriber = dds_create_subscriber (participant, subQos, NULL); - DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (subscriber < 0) + DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber)); dds_delete_qos (subQos); /* A DDS_DataReader is created on the Subscriber & Topic with a modified QoS. */ drQos = dds_create_qos (); dds_qset_reliability (drQos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10)); *rd = dds_create_reader (subscriber, topic, drQos, listener); - DDS_ERR_CHECK (*rd, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*rd < 0) + DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*rd)); dds_delete_qos (drQos); waitSet = dds_create_waitset (participant); if (listener == NULL) { *rdcond = dds_create_readcondition (*rd, DDS_ANY_STATE); status = dds_waitset_attach (waitSet, *rdcond, *rd); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); } else { *rdcond = 0; } status = dds_waitset_attach (waitSet, waitSet, waitSet); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); return participant; } @@ -490,5 +506,6 @@ static void finalize_dds(dds_entity_t ppant) { dds_return_t status; status = dds_delete (ppant); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status)); } diff --git a/src/examples/roundtrip/pong.c b/src/examples/roundtrip/pong.c index 985e9d8..ef692f5 100644 --- a/src/examples/roundtrip/pong.c +++ b/src/examples/roundtrip/pong.c @@ -1,4 +1,4 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "RoundTrip.h" #include #include @@ -42,7 +42,8 @@ static void data_available(dds_entity_t rd, void *arg) int status, samplecount; (void)arg; samplecount = dds_take (rd, samples, info, MAX_SAMPLES, MAX_SAMPLES); - DDS_ERR_CHECK (samplecount, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (samplecount < 0) + DDS_FATAL("dds_take: %s\n", dds_strretcode(-samplecount)); for (int j = 0; !dds_triggered (waitSet) && j < samplecount; j++) { /* If writer has been disposed terminate pong */ @@ -58,7 +59,8 @@ static void data_available(dds_entity_t rd, void *arg) /* If sample is valid, send it back to ping */ RoundTripModule_DataType * valid_sample = &data[j]; status = dds_write_ts (writer, valid_sample, info[j].source_timestamp); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_write_ts: %s\n", -status); } } } @@ -101,7 +103,8 @@ int main (int argc, char *argv[]) } participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (participant < 0) + DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant)); if (use_listener) { @@ -116,7 +119,8 @@ int main (int argc, char *argv[]) /* Wait for a sample from ping */ status = dds_waitset_wait (waitSet, wsresults, wsresultsize, waitTimeout); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status)); /* Take samples */ if (listener == NULL) { @@ -140,7 +144,8 @@ static void finalize_dds(dds_entity_t pp, RoundTripModule_DataType xs[MAX_SAMPLE { dds_return_t status; status = dds_delete (pp); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status)); for (unsigned int i = 0; i < MAX_SAMPLES; i++) { RoundTripModule_DataType_free (&xs[i], DDS_FREE_CONTENTS); @@ -160,7 +165,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t /* A DDS Topic is created for our sample type on the domain participant. */ topic = dds_create_topic (participant, &RoundTripModule_DataType_desc, "RoundTrip", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); /* A DDS Publisher is created on the domain participant. */ @@ -168,7 +174,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t dds_qset_partition (qos, 1, pubPartitions); publisher = dds_create_publisher (participant, qos, NULL); - DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (publisher < 0) + DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher)); dds_delete_qos (qos); /* A DDS DataWriter is created on the Publisher & Topic with a modififed Qos. */ @@ -177,7 +184,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10)); dds_qset_writer_data_lifecycle (qos, false); *wr = dds_create_writer (publisher, topic, qos, NULL); - DDS_ERR_CHECK (*wr, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*wr < 0) + DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*wr)); dds_delete_qos (qos); /* A DDS Subscriber is created on the domain participant. */ @@ -186,7 +194,8 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t dds_qset_partition (qos, 1, subPartitions); subscriber = dds_create_subscriber (participant, qos, NULL); - DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (subscriber < 0) + DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber)); dds_delete_qos (qos); /* A DDS DataReader is created on the Subscriber & Topic with a modified QoS. */ @@ -194,19 +203,22 @@ static dds_entity_t prepare_dds(dds_entity_t *wr, dds_entity_t *rd, dds_entity_t qos = dds_create_qos (); dds_qset_reliability (qos, DDS_RELIABILITY_RELIABLE, DDS_SECS(10)); *rd = dds_create_reader (subscriber, topic, qos, rdlist); - DDS_ERR_CHECK (*rd, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*rd < 0) + DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*rd)); dds_delete_qos (qos); waitSet = dds_create_waitset (participant); if (rdlist == NULL) { *rdcond = dds_create_readcondition (*rd, DDS_ANY_STATE); status = dds_waitset_attach (waitSet, *rdcond, *rd); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); } else { *rdcond = 0; } status = dds_waitset_attach (waitSet, waitSet, waitSet); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); printf ("Waiting for samples from ping to send back...\n"); fflush (stdout); diff --git a/src/examples/throughput/publisher.c b/src/examples/throughput/publisher.c index 0f7cce8..69cbc09 100644 --- a/src/examples/throughput/publisher.c +++ b/src/examples/throughput/publisher.c @@ -1,4 +1,4 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "Throughput.h" #include #include @@ -44,6 +44,7 @@ int main (int argc, char **argv) char * partitionName = "Throughput example"; dds_entity_t participant; dds_entity_t writer; + dds_return_t rc; ThroughputModule_DataType sample; #if !defined(_WIN32) @@ -59,7 +60,9 @@ int main (int argc, char **argv) /* Wait until have a reader */ if (wait_for_reader(writer, participant) == 0) { printf ("=== [Publisher] Did not discover a reader.\n"); - DDS_ERR_CHECK (dds_delete (participant), DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_delete (participant); + if (rc < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc)); return EXIT_FAILURE; } @@ -143,18 +146,21 @@ static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName) /* A domain participant is created for the default domain. */ participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (participant < 0) + DDS_FATAL("dds_create_participant: %s\n", dds_strretcode(-participant)); /* A topic is created for our sample type on the domain participant. */ topic = dds_create_topic (participant, &ThroughputModule_DataType_desc, "Throughput", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); /* A publisher is created on the domain participant. */ pubQos = dds_create_qos (); pubParts[0] = partitionName; dds_qset_partition (pubQos, 1, pubParts); publisher = dds_create_publisher (participant, pubQos, NULL); - DDS_ERR_CHECK (publisher, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (publisher < 0) + DDS_FATAL("dds_create_publisher: %s\n", dds_strretcode(-publisher)); dds_delete_qos (pubQos); /* A DataWriter is created on the publisher. */ @@ -163,7 +169,8 @@ static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName) dds_qset_history (dwQos, DDS_HISTORY_KEEP_ALL, 0); dds_qset_resource_limits (dwQos, MAX_SAMPLES, DDS_LENGTH_UNLIMITED, DDS_LENGTH_UNLIMITED); *writer = dds_create_writer (publisher, topic, dwQos, NULL); - DDS_ERR_CHECK (*writer, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*writer < 0) + DDS_FATAL("dds_create_writer: %s\n", dds_strretcode(-*writer)); dds_delete_qos (dwQos); /* Enable write batching */ @@ -176,22 +183,26 @@ static dds_return_t wait_for_reader(dds_entity_t writer, dds_entity_t participan { printf ("\n=== [Publisher] Waiting for a reader ...\n"); - dds_return_t ret; + dds_return_t rc; dds_entity_t waitset; - ret = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS); + if (rc < 0) + DDS_FATAL("dds_set_status_mask: %s\n", dds_strretcode(-rc)); waitset = dds_create_waitset(participant); - DDS_ERR_CHECK (waitset, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (waitset < 0) + DDS_FATAL("dds_create_waitset: %s\n", dds_strretcode(-waitset)); - ret = dds_waitset_attach(waitset, writer, (dds_attach_t)NULL); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_waitset_attach(waitset, writer, (dds_attach_t)NULL); + if (rc < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-rc)); - ret = dds_waitset_wait(waitset, NULL, 0, DDS_SECS(30)); - DDS_ERR_CHECK (ret, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + rc = dds_waitset_wait(waitset, NULL, 0, DDS_SECS(30)); + if (rc < 0) + DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-rc)); - return ret; + return rc; } static void start_writing( @@ -225,9 +236,12 @@ static void start_writing( { timedOut = true; } + else if (status < 0) + { + DDS_FATAL("dds_write: %s\n", dds_strretcode(-status)); + } else { - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); sample->count++; burstCount++; } @@ -277,12 +291,11 @@ static void start_writing( static void finalize_dds(dds_entity_t participant, dds_entity_t writer, ThroughputModule_DataType sample) { dds_return_t status = dds_dispose (writer, &sample); - if (dds_err_nr (status) != DDS_RETCODE_TIMEOUT) - { - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); - } + if (dds_err_nr (status) != DDS_RETCODE_TIMEOUT && status < 0) + DDS_FATAL("dds_dispose: %s\n", dds_strretcode(-status)); dds_free (sample.payload._buffer); status = dds_delete (participant); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status)); } diff --git a/src/examples/throughput/subscriber.c b/src/examples/throughput/subscriber.c index 2f43f49..f57fed7 100644 --- a/src/examples/throughput/subscriber.c +++ b/src/examples/throughput/subscriber.c @@ -1,4 +1,4 @@ -#include "ddsc/dds.h" +#include "dds/dds.h" #include "Throughput.h" #include #include @@ -168,7 +168,8 @@ static int do_take (dds_entity_t reader) /* Take samples and iterate through them */ samples_received = dds_take (reader, samples, info, MAX_SAMPLES, MAX_SAMPLES); - DDS_ERR_CHECK (samples_received, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (samples_received < 0) + DDS_FATAL("dds_take: %s\n", dds_strretcode(-samples_received)); for (int i = 0; !done && i < samples_received; i++) { @@ -256,7 +257,8 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles) else { status = dds_waitset_wait (waitSet, wsresults, sizeof(wsresults)/sizeof(wsresults[0]), DDS_MSECS(100)); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_wait: %s\n", dds_strretcode(-status)); } if (pollingDelay >= 0) @@ -316,19 +318,22 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName) /* A Participant is created for the default domain. */ participant = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL); - DDS_ERR_CHECK (participant, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (participant < 0) + DDS_FATAL("dds_create_particpant: %s\n", dds_strretcode(-participant)); /* A Topic is created for our sample type on the domain participant. */ topic = dds_create_topic (participant, &ThroughputModule_DataType_desc, "Throughput", NULL, NULL); - DDS_ERR_CHECK (topic, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (topic < 0) + DDS_FATAL("dds_create_topic: %s\n", dds_strretcode(-topic)); /* A Subscriber is created on the domain participant. */ subParts[0] = partitionName; dds_qset_partition (subQos, 1, subParts); subscriber = dds_create_subscriber (participant, subQos, NULL); - DDS_ERR_CHECK (subscriber, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (subscriber < 0) + DDS_FATAL("dds_create_subscriber: %s\n", dds_strretcode(-subscriber)); dds_delete_qos (subQos); /* A Reader is created on the Subscriber & Topic with a modified Qos. */ @@ -342,10 +347,12 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName) /* A Read Condition is created which is triggered when data is available to read */ waitSet = dds_create_waitset (participant); - DDS_ERR_CHECK (waitSet, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (waitSet < 0) + DDS_FATAL("dds_create_waitset: %s\n", dds_strretcode(-waitSet)); status = dds_waitset_attach (waitSet, waitSet, waitSet); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); imap = HandleMap__alloc (); @@ -356,12 +363,14 @@ static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName) } *reader = dds_create_reader (subscriber, topic, drQos, pollingDelay < 0 ? rd_listener : NULL); - DDS_ERR_CHECK (*reader, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (*reader < 0) + DDS_FATAL("dds_create_reader: %s\n", dds_strretcode(-*reader)); if (pollingDelay == 0) { status = dds_waitset_attach (waitSet, *reader, *reader); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_attach: %s\n", dds_strretcode(-status)); } dds_delete_qos (drQos); @@ -380,9 +389,12 @@ static void finalize_dds(dds_entity_t participant) } status = dds_waitset_detach (waitSet, waitSet); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_waitset_detach: %s\n", dds_strretcode(-status)); status = dds_delete (waitSet); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status)); status = dds_delete (participant); - DDS_ERR_CHECK (status, DDS_CHECK_REPORT | DDS_CHECK_EXIT); + if (status < 0) + DDS_FATAL("dds_delete: %s\n", dds_strretcode(-status)); } diff --git a/src/idlc/src/org/eclipse/cyclonedds/templates/h/file.st b/src/idlc/src/org/eclipse/cyclonedds/templates/h/file.st index 64cbaf3..06d8074 100644 --- a/src/idlc/src/org/eclipse/cyclonedds/templates/h/file.st +++ b/src/idlc/src/org/eclipse/cyclonedds/templates/h/file.st @@ -11,7 +11,7 @@ file (banner, name, nameupper, declarations, dll, includes) ::= << -#include "ddsc/dds_public_impl.h" +#include "dds/ddsc/dds_public_impl.h" .h"}; separator="\n"> #ifndef _DDSL__H_ diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt deleted file mode 100644 index 83e1afd..0000000 --- a/src/os/CMakeLists.txt +++ /dev/null @@ -1,139 +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 -# -include(CheckCSourceCompiles) -include(CheckLibraryExists) -include(CheckTypeSize) -include(GenerateExportHeader) -include(TestBigEndian) - -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) - -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) - -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 ${sources}) - -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -find_package(Threads REQUIRED) -target_link_libraries(OSAPI INTERFACE Threads::Threads) -set_property(TARGET OSAPI PROPERTY POSITION_INDEPENDENT_CODE TRUE) - -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) - 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_RT) - if(HAVE_CLOCK_GETTIME_RT) - set(HAVE_CLOCK_GETTIME "${HAVE_CLOCK_GETTIME_RT}") - 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) -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_include_directories( - OSAPI PUBLIC - "$" - "$" - "$" - "$" - "$") - -if(BUILD_TESTING) - add_subdirectory(tests) -endif() - -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/os/${system_name}/os_platform_public.h") - set(os_platform_public_h "${CMAKE_CURRENT_SOURCE_DIR}/include/os/${system_name}/os_platform_public.h") -else() - set(os_platform_public_h "${CMAKE_CURRENT_SOURCE_DIR}/include/os/posix/os_platform_public.h") -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" - "${os_platform_public_h}" - DESTINATION - "${CMAKE_INSTALL_INCLUDEDIR}/ddsc/os" - COMPONENT - dev) - diff --git a/src/os/cmake/os_project.h.in b/src/os/cmake/os_project.h.in deleted file mode 100644 index c59dc09..0000000 --- a/src/os/cmake/os_project.h.in +++ /dev/null @@ -1,38 +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 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@ -#define OS_VERSION_PATCH @CycloneDDS_VERSION_PATCH@ -#define OS_VERSION_TWEAK @CycloneDDS_VERSION_TWEAK@ -#define OS_PROJECT_NAME_NOSPACE_CAPS "@CMAKE_PROJECT_NAME_CAPS@" -#define OS_PROJECT_NAME_NOSPACE_SMALL "@CMAKE_PROJECT_NAME_SMALL@" -#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 */ diff --git a/src/os/include/os/darwin/os_platform.h b/src/os/include/os/darwin/os_platform.h deleted file mode 100644 index 7e460ae..0000000 --- a/src/os/include/os/darwin/os_platform.h +++ /dev/null @@ -1,48 +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 OS_PLATFORM_H -#define OS_PLATFORM_H - -#include -#include -#include -#include -#include -#include -#include - -#define PRIdSIZE "zd" -#define PRIuSIZE "zu" -#define PRIxSIZE "zx" - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_DARWIN 1 -#define OS_HAVE_GETRUSAGE 1 - - typedef double os_timeReal; - typedef int os_timeSec; - typedef pid_t os_procId; - #define PRIprocId "d" - -#include "os/posix/os_platform_socket.h" -#include "os/posix/os_platform_sync.h" -#include "os/posix/os_platform_thread.h" -#include "os/posix/os_platform_stdlib.h" - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/linux/os_platform.h b/src/os/include/os/linux/os_platform.h deleted file mode 100644 index 13809d4..0000000 --- a/src/os/include/os/linux/os_platform.h +++ /dev/null @@ -1,48 +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 OS_PLATFORM_H -#define OS_PLATFORM_H - -#include -#include -#include -#include -#include -#include -#include - -#define PRIdSIZE "zd" -#define PRIuSIZE "zu" -#define PRIxSIZE "zx" - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_LINUX 1 -#define OS_HAVE_GETRUSAGE 1 - - typedef double os_timeReal; - typedef int os_timeSec; - typedef pid_t os_procId; - #define PRIprocId "d" - -#include "os/posix/os_platform_socket.h" -#include "os/posix/os_platform_sync.h" -#include "os/posix/os_platform_thread.h" -#include "os/posix/os_platform_stdlib.h" - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/os.h b/src/os/include/os/os.h deleted file mode 100644 index af68180..0000000 --- a/src/os/include/os/os.h +++ /dev/null @@ -1,50 +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 OS_H -#define OS_H - -#include "os/os_project.h" -#include "os/osapi_export.h" -#include "os_public.h" - -#if __linux__ == 1 -#include "linux/os_platform.h" -#elif defined(__VXWORKS__) -#include "vxworks/os_platform.h" -#elif __sun == 1 -#include "solaris/os_platform.h" -#elif defined(_MSC_VER) -#include "windows/os_platform.h" -#elif defined __APPLE__ -#include "darwin/os_platform.h" -#else -#error "Platform missing from os.h list" -#endif - -#include "os_defs.h" -#include "os_thread.h" -#include "os_sync.h" -#include "os_time.h" -#include "os_atomics.h" -#include "os_socket.h" -#include "os_heap.h" -#include "os_stdlib.h" -#include "os_init.h" -#include "os_process.h" -#include "os_errno.h" -#include "os_iter.h" -#include "os_log.h" -#include "os_strlcpy.h" -#include "os_random.h" -#include "os_rusage.h" - -#endif diff --git a/src/os/include/os/os_atomics.h b/src/os/include/os/os_atomics.h deleted file mode 100644 index 5169676..0000000 --- a/src/os/include/os/os_atomics.h +++ /dev/null @@ -1,58 +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 OS_ATOMICS_H -#define OS_ATOMICS_H - -#include -#include - -#include "os/os_defs.h" - -#if defined (__cplusplus) -extern "C" { -#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 */ -#include "os_atomics_win32.h" -#endif - -#if ! OS_ATOMIC_SUPPORT && defined __sun -#include "os_atomics_solaris.h" -#endif - -#if ! OS_ATOMIC_SUPPORT -#error "No support for atomic operations on this platform" -#endif - -/* LIFO */ -#if OS_ATOMIC_LIFO_SUPPORT -typedef struct os_atomic_lifo { - os_atomic_uintptr2_t aba_head; -} os_atomic_lifo_t; - -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 - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_ATOMICS_H */ diff --git a/src/os/include/os/os_atomics_gcc.h b/src/os/include/os/os_atomics_gcc.h deleted file mode 100644 index 8de1e41..0000000 --- a/src/os/include/os/os_atomics_gcc.h +++ /dev/null @@ -1,294 +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 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40100 - -/* I don't quite know how to check whether 64-bit operations are - supported, but my guess is that the size of a pointer is a fairly - good indication. Define OS_ATOMIC_ATOMIC64_SUPPORT beforehand to override - this. (Obviously, I'm also assuming that uintptr_t is an unsigned - integer exactly as wide as a pointer, even though it may be - wider.) */ -#ifndef OS_ATOMIC64_SUPPORT -#ifdef OS_64BIT -#define OS_ATOMIC64_SUPPORT 1 -#else -#define OS_ATOMIC64_SUPPORT 0 -#endif -#endif - -#if ( OS_ATOMIC64_SUPPORT && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || \ - (!OS_ATOMIC64_SUPPORT && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) - -#define OS_ATOMIC_LIFO_SUPPORT 1 - -#if OS_ATOMIC64_SUPPORT -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 */ - -inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; } -#if OS_ATOMIC64_SUPPORT -inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; } -#endif -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); } - -inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; } -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; } -#endif -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 */ - -inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) { - __sync_fetch_and_add (&x->v, 1); -} -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) { - __sync_fetch_and_add (&x->v, 1); -} -#endif -inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) { - __sync_fetch_and_add (&x->v, 1); -} -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 -inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) { - return __sync_add_and_fetch (&x->v, 1); -} -#endif -inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) { - return __sync_add_and_fetch (&x->v, 1); -} - -/* DEC */ - -inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) { - __sync_fetch_and_sub (&x->v, 1); -} -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) { - __sync_fetch_and_sub (&x->v, 1); -} -#endif -inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) { - __sync_fetch_and_sub (&x->v, 1); -} -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 -inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) { - return __sync_sub_and_fetch (&x->v, 1); -} -#endif -inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) { - return __sync_sub_and_fetch (&x->v, 1); -} -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 -inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) { - return __sync_fetch_and_sub (&x->v, 1); -} -#endif -inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) { - return __sync_fetch_and_sub (&x->v, 1); -} - -/* ADD */ - -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 -inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) { - __sync_fetch_and_add (&x->v, v); -} -#endif -inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - __sync_fetch_and_add (&x->v, 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); -} -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 -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 -inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) { - return __sync_add_and_fetch (&x->v, 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 */ - -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 -inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) { - __sync_fetch_and_sub (&x->v, v); -} -#endif -inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - __sync_fetch_and_sub (&x->v, 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); -} -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 -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 -inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v) { - return __sync_sub_and_fetch (&x->v, 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 */ - -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 -inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) { - __sync_fetch_and_and (&x->v, v); -} -#endif -inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - __sync_fetch_and_and (&x->v, 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 -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 -inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) { - return __sync_fetch_and_and (&x->v, 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 -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 -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 */ - -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 -inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) { - __sync_fetch_and_or (&x->v, v); -} -#endif -inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - __sync_fetch_and_or (&x->v, 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 -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 -inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v) { - return __sync_fetch_and_or (&x->v, 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 -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 -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 */ - -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 -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 -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); -} -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 */ - -inline void os_atomic_fence (void) { - __sync_synchronize (); -} -inline void os_atomic_fence_ldld (void) { -#if !(defined __i386__ || defined __x86_64__ || defined _M_IX86 || defined _M_X64) - __sync_synchronize (); -#endif -} -inline void os_atomic_fence_acq (void) { - os_atomic_fence (); -} -inline void os_atomic_fence_rel (void) { - os_atomic_fence (); -} - -#define OS_ATOMIC_SUPPORT 1 -#endif diff --git a/src/os/include/os/os_atomics_solaris.h b/src/os/include/os/os_atomics_solaris.h deleted file mode 100644 index daeda50..0000000 --- a/src/os/include/os/os_atomics_solaris.h +++ /dev/null @@ -1,242 +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 - */ -#include - -#define OS_ATOMIC64_SUPPORT 1 - -/* LD, ST */ - -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); } - -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 */ - -inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) { - atomic_inc_32 (&x->v); -} -inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) { - atomic_inc_64 (&x->v); -} -inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) { - atomic_inc_ulong (&x->v); -} -inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) { - return atomic_inc_32_nv (&x->v); -} -inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) { - return atomic_inc_64_nv (&x->v); -} -inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) { - return atomic_inc_ulong_nv (&x->v); -} - -/* DEC */ - -inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) { - atomic_dec_32 (&x->v); -} -inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) { - atomic_dec_64 (&x->v); -} -inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) { - atomic_dec_ulong (&x->v); -} -inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) { - return atomic_dec_32_nv (&x->v); -} -inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) { - return atomic_dec_64_nv (&x->v); -} -inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) { - return atomic_dec_ulong_nv (&x->v); -} -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; -} -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; -} -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; -} - -/* ADD */ - -inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) { - atomic_add_32 (&x->v, v); -} -inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) { - atomic_add_64 (&x->v, v); -} -inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - atomic_add_long (&x->v, v); -} -inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) { - atomic_add_ptr (&x->v, 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); -} -inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) { - return atomic_add_64_nv (&x->v, 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); -} -inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) { - return atomic_add_ptr_nv (&x->v, v); -} - -/* SUB */ - -inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v) { - atomic_add_32 (&x->v, -v); -} -inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v) { - atomic_add_64 (&x->v, -v); -} -inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - atomic_add_long (&x->v, -v); -} -inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v) { - atomic_add_ptr (&x->v, -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); -} -inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v) { - return atomic_add_64_nv (&x->v, -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); -} -inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v) { - return atomic_add_ptr_nv (&x->v, -v); -} - -/* AND */ - -inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v) { - atomic_and_32 (&x->v, v); -} -inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) { - atomic_and_64 (&x->v, v); -} -inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - atomic_and_ulong (&x->v, 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; -} -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; -} -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; -} -inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v) { - return atomic_and_32_nv (&x->v, 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); -} -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 */ - -inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v) { - atomic_or_32 (&x->v, v); -} -inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) { - atomic_or_64 (&x->v, v); -} -inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - atomic_or_ulong (&x->v, 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; -} -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; -} -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; -} -inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v) { - return atomic_or_32_nv (&x->v, 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); -} -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 */ - -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; -} -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; -} -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; -} -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 */ - -inline void os_atomic_fence (void) { - membar_exit (); - membar_enter (); -} -inline void os_atomic_fence_ldld (void) { - membar_enter (); -} -inline void os_atomic_fence_acq (void) { - membar_enter (); -} -inline void os_atomic_fence_rel (void) { - membar_exit (); -} - -#define OS_ATOMIC_SUPPORT 1 diff --git a/src/os/include/os/os_atomics_win32.h b/src/os/include/os/os_atomics_win32.h deleted file mode 100644 index bdff0e2..0000000 --- a/src/os/include/os/os_atomics_win32.h +++ /dev/null @@ -1,429 +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 - */ -/* x86 has supported 64-bit CAS for a long time, so Windows ought to - provide all the interlocked operations for 64-bit operands on x86 - platforms, but it doesn't. */ - -#if defined OS_64BIT -#define OS_ATOMIC64_SUPPORT 1 -#else -#define OS_ATOMIC64_SUPPORT 0 -#endif - -#if defined OS_64BIT -#define OS_ATOMIC_PTROP(name) name##64 -#else -#define OS_ATOMIC_PTROP(name) name -#endif - -/* 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 -#define OS_ATOMIC_INTERLOCKED_AND _InterlockedAnd -#define OS_ATOMIC_INTERLOCKED_OR _InterlockedOr -#define OS_ATOMIC_INTERLOCKED_AND64 _InterlockedAnd64 -#define OS_ATOMIC_INTERLOCKED_OR64 _InterlockedOr64 -#else -#define OS_ATOMIC_INTERLOCKED_AND InterlockedAnd -#define OS_ATOMIC_INTERLOCKED_OR InterlockedOr -#define OS_ATOMIC_INTERLOCKED_AND64 InterlockedAnd64 -#define OS_ATOMIC_INTERLOCKED_OR64 InterlockedOr64 -#endif -#endif - -/* LD, ST */ - -inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x) { return x->v; } -#if OS_ATOMIC64_SUPPORT -inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x) { return x->v; } -#endif -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); } - -inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v) { x->v = v; } -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v) { x->v = v; } -#endif -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 */ - -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 -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 -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; -} -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 */ - -inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x) { - InterlockedIncrement (&x->v); -} -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x) { - InterlockedIncrement64 (&x->v); -} -#endif -inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x) { - OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v); -} -inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x) { - return InterlockedIncrement (&x->v); -} -#if OS_ATOMIC64_SUPPORT -inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x) { - return InterlockedIncrement64 (&x->v); -} -#endif -inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x) { - return OS_ATOMIC_PTROP (InterlockedIncrement) (&x->v); -} - -/* DEC */ - -inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x) { - InterlockedDecrement (&x->v); -} -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x) { - InterlockedDecrement64 (&x->v); -} -#endif -inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x) { - OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v); -} -inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x) { - return InterlockedDecrement (&x->v); -} -#if OS_ATOMIC64_SUPPORT -inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x) { - return InterlockedDecrement64 (&x->v); -} -#endif -inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x) { - return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v); -} -inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x) { - return InterlockedDecrement (&x->v) + 1; -} -#if OS_ATOMIC64_SUPPORT -inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x) { - return InterlockedDecrement64 (&x->v) + 1; -} -#endif -inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x) { - return OS_ATOMIC_PTROP (InterlockedDecrement) (&x->v) + 1; -} - -/* ADD */ - -inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v) { - InterlockedExchangeAdd (&x->v, v); -} -#if OS_ATOMIC64_SUPPORT -inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v) { - InterlockedExchangeAdd64 (&x->v, v); -} -#endif -inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - OS_ATOMIC_PTROP (InterlockedExchangeAdd) (&x->v, 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); -} -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 -inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v) { - return InterlockedExchangeAdd64 (&x->v, v) + v; -} -#endif -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; -} -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 */ - -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) - InterlockedExchangeAdd (&x->v, -v); -#pragma warning (pop) -} -#if OS_ATOMIC64_SUPPORT -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) - InterlockedExchangeAdd64 (&x->v, -v); -#pragma warning (pop) -} -#endif -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) -} -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); -} -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) - return InterlockedExchangeAdd (&x->v, -v) - v; -#pragma warning (pop) -} -#if OS_ATOMIC64_SUPPORT -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) - return InterlockedExchangeAdd64 (&x->v, -v) - v; -#pragma warning (pop) -} -#endif -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) -} -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 */ - -#if defined OS_ATOMIC_INTERLOCKED_AND - -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 -inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) { - InterlockedAnd64 (&x->v, v); -} -#endif -inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_AND) (&x->v, 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 -inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v) { - return InterlockedAnd64 (&x->v, v); -} -#endif -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); -} -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 -inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v) { - return InterlockedAnd64 (&x->v, v) & v; -} -#endif -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 */ - -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 -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 -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; -} -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 -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 -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; -} -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 -inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v) { - (void) os_atomic_and64_nv (x, v); -} -#endif -inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - (void) os_atomic_andptr_nv (x, v); -} - -#endif - -/* OR */ - -#if defined OS_ATOMIC_INTERLOCKED_OR - -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 -inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) { - InterlockedOr64 (&x->v, v); -} -#endif -inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - OS_ATOMIC_PTROP (OS_ATOMIC_INTERLOCKED_OR) (&x->v, 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 -inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v) { - return InterlockedOr64 (&x->v, v); -} -#endif -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); -} -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 -inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v) { - return InterlockedOr64 (&x->v, v) | v; -} -#endif -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 */ - -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 -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 -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; -} -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 -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 -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; -} -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 -inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v) { - (void) os_atomic_or64_nv (x, v); -} -#endif -inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v) { - (void) os_atomic_orptr_nv (x, v); -} - -#endif - -/* FENCES */ - -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. */ -#pragma warning (push) -#pragma warning (disable: 28113) - volatile LONG tmp = 0; - InterlockedExchange (&tmp, 0); -#pragma warning (pop) -} -inline void os_atomic_fence_ldld (void) { -#if !(defined _M_IX86 || defined _M_X64) - os_atomic_fence (); -#endif -} -inline void os_atomic_fence_acq (void) { - os_atomic_fence (); -} -inline void os_atomic_fence_rel (void) { - os_atomic_fence (); -} - -#undef OS_ATOMIC_INTERLOCKED_AND -#undef OS_ATOMIC_INTERLOCKED_OR -#undef OS_ATOMIC_INTERLOCKED_AND64 -#undef OS_ATOMIC_INTERLOCKED_OR64 - -#undef OS_ATOMIC_PTROP -#define OS_ATOMIC_SUPPORT 1 diff --git a/src/os/include/os/os_decl_attributes.h b/src/os/include/os/os_decl_attributes.h deleted file mode 100644 index c2ea8cb..0000000 --- a/src/os/include/os/os_decl_attributes.h +++ /dev/null @@ -1,129 +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 OS_DECL_ATTRIBUTES_H -#define OS_DECL_ATTRIBUTES_H - -#define OS_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) - -#ifndef __has_attribute -# if defined __GNUC__ && !defined __clang__ -# define __has_attribute(x) 1 /* Compatibility with GCC compilers that don't have __has_attribute. */ -# else -# define __has_attribute(x) 0 /* Compatibility with compilers that don't have __has_attribute. */ -# endif -#endif - -#ifndef __attribute_malloc__ -# if __has_attribute(malloc) -# define __attribute_malloc__ __attribute__((__malloc__)) -# else -# define __attribute_malloc__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_unused__ -# if __has_attribute(unused) -# define __attribute_unused__ __attribute__((__unused__)) -# else -# define __attribute_unused__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_noreturn__ -# if __has_attribute(noreturn) -# define __attribute_noreturn__ __attribute__((__noreturn__)) -# else -# define __attribute_noreturn__ /* Ignore. */ -# endif -#endif - -#if defined FIX_FAULTY_ATTRIBUTE_NONNULL || defined __clang__ || OS_GNUC_VERSION >= 50200 -/* Some platforms have a faulty definition of the __nonnull macro where params - * are expanded within brackets, causing the parameters to be treated as a comma- - * expression. If FIX_FAULTY_ATTRIBUTE_NONNULL is defined, the macro is undeffed - * so our own definition will be used instead. */ -# undef __nonnull -#endif - -#ifndef __nonnull -# if __has_attribute(nonnull) -# define __nonnull(params) __attribute__((__nonnull__ params)) -# define __nonnull_all__ __attribute__((__nonnull__)) -# else -# define __nonnull(params) /* Ignore. */ -# define __nonnull_all__ /* Ignore. */ -# endif -#else -# define __nonnull_all__ __attribute__((__nonnull__)) -#endif - -#ifndef __attribute_returns_nonnull__ -# if __has_attribute(returns_nonnull) && (defined __clang__ || OS_GNUC_VERSION >= 40900) -# define __attribute_returns_nonnull__ __attribute__((__returns_nonnull__)) -# else -# define __attribute_returns_nonnull__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_alloc_size__ -/* Silence GCC <= V4.2.4, which reports that it has the attribute, but nags that it ignores it. */ -# if __has_attribute(alloc_size) && OS_GNUC_VERSION > 40204 -# define __attribute_alloc_size__(params) __attribute__ ((__alloc_size__ params)) -# else -# define __attribute_alloc_size__(params) /* Ignore. */ -# endif -#endif - -#ifndef __attribute_const__ -# if __has_attribute(const) -# define __attribute_const__ __attribute__ ((__const__)) -# else -# define __attribute_const__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_pure__ -# if __has_attribute(pure) -# define __attribute_pure__ __attribute__ ((__pure__)) -# else -# define __attribute_pure__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_format__ -# if __has_attribute(format) -# define __attribute_format__(params) __attribute__ ((__format__ params)) -# else -# define __attribute_format__(params) /* Ignore. */ -# endif -#endif - -#ifndef __attribute_warn_unused_result__ -# if __has_attribute(warn_unused_result) -# define __attribute_warn_unused_result__ __attribute__ ((__warn_unused_result__)) -# else -# define __attribute_warn_unused_result__ /* Ignore. */ -# endif -#endif - -#ifndef __attribute_assume_aligned__ -# if __has_attribute(assume_aligned) -# define __attribute_assume_aligned__(params) __attribute__ ((__assume_aligned__ params)) -# else -# define __attribute_assume_aligned__(params) /* Ignore. */ -# endif -#endif - -#include "os_decl_attributes_sal.h" - -#undef OS_GNUC_VERSION -#endif diff --git a/src/os/include/os/os_decl_attributes_sal.h b/src/os/include/os/os_decl_attributes_sal.h deleted file mode 100644 index 61fd35b..0000000 --- a/src/os/include/os/os_decl_attributes_sal.h +++ /dev/null @@ -1,2071 +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 OS_DECL_ATTRIBUTES_SAL_H -#define OS_DECL_ATTRIBUTES_SAL_H - -#if defined(_MSC_VER) -# include - /* SAL-like extension to signify that the following line isn't reached */ -# define _Noreturn_ __declspec(noreturn) _Analysis_noreturn_ -#endif - -#ifndef _Acquires_exclusive_lock_ -#define _Acquires_exclusive_lock_(lock) -#endif -#ifndef _Acquires_lock_ -#define _Acquires_lock_(lock) -#endif -#ifndef _Acquires_nonreentrant_lock_ -#define _Acquires_nonreentrant_lock_(lock) -#endif -#ifndef _Acquires_shared_lock_ -#define _Acquires_shared_lock_(lock) -#endif -#ifndef _Always_ -#define _Always_(annos) -#endif -#ifndef _Analysis_assume_ -#define _Analysis_assume_(expr) -#endif -#ifndef _Analysis_assume_ -#define _Analysis_assume_(expr) -#endif -#ifndef _Analysis_assume_lock_acquired_ -#define _Analysis_assume_lock_acquired_(lock) -#endif -#ifndef _Analysis_assume_lock_held_ -#define _Analysis_assume_lock_held_(lock) -#endif -#ifndef _Analysis_assume_lock_not_held_ -#define _Analysis_assume_lock_not_held_(lock) -#endif -#ifndef _Analysis_assume_lock_released_ -#define _Analysis_assume_lock_released_(lock) -#endif -#ifndef _Analysis_assume_nullterminated_ -#define _Analysis_assume_nullterminated_(x) -#endif -#ifndef _Analysis_assume_nullterminated_ -#define _Analysis_assume_nullterminated_(x) -#endif -#ifndef _Analysis_assume_same_lock_ -#define _Analysis_assume_same_lock_(lock1, lock2) -#endif -#ifndef _Analysis_mode_ -#define _Analysis_mode_(mode) -#endif -#ifndef _Analysis_mode_ -#define _Analysis_mode_(mode) -#endif -#ifndef _Analysis_noreturn_ -#define _Analysis_noreturn_ __attribute_noreturn__ -#endif -#ifndef _Analysis_suppress_lock_checking_ -#define _Analysis_suppress_lock_checking_(lock) -#endif -#ifndef _At_ -#define _At_(target, annos) -#endif -#ifndef _At_buffer_ -#define _At_buffer_(target, iter, bound, annos) -#endif -#ifndef _Benign_race_begin_ -#define _Benign_race_begin_ -#endif -#ifndef _Benign_race_end_ -#define _Benign_race_end_ -#endif -#ifndef _COM_Outptr_ -#define _COM_Outptr_ -#endif -#ifndef _COM_Outptr_opt_ -#define _COM_Outptr_opt_ -#endif -#ifndef _COM_Outptr_opt_result_maybenull_ -#define _COM_Outptr_opt_result_maybenull_ -#endif -#ifndef _COM_Outptr_result_maybenull_ -#define _COM_Outptr_result_maybenull_ -#endif -#ifndef _Called_from_function_class_ -#define _Called_from_function_class_(x) -#endif -#ifndef _Check_return_ -#define _Check_return_ __attribute_warn_unused_result__ -#endif -#ifndef _Const_ -#define _Const_ -#endif -#ifndef _Create_lock_level_ -#define _Create_lock_level_(level) -#endif -#ifndef _Csalcat1_ -#define _Csalcat1_(x,y) -#endif -#ifndef _Csalcat2_ -#define _Csalcat2_(x,y) -#endif -#ifndef _Deref2_pre_readonly_ -#define _Deref2_pre_readonly_ -#endif -#ifndef _Deref_in_bound_ -#define _Deref_in_bound_ -#endif -#ifndef _Deref_in_range_ -#define _Deref_in_range_(lb,ub) -#endif -#ifndef _Deref_inout_bound_ -#define _Deref_inout_bound_ -#endif -#ifndef _Deref_inout_z_ -#define _Deref_inout_z_ -#endif -#ifndef _Deref_inout_z_bytecap_c_ -#define _Deref_inout_z_bytecap_c_(size) -#endif -#ifndef _Deref_inout_z_cap_c_ -#define _Deref_inout_z_cap_c_(size) -#endif -#ifndef _Deref_opt_out_ -#define _Deref_opt_out_ -#endif -#ifndef _Deref_opt_out_opt_ -#define _Deref_opt_out_opt_ -#endif -#ifndef _Deref_opt_out_opt_z_ -#define _Deref_opt_out_opt_z_ -#endif -#ifndef _Deref_opt_out_z_ -#define _Deref_opt_out_z_ -#endif -#ifndef _Deref_out_ -#define _Deref_out_ -#endif -#ifndef _Deref_out_bound_ -#define _Deref_out_bound_ -#endif -#ifndef _Deref_out_opt_ -#define _Deref_out_opt_ -#endif -#ifndef _Deref_out_opt_z_ -#define _Deref_out_opt_z_ -#endif -#ifndef _Deref_out_range_ -#define _Deref_out_range_(lb,ub) -#endif -#ifndef _Deref_out_z_ -#define _Deref_out_z_ -#endif -#ifndef _Deref_out_z_bytecap_c_ -#define _Deref_out_z_bytecap_c_(size) -#endif -#ifndef _Deref_out_z_cap_c_ -#define _Deref_out_z_cap_c_(size) -#endif -#ifndef _Deref_post_bytecap_ -#define _Deref_post_bytecap_(size) -#endif -#ifndef _Deref_post_bytecap_c_ -#define _Deref_post_bytecap_c_(size) -#endif -#ifndef _Deref_post_bytecap_x_ -#define _Deref_post_bytecap_x_(size) -#endif -#ifndef _Deref_post_bytecount_ -#define _Deref_post_bytecount_(size) -#endif -#ifndef _Deref_post_bytecount_c_ -#define _Deref_post_bytecount_c_(size) -#endif -#ifndef _Deref_post_bytecount_x_ -#define _Deref_post_bytecount_x_(size) -#endif -#ifndef _Deref_post_cap_ -#define _Deref_post_cap_(size) -#endif -#ifndef _Deref_post_cap_c_ -#define _Deref_post_cap_c_(size) -#endif -#ifndef _Deref_post_cap_x_ -#define _Deref_post_cap_x_(size) -#endif -#ifndef _Deref_post_count_ -#define _Deref_post_count_(size) -#endif -#ifndef _Deref_post_count_c_ -#define _Deref_post_count_c_(size) -#endif -#ifndef _Deref_post_count_x_ -#define _Deref_post_count_x_(size) -#endif -#ifndef _Deref_post_maybenull_ -#define _Deref_post_maybenull_ -#endif -#ifndef _Deref_post_notnull_ -#define _Deref_post_notnull_ -#endif -#ifndef _Deref_post_null_ -#define _Deref_post_null_ -#endif -#ifndef _Deref_post_opt_bytecap_ -#define _Deref_post_opt_bytecap_(size) -#endif -#ifndef _Deref_post_opt_bytecap_c_ -#define _Deref_post_opt_bytecap_c_(size) -#endif -#ifndef _Deref_post_opt_bytecap_x_ -#define _Deref_post_opt_bytecap_x_(size) -#endif -#ifndef _Deref_post_opt_bytecount_ -#define _Deref_post_opt_bytecount_(size) -#endif -#ifndef _Deref_post_opt_bytecount_c_ -#define _Deref_post_opt_bytecount_c_(size) -#endif -#ifndef _Deref_post_opt_bytecount_x_ -#define _Deref_post_opt_bytecount_x_(size) -#endif -#ifndef _Deref_post_opt_cap_ -#define _Deref_post_opt_cap_(size) -#endif -#ifndef _Deref_post_opt_cap_c_ -#define _Deref_post_opt_cap_c_(size) -#endif -#ifndef _Deref_post_opt_cap_x_ -#define _Deref_post_opt_cap_x_(size) -#endif -#ifndef _Deref_post_opt_count_ -#define _Deref_post_opt_count_(size) -#endif -#ifndef _Deref_post_opt_count_c_ -#define _Deref_post_opt_count_c_(size) -#endif -#ifndef _Deref_post_opt_count_x_ -#define _Deref_post_opt_count_x_(size) -#endif -#ifndef _Deref_post_opt_valid_ -#define _Deref_post_opt_valid_ -#endif -#ifndef _Deref_post_opt_valid_bytecap_ -#define _Deref_post_opt_valid_bytecap_(size) -#endif -#ifndef _Deref_post_opt_valid_bytecap_c_ -#define _Deref_post_opt_valid_bytecap_c_(size) -#endif -#ifndef _Deref_post_opt_valid_bytecap_x_ -#define _Deref_post_opt_valid_bytecap_x_(size) -#endif -#ifndef _Deref_post_opt_valid_cap_ -#define _Deref_post_opt_valid_cap_(size) -#endif -#ifndef _Deref_post_opt_valid_cap_c_ -#define _Deref_post_opt_valid_cap_c_(size) -#endif -#ifndef _Deref_post_opt_valid_cap_x_ -#define _Deref_post_opt_valid_cap_x_(size) -#endif -#ifndef _Deref_post_opt_z_ -#define _Deref_post_opt_z_ -#endif -#ifndef _Deref_post_opt_z_bytecap_ -#define _Deref_post_opt_z_bytecap_(size) -#endif -#ifndef _Deref_post_opt_z_bytecap_c_ -#define _Deref_post_opt_z_bytecap_c_(size) -#endif -#ifndef _Deref_post_opt_z_bytecap_x_ -#define _Deref_post_opt_z_bytecap_x_(size) -#endif -#ifndef _Deref_post_opt_z_cap_ -#define _Deref_post_opt_z_cap_(size) -#endif -#ifndef _Deref_post_opt_z_cap_c_ -#define _Deref_post_opt_z_cap_c_(size) -#endif -#ifndef _Deref_post_opt_z_cap_x_ -#define _Deref_post_opt_z_cap_x_(size) -#endif -#ifndef _Deref_post_valid_ -#define _Deref_post_valid_ -#endif -#ifndef _Deref_post_valid_bytecap_ -#define _Deref_post_valid_bytecap_(size) -#endif -#ifndef _Deref_post_valid_bytecap_c_ -#define _Deref_post_valid_bytecap_c_(size) -#endif -#ifndef _Deref_post_valid_bytecap_x_ -#define _Deref_post_valid_bytecap_x_(size) -#endif -#ifndef _Deref_post_valid_cap_ -#define _Deref_post_valid_cap_(size) -#endif -#ifndef _Deref_post_valid_cap_c_ -#define _Deref_post_valid_cap_c_(size) -#endif -#ifndef _Deref_post_valid_cap_x_ -#define _Deref_post_valid_cap_x_(size) -#endif -#ifndef _Deref_post_z_ -#define _Deref_post_z_ -#endif -#ifndef _Deref_post_z_bytecap_ -#define _Deref_post_z_bytecap_(size) -#endif -#ifndef _Deref_post_z_bytecap_c_ -#define _Deref_post_z_bytecap_c_(size) -#endif -#ifndef _Deref_post_z_bytecap_x_ -#define _Deref_post_z_bytecap_x_(size) -#endif -#ifndef _Deref_post_z_cap_ -#define _Deref_post_z_cap_(size) -#endif -#ifndef _Deref_post_z_cap_c_ -#define _Deref_post_z_cap_c_(size) -#endif -#ifndef _Deref_post_z_cap_x_ -#define _Deref_post_z_cap_x_(size) -#endif -#ifndef _Deref_pre_bytecap_ -#define _Deref_pre_bytecap_(size) -#endif -#ifndef _Deref_pre_bytecap_c_ -#define _Deref_pre_bytecap_c_(size) -#endif -#ifndef _Deref_pre_bytecap_x_ -#define _Deref_pre_bytecap_x_(size) -#endif -#ifndef _Deref_pre_bytecount_ -#define _Deref_pre_bytecount_(size) -#endif -#ifndef _Deref_pre_bytecount_c_ -#define _Deref_pre_bytecount_c_(size) -#endif -#ifndef _Deref_pre_bytecount_x_ -#define _Deref_pre_bytecount_x_(size) -#endif -#ifndef _Deref_pre_cap_ -#define _Deref_pre_cap_(size) -#endif -#ifndef _Deref_pre_cap_c_ -#define _Deref_pre_cap_c_(size) -#endif -#ifndef _Deref_pre_cap_x_ -#define _Deref_pre_cap_x_(size) -#endif -#ifndef _Deref_pre_count_ -#define _Deref_pre_count_(size) -#endif -#ifndef _Deref_pre_count_c_ -#define _Deref_pre_count_c_(size) -#endif -#ifndef _Deref_pre_count_x_ -#define _Deref_pre_count_x_(size) -#endif -#ifndef _Deref_pre_invalid_ -#define _Deref_pre_invalid_ -#endif -#ifndef _Deref_pre_maybenull_ -#define _Deref_pre_maybenull_ -#endif -#ifndef _Deref_pre_notnull_ -#define _Deref_pre_notnull_ -#endif -#ifndef _Deref_pre_null_ -#define _Deref_pre_null_ -#endif -#ifndef _Deref_pre_opt_bytecap_ -#define _Deref_pre_opt_bytecap_(size) -#endif -#ifndef _Deref_pre_opt_bytecap_c_ -#define _Deref_pre_opt_bytecap_c_(size) -#endif -#ifndef _Deref_pre_opt_bytecap_x_ -#define _Deref_pre_opt_bytecap_x_(size) -#endif -#ifndef _Deref_pre_opt_bytecount_ -#define _Deref_pre_opt_bytecount_(size) -#endif -#ifndef _Deref_pre_opt_bytecount_c_ -#define _Deref_pre_opt_bytecount_c_(size) -#endif -#ifndef _Deref_pre_opt_bytecount_x_ -#define _Deref_pre_opt_bytecount_x_(size) -#endif -#ifndef _Deref_pre_opt_cap_ -#define _Deref_pre_opt_cap_(size) -#endif -#ifndef _Deref_pre_opt_cap_c_ -#define _Deref_pre_opt_cap_c_(size) -#endif -#ifndef _Deref_pre_opt_cap_x_ -#define _Deref_pre_opt_cap_x_(size) -#endif -#ifndef _Deref_pre_opt_count_ -#define _Deref_pre_opt_count_(size) -#endif -#ifndef _Deref_pre_opt_count_c_ -#define _Deref_pre_opt_count_c_(size) -#endif -#ifndef _Deref_pre_opt_count_x_ -#define _Deref_pre_opt_count_x_(size) -#endif -#ifndef _Deref_pre_opt_valid_ -#define _Deref_pre_opt_valid_ -#endif -#ifndef _Deref_pre_opt_valid_bytecap_ -#define _Deref_pre_opt_valid_bytecap_(size) -#endif -#ifndef _Deref_pre_opt_valid_bytecap_c_ -#define _Deref_pre_opt_valid_bytecap_c_(size) -#endif -#ifndef _Deref_pre_opt_valid_bytecap_x_ -#define _Deref_pre_opt_valid_bytecap_x_(size) -#endif -#ifndef _Deref_pre_opt_valid_cap_ -#define _Deref_pre_opt_valid_cap_(size) -#endif -#ifndef _Deref_pre_opt_valid_cap_c_ -#define _Deref_pre_opt_valid_cap_c_(size) -#endif -#ifndef _Deref_pre_opt_valid_cap_x_ -#define _Deref_pre_opt_valid_cap_x_(size) -#endif -#ifndef _Deref_pre_opt_z_ -#define _Deref_pre_opt_z_ -#endif -#ifndef _Deref_pre_opt_z_bytecap_ -#define _Deref_pre_opt_z_bytecap_(size) -#endif -#ifndef _Deref_pre_opt_z_bytecap_c_ -#define _Deref_pre_opt_z_bytecap_c_(size) -#endif -#ifndef _Deref_pre_opt_z_bytecap_x_ -#define _Deref_pre_opt_z_bytecap_x_(size) -#endif -#ifndef _Deref_pre_opt_z_cap_ -#define _Deref_pre_opt_z_cap_(size) -#endif -#ifndef _Deref_pre_opt_z_cap_c_ -#define _Deref_pre_opt_z_cap_c_(size) -#endif -#ifndef _Deref_pre_opt_z_cap_x_ -#define _Deref_pre_opt_z_cap_x_(size) -#endif -#ifndef _Deref_pre_readonly_ -#define _Deref_pre_readonly_ -#endif -#ifndef _Deref_pre_valid_ -#define _Deref_pre_valid_ -#endif -#ifndef _Deref_pre_valid_bytecap_ -#define _Deref_pre_valid_bytecap_(size) -#endif -#ifndef _Deref_pre_valid_bytecap_c_ -#define _Deref_pre_valid_bytecap_c_(size) -#endif -#ifndef _Deref_pre_valid_bytecap_x_ -#define _Deref_pre_valid_bytecap_x_(size) -#endif -#ifndef _Deref_pre_valid_cap_ -#define _Deref_pre_valid_cap_(size) -#endif -#ifndef _Deref_pre_valid_cap_c_ -#define _Deref_pre_valid_cap_c_(size) -#endif -#ifndef _Deref_pre_valid_cap_x_ -#define _Deref_pre_valid_cap_x_(size) -#endif -#ifndef _Deref_pre_writeonly_ -#define _Deref_pre_writeonly_ -#endif -#ifndef _Deref_pre_z_ -#define _Deref_pre_z_ -#endif -#ifndef _Deref_pre_z_bytecap_ -#define _Deref_pre_z_bytecap_(size) -#endif -#ifndef _Deref_pre_z_bytecap_c_ -#define _Deref_pre_z_bytecap_c_(size) -#endif -#ifndef _Deref_pre_z_bytecap_x_ -#define _Deref_pre_z_bytecap_x_(size) -#endif -#ifndef _Deref_pre_z_cap_ -#define _Deref_pre_z_cap_(size) -#endif -#ifndef _Deref_pre_z_cap_c_ -#define _Deref_pre_z_cap_c_(size) -#endif -#ifndef _Deref_pre_z_cap_x_ -#define _Deref_pre_z_cap_x_(size) -#endif -#ifndef _Deref_prepost_bytecap_ -#define _Deref_prepost_bytecap_(size) -#endif -#ifndef _Deref_prepost_bytecap_x_ -#define _Deref_prepost_bytecap_x_(size) -#endif -#ifndef _Deref_prepost_bytecount_ -#define _Deref_prepost_bytecount_(size) -#endif -#ifndef _Deref_prepost_bytecount_x_ -#define _Deref_prepost_bytecount_x_(size) -#endif -#ifndef _Deref_prepost_cap_ -#define _Deref_prepost_cap_(size) -#endif -#ifndef _Deref_prepost_cap_x_ -#define _Deref_prepost_cap_x_(size) -#endif -#ifndef _Deref_prepost_count_ -#define _Deref_prepost_count_(size) -#endif -#ifndef _Deref_prepost_count_x_ -#define _Deref_prepost_count_x_(size) -#endif -#ifndef _Deref_prepost_opt_bytecap_ -#define _Deref_prepost_opt_bytecap_(size) -#endif -#ifndef _Deref_prepost_opt_bytecap_x_ -#define _Deref_prepost_opt_bytecap_x_(size) -#endif -#ifndef _Deref_prepost_opt_bytecount_ -#define _Deref_prepost_opt_bytecount_(size) -#endif -#ifndef _Deref_prepost_opt_bytecount_x_ -#define _Deref_prepost_opt_bytecount_x_(size) -#endif -#ifndef _Deref_prepost_opt_cap_ -#define _Deref_prepost_opt_cap_(size) -#endif -#ifndef _Deref_prepost_opt_cap_x_ -#define _Deref_prepost_opt_cap_x_(size) -#endif -#ifndef _Deref_prepost_opt_count_ -#define _Deref_prepost_opt_count_(size) -#endif -#ifndef _Deref_prepost_opt_count_x_ -#define _Deref_prepost_opt_count_x_(size) -#endif -#ifndef _Deref_prepost_opt_valid_ -#define _Deref_prepost_opt_valid_ -#endif -#ifndef _Deref_prepost_opt_valid_bytecap_ -#define _Deref_prepost_opt_valid_bytecap_(size) -#endif -#ifndef _Deref_prepost_opt_valid_bytecap_x_ -#define _Deref_prepost_opt_valid_bytecap_x_(size) -#endif -#ifndef _Deref_prepost_opt_valid_cap_ -#define _Deref_prepost_opt_valid_cap_(size) -#endif -#ifndef _Deref_prepost_opt_valid_cap_x_ -#define _Deref_prepost_opt_valid_cap_x_(size) -#endif -#ifndef _Deref_prepost_opt_z_ -#define _Deref_prepost_opt_z_ -#endif -#ifndef _Deref_prepost_opt_z_bytecap_ -#define _Deref_prepost_opt_z_bytecap_(size) -#endif -#ifndef _Deref_prepost_opt_z_cap_ -#define _Deref_prepost_opt_z_cap_(size) -#endif -#ifndef _Deref_prepost_valid_ -#define _Deref_prepost_valid_ -#endif -#ifndef _Deref_prepost_valid_bytecap_ -#define _Deref_prepost_valid_bytecap_(size) -#endif -#ifndef _Deref_prepost_valid_bytecap_x_ -#define _Deref_prepost_valid_bytecap_x_(size) -#endif -#ifndef _Deref_prepost_valid_cap_ -#define _Deref_prepost_valid_cap_(size) -#endif -#ifndef _Deref_prepost_valid_cap_x_ -#define _Deref_prepost_valid_cap_x_(size) -#endif -#ifndef _Deref_prepost_z_ -#define _Deref_prepost_z_ -#endif -#ifndef _Deref_prepost_z_bytecap_ -#define _Deref_prepost_z_bytecap_(size) -#endif -#ifndef _Deref_prepost_z_cap_ -#define _Deref_prepost_z_cap_(size) -#endif -#ifndef _Deref_ret_bound_ -#define _Deref_ret_bound_ -#endif -#ifndef _Deref_ret_opt_z_ -#define _Deref_ret_opt_z_ -#endif -#ifndef _Deref_ret_range_ -#define _Deref_ret_range_(lb,ub) -#endif -#ifndef _Deref_ret_z_ -#define _Deref_ret_z_ -#endif -#ifndef _Enum_is_bitflag_ -#define _Enum_is_bitflag_ -#endif -#ifndef _Field_range_ -#define _Field_range_(min,max) -#endif -#ifndef _Field_size_ -#define _Field_size_(size) -#endif -#ifndef _Field_size_bytes_ -#define _Field_size_bytes_(size) -#endif -#ifndef _Field_size_bytes_full_ -#define _Field_size_bytes_full_(size) -#endif -#ifndef _Field_size_bytes_full_opt_ -#define _Field_size_bytes_full_opt_(size) -#endif -#ifndef _Field_size_bytes_opt_ -#define _Field_size_bytes_opt_(size) -#endif -#ifndef _Field_size_bytes_part_ -#define _Field_size_bytes_part_(size, count) -#endif -#ifndef _Field_size_bytes_part_opt_ -#define _Field_size_bytes_part_opt_(size, count) -#endif -#ifndef _Field_size_full_ -#define _Field_size_full_(size) -#endif -#ifndef _Field_size_full_opt_ -#define _Field_size_full_opt_(size) -#endif -#ifndef _Field_size_opt_ -#define _Field_size_opt_(size) -#endif -#ifndef _Field_size_part_ -#define _Field_size_part_(size, count) -#endif -#ifndef _Field_size_part_opt_ -#define _Field_size_part_opt_(size, count) -#endif -#ifndef _Field_z_ -#define _Field_z_ -#endif -#ifndef _Function_class_ -#define _Function_class_(x) -#endif -#ifndef _Function_ignore_lock_checking_ -#define _Function_ignore_lock_checking_(lock) -#endif -#ifndef _GrouP_ -#define _GrouP_(annos) -#endif -#ifndef _Group_ -#define _Group_(annos) -#endif -#ifndef _Guarded_by_ -#define _Guarded_by_(lock) -#endif -#ifndef _Has_lock_kind_ -#define _Has_lock_kind_(kind) -#endif -#ifndef _Has_lock_level_ -#define _Has_lock_level_(level) -#endif -#ifndef _In_ -#define _In_ -#endif -#ifndef _In_bound_ -#define _In_bound_ -#endif -#ifndef _In_bytecount_ -#define _In_bytecount_(size) -#endif -#ifndef _In_bytecount_c_ -#define _In_bytecount_c_(size) -#endif -#ifndef _In_bytecount_x_ -#define _In_bytecount_x_(size) -#endif -#ifndef _In_count_ -#define _In_count_(size) -#endif -#ifndef _In_count_c_ -#define _In_count_c_(size) -#endif -#ifndef _In_count_x_ -#define _In_count_x_(size) -#endif -#ifndef _In_defensive_ -#define _In_defensive_(annotes) -#endif -#ifndef _In_function_class_ -#define _In_function_class_(x) -#endif -#ifndef _In_opt_ -#define _In_opt_ -#endif -#ifndef _In_opt_bytecount_ -#define _In_opt_bytecount_(size) -#endif -#ifndef _In_opt_bytecount_c_ -#define _In_opt_bytecount_c_(size) -#endif -#ifndef _In_opt_bytecount_x_ -#define _In_opt_bytecount_x_(size) -#endif -#ifndef _In_opt_count_ -#define _In_opt_count_(size) -#endif -#ifndef _In_opt_count_c_ -#define _In_opt_count_c_(size) -#endif -#ifndef _In_opt_count_x_ -#define _In_opt_count_x_(size) -#endif -#ifndef _In_opt_ptrdiff_count_ -#define _In_opt_ptrdiff_count_(size) -#endif -#ifndef _In_opt_z_ -#define _In_opt_z_ -#endif -#ifndef _In_opt_z_bytecount_ -#define _In_opt_z_bytecount_(size) -#endif -#ifndef _In_opt_z_bytecount_c_ -#define _In_opt_z_bytecount_c_(size) -#endif -#ifndef _In_opt_z_count_ -#define _In_opt_z_count_(size) -#endif -#ifndef _In_opt_z_count_c_ -#define _In_opt_z_count_c_(size) -#endif -#ifndef _In_ptrdiff_count_ -#define _In_ptrdiff_count_(size) -#endif -#ifndef _In_range_ -#define _In_range_(lb,ub) -#endif -#ifndef _In_reads_ -#define _In_reads_(size) -#endif -#ifndef _In_reads_bytes_ -#define _In_reads_bytes_(size) -#endif -#ifndef _In_reads_bytes_opt_ -#define _In_reads_bytes_opt_(size) -#endif -#ifndef _In_reads_opt_ -#define _In_reads_opt_(size) -#endif -#ifndef _In_reads_opt_z_ -#define _In_reads_opt_z_(size) -#endif -#ifndef _In_reads_or_z_ -#define _In_reads_or_z_(size) -#endif -#ifndef _In_reads_or_z_opt_ -#define _In_reads_or_z_opt_(size) -#endif -#ifndef _In_reads_to_ptr_ -#define _In_reads_to_ptr_(ptr) -#endif -#ifndef _In_reads_to_ptr_opt_ -#define _In_reads_to_ptr_opt_(ptr) -#endif -#ifndef _In_reads_to_ptr_opt_z_ -#define _In_reads_to_ptr_opt_z_(ptr) -#endif -#ifndef _In_reads_to_ptr_z_ -#define _In_reads_to_ptr_z_(ptr) -#endif -#ifndef _In_reads_z_ -#define _In_reads_z_(size) -#endif -#ifndef _In_z_ -#define _In_z_ -#endif -#ifndef _In_z_bytecount_ -#define _In_z_bytecount_(size) -#endif -#ifndef _In_z_bytecount_c_ -#define _In_z_bytecount_c_(size) -#endif -#ifndef _In_z_count_ -#define _In_z_count_(size) -#endif -#ifndef _In_z_count_c_ -#define _In_z_count_c_(size) -#endif -#ifndef _Inout_ -#define _Inout_ -#endif -#ifndef _Inout_bytecap_ -#define _Inout_bytecap_(size) -#endif -#ifndef _Inout_bytecap_c_ -#define _Inout_bytecap_c_(size) -#endif -#ifndef _Inout_bytecap_x_ -#define _Inout_bytecap_x_(size) -#endif -#ifndef _Inout_bytecount_ -#define _Inout_bytecount_(size) -#endif -#ifndef _Inout_bytecount_c_ -#define _Inout_bytecount_c_(size) -#endif -#ifndef _Inout_bytecount_x_ -#define _Inout_bytecount_x_(size) -#endif -#ifndef _Inout_cap_ -#define _Inout_cap_(size) -#endif -#ifndef _Inout_cap_c_ -#define _Inout_cap_c_(size) -#endif -#ifndef _Inout_cap_x_ -#define _Inout_cap_x_(size) -#endif -#ifndef _Inout_count_ -#define _Inout_count_(size) -#endif -#ifndef _Inout_count_c_ -#define _Inout_count_c_(size) -#endif -#ifndef _Inout_count_x_ -#define _Inout_count_x_(size) -#endif -#ifndef _Inout_defensive_ -#define _Inout_defensive_(annotes) -#endif -#ifndef _Inout_opt_ -#define _Inout_opt_ -#endif -#ifndef _Inout_opt_bytecap_ -#define _Inout_opt_bytecap_(size) -#endif -#ifndef _Inout_opt_bytecap_c_ -#define _Inout_opt_bytecap_c_(size) -#endif -#ifndef _Inout_opt_bytecap_x_ -#define _Inout_opt_bytecap_x_(size) -#endif -#ifndef _Inout_opt_bytecount_ -#define _Inout_opt_bytecount_(size) -#endif -#ifndef _Inout_opt_bytecount_c_ -#define _Inout_opt_bytecount_c_(size) -#endif -#ifndef _Inout_opt_bytecount_x_ -#define _Inout_opt_bytecount_x_(size) -#endif -#ifndef _Inout_opt_cap_ -#define _Inout_opt_cap_(size) -#endif -#ifndef _Inout_opt_cap_c_ -#define _Inout_opt_cap_c_(size) -#endif -#ifndef _Inout_opt_cap_x_ -#define _Inout_opt_cap_x_(size) -#endif -#ifndef _Inout_opt_count_ -#define _Inout_opt_count_(size) -#endif -#ifndef _Inout_opt_count_c_ -#define _Inout_opt_count_c_(size) -#endif -#ifndef _Inout_opt_count_x_ -#define _Inout_opt_count_x_(size) -#endif -#ifndef _Inout_opt_ptrdiff_count_ -#define _Inout_opt_ptrdiff_count_(size) -#endif -#ifndef _Inout_opt_z_ -#define _Inout_opt_z_ -#endif -#ifndef _Inout_opt_z_bytecap_ -#define _Inout_opt_z_bytecap_(size) -#endif -#ifndef _Inout_opt_z_bytecap_c_ -#define _Inout_opt_z_bytecap_c_(size) -#endif -#ifndef _Inout_opt_z_bytecap_x_ -#define _Inout_opt_z_bytecap_x_(size) -#endif -#ifndef _Inout_opt_z_bytecount_ -#define _Inout_opt_z_bytecount_(size) -#endif -#ifndef _Inout_opt_z_bytecount_c_ -#define _Inout_opt_z_bytecount_c_(size) -#endif -#ifndef _Inout_opt_z_cap_ -#define _Inout_opt_z_cap_(size) -#endif -#ifndef _Inout_opt_z_cap_c_ -#define _Inout_opt_z_cap_c_(size) -#endif -#ifndef _Inout_opt_z_cap_x_ -#define _Inout_opt_z_cap_x_(size) -#endif -#ifndef _Inout_opt_z_count_ -#define _Inout_opt_z_count_(size) -#endif -#ifndef _Inout_opt_z_count_c_ -#define _Inout_opt_z_count_c_(size) -#endif -#ifndef _Inout_ptrdiff_count_ -#define _Inout_ptrdiff_count_(size) -#endif -#ifndef _Inout_updates_ -#define _Inout_updates_(size) -#endif -#ifndef _Inout_updates_all_ -#define _Inout_updates_all_(size) -#endif -#ifndef _Inout_updates_all_opt_ -#define _Inout_updates_all_opt_(size) -#endif -#ifndef _Inout_updates_bytes_ -#define _Inout_updates_bytes_(size) -#endif -#ifndef _Inout_updates_bytes_all_ -#define _Inout_updates_bytes_all_(size) -#endif -#ifndef _Inout_updates_bytes_all_opt_ -#define _Inout_updates_bytes_all_opt_(size) -#endif -#ifndef _Inout_updates_bytes_opt_ -#define _Inout_updates_bytes_opt_(size) -#endif -#ifndef _Inout_updates_bytes_to_ -#define _Inout_updates_bytes_to_(size,count) -#endif -#ifndef _Inout_updates_bytes_to_opt_ -#define _Inout_updates_bytes_to_opt_(size,count) -#endif -#ifndef _Inout_updates_opt_ -#define _Inout_updates_opt_(size) -#endif -#ifndef _Inout_updates_opt_z_ -#define _Inout_updates_opt_z_(size) -#endif -#ifndef _Inout_updates_to_ -#define _Inout_updates_to_(size,count) -#endif -#ifndef _Inout_updates_to_opt_ -#define _Inout_updates_to_opt_(size,count) -#endif -#ifndef _Inout_updates_z_ -#define _Inout_updates_z_(size) -#endif -#ifndef _Inout_z_ -#define _Inout_z_ -#endif -#ifndef _Inout_z_bytecap_ -#define _Inout_z_bytecap_(size) -#endif -#ifndef _Inout_z_bytecap_c_ -#define _Inout_z_bytecap_c_(size) -#endif -#ifndef _Inout_z_bytecap_x_ -#define _Inout_z_bytecap_x_(size) -#endif -#ifndef _Inout_z_bytecount_ -#define _Inout_z_bytecount_(size) -#endif -#ifndef _Inout_z_bytecount_c_ -#define _Inout_z_bytecount_c_(size) -#endif -#ifndef _Inout_z_cap_ -#define _Inout_z_cap_(size) -#endif -#ifndef _Inout_z_cap_c_ -#define _Inout_z_cap_c_(size) -#endif -#ifndef _Inout_z_cap_x_ -#define _Inout_z_cap_x_(size) -#endif -#ifndef _Inout_z_count_ -#define _Inout_z_count_(size) -#endif -#ifndef _Inout_z_count_c_ -#define _Inout_z_count_c_(size) -#endif -#ifndef _Interlocked_ -#define _Interlocked_ -#endif -#ifndef _Interlocked_operand_ -#define _Interlocked_operand_ -#endif -#ifndef _Internal_lock_level_order_ -#define _Internal_lock_level_order_(a,b) -#endif -#ifndef _Internal_set_lock_count_ -#define _Internal_set_lock_count_(lock, count) -#endif -#ifndef _Literal_ -#define _Literal_ -#endif -#ifndef _Lock_level_order_ -#define _Lock_level_order_(a,b) -#endif -#ifndef _Maybe_raises_SEH_exception_ -#define _Maybe_raises_SEH_exception_ -#endif -#ifndef _Maybenull_ -#define _Maybenull_ -#endif -#ifndef _Maybevalid_ -#define _Maybevalid_ -#endif -#ifndef _Must_inspect_result_ -#define _Must_inspect_result_ __attribute_warn_unused_result__ -#endif -#ifndef _No_competing_thread_ -#define _No_competing_thread_ -#endif -#ifndef _No_competing_thread_begin_ -#define _No_competing_thread_begin_ -#endif -#ifndef _No_competing_thread_end_ -#define _No_competing_thread_end_ -#endif -#ifndef _Notliteral_ -#define _Notliteral_ -#endif -#ifndef _Notnull_ -#define _Notnull_ -#endif -#ifndef _Notref_ -#define _Notref_ -#endif -#ifndef _Notvalid_ -#define _Notvalid_ -#endif -#ifndef _NullNull_terminated_ -#define _NullNull_terminated_ -#endif -#ifndef _Null_ -#define _Null_ -#endif -#ifndef _Null_terminated_ -#define _Null_terminated_ -#endif -#ifndef _On_failure_ -#define _On_failure_(annos) -#endif -#ifndef _Out_ -#define _Out_ -#endif -#ifndef _Out_bound_ -#define _Out_bound_ -#endif -#ifndef _Out_bytecap_ -#define _Out_bytecap_(size) -#endif -#ifndef _Out_bytecap_c_ -#define _Out_bytecap_c_(size) -#endif -#ifndef _Out_bytecap_post_bytecount_ -#define _Out_bytecap_post_bytecount_(cap,count) -#endif -#ifndef _Out_bytecap_x_ -#define _Out_bytecap_x_(size) -#endif -#ifndef _Out_bytecapcount_ -#define _Out_bytecapcount_(capcount) -#endif -#ifndef _Out_bytecapcount_x_ -#define _Out_bytecapcount_x_(capcount) -#endif -#ifndef _Out_cap_ -#define _Out_cap_(size) -#endif -#ifndef _Out_cap_c_ -#define _Out_cap_c_(size) -#endif -#ifndef _Out_cap_m_ -#define _Out_cap_m_(mult,size) -#endif -#ifndef _Out_cap_post_count_ -#define _Out_cap_post_count_(cap,count) -#endif -#ifndef _Out_cap_x_ -#define _Out_cap_x_(size) -#endif -#ifndef _Out_capcount_ -#define _Out_capcount_(capcount) -#endif -#ifndef _Out_capcount_x_ -#define _Out_capcount_x_(capcount) -#endif -#ifndef _Out_defensive_ -#define _Out_defensive_(annotes) -#endif -#ifndef _Out_opt_ -#define _Out_opt_ -#endif -#ifndef _Out_opt_bytecap_ -#define _Out_opt_bytecap_(size) -#endif -#ifndef _Out_opt_bytecap_c_ -#define _Out_opt_bytecap_c_(size) -#endif -#ifndef _Out_opt_bytecap_post_bytecount_ -#define _Out_opt_bytecap_post_bytecount_(cap,count) -#endif -#ifndef _Out_opt_bytecap_x_ -#define _Out_opt_bytecap_x_(size) -#endif -#ifndef _Out_opt_bytecapcount_ -#define _Out_opt_bytecapcount_(capcount) -#endif -#ifndef _Out_opt_bytecapcount_x_ -#define _Out_opt_bytecapcount_x_(capcount) -#endif -#ifndef _Out_opt_cap_ -#define _Out_opt_cap_(size) -#endif -#ifndef _Out_opt_cap_c_ -#define _Out_opt_cap_c_(size) -#endif -#ifndef _Out_opt_cap_m_ -#define _Out_opt_cap_m_(mult,size) -#endif -#ifndef _Out_opt_cap_post_count_ -#define _Out_opt_cap_post_count_(cap,count) -#endif -#ifndef _Out_opt_cap_x_ -#define _Out_opt_cap_x_(size) -#endif -#ifndef _Out_opt_capcount_ -#define _Out_opt_capcount_(capcount) -#endif -#ifndef _Out_opt_capcount_x_ -#define _Out_opt_capcount_x_(capcount) -#endif -#ifndef _Out_opt_ptrdiff_cap_ -#define _Out_opt_ptrdiff_cap_(size) -#endif -#ifndef _Out_opt_z_bytecap_ -#define _Out_opt_z_bytecap_(size) -#endif -#ifndef _Out_opt_z_bytecap_c_ -#define _Out_opt_z_bytecap_c_(size) -#endif -#ifndef _Out_opt_z_bytecap_post_bytecount_ -#define _Out_opt_z_bytecap_post_bytecount_(cap,count) -#endif -#ifndef _Out_opt_z_bytecap_x_ -#define _Out_opt_z_bytecap_x_(size) -#endif -#ifndef _Out_opt_z_bytecapcount_ -#define _Out_opt_z_bytecapcount_(capcount) -#endif -#ifndef _Out_opt_z_cap_ -#define _Out_opt_z_cap_(size) -#endif -#ifndef _Out_opt_z_cap_c_ -#define _Out_opt_z_cap_c_(size) -#endif -#ifndef _Out_opt_z_cap_m_ -#define _Out_opt_z_cap_m_(mult,size) -#endif -#ifndef _Out_opt_z_cap_post_count_ -#define _Out_opt_z_cap_post_count_(cap,count) -#endif -#ifndef _Out_opt_z_cap_x_ -#define _Out_opt_z_cap_x_(size) -#endif -#ifndef _Out_opt_z_capcount_ -#define _Out_opt_z_capcount_(capcount) -#endif -#ifndef _Out_ptrdiff_cap_ -#define _Out_ptrdiff_cap_(size) -#endif -#ifndef _Out_range_ -#define _Out_range_(lb,ub) -#endif -#ifndef _Out_writes_ -#define _Out_writes_(size) -#endif -#ifndef _Out_writes_all_ -#define _Out_writes_all_(size) -#endif -#ifndef _Out_writes_all_opt_ -#define _Out_writes_all_opt_(size) -#endif -#ifndef _Out_writes_bytes_ -#define _Out_writes_bytes_(size) -#endif -#ifndef _Out_writes_bytes_all_ -#define _Out_writes_bytes_all_(size) -#endif -#ifndef _Out_writes_bytes_all_opt_ -#define _Out_writes_bytes_all_opt_(size) -#endif -#ifndef _Out_writes_bytes_opt_ -#define _Out_writes_bytes_opt_(size) -#endif -#ifndef _Out_writes_bytes_to_ -#define _Out_writes_bytes_to_(size,count) -#endif -#ifndef _Out_writes_bytes_to_opt_ -#define _Out_writes_bytes_to_opt_(size,count) -#endif -#ifndef _Out_writes_opt_ -#define _Out_writes_opt_(size) -#endif -#ifndef _Out_writes_opt_z_ -#define _Out_writes_opt_z_(size) -#endif -#ifndef _Out_writes_to_ -#define _Out_writes_to_(size,count) -#endif -#ifndef _Out_writes_to_opt_ -#define _Out_writes_to_opt_(size,count) -#endif -#ifndef _Out_writes_to_ptr_ -#define _Out_writes_to_ptr_(ptr) -#endif -#ifndef _Out_writes_to_ptr_opt_ -#define _Out_writes_to_ptr_opt_(ptr) -#endif -#ifndef _Out_writes_to_ptr_opt_z_ -#define _Out_writes_to_ptr_opt_z_(ptr) -#endif -#ifndef _Out_writes_to_ptr_z_ -#define _Out_writes_to_ptr_z_(ptr) -#endif -#ifndef _Out_writes_z_ -#define _Out_writes_z_(size) -#endif -#ifndef _Out_z_bytecap_ -#define _Out_z_bytecap_(size) -#endif -#ifndef _Out_z_bytecap_c_ -#define _Out_z_bytecap_c_(size) -#endif -#ifndef _Out_z_bytecap_post_bytecount_ -#define _Out_z_bytecap_post_bytecount_(cap,count) -#endif -#ifndef _Out_z_bytecap_x_ -#define _Out_z_bytecap_x_(size) -#endif -#ifndef _Out_z_bytecapcount_ -#define _Out_z_bytecapcount_(capcount) -#endif -#ifndef _Out_z_cap_ -#define _Out_z_cap_(size) -#endif -#ifndef _Out_z_cap_c_ -#define _Out_z_cap_c_(size) -#endif -#ifndef _Out_z_cap_m_ -#define _Out_z_cap_m_(mult,size) -#endif -#ifndef _Out_z_cap_post_count_ -#define _Out_z_cap_post_count_(cap,count) -#endif -#ifndef _Out_z_cap_x_ -#define _Out_z_cap_x_(size) -#endif -#ifndef _Out_z_capcount_ -#define _Out_z_capcount_(capcount) -#endif -#ifndef _Outptr_ -#define _Outptr_ -#endif -#ifndef _Outptr_opt_ -#define _Outptr_opt_ -#endif -#ifndef _Outptr_opt_result_buffer_ -#define _Outptr_opt_result_buffer_(size) -#endif -#ifndef _Outptr_opt_result_buffer_all_ -#define _Outptr_opt_result_buffer_all_(size) -#endif -#ifndef _Outptr_opt_result_buffer_all_maybenull_ -#define _Outptr_opt_result_buffer_all_maybenull_(size) -#endif -#ifndef _Outptr_opt_result_buffer_maybenull_ -#define _Outptr_opt_result_buffer_maybenull_(size) -#endif -#ifndef _Outptr_opt_result_buffer_to_ -#define _Outptr_opt_result_buffer_to_(size, count) -#endif -#ifndef _Outptr_opt_result_buffer_to_maybenull_ -#define _Outptr_opt_result_buffer_to_maybenull_(size, count) -#endif -#ifndef _Outptr_opt_result_bytebuffer_ -#define _Outptr_opt_result_bytebuffer_(size) -#endif -#ifndef _Outptr_opt_result_bytebuffer_all_ -#define _Outptr_opt_result_bytebuffer_all_(size) -#endif -#ifndef _Outptr_opt_result_bytebuffer_all_maybenull_ -#define _Outptr_opt_result_bytebuffer_all_maybenull_(size) -#endif -#ifndef _Outptr_opt_result_bytebuffer_maybenull_ -#define _Outptr_opt_result_bytebuffer_maybenull_(size) -#endif -#ifndef _Outptr_opt_result_bytebuffer_to_ -#define _Outptr_opt_result_bytebuffer_to_(size, count) -#endif -#ifndef _Outptr_opt_result_bytebuffer_to_maybenull_ -#define _Outptr_opt_result_bytebuffer_to_maybenull_(size, count) -#endif -#ifndef _Outptr_opt_result_maybenull_ -#define _Outptr_opt_result_maybenull_ -#endif -#ifndef _Outptr_opt_result_maybenull_z_ -#define _Outptr_opt_result_maybenull_z_ -#endif -#ifndef _Outptr_opt_result_nullonfailure_ -#define _Outptr_opt_result_nullonfailure_ -#endif -#ifndef _Outptr_opt_result_z_ -#define _Outptr_opt_result_z_ -#endif -#ifndef _Outptr_result_buffer_ -#define _Outptr_result_buffer_(size) -#endif -#ifndef _Outptr_result_buffer_all_ -#define _Outptr_result_buffer_all_(size) -#endif -#ifndef _Outptr_result_buffer_all_maybenull_ -#define _Outptr_result_buffer_all_maybenull_(size) -#endif -#ifndef _Outptr_result_buffer_maybenull_ -#define _Outptr_result_buffer_maybenull_(size) -#endif -#ifndef _Outptr_result_buffer_to_ -#define _Outptr_result_buffer_to_(size, count) -#endif -#ifndef _Outptr_result_buffer_to_maybenull_ -#define _Outptr_result_buffer_to_maybenull_(size, count) -#endif -#ifndef _Outptr_result_bytebuffer_ -#define _Outptr_result_bytebuffer_(size) -#endif -#ifndef _Outptr_result_bytebuffer_all_ -#define _Outptr_result_bytebuffer_all_(size) -#endif -#ifndef _Outptr_result_bytebuffer_all_maybenull_ -#define _Outptr_result_bytebuffer_all_maybenull_(size) -#endif -#ifndef _Outptr_result_bytebuffer_maybenull_ -#define _Outptr_result_bytebuffer_maybenull_(size) -#endif -#ifndef _Outptr_result_bytebuffer_to_ -#define _Outptr_result_bytebuffer_to_(size, count) -#endif -#ifndef _Outptr_result_bytebuffer_to_maybenull_ -#define _Outptr_result_bytebuffer_to_maybenull_(size, count) -#endif -#ifndef _Outptr_result_maybenull_ -#define _Outptr_result_maybenull_ -#endif -#ifndef _Outptr_result_maybenull_z_ -#define _Outptr_result_maybenull_z_ -#endif -#ifndef _Outptr_result_nullonfailure_ -#define _Outptr_result_nullonfailure_ -#endif -#ifndef _Outptr_result_z_ -#define _Outptr_result_z_ -#endif -#ifndef _Outref_ -#define _Outref_ -#endif -#ifndef _Outref_result_buffer_ -#define _Outref_result_buffer_(size) -#endif -#ifndef _Outref_result_buffer_all_ -#define _Outref_result_buffer_all_(size) -#endif -#ifndef _Outref_result_buffer_all_maybenull_ -#define _Outref_result_buffer_all_maybenull_(size) -#endif -#ifndef _Outref_result_buffer_maybenull_ -#define _Outref_result_buffer_maybenull_(size) -#endif -#ifndef _Outref_result_buffer_to_ -#define _Outref_result_buffer_to_(size, count) -#endif -#ifndef _Outref_result_buffer_to_maybenull_ -#define _Outref_result_buffer_to_maybenull_(size, count) -#endif -#ifndef _Outref_result_bytebuffer_ -#define _Outref_result_bytebuffer_(size) -#endif -#ifndef _Outref_result_bytebuffer_all_ -#define _Outref_result_bytebuffer_all_(size) -#endif -#ifndef _Outref_result_bytebuffer_all_maybenull_ -#define _Outref_result_bytebuffer_all_maybenull_(size) -#endif -#ifndef _Outref_result_bytebuffer_maybenull_ -#define _Outref_result_bytebuffer_maybenull_(size) -#endif -#ifndef _Outref_result_bytebuffer_to_ -#define _Outref_result_bytebuffer_to_(size, count) -#endif -#ifndef _Outref_result_bytebuffer_to_maybenull_ -#define _Outref_result_bytebuffer_to_maybenull_(size, count) -#endif -#ifndef _Outref_result_maybenull_ -#define _Outref_result_maybenull_ -#endif -#ifndef _Outref_result_nullonfailure_ -#define _Outref_result_nullonfailure_ -#endif -#ifndef _Points_to_data_ -#define _Points_to_data_ -#endif -#ifndef _Post_ -#define _Post_ -#endif -#ifndef _Post_bytecap_ -#define _Post_bytecap_(size) -#endif -#ifndef _Post_bytecount_ -#define _Post_bytecount_(size) -#endif -#ifndef _Post_bytecount_c_ -#define _Post_bytecount_c_(size) -#endif -#ifndef _Post_bytecount_x_ -#define _Post_bytecount_x_(size) -#endif -#ifndef _Post_cap_ -#define _Post_cap_(size) -#endif -#ifndef _Post_count_ -#define _Post_count_(size) -#endif -#ifndef _Post_count_c_ -#define _Post_count_c_(size) -#endif -#ifndef _Post_count_x_ -#define _Post_count_x_(size) -#endif -#ifndef _Post_defensive_ -#define _Post_defensive_ -#endif -#ifndef _Post_equal_to_ -#define _Post_equal_to_(expr) -#endif -#ifndef _Post_invalid_ -#define _Post_invalid_ -#endif -#ifndef _Post_maybenull_ -#define _Post_maybenull_ -#endif -#ifndef _Post_maybez_ -#define _Post_maybez_ -#endif -#ifndef _Post_notnull_ -#define _Post_notnull_ -#endif -#ifndef _Post_null_ -#define _Post_null_ -#endif -#ifndef _Post_ptr_invalid_ -#define _Post_ptr_invalid_ -#endif -#ifndef _Post_readable_byte_size_ -#define _Post_readable_byte_size_(size) -#endif -#ifndef _Post_readable_size_ -#define _Post_readable_size_(size) -#endif -#ifndef _Post_same_lock_ -#define _Post_same_lock_(lock1,lock2) -#endif -#ifndef _Post_satisfies_ -#define _Post_satisfies_(cond) -#endif -#ifndef _Post_valid_ -#define _Post_valid_ -#endif -#ifndef _Post_writable_byte_size_ -#define _Post_writable_byte_size_(size) -#endif -#ifndef _Post_writable_size_ -#define _Post_writable_size_(size) -#endif -#ifndef _Post_z_ -#define _Post_z_ -#endif -#ifndef _Post_z_bytecount_ -#define _Post_z_bytecount_(size) -#endif -#ifndef _Post_z_bytecount_c_ -#define _Post_z_bytecount_c_(size) -#endif -#ifndef _Post_z_bytecount_x_ -#define _Post_z_bytecount_x_(size) -#endif -#ifndef _Post_z_count_ -#define _Post_z_count_(size) -#endif -#ifndef _Post_z_count_c_ -#define _Post_z_count_c_(size) -#endif -#ifndef _Post_z_count_x_ -#define _Post_z_count_x_(size) -#endif -#ifndef _Pre_ -#define _Pre_ -#endif -#ifndef _Pre_bytecap_ -#define _Pre_bytecap_(size) -#endif -#ifndef _Pre_bytecap_c_ -#define _Pre_bytecap_c_(size) -#endif -#ifndef _Pre_bytecap_x_ -#define _Pre_bytecap_x_(size) -#endif -#ifndef _Pre_bytecount_ -#define _Pre_bytecount_(size) -#endif -#ifndef _Pre_bytecount_c_ -#define _Pre_bytecount_c_(size) -#endif -#ifndef _Pre_bytecount_x_ -#define _Pre_bytecount_x_(size) -#endif -#ifndef _Pre_cap_ -#define _Pre_cap_(size) -#endif -#ifndef _Pre_cap_c_ -#define _Pre_cap_c_(size) -#endif -#ifndef _Pre_cap_c_one_ -#define _Pre_cap_c_one_ -#endif -#ifndef _Pre_cap_for_ -#define _Pre_cap_for_(param) -#endif -#ifndef _Pre_cap_m_ -#define _Pre_cap_m_(mult,size) -#endif -#ifndef _Pre_cap_x_ -#define _Pre_cap_x_(size) -#endif -#ifndef _Pre_count_ -#define _Pre_count_(size) -#endif -#ifndef _Pre_count_c_ -#define _Pre_count_c_(size) -#endif -#ifndef _Pre_count_x_ -#define _Pre_count_x_(size) -#endif -#ifndef _Pre_defensive_ -#define _Pre_defensive_ -#endif -#ifndef _Pre_equal_to_ -#define _Pre_equal_to_(expr) -#endif -#ifndef _Pre_invalid_ -#define _Pre_invalid_ -#endif -#ifndef _Pre_maybenull_ -#define _Pre_maybenull_ -#endif -#ifndef _Pre_notnull_ -#define _Pre_notnull_ -#endif -#ifndef _Pre_null_ -#define _Pre_null_ -#endif -#ifndef _Pre_opt_bytecap_ -#define _Pre_opt_bytecap_(size) -#endif -#ifndef _Pre_opt_bytecap_c_ -#define _Pre_opt_bytecap_c_(size) -#endif -#ifndef _Pre_opt_bytecap_x_ -#define _Pre_opt_bytecap_x_(size) -#endif -#ifndef _Pre_opt_bytecount_ -#define _Pre_opt_bytecount_(size) -#endif -#ifndef _Pre_opt_bytecount_c_ -#define _Pre_opt_bytecount_c_(size) -#endif -#ifndef _Pre_opt_bytecount_x_ -#define _Pre_opt_bytecount_x_(size) -#endif -#ifndef _Pre_opt_cap_ -#define _Pre_opt_cap_(size) -#endif -#ifndef _Pre_opt_cap_c_ -#define _Pre_opt_cap_c_(size) -#endif -#ifndef _Pre_opt_cap_c_one_ -#define _Pre_opt_cap_c_one_ -#endif -#ifndef _Pre_opt_cap_for_ -#define _Pre_opt_cap_for_(param) -#endif -#ifndef _Pre_opt_cap_m_ -#define _Pre_opt_cap_m_(mult,size) -#endif -#ifndef _Pre_opt_cap_x_ -#define _Pre_opt_cap_x_(size) -#endif -#ifndef _Pre_opt_count_ -#define _Pre_opt_count_(size) -#endif -#ifndef _Pre_opt_count_c_ -#define _Pre_opt_count_c_(size) -#endif -#ifndef _Pre_opt_count_x_ -#define _Pre_opt_count_x_(size) -#endif -#ifndef _Pre_opt_ptrdiff_cap_ -#define _Pre_opt_ptrdiff_cap_(ptr) -#endif -#ifndef _Pre_opt_ptrdiff_count_ -#define _Pre_opt_ptrdiff_count_(ptr) -#endif -#ifndef _Pre_opt_valid_ -#define _Pre_opt_valid_ -#endif -#ifndef _Pre_opt_valid_bytecap_ -#define _Pre_opt_valid_bytecap_(size) -#endif -#ifndef _Pre_opt_valid_bytecap_c_ -#define _Pre_opt_valid_bytecap_c_(size) -#endif -#ifndef _Pre_opt_valid_bytecap_x_ -#define _Pre_opt_valid_bytecap_x_(size) -#endif -#ifndef _Pre_opt_valid_cap_ -#define _Pre_opt_valid_cap_(size) -#endif -#ifndef _Pre_opt_valid_cap_c_ -#define _Pre_opt_valid_cap_c_(size) -#endif -#ifndef _Pre_opt_valid_cap_x_ -#define _Pre_opt_valid_cap_x_(size) -#endif -#ifndef _Pre_opt_z_ -#define _Pre_opt_z_ -#endif -#ifndef _Pre_opt_z_bytecap_ -#define _Pre_opt_z_bytecap_(size) -#endif -#ifndef _Pre_opt_z_bytecap_c_ -#define _Pre_opt_z_bytecap_c_(size) -#endif -#ifndef _Pre_opt_z_bytecap_x_ -#define _Pre_opt_z_bytecap_x_(size) -#endif -#ifndef _Pre_opt_z_cap_ -#define _Pre_opt_z_cap_(size) -#endif -#ifndef _Pre_opt_z_cap_c_ -#define _Pre_opt_z_cap_c_(size) -#endif -#ifndef _Pre_opt_z_cap_x_ -#define _Pre_opt_z_cap_x_(size) -#endif -#ifndef _Pre_ptrdiff_cap_ -#define _Pre_ptrdiff_cap_(ptr) -#endif -#ifndef _Pre_ptrdiff_count_ -#define _Pre_ptrdiff_count_(ptr) -#endif -#ifndef _Pre_readable_byte_size_ -#define _Pre_readable_byte_size_(size) -#endif -#ifndef _Pre_readable_size_ -#define _Pre_readable_size_(size) -#endif -#ifndef _Pre_readonly_ -#define _Pre_readonly_ -#endif -#ifndef _Pre_satisfies_ -#define _Pre_satisfies_(cond) -#endif -#ifndef _Pre_unknown_ -#define _Pre_unknown_ -#endif -#ifndef _Pre_valid_ -#define _Pre_valid_ -#endif -#ifndef _Pre_valid_bytecap_ -#define _Pre_valid_bytecap_(size) -#endif -#ifndef _Pre_valid_bytecap_c_ -#define _Pre_valid_bytecap_c_(size) -#endif -#ifndef _Pre_valid_bytecap_x_ -#define _Pre_valid_bytecap_x_(size) -#endif -#ifndef _Pre_valid_cap_ -#define _Pre_valid_cap_(size) -#endif -#ifndef _Pre_valid_cap_c_ -#define _Pre_valid_cap_c_(size) -#endif -#ifndef _Pre_valid_cap_x_ -#define _Pre_valid_cap_x_(size) -#endif -#ifndef _Pre_writable_byte_size_ -#define _Pre_writable_byte_size_(size) -#endif -#ifndef _Pre_writable_size_ -#define _Pre_writable_size_(size) -#endif -#ifndef _Pre_writeonly_ -#define _Pre_writeonly_ -#endif -#ifndef _Pre_z_ -#define _Pre_z_ -#endif -#ifndef _Pre_z_bytecap_ -#define _Pre_z_bytecap_(size) -#endif -#ifndef _Pre_z_bytecap_c_ -#define _Pre_z_bytecap_c_(size) -#endif -#ifndef _Pre_z_bytecap_x_ -#define _Pre_z_bytecap_x_(size) -#endif -#ifndef _Pre_z_cap_ -#define _Pre_z_cap_(size) -#endif -#ifndef _Pre_z_cap_c_ -#define _Pre_z_cap_c_(size) -#endif -#ifndef _Pre_z_cap_x_ -#define _Pre_z_cap_x_(size) -#endif -#ifndef _Prepost_bytecount_ -#define _Prepost_bytecount_(size) -#endif -#ifndef _Prepost_bytecount_c_ -#define _Prepost_bytecount_c_(size) -#endif -#ifndef _Prepost_bytecount_x_ -#define _Prepost_bytecount_x_(size) -#endif -#ifndef _Prepost_count_ -#define _Prepost_count_(size) -#endif -#ifndef _Prepost_count_c_ -#define _Prepost_count_c_(size) -#endif -#ifndef _Prepost_count_x_ -#define _Prepost_count_x_(size) -#endif -#ifndef _Prepost_opt_bytecount_ -#define _Prepost_opt_bytecount_(size) -#endif -#ifndef _Prepost_opt_bytecount_c_ -#define _Prepost_opt_bytecount_c_(size) -#endif -#ifndef _Prepost_opt_bytecount_x_ -#define _Prepost_opt_bytecount_x_(size) -#endif -#ifndef _Prepost_opt_count_ -#define _Prepost_opt_count_(size) -#endif -#ifndef _Prepost_opt_count_c_ -#define _Prepost_opt_count_c_(size) -#endif -#ifndef _Prepost_opt_count_x_ -#define _Prepost_opt_count_x_(size) -#endif -#ifndef _Prepost_opt_valid_ -#define _Prepost_opt_valid_ -#endif -#ifndef _Prepost_opt_z_ -#define _Prepost_opt_z_ -#endif -#ifndef _Prepost_valid_ -#define _Prepost_valid_ -#endif -#ifndef _Prepost_z_ -#define _Prepost_z_ -#endif -#ifndef _Printf_format_string_ -#define _Printf_format_string_ -#endif -#ifndef _Printf_format_string_params_ -#define _Printf_format_string_params_(x) -#endif -#ifndef _Raises_SEH_exception_ -#define _Raises_SEH_exception_ -#endif -#ifndef _Readable_bytes_ -#define _Readable_bytes_(size) -#endif -#ifndef _Readable_elements_ -#define _Readable_elements_(size) -#endif -#ifndef _Releases_exclusive_lock_ -#define _Releases_exclusive_lock_(lock) -#endif -#ifndef _Releases_lock_ -#define _Releases_lock_(lock) -#endif -#ifndef _Releases_nonreentrant_lock_ -#define _Releases_nonreentrant_lock_(lock) -#endif -#ifndef _Releases_shared_lock_ -#define _Releases_shared_lock_(lock) -#endif -#ifndef _Requires_exclusive_lock_held_ -#define _Requires_exclusive_lock_held_(lock) -#endif -#ifndef _Requires_lock_held_ -#define _Requires_lock_held_(lock) -#endif -#ifndef _Requires_lock_not_held_ -#define _Requires_lock_not_held_(lock) -#endif -#ifndef _Requires_no_locks_held_ -#define _Requires_no_locks_held_ -#endif -#ifndef _Requires_shared_lock_held_ -#define _Requires_shared_lock_held_(lock) -#endif -#ifndef _Reserved_ -#define _Reserved_ -#endif -#ifndef _Result_nullonfailure_ -#define _Result_nullonfailure_ -#endif -#ifndef _Result_zeroonfailure_ -#define _Result_zeroonfailure_ -#endif -#ifndef _Ret_ -#define _Ret_ -#endif -#ifndef _Ret_bound_ -#define _Ret_bound_ -#endif -#ifndef _Ret_bytecap_ -#define _Ret_bytecap_(size) -#endif -#ifndef _Ret_bytecap_c_ -#define _Ret_bytecap_c_(size) -#endif -#ifndef _Ret_bytecap_x_ -#define _Ret_bytecap_x_(size) -#endif -#ifndef _Ret_bytecount_ -#define _Ret_bytecount_(size) -#endif -#ifndef _Ret_bytecount_c_ -#define _Ret_bytecount_c_(size) -#endif -#ifndef _Ret_bytecount_x_ -#define _Ret_bytecount_x_(size) -#endif -#ifndef _Ret_cap_ -#define _Ret_cap_(size) -#endif -#ifndef _Ret_cap_c_ -#define _Ret_cap_c_(size) -#endif -#ifndef _Ret_cap_x_ -#define _Ret_cap_x_(size) -#endif -#ifndef _Ret_count_ -#define _Ret_count_(size) -#endif -#ifndef _Ret_count_c_ -#define _Ret_count_c_(size) -#endif -#ifndef _Ret_count_x_ -#define _Ret_count_x_(size) -#endif -#ifndef _Ret_maybenull_ -#define _Ret_maybenull_ -#endif -#ifndef _Ret_maybenull_z_ -#define _Ret_maybenull_z_ -#endif -#ifndef _Ret_notnull_ -#define _Ret_notnull_ -#endif -#ifndef _Ret_null_ -#define _Ret_null_ -#endif -#ifndef _Ret_opt_ -#define _Ret_opt_ -#endif -#ifndef _Ret_opt_bytecap_ -#define _Ret_opt_bytecap_(size) -#endif -#ifndef _Ret_opt_bytecap_c_ -#define _Ret_opt_bytecap_c_(size) -#endif -#ifndef _Ret_opt_bytecap_x_ -#define _Ret_opt_bytecap_x_(size) -#endif -#ifndef _Ret_opt_bytecount_ -#define _Ret_opt_bytecount_(size) -#endif -#ifndef _Ret_opt_bytecount_c_ -#define _Ret_opt_bytecount_c_(size) -#endif -#ifndef _Ret_opt_bytecount_x_ -#define _Ret_opt_bytecount_x_(size) -#endif -#ifndef _Ret_opt_cap_ -#define _Ret_opt_cap_(size) -#endif -#ifndef _Ret_opt_cap_c_ -#define _Ret_opt_cap_c_(size) -#endif -#ifndef _Ret_opt_cap_x_ -#define _Ret_opt_cap_x_(size) -#endif -#ifndef _Ret_opt_count_ -#define _Ret_opt_count_(size) -#endif -#ifndef _Ret_opt_count_c_ -#define _Ret_opt_count_c_(size) -#endif -#ifndef _Ret_opt_count_x_ -#define _Ret_opt_count_x_(size) -#endif -#ifndef _Ret_opt_valid_ -#define _Ret_opt_valid_ -#endif -#ifndef _Ret_opt_z_ -#define _Ret_opt_z_ -#endif -#ifndef _Ret_opt_z_bytecap_ -#define _Ret_opt_z_bytecap_(size) -#endif -#ifndef _Ret_opt_z_bytecount_ -#define _Ret_opt_z_bytecount_(size) -#endif -#ifndef _Ret_opt_z_cap_ -#define _Ret_opt_z_cap_(size) -#endif -#ifndef _Ret_opt_z_count_ -#define _Ret_opt_z_count_(size) -#endif -#ifndef _Ret_range_ -#define _Ret_range_(lb,ub) -#endif -#ifndef _Ret_valid_ -#define _Ret_valid_ -#endif -#ifndef _Ret_writes_ -#define _Ret_writes_(size) -#endif -#ifndef _Ret_writes_bytes_ -#define _Ret_writes_bytes_(size) -#endif -#ifndef _Ret_writes_bytes_maybenull_ -#define _Ret_writes_bytes_maybenull_(size) -#endif -#ifndef _Ret_writes_bytes_to_ -#define _Ret_writes_bytes_to_(size,count) -#endif -#ifndef _Ret_writes_bytes_to_maybenull_ -#define _Ret_writes_bytes_to_maybenull_(size,count) -#endif -#ifndef _Ret_writes_maybenull_ -#define _Ret_writes_maybenull_(size) -#endif -#ifndef _Ret_writes_maybenull_z_ -#define _Ret_writes_maybenull_z_(size) -#endif -#ifndef _Ret_writes_to_ -#define _Ret_writes_to_(size,count) -#endif -#ifndef _Ret_writes_to_maybenull_ -#define _Ret_writes_to_maybenull_(size,count) -#endif -#ifndef _Ret_writes_z_ -#define _Ret_writes_z_(size) -#endif -#ifndef _Ret_z_ -#define _Ret_z_ -#endif -#ifndef _Ret_z_bytecap_ -#define _Ret_z_bytecap_(size) -#endif -#ifndef _Ret_z_bytecount_ -#define _Ret_z_bytecount_(size) -#endif -#ifndef _Ret_z_cap_ -#define _Ret_z_cap_(size) -#endif -#ifndef _Ret_z_count_ -#define _Ret_z_count_(size) -#endif -#ifndef _Return_type_success_ -#define _Return_type_success_(expr) -#endif -#ifndef _Scanf_format_string_ -#define _Scanf_format_string_ -#endif -#ifndef _Scanf_format_string_params_ -#define _Scanf_format_string_params_(x) -#endif -#ifndef _Scanf_s_format_string_ -#define _Scanf_s_format_string_ -#endif -#ifndef _Scanf_s_format_string_params_ -#define _Scanf_s_format_string_params_(x) -#endif -#ifndef _Strict_type_match_ -#define _Strict_type_match_ -#endif -#ifndef _Struct_size_bytes_ -#define _Struct_size_bytes_(size) -#endif -#ifndef _Success_ -#define _Success_(expr) -#endif -#ifndef _Unchanged_ -#define _Unchanged_(e) -#endif -#ifndef _Use_decl_annotations_ -#define _Use_decl_annotations_ -#endif -#ifndef _Valid_ -#define _Valid_ -#endif -#ifndef _When_ -#define _When_(expr, annos) -#endif -#ifndef _Writable_bytes_ -#define _Writable_bytes_(size) -#endif -#ifndef _Writable_elements_ -#define _Writable_elements_(size) -#endif -#ifndef _Write_guarded_by_ -#define _Write_guarded_by_(lock) -#endif - -#endif /* OS_DECL_ATTRIBUTES_SAL_H */ diff --git a/src/os/include/os/os_defs.h b/src/os/include/os/os_defs.h deleted file mode 100644 index f9e59fe..0000000 --- a/src/os/include/os/os_defs.h +++ /dev/null @@ -1,213 +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 OS_DEFS_H -#define OS_DEFS_H - -#define OS_LITTLE_ENDIAN 1 -#define OS_BIG_ENDIAN 2 - -#if OS_ENDIANNESS != OS_LITTLE_ENDIAN && OS_ENDIANNESS != OS_BIG_ENDIAN -#error "OS_ENDIANNESS not set correctly" -#endif - -#include "os/os_decl_attributes.h" - -#if defined (__cplusplus) -extern "C" { -#endif - - /* \brief OS_FUNCTION provides undecorated function name of current function - * - * Behavior of OS_FUNCTION outside a function is undefined. Note that - * implementations differ across compilers and compiler versions. It might be - * implemented as either a string literal or a constant variable. - */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) -# define OS_FUNCTION __func__ -#elif defined(__cplusplus) && (__cplusplus >= 201103) -# define OS_FUNCTION __func__ -#elif defined(__GNUC__) -# define OS_FUNCTION __FUNCTION__ -#elif defined(__clang__) -# define OS_FUNCTION __FUNCTION__ -#elif defined(__ghs__) -# define OS_FUNCTION __FUNCTION__ -#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) - /* Solaris Studio had support for __func__ before it supported __FUNCTION__. - Compiler flag -features=extensions is required on older versions. */ -# define OS_FUNCTION __func__ -#elif defined(__FUNCTION__) - /* Visual Studio */ -# define OS_FUNCTION __FUNCTION__ -#elif defined(__vxworks) - /* At least versions 2.9.6 and 3.3.4 of the GNU C Preprocessor only define - __GNUC__ if the entire GNU C compiler is in use. VxWorks 5.5 targets invoke - the preprocessor separately resulting in __GNUC__ not being defined. */ -# define OS_FUNCTION __FUNCTION__ -#else -# warning "OS_FUNCTION is not supported" -#endif - - /* \brief OS_PRETTY_FUNCTION provides function signature of current function - * - * See comments on OS_FUNCTION for details. - */ -#if defined(__GNUC__) -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif defined(__clang__) -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif defined(__ghs__) -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif (defined(__SUNPRO_C) && __SUNPRO_C >= 0x5100) - /* Solaris Studio supports __PRETTY_FUNCTION__ in C since version 12.1 */ -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5120) - /* Solaris Studio supports __PRETTY_FUNCTION__ in C++ since version 12.3 */ -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#elif defined(__FUNCSIG__) - /* Visual Studio */ -# define OS_PRETTY_FUNCTION __FUNCSIG__ -#elif defined(__vxworks) - /* See comments on __vxworks macro above. */ -# define OS_PRETTY_FUNCTION __PRETTY_FUNCTION__ -#else - /* Do not warn user about OS_PRETTY_FUNCTION falling back to OS_FUNCTION. - # warning "OS_PRETTY_FUNCTION is not supported, using OS_FUNCTION" - */ -# define OS_PRETTY_FUNCTION OS_FUNCTION -#endif - -#if defined(__GNUC__) -#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 -#define OSPL_GCC_DIAG_STR(s) #s -#define OSPL_GCC_DIAG_JOINSTR(x,y) OSPL_GCC_DIAG_STR(x ## y) -#define OSPL_GCC_DIAG_DO_PRAGMA(x) _Pragma (#x) -#define OSPL_GCC_DIAG_PRAGMA(x) OSPL_GCC_DIAG_DO_PRAGMA(GCC diagnostic x) -#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 -#define OS_WARNING_GNUC_OFF(x) OSPL_GCC_DIAG_PRAGMA(push) OSPL_GCC_DIAG_PRAGMA(ignored OSPL_GCC_DIAG_JOINSTR(-W,x)) -#define OS_WARNING_GNUC_ON(x) OSPL_GCC_DIAG_PRAGMA(pop) -#else -#define OS_WARNING_GNUC_OFF(x) OSPL_GCC_DIAG_PRAGMA(ignored OSPL_GCC_DIAG_JOINSTR(-W,x)) -#define OS_WARNING_GNUC_ON(x) OSPL_GCC_DIAG_PRAGMA(warning OSPL_GCC_DIAG_JOINSTR(-W,x)) -#endif -#else -#define OS_WARNING_GNUC_OFF(x) -#define OS_WARNING_GNUC_ON(x) -#endif -#else -#define OS_WARNING_GNUC_OFF(x) -#define OS_WARNING_GNUC_ON(x) -#endif - -#ifdef _MSC_VER - -#define OS_WARNING_MSVC_OFF(x) \ -__pragma (warning(push)) \ -__pragma (warning(disable: ## x)) - -#define OS_WARNING_MSVC_ON(x) \ -__pragma (warning(pop)) -#else -#define OS_WARNING_MSVC_OFF(x) -#define OS_WARNING_MSVC_ON(x) -#endif - -/** - * \brief Calculate maximum value of an integer type - * - * A somewhat complex, but efficient way to calculate the maximum value of an - * integer type at compile time. - * - * For unsigned numerical types the first part up to XOR is enough. The second - * part is to make up for signed numerical types. - */ -#define OS_MAX_INTEGER(T) \ - ((T)(((T)~0) ^ ((T)!((T)~0 > 0) << (CHAR_BIT * sizeof(T) - 1)))) -/** - * \brief Calculate minimum value of an integer type - */ -#define OS_MIN_INTEGER(T) \ - ((-OS_MAX_INTEGER(T)) - 1) - -#if !defined (OS_UNUSED_ARG) -#define OS_UNUSED_ARG(a) (void) (a) -#endif - - /** \brief Time structure definition - */ - typedef struct os_time { - /** Seconds since the Unix epoch; 1-jan-1970 00:00:00 (UTC) */ - os_timeSec tv_sec; - /** Number of nanoseconds since the Unix epoch, modulo 10^9. */ - int32_t tv_nsec; - /** os_time can be used for a duration type with the following - semantics for negative durations: tv_sec specifies the - sign of the duration, tv_nsec is always positive and added - to the real value (thus real value is tv_sec+tv_nsec/10^9, - for example { -1, 500000000 } is -0.5 seconds) */ - } os_time; - - /** \brief Types on which we define atomic operations. The 64-bit - * types are always defined, even if we don't really support atomic - * operations on them. - */ - typedef struct { uint32_t v; } os_atomic_uint32_t; - typedef struct { uint64_t v; } os_atomic_uint64_t; - typedef struct { uintptr_t v; } os_atomic_uintptr_t; - typedef os_atomic_uintptr_t os_atomic_voidp_t; - - /** \brief Initializers for the types on which atomic operations are - defined. - */ -#define OS_ATOMIC_UINT32_INIT(v) { (v) } -#define OS_ATOMIC_UINT64_INIT(v) { (v) } -#define OS_ATOMIC_UINTPTR_INIT(v) { (v) } -#define OS_ATOMIC_VOIDP_INIT(v) { (uintptr_t) (v) } - - /** \brief Definition of the service return values */ - typedef _Return_type_success_(return == os_resultSuccess) enum os_result { - /** The service is successfully completed */ - os_resultSuccess, - /** A resource was not found */ - os_resultUnavailable, - /** The service is timed out */ - os_resultTimeout, - /** The requested resource is busy */ - os_resultBusy, - /** An invalid argument is passed */ - os_resultInvalid, - /** The operating system returned a failure */ - os_resultFail - } os_result; - -#if defined(_MSC_VER) - /* Thread-local storage using __declspec(thread) on Windows versions before - Vista and Server 2008 works in DLLs if they are bound to the executable, - it does not work if the library is loaded using LoadLibrary. */ -#define os_threadLocal __declspec(thread) -#elif defined(__GNUC__) || (defined(__clang__) && __clang_major__ >= 2) - /* GCC supports Thread-local storage for x86 since version 3.3. Clang - supports Thread-local storage since version 2.0. */ - /* VxWorks 7 supports __thread for both GCC and DIAB, older versions may - support it as well, but that is not verified. */ -#define os_threadLocal __thread -#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) -#define os_threadLocal __thread -#else -#error "os_threadLocal is not supported" -#endif - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/os_errno.h b/src/os/include/os/os_errno.h deleted file mode 100644 index 5ee172d..0000000 --- a/src/os/include/os/os_errno.h +++ /dev/null @@ -1,107 +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 OS_ERRNO_H -#define OS_ERRNO_H - -#if defined (__cplusplus) -extern "C" { -#endif - -#include "os/os_defs.h" - -#if (defined(WIN32) || defined(WINCE)) -#include -#endif - -#include /* 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 - * - * @return Error code - */ - OSAPI_EXPORT int - os_getErrno ( - void); - - /** \brief Set error code to specified value - * - * @return void - * @param err Error code - */ - OSAPI_EXPORT void - 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 - * - * @return 0 success. On error a (positive) error number is returned - * @param err Error number - * @param buf Buffer to store description in - * @oaram bufsz Number of bytes available in buf - */ - OSAPI_EXPORT int - os_strerror_r ( - _In_ int err, - _Out_writes_z_(bufsz) char *buf, - _In_ size_t bufsz); - - /** - * \brief Get description for specified error code - * - * @return Pointer to string allocated in thread specific memory - * @param err Error number - */ - OSAPI_EXPORT const char * - os_strerror ( - _In_ int err); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_ERRNO_H */ diff --git a/src/os/include/os/os_heap.h b/src/os/include/os/os_heap.h deleted file mode 100644 index 834faab..0000000 --- a/src/os/include/os/os_heap.h +++ /dev/null @@ -1,167 +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 - */ -/**************************************************************** - * Interface definition for OS layer heap memory managment * - ****************************************************************/ - -/** \file os_heap.h - * \brief Heap memory management - * - * os_heap.h provides abstraction to heap memory management functions. - */ - -#ifndef OS_HEAP_H -#define OS_HEAP_H - -#if defined (__cplusplus) -extern "C" { -#endif - - /* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - - /** \brief Allocate memory from heap - * - * Allocate memory from heap with the identified size. The returned pointer must be free'd with - * os_free. If size is 0, os_malloc_s will still return a non-NULL pointer which must be free'd - * with os_free. - * - * Possible Results: - * - returns pointer to allocated memory, abort() if out of memory detected - */ - _Check_return_ _Ret_bytecap_(size) - OSAPI_EXPORT void * os_malloc(_In_ size_t size); - - /** \brief Allocate memory from heap - * - * Allocate memory from heap with the identified size. The returned pointer must be free'd with - * os_free. If size is 0, os_malloc_s will still return a non-NULL pointer which must be free'd - * with os_free. - * - * Possible Results: - * - returns pointer to allocated memory, or null if out of memory - */ - _Check_return_ _Ret_opt_bytecap_(size) - OSAPI_EXPORT void * os_malloc_s(_In_ size_t size); - - /** \brief Allocate zeroed memory from heap - * - * Allocate memory from heap with the identified size and initialized to zero. The returned - * pointer must be free'd with os_free. If size is 0, os_malloc_0_s will still return a non-NULL - * pointer which must be free'd with os_free. - * - * Possible Results: - * - returns pointer to allocated zeroed memory, abort() if out of memory detected - */ - _Check_return_ - _Ret_bytecount_(size) - OSAPI_EXPORT void * - os_malloc_0(_In_ size_t size) - __attribute_malloc__ - __attribute_alloc_size__((1)); - - /** \brief Allocate zeroed memory from heap - * - * Allocate memory from heap with the identified size and initialized to zero. The returned - * pointer must be free'd with os_free. If size is 0, os_malloc_0_s will still return a non-NULL - * pointer which must be free'd with os_free. - * - * Possible Results: - * - returns pointer to allocated zeroed memory, or null if out of memory - */ - _Check_return_ - _Ret_opt_bytecount_(size) - OSAPI_EXPORT void * - os_malloc_0_s(_In_ size_t size) - __attribute_malloc__ - __attribute_alloc_size__((1)); - - /** \brief Allocate memory from heap for an array with count elements of size size - * - * The allocated memory is initialized to zero. The returned pointer must be free'd - * with os_free. If size and/or count is 0, os_calloc will still return a non-NULL - * pointer which must be free'd with os_free. - * - * Possible Results: - * - returns pointer to allocated and zeroed memory, abort() if out of memory detected - */ - _Check_return_ - _Ret_bytecount_(count * size) - OSAPI_EXPORT void * - os_calloc(_In_ size_t count, - _In_ size_t size) - __attribute_malloc__; - - /** \brief Allocate memory from heap for an array with count elements of size size - * - * The allocated memory is initialized to zero. The returned pointer must be free'd - * with os_free. If size and/or count is 0, os_calloc_s will still return a non-NULL - * pointer which must be free'd with os_free. - * - * Possible Results: - * - returns pointer to allocated and zeroed memory, or null if out of memory - */ - _Check_return_ - _Ret_opt_bytecount_(count * size) - OSAPI_EXPORT void * - os_calloc_s(_In_ size_t count, - _In_ size_t size) - __attribute_malloc__; - - /** \brief Reallocate memory from heap - * - * Reallocate memory from heap. If memblk is NULL the function returns os_malloc_s(size). If - * size is 0, os_realloc_s free's the memory pointed to by memblk and returns a pointer as if - * os_malloc_s(0) was invoked. The returned pointer must be free'd with os_free. - * Possible Results: - * - return pointer to reallocated memory, abort() if out of memory detected - */ - _Check_return_ - _Ret_bytecap_(size) - OSAPI_EXPORT void * - os_realloc( - _Pre_maybenull_ _Post_ptr_invalid_ void *memblk, - _In_ size_t size) - __attribute_malloc__ - __attribute_alloc_size__((1)); - - /** \brief Reallocate memory from heap - * - * Reallocate memory from heap. If memblk is NULL the function returns os_malloc_s(size). If - * size is 0, os_realloc_s free's the memory pointed to by memblk and returns a pointer as if - * os_malloc_s(0) was invoked. The returned pointer must be free'd with os_free. - * Possible Results: - * - return pointer to reallocated memory, or null if out of memory . - */ - _Success_(return != NULL) - _Check_return_ - _Ret_opt_bytecap_(size) - OSAPI_EXPORT void * - os_realloc_s( - _Pre_maybenull_ _Post_ptr_invalid_ void *memblk, - _In_ size_t size) - __attribute_malloc__ - __attribute_alloc_size__((1)); - - /** \brief Free allocated memory and return it to heap - * - * Free the allocated memory pointed to by \b ptr - * and release it to the heap. When \b ptr is NULL, - * os_free will return without doing any action. - */ - OSAPI_EXPORT void - os_free(_Pre_maybenull_ _Post_ptr_invalid_ void *ptr); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_HEAP_H */ diff --git a/src/os/include/os/os_init.h b/src/os/include/os/os_init.h deleted file mode 100644 index 3cbc310..0000000 --- a/src/os/include/os/os_init.h +++ /dev/null @@ -1,22 +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 OS_INIT_H -#define OS_INIT_H - -void os_osInit(void); -void os_osExit(void); - -/* implemented by the platform-specific code */ -void os_osPlatformInit (void); -void os_osPlatformExit (void); - -#endif diff --git a/src/os/include/os/os_iter.h b/src/os/include/os/os_iter.h deleted file mode 100644 index ef71cc9..0000000 --- a/src/os/include/os/os_iter.h +++ /dev/null @@ -1,79 +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 OS_ITER_H -#define OS_ITER_H - -#if defined(__cplusplus) -extern "C" { -#endif - -typedef struct os_iter_s os_iter; /* opaque type */ - -_Check_return_ -_Ret_valid_ -OSAPI_EXPORT os_iter * -os_iterNew( - void); - -OSAPI_EXPORT void -os_iterFree( - _In_opt_ _Post_ptr_invalid_ os_iter *iter, - _In_opt_ void(*func)(_Inout_ void *)); - -OSAPI_EXPORT _Ret_range_(0, INT32_MAX) uint32_t -os_iterLength( - _In_ const os_iter *__restrict iter); - -/* Negative integers (borrowed from Python) can be used to access elements in - the iter. Most often it is used as a shorthand to access the last element. - i.e. os_iterOjbect(iter, -1) is functionally equivalent to - os_iterOjbect(iter, os_iterLength(iter) - 1) */ - -/* Special constant functionally equivalent to the value returned by - os_iterLength when passed as an index to os_iterInsert. INT32_MIN never - represents a valid negative index as it is exactly -(pow(2, n - 1)), whereas - the maximum positive value is exactly (pow(2, n - 1) - 1), therefore the - resulting index would always be negative */ -#define OS_ITER_LENGTH (INT32_MIN) - -OSAPI_EXPORT _Success_(return >= 0) _Ret_range_(-1, INT32_MAX) int32_t -os_iterInsert( - _Inout_ os_iter *iter, - _In_opt_ void *object, - _In_ int32_t index); - -#define os_iterPrepend(iter, ojbect) \ - os_iterInsert((iter), (object), 0) -#define os_iterAppend(iter, object) \ - os_iterInsert((iter), (object), OS_ITER_LENGTH) - -OSAPI_EXPORT _Ret_opt_valid_ void * -os_iterObject( - _In_ const os_iter *iter, - _In_range_(INT32_MIN+1, INT32_MAX) int32_t index); - -OSAPI_EXPORT _Ret_opt_valid_ void * -os_iterTake( - _Inout_ os_iter *iter, - _In_range_(INT32_MIN+1, INT32_MAX) int32_t index); - -OSAPI_EXPORT void -os_iterWalk( - _In_ const os_iter *iter, - _In_ void(*func)(_Inout_ void *obj, _Inout_opt_ void *arg), - _Inout_opt_ void *arg); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_ITER_H */ diff --git a/src/os/include/os/os_platform_public.h b/src/os/include/os/os_platform_public.h deleted file mode 100644 index ced8976..0000000 --- a/src/os/include/os/os_platform_public.h +++ /dev/null @@ -1,29 +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 OS_PLATFORM_PUBLIC_H -#define OS_PLATFORM_PUBLIC_H - -#if __linux__ == 1 - #include "os/posix/os_platform_public.h" -#elif defined(__VXWORKS__) - #include "os/posix/os_platform_public.h" -#elif defined(_MSC_VER) - #include "os/windows/os_platform_public.h" -#elif defined __APPLE__ - #include "os/posix/os_platform_public.h" -#elif defined __sun - #include "os/posix/os_platform_public.h" -#else - #error "Platform missing from os_public.h list" -#endif - -#endif diff --git a/src/os/include/os/os_process.h b/src/os/include/os/os_process.h deleted file mode 100644 index 262174f..0000000 --- a/src/os/include/os/os_process.h +++ /dev/null @@ -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 - */ -/**************************************************************** - * Interface definition for process management * - ****************************************************************/ - -/** \file os_process.h - * \brief Process management - process creation and termination - */ - -#ifndef OS_PROCESS_H -#define OS_PROCESS_H - -#if defined (__cplusplus) -extern "C" { -#endif - -#include "os/os_defs.h" -/* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - -/** \brief Return the process ID of the calling process - * - * Possible Results: - * - returns the process ID of the calling process - */ -OSAPI_EXPORT os_procId os_getpid(void); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_PROCESS_H */ diff --git a/src/os/include/os/os_public.h b/src/os/include/os/os_public.h deleted file mode 100644 index df54b90..0000000 --- a/src/os/include/os/os_public.h +++ /dev/null @@ -1,19 +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 OS_PUBLIC_H -#define OS_PUBLIC_H - -#include -#include "os_platform_public.h" -#include "os_decl_attributes.h" - -#endif diff --git a/src/os/include/os/os_rusage.h b/src/os/include/os/os_rusage.h deleted file mode 100644 index 19a0b3d..0000000 --- a/src/os/include/os/os_rusage.h +++ /dev/null @@ -1,35 +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 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 */ diff --git a/src/os/include/os/os_socket.h b/src/os/include/os/os_socket.h deleted file mode 100644 index 1b9f795..0000000 --- a/src/os/include/os/os_socket.h +++ /dev/null @@ -1,349 +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 OS_SOCKET_H -#define OS_SOCKET_H - -#ifndef OS_SOCKET_HAS_IPV6 -#error "OS_SOCKET_HAS_IPV6 should have been defined by os_platform_socket.h" -#endif -#ifndef OS_NO_SIOCGIFINDEX -#error "OS_NO_SIOCGIFINDEX should have been defined by os_platform_socket.h" -#endif -#ifndef OS_NO_NETLINK -#error "OS_NO_NETLINK should have been defined by os_platform_socket.h" -#endif -#ifndef OS_SOCKET_HAS_SSM -#error "OS_SOCKET_HAS_SSM should have been defined by os_platform_socket.h" -#endif - -#if defined (__cplusplus) -extern "C" { -#endif - - /* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - - /** - * @file - * @addtogroup OS_NET - * @{ - */ -#define OS_VALID_SOCKET(s) ((s) != OS_INVALID_SOCKET) - - /** - * Socket handle type. SOCKET on windows, int otherwise. - */ - - /* Indirecting all the socket types. Some IPv6 & protocol agnostic - stuff seems to be not always be available */ - - typedef struct sockaddr_in os_sockaddr_in; - typedef struct sockaddr os_sockaddr; - typedef struct sockaddr_storage os_sockaddr_storage; - -#if OS_SOCKET_HAS_IPV6 - typedef struct ipv6_mreq os_ipv6_mreq; - typedef struct in6_addr os_in6_addr; - - typedef struct sockaddr_in6 os_sockaddr_in6; - - 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") */ - -#define SD_FLAG_IS_SET(flags, flag) ((((uint32_t)(flags) & (uint32_t)(flag))) != 0U) - -#define OS_AF_NULL (-1) - - /** Network interface attributes */ - typedef struct os_ifaddrs_s { - struct os_ifaddrs_s *next; - char *name; - uint32_t index; - uint32_t flags; - os_sockaddr *addr; - os_sockaddr *netmask; - os_sockaddr *broadaddr; - } os_ifaddrs_t; - - /** - * @brief Get interface addresses - * - * Retrieve network interfaces available on the local system and store - * them in a linked list of os_ifaddrs_t structures. - * - * The data returned by os_getifaddrs() is dynamically allocated and should - * be freed using os_freeifaddrs when no longer needed. - * - * @param[in,out] ifap Address of first os_ifaddrs_t structure in the list. - * @param[in] afs NULL-terminated array of address families (AF_xyz) to - * restrict resulting set of network interfaces too. NULL to - * return all network interfaces for all supported address - * families. Terminate the array with OS_AF_NULL. - * - * @returns Returns zero on success or a valid errno value on error. - */ - OSAPI_EXPORT _Success_(return == 0) int - os_getifaddrs( - _Inout_ os_ifaddrs_t **ifap, - _In_opt_ const int *afs); - - /** - * @brief Free os_ifaddrs_t structure list allocated by os_getifaddrs() - * - * @param[in] Address of first os_ifaddrs_t structure in the list. - */ - OSAPI_EXPORT void - os_freeifaddrs( - _Pre_maybenull_ _Post_ptr_invalid_ os_ifaddrs_t *ifa); - - OSAPI_EXPORT os_socket - os_sockNew( - int domain, /* AF_INET */ - int type /* SOCK_DGRAM */); - - OSAPI_EXPORT os_result - os_sockBind( - os_socket s, - const struct sockaddr *name, - uint32_t namelen); - - OSAPI_EXPORT os_result - os_sockGetsockname( - os_socket s, - const struct sockaddr *name, - uint32_t namelen); - - OSAPI_EXPORT os_result - os_sockSendto( - os_socket s, - const void *msg, - size_t len, - const struct sockaddr *to, - size_t tolen, - size_t *bytesSent); - - OSAPI_EXPORT os_result - os_sockRecvfrom( - os_socket s, - void *buf, - size_t len, - struct sockaddr *from, - size_t *fromlen, - size_t *bytesRead); - - OSAPI_EXPORT os_result - os_sockGetsockopt( - os_socket s, - int32_t level, /* SOL_SOCKET */ - int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */ - void *optval, - uint32_t *optlen); - - OSAPI_EXPORT os_result - os_sockSetsockopt( - os_socket s, - int32_t level, /* SOL_SOCKET */ - int32_t optname, /* SO_REUSEADDR, SO_DONTROUTE, SO_BROADCAST, SO_SNDBUF, SO_RCVBUF */ - const void *optval, - uint32_t optlen); - - - /** - * Sets the I/O on the socket to nonblocking if value is nonzero, - * or to blocking if value is 0. - * - * @param s The socket to set the I/O mode for - * @param nonblock Boolean indicating whether nonblocking mode should be enabled - * @return - os_resultSuccess: if the flag could be set successfully - * - os_resultBusy: if the flag could not be set because a blocking - * call is in progress on the socket - * - os_resultInvalid: if s is not a valid socket - * - os_resultFail: if an operating system error occurred - */ - OSAPI_EXPORT os_result - os_sockSetNonBlocking( - os_socket s, - bool nonblock); - - OSAPI_EXPORT os_result - os_sockFree( - os_socket s); - -#ifdef WIN32 -/* SOCKETs on Windows are NOT integers. The nfds parameter is only there for - compatibility, the implementation ignores it. Implicit casts will generate - warnings though, therefore os_sockSelect on Windows is a proxy macro that - discards the parameter */ -#define os_sockSelect(nfds, readfds, writefds, errorfds, timeout) \ - os__sockSelect((readfds), (writefds), (errorfds), (timeout)) - - OSAPI_EXPORT int32_t - os__sockSelect( - fd_set *readfds, - fd_set *writefds, - fd_set *errorfds, - os_time *timeout); -#else - OSAPI_EXPORT int32_t - os_sockSelect( - int32_t nfds, - fd_set *readfds, - fd_set *writefds, - fd_set *errorfds, - os_time *timeout); -#endif /* WIN32 */ - - /** - * Returns size of socket address. - * @param sa Socket address to return the size for. - * @return Size of the socket address based on the address family, or 0 if - * the address family is unknown. - * @pre sa is a valid os_sockaddr pointer. - */ - OSAPI_EXPORT size_t - os_sockaddr_get_size( - const os_sockaddr *const sa) __nonnull_all__; - - /** - * Retrieve port number from the given socket address. - * @param sa Socket address to retrieve the port from. - * @return Port number in host order. - * @pre sa is a valid os_sockaddr pointer. - */ - OSAPI_EXPORT uint16_t - os_sockaddr_get_port(const os_sockaddr *const sa) __nonnull_all__; - - /** - * Check if IP address of given socket address is unspecified. - * @param sa Socket address - * @return true if unspecified, false otherwise. - * @pre sa is a valid os_sockaddr pointer. - */ - OSAPI_EXPORT int - os_sockaddr_is_unspecified( - _In_ const os_sockaddr *__restrict sa) __nonnull_all__; - - /** - * 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); - -#ifdef OS_SOCKET_HAS_DNS - - typedef struct { - size_t naddrs; - os_sockaddr_storage addrs[]; - } os_hostent_t; - - /** - * Lookup addresses for given host name. - * - * @param[in] name Host name to resolve. - * @param[in] af Address family, either AF_INET, AF_INET6 or AF_UNSPEC. - * @param[out] hent Structure of type 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. - */ - OSAPI_EXPORT _Success_(return == 0) int - os_gethostbyname( - _In_z_ const char *name, - _In_ int af, - _Out_ os_hostent_t **hent); - -#endif /* OS_SOCKET_HAS_DNS */ - - /** - * 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 _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); - - /** - * @} - */ - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_SOCKET_H */ diff --git a/src/os/include/os/os_stdlib.h b/src/os/include/os/os_stdlib.h deleted file mode 100644 index bc4ce19..0000000 --- a/src/os/include/os/os_stdlib.h +++ /dev/null @@ -1,595 +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 - */ -/**************************************************************** - * Interface definition for standard operating system features * - ****************************************************************/ - -/** \file os_stdlib.h - * \brief standard operating system features - */ - -#ifndef OS_STDLIB_H -#define OS_STDLIB_H - -#include -#include -#include "os/os_defs.h" - -#if defined (__cplusplus) -extern "C" { -#endif - /* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - - /** \brief Get host or processor name - * - * Possible Results: - * - assertion failure: hostname = NULL - * - returns os_resultSuccess if - * hostname correctly identifies the name of the host - * - returns os_resultFail if - * actual hostname is longer than buffersize - */ - OSAPI_EXPORT os_result - os_gethostname( - char *hostname, - size_t buffersize); - - /** \brief Get environment variable definition - * - * Postcondition: - * - the pointer returned is only to be accessed readonly - * - * Possible Results: - * - assertion failure: variable = NULL - * - returns pointer to value of variable if - * variable is found - * - returns NULL if - * variable is not found - * - * TODO CHAM-379 : Coverity generates a tainted string. - * For now, the Coverity warning reported intentional in Coverity. - */ - OSAPI_EXPORT _Ret_opt_z_ const char * - os_getenv( - _In_z_ const char *variable); - - /** \brief Set environment variable definition - * - * Precondition: - * - variable_definition follows the format "=" - * - * Possible Results: - * - assertion failure: variable_definition = NULL - * - returns os_resultSuccess if - * environment variable is set according the variable_definition - * - returns os_resultFail if - * environment variable could not be set according the - * variable_definition - * @deprecated This function is a thin, bordering on anorexic, wrapper to - * putenv. putenv behaviour varies from unsafe to leaky across different - * platforms. Use ::os_setenv instead. - */ - OSAPI_EXPORT os_result - os_putenv( - char *variable_definition); - - /** \brief rindex wrapper - * - * because not all operating systems have - * interfaces to rindex a wrapper is made - * - * Precondition: - * None - * - * Possible results: - * - return NULL if - * char c is not found in string s - * - return address of last occurance of c in s - */ - OSAPI_EXPORT char * - os_rindex( - const char *s, - int c); - - /** \brief index wrapper - * - * because not all operating systems have - * interfaces to index a wrapper is made - * - * Precondition: - * None - * - * Possible results: - * - return NULL if - * char c is not found in string s - * - return address of first occurance of c in s - */ - OSAPI_EXPORT char * - os_index( - const char *s, - int c); - - /** \brief strdup wrapper - * - * because not all operating systems have - * interfaces to strdup a wrapper is made - * - * Precondition: - * None - * Postcondition: - * The allocated string must be freed using os_free - * - * Possible results: - * - return duplicate of the string s1 allocated via - * os_malloc - */ - _Ret_z_ - _Check_return_ - OSAPI_EXPORT char * - os_strdup( - _In_z_ const char *s1) __nonnull_all__ - __attribute_malloc__ - __attribute_returns_nonnull__ - __attribute_warn_unused_result__; - - void * - os_memdup(const void *src, size_t n); - - /** \brief os_strsep wrapper - * - * See strsep() - */ - OSAPI_EXPORT char * - os_strsep( - char **stringp, - const char *delim); - - /** \brief write a formatted string to a newly allocated buffer - */ - OSAPI_EXPORT int - os_asprintf( - char **strp, - const char *fmt, - ...); - - /** \brief os_vsnprintf wrapper - * - * Microsoft generates deprected warnings for vsnprintf, - * wrapper removes warnings for win32 - * - * Precondition: - * None - * Postcondition: - * None - * - * Possible results: - * - os_vsnprintf() does not write more than size bytes (including the trailing '\0'). - * If the output was truncated due to this limit then the return value is the - * number of characters (not including the trailing '\0') which would have been - * written to the final string if enough space had been available. - * Thus, a return value of size or more means that the output was truncated. - */ - - OSAPI_EXPORT int - os_vsnprintf( - char *str, - size_t size, - const char *format, - va_list args); - - /** \brief strtoll wrapper - * - * Translate string str to long long value considering base, - * and sign. If base is 0, base is determined from - * str ([1-9]+ base = 10, 0x[0-9]+ base = 16, - * 0X[0-9]+ base = 16, 0[0-9] base = 8). - * - * Precondition: - * errno is set to 0 - * - * Possible results: - * - return 0 and errno == EINVAL in case of conversion error - * - return OS_LLONG_MIN and errno == ERANGE - * - return OS_LLONG_MAX and errno == ERANGE - * - return value(str) - */ - OSAPI_EXPORT long long - os_strtoll( - const char *str, - char **endptr, - int32_t base); - - /** \brief strtoull wrapper - * - * Translate string str to unsigned long long value considering - * base. If base is 0, base is determined from - * str ([1-9]+ base = 10, 0x[0-9]+ base = 16, - * 0X[0-9]+ base = 16, 0[0-9] base = 8). - * - * Precondition: - * errno is set to 0 - * - * Possible results: - * - return 0 and errno == EINVAL in case of conversion error - * - return OS_ULLONG_MIN and errno == ERANGE - * - return OS_ULLONG_MAX and errno == ERANGE - * - return value(str) - */ - OSAPI_EXPORT unsigned long long - os_strtoull( - const char *str, - char **endptr, - int32_t base); - - /** \brief atoll wrapper - * - * Translate string to long long value considering base 10. - * - * Precondition: - * errno is set to 0 - * - * Possible results: - * - return os_strtoll(str, 10) - */ - OSAPI_EXPORT long long - os_atoll( - const char *str); - - /** \brief atoull wrapper - * - * Translate string to unsigned long long value considering base 10. - * - * Precondition: - * errno is set to 0 - * - * Possible results: - * - return os_strtoll(str, 10) - */ - OSAPI_EXPORT unsigned long long - os_atoull( - const char *str); - - /** \brief lltostr wrapper - * - * Translate long long value into string representation based - * on radix 10. - * - * Precondition: - * none - * - * Possible results: - * - return 0 and errno == EINVAL in case of conversion error - * - return value(str) - */ - OSAPI_EXPORT char * - os_lltostr( - long long num, - char *str, - size_t len, - char **endptr); - - /** \brief ulltostr wrapper - * - * Translate unsigned long long value into string representation based - * on radix 10. - * - * Precondition: - * none - * - * Possible results: - * - return 0 and errno == EINVAL in case of conversion error - * - return value(str) - */ - OSAPI_EXPORT char * - os_ulltostr( - unsigned long long num, - char *str, - size_t len, - char **endptr); - - /** \brief strtod wrapper - * - * Translate string to double value considering base 10. - * - * Normal strtod is locale dependent, meaning that if you - * provide "2.2" and lc_numeric is ',', then the result - * would be 2. This function makes sure that both "2.2" - * (which is mostly used) and "2,2" (which could be provided - * by applications) are translated to 2.2 when the locale - * indicates that lc_numeric is ','. - * - * Precondition: - * none - * - * Possible results: - * - return value(str) - */ - OSAPI_EXPORT double - os_strtod(const char *nptr, char **endptr); - - /** \brief strtof wrapper - * - * Translate string to float value considering base 10. - * - * Normal strtof is locale dependent, meaning that if you - * provide "2.2" and lc_numeric is ',', then the result - * would be 2. This function makes sure that both "2.2" - * (which is mostly used) and "2,2" (which could be provided - * by applications) are translated to 2.2 when the locale - * indicates that lc_numeric is ','. - * - * Precondition: - * none - * - * Possible results: - * - return value(str) - */ - OSAPI_EXPORT float - os_strtof(const char *nptr, char **endptr); - - /** \brief os_strtod mirror - * - * Translate double to string considering base 10. - * - * The function dtostr doesn't exists and can be done by - * snprintf((char*)dst, "%f", (double)src). - * But like strtod, snprint is locale dependent, meaning - * that if you provide 2.2 and lc_numeric is ',' then the - * result would be "2,2". This comma can cause problems - * when serializing data to other nodes with different - * locales. - * This function makes sure that 2.2 is translated into - * "2.2", whatever lc_numeric is set ('.' or ','). - * - * Precondition: - * none - * - * Possible results: - * - return value(str) - */ - OSAPI_EXPORT int - os_dtostr(double src, char *str, size_t size); - - /** \brief os_strtof mirror - * - * Translate float to string considering base 10. - * - * The function ftostr doesn't exists and can be done by - * snprintf((char*)dst, "%f", (float)src). - * But like strtof, snprint is locale dependent, meaning - * that if you provide 2.2 and lc_numeric is ',' then the - * result would be "2,2". This comma can cause problems - * when serializing data to other nodes with different - * locales. - * This function makes sure that 2.2 is translated into - * "2.2", whatever lc_numeric is set ('.' or ','). - * - * Precondition: - * none - * - * Possible results: - * - return value(str) - */ - OSAPI_EXPORT int - os_ftostr(float src, char *str, size_t size); - - /** \brief strcasecm wrapper - * - * Compare 2 strings conform strcasecmp - * - * Precondition: - * none - * - * Possible results: - * - return 0 and s1 equals s2 - * - return <0 and s1 is less than s2 - * - return >0 and s1 is greater than s2 - */ - OSAPI_EXPORT int - os_strcasecmp( - const char *s1, - const char *s2); - - /** \brief strncasecm wrapper - * - * Compare 2 strings conform strncasecmp - * - * Precondition: - * none - * - * Possible results: - * - return 0 and s1 equals s2 (maximum the first n characters) - * - return <0 and s1 is less than s2 (maximum the first n characters) - * - return >0 and s1 is greater than s2 (maximum the first n characters) - */ - OSAPI_EXPORT int - os_strncasecmp( - const char *s1, - const char *s2, - size_t n); - - /** \brief strtok_r wrapper - * - * Tokenise strings based on delim - * - * Precondition: - * none - * - * Possible results: - * - return ptr to next token or NULL if there are no tokens left. - */ - OSAPI_EXPORT char * - os_strtok_r(char *str, const char *delim, char **saveptr); - - /** - * \brief writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd. - * - * - * Precondition: - * none - * - * Possible results: - * - On success, the number of bytes written is returned (zero indicates - * nothing was written). On error, -1 is returned - * - */ - OSAPI_EXPORT ssize_t os_write( - _In_ int fd, - _In_reads_bytes_(count) void const* buf, - _In_ size_t count); - - /** - * \brief binary search algorithm on an already sorted list. - * - * - * Precondition: - * list must be sorted in ascending order - * - * Possible results: - * - On success, the number the matching item is returned. When the item - * does not exist, NULL is returned. - * - */ - OSAPI_EXPORT void * - os_bsearch(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *)); - - /** - * \brief the os_getopt function gets the next option argument from the argument - * list specified by the argv and argc arguments. Normally these values come - * directly from the arguments received by main. - * - * The opts argument is a string that specifies the option characters that are - * valid for this program. An option character in this string can be followed - * by a colon (‘:’) to indicate that it takes a required argument. If an option - * character is followed by two colons (‘::’), its argument is optional; - * - * - * Precondition: - * none - * - * Possible results: - * - If an option was successfully found, then os_getopt() returns the option - * character. If all command-line options have been parsed, then - * os_getopt() returns -1. If os_getopt() encounters an option character that - * was not in opts, then '?' is returned. If os_getopt() encounters - * an option with a missing argument, then the return value depends on - * the first character in opts: if it is ':', then ':' is returned; - * otherwise '?' is returned. - * - */ - OSAPI_EXPORT int - os_getopt( - _In_range_(0, INT_MAX) int argc, - _In_reads_z_(argc) char **argv, - _In_z_ const char *opts); - - /** - * \brief the os_set_opterr function sets the value of the opterr variable. - * opterr is used as a flag to suppress an error message generated by - * getopt. When opterr is set to 0, it suppresses the error message generated - * by getopt when that function does not recognize an option character. - * - * Precondition: - * none - * - * Possible results: - * - No error information is returned. - * Set the value of the opterr variable. - * - */ - OSAPI_EXPORT void - os_set_opterr(_In_range_(0, INT_MAX) int err); - - /** - * \brief the os_get_opterr returns the value of the opterr variable. - * opterr is used as a flag to suppress an error message generated by - * getopt. When opterr is set to 0, it suppresses the error message generated - * by getopt when that function does not recognize an option character. - * - * Precondition: - * none - * - * Possible results: - * - return the value of the opterr variable. - * - */ - OSAPI_EXPORT int - os_get_opterr(void); - - /** - * \brief the os_set_optind function sets the value of the optind variable. - * - * Precondition: - * none - * - * Possible results: - * - No error information is returned. - * Set the value of the optind variable. - * - */ - OSAPI_EXPORT void - os_set_optind(_In_range_(0, INT_MAX) int index); - - /** - * \brief the os_get_optind function returns the value of the optind variable. - * optind is set by getopt to the index of the next element of the argv - * array to be processed. Once getopt has found all of the option arguments, - * this variable can be used to determine where the remaining non-option - * arguments begin. The initial value of this variable is 1. - * - * Precondition: - * none - * - * Possible results: - * - return the value of the optind variable. - * - */ - OSAPI_EXPORT int - os_get_optind(void); - - /** - * \brief the os_get_optopt function returns the value of the optopt variable. - * optopt holds the unknown option character when that option - * character is not recognized by getopt. - * - * Precondition: - * none - * - * Possible results: - * - return the value of the optopt variable. - * - */ - OSAPI_EXPORT int - os_get_optopt(void); - - /** - * \brief the os_get_optarg function returns the value of the optarg variable. - * optarg is set by getopt to point at the value of the option - * argument, for those options that accept arguments. - * - * Precondition: - * none - * - * Possible results: - * - return the value of the optarg variable. - * - */ - OSAPI_EXPORT char * - os_get_optarg(void); - - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_STDLIB_H */ diff --git a/src/os/include/os/os_strlcpy.h b/src/os/include/os/os_strlcpy.h deleted file mode 100644 index 4700ef5..0000000 --- a/src/os/include/os/os_strlcpy.h +++ /dev/null @@ -1,72 +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 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 */ diff --git a/src/os/include/os/os_sync.h b/src/os/include/os/os_sync.h deleted file mode 100644 index 29f550a..0000000 --- a/src/os/include/os/os_sync.h +++ /dev/null @@ -1,371 +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 OS_SYNC_H -#define OS_SYNC_H - -#if defined (__cplusplus) -extern "C" { -#endif - - /** \brief Sets the priority inheritance mode for mutexes - * that are created after this call. (only effective on - * platforms that support priority inheritance) - * - * Possible Results: - * - returns os_resultSuccess if - * mutex is successfuly initialized - * - returns os_resultSuccess - */ - OSAPI_EXPORT os_result - os_mutexSetPriorityInheritanceMode( - bool enabled); - - /** \brief Initialize the mutex - * - * Possible Results: - * - assertion failure: mutex = NULL - * - returns os_resultSuccess if - * mutex is successfuly initialized - * - returns os_resultFail if - * mutex is not initialized because of a failure - */ - OSAPI_EXPORT void - os_mutexInit( - _Out_ os_mutex *mutex) - __nonnull((1)); - - /** \brief Destroy the mutex - * - * Never returns on failure - */ - OSAPI_EXPORT void - os_mutexDestroy( - _Inout_ _Post_invalid_ os_mutex *mutex) - __nonnull_all__; - - /** \brief Acquire the mutex. - * - * If you need to detect an error, use os_mutexLock_s instead. - * - * @see os_mutexLock_s - */ - _Acquires_nonreentrant_lock_(&mutex->lock) - OSAPI_EXPORT void - os_mutexLock( - _Inout_ os_mutex *mutex) - __nonnull_all__; - - /** - * \brief Acquire the mutex. Returns whether the call succeeeded or an error - * occurred. - * - * Precondition: - * - mutex is not yet acquired by the calling thread - * - * Possible Results: - * - assertion failure: mutex = NULL - * - returns os_resultSuccess if - * mutex is acquired - * - returns os_resultFail if - * mutex is not acquired because of a failure - */ - _Check_return_ - _When_(return == os_resultSuccess, _Acquires_nonreentrant_lock_(&mutex->lock)) - OSAPI_EXPORT os_result - os_mutexLock_s( - _Inout_ os_mutex *mutex) - __nonnull_all__ - __attribute_warn_unused_result__; - - /** \brief Try to acquire the mutex, immediately return if the mutex - * is already acquired by another thread - * - * Precondition: - * - mutex is not yet acquired by the calling thread - * - * Possible Results: - * - assertion failure: mutex = NULL - * - returns os_resultSuccess if - * mutex is acquired - * - returns os_resultBusy if - * mutex is not acquired because it is already acquired - * by another thread - * - returns os_resultFail if - * mutex is not acquired because of a failure - */ - _Check_return_ - _When_(return == os_resultSuccess, _Acquires_nonreentrant_lock_(&mutex->lock)) - OSAPI_EXPORT os_result - os_mutexTryLock ( - _Inout_ os_mutex *mutex) - __nonnull_all__ - __attribute_warn_unused_result__; - - /** \brief Release the acquired mutex - */ - _Releases_nonreentrant_lock_(&mutex->lock) - OSAPI_EXPORT void - os_mutexUnlock ( - _Inout_ os_mutex *mutex) - __nonnull_all__; - - /** \brief Initialize the condition variable - * - * Possible Results: - * - returns os_resultSuccess if - * cond is successfuly initialized - * - returns os_resultFail if - * cond is not initialized and can not be used - */ - OSAPI_EXPORT void - os_condInit( - _Out_ os_cond *cond, - _In_ os_mutex *mutex) - __nonnull_all__; - - /** \brief Destroy the condition variable - */ - OSAPI_EXPORT void - os_condDestroy( - _Inout_ _Post_invalid_ os_cond *cond) - __nonnull_all__; - - /** \brief Wait for the condition - * - * Precondition: - * - mutex is acquired by the calling thread before calling - * os_condWait - * - * Postcondition: - * - mutex is still acquired by the calling thread and should - * be released by it - */ - OSAPI_EXPORT void - os_condWait( - os_cond *cond, - os_mutex *mutex) - __nonnull_all__; - - /** \brief Wait for the condition but return when the specified - * time has expired before the condition is triggered - * - * Precondition: - * - mutex is acquired by the calling thread before calling - * os_condTimedWait - * - * Postcondition: - * - mutex is still acquired by the calling thread and should - * be released by it - * - * Possible Results: - * - assertion failure: cond = NULL || mutex = NULL || - * time = NULL - * - returns os_resultSuccess if - * cond is triggered - * - returns os_resultTimeout if - * cond is timed out - * - returns os_resultFail if - * cond is not triggered nor is timed out but - * os_condTimedWait has returned because of a failure - */ - OSAPI_EXPORT os_result - os_condTimedWait( - os_cond *cond, - os_mutex *mutex, - const os_time *time) - __nonnull_all__; - - /** \brief Signal the condition and wakeup one thread waiting - * for the condition - * - * Precondition: - * - the mutex used with the condition in general should be - * acquired by the calling thread before setting the - * condition state and signalling - */ - OSAPI_EXPORT void - os_condSignal( - os_cond *cond) - __nonnull_all__; - - /** \brief Signal the condition and wakeup all thread waiting - * for the condition - * - * Precondition: - * - the mutex used with the condition in general should be - * acquired by the calling thread before setting the - * condition state and signalling - */ - OSAPI_EXPORT void - os_condBroadcast( - os_cond *cond) - __nonnull_all__; - - /** \brief Initialize the rwloc - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is successfuly initialized - * - returns os_resultFail - * rwlock is not initialized and can not be used - */ - OSAPI_EXPORT void - os_rwlockInit( - _Out_ os_rwlock *rwlock); - - /** \brief Destroy the rwlock - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is successfuly destroyed - * - returns os_resultBusy if - * rwlock is not destroyed because it is still claimed or referenced by a thread - * - returns os_resultFail if - * rwlock is not destroyed - */ - OSAPI_EXPORT void - os_rwlockDestroy( - _Inout_ _Post_invalid_ os_rwlock *rwlock); - - /** \brief Acquire the rwlock while intending to read only - * - * Precondition: - * - rwlock is not yet acquired by the calling thread - * - * Postcondition: - * - The data related to the critical section is not changed - * by the calling thread - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is acquired - * - returns os_resultFail if - * rwlock is not acquired because of a failure - */ - OSAPI_EXPORT void - os_rwlockRead( - os_rwlock *rwlock); - - /** \brief Acquire the rwlock while intending to write - * - * Precondition: - * - rwlock is not yet acquired by the calling thread - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is acquired - * - returns os_resultFail if - * rwlock is not acquired because of a failure - */ - OSAPI_EXPORT void - os_rwlockWrite( - os_rwlock *rwlock); - - /** \brief Try to acquire the rwlock while intending to read only - * - * Try to acquire the rwlock while intending to read only, - * immediately return if the mutex is acquired by - * another thread with the intention to write - * - * Precondition: - * - rwlock is not yet acquired by the calling thread - * - * Postcondition: - * - The data related to the critical section is not changed - * by the calling thread - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is acquired - * - returns os_resultBusy if - * rwlock is not acquired because it is already - * acquired by another thread with the intention to write - * - returns os_resultFail if - * rwlock is not acquired because of a failure - */ - OSAPI_EXPORT os_result - os_rwlockTryRead( - os_rwlock *rwlock); - - /** \brief Try to acquire the rwlock while intending to write - * - * Try to acquire the rwlock while intending to write, - * immediately return if the mutex is acquired by - * another thread, either for read or for write - * - * Precondition: - * - rwlock is not yet acquired by the calling thread - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is acquired - * - returns os_resultBusy if - * rwlock is not acquired because it is already - * acquired by another thread - * - returns os_resultFail if - * rwlock is not acquired because of a failure - */ - OSAPI_EXPORT os_result - os_rwlockTryWrite( - os_rwlock *rwlock); - - /** \brief Release the acquired rwlock - * - * Precondition: - * - rwlock is already acquired by the calling thread - * - * Possible Results: - * - assertion failure: rwlock = NULL - * - returns os_resultSuccess if - * rwlock is released - * - returns os_resultFail if - * rwlock is not released because of a failure - */ - OSAPI_EXPORT void - os_rwlockUnlock( - os_rwlock *rwlock); - - /* Initialization callback used by os_once */ - typedef void (*os_once_fn)(void); - - /** \brief Invoke init_fn exactly once for a given control - * - * The first thread calling os_once(...) with a given control will invoke the - * init_fn() with no arguments. Following calls with the same control will not - * invoke init_fn(). - * - * Precondition: - * - The control parameter is properly initialized with OS_ONCE_T_STATIC_INIT - * - * Postcondition: - * - On return init_fn() has completed exactly once for the given control. - */ - OSAPI_EXPORT void - os_once( - _Inout_ os_once_t *control, - _In_ os_once_fn init_fn); - - OSAPI_EXPORT os_mutex * - os_getSingletonMutex( - void); - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/os_thread.h b/src/os/include/os/os_thread.h deleted file mode 100644 index ecf958c..0000000 --- a/src/os/include/os/os_thread.h +++ /dev/null @@ -1,260 +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 - */ -/**************************************************************** - * Interface definition for thread management of SPLICE-DDS * - ****************************************************************/ - -#ifndef OS_THREAD_H -#define OS_THREAD_H - -/** \file os_thread.h - * \brief Thread management - create threads - */ - -#include "os/os_defs.h" - -#if defined (__cplusplus) -extern "C" { -#endif - - /* Number of slots in Thread Private Memory */ - - typedef enum os_threadMemoryIndex { - OS_THREAD_CLOCK_OFFSET, - OS_THREAD_UT_TRACE, - OS_THREAD_JVM, - OS_THREAD_PROTECT, - OS_THREAD_API_INFO, - OS_THREAD_WARNING, - OS_THREAD_ALLOCATOR_STATE, - OS_THREAD_NAME, - OS_THREAD_PROCESS_INFO, - OS_THREAD_STATE, /* Used for monitoring thread progress */ - OS_THREAD_STR_ERROR, - OS_THREAD_MEM_ARRAY_SIZE /* Number of slots in Thread Private Memory */ - } os_threadMemoryIndex; - - /** \brief Definition for a thread routine invoked on thread create. */ - typedef uint32_t (*os_threadRoutine)(void*); - - /** \brief Definition of the scheduling class */ - typedef enum os_schedClass { - /** Schedule processes and threads according a platform default. - * OS_SCHED_REALTIME for timesharing platforms and - * OS_SCHED_TIMESHARE for realtime platforms - */ - OS_SCHED_DEFAULT, - /** Schedule processes and threads on realtime basis, - * on most platforms implying: - * - Fixed Priority - * - Preemption - * - Either "First In First Out" or "Round Robin" - */ - OS_SCHED_REALTIME, - /** Schedule processes and threads on timesharing basis, - * on most platforms implying: - * - Dynamic Priority to guarantee fair share - * - Preemption - */ - OS_SCHED_TIMESHARE - } os_schedClass; - - /** \brief Definition of the thread attributes - */ - typedef struct os_threadAttr { - /** Specifies the scheduling class */ - os_schedClass schedClass; - /** Specifies the thread priority */ - int32_t schedPriority; - /** Specifies the thread stack size */ - uint32_t stackSize; - } os_threadAttr; - - /** \brief Internal structure used to store cleanup handlers (private) */ - typedef struct { - void (*func)(void *); - void *data; - } os_threadCleanup; - - /** \brief Create a new thread - * - * Creates a new thread of control that executes concurrently with - * the calling thread. The new thread applies the function start_routine - * passing it arg as first argument. - * - * The new thread terminates by returning from the start_routine function. - * The created thread is identified by the returned threadId. - * - * Possible Results: - * - assertion failure: threadId = NULL || name = NULL || - * threadAttr = NULL || start_routine = NULL - * - returns os_resultSuccess if - * the thread is successfuly created - * - returns os_resultFail if - * the thread is not created because of an failure - */ - OSAPI_EXPORT os_result - os_threadCreate( - _Out_ os_threadId *threadId, - _In_z_ const char *name, - _In_ const os_threadAttr *threadAttr, - _In_ os_threadRoutine start_routine, - _In_opt_ void *arg); - - /** \brief Return the integer representation of the given thread ID - * - * Possible Results: - * - returns the integer representation of the given thread ID - */ - OSAPI_EXPORT uintmax_t - os_threadIdToInteger( - os_threadId id); - - /** \brief Return the thread ID of the calling thread - * - * Possible Results: - * - returns the tread ID of the calling thread - */ - 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 - * else return immediately. In thread_result it returns the exit status - * of the thread. If thread_result is passed as a NULL pointer, - * no exit status is returned, but os_threadWaitExit still waits for the - * thread to terminate. - * - * Possible Results: - * - assertion failure: threadId = 0 - * - returns os_resultSuccess when - * the identified thread is not running - * - returns os_threadFail if - * the services is aborted because of a failure - */ - OSAPI_EXPORT os_result - os_threadWaitExit( - _In_ os_threadId threadId, - _Out_opt_ uint32_t *thread_result); - - /** \brief Get name of current thread - * - * Postcondition: - * - \b name is "" - * the thread name could not be determined - * - \b name is "" - * the thread name could be determined - * - * \b name will not be filled beyond the specified \b length - */ - OSAPI_EXPORT int32_t - os_threadGetThreadName( - char *name, - uint32_t length); - - /** \brief Set the default thread attributes - * - * Postcondition: - * - thread scheduling class is OS_SCHED_DEFAULT - * - thread priority is platform dependent - * - * Possible Results: - * - assertion failure: threadAttr = NULL - */ - OSAPI_EXPORT void - os_threadAttrInit( - os_threadAttr *threadAttr) - __nonnull_all__; - - /** \brief Allocate thread private memory - * - * Allocate heap memory of the specified \b size and - * relate it to the thread by storing the memory - * reference in an thread specific reference array - * indexed by \b index. If the indexed thread reference - * array location already contains a reference, no - * memory will be allocated and NULL is returned. - * - * Possible Results: - * - returns NULL if - * index < 0 || index >= OS_THREAD_MEM_ARRAY_SIZE - * - returns NULL if - * no sufficient memory is available on heap - * - returns NULL if - * os_threadMemGet (index) returns != NULL - * - returns reference to allocated heap memory - * of the requested size if - * memory is successfully allocated - */ - OSAPI_EXPORT void * - os_threadMemMalloc( - int32_t index, - size_t size); - - /** \brief Free thread private memory - * - * Free the memory referenced by the thread reference - * array indexed location. If this reference is NULL, - * or index is invalid, no action is taken. - * The reference is set to NULL after freeing the - * heap memory. - * - * Postcondition: - * - os_threadMemGet (index) = NULL and allocated - * heap memory is freed - */ - OSAPI_EXPORT void - os_threadMemFree( - int32_t index); - - /** \brief Get thread private memory - * - * Possible Results: - * - returns NULL if - * index < 0 || index >= OS_THREAD_MEM_ARRAY_SIZE - * - returns NULL if - * No heap memory is related to the thread for - * the specified index - * - returns a reference to the allocated memory - */ - OSAPI_EXPORT void * - os_threadMemGet( - int32_t index); - - /** \brief Pop cleanup handler from the top of thread's cleanup stack - * - * Remove routine at the top of the calling thread's cleanup stack and - * optionally invoke it (if execute is non-zero). - */ - OSAPI_EXPORT void - os_threadCleanupPop( - int32_t execute); - - /** \brief Push cleanup handler onto thread's cleanup stack - * - * Push a cleanup handler onto the top of the calling thread's cleanup - * stack. The cleanup handler will be popped of the thread's cleanup stack - * and invoked with the specified argument when the thread exits. - */ - OSAPI_EXPORT void - os_threadCleanupPush( - void (*routine)(void*), - void *arg); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_THREAD_H */ diff --git a/src/os/include/os/os_time.h b/src/os/include/os/os_time.h deleted file mode 100644 index 05d4c55..0000000 --- a/src/os/include/os/os_time.h +++ /dev/null @@ -1,276 +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 - */ -/**************************************************************** - * Interface definition for time management of SPLICE-DDS * - ****************************************************************/ - -#ifndef OS_TIME_H -#define OS_TIME_H - -#include "os/os_defs.h" -/* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - -#if defined (__cplusplus) -extern "C" { -#endif - - /** \brief Specification of maximum time values (platform dependent) - */ -#define OS_TIME_INFINITE_SEC INT32_MAX -#define OS_TIME_INFINITE_NSEC INT32_MAX - -#define os_timeIsInfinite(t) \ - (((t).tv_sec == OS_TIME_INFINITE_SEC) && ((t).tv_nsec == OS_TIME_INFINITE_NSEC)) - - /** \brief Get the current time. - * - * The returned time represents the seconds and nanoseconds since the Unix Epoch - * (Thursday, 1 January 1970, 00:00:00 (UTC)). - * - * Possible Results: - * - returns "the current time" - */ - OSAPI_EXPORT os_time - os_timeGet(void); - - os_time os__timeDefaultTimeGet(void); - - - /** \brief Get high resolution, monotonic time. - * - * The monotonic clock is a clock with near real-time progression and can be - * used when a high-resolution time is needed without the need for it to be - * related to the wall-clock. The resolution of the clock is typically the - * highest available on the platform. - * - * The clock is not guaranteed to be strictly monotonic, but on most common - * platforms it will be (based on performance-counters or HPET's). - * - * If no monotonic clock is available the real time clock is used. - * - * \return a high-resolution time with no guaranteed relation to wall-time - * when available - * \return wall-time, otherwise - */ - OSAPI_EXPORT os_time - os_timeGetMonotonic(void); - - /** \brief Get high resolution, elapsed (and thus monotonic) time since some - * fixed unspecified past time. - * - * The elapsed time clock is a clock with near real-time progression and can be - * used when a high-resolution suspend-aware monotonic clock is needed, without - * having to deal with the complications of discontinuities if for example the - * time is changed. The fixed point from which the elapsed time is returned is - * not guaranteed to be fixed over reboots of the system. - * - * If no elapsed time clock is available, the os_timeGetMonotonic() is used as a - * fall-back. - * - * \return elapsed time since some unspecified fixed past time - * \return os_timeGetMonotonic() otherwise - */ - OSAPI_EXPORT os_time - os_timeGetElapsed(void); - - /** \brief Add time t1 to time t2 - * - * Possible Results: - * - returns t1 + t2 when - * the result fits within the time structure - * - returns an unspecified value when - * the result does not fit within the time structure - */ - OSAPI_EXPORT os_time - os_timeAdd( - os_time t1, - os_time t2); - - /** \brief Subtract time t2 from time t1 - * - * Possible Results: - * - returns t1 - t2 when - * the result fits within the time structure - * - returns an unspecified value when - * the result does not fit within the time structure - */ - OSAPI_EXPORT os_time - os_timeSub( - os_time t1, - os_time t2); - - /** \brief Multiply time t with a real value - * - * Possible Results: - * - returns t * multiply when - * the result fits within the time structure - * - returns an unspecified value when - * the result does not fit within the time structure - */ - OSAPI_EXPORT os_time - os_timeMulReal( - os_time t1, - double multiply); - - /** \brief Determine the absolute value of time t - * - * Possible Results: - * - returns |t| when - * the result fits within the time structure - * - returns an unspecified value when - * the result does not fit within the time structure - */ - OSAPI_EXPORT os_time - os_timeAbs( - os_time t); - - /** \brief Compare time t1 with time t2 - * - * Possible Results: - * - returns -1 when - * value t1 < value t2 - * - returns 1 when - * value t1 > value t2 - * - returns 0 when - * value t1 = value t2 - */ - OSAPI_EXPORT int - os_timeCompare( - os_time t1, - os_time t2); - - /** \brief Convert time t into a floating point representation of t - * - * Postcondition: - * - Due to the limited accuracy, the least significant part - * of the floating point time will be about 1 us. - * - * Possible Results: - * - returns floating point representation of t - */ - OSAPI_EXPORT os_timeReal - os_timeToReal( - os_time t); - - /** \brief Convert a floating point time representation into time - * - * Possible Results: - * - returns t in os_time representation - */ - OSAPI_EXPORT os_time - os_realToTime( - os_timeReal t); - - /** \brief Suspend the execution of the calling thread for the specified time - * - * Possible Results: - * - returns os_resultSuccess if - * the thread is suspended for the specified time - * - returns os_resultFail if - * the thread is not suspended for the specified time because of a failure, - * for example when a negative delay is supplied or when the ns-part is not - * normalized. - */ - OSAPI_EXPORT os_result - os_nanoSleep( - _In_ os_time delay); - - /** \brief Translate calendar time into a readable string representation - * - * It converts the calendar time t into a '\0'-terminated string of the form: - * - * "Mon Feb 03 14:28:56 2014" - * - * The time-zone information may not be included on all platforms and may be a - * non-abbreviated string too. In order to obtain the time-zone, more room (at - * least 4 bytes more for an abbreviated, and unknown more for spelled out) needs - * to be provided in buf than the minimum of OS_CTIME_R_BUFSIZE. On Windows (if - * enough room is provided) it may for example expand to: - * - * "Wed Oct 01 15:59:53 W. Europe Daylight Time 2014" - * - * And on Linux to: - * - * "Wed Oct 01 15:59:53 CEST 2014" - * - * \param t the time to be translated - * \param buf a buffer to which the string must be written, with room for holding - * at least OS_CTIME_R_BUFSIZE (26) characters. - * - * Possible Results: - * If buf != NULL, buf contains a readable string representation of time t. The - * string is '\0'-terminated (and doesn't include a '\n' as the last character). - * \return The number of bytes written (not including the terminating \0) to buf - * and 0 if buf was NULL. - */ - OSAPI_EXPORT size_t - os_ctime_r( - os_time *t, - char *buf, - size_t bufsz); - - /** Minimum capacity of buffer supplied to os_ctime_r - * - * Apparently, the French national representation of the abbreviated weekday - * name and month name is 4 characters, so therefore added 2 to the expected - * size of 26. - */ -#define OS_CTIME_R_BUFSIZE (28) - - typedef struct os_timePowerEvents_s { - uint32_t suspendCount; /**< The number of detected suspends. */ - os_time suspendLastDetected; /**< The time of the last detected suspend (real time). */ - os_atomic_uint32_t resumeCount; /**< The number of detected resumes. */ - os_time resumeLastDetected; /**< The time of the last detected resume (real time). */ - } os_timePowerEvents; - - /** \brief Query (and optionally synchronize) on the number of detected power events. - * - * This call can be used to retrieve the number of power events (suspend/resume) that were - * detected. It is possible to block on changes by specifying a maxBlockingTime. - * - * The lastDetected timestamps are retrieved with os_getTime() and are the times on which the - * event was detected (which may not be the exact time at which the events actually occurred). - * The reported counts are monotonically increased on detection of power events. - * - * There is no guarantee that suspends (either hibernate or sleep) are detected. In general not - * all events may be detectable. Only the last resume event is guaranteed to be detected. - * - * The initial state (when no events are detected yet) is all counts and times zeroed. - * - * \param [in,out] events Pointer to a struct in which the result of the call is returned. - * If maxBlockingTime == 0, events is an out-parameter, otherwise it - * is in/out. The call will block until the actual state is different - * from the state pointed to by events. - * \param [in] maxBlockingTime The maximum time the call may block for the state to change from - * the state specified in events. If 0, the call will not block and - * return immediately the current state. - * \retval os_resultSuccess When the call succeeded and the struct pointed to by events contains - * the new status. - * \retval os_resultTimeout Iff maxBlockingTime != 0 and maxBlockingTime elapsed before the state - * changed. - * - * \pre The parameter events is not NULL and points to a location sufficiently large to hold an - * os_powerEvents struct. - * \pre The parameter maxBlockingTime is a valid time representation. - * \post The struct pointed to by events contains the current values. - */ - OSAPI_EXPORT os_result - os_timeGetPowerEvents( - os_timePowerEvents *events, - os_time maxBlockingTime); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_TIME_H */ diff --git a/src/os/include/os/posix/os_platform_socket.h b/src/os/include/os/posix/os_platform_socket.h deleted file mode 100644 index e8a9e94..0000000 --- a/src/os/include/os/posix/os_platform_socket.h +++ /dev/null @@ -1,93 +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 OS_PLATFORM_SOCKET_H -#define OS_PLATFORM_SOCKET_H - -#ifdef __VXWORKS__ -#include -#include -#include -#endif /* __VXWORKS__ */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#endif /* __APPLE__ */ -#include - -#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 -#define OS_NO_NETLINK 1 -#define OS_SOCKET_HAS_SSM 1 - -#define os_sockEAGAIN EAGAIN /* Operation would block, or a timeout expired before operation succeeded */ -#define os_sockEWOULDBLOCK EWOULDBLOCK /* Operation would block */ -#define os_sockEPERM EPERM /* Operation not permitted */ -#define os_sockENOENT ENOENT /* No such file or directory */ -#define os_sockEINTR EINTR /* Interrupted system call */ -#define os_sockEBADF EBADF /* Bad file number */ -#define os_sockENOMEM ENOMEM /* Out of memory */ -#define os_sockEACCES EACCES /* Permission denied */ -#define os_sockEINVAL EINVAL /* Invalid argument */ -#define os_sockEMFILE EMFILE /* Too many open files */ -#define os_sockENOSR ENOSR /* Out of streams resources */ -#define os_sockENOTSOCK ENOTSOCK /* Socket operation on non-socket */ -#define os_sockEMSGSIZE EMSGSIZE /* Message too long */ -#define os_sockENOPROTOOPT ENOPROTOOPT /* Protocol not available */ -#define os_sockEPROTONOSUPPORT EPROTONOSUPPORT /* Protocol not supported */ -#define os_sockEADDRINUSE EADDRINUSE /* Address already in use */ -#define os_sockEADDRNOTAVAIL EADDRNOTAVAIL /* Cannot assign requested address */ -#define os_sockENETUNREACH ENETUNREACH /* Network is unreachable */ -#define os_sockENOBUFS ENOBUFS /* No buffer space available */ -#define os_sockECONNRESET ECONNRESET /* Connection reset by peer */ -#define os_sockEPIPE EPIPE /* Connection reset by peer */ - - typedef int os_socket; /* signed */ - #define PRIsock "d" - -#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 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) -} -#endif - -#endif /* OS_PLATFORM_SOCKET_H */ diff --git a/src/os/include/os/posix/os_platform_stdlib.h b/src/os/include/os/posix/os_platform_stdlib.h deleted file mode 100644 index fd46052..0000000 --- a/src/os/include/os/posix/os_platform_stdlib.h +++ /dev/null @@ -1,12 +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 - */ -#include "../../../src/snippets/include/os_posix_stdlib.h" diff --git a/src/os/include/os/posix/os_platform_sync.h b/src/os/include/os/posix/os_platform_sync.h deleted file mode 100644 index cd7987d..0000000 --- a/src/os/include/os/posix/os_platform_sync.h +++ /dev/null @@ -1,47 +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 OS_PLATFORM_SYNC_H -#define OS_PLATFORM_SYNC_H - -#include -#include -#if HAVE_LKST -#include "lkst.h" -#endif - -#if defined (__cplusplus) -extern "C" { -#endif - - typedef struct os_cond { - pthread_cond_t cond; - } os_cond; - - typedef struct os_mutex { - pthread_mutex_t mutex; - } os_mutex; - - typedef struct os_rwlock { - pthread_rwlock_t rwlock; - } os_rwlock; - - typedef pthread_once_t os_once_t; - #define OS_ONCE_T_STATIC_INIT PTHREAD_ONCE_INIT - - void os_syncModuleInit(void); - void os_syncModuleExit(void); - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/solaris/os_platform.h b/src/os/include/os/solaris/os_platform.h deleted file mode 100644 index 1489fa3..0000000 --- a/src/os/include/os/solaris/os_platform.h +++ /dev/null @@ -1,48 +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 OS_PLATFORM_H -#define OS_PLATFORM_H - -#include -#include -#include -#include -#include -#include -#include - -#define PRIdSIZE "zd" -#define PRIuSIZE "zu" -#define PRIxSIZE "zx" - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_SOLARIS 1 -#define OS_HAVE_GETRUSAGE 1 - - typedef double os_timeReal; - typedef int os_timeSec; - typedef pid_t os_procId; - #define PRIprocId "d" - -#include "os/posix/os_platform_socket.h" -#include "os/posix/os_platform_sync.h" -#include "os/posix/os_platform_thread.h" -#include "os/posix/os_platform_stdlib.h" - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/vxworks/os_platform.h b/src/os/include/os/vxworks/os_platform.h deleted file mode 100644 index 6c3fb9d..0000000 --- a/src/os/include/os/vxworks/os_platform.h +++ /dev/null @@ -1,135 +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 OS_PLATFORM_H -#define OS_PLATFORM_H - -#include -#include -#include -#include - -#define PRIdSIZE "zd" -#define PRIuSIZE "zu" -#define PRIxSIZE "zx" - -#ifdef _WRS_KERNEL -/* inttypes.h does not exist in VxWorks DKM */ -#include -#include - -/* The above inttypes includes don't seem to define uintmax_t &c. */ -#ifdef _WRS_CONFIG_LP64 /* Used in cafe/inttypes.h too */ -#define _PFX_64 "l" -typedef unsigned long int uintmax_t; -#else -#define _PFX_64 "ll" -typedef unsigned long long int uintmax_t; -#endif - -/* FIXME: Not a complete replacement for inttypes.h (yet); no SCN/PRI?LEAST/FAST/etc */ -/* FIXME: Wrap all of them in #ifndefs */ -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 _PFX_64 "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 _PFX_64 "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 _PFX_64 "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 _PFX_64 "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -/*#define PRIx64 _PFX_64 "x" // Defined in cafe/inttypes.h apparently */ - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 _PFX_64 "X" - -#define PRIdMAX _PFX_64 "d" -#define PRIiMAX _PFX_64 "i" -#define PRIoMAX _PFX_64 "o" -#define PRIuMAX _PFX_64 "u" -#define PRIxMAX _PFX_64 "x" -#define PRIXMAX _PFX_64 "X" - -#define PRIdPTR _PFX_64 "d" -#define PRIiPTR _PFX_64 "i" -#define PRIoPTR _PFX_64 "o" -/*#define PRIuPTR _PFX_64 "u" // Defined in cafe/inttypes.h apparently */ -/*#define PRIxPTR _PFX_64 "x" // Defined in cafe/inttypes.h apparently */ -#define PRIXPTR _PFX_64 "X" - -#define INFINITY infinity() -#define NAN ((float)(INFINITY * 0.0F)) - -#if !defined(__PPC) && !defined(__x64_64__) -/* FIXME: Is this still required for VxWorks 7? */ -#define OS_USE_ALLIGNED_MALLOC -#endif - -#else -#include -#endif /* _WRS_KERNEL */ - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_VXWORKS 1 -#define OS_HAVE_GETRUSAGE 0 - -typedef double os_timeReal; -typedef int os_timeSec; -#ifdef _WRS_KERNEL -typedef RTP_ID os_procId; /* typedef struct wind_rtp *RTP_ID */ -#define PRIprocId "d" -#else -typedef pid_t os_procId; -#define PRIprocId "d" - -/* If unistd.h is included after stdint.h, intptr_t will be defined twice. - * It seems like this is an issue with the VxWorks provided header-files. The - * define done by stdint.h is not checked in unistd.h. Below is a workaround - * for this issue. */ -#if !defined _INTPTR_T && defined _INTPTR -# define _INTPTR_T _INTPTR -#endif -#endif - -#include "os/posix/os_platform_socket.h" -#ifdef _WRS_KERNEL -/* Pulling in netinet/in.h automatically pulls in net/mbuf.h in VxWorks DKM */ -#undef m_next -#undef m_flags -#endif -#include "os/posix/os_platform_sync.h" -#include "os/posix/os_platform_thread.h" -#include "os/posix/os_platform_stdlib.h" - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_PLATFORM_H */ diff --git a/src/os/include/os/windows/os_platform.h b/src/os/include/os/windows/os_platform.h deleted file mode 100644 index 02c176f..0000000 --- a/src/os/include/os/windows/os_platform.h +++ /dev/null @@ -1,55 +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 OS_PLATFORM_H -#define OS_PLATFORM_H - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include -#include - -#include -#include -#include -#include -#include - -#define PRIdSIZE "zd" -#define PRIuSIZE "zu" -#define PRIxSIZE "zx" - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_WIN32 1 -#define OS_HAVE_GETRUSAGE 1 - - typedef double os_timeReal; - typedef int os_timeSec; - typedef DWORD os_procId; - #define PRIprocId "u" - typedef SSIZE_T ssize_t; - -#include "os/windows/os_platform_socket.h" -#include "os/windows/os_platform_sync.h" -#include "os/windows/os_platform_thread.h" -#include "os/windows/os_platform_stdlib.h" -#include "os/windows/os_platform_time.h" - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/os/include/os/windows/os_platform_socket.h b/src/os/include/os/windows/os_platform_socket.h deleted file mode 100644 index b27bf60..0000000 --- a/src/os/include/os/windows/os_platform_socket.h +++ /dev/null @@ -1,102 +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 OS_PLATFORM_SOCKET_H -#define OS_PLATFORM_SOCKET_H - -#include -#include -#include - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_SOCK_VERSION 2 -#define OS_SOCK_REVISION 0 - -/* 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 - -#if defined NTDDI_VERSION && defined _WIN32_WINNT_WS03 && NTDDI_VERSION >= _WIN32_WINNT_WS03 -#define OS_SOCKET_HAS_SSM 1 -#else -#define OS_SOCKET_HAS_SSM 0 -#endif - -#define IFF_POINTOPOINT IFF_POINTTOPOINT - -#define os_sockEAGAIN WSAEWOULDBLOCK /* Operation would block, or a timeout expired before operation succeeded */ -#define os_sockEWOULDBLOCK WSAEWOULDBLOCK /* Operation would block */ -#define os_sockENOMEM WSABASEERR -#define os_sockENOSR WSABASEERR -#define os_sockENOENT WSABASEERR -#define os_sockEPERM WSAEACCES -#define os_sockEINTR WSAEINTR -#define os_sockEBADF WSAEBADF -#define os_sockEACCES WSAEACCES -#define os_sockEINVAL WSAEINVAL -#define os_sockEMFILE WSAEMFILE -#define os_sockENOTSOCK WSAENOTSOCK -#define os_sockEMSGSIZE WSAEMSGSIZE -#define os_sockENOPROTOOPT WSAENOPROTOOPT -#define os_sockEPROTONOSUPPORT WSAEPROTONOSUPPORT -#define os_sockEADDRINUSE WSAEADDRINUSE -#define os_sockEADDRNOTAVAIL WSAEADDRNOTAVAIL -#define os_sockEHOSTUNREACH WSAEHOSTUNREACH -#define os_sockENOBUFS WSAENOBUFS -#define os_sockECONNRESET WSAECONNRESET /* Connection reset by peer */ - - typedef SOCKET os_socket; - #define PRIsock PRIuPTR - -#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); - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_PLATFORM_SOCKET_H */ diff --git a/src/os/include/os/windows/os_platform_stdlib.h b/src/os/include/os/windows/os_platform_stdlib.h deleted file mode 100644 index a5e8a42..0000000 --- a/src/os/include/os/windows/os_platform_stdlib.h +++ /dev/null @@ -1,46 +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 OS_PLATFORM_STDLIB_H -#define OS_PLATFORM_STDLIB_H - -#include -#include - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_ROK (_S_IREAD) -#define OS_WOK (_S_IWRITE) -#define OS_XOK (_S_IEXEC) -#define OS_FOK (0) - -#define OS_ISDIR(mode) (mode & _S_IFDIR) -#define OS_ISREG(mode) (mode & _S_IFREG) -#define OS_ISLNK(mode) (0) /* not supported on this platform */ - - /* on this platform these permission masks are don't cares! */ -#define S_IRWXU 00700 -#define S_IRWXG 00070 -#define S_IRWXO 00007 - -#define MAXHOSTNAMELEN MAX_HOSTNAME_LEN - -#if _MSC_VER < 1900 -extern int snprintf(char *s, size_t n, const char *format, ...); -#endif - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_PLATFORM_STDLIB_H */ diff --git a/src/os/src/os_atomics.c b/src/os/src/os_atomics.c deleted file mode 100644 index 5375dad..0000000 --- a/src/os/src/os_atomics.c +++ /dev/null @@ -1,164 +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 - */ - -#include "os/os.h" - -/* LD, ST */ -extern inline uint32_t os_atomic_ld32 (const volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_ld64 (const volatile os_atomic_uint64_t *x); -#endif -extern inline uintptr_t os_atomic_ldptr (const volatile os_atomic_uintptr_t *x); -extern inline void *os_atomic_ldvoidp (const volatile os_atomic_voidp_t *x); -extern inline void os_atomic_st32 (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_st64 (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline void os_atomic_stptr (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline void os_atomic_stvoidp (volatile os_atomic_voidp_t *x, void *v); -/* INC */ -extern inline void os_atomic_inc32 (volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_inc64 (volatile os_atomic_uint64_t *x); -#endif -extern inline void os_atomic_incptr (volatile os_atomic_uintptr_t *x); -extern inline uint32_t os_atomic_inc32_nv (volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_inc64_nv (volatile os_atomic_uint64_t *x); -#endif -extern inline uintptr_t os_atomic_incptr_nv (volatile os_atomic_uintptr_t *x); -/* DEC */ -extern inline void os_atomic_dec32 (volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_dec64 (volatile os_atomic_uint64_t *x); -#endif -extern inline void os_atomic_decptr (volatile os_atomic_uintptr_t *x); -extern inline uint32_t os_atomic_dec32_nv (volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_dec64_nv (volatile os_atomic_uint64_t *x); -#endif -extern inline uintptr_t os_atomic_decptr_nv (volatile os_atomic_uintptr_t *x); -extern inline uint32_t os_atomic_dec32_ov (volatile os_atomic_uint32_t *x); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_dec64_ov (volatile os_atomic_uint64_t *x); -#endif -extern inline uintptr_t os_atomic_decptr_ov (volatile os_atomic_uintptr_t *x); -/* ADD */ -extern inline void os_atomic_add32 (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_add64 (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline void os_atomic_addptr (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline void os_atomic_addvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v); -extern inline uint32_t os_atomic_add32_nv (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_add64_nv (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_addptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline void *os_atomic_addvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v); -/* SUB */ -extern inline void os_atomic_sub32 (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_sub64 (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline void os_atomic_subptr (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline void os_atomic_subvoidp (volatile os_atomic_voidp_t *x, ptrdiff_t v); -extern inline uint32_t os_atomic_sub32_nv (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_sub64_nv (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_subptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline void *os_atomic_subvoidp_nv (volatile os_atomic_voidp_t *x, ptrdiff_t v); -/* AND */ -extern inline void os_atomic_and32 (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_and64 (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline void os_atomic_andptr (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline uint32_t os_atomic_and32_ov (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_and64_ov (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_andptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline uint32_t os_atomic_and32_nv (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_and64_nv (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_andptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v); -/* OR */ -extern inline void os_atomic_or32 (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline void os_atomic_or64 (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline void os_atomic_orptr (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline uint32_t os_atomic_or32_ov (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_or64_ov (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_orptr_ov (volatile os_atomic_uintptr_t *x, uintptr_t v); -extern inline uint32_t os_atomic_or32_nv (volatile os_atomic_uint32_t *x, uint32_t v); -#if OS_ATOMIC64_SUPPORT -extern inline uint64_t os_atomic_or64_nv (volatile os_atomic_uint64_t *x, uint64_t v); -#endif -extern inline uintptr_t os_atomic_orptr_nv (volatile os_atomic_uintptr_t *x, uintptr_t v); -/* CAS */ -extern inline int os_atomic_cas32 (volatile os_atomic_uint32_t *x, uint32_t exp, uint32_t des); -#if OS_ATOMIC64_SUPPORT -extern inline int os_atomic_cas64 (volatile os_atomic_uint64_t *x, uint64_t exp, uint64_t des); -#endif -extern inline int os_atomic_casptr (volatile os_atomic_uintptr_t *x, uintptr_t exp, uintptr_t des); -extern inline int os_atomic_casvoidp (volatile os_atomic_voidp_t *x, void *exp, void *des); -#if OS_ATOMIC_LIFO_SUPPORT -extern inline int os_atomic_casvoidp2 (volatile os_atomic_uintptr2_t *x, uintptr_t a0, uintptr_t b0, uintptr_t a1, uintptr_t b1); -#endif -/* FENCES */ -extern inline void os_atomic_fence (void); -extern inline void os_atomic_fence_ldld (void); -extern inline void os_atomic_fence_acq (void); -extern inline void os_atomic_fence_rel (void); - -#if OS_ATOMIC_LIFO_SUPPORT -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 diff --git a/src/os/src/os_dns.c b/src/os/src/os_dns.c deleted file mode 100644 index 36a29f0..0000000 --- a/src/os/src/os_dns.c +++ /dev/null @@ -1,146 +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 - */ -#define _GNU_SOURCE - -#include -#include - -#include "os/os.h" - -int -os_gethostbyname( - const char *name, - int af, - os_hostent_t **hentp) -{ - int err = 0; - int gai_err = 0; - struct addrinfo hints, *res = NULL; - os_hostent_t *hent = NULL; - - assert(name != NULL); - assert(hentp != NULL); - - switch (af) { -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: -#endif - case AF_INET: - case AF_UNSPEC: - break; - default: - return EAFNOSUPPORT; - } - - /* Windows returns all registered addresses on the local computer if the - "nodename" parameter is an empty string. *NIX return HOST_NOT_FOUND. - Deny empty hostnames to keep behavior across platforms consistent. */ - if (strlen(name) == 0) { - return OS_HOST_NOT_FOUND; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = af; - - gai_err = getaddrinfo(name, NULL, &hints, &res); - /* gai_strerror cannot be used because Windows does not offer a thread-safe - implementation and lwIP (there maybe others as well) does not offer an - implementation at all. - - NOTE: Error codes returned by getaddrinfo map directly onto Windows - Socket error codes and WSAGetLastError can be used instead. */ - DDS_TRACE("getaddrinfo for %s returned %d\n", name, gai_err); - switch (gai_err) { -#if defined(EAI_AGAIN) - case EAI_AGAIN: - /* Name server returned a temporary failure indication. */ - err = OS_TRY_AGAIN; - break; -#endif - case EAI_FAIL: - /* Name server returned a permanent failure indication. */ - err = OS_NO_RECOVERY; - break; -/* Windows defines EAI_NODATA to EAI_NONAME. */ -#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) - case EAI_NODATA: - /* Host exists, but does not have any network addresses defined. */ - err = OS_NO_DATA; - break; -#endif -#if defined(EAI_ADDRFAMILY) - case EAI_ADDRFAMILY: /* Host has no addresses in requested family. */ -#endif -#if defined(EAI_NOSECURENAME) /* Windows */ - case EAI_NOSECURENAME: -#endif - case EAI_NONAME: - /* Host does not exist. */ - err = OS_HOST_NOT_FOUND; - break; - case EAI_MEMORY: - /* Out of memory. */ - err = ENOMEM; - break; -#if defined(EAI_SYSTEM) - case EAI_SYSTEM: - /* Other system error. */ - err = errno; - break; -#endif - case EAI_BADFLAGS: /* Invalid flags in hints.ai_flags. */ - case EAI_FAMILY: /* Address family not supported. */ - case EAI_SERVICE: /* Service not available for socket type. */ - case EAI_SOCKTYPE: /* Socket type not supported. */ - case 0: - { - struct addrinfo *ai; - size_t addrno, naddrs, size; - - assert(gai_err == 0); - assert(res != NULL); - - naddrs = 0; - for (ai = res; ai != NULL; ai = ai->ai_next) { - naddrs++; - } - - size = sizeof(*hent) + (naddrs * sizeof(hent->addrs[0])); - if ((hent = os_malloc_0_s(size)) != NULL) { - hent->naddrs = naddrs; - for (addrno = 0, ai = res; - addrno < naddrs && ai != NULL; - addrno++, ai = ai->ai_next) - { - memcpy(&hent->addrs[addrno], res->ai_addr, res->ai_addrlen); - } - } else { - err = ENOMEM; - } - } - break; - default: - DDS_FATAL("getaddrinfo returned unkown error %d\n", gai_err); - } - - if (res != NULL) { - freeaddrinfo(res); - } - - if (err == 0) { - *hentp = hent; - } else { - os_free(hent); - } - - return err; -} diff --git a/src/os/src/os_errno.c b/src/os/src/os_errno.c deleted file mode 100644 index 33dd4ce..0000000 --- a/src/os/src/os_errno.c +++ /dev/null @@ -1,134 +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 - */ -#include "os/os.h" - -#include -#include -#include - -static struct { int err; const char *str; } errstrs[] = -{ - { OS_HOST_NOT_FOUND, "Host not found" }, - { OS_NO_DATA, "Valid name, no data record of requested type" }, - { OS_NO_RECOVERY, "Nonrecoverable error" }, - { OS_TRY_AGAIN, "Nonauthoritative host not found" }, -}; - -int os_errstr(_In_ int errnum, char *buf, size_t buflen) -{ - int err = 0; - const char *str = NULL; - unsigned idx = (unsigned)(errnum - (OS_ERRBASE + 1)); - static const unsigned max = (unsigned)(sizeof(errstrs)/sizeof(errstrs[0])); - - if (errnum > OS_ERRBASE && idx < max) { - size_t len; - assert(errstrs[idx].err == errnum); - str = errstrs[idx].str; - assert(str != NULL); - len = strlen(str); - if (len < buflen) { - memcpy(buf, str, len); - buf[len] = '\0'; - } else { - err = ERANGE; - } - } else { - err = EINVAL; - } - - return err; -} - -#define MIN_BUFLEN (64) -#define MAX_BUFLEN (1024) - -const char * -os_strerror( - _In_ int err) -{ - char *mem; - char *ptr, *str = NULL; - size_t len = 0; - size_t tot; - int ret = 0; - - /* os_threadMem* does not support destructors, but does free the memory - referred to by the index. To avoid memory leaks and extra work the - length of the string is placed in front of the string. */ - if ((mem = os_threadMemGet(OS_THREAD_STR_ERROR)) == NULL) { - ret = ERANGE; - } else { - str = mem + sizeof(len); - memcpy(&len, mem, sizeof(len)); - } - - /* os_strerror_r returns ERANGE if the buffer is too small. - Iteratively increase the buffer and retry until MAX_BUFLEN is reached, - in which case, give up and print the error number as text. */ - do { - if (ret == ERANGE && len < MAX_BUFLEN) { - os_threadMemFree(OS_THREAD_STR_ERROR); - if (len == 0) { - len = MIN_BUFLEN; - } else { - len *= 2; - } - - tot = sizeof(len) + len + 1; - mem = os_threadMemMalloc(OS_THREAD_STR_ERROR, tot); - if (mem != NULL) { - memcpy(mem, &len, sizeof(len)); - str = mem + sizeof(len); - } else { - ret = ENOMEM; - str = NULL; - len = 0; - } - } - - if (str != NULL) { - assert(len != 0 && len >= MIN_BUFLEN && len <= MAX_BUFLEN); - assert((len % MIN_BUFLEN) == 0); - if (ret == ERANGE && len == MAX_BUFLEN) { - ret = 0; - (void)snprintf(str, len, "Error (%d)", err); - } else { - /* Solaris 10 does not populate buffer if it is too small */ - memset(str, '\0', len + 1); - ret = os_strerror_r(err, str, len); - } - } - } while (str != NULL && ret == ERANGE); - - switch(ret) { - case ENOMEM: - str = "Out of memory"; - break; - case EINVAL: - (void)snprintf(str, len, "Unknown error (%d)", err); - break; - default: - assert(str != NULL); - /* strip newline and/or carriage return */ - ptr = str; - while (*ptr != '\0' && *ptr != '\n' && *ptr != '\r') { - ptr++; - } - if (*ptr == '\n' || *ptr == '\r') { - *ptr = '\0'; - } - break; - } - - return str; -} diff --git a/src/os/src/os_init.c b/src/os/src/os_init.c deleted file mode 100644 index 1a74096..0000000 --- a/src/os/src/os_init.c +++ /dev/null @@ -1,75 +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 - */ -/**************************************************************** - * Initialization / Deinitialization * - ****************************************************************/ - -/** \file os/code/os_init.c - * \brief Initialization / Deinitialization - * - * Initialization / Deinitialization provides routines for - * initializing the OS layer claiming required resources - * and routines to deinitialize the OS layer, releasing - * all resources still claimed. - */ - -#include "os/os.h" - -#define OSINIT_STATUS_OK 0x80000000u -static os_atomic_uint32_t osinit_status = OS_ATOMIC_UINT32_INIT(0); -static os_mutex init_mutex; - -void os_osInit (void) -{ - uint32_t v; - v = os_atomic_inc32_nv(&osinit_status); -retry: - if (v > OSINIT_STATUS_OK) - return; - else if (v == 1) { - os_osPlatformInit(); - os_mutexInit(&init_mutex); - os_atomic_or32(&osinit_status, OSINIT_STATUS_OK); - } else { - while (v > 1 && !(v & OSINIT_STATUS_OK)) { - os_nanoSleep((os_time){0, 10000000}); - v = os_atomic_ld32(&osinit_status); - } - goto retry; - } -} - -void os_osExit (void) -{ - uint32_t v, nv; - do { - v = os_atomic_ld32(&osinit_status); - if (v == (OSINIT_STATUS_OK | 1)) { - nv = 1; - } else { - nv = v - 1; - } - } while (!os_atomic_cas32(&osinit_status, v, nv)); - if (nv == 1) - { - os_mutexDestroy(&init_mutex); - os_osPlatformExit(); - os_atomic_dec32(&osinit_status); - } -} - -os_mutex *os_getSingletonMutex(void) -{ - return &init_mutex; -} - - diff --git a/src/os/src/os_iter.c b/src/os/src/os_iter.c deleted file mode 100644 index 1f02d60..0000000 --- a/src/os/src/os_iter.c +++ /dev/null @@ -1,229 +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 - */ -#include -#include - -#include "os/os.h" - -typedef struct os_iterNode_s os_iterNode; - -struct os_iterNode_s { - os_iterNode *next; - void *object; -}; - -struct os_iter_s { - int32_t length; - os_iterNode *head; - os_iterNode *tail; -}; - -_Ret_range_(-1, iter->length) static int32_t -os__iterIndex( - _In_ const os_iter *iter, - _In_ int32_t index) -{ - int32_t idx = 0; - - assert(iter != NULL); - - if (index == OS_ITER_LENGTH) { - idx = iter->length; - } else if (index < 0) { - index *= -1; - if (index > iter->length) { - idx = -1; - } else { - idx = iter->length - index; - } - } else { - if (index > iter->length) { - idx = iter->length; - } else { - idx = index; - } - } - - return idx; -} - -_Check_return_ -_Ret_valid_ -os_iter * -os_iterNew( - void) -{ - os_iter *iter = os_malloc_0(sizeof *iter); - - return iter; -} - -void -os_iterFree( - _In_opt_ _Post_ptr_invalid_ os_iter *iter, - _In_opt_ void(*func)(_Inout_ void *)) -{ - os_iterNode *node, *next; - - if (iter != NULL) { - node = iter->head; - while (node != NULL) { - next = node->next; - if (node->object != NULL && func != NULL) { - func(node->object); - } - os_free(node); - node = next; - } - os_free(iter); - } -} - -_Success_(return >= 0) _Ret_range_(-1, INT32_MAX) int32_t -os_iterInsert( - _Inout_ os_iter *iter, - _In_opt_ void *object, - _In_ int32_t index) -{ - int32_t cnt, idx = -1; - os_iterNode *node, *prev; - - assert(iter->length < INT32_MAX); - node = os_malloc_0(sizeof *node); - node->object = object; - - idx = os__iterIndex(iter, index); - prev = NULL; - if (idx > 0) { - assert(iter->length != 0); - assert(iter->head != iter->tail || iter->length == 1); - if (idx == iter->length) { - prev = iter->tail; - iter->tail = node; - } else { - cnt = 1; - prev = iter->head; - while (cnt++ < idx) { - prev = prev->next; - } - assert(prev != iter->tail); - node->next = prev->next; - prev->next = node; - } - prev->next = node; - } else { - assert(idx == 0 || idx == -1); - idx = 0; - node->next = iter->head; - iter->head = node; - if (iter->tail == NULL) { - assert(iter->length == 0); - iter->tail = node; - } - } - - iter->length++; - - return idx; -} - -_Ret_opt_valid_ void * -os_iterObject( - _In_ const os_iter *iter, - _In_range_(INT32_MIN+1, INT32_MAX) int32_t index) -{ - os_iterNode *node; - int32_t cnt, idx; - void *obj = NULL; - - assert(iter != NULL); - - idx = os__iterIndex(iter, index); - if (idx >= 0 && idx < iter->length) { - if (idx == (iter->length - 1)) { - node = iter->tail; - } else { - node = iter->head; - for (cnt = 0; cnt < idx; cnt++) { - node = node->next; - } - } - obj = node->object; - } - - return obj; -} - -_Ret_opt_valid_ void * -os_iterTake( - _Inout_ os_iter *iter, - _In_range_(INT32_MIN+1, INT32_MAX) int32_t index) -{ - os_iterNode *node, *prev; - int32_t cnt, idx; - void *obj = NULL; - - assert(iter != NULL); - - idx = os__iterIndex(iter, index); - if (idx >= 0 && idx < iter->length) { - prev = NULL; - node = iter->head; - for (cnt = 0; cnt < idx; cnt++) { - prev = node; - node = node->next; - } - if (node == iter->head) { - iter->head = node->next; - } else { - assert(prev != NULL); - prev->next = node->next; - } - if (node == iter->tail) { - iter->tail = prev; - } - - obj = node->object; - os_free(node); - iter->length--; - } - - return obj; -} - -_Ret_range_(0, INT32_MAX) uint32_t -os_iterLength( - _In_ const os_iter *__restrict iter) -{ - assert(iter != NULL); - return (uint32_t)iter->length; -} - -void -os_iterWalk( - _In_ const os_iter *iter, - _In_ void(*func)(_Inout_ void *obj, _Inout_opt_ void *arg), - _Inout_opt_ void *arg) -{ - os_iterNode *node; - - assert(iter != NULL); - assert(func != NULL); - - node = iter->head; - while (node != NULL) { - if(node->object) { - func(node->object, arg); - } - node = node->next; - } -} diff --git a/src/os/src/os_log.c b/src/os/src/os_log.c deleted file mode 100644 index 08edfd2..0000000 --- a/src/os/src/os_log.c +++ /dev/null @@ -1,299 +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 - */ -#include -#include -#include -#include - -#include "os/os.h" - -#define MAX_TIMESTAMP_LEN (10 + 1 + 6) -#define MAX_TID_LEN (10) -#define HDR_LEN (MAX_TIMESTAMP_LEN + 1 + MAX_TID_LEN + 2) - -#define BUF_OFFSET HDR_LEN - -typedef struct { - char buf[2048]; - size_t pos; -} log_buffer_t; - -typedef struct { - dds_log_write_fn_t funcs[2]; - void *ptr; - FILE *out; -} log_sink_t; - -static os_threadLocal log_buffer_t log_buffer; - -static os_once_t lock_inited = OS_ONCE_T_STATIC_INIT; -static os_rwlock lock; - -static uint32_t log_mask = DDS_LC_ERROR | DDS_LC_WARNING; - -static void default_sink(void *ptr, const dds_log_data_t *data) -{ - fwrite(data->message - HDR_LEN, 1, HDR_LEN + data->size + 1, (FILE *)ptr); - fflush((FILE *)ptr); -} - -static void nop_sink(void *ptr, const dds_log_data_t *data) -{ - (void)ptr; - (void)data; - return; -} - -#define LOG (0) -#define TRACE (1) -#define USE (0) -#define SET (1) - -static log_sink_t sinks[] = { - /* Log */ - { .funcs = { default_sink, default_sink }, .ptr = NULL, .out = NULL }, - /* Trace */ - { .funcs = { nop_sink, default_sink }, .ptr = NULL, .out = NULL } -}; - -uint32_t *const dds_log_mask = &log_mask; - -#define RDLOCK (1) -#define WRLOCK (2) - -static void init_lock(void) -{ - os_rwlockInit(&lock); - sinks[LOG].ptr = sinks[TRACE].ptr = stderr; - sinks[LOG].out = sinks[TRACE].out = stderr; -} - -static void lock_sink(int type) -{ - assert(type == RDLOCK || type == WRLOCK); - os_once(&lock_inited, &init_lock); - - if (type == RDLOCK) { - os_rwlockRead(&lock); - } else { - os_rwlockWrite(&lock); - } -} - -static void unlock_sink(void) -{ - os_rwlockUnlock(&lock); -} - -static void set_active_log_sinks(void) -{ - if (dds_get_log_mask() & DDS_LOG_MASK) { - sinks[LOG].funcs[USE] = sinks[LOG].funcs[SET]; - } else { - sinks[LOG].funcs[USE] = nop_sink; - } - if (dds_get_log_mask() & DDS_TRACE_MASK) { - sinks[TRACE].funcs[USE] = sinks[TRACE].funcs[SET]; - } else { - sinks[TRACE].funcs[USE] = nop_sink; - } - if (sinks[LOG].funcs[USE] == sinks[TRACE].funcs[USE] && - sinks[LOG].ptr == sinks[TRACE].ptr) - { - sinks[LOG].funcs[USE] = nop_sink; - } -} - -static void -set_log_sink( - _In_ log_sink_t *sink, - _In_opt_ dds_log_write_fn_t func, - _In_opt_ void *ptr) -{ - assert(sink != NULL); - - /* No life cycle management is done for log sinks, the caller is - responsible for that. Ensure this operation is deterministic and that on - return, no thread in the DDS stack still uses the deprecated sink. */ - lock_sink(WRLOCK); - - if (func == 0) { - sink->funcs[SET] = default_sink; - sink->ptr = sink->out; - } else { - sink->funcs[SET] = func; - sink->ptr = ptr; - } - - set_active_log_sinks(); - unlock_sink(); -} - -/* dds_set_log_file must be considered private. */ -void dds_set_log_file(_In_ FILE *file) -{ - lock_sink(WRLOCK); - sinks[LOG].out = file; - if (sinks[LOG].funcs[SET] == default_sink) { - sinks[LOG].ptr = sinks[LOG].out; - } - set_active_log_sinks(); - unlock_sink(); -} - -void dds_set_trace_file(_In_ FILE *file) -{ - lock_sink(WRLOCK); - sinks[TRACE].out = file; - if (sinks[TRACE].funcs[SET] == default_sink) { - sinks[TRACE].ptr = sinks[TRACE].out; - } - set_active_log_sinks(); - unlock_sink(); -} - -void dds_set_log_sink( - _In_opt_ dds_log_write_fn_t callback, - _In_opt_ void *userdata) -{ - set_log_sink(&sinks[LOG], callback, userdata); -} - -void dds_set_trace_sink( - _In_opt_ dds_log_write_fn_t callback, - _In_opt_ void *userdata) -{ - set_log_sink(&sinks[TRACE], callback, userdata); -} - -extern inline uint32_t -dds_get_log_mask(void); - -void -dds_set_log_mask(_In_ uint32_t cats) -{ - lock_sink(WRLOCK); - *dds_log_mask = (cats & (DDS_LOG_MASK | DDS_TRACE_MASK)); - set_active_log_sinks(); - unlock_sink(); -} - -static void print_header(char *str) -{ - int cnt; - char *tid, buf[MAX_TID_LEN+1] = { 0 }; - static const char fmt[] = "%10u.%06d/%*.*s:"; - os_time tv; - unsigned sec; - int usec; - - (void)os_threadGetThreadName(buf, sizeof(buf)); - tid = (buf[0] == '\0' ? "(anon)" : buf); - tv = os_timeGet(); - sec = (unsigned)tv.tv_sec; - usec = (int)(tv.tv_nsec / 1000); - - cnt = snprintf( - str, HDR_LEN, fmt, sec, usec, MAX_TID_LEN, MAX_TID_LEN, tid); - assert(cnt == (HDR_LEN - 1)); - str[cnt] = ' '; /* Replace snprintf null byte by space. */ -} - -static void vlog( - _In_ uint32_t cat, - _In_z_ const char *file, - _In_ uint32_t line, - _In_z_ const char *func, - _In_z_ const char *fmt, - va_list ap) -{ - int n, trunc = 0; - size_t nrem; - log_buffer_t *lb; - dds_log_data_t data; - - if (*fmt == 0) { - return; - } - - lock_sink(RDLOCK); - lb = &log_buffer; - - /* Thread-local buffer is always initialized with all zeroes. The pos - member must always be greater or equal to BUF_OFFSET. */ - if (lb->pos < BUF_OFFSET) { - lb->pos = BUF_OFFSET; - lb->buf[lb->pos] = 0; - } - nrem = sizeof (lb->buf) - lb->pos; - if (nrem > 0) { - n = os_vsnprintf(lb->buf + lb->pos, nrem, fmt, ap); - if (n >= 0 && (size_t) n < nrem) { - lb->pos += (size_t) n; - } else { - lb->pos += nrem; - trunc = 1; - } - if (trunc) { - static const char msg[] = "(trunc)\n"; - const size_t msglen = sizeof (msg) - 1; - assert(lb->pos <= sizeof (lb->buf)); - assert(lb->pos >= msglen); - memcpy(lb->buf + lb->pos - msglen, msg, msglen); - } - } - - if (fmt[strlen (fmt) - 1] == '\n') { - print_header(lb->buf); - - data.priority = cat; - data.file = file; - data.function = func; - data.line = line; - data.message = lb->buf + BUF_OFFSET; - data.size = strlen(data.message) - 1; - - for (size_t i = (cat & DDS_LOG_MASK) ? LOG : TRACE; - i < sizeof(sinks) / sizeof(sinks[0]); - i++) - { - sinks[i].funcs[USE](sinks[i].ptr, &data); - } - - lb->pos = BUF_OFFSET; - lb->buf[lb->pos] = 0; - } - - unlock_sink(); -} - -int -dds_log( - _In_ uint32_t cat, - _In_z_ const char *file, - _In_ uint32_t line, - _In_z_ const char *func, - _In_z_ _Printf_format_string_ const char *fmt, - ...) -{ - if ((dds_get_log_mask() & cat) || (cat & DDS_LC_FATAL)) { - va_list ap; - va_start(ap, fmt); - vlog(cat, file, line, func, fmt, ap); - va_end(ap); - } - if (cat & DDS_LC_FATAL) { - abort(); - } - - return 0; -} diff --git a/src/os/src/os_socket.c b/src/os/src/os_socket.c deleted file mode 100644 index 49a93ad..0000000 --- a/src/os/src/os_socket.c +++ /dev/null @@ -1,271 +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 - */ -/**************************************************************** - * Implementation for socket services conforming to * - * OpenSplice requirements * - ****************************************************************/ - -/** \file os/code/os_socket.c - * \brief socket management - */ - -#include -#include - -#ifdef __linux -#include /* sockaddr_ll */ -#endif /* __linux */ - -#include "os/os.h" - -#if (OS_SOCKET_HAS_IPV6 == 1) -#ifndef _VXWORKS -const os_in6_addr os_in6addr_any = IN6ADDR_ANY_INIT; -const os_in6_addr os_in6addr_loopback = IN6ADDR_LOOPBACK_INIT; -#else -const os_in6_addr os_in6addr_any = { { 0 } }; -const os_in6_addr os_in6addr_loopback = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }; -#endif -#endif - -const int afs[] = { -#ifdef __linux - AF_PACKET, -#endif /* __linux */ -#if OS_SOCKET_HAS_IPV6 - AF_INET6, -#endif /* OS_SOCKET_HAS_IPV6 */ - AF_INET, - OS_AF_NULL /* Terminator */ -}; - -const int *const os_supp_afs = afs; - -size_t -os_sockaddr_get_size(const os_sockaddr *const sa) -{ - size_t sz; - - assert(sa != NULL); - - switch(sa->sa_family) { -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - sz = sizeof(os_sockaddr_in6); - break; -#endif /* OS_SOCKET_HAS_IPV6 */ -#ifdef __linux - case AF_PACKET: - sz = sizeof(struct sockaddr_ll); - break; -#endif /* __linux */ - default: - assert(sa->sa_family == AF_INET); - sz = sizeof(os_sockaddr_in); - break; - } - - return sz; -} - -uint16_t os_sockaddr_get_port(const os_sockaddr *const sa) -{ - unsigned short port = 0; - - switch(sa->sa_family) { -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - port = ntohs(((os_sockaddr_in6 *)sa)->sin6_port); - break; -#endif /* OS_SOCKET_HAS_IPV6 */ - default: - assert(sa->sa_family == AF_INET); - port = ntohs(((os_sockaddr_in *)sa)->sin_port); - break; - } - - return port; -} - -int -os_sockaddr_is_unspecified( - _In_ const os_sockaddr *__restrict sa) -{ - assert(sa != NULL); - - switch(sa->sa_family) { -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - return IN6_IS_ADDR_UNSPECIFIED(&((os_sockaddr_in6*)sa)->sin6_addr); -#endif - case AF_INET: - return (((os_sockaddr_in *)sa)->sin_addr.s_addr == 0); - } - - return 0; -} - -int -os_sockaddr_is_loopback( - _In_ const os_sockaddr *__restrict sa) -{ - assert(sa != NULL); - - switch (sa->sa_family) { -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - return IN6_IS_ADDR_LOOPBACK( - &((const os_sockaddr_in6 *)sa)->sin6_addr); -#endif /* OS_SOCKET_HAS_IPV6 */ - case AF_INET: - return (((const os_sockaddr_in *)sa)->sin_addr.s_addr - == htonl(INADDR_LOOPBACK)); - } - - return 0; -} - -bool -os_sockaddrSameSubnet(const os_sockaddr* thisSock, - const os_sockaddr* thatSock, - const os_sockaddr* mask) -{ - bool result = false; -#if (OS_SOCKET_HAS_IPV6 == 1) - os_sockaddr_in6 thisV6, thatV6, *maskV6; -#endif - - if (thisSock->sa_family == thatSock->sa_family && - thisSock->sa_family == mask->sa_family) - { - if (thisSock->sa_family == AF_INET) - { - /* IPv4 */ - result = ((((os_sockaddr_in*)thisSock)->sin_addr.s_addr & ((os_sockaddr_in*)mask)->sin_addr.s_addr ) == - (((os_sockaddr_in*)thatSock)->sin_addr.s_addr & ((os_sockaddr_in*)mask)->sin_addr.s_addr) ? - true: false); - } -#if (OS_SOCKET_HAS_IPV6 == 1) - else - { - size_t i, size; - /* IPv6 */ - memcpy(&thisV6, thisSock, sizeof(thisV6)); - memcpy(&thatV6, thatSock, sizeof(thatV6)); - maskV6 = (os_sockaddr_in6*) mask; - size = sizeof(thisV6.sin6_addr.s6_addr); - for (i=0; i < size; i++) { - thisV6.sin6_addr.s6_addr[i] &= maskV6->sin6_addr.s6_addr[i]; - thatV6.sin6_addr.s6_addr[i] &= maskV6->sin6_addr.s6_addr[i]; - } - result = (memcmp(&thisV6.sin6_addr.s6_addr, &thatV6.sin6_addr.s6_addr, size) ? - false : true); - } -#endif - } - return result; -} - -int _Success_(return == 0) -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 /* OS_SOCKET_HAS_IPV6 */ - void *sa) -{ - int err = 0; - - assert(str != NULL); - assert(sa != NULL); - - switch (af) { - case AF_INET: - { - struct in_addr buf; - if (inet_pton(af, str, &buf) != 1) { - err = EINVAL; - } else { - memset(sa, 0, sizeof(os_sockaddr_in)); - ((os_sockaddr_in *)sa)->sin_family = AF_INET; - memcpy(&((os_sockaddr_in *)sa)->sin_addr, &buf, sizeof(buf)); - } - } - break; -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - { - struct in6_addr buf; - if (inet_pton(af, str, &buf) != 1) { - err = EINVAL; - } else { - memset(sa, 0, sizeof(os_sockaddr_in6)); - ((os_sockaddr_in6 *)sa)->sin6_family = AF_INET6; - memcpy(&((os_sockaddr_in6 *)sa)->sin6_addr, &buf, sizeof(buf)); - } - } - break; -#endif /* OS_SOCKET_HAS_IPV6 */ - default: - err = EAFNOSUPPORT; - break; - } - - return err; -} - -int _Success_(return == 0) -os_sockaddrtostr( - _In_ const void *sa, - _Out_writes_z_(size) char *buf, - _In_ size_t size) -{ - int err = 0; - const char *ptr; - - assert(sa != NULL); - assert(buf != NULL); - - switch (((os_sockaddr *)sa)->sa_family) { - case AF_INET: - ptr = inet_ntop( - AF_INET, &((os_sockaddr_in *)sa)->sin_addr, buf, (socklen_t)size); - break; -#if OS_SOCKET_HAS_IPV6 - case AF_INET6: - ptr = inet_ntop( - AF_INET6, &((os_sockaddr_in6 *)sa)->sin6_addr, buf, (socklen_t)size); - break; -#endif - default: - return EAFNOSUPPORT; - } - - if (ptr == NULL) { -#if WIN32 - err = GetLastError(); - if (ERROR_INVALID_PARAMETER) { - /* ERROR_INVALID_PARAMETER is returned if the buffer is a null - pointer or the size of the buffer is not sufficiently large - enough. *NIX platforms set errno to ENOSPC if the buffer is not - large enough to store the IP address in text form. */ - err = ENOSPC; - } -#else - err = errno; -#endif - } - - return err; -} diff --git a/src/os/src/os_strlcpy.c b/src/os/src/os_strlcpy.c deleted file mode 100644 index 39cadf3..0000000 --- a/src/os/src/os_strlcpy.c +++ /dev/null @@ -1,80 +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 - */ -#include -#include - -#include "os/os.h" - -_Success_(return < size) -size_t -os_strlcpy( - _Out_writes_z_(size) char * __restrict dest, - _In_z_ const char * __restrict src, - _In_ size_t size) -{ - size_t srclen = 0; - - assert(dest != NULL); - assert(src != NULL); - - /* strlcpy must return the number of bytes that (would) have been written, - i.e. the length of src. */ - srclen = strlen(src); - if (size > 0) { - size_t len = srclen; - if (size <= srclen) { - len = size - 1; - } - memcpy(dest, src, len); - dest[len] = '\0'; - } - - return srclen; -} - -/* NOTE: os_strlcat does not forward to strlcat too avoid a bug in the macOS - implementation where it does not return the right result if dest - contains more characters than the size specified if size is either - 0 or 1. */ -_Success_(return < size) -size_t -os_strlcat( - _Inout_updates_z_(size) char * __restrict dest, - _In_z_ const char * __restrict src, - _In_ size_t size) -{ - size_t destlen, srclen; - - assert(dest != NULL); - assert(src != NULL); - - /* strlcat must return the number of bytes that (would) have been written, - i.e. the length of dest plus the length of src. */ - destlen = strlen(dest); - srclen = strlen(src); - if (SIZE_MAX == destlen) { - srclen = 0; - } else if ((SIZE_MAX - destlen) <= srclen) { - srclen = (SIZE_MAX - destlen) - 1; - } - if (size > 0 && --size > destlen) { - size_t len = srclen; - size -= destlen; - if (size <= srclen) { - len = size; - } - memcpy(dest + destlen, src, len); - dest[destlen + len] = '\0'; - } - - return destlen + srclen; -} diff --git a/src/os/src/os_thread.c b/src/os/src/os_thread.c deleted file mode 100644 index 03f26ac..0000000 --- a/src/os/src/os_thread.c +++ /dev/null @@ -1,45 +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 - */ -/** \file os/common/code/os_thread_attr.c - * \brief Common thread attributes - * - * Implements os_threadAttrInit and sets attributes - * to platform independent values: - * - scheduling class is OS_SCHED_DEFAULT - * - thread priority is 0 - */ - -#include -#include "os/os.h" - -/** \brief Initialize thread attributes - * - * - Set \b procAttr->schedClass to \b OS_SCHED_DEFAULT - * (take the platforms default scheduling class, Time-sharing for - * non realtime platforms, Real-time for realtime platforms) - * - Set \b procAttr->schedPriority to \b 0 - */ -void -os_threadAttrInit ( - os_threadAttr *threadAttr) -{ - assert (threadAttr != NULL); - threadAttr->schedClass = OS_SCHED_DEFAULT; - threadAttr->schedPriority = 0; - threadAttr->stackSize = 0; -} - -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); -} diff --git a/src/os/src/os_time.c b/src/os/src/os_time.c deleted file mode 100644 index ca06038..0000000 --- a/src/os/src/os_time.c +++ /dev/null @@ -1,355 +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 - */ -/** \file os/common/code/os_time.c - * \brief Common time management services - * - * Implements os_timeAdd, os_timeSub, os_timeCompare, - * os_timeAbs, os_timeMulReal, os_timeToReal, os_realToTime - * which are platform independent - */ - -#include -#include -#include -#include "os/os.h" - -/* double type definition for calculations in os_timeMulReal */ -/* Can be adapted to available and required accuracy */ -typedef double os_cdouble; - -/** \brief return value of \b t1 + \b t2 - * - * If the value \b t1 + \b t2 does not fit in os_time the value - * will be incorrect. - */ -os_time os_timeAdd(os_time t1, os_time t2) -{ - os_time tr; - - assert (t1.tv_nsec >= 0); - assert (t1.tv_nsec < 1000000000); - assert (t2.tv_nsec >= 0); - assert (t2.tv_nsec < 1000000000); - - tr.tv_nsec = t1.tv_nsec + t2.tv_nsec; - tr.tv_sec = t1.tv_sec + t2.tv_sec; - if (tr.tv_nsec >= 1000000000) { - tr.tv_sec++; - tr.tv_nsec = tr.tv_nsec - 1000000000; - } - return tr; -} - -/** \brief return value of \b t1 - \b t2 - * - * If the value \b t1 - \b t2 does not fit in os_time the value - * will be incorrect. - */ -os_time os_timeSub(os_time t1, os_time t2) -{ - os_time tr; - - assert (t1.tv_nsec >= 0); - assert (t1.tv_nsec < 1000000000); - assert (t2.tv_nsec >= 0); - assert (t2.tv_nsec < 1000000000); - - if (t1.tv_nsec >= t2.tv_nsec) { - tr.tv_nsec = t1.tv_nsec - t2.tv_nsec; - tr.tv_sec = t1.tv_sec - t2.tv_sec; - } else { - tr.tv_nsec = t1.tv_nsec - t2.tv_nsec + 1000000000; - tr.tv_sec = t1.tv_sec - t2.tv_sec - 1; - } - return tr; -} - -/** \brief Compare \b t1 with \b t2 - * - * - If the value of \b t1 < value of \b t2 return \b OS_LESS - * - If the value of \b t1 > value of \b t2 return \b OS_MORE - * - If the value of \b t1 equals the value of \b t2 return \b OS_EQUAL - */ -int -os_timeCompare( - os_time t1, - os_time t2) -{ - int rv; - - assert (t1.tv_nsec >= 0); - assert (t1.tv_nsec < 1000000000); - assert (t2.tv_nsec >= 0); - assert (t2.tv_nsec < 1000000000); - - if (t1.tv_sec < t2.tv_sec) { - rv = -1; - } else if (t1.tv_sec > t2.tv_sec) { - rv = 1; - } else if (t1.tv_nsec < t2.tv_nsec) { - rv = -1; - } else if (t1.tv_nsec > t2.tv_nsec) { - rv = 1; - } else { - rv = 0; - } - return rv; -} - -/** \brief return absolute value \b t - * - * If the value |\b t| does not fit in os_time the value - * will be incorrect. - */ -os_time -os_timeAbs( - os_time t) -{ - os_time tr; - - assert (t.tv_nsec >= 0); - assert (t.tv_nsec < 1000000000); - - if (t.tv_sec < 0) { - tr.tv_sec = -t.tv_sec - 1; - tr.tv_nsec = 1000000000 - t.tv_nsec; - } else { - tr.tv_sec = t.tv_sec; - tr.tv_nsec = t.tv_nsec; - } - return tr; -} - -/** \brief return value \b t * \b multiply - * - * if the result value does not fit in os_time the value - * will be incorrect. - */ -os_time -os_timeMulReal( - os_time t, - double multiply) -{ - os_time tr; - os_cdouble trr; - os_cdouble sec; - os_cdouble nsec; - - assert (t.tv_nsec >= 0); - assert (t.tv_nsec < 1000000000); - - sec = (os_cdouble)t.tv_sec; - nsec = (os_cdouble)t.tv_nsec / (os_cdouble)1000000000.0; - trr = (sec + nsec) * multiply; - if (trr >= 0.0) { - tr.tv_sec = (os_timeSec)trr; - tr.tv_nsec = (int)((trr-(os_cdouble)tr.tv_sec) * (os_cdouble)1000000000.0); - } else { - tr.tv_sec = (os_timeSec)trr - 1; - tr.tv_nsec = (int)((trr-(os_cdouble)tr.tv_sec) * (os_cdouble)1000000000.0); - } - return tr; -} - -/** \brief return floating point representation of \b t - * - * because of the limited floating point represenation (64 bits) - * the value will be limited to a resoltion of about 1 us. - */ -os_timeReal -os_timeToReal( - os_time t) -{ - volatile os_timeReal tr; /* This var is volatile to bypass a GCC 3.x bug on X86 */ - - assert (t.tv_nsec >= 0); - assert (t.tv_nsec < 1000000000); - - tr = (os_timeReal)t.tv_sec + (os_timeReal)t.tv_nsec / (os_timeReal)1000000000.0; - - return tr; -} - -/** \brief return os_time represenation of floating time \b t - * - * because of the limited floating point represenation (64 bits) - * the value will be limited to a resoltion of about 1 us. - */ -os_time -os_realToTime( - os_timeReal t) -{ - os_time tr; - - if (t >= 0.0) { - tr.tv_sec = (os_timeSec)t; - tr.tv_nsec = (int)((t-(os_timeReal)tr.tv_sec) * (os_timeReal)1000000000.0); - } else { - tr.tv_sec = (os_timeSec)t - 1; - tr.tv_nsec = (int)((t-(os_timeReal)tr.tv_sec) * (os_timeReal)1000000000.0); - } - assert(tr.tv_nsec >= 0 && tr.tv_nsec < 1000000000); - return tr; -} - -#if 0 -os_result -os_timeGetPowerEvents( - os_timePowerEvents *events, - os_time maxBlockingTime) -{ - static os_time mt_el_offset; /* offset of os_timeGetElapsed() to os_timeGetMonotonic */ - static int mt_el_offset_isset; - const os_time maxPowerEventDiffTime = { 3, 0 }; /* use 3 seconds as the threshold to determine whether a power event has occurred or not */ - const os_time delay = { 0, 100000000 }; /* 100ms; seems a good balance between performance vs. reactivy */ - static const os_time zeroTime = { 0, 0 }; - os_time toBlock, delta, mt, el; - os_boolean stateEqualsEvents; - os_boolean timeoutDetected = OS_FALSE; - static os_timePowerEvents state; - - assert(events); - - toBlock = maxBlockingTime; - - do { - /* TODO: When OSPL-4394 (clock-property querying) is done, this loop can - * be skipped when either of the clocks isn't available with the right - * properties. Perhaps the call should even return something to signal - * that this call isn't supported. */ - mt = os_timeGetMonotonic(); - el = os_timeGetElapsed(); /* Determine el last */ - - /* This isn't thread-safe, but since syncing should be more or less - * idempotent, this doesn't matter functionally. */ - if(!mt_el_offset_isset){ - mt_el_offset = os_timeSub(mt, el); - mt_el_offset_isset = 1; - } - - /* A resume event is detected when the elapsed time differs from the - * monotonic time (expressed in elapsed-time) > maxPowerEventDiffTime. */ - delta = os_timeSub(el, os_timeSub(mt, mt_el_offset)); - if (os_timeCompare(delta, maxPowerEventDiffTime) == OS_MORE) { - pa_inc32_nv(&state.resumeCount); - /* Updating state.resumeLastDetected is NOT thread-safe! Consequently, - * these could be assigned an incorrect time value that does not - * reflect the actual time of occurrence of a power event when - * different threads are setting this value concurrently. The time - * value is (according to the interface) supposed to be used for - * logging only. */ - state.resumeLastDetected = os_timeGet(); - } - - /* In all cases after the above check, the clocks can be re-synced. This - * isn't thread-safe, but since re-syncing should be more or less - * idempotent, this doesn't matter functionally. */ - mt_el_offset = os_timeSub(mt, el); - - /* If maxBlockingTime == 0, events is not an in-parameter, so its - * contents shouldn't be inspected. Furthermore, the function should - * never return os_resultTimeOut in this case, so break out of the loop. */ - if(os_timeCompare(maxBlockingTime, zeroTime) == OS_EQUAL){ - break; - } - - stateEqualsEvents = (memcmp(&state, events, sizeof state) == 0) ? OS_TRUE : OS_FALSE; - - if (stateEqualsEvents == OS_TRUE) { - if (os_timeCompare(toBlock, zeroTime) == OS_EQUAL) { - /* maxBlockingTime reached, break the loop */ - timeoutDetected = OS_TRUE; - } else if (os_timeCompare(delay, toBlock) == OS_LESS) { - /* It is safe to sleep for delay */ - os_nanoSleep(delay); - /* Set the new max blocking time and redo the loop. */ - toBlock = os_timeSub(toBlock, delay); - } else { - /* The time to block is less than delay. */ - os_nanoSleep(toBlock); - /* Set the resulting max blocking time zero to check for power - * events one more time. */ - toBlock = zeroTime; - } - } - } while ( (stateEqualsEvents == OS_TRUE) && (timeoutDetected == OS_FALSE) ); - - /* Store current state in events */ - *events = state; - - return timeoutDetected ? os_resultTimeout : os_resultSuccess; -} -#endif - -/* All implementations have to implement the os__timeDefaultTimeGet() function. - * This is the default clock that is used for os_timeGet(). This wrapper - * implements the ability to set a user-clock. */ - -/* Const-pointer to the default time implementation function. */ -static os_time (*const os_time_clockGetDefaultFunc)(void) = os__timeDefaultTimeGet; -/* Pointer to the actual time implementation function. */ -static os_time (*os_time_clockGetFunc)(void) = os__timeDefaultTimeGet; - -/** \brief Set the user clock - * - * \b os_timeSetUserClock sets the current time source - * get function. - */ -void -os_timeSetUserClock( - os_time (*userClock)(void)) -{ - if (userClock) { - os_time_clockGetFunc = userClock; - } else { - os_time_clockGetFunc = os_time_clockGetDefaultFunc; - } -} - -/** \brief Get the current time - * - * This common wrapper implements the user-clock overloading. - */ -os_time -os_timeGet ( - void) -{ - return os_time_clockGetFunc(); -} - -size_t os_ctime_r (os_time *t, char *buf, size_t bufsz) -{ - size_t result = 0; - time_t tt = t->tv_sec; - - assert(bufsz >= OS_CTIME_R_BUFSIZE); - - if (buf) { - /* This should be common code. But unfortunately, VS2012 C Runtime contains - * a bug that causes a crash when using %Z with a buffer that is too small: - * https://connect.microsoft.com/VisualStudio/feedback/details/782889/ - * So, don't execute strftime with %Z when VS2012 is the compiler. */ -#if !(_MSC_VER == 1700) - result = strftime(buf, bufsz, "%a %b %d %H:%M:%S %Z %Y", localtime(&tt)); -#endif - - if(result == 0) { - /* If not enough room was available, the %Z (time-zone) is left out - * resulting in the output as expected from ctime_r. */ - result = strftime(buf, bufsz, "%a %b %d %H:%M:%S %Y", localtime(&tt)); - assert(result); - } - } - return result; -} - - diff --git a/src/os/src/posix/os_platform_errno.c b/src/os/src/posix/os_platform_errno.c deleted file mode 100644 index 9572b08..0000000 --- a/src/os/src/posix/os_platform_errno.c +++ /dev/null @@ -1,12 +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 - */ -#include "../snippets/code/os_posix_errno.c" diff --git a/src/os/src/posix/os_platform_heap.c b/src/os/src/posix/os_platform_heap.c deleted file mode 100644 index a2f6698..0000000 --- a/src/os/src/posix/os_platform_heap.c +++ /dev/null @@ -1,19 +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 - */ -/** \file os/darwin/code/os_heap.c - * \brief Darwin heap memory management - * - * Implements heap memory management for Darwin - * by including the common implementation - */ - -#include "../snippets/code/os_heap.c" diff --git a/src/os/src/posix/os_platform_ifaddrs.c b/src/os/src/posix/os_platform_ifaddrs.c deleted file mode 100644 index 07736f5..0000000 --- a/src/os/src/posix/os_platform_ifaddrs.c +++ /dev/null @@ -1,119 +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 - */ -#include -#include - -#include "os/os.h" - -extern const int *const os_supp_afs; - -static int -copyaddr(os_ifaddrs_t **ifap, const struct ifaddrs *sys_ifa) -{ - int err = 0; - os_ifaddrs_t *ifa; - size_t sz; - - assert(ifap != NULL); - assert(sys_ifa != NULL); - - sz = os_sockaddr_get_size(sys_ifa->ifa_addr); - ifa = os_calloc_s(1, sizeof(*ifa)); - if (ifa == NULL) { - err = errno; - } else { - ifa->index = if_nametoindex(sys_ifa->ifa_name); - ifa->flags = sys_ifa->ifa_flags; - if ((ifa->name = os_strdup(sys_ifa->ifa_name)) == NULL || - (ifa->addr = os_memdup(sys_ifa->ifa_addr, sz)) == NULL || - (sys_ifa->ifa_netmask != NULL && - (ifa->netmask = os_memdup(sys_ifa->ifa_netmask, sz)) == NULL) || - (sys_ifa->ifa_broadaddr != NULL && - (sys_ifa->ifa_flags & IFF_BROADCAST) && - (ifa->broadaddr = os_memdup(sys_ifa->ifa_broadaddr, sz)) == NULL)) - { - err = errno; - } - /* Seen on macOS using OpenVPN: netmask without an address family, - in which case copy it from the interface address */ - if (ifa->addr && ifa->netmask && ifa->netmask->sa_family == 0) { - ifa->netmask->sa_family = ifa->addr->sa_family; - } - } - - if (err == 0) { - *ifap = ifa; - } else { - os_freeifaddrs(ifa); - } - - return err; -} - -_Success_(return == 0) int -os_getifaddrs( - _Inout_ os_ifaddrs_t **ifap, - _In_opt_ const int *afs) -{ - int err = 0; - int use; - os_ifaddrs_t *ifa, *ifa_root, *ifa_next; - struct ifaddrs *sys_ifa, *sys_ifa_root; - struct sockaddr *sa; - - assert(ifap != NULL); - - if (afs == NULL) { - afs = os_supp_afs; - } - - if (getifaddrs(&sys_ifa_root) == -1) { - err = errno; - } else { - ifa = ifa_root = NULL; - - for (sys_ifa = sys_ifa_root; - sys_ifa != NULL && err == 0; - sys_ifa = sys_ifa->ifa_next) - { - sa = sys_ifa->ifa_addr; - if (sa != NULL) { - use = 0; - for (int i = 0; !use && afs[i] != OS_AF_NULL; i++) { - use = (sa->sa_family == afs[i]); - } - - if (use) { - err = copyaddr(&ifa_next, sys_ifa); - if (err == 0) { - if (ifa == NULL) { - ifa = ifa_root = ifa_next; - } else { - ifa->next = ifa_next; - ifa = ifa_next; - } - } - } - } - } - - freeifaddrs(sys_ifa_root); - - if (err == 0) { - *ifap = ifa_root; - } else { - os_freeifaddrs(ifa_root); - } - } - - return err; -} diff --git a/src/os/src/posix/os_platform_init.c b/src/os/src/posix/os_platform_init.c deleted file mode 100644 index ac9b874..0000000 --- a/src/os/src/posix/os_platform_init.c +++ /dev/null @@ -1,57 +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 - */ -/**************************************************************** - * Initialization / Deinitialization * - ****************************************************************/ - -/** \file os/darwin/code/os_init.c - * \brief Initialization / Deinitialization - */ - -#include -#include "os/os.h" - -/** \brief OS layer initialization - * - * \b os_osInit calls: - * - \b os_sharedMemoryInit - * - \b os_threadInit - */ -void os_osPlatformInit (void) -{ - os_syncModuleInit(); - os_threadModuleInit(); -} - -/** \brief OS layer deinitialization - */ -void os_osPlatformExit (void) -{ - os_threadModuleExit(); - os_syncModuleExit(); -} - -/* This constructor is invoked when the library is loaded into a process. */ -void __attribute__ ((constructor)) -os__osInit( - void) -{ - os_osInit(); -} - -/* This destructor is invoked when the library is unloaded from a process. */ -void __attribute__ ((destructor)) -os__osExit( - void) -{ - os_osExit(); -} diff --git a/src/os/src/posix/os_platform_rusage.c b/src/os/src/posix/os_platform_rusage.c deleted file mode 100644 index 5e3416d..0000000 --- a/src/os/src/posix/os_platform_rusage.c +++ /dev/null @@ -1,93 +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 - */ -#define _GNU_SOURCE /* Required for RUSAGE_THREAD. */ -#include -#include -#include -#include - -#if defined(__APPLE__) -#include -#include -#include -#endif - -#include "os/os.h" - -_Pre_satisfies_((who == OS_RUSAGE_SELF) || \ - (who == OS_RUSAGE_THREAD)) -_Success_(return == 0) -int os_getrusage(_In_ int who, _Out_ os_rusage_t *usage) -{ - int err = 0; - struct rusage buf; - - assert(who == OS_RUSAGE_SELF || who == OS_RUSAGE_THREAD); - assert(usage != NULL); - - memset(&buf, 0, sizeof(buf)); - -#if defined(__linux) - if (getrusage(who, &buf) == -1) { - err = errno; - } else { - buf.ru_maxrss *= 1024; - } -#else - if (getrusage(RUSAGE_SELF, &buf) == -1) { - err = errno; - } else if (who == OS_RUSAGE_THREAD) { - memset(&buf.ru_utime, 0, sizeof(buf.ru_utime)); - memset(&buf.ru_stime, 0, sizeof(buf.ru_stime)); - buf.ru_nvcsw = 0; - buf.ru_nivcsw = 0; - -#if defined(__APPLE__) - kern_return_t ret; - mach_port_t thr; - mach_msg_type_number_t cnt; - thread_basic_info_data_t info; - - thr = mach_thread_self(); - assert(thr != MACH_PORT_DEAD); - if (thr == MACH_PORT_NULL) { - /* Resource shortage prevented reception of send right. */ - err = ENOMEM; - } else { - cnt = THREAD_BASIC_INFO_COUNT; - ret = thread_info( - thr, THREAD_BASIC_INFO, (thread_info_t)&info, &cnt); - assert(ret != KERN_INVALID_ARGUMENT); - /* Assume MIG_ARRAY_TOO_LARGE will not happen. */ - buf.ru_utime.tv_sec = info.user_time.seconds; - buf.ru_utime.tv_usec = info.user_time.microseconds; - buf.ru_stime.tv_sec = info.system_time.seconds; - buf.ru_stime.tv_usec = info.system_time.microseconds; - mach_port_deallocate(mach_task_self(), thr); - } -#endif /* __APPLE__ */ - } -#endif /* __linux */ - - if (err == 0) { - usage->utime.tv_sec = (os_timeSec)buf.ru_utime.tv_sec; - usage->utime.tv_nsec = (int32_t)buf.ru_utime.tv_usec * 1000; - usage->stime.tv_sec = (os_timeSec)buf.ru_stime.tv_sec; - usage->stime.tv_nsec = (int32_t)buf.ru_stime.tv_usec * 1000; - usage->maxrss = (size_t)buf.ru_maxrss; - usage->idrss = (size_t)buf.ru_idrss; - usage->nvcsw = (size_t)buf.ru_nvcsw; - usage->nivcsw = (size_t)buf.ru_nivcsw; - } - - return err; -} diff --git a/src/os/src/posix/os_platform_socket.c b/src/os/src/posix/os_platform_socket.c deleted file mode 100644 index 92af40f..0000000 --- a/src/os/src/posix/os_platform_socket.c +++ /dev/null @@ -1,232 +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 - */ -#include -#include -#include -#ifndef __VXWORKS__ -#include -#endif -#include "os/os.h" - -os_socket -os_sockNew( - int domain, - int type) -{ - return socket (domain, type, 0); -} - -os_result -os_sockBind( - os_socket s, - const struct sockaddr *name, - uint32_t namelen) -{ - os_result result = os_resultSuccess; - - if (bind(s, (struct sockaddr *)name, (unsigned)namelen) == -1) { - result = os_resultFail; - } - return result; -} - -os_result -os_sockGetsockname( - os_socket s, - const struct sockaddr *name, - uint32_t namelen) -{ - os_result result = os_resultSuccess; - socklen_t len = namelen; - - if (getsockname(s, (struct sockaddr *)name, &len) == -1) { - result = os_resultFail; - } - return result; -} - -os_result -os_sockSendto( - os_socket s, - const void *msg, - size_t len, - const struct sockaddr *to, - size_t tolen, - size_t *bytesSent) -{ - ssize_t res; - assert (tolen <= 0x7fffffff); - res = sendto(s, msg, len, 0, to, (socklen_t) tolen); - if (res < 0) - { - *bytesSent = 0; - return os_resultFail; - } - else - { - *bytesSent = (size_t) res; - return os_resultSuccess; - } -} - -os_result -os_sockRecvfrom( - os_socket s, - void *buf, - size_t len, - struct sockaddr *from, - size_t *fromlen, - size_t *bytesRead) -{ - ssize_t res; - socklen_t fl; - assert (*fromlen <= 0x7fffffff); - fl = (socklen_t) *fromlen; - res = recvfrom(s, buf, len, 0, from, &fl); - if (res < 0) - { - *bytesRead = 0; - return os_resultFail; - } - else - { - *fromlen=fl; - *bytesRead = (size_t)res; - return os_resultSuccess; - } -} - -os_result -os_sockGetsockopt( - os_socket s, - int32_t level, - int32_t optname, - void *optval, - uint32_t *optlen) -{ - int res; - socklen_t ol = *optlen; - res = getsockopt(s, level, optname, optval, &ol); - *optlen = ol; - return ( res == -1 ? os_resultFail : os_resultSuccess ); -} - -os_result -os_sockSetsockopt( - os_socket s, - int32_t level, - int32_t optname, - const void *optval, - uint32_t optlen) -{ - os_result result = os_resultSuccess; - - if (optname == SO_SNDBUF || optname == SO_RCVBUF) - { - if (optlen == 4 && *((unsigned *) optval) == 0) - { - /* We know this won't work */ - return os_resultSuccess; - } - } - else if (optname == SO_DONTROUTE) - { - /* Enabling DONTROUTE gives nothing but grief on MacOS (e.g., no multicasting), - and I'm not aware of any serious use-case. */ - return os_resultSuccess; - } - - if (setsockopt(s, level, optname, optval, optlen) == -1) { - result = os_resultFail; - } - -#ifdef __APPLE__ - if (result == os_resultSuccess && level == SOL_SOCKET && optname == SO_REUSEADDR) - { - if (setsockopt(s, level, SO_REUSEPORT, optval, optlen) == -1) - { - result = os_resultFail; - } - } -#endif - - return result; -} - -os_result -os_sockSetNonBlocking( - os_socket s, - bool nonblock) -{ - int oldflags; - os_result r; - - assert(nonblock == false || nonblock == true); - - oldflags = fcntl(s, F_GETFL, 0); - if(oldflags >= 0){ - if (nonblock){ - oldflags |= O_NONBLOCK; - } else { - oldflags &= ~O_NONBLOCK; - } - if(fcntl (s, F_SETFL, oldflags) == 0){ - r = os_resultSuccess; - } else { - r = os_resultFail; - } - } else { - switch(os_getErrno()){ - case EAGAIN: - r = os_resultBusy; - break; - case EBADF: - r = os_resultInvalid; - break; - default: - r = os_resultFail; - break; - } - } - - return r; -} - -os_result -os_sockFree( - os_socket s) -{ - os_result result = os_resultSuccess; - - if (close(s) == -1) { - result = os_resultFail; - } - return result; -} - -int32_t -os_sockSelect( - int32_t nfds, - fd_set *readfds, - fd_set *writefds, - fd_set *errorfds, - os_time *timeout) -{ - struct timeval t; - int r; - - t.tv_sec = timeout->tv_sec; - t.tv_usec = timeout->tv_nsec / 1000; - r = select(nfds, readfds, writefds, errorfds, &t); - - return r; -} diff --git a/src/os/src/posix/os_platform_stdlib.c b/src/os/src/posix/os_platform_stdlib.c deleted file mode 100644 index e7a5c98..0000000 --- a/src/os/src/posix/os_platform_stdlib.c +++ /dev/null @@ -1,22 +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 - */ -#include -#include -#include "os/os.h" - -#define OS_HAS_STRTOK_R 1 -#include "../snippets/code/os_gethostname.c" -#include "../snippets/code/os_stdlib.c" -#include "../snippets/code/os_stdlib_bsearch.c" -#include "../snippets/code/os_stdlib_strtod.c" -#include "../snippets/code/os_stdlib_strtol.c" -#include "../snippets/code/os_stdlib_strtok_r.c" diff --git a/src/os/src/posix/os_platform_sync.c b/src/os/src/posix/os_platform_sync.c deleted file mode 100644 index 8c4a75f..0000000 --- a/src/os/src/posix/os_platform_sync.c +++ /dev/null @@ -1,368 +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 - */ -#include -#include -#include -#include -#include -#include -#include - -#include "os/os.h" - -#if HAVE_LKST -#include "lkst.h" -#include "mach/mach_time.h" - -extern int ospl_lkst_enabled; -#endif - -static bool ospl_mtx_prio_inherit = false; -#if HAVE_LKST -int ospl_lkst_enabled; -#endif - -#if defined __GLIBC_PREREQ -#if __GLIBC_PREREQ(2,5) -#define OSPL_PRIO_INHERIT_SUPPORTED -#endif -#endif - -#if HAVE_LKST -static void random_delay(unsigned long long t) -{ - unsigned z = (unsigned)((t * 16292676669999574021ull) >> 32); - struct timespec ts; - /* delay ~ 10% of the lock operations */ - if ((z & 1023) < 900) - return; - /* delay by up to < 16ms */ - ts.tv_sec = 0; - ts.tv_nsec = (z >> 10) & 16383; - (void) nanosleep (&ts, NULL); -} -#endif - -void os_syncModuleInit(void) -{ -#if HAVE_LKST - ospl_lkst_enabled = lkst_init (1); -#endif - ospl_mtx_prio_inherit = 0; -} - -void os_syncModuleExit(void) -{ -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_fini (); -#endif -} - -os_result os_mutexSetPriorityInheritanceMode(bool enabled) -{ - ospl_mtx_prio_inherit = enabled; - return os_resultSuccess; -} - -void os_mutexInit (os_mutex *mutex) -{ - int shared; - assert (mutex != NULL); - - pthread_mutex_init (&mutex->mutex, NULL); -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_track_init (mutex, shared ? LKST_MF_SHARED : 0); -#else - (void)shared; -#endif -} - -void os_mutexDestroy (os_mutex *mutex) -{ - assert (mutex != NULL); -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_track_destroy (mutex); -#endif - - if (pthread_mutex_destroy (&mutex->mutex) != 0) - abort(); -} - -void os_mutexLock (os_mutex *mutex) -{ - assert (mutex != NULL); - -#if HAVE_LKST - if (!ospl_lkst_enabled) -#endif - { - if (pthread_mutex_lock (&mutex->mutex) != 0) - abort(); - } -#if HAVE_LKST - else - { - unsigned long long t = mach_absolute_time (), dt; - if (ospl_lkst_enabled > 1) - random_delay (t); - if (pthread_mutex_trylock (&mutex->mutex) == 0) - dt = 0; - else - { - if (pthread_mutex_lock (&mutex->mutex) != 0) - abort(); - dt = 1 | (mach_absolute_time () - t); - } - lkst_track_op (mutex, LKST_LOCK, t, dt); - } -#endif -} - -os_result os_mutexLock_s (os_mutex *mutex) -{ - int result; - assert (mutex != NULL); - -#if HAVE_LKST - if (!ospl_lkst_enabled) -#endif - { - result = pthread_mutex_lock (&mutex->mutex); - } -#if HAVE_LKST - else - { - unsigned long long t = mach_absolute_time (), dt; - if (ospl_lkst_enabled > 1) - random_delay (t); - if ((result = pthread_mutex_trylock (&mutex->mutex)) == 0) - dt = 0; - else - { - result = pthread_mutex_lock (&mutex->mutex); - dt = 1 | (mach_absolute_time () - t); - } - lkst_track_op (mutex, LKST_LOCK, t, dt); - } -#endif - return (result == 0) ? os_resultSuccess : os_resultFail; -} - -os_result os_mutexTryLock (os_mutex *mutex) -{ - int result; - assert (mutex != NULL); - - result = pthread_mutex_trylock (&mutex->mutex); - if (result != 0 && result != EBUSY) - abort(); -#if HAVE_LKST - if (result == 0 && ospl_lkst_enabled) - lkst_track_op (mutex, LKST_LOCK, mach_absolute_time (), 0); -#endif - return (result == 0) ? os_resultSuccess : os_resultBusy; -} - -void os_mutexUnlock (os_mutex *mutex) -{ - assert (mutex != NULL); - -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_track_op (mutex, LKST_UNLOCK, mach_absolute_time (), 0); -#endif - if (pthread_mutex_unlock (&mutex->mutex) != 0) - abort(); -} - -void os_condInit (os_cond *cond, os_mutex *dummymtx __attribute__ ((unused))) -{ - assert (cond != NULL); - - pthread_cond_init (&cond->cond, NULL); -} - -void os_condDestroy (os_cond *cond) -{ - assert (cond != NULL); - - if (pthread_cond_destroy (&cond->cond) != 0) - abort(); -} - -void os_condWait (os_cond *cond, os_mutex *mutex) -{ - assert (cond != NULL); - assert (mutex != NULL); - -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_track_op (mutex, LKST_UNLOCK, mach_absolute_time (), 0); -#endif - if (pthread_cond_wait (&cond->cond, &mutex->mutex) != 0) - abort(); -#if HAVE_LKST - /* Have no way of determining whether it was uncontended or not, and - if not, how long the wait was. */ - if (ospl_lkst_enabled) - lkst_track_op (mutex, LKST_LOCK, mach_absolute_time (), 0); -#endif -} - -os_result os_condTimedWait (os_cond *cond, os_mutex *mutex, const os_time *time) -{ - struct timespec t; - int result; - os_time wakeup_time; - struct timeval tv; - os_time rt; - - assert (cond != NULL); - assert (mutex != NULL); - assert (time != NULL); - - (void) gettimeofday (&tv, NULL); - - rt.tv_sec = (os_timeSec) tv.tv_sec; - rt.tv_nsec = (int32_t) tv.tv_usec * 1000; - - wakeup_time = os_timeAdd (rt, *time); - t.tv_sec = wakeup_time.tv_sec; - t.tv_nsec = wakeup_time.tv_nsec; - -#if HAVE_LKST - if (ospl_lkst_enabled) - lkst_track_op (mutex, LKST_UNLOCK, mach_absolute_time (), 0); -#endif - /* By default Darwin uses the realtime clock in pthread_cond_timedwait(). - * Unfortunately Darwin has not (yet) implemented - * pthread_condattr_setclock(), so we cannot tell it to use the - * the monotonic clock. */ - result = pthread_cond_timedwait (&cond->cond, &mutex->mutex, &t); - if (result != 0 && result != ETIMEDOUT) - abort(); -#if HAVE_LKST - /* Have no way of determining whether it was uncontended or not, and - if not, how long the wait was. */ - if (ospl_lkst_enabled) - lkst_track_op (mutex, LKST_LOCK, mach_absolute_time (), 0); -#endif - return (result == ETIMEDOUT) ? os_resultTimeout : os_resultSuccess; -} - -void os_condSignal (os_cond *cond) -{ - assert (cond != NULL); - - if (pthread_cond_signal (&cond->cond) != 0) - abort(); -} - -void os_condBroadcast (os_cond *cond) -{ - assert (cond != NULL); - - if (pthread_cond_broadcast (&cond->cond) != 0) - abort(); -} - -void os_rwlockInit(os_rwlock *rwlock) -{ - int err = 0; - - assert(rwlock != NULL); - - /* process-shared attribute is set to PTHREAD_PROCESS_PRIVATE by default */ - if ((err = pthread_rwlock_init(&rwlock->rwlock, NULL)) != 0) { - abort(); - } -} - -void os_rwlockDestroy(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - if ((err = pthread_rwlock_destroy(&rwlock->rwlock)) != 0) { - abort(); - } -} - -void os_rwlockRead(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - err = pthread_rwlock_rdlock(&rwlock->rwlock); - assert(err == 0); - (void)err; -} - -void os_rwlockWrite(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - err = pthread_rwlock_wrlock(&rwlock->rwlock); - assert(err == 0); - (void)err; -} - -os_result os_rwlockTryRead(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - err = pthread_rwlock_tryrdlock(&rwlock->rwlock); - assert(err == 0 || err == EBUSY); - - return err == 0 ? os_resultSuccess : os_resultBusy; -} - -os_result os_rwlockTryWrite(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - err = pthread_rwlock_trywrlock(&rwlock->rwlock); - assert(err == 0 || err == EBUSY); - - return err == 0 ? os_resultSuccess : os_resultBusy; -} - -void os_rwlockUnlock(os_rwlock *rwlock) -{ - int err; - - assert(rwlock != NULL); - - err = pthread_rwlock_unlock(&rwlock->rwlock); - assert(err == 0); - (void)err; -} - -void -os_once( - _Inout_ os_once_t *control, - _In_ os_once_fn init_fn) -{ - /* There are no defined errors that can be returned by pthread_once */ - (void)pthread_once(control, init_fn); -} diff --git a/src/os/src/posix/os_platform_thread.c b/src/os/src/posix/os_platform_thread.c deleted file mode 100644 index ce17c33..0000000 --- a/src/os/src/posix/os_platform_thread.c +++ /dev/null @@ -1,12 +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 - */ -#include "../snippets/code/os_posix_thread.c" diff --git a/src/os/src/posix/os_platform_time.c b/src/os/src/posix/os_platform_time.c deleted file mode 100644 index 8173226..0000000 --- a/src/os/src/posix/os_platform_time.c +++ /dev/null @@ -1,149 +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 - */ -/** \file os/darwin/code/os_time.c - * \brief Darwin time management - * - * Implements time management for Darwin - */ -#include -#include -#include -#include -#include -#include "os/os.h" - -#ifndef __APPLE__ - -os_time os__timeDefaultTimeGet(void) -{ - static int timeshift = INT_MAX; - struct timespec t; - os_time rt; - - if(timeshift == INT_MAX) { - const char *p = getenv("OSPL_TIMESHIFT"); - timeshift = (p == NULL) ? 0 : atoi(p); - } - - (void) clock_gettime (CLOCK_REALTIME, &t); - - rt.tv_sec = (os_timeSec) t.tv_sec + timeshift; - rt.tv_nsec = (int32_t) t.tv_nsec; - - return rt; -} - -os_time os_timeGetMonotonic (void) -{ - struct timespec t; - os_time rt; - (void) clock_gettime (CLOCK_MONOTONIC, &t); - - rt.tv_sec = (os_timeSec) t.tv_sec; - rt.tv_nsec = (int32_t) t.tv_nsec; - - return rt; -} - -os_time os_timeGetElapsed (void) -{ - /* Elapsed time clock not worth the bother for now. */ - return os_timeGetMonotonic(); -} - -#else /* MacOS */ - -#include - -os_time os__timeDefaultTimeGet(void) -{ - static int timeshift = INT_MAX; - struct timeval tv; - os_time rt; - - if(timeshift == INT_MAX) { - const char *p = getenv("OSPL_TIMESHIFT"); - timeshift = (p == NULL) ? 0 : atoi(p); - } - - (void) gettimeofday (&tv, NULL); - - rt.tv_sec = (os_timeSec) tv.tv_sec + timeshift; - rt.tv_nsec = tv.tv_usec*1000; - - return rt; -} - -os_time os_timeGetMonotonic (void) -{ - static mach_timebase_info_data_t timeInfo; - os_time t; - uint64_t mt; - uint64_t mtNano; - - /* The Mach absolute time returned by mach_absolute_time is very similar to - * the QueryPerformanceCounter on Windows. The update-rate isn't fixed, so - * that information needs to be resolved to provide a clock with real-time - * progression. - * - * The mach_absolute_time does include time spent during sleep (on Intel - * CPU's, not on PPC), but not the time spent during suspend. - * - * The result is not adjusted based on NTP, so long-term progression by this - * clock may not match the time progression made by the real-time clock. */ - mt = mach_absolute_time(); - - if( timeInfo.denom == 0) { - (void) mach_timebase_info(&timeInfo); - } - mtNano = mt * timeInfo.numer / timeInfo.denom; - t.tv_sec = (os_timeSec) (mtNano / 1000000000); - t.tv_nsec = (int32_t) (mtNano % 1000000000); - - return t; -} - -os_time os_timeGetElapsed (void) -{ - /* Elapsed time clock not (yet) supported on this platform. */ - return os_timeGetMonotonic(); -} - -#endif - -os_result os_nanoSleep (os_time delay) -{ - struct timespec t; - struct timespec r; - int result; - os_result rv; - - if( delay.tv_sec >= 0 && delay.tv_nsec >= 0) { - /* Time should be normalized */ - assert (delay.tv_nsec < 1000000000); - t.tv_sec = delay.tv_sec; - t.tv_nsec = delay.tv_nsec; - result = nanosleep (&t, &r); - while (result && os_getErrno() == EINTR) { - t = r; - result = nanosleep (&t, &r); - } - if (result == 0) { - rv = os_resultSuccess; - } else { - rv = os_resultFail; - } - } else { - rv = os_resultFail; - } - return rv; -} diff --git a/src/os/src/snippets/code/os_gethostname.c b/src/os/src/snippets/code/os_gethostname.c deleted file mode 100644 index 5a49654..0000000 --- a/src/os/src/snippets/code/os_gethostname.c +++ /dev/null @@ -1,36 +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 - */ -#include - -#include "os/os.h" - -os_result -os_gethostname( - char *hostname, - size_t buffersize) -{ - os_result result; - char hostnamebuf[MAXHOSTNAMELEN]; - - if (gethostname (hostnamebuf, MAXHOSTNAMELEN) == 0) { - if ((strlen(hostnamebuf)+1) > buffersize) { - result = os_resultFail; - } else { - os_strlcpy (hostname, hostnamebuf, buffersize); - result = os_resultSuccess; - } - } else { - result = os_resultFail; - } - - return result; -} diff --git a/src/os/src/snippets/code/os_heap.c b/src/os/src/snippets/code/os_heap.c deleted file mode 100644 index 2d9aa7e..0000000 --- a/src/os/src/snippets/code/os_heap.c +++ /dev/null @@ -1,143 +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 - */ -/** \file os/common/code/os_heap.c - * \brief Heap memory management service - * - * Implements functions for allocation and freeing - * memory from and to heap respectively. - */ - -#include "os/os.h" - -/** \brief Allocate memory from heap - * - */ -_Check_return_ -_Ret_opt_bytecap_(size) -void * -os_malloc_s( - _In_ size_t size) -{ - return malloc(size ? size : 1); /* Allocate memory even if size == 0 */ -} - -_Check_return_ -_Ret_bytecap_(size) -void * -os_malloc( - _In_ size_t size) -{ - void *ptr = os_malloc_s(size); - - if(ptr == NULL) { - /* Heap exhausted */ - abort(); - } - - return ptr; -} - -_Check_return_ -_Ret_bytecount_(size) -void * -os_malloc_0(_In_ size_t size) -{ - return os_calloc(size, 1); -} - -_Check_return_ -_Ret_opt_bytecount_(size) -void * -os_malloc_0_s(_In_ size_t size) -{ - return os_calloc_s(size, 1); -} - -_Check_return_ -_Ret_bytecount_(count * size) -void * -os_calloc( - _In_ size_t count, - _In_ size_t size) -{ - char *ptr; - - ptr = os_calloc_s(count, size); - - if(ptr == NULL) { - /* Heap exhausted */ - abort(); - } - - return ptr; -} - -_Check_return_ -_Ret_opt_bytecount_(count * size) -void * -os_calloc_s( - _In_ size_t count, - _In_ size_t size) -{ - if(count == 0 || size == 0) { - count = size = 1; - } - return calloc(count, size); -} - -_Check_return_ -_Ret_bytecap_(size) -void * -os_realloc( - _Pre_maybenull_ _Post_ptr_invalid_ void *memblk, - _In_ size_t size) -{ - void *ptr; - - ptr = os_realloc_s(memblk, size); - - if(ptr == NULL){ - /* Heap exhausted */ - abort(); - } - - return ptr; -} - -_Success_(return != NULL) -_Check_return_ -_Ret_opt_bytecap_(size) -void * -os_realloc_s( - _Pre_maybenull_ _Post_ptr_invalid_ void *memblk, - _In_ size_t size) -{ - /* Even though newmem = realloc(mem, 0) is equivalent to calling free(mem), not all platforms - * will return newmem == NULL. We consistently do, so the result of a non-failing os_realloc_s - * always needs to be free'd, like os_malloc_s(0). */ - return realloc(memblk, size ? size : 1); -} - -/** \brief Free memory to heap - * - * \b os_free calls \b free which is a function pointer - * which defaults to \b free, but can be redefined via - * \b os_heapSetService. - */ -void -os_free ( - _Pre_maybenull_ _Post_ptr_invalid_ void *ptr) -{ - if (ptr) { - free (ptr); - } -} diff --git a/src/os/src/snippets/code/os_posix_thread.c b/src/os/src/snippets/code/os_posix_thread.c deleted file mode 100644 index d25193e..0000000 --- a/src/os/src/snippets/code/os_posix_thread.c +++ /dev/null @@ -1,512 +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 - */ -/** \file os/posix/code/os_thread.c - * \brief Posix thread management - * - * Implements thread management for POSIX - */ - -#include "os/os.h" - -#include -#include -#include -#include -#include -#include -#include -#include -/* TODO: should introduce a HAVE_PRCTL define rather than blacklisting some platforms */ -#if !defined __VXWORKS__ && !defined __APPLE__ && !defined __sun -#include -#endif -#include - -typedef struct { - char *threadName; - void *arguments; - uint32_t (*startRoutine) (void *); -} os_threadContext; - -static pthread_key_t os_threadNameKey; -static pthread_key_t os_threadMemKey; -static pthread_key_t cleanup_key; -static pthread_once_t cleanup_once = PTHREAD_ONCE_INIT; - -static sigset_t os_threadBlockAllMask; - -/** \brief Initialize the thread private memory array - * - * \b os_threadMemInit initializes the thread private memory array - * for the calling thread - * - * pre condition: - * os_threadMemKey is initialized - * - * post condition: - * pthreadMemArray is initialized - * or - * an appropriate error report is generated - */ -static void os_threadMemInit (void) -{ - const size_t sz = sizeof(void *) * OS_THREAD_MEM_ARRAY_SIZE; - void *pthreadMemArray; - int ret; - if ((pthreadMemArray = os_malloc (sz)) == NULL) - DDS_FATAL ("os_threadMemInit: out of memory\n"); - memset (pthreadMemArray, 0, sz); - if ((ret = pthread_setspecific (os_threadMemKey, pthreadMemArray)) != 0) - DDS_FATAL ("pthread_setspecific failed with error (%d), invalid threadMemKey value\n", ret); -} - -/** \brief Initialize the thread private memory array - * - * \b os_threadMemInit releases the thread private memory array - * for the calling thread, the allocated private memory areas - * referenced by the array are also freed. - * - * pre condition: - * os_threadMemKey is initialized - * - * post condition: - * pthreadMemArray is released - * or - * an appropriate error report is generated - */ -static void os_threadMemExit (void) -{ - void **pthreadMemArray = pthread_getspecific (os_threadMemKey); - if (pthreadMemArray != NULL) - { - int ret; - for (int i = 0; i < OS_THREAD_MEM_ARRAY_SIZE; i++) - if (pthreadMemArray[i] != NULL) - os_free (pthreadMemArray[i]); - os_free (pthreadMemArray); - if ((ret = pthread_setspecific (os_threadMemKey, NULL)) != 0) - DDS_FATAL ("pthread_setspecific failed with error %d\n", ret); - } -} - -/** \brief Initialize the thread module - * - * \b os_threadModuleInit initializes the thread module for the - * calling process - */ -void os_threadModuleInit (void) -{ - pthread_key_create (&os_threadNameKey, NULL); - pthread_key_create (&os_threadMemKey, NULL); - sigfillset(&os_threadBlockAllMask); - os_threadMemInit(); -} - -/** \brief Deinitialize the thread module - * - * \b os_threadModuleExit deinitializes the thread module for the - * calling process - */ -void os_threadModuleExit (void) -{ - os_threadMemExit(); - pthread_key_delete(os_threadNameKey); - pthread_key_delete(os_threadMemKey); -} - -/** \brief Wrap thread start routine - * - * \b os_startRoutineWrapper wraps a threads starting routine. - * before calling the user routine, it sets the threads name - * in the context of the thread. With \b pthread_getspecific, - * the name can be retreived for different purposes. - */ -static void *os_startRoutineWrapper (void *threadContext) -{ - os_threadContext *context = threadContext; - uintptr_t resultValue; - int ret; - -#if !defined(__VXWORKS__) && !defined(__APPLE__) && !defined(__sun) - /* FIXME: Switch to use pthread_setname_np in the future. - * Linux: pthread_setname_np(pthread_t, const char *) - * macOS: pthread_setname_np(const char *) - * FreeBSD: pthread_set_name_np(pthread_t, const char *) */ - prctl(PR_SET_NAME, context->threadName); -#endif - - /* store the thread name with the thread via thread specific data */ - if ((ret = pthread_setspecific (os_threadNameKey, context->threadName)) != 0) - DDS_FATAL ("pthread_setspecific failed with error %d, invalid os_threadNameKey value\n", ret); - - /* allocate an array to store thread private memory references */ - os_threadMemInit (); - - /* Call the user routine */ - resultValue = context->startRoutine (context->arguments); - - /* Free the thread context resources, arguments is responsibility */ - /* for the caller of os_procCreate */ - os_free (context->threadName); - os_free (context); - - /* deallocate the array to store thread private memory references */ - os_threadMemExit (); - - /* return the result of the user routine */ - return (void *)resultValue; -} - -/** \brief Create a new thread - * - * \b os_threadCreate creates a thread by calling \b pthread_create. - * But first it processes all thread attributes in \b threadAttr and - * sets the scheduling properties with \b pthread_attr_setscope - * to create a bounded thread, \b pthread_attr_setschedpolicy to - * set the scheduling class and \b pthread_attr_setschedparam to - * set the scheduling priority. - * \b pthread_attr_setdetachstate is called with parameter - * \PTHREAD_CREATE_JOINABLE to make the thread joinable, which - * is needed to be able to wait for the threads termination - * in \b os_threadWaitExit. - */ -os_result os_threadCreate (os_threadId *threadId, const char *name, const os_threadAttr *threadAttr, uint32_t (*start_routine) (void *), void *arg) -{ - pthread_attr_t attr; - os_threadContext *threadContext; - os_threadAttr tattr; - int result, create_ret; - - assert (threadId != NULL); - assert (name != NULL); - assert (threadAttr != NULL); - assert (start_routine != NULL); - tattr = *threadAttr; - - if (pthread_attr_init (&attr) != 0) - return os_resultFail; - -#ifdef __VXWORKS__ - /* PR_SET_NAME is not available on VxWorks. Use pthread_attr_setname instead (proprietary VxWorks extension) */ - (void) pthread_attr_setname (&attr, name); -#endif - - if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM) != 0 || - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE) != 0) - goto err; - - if (tattr.stackSize != 0) - { -#ifdef PTHREAD_STACK_MIN - if (tattr.stackSize < PTHREAD_STACK_MIN) - tattr.stackSize = PTHREAD_STACK_MIN; -#endif - if ((result = pthread_attr_setstacksize (&attr, tattr.stackSize)) != 0) - { - DDS_ERROR ("os_threadCreate(%s): pthread_attr_setstacksize(%"PRIu32") failed with error %d\n", name, tattr.stackSize, result); - goto err; - } - } - - if (tattr.schedClass == OS_SCHED_DEFAULT) - { - if (tattr.schedPriority != 0) - { - /* If caller doesn't set the class, he must not try to set the priority, which we - approximate by expecting a 0. FIXME: should do this as part of config validation */ - DDS_ERROR("os_threadCreate(%s): schedClass DEFAULT but priority != 0 is unsupported\n", name); - goto err; - } - } - else - { - int policy; - struct sched_param sched_param; - if ((result = pthread_getschedparam (pthread_self (), &policy, &sched_param) != 0) != 0) - { - DDS_ERROR("os_threadCreate(%s): pthread_attr_getschedparam(self) failed with error %d\n", name, result); - goto err; - } - switch (tattr.schedClass) - { - case OS_SCHED_DEFAULT: - assert (0); - break; - case OS_SCHED_REALTIME: - policy = SCHED_FIFO; - break; - case OS_SCHED_TIMESHARE: - policy = SCHED_OTHER; - break; - } - if ((result = pthread_attr_setschedpolicy (&attr, policy)) != 0) - { - DDS_ERROR("os_threadCreate(%s): pthread_attr_setschedpolicy(%d) failed with error %d\n", name, policy, result); - goto err; - } - sched_param.sched_priority = tattr.schedPriority; - if ((result = pthread_attr_setschedparam (&attr, &sched_param)) != 0) - { - DDS_ERROR("os_threadCreate(%s): pthread_attr_setschedparam(priority = %d) failed with error %d\n", name, tattr.schedPriority, result); - goto err; - } - if ((result = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED)) != 0) - { - DDS_ERROR("os_threadCreate(%s): pthread_attr_setinheritsched(EXPLICIT) failed with error %d\n", name, result); - goto err; - } - } - - /* Construct context structure & start thread */ - threadContext = os_malloc (sizeof (os_threadContext)); - threadContext->threadName = os_malloc (strlen (name) + 1); - strcpy (threadContext->threadName, name); - threadContext->startRoutine = start_routine; - threadContext->arguments = arg; - if ((create_ret = pthread_create (&threadId->v, &attr, os_startRoutineWrapper, threadContext)) != 0) - { - DDS_ERROR ("os_threadCreate(%s): pthread_create failed with error %d\n", name, create_ret); - goto err_create; - } - pthread_attr_destroy (&attr); - return os_resultSuccess; - -err_create: - os_free (threadContext->threadName); - os_free (threadContext); -err: - pthread_attr_destroy (&attr); - return os_resultFail; -} - -/** \brief Return the integer representation of the given thread ID - * - * Possible Results: - * - returns the integer representation of the given thread ID - */ -uintmax_t os_threadIdToInteger (os_threadId id) -{ - return (uintmax_t) ((uintptr_t) id.v); -} - -/** \brief Return the thread ID of the calling thread - * - * \b os_threadIdSelf determines the own thread ID by - * calling \b pthread_self. - */ -os_threadId os_threadIdSelf (void) -{ - os_threadId id = { .v = pthread_self () }; - return id; -} - -int32_t os_threadGetThreadName (char *buffer, uint32_t length) -{ - char *name; - if ((name = pthread_getspecific (os_threadNameKey)) == NULL) - name = ""; - return snprintf (buffer, length, "%s", name); -} - -/** \brief Wait for the termination of the identified thread - * - * \b os_threadWaitExit wait for the termination of the - * thread \b threadId by calling \b pthread_join. The return - * value of the thread is passed via \b thread_result. - */ -os_result os_threadWaitExit (os_threadId threadId, uint32_t *thread_result) -{ - int result; - void *vthread_result; - - assert (threadId.v); - -#if defined(__VXWORKS__) && !defined(_WRS_KERNEL) - struct sched_param sched_param; - int max, policy = 0; - - /* There is a known issue in pthread_join on VxWorks 6.x RTP mode. - - WindRiver: When pthread_join returns, it does not indicate end of a - thread in 100% of the situations. If the thread that calls pthread_join - has a higher priority than the thread that is currently terminating, - pthread_join could return before pthread_exit has finished. This - conflicts with the POSIX specification that dictates that pthread_join - must only return when the thread is really terminated. The workaround - suggested by WindRiver support is to increase the priority of the thread - (task) to be terminated before handing back the semaphore to ensure the - thread exits before pthread_join returns. - - This bug was submitted to WindRiver as TSR 815826. */ - - /* Note that any possible errors raised here are not terminal since the - thread may have exited at this point anyway. */ - if (pthread_getschedparam (threadId.v, &policy, &sched_param) == 0) { - max = sched_get_priority_max (policy); - if (max != -1) { - (void) pthread_setschedprio (threadId.v, max); - } - } -#endif - - if ((result = pthread_join (threadId.v, &vthread_result)) != 0) - { - DDS_TRACE ("pthread_join(0x%"PRIxMAX") failed with error %d\n", os_threadIdToInteger (threadId), result); - return os_resultFail; - } - - if (thread_result) - *thread_result = (uint32_t) ((uintptr_t) vthread_result); - return os_resultSuccess; -} - -/** \brief Allocate thread private memory - * - * Allocate heap memory of the specified \b size and - * relate it to the thread by storing the memory - * reference in an thread specific reference array - * indexed by \b index. If the indexed thread reference - * array location already contains a reference, no - * memory will be allocated and NULL is returned. - * - * Possible Results: - * - returns NULL if - * index < 0 || index >= OS_THREAD_MEM_ARRAY_SIZE - * - returns NULL if - * no sufficient memory is available on heap - * - returns NULL if - * os_threadMemGet (index) returns != NULL - * - returns reference to allocated heap memory - * of the requested size if - * memory is successfully allocated - */ -void *os_threadMemMalloc (int32_t index, size_t size) -{ - void **pthreadMemArray; - - assert (0 <= index && index < OS_THREAD_MEM_ARRAY_SIZE); - if ((pthreadMemArray = pthread_getspecific (os_threadMemKey)) == NULL) - { - os_threadMemInit (); - pthreadMemArray = pthread_getspecific (os_threadMemKey); - } - assert (pthreadMemArray[index] == NULL); - - pthreadMemArray[index] = os_malloc (size); - return pthreadMemArray[index]; -} - -/** \brief Free thread private memory - * - * Free the memory referenced by the thread reference - * array indexed location. If this reference is NULL, - * no action is taken. The reference is set to NULL - * after freeing the heap memory. - * - * Postcondition: - * - os_threadMemGet (index) = NULL and allocated - * heap memory is freed - */ -void os_threadMemFree (int32_t index) -{ - assert (0 <= index && index < OS_THREAD_MEM_ARRAY_SIZE); - void **pthreadMemArray = pthread_getspecific (os_threadMemKey); - if (pthreadMemArray != NULL && pthreadMemArray[index] != NULL) - { - os_free (pthreadMemArray[index]); - pthreadMemArray[index] = NULL; - } -} - -/** \brief Get thread private memory - * - * Possible Results: - * - returns NULL if - * 0 < index <= OS_THREAD_MEM_ARRAY_SIZE - * - returns NULL if - * No heap memory is related to the thread for - * the specified index - * - returns a reference to the allocated memory - */ -void *os_threadMemGet (int32_t index) -{ - assert (0 <= index && index < OS_THREAD_MEM_ARRAY_SIZE); - void **pthreadMemArray = pthread_getspecific (os_threadMemKey); - return (pthreadMemArray != NULL) ? pthreadMemArray[index] : NULL; -} - -static void os_threadCleanupFini (void *data) -{ - if (data == NULL) - return; - - os_iter *itr = data; - os_threadCleanup *obj; - for (obj = os_iterTake (itr, -1); obj != NULL; obj = os_iterTake (itr, -1)) - { - assert (obj->func != NULL); - obj->func (obj->data); - os_free (obj); - } - os_iterFree (itr, NULL); -} - -static void os_threadCleanupInit (void) -{ - int ret; - if ((ret = pthread_key_create (&cleanup_key, &os_threadCleanupFini)) != 0) - DDS_FATAL ("os_threadCleanupInit: pthread_key_create failed with error %d\n", ret); -} - -/* os_threadCleanupPush and os_threadCleanupPop are mapped onto a destructor - registered with pthread_key_create in stead of being mapped directly onto - pthread_cleanup_push/pthread_cleanup_pop because the cleanup routines could - otherwise be popped of the stack by the user */ -void os_threadCleanupPush (void (*func) (void *), void *data) -{ - os_iter *itr; - os_threadCleanup *obj; - - assert (func != NULL); - - (void) pthread_once (&cleanup_once, &os_threadCleanupInit); - if ((itr = pthread_getspecific (cleanup_key)) == NULL) - { - int ret; - itr = os_iterNew (); - assert (itr != NULL); - if ((ret = pthread_setspecific (cleanup_key, itr)) != 0) - DDS_FATAL ("os_threadCleanupPush: pthread_setspecific failed with error %d\n", ret); - } - - obj = os_malloc (sizeof (*obj)); - obj->func = func; - obj->data = data; - os_iterAppend (itr, obj); -} - -void os_threadCleanupPop (int execute) -{ - os_iter *itr; - - (void) pthread_once (&cleanup_once, &os_threadCleanupInit); - if ((itr = pthread_getspecific (cleanup_key)) != NULL) - { - os_threadCleanup *obj; - if ((obj = os_iterTake (itr, -1)) != NULL) - { - if (execute) - obj->func(obj->data); - os_free(obj); - } - } -} diff --git a/src/os/src/snippets/code/os_stdlib.c b/src/os/src/snippets/code/os_stdlib.c deleted file mode 100644 index 9787e2f..0000000 --- a/src/os/src/snippets/code/os_stdlib.c +++ /dev/null @@ -1,99 +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 - */ -#include "os/os.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "os_stdlib_strsep.c" -#include "os_stdlib_memdup.c" -#include "os_stdlib_rindex.c" -#include "os_stdlib_asprintf.c" -#include "os_stdlib_strcasecmp.c" -#include "os_stdlib_strncasecmp.c" -#include "os_stdlib_strdup.c" - -_Ret_opt_z_ const char * -os_getenv( - _In_z_ const char *variable) -{ - return getenv(variable); -} - -os_result -os_putenv( - char *variable_definition) -{ - os_result result; - - if (putenv (variable_definition) == 0) { - result = os_resultSuccess; - } else { - result = os_resultFail; - } - return result; -} - -int -os_vsnprintf( - char *str, - size_t size, - const char *format, - va_list args) -{ - return vsnprintf(str, size, format, args); -} - -ssize_t os_write(int fd, const void *buf, size_t count) -{ - return write(fd, buf, count); -} - -int os_getopt(int argc, char **argv, const char *opts) -{ - return getopt(argc, argv, opts); -} - -void os_set_opterr(int err) -{ - opterr = err; -} - -int os_get_opterr(void) -{ - return opterr; -} - -void os_set_optind(int index) -{ - optind = index; -} - -int os_get_optind(void) -{ - return optind; -} - -int os_get_optopt(void) -{ - return optopt; -} - -char * os_get_optarg(void) -{ - return optarg; -} diff --git a/src/os/src/snippets/code/os_stdlib_asprintf.c b/src/os/src/snippets/code/os_stdlib_asprintf.c deleted file mode 100644 index 9432375..0000000 --- a/src/os/src/snippets/code/os_stdlib_asprintf.c +++ /dev/null @@ -1,48 +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 - */ -#include "os/os.h" - -int -os_asprintf( - char **strp, - const char *fmt, - ...) -{ - int ret; - unsigned int len; - char buf[1] = { '\0' }; - char *str = NULL; - va_list args1, args2; - - assert(strp != NULL); - assert(fmt != NULL); - - va_start(args1, fmt); - va_copy(args2, args1); /* va_list cannot be reused */ - - if ((ret = os_vsnprintf(buf, sizeof(buf), fmt, args1)) >= 0) { - len = (unsigned int)ret; /* +1 for null byte */ - if ((str = os_malloc(len + 1)) == NULL) { - ret = -1; - } else if ((ret = os_vsnprintf(str, len + 1, fmt, args2)) >= 0) { - assert(((unsigned int)ret) == len); - *strp = str; - } else { - os_free(str); - } - } - - va_end(args1); - va_end(args2); - - return ret; -} diff --git a/src/os/src/snippets/code/os_stdlib_bsearch.c b/src/os/src/snippets/code/os_stdlib_bsearch.c deleted file mode 100644 index 081b550..0000000 --- a/src/os/src/snippets/code/os_stdlib_bsearch.c +++ /dev/null @@ -1,17 +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 - */ -void * -os_bsearch(const void *key, const void *base, size_t nmemb, size_t size, - int (*compar) (const void *, const void *)) -{ - return bsearch (key,base,nmemb,size,compar); -} diff --git a/src/os/src/snippets/code/os_stdlib_rindex.c b/src/os/src/snippets/code/os_stdlib_rindex.c deleted file mode 100644 index a1a8f1a..0000000 --- a/src/os/src/snippets/code/os_stdlib_rindex.c +++ /dev/null @@ -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 - */ -#include - -char * -os_rindex( - const char *s, - int c) -{ - char *last = NULL; - - while (*s) { - if (*s == c) { - last = (char *)s; - } - s++; - } - return last; -} diff --git a/src/os/src/snippets/code/os_stdlib_strcasecmp.c b/src/os/src/snippets/code/os_stdlib_strcasecmp.c deleted file mode 100644 index a784b8e..0000000 --- a/src/os/src/snippets/code/os_stdlib_strcasecmp.c +++ /dev/null @@ -1,34 +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 - */ -#include "os/os.h" - -#ifdef _MSC_VER -#pragma warning( default : 4996 ) -#endif /* _MSC_VER */ -int -os_strcasecmp( - const char *s1, - const char *s2) -{ - int cr; - - while (*s1 && *s2) { - cr = tolower(*s1) - tolower(*s2); - if (cr) { - return cr; - } - s1++; - s2++; - } - cr = tolower(*s1) - tolower(*s2); - return cr; -} diff --git a/src/os/src/snippets/code/os_stdlib_strdup.c b/src/os/src/snippets/code/os_stdlib_strdup.c deleted file mode 100644 index 3145f2e..0000000 --- a/src/os/src/snippets/code/os_stdlib_strdup.c +++ /dev/null @@ -1,23 +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 - */ -#include "os/os.h" - -_Ret_z_ -_Check_return_ -char * -os_strdup( - _In_z_ const char *str) -{ - assert(str != NULL); - - return os_memdup(str, strlen(str) + 1); -} diff --git a/src/os/src/snippets/code/os_stdlib_strncasecmp.c b/src/os/src/snippets/code/os_stdlib_strncasecmp.c deleted file mode 100644 index 753042d..0000000 --- a/src/os/src/snippets/code/os_stdlib_strncasecmp.c +++ /dev/null @@ -1,35 +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 - */ -#include "os/os.h" - -int -os_strncasecmp( - const char *s1, - const char *s2, - size_t n) -{ - int cr = 0; - - while (*s1 && *s2 && n) { - cr = tolower(*s1) - tolower(*s2); - if (cr) { - return cr; - } - s1++; - s2++; - n--; - } - if (n) { - cr = tolower(*s1) - tolower(*s2); - } - return cr; -} diff --git a/src/os/src/snippets/code/os_stdlib_strsep.c b/src/os/src/snippets/code/os_stdlib_strsep.c deleted file mode 100644 index 0a21265..0000000 --- a/src/os/src/snippets/code/os_stdlib_strsep.c +++ /dev/null @@ -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 - */ -#include "os/os_stdlib.h" - -char *os_strsep (char **str, const char *sep) -{ - char *ret; - if (**str == '\0') - return 0; - ret = *str; - while (**str && strchr (sep, **str) == 0) - (*str)++; - if (**str != '\0') - { - **str = '\0'; - (*str)++; - } - return ret; -} diff --git a/src/os/src/snippets/code/os_stdlib_strtod.c b/src/os/src/snippets/code/os_stdlib_strtod.c deleted file mode 100644 index b5cd6a5..0000000 --- a/src/os/src/snippets/code/os_stdlib_strtod.c +++ /dev/null @@ -1,187 +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 - */ -/** \file os/common/code/os_stdlib_strtod.c - * \brief Double/Float to/from string conversions - * - * OSPL uses '.' as decimal point. - * Most stdlib like functions are locale dependent. - * This means that they can't be simply used when the - * LC_NUMERIC part of the locale is set to ',' like - * the locales nl_NL and fr_FR. - * This would clash with OSPL using '.'. - * - * The functions in this file provide locale - * independent conversions. - */ - -/* - * Determine the maximum size that a string should have to be - * able to contain a double. - * See the following site for the calculation explanation: - * http://stackoverflow.com/questions/1701055/what-is-the-maximum-length-in-chars-needed-to-represent-any-double-value - */ -#include -#define DOUBLE_STRING_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP) - -/* - * VALID_DOUBLE_CHAR(c) is used to determine if the given char - * can be valid when it appears in a string that should represent - * a double. - * It is used to detect the end of a double string representation. - * Because it doesn't consider context, it is possible that more - * characters are detected after the double (fi. when a few white - * spaces tail the double). This isn't that bad, because the call - * to strtod itself will handle these extra characters properly. - */ -#define VALID_DOUBLE_CHAR(c) ( (isspace((unsigned char)(c))) || /* (leading) whitespaces */ \ - (isxdigit((unsigned char)(c))) || /* (hexa)decimal digits */ \ - ((c) == '.') || /* ospl LC_NUMERIC */ \ - ((c) == os_lcNumericGet()) || /* locale LC_NUMERIC */ \ - ((c) == '+') || ((c) == '-') || /* signs */ \ - ((c) == 'x') || ((c) == 'X') || /* hexadecimal indication */ \ - ((c) == 'e') || ((c) == 'E') || /* exponent chars */ \ - ((c) == 'p') || ((c) == 'P') || /* binary exponent chars */ \ - ((c) == 'a') || ((c) == 'A') || /* char for NaN */ \ - ((c) == 'n') || ((c) == 'N') || /* char for NaN & INFINITY */ \ - ((c) == 'i') || ((c) == 'I') || /* char for INFINITY */ \ - ((c) == 'f') || ((c) == 'F') || /* char for INFINITY */ \ - ((c) == 't') || ((c) == 'T') || /* char for INFINITY */ \ - ((c) == 'y') || ((c) == 'Y')) /* char for INFINITY */ - - - -/** \brief Detect and return the LC_NUMERIC char of the locale. - */ -static char -os_lcNumericGet(void) -{ - static char lcNumeric = ' '; - - /* Detect lcNumeric only once. */ - if (lcNumeric == ' ') { - /* There could be multiple threads here, but it is still save and works. - * Only side effect is that possibly multiple os_reports are traced. */ - char num[] = { '\0', '\0', '\0', '\0' }; - (void) snprintf(num, 4, "%3.1f", 2.2); - lcNumeric = num [1]; - if (lcNumeric != '.') { - DDS_WARNING("Locale with LC_NUMERIC \'%c\' detected, which is not '.'. " - "This can decrease performance.", lcNumeric); - } - } - - return lcNumeric; -} - - -/** \brief Replace lcNumeric char with '.' in floating point string when locale dependent - * functions use a non '.' LC_NUMERIC, while we want locale indepenent '.'. - */ -static void -os_lcNumericReplace(char *str) { - /* We only need to replace when standard functions - * did not put a '.' in the result string. */ - char lcNumeric = os_lcNumericGet(); - if (lcNumeric != '.') { - str = os_index(str, lcNumeric); - if (str != NULL) { - *str = '.'; - } - } -} - - -/** \brief Locale independent strtod wrapper. - */ -double -os_strtod(const char *nptr, char **endptr) { - double ret; - - if (os_lcNumericGet() == '.') { - /* The current locale uses '.', so we can use the - * standard functions as is. */ - ret = strtod(nptr, endptr); - } else { - /* The current locale uses ',', so we can not use the - * standard functions as is, but have to do extra work - * because ospl uses "x.x" doubles (notice the dot). - * Just copy the string and replace the LC_NUMERIC. */ - char nptrCopy[DOUBLE_STRING_MAX_LENGTH]; - char *nptrCopyIdx; - char *nptrCopyEnd; - char *nptrIdx; - - /* It is possible that the given nptr just starts with a double - * representation but continues with other data. - * To be able to copy not too much and not too little, we have - * to scan across nptr until we detect the doubles' end. */ - nptrIdx = (char*)nptr; - nptrCopyIdx = nptrCopy; - nptrCopyEnd = nptrCopyIdx + DOUBLE_STRING_MAX_LENGTH - 1; - while (VALID_DOUBLE_CHAR(*nptrIdx) && (nptrCopyIdx < nptrCopyEnd)) { - if (*nptrIdx == '.') { - /* Replace '.' with locale LC_NUMERIC to get strtod to work. */ - *nptrCopyIdx = os_lcNumericGet(); - } else { - *nptrCopyIdx = *nptrIdx; - } - nptrIdx++; - nptrCopyIdx++; - } - *nptrCopyIdx = '\0'; - - /* Now that we have a copy with the proper locale LC_NUMERIC, - * we can use strtod() for the conversion. */ - ret = strtod(nptrCopy, &nptrCopyEnd); - - /* Calculate the proper end char when needed. */ - if (endptr != NULL) { - *endptr = (char*)nptr + (nptrCopyEnd - nptrCopy); - } - } - return ret; -} - - -/** \brief Locale independent strtof wrapper. - */ -float -os_strtof(const char *nptr, char **endptr) { - /* Just use os_strtod(). */ - return (float)os_strtod(nptr, endptr); -} - - -/** \brief Locale independent snprintf wrapper, which mirrors os_strtod. - */ -int -os_dtostr(double src, char *str, size_t size) { - int i; - /* Use locale dependent standard function. */ - i = snprintf(str, size, "%0.15g", src); - /* Make sure the result is a locale independent "x.x" double. */ - os_lcNumericReplace(str); - return i; -} - - -/** \brief Locale independent snprintf wrapper, which mirrors os_strtof. - */ -int -os_ftostr(float src, char *str, size_t size) { - int i; - /* Use locale dependent standard function. */ - i = snprintf(str, size, "%0.7g", src); - /* Make sure the result is a locale independent "x.x" float. */ - os_lcNumericReplace(str); - return i; -} diff --git a/src/os/src/snippets/code/os_stdlib_strtok_r.c b/src/os/src/snippets/code/os_stdlib_strtok_r.c deleted file mode 100644 index 99d1a8b..0000000 --- a/src/os/src/snippets/code/os_stdlib_strtok_r.c +++ /dev/null @@ -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 - */ -char * -os_index( - const char *s, - int c) -{ - char *first = NULL; - while (*s) { - if (*s == c) { - first = (char *)s; - break; - } - s++; - } - return first; -} - -char *os_strtok_r(char *str, const char *delim, char **saveptr) -{ -#if OS_HAS_STRTOK_R == 1 - return( strtok_r( str, delim, saveptr ) ); -#else - char *ret; - int found = 0; - - if ( str == NULL ) - { - str = *saveptr; - } - ret = str; - - if ( str != NULL ) - { - /* Ignore delimiters at start */ - while ( *str != '\0' && os_index( delim, *str ) != NULL ) - { - str++; - ret++; - }; - - while ( *str != '\0' ) - { - if ( os_index( delim, *str ) != NULL ) - { - *str='\0'; - *saveptr=(str+1); - found=1; - break; - } - str++; - } - - if ( !found ) - { - *saveptr=NULL; - } - } - return ( ret != NULL && *ret == '\0' ? NULL : ret ); -#endif -} diff --git a/src/os/src/snippets/code/os_stdlib_strtol.c b/src/os/src/snippets/code/os_stdlib_strtol.c deleted file mode 100644 index ab1e7a7..0000000 --- a/src/os/src/snippets/code/os_stdlib_strtol.c +++ /dev/null @@ -1,266 +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 - */ -#include -#include -#include "os/os.h" - -int os_todigit (const int chr) -{ - int num = -1; - - if (chr >= '0' && chr <= '9') { - num = chr - '0'; - } else if (chr >= 'a' && chr <= 'z') { - num = 10 + (chr - 'a'); - } else if (chr >= 'A' && chr <= 'Z') { - num = 10 + (chr - 'A'); - } - - return num; -} - -static unsigned long long -os__strtoull__ ( - const char *str, - char **endptr, - int32_t base, - unsigned long long max) -{ - int err = 0; - int num; - size_t cnt = 0; - unsigned long long tot = 0; - - assert (str != NULL); - - if (base == 0) { - if (str[0] == '0') { - if ((str[1] == 'x' || str[1] == 'X') && os_todigit (str[2]) < 16) { - base = 16; - cnt = 2; - } else { - base = 8; - } - } else { - base = 10; - } - } else if (base == 16) { - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { - cnt = 2; - } - } else if (base < 2 || base > 36) { - err = EINVAL; - } - - while (!err && (num = os_todigit (str[cnt])) >= 0 && num < base) { - if (tot <= (max / (unsigned) base)) { - tot *= (unsigned) base; - tot += (unsigned) num; - cnt++; - } else { - err = ERANGE; - tot = max; - } - } - - if (endptr != NULL) { - *endptr = (char *)str + cnt; - } - - if (err) { - os_setErrno(err); - } - - return tot; -} - -long long -os_strtoll( - const char *str, - char **endptr, - int32_t base) -{ - size_t cnt = 0; - long long tot = 1; - unsigned long long max = INT64_MAX; - - assert (str != NULL); - - for (; isspace((unsigned char)str[cnt]); cnt++) { - /* ignore leading whitespace */ - } - - if (str[cnt] == '-') { - tot = -1; - max++; - cnt++; - } else if (str[cnt] == '+') { - cnt++; - } - - tot *= (long long) os__strtoull__ (str + cnt, endptr, base, max); - - if (endptr && *endptr == (str + cnt)) { - *endptr = (char *)str; - } - - return tot; -} - -unsigned long long -os_strtoull ( - const char *str, - char **endptr, - int32_t base) -{ - size_t cnt = 0; - unsigned long long tot = 1; - unsigned long long max = UINT64_MAX; - - assert (str != NULL); - - for (; isspace((unsigned char)str[cnt]); cnt++) { - /* ignore leading whitespace */ - } - - if (str[cnt] == '-') { - tot = (unsigned long long) -1; - cnt++; - } else if (str[cnt] == '+') { - cnt++; - } - - tot *= os__strtoull__ (str + cnt, endptr, base, max); - - if (endptr && *endptr == (str + cnt)) { - *endptr = (char *)str; - } - - return tot; -} - -long long -os_atoll( - const char *str) -{ - return os_strtoll(str, NULL, 10); -} - -unsigned long long -os_atoull( - const char *str) -{ - return os_strtoull(str, NULL, 10); -} - -char * -os_ulltostr ( - unsigned long long num, - char *str, - size_t len, - char **endptr) -{ - char chr, *ptr; - size_t cnt; - size_t lim = 0; - size_t tot = 0; - - assert (str != NULL); - - if (len > 1) { - lim = len - 1; - - do { - str[tot] = (char)('0' + (int)(num % 10)); - num /= 10; - - if (tot == (lim - 1)) { - if (num > 0ULL) { - /* Simply using memmove would have been easier, but the - function is safe to use in asynchronous code like this. - Normally this code should not affect performance, - because ideally the buffer is sufficiently large - enough. */ - for (cnt = 0; cnt < tot; cnt++) { - str[cnt] = str[cnt + 1]; - } - } - } else if (num > 0ULL) { - tot++; - } - } while (num > 0ULL); - - lim = tot + 1; - } - - for (cnt = 0; cnt < (tot - cnt); cnt++) { - chr = str[tot - cnt]; - str[tot - cnt] = str[cnt]; - str[cnt] = chr; - } - - if (len == 0) { - str = NULL; - ptr = NULL; - } else { - str[lim] = '\0'; - ptr = str + lim; - } - - if (endptr != NULL) { - *endptr = ptr; - } - - return str; -} - -char * -os_lltostr ( - long long num, - char *str, - size_t len, - char **endptr) -{ - unsigned long long pos; - char *ptr; - size_t cnt = 0; - - assert (str != NULL); - - if (len == 0) { - str = NULL; - ptr = NULL; - } else if (len == 1) { - str[0] = '\0'; - ptr = str; - } else { - if (num < 0LL) { - if (num == INT64_MIN) { - pos = (unsigned long long)INT64_MAX + 1; - } else { - pos = (unsigned long long) -num; - } - - str[cnt++] = '-'; - } else { - pos = (unsigned long long) num; - } - - (void)os_ulltostr (pos, str + cnt, len - cnt, &ptr); - } - - if (endptr != NULL) { - *endptr = ptr; - } - - return str; -} diff --git a/src/os/src/snippets/include/os_posix_stdlib.h b/src/os/src/snippets/include/os_posix_stdlib.h deleted file mode 100644 index a7dc407..0000000 --- a/src/os/src/snippets/include/os_posix_stdlib.h +++ /dev/null @@ -1,45 +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 OS_POSIX_STDLIB_H -#define OS_POSIX_STDLIB_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __VXWORKS__ -void os_stdlibInitialize(void); -#endif - -#if defined (__cplusplus) -extern "C" { -#endif - -#define OS_ROK R_OK -#define OS_WOK W_OK -#define OS_XOK X_OK -#define OS_FOK F_OK - -#define OS_ISDIR S_ISDIR -#define OS_ISREG S_ISREG -#define OS_ISLNK S_ISLNK - -#if defined (__cplusplus) -} -#endif - -#endif /* OS_POSIX_STDLIB_H */ diff --git a/src/os/src/vxworks/os_platform_errno.c b/src/os/src/vxworks/os_platform_errno.c deleted file mode 100644 index 2bda2d1..0000000 --- a/src/os/src/vxworks/os_platform_errno.c +++ /dev/null @@ -1,87 +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 - */ -#include -#include -#include - -#include "os/os.h" - -int -os_getErrno(void) -{ - return errno; -} - -void -os_setErrno(int err) -{ - errno = err; -} - -#ifdef _WRS_KERNEL - -extern char * -strerrorIf( - int errcode); - -/* VxWorks has a non-compliant strerror_r in kernel mode which only takes a - buffer and an error number. Providing a buffer smaller than NAME_MAX + 1 - (256) may result in a buffer overflow. See target/src/libc/strerror.c for - details. NAME_MAX is defined in limits.h. */ - -int -os_strerror_r(int errnum, char *buf, size_t buflen) -{ - int err; - const char *str; - - assert(buf != NULL); - - if ((err = os_errstr(errnum, buf, buflen)) == EINVAL) { - err = 0; - if (buflen < (NAME_MAX + 1)) { - err = ERANGE; - } else if (strerrorIf(errnum) != NULL) { - (void)strerror_r(errnum, buf); - } - } - - return err; -} - -#else - -int -os_strerror_r(int errnum, char *buf, size_t buflen) -{ - int err; - const char *str; - - assert(buf != NULL); - - if ((err = os_errstr(errnum, buf, buflen)) == EINVAL) { - /* VxWorks's strerror_r always returns 0 (zero), so the only way to - decide if the error was truncated is to check if the last position - in the buffer is overwritten by strerror_r. */ - err = 0; - buf[buflen - 1] = 'x'; - (void)strerror_r(errnum, buf, buflen); - if (buf[buflen - 1] != 'x') { - err = ERANGE; - } - buf[buflen - 1] = '\0'; /* Always null terminate, just to be safe. */ - } - - return err; -} - -#endif /* _WRS_KERNEL */ diff --git a/src/os/src/vxworks/os_platform_init.c b/src/os/src/vxworks/os_platform_init.c deleted file mode 100644 index a88bd75..0000000 --- a/src/os/src/vxworks/os_platform_init.c +++ /dev/null @@ -1,129 +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 - */ -/**************************************************************** - * Initialization / Deinitialization * - ****************************************************************/ - -/** \file os/vxworks/os_platform_init.c - * \brief Initialization / Deinitialization - */ - -#include - -#include "os/os.h" - - -#if defined(OS_USE_ALLIGNED_MALLOC) && !defined(NDEBUG) -#include "os/os_atomics.h" -extern atomic_t os__reallocdoublecopycount ; -#endif - -/** \brief Counter that keeps track of number of times os-layer is initialized */ -static os_atomic_uint32_t _ospl_osInitCount = OS_ATOMIC_UINT32_INIT(0); - -/* Check expression is true at compile time ( no code generated ) - - will get negative sized array on failure */ -#define EXPRCHECK(expr) (void)sizeof(char[1-(signed int)(2*(unsigned int)!(expr))]); - - -/** \brief OS layer initialization - * - * \b os_osInit calls: - * - \b os_sharedMemoryInit - * - \b os_threadInit - */ -void os_osInit (void) -{ - uint32_t initCount; - - /* Sanity checks, don't remove, they don't generate any code anyway. */ - EXPRCHECK(sizeof(char)==1) - EXPRCHECK(sizeof(unsigned char)==1) - EXPRCHECK(sizeof(short)==2) - EXPRCHECK(sizeof(unsigned short)==2) - EXPRCHECK(sizeof(int32_t)==4) - EXPRCHECK(sizeof(uint32_t)==4) - EXPRCHECK(sizeof(int64_t)==8) - EXPRCHECK(sizeof(uint64_t)==8) - EXPRCHECK(sizeof(float)==4) - EXPRCHECK(sizeof(double)==8) - -#ifdef OS_USE_ALLIGNED_MALLOC - /* Check for heap realignment code which needs types below being 32bit */ - EXPRCHECK(sizeof(size_t)==4) - EXPRCHECK(sizeof(void *)==4) -#endif - - initCount = os_atomic_inc32_nv(&_ospl_osInitCount); - - if (initCount == 1) { - /* init for programs using data base threads */ - os_threadModuleInit(); - os_reportInit(false); -#ifdef _WRS_KERNEL - os_stdlibInitialize(); -#endif - } - - return; -} - -/** \brief OS layer deinitialization - */ -void os_osExit (void) -{ - uint32_t initCount; - -#if defined(OS_USE_ALLIGNED_MALLOC) && !defined(NDEBUG) - DDS_INFO("count=%d\n", vxAtomicGet(&os__reallocdoublecopycount)); -#endif - initCount = os_atomic_dec32_nv(&_ospl_osInitCount); - - if (initCount == 0) { - os_reportExit(); - os_threadModuleExit(); - os_syncModuleExit(); - } else if ((initCount + 1) < initCount){ - /* The 0 boundary is passed, so os_osExit is called more often than - * os_osInit. Therefore undo decrement as nothing happened and warn. */ - initCount = os_atomic_inc32_nv(&_ospl_osInitCount); - DDS_WARNING("OS-layer not initialized\n"); - /* Fail in case of DEV, as it is incorrect API usage */ - assert(0); - } - return; -} - -#ifdef _WRS_KERNEL -/* This constructor is invoked when the library is loaded into a process. */ -void __attribute__ ((constructor)) -os__osInit( - void) -{ - os_osInit(); -} - -/* This destructor is invoked when the library is unloaded from a process. */ -void __attribute__ ((destructor)) -os__osExit( - void) -{ - os_osExit(); -} -#else -/* This constructor is invoked when the library is loaded into a process. */ -_WRS_CONSTRUCTOR(os__osInit, 100) { - os_osInit(); - atexit(&os_osExit); /* There is no _WRS_DESTRUCTOR, use atexit instead */ - return; -} -#endif diff --git a/src/os/src/vxworks/os_platform_socket.c b/src/os/src/vxworks/os_platform_socket.c deleted file mode 100644 index 71d6f4e..0000000 --- a/src/os/src/vxworks/os_platform_socket.c +++ /dev/null @@ -1,12 +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 - */ -#include "../posix/os_platform_socket.c" diff --git a/src/os/src/vxworks/os_platform_stdlib.c b/src/os/src/vxworks/os_platform_stdlib.c deleted file mode 100644 index ebad4ff..0000000 --- a/src/os/src/vxworks/os_platform_stdlib.c +++ /dev/null @@ -1,50 +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 - */ -#include -#include -#include /* MAXHOSTNAMELEN */ - -#include "os/os.h" - -#ifdef _WRS_KERNEL -#include - -extern char *os_environ[]; - -void -os_stdlibInitialize( - void) -{ - char **varset; - - for ( varset = &os_environ[0]; *varset != NULL; varset++ ) - { - char *savePtr=NULL; - char *varName; - char *tmp = os_strdup( *varset ); - varName = strtok_r( tmp, "=", &savePtr ); - if ( os_getenv( varName ) == NULL ) - { - os_putenv( *varset ); - } - os_free(tmp); - } -} -#endif - -#define OS_HAS_STRTOK_R 1 /* FIXME: Should be handled by CMake */ -#include "../snippets/code/os_gethostname.c" -#include "../snippets/code/os_stdlib.c" -#include "../snippets/code/os_stdlib_bsearch.c" -#include "../snippets/code/os_stdlib_strtod.c" -#include "../snippets/code/os_stdlib_strtol.c" -#include "../snippets/code/os_stdlib_strtok_r.c" diff --git a/src/os/src/vxworks/os_platform_sync.c b/src/os/src/vxworks/os_platform_sync.c deleted file mode 100644 index 5f15a62..0000000 --- a/src/os/src/vxworks/os_platform_sync.c +++ /dev/null @@ -1,12 +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 - */ -#include "../posix/os_platform_sync.c" diff --git a/src/os/src/vxworks/os_platform_thread.c b/src/os/src/vxworks/os_platform_thread.c deleted file mode 100644 index ce17c33..0000000 --- a/src/os/src/vxworks/os_platform_thread.c +++ /dev/null @@ -1,12 +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 - */ -#include "../snippets/code/os_posix_thread.c" diff --git a/src/os/src/vxworks/os_platform_time.c b/src/os/src/vxworks/os_platform_time.c deleted file mode 100644 index 02d40ef..0000000 --- a/src/os/src/vxworks/os_platform_time.c +++ /dev/null @@ -1,12 +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 - */ -#include "../posix/os_platform_time.c" diff --git a/src/os/src/windows/os_platform_errno.c b/src/os/src/windows/os_platform_errno.c deleted file mode 100644 index 55e3d03..0000000 --- a/src/os/src/windows/os_platform_errno.c +++ /dev/null @@ -1,96 +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 - */ -#include "os/os.h" - -#include - -/* WSAGetLastError, GetLastError and errno - -Windows supports errno (The Microsoft c Run-Time Library for Windows CE -does so since version 15 (Visual Studio 2008)). Error codes set by the -Windows Sockets implementation, however, are NOT made available via the -errno variable. - -WSAGetLastError used to be the thread-safe version of GetLastError, but -nowadays is just an an alias for GetLastError as intended by Microsoft: -http://www.sockets.com/winsock.htm#Deviation_ErrorCodes - -There is no relationship between GetLastError and errno. -GetLastError returns the last error that occurred in a Windows API function -(for the current thread). errno contains the last error that occurred in the C -runtime library. Normally if a WinAPI call fails, e.g. CreateFile, GetLastError -should be used to retrieve the error. If a C runtime library function fails, -e.g. fopen, errno contains the error number. -*/ - -int -os_getErrno(void) -{ - DWORD err = GetLastError(); - if (err != 0) { - errno = (int)err; - } - return errno; -} - -void -os_setErrno(int err) -{ - SetLastError(err); - errno = err; -} - -int -os_strerror_r( - _In_ int errnum, - _Out_writes_z_(buflen) char *buf, - _In_ size_t buflen) -{ - int err = 0, errs[2]; - DWORD cnt; - - assert(buf != NULL); - assert(buflen > 0); - - if ((err = os_errstr(errnum, buf, buflen)) == EINVAL) { - err = 0; - buf[0] = '\0'; /* Null-terminate in case nothing is written. */ - errs[0] = os_getErrno(); - cnt = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_MAX_WIDTH_MASK, - NULL, - errnum, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)buf, - (DWORD)buflen, - NULL); - - errs[1] = os_getErrno(); - if (cnt == 0) { - if (errs[1] == ERROR_MORE_DATA) { - err = ERANGE; - } else { - err = EINVAL; - } - } - - /* os_strerror_r should not modify errno itself. */ - if (errs[0] != errs[1]) { - os_setErrno(errs[0]); - } - - buf[buflen - 1] = '\0'; /* Always null-terminate, just to be safe. */ - } - - return err; -} diff --git a/src/os/src/windows/os_platform_heap.c b/src/os/src/windows/os_platform_heap.c deleted file mode 100644 index a2f6698..0000000 --- a/src/os/src/windows/os_platform_heap.c +++ /dev/null @@ -1,19 +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 - */ -/** \file os/darwin/code/os_heap.c - * \brief Darwin heap memory management - * - * Implements heap memory management for Darwin - * by including the common implementation - */ - -#include "../snippets/code/os_heap.c" diff --git a/src/os/src/windows/os_platform_ifaddrs.c b/src/os/src/windows/os_platform_ifaddrs.c deleted file mode 100644 index 65dd98f..0000000 --- a/src/os/src/windows/os_platform_ifaddrs.c +++ /dev/null @@ -1,272 +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 - */ -#include -#include - -#include "os/os.h" - -extern const int *const os_supp_afs; - -static int -getifaces(PIP_ADAPTER_ADDRESSES *ptr) -{ - int err = ERANGE; - PIP_ADAPTER_ADDRESSES buf = NULL; - ULONG bufsz = 0; /* Size is determined on first iteration. */ - ULONG ret; - size_t i; - - static const size_t max = 2; - static const ULONG filter = GAA_FLAG_INCLUDE_PREFIX | - GAA_FLAG_SKIP_ANYCAST | - GAA_FLAG_SKIP_MULTICAST | - GAA_FLAG_SKIP_DNS_SERVER; - - assert(ptr != NULL); - - for (i = 0; err == ERANGE && i < max; i++) { - ret = GetAdaptersAddresses(AF_UNSPEC, filter, NULL, buf, &bufsz); - assert(ret != ERROR_INVALID_PARAMETER); - switch (ret) { - case ERROR_BUFFER_OVERFLOW: - err = ERANGE; - os_free(buf); - if ((buf = (IP_ADAPTER_ADDRESSES *)os_malloc(bufsz)) == NULL) { - err = ENOMEM; - } - break; - case ERROR_NOT_ENOUGH_MEMORY: - err = ENOMEM; - break; - case ERROR_SUCCESS: - case ERROR_ADDRESS_NOT_ASSOCIATED: /* No address associated yet. */ - case ERROR_NO_DATA: /* No adapters that match the filter. */ - default: - err = 0; - break; - } - } - - if (err == 0) { - *ptr = buf; - } else { - os_free(buf); - } - - return err; -} - -static int -getaddrtable(PMIB_IPADDRTABLE *ptr) -{ - int err = ERANGE; - PMIB_IPADDRTABLE buf = NULL; - ULONG bufsz = 0; - DWORD ret; - size_t i; - - static const size_t max = 2; - - assert(ptr != NULL); - - for (i = 0; err == ERANGE && i < max; i++) { - ret = GetIpAddrTable(buf, &bufsz, 0); - assert(ret != ERROR_INVALID_PARAMETER && - ret != ERROR_NOT_SUPPORTED); - switch (ret) { - case ERROR_INSUFFICIENT_BUFFER: - err = ERANGE; - os_free(buf); - if ((buf = (PMIB_IPADDRTABLE)os_malloc(bufsz)) == NULL) { - err = ENOMEM; - } - break; - case ERROR_SUCCESS: - default: - err = GetLastError(); - break; - } - } - - if (err == 0) { - *ptr = buf; - } else { - os_free(buf); - } - - return err; -} - -static uint32_t -getflags(const PIP_ADAPTER_ADDRESSES iface) -{ - uint32_t flags = 0; - - if (iface->OperStatus == IfOperStatusUp) { - flags |= IFF_UP; - } - if (!(iface->Flags & IP_ADAPTER_NO_MULTICAST) && iface->IfType != IF_TYPE_SOFTWARE_LOOPBACK) { - /* multicast over loopback doesn't seem to work despite the NO_MULTICAST flag being clear - assuming an interface is multicast-capable when in fact it isn't is disastrous, so it - makes more sense to err by assuming it won't work as there is always the - AssumeMulticastCapable setting to overrule it */ - flags |= IFF_MULTICAST; - } - - switch (iface->IfType) { - case IF_TYPE_SOFTWARE_LOOPBACK: - flags |= IFF_LOOPBACK; - break; - case IF_TYPE_ETHERNET_CSMACD: - case IF_TYPE_IEEE80211: - case IF_TYPE_IEEE1394: - case IF_TYPE_ISO88025_TOKENRING: - flags |= IFF_BROADCAST; - break; - default: - flags |= IFF_POINTTOPOINT; - break; - } - - return flags; -} - -static int -copyaddr( - os_ifaddrs_t **ifap, - const PIP_ADAPTER_ADDRESSES iface, - const PMIB_IPADDRTABLE addrtable, - const PIP_ADAPTER_UNICAST_ADDRESS addr) -{ - int err = 0; - os_ifaddrs_t *ifa; - struct sockaddr *sa; - size_t sz; - - assert(iface != NULL); - assert(addrtable != NULL); - assert(addr != NULL); - - sa = (struct sockaddr *)addr->Address.lpSockaddr; - sz = (size_t)addr->Address.iSockaddrLength; - - if ((ifa = os_calloc_s(1, sizeof(*ifa))) == NULL) { - err = ENOMEM; - } else { - ifa->flags = getflags(iface); - ifa->addr = os_memdup(sa, sz); - (void)os_asprintf(&ifa->name, "%wS", iface->FriendlyName); - if (ifa->addr == NULL || ifa->name == NULL) { - err = ENOMEM; - } else if (ifa->addr->sa_family == AF_INET6) { - ifa->index = iface->Ipv6IfIndex; - - /* Address is not in addrtable if the interface is not connected. */ - } else if (ifa->addr->sa_family == AF_INET && (ifa->flags & IFF_UP)) { - DWORD i = 0; - struct sockaddr_in nm, bc, *sin = (struct sockaddr_in *)sa; - - assert(sz == sizeof(nm)); - memset(&nm, 0, sz); - memset(&bc, 0, sz); - nm.sin_family = bc.sin_family = AF_INET; - - for (; i < addrtable->dwNumEntries; i++) { - if (sin->sin_addr.s_addr == addrtable->table[i].dwAddr) { - ifa->index = addrtable->table[i].dwIndex; - nm.sin_addr.s_addr = addrtable->table[i].dwMask; - bc.sin_addr.s_addr = - sin->sin_addr.s_addr | ~(nm.sin_addr.s_addr); - break; - } - } - - assert(i < addrtable->dwNumEntries); - - if ((ifa->netmask = os_memdup(&nm, sz)) == NULL || - (ifa->broadaddr = os_memdup(&bc, sz)) == NULL) - { - err = ENOMEM; - } - } - } - - if (err == 0) { - *ifap = ifa; - } else { - os_freeifaddrs(ifa); - } - - return err; -} - -_Success_(return == 0) int -os_getifaddrs( - _Inout_ os_ifaddrs_t **ifap, - _In_opt_ const int *afs) -{ - int err = 0; - int use; - PIP_ADAPTER_ADDRESSES ifaces = NULL, iface; - PIP_ADAPTER_UNICAST_ADDRESS addr = NULL; - PMIB_IPADDRTABLE addrtable = NULL; - os_ifaddrs_t *ifa, *ifa_root, *ifa_next; - struct sockaddr *sa; - - assert(ifap != NULL); - - if (afs == NULL) { - afs = os_supp_afs; - } - - ifa = ifa_root = ifa_next = NULL; - - if ((err = getifaces(&ifaces)) == 0 && - (err = getaddrtable(&addrtable)) == 0) - { - for (iface = ifaces; !err && iface != NULL; iface = iface->Next) { - for (addr = iface->FirstUnicastAddress; - addr != NULL; - addr = addr->Next) - { - sa = (struct sockaddr *)addr->Address.lpSockaddr; - use = 0; - for (int i = 0; !use && afs[i] != OS_AF_NULL; i++) { - use = (afs[i] == sa->sa_family); - } - - if (use) { - err = copyaddr(&ifa_next, iface, addrtable, addr); - if (err == 0) { - if (ifa == NULL) { - ifa = ifa_root = ifa_next; - } else { - ifa->next = ifa_next; - ifa = ifa_next; - } - } - } - } - } - } - - os_free(ifaces); - os_free(addrtable); - - if (err == 0) { - *ifap = ifa_root; - } else { - os_freeifaddrs(ifa_root); - } - - return err; -} diff --git a/src/os/src/windows/os_platform_init.c b/src/os/src/windows/os_platform_init.c deleted file mode 100644 index e20bd91..0000000 --- a/src/os/src/windows/os_platform_init.c +++ /dev/null @@ -1,69 +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 - */ -/**************************************************************** - * Initialization / Deinitialization * - ****************************************************************/ - -/** \file os/darwin/code/os_init.c - * \brief Initialization / Deinitialization - */ - -#include - -#include "os/os.h" - -void os_osPlatformInit (void) -{ - os_threadModuleInit(); - os_timeModuleInit(); - os_socketModuleInit(); -} - -void os_osPlatformExit (void) -{ - os_socketModuleExit(); - os_timeModuleExit(); - os_threadModuleExit(); -} - -/* We need this on windows to make sure the main thread of MFC applications - * calls os_osInit(). - */ -BOOL WINAPI DllMain( - HINSTANCE hinstDLL, /* handle to DLL module */ - DWORD fdwReason, /* reason for calling function */ - LPVOID lpReserved ) /* reserved */ -{ - /* Perform actions based on the reason for calling.*/ - switch( fdwReason ) { - case DLL_PROCESS_ATTACH: - /* Initialize once for each new process. - * Return FALSE to fail DLL load. - */ - os_osInit(); - break; - case DLL_THREAD_ATTACH: - /* Do thread-specific initialization. - */ - break; - case DLL_THREAD_DETACH: - /* Do thread-specific cleanup. - */ - break; - case DLL_PROCESS_DETACH: - /* Perform any necessary cleanup. - */ - os_osExit(); - break; - } - return TRUE; /* Successful DLL_PROCESS_ATTACH.*/ -} diff --git a/src/os/src/windows/os_platform_socket.c b/src/os/src/windows/os_platform_socket.c deleted file mode 100644 index 5ca94bd..0000000 --- a/src/os/src/windows/os_platform_socket.c +++ /dev/null @@ -1,599 +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 - */ -/** \file - * \brief WIN32 socket management - * - * Implements socket management for WIN32 - */ -#include "os/os.h" -#include - -#include - -typedef BOOL (WINAPI *qwaveQOSCreateHandleFuncT) (_In_ PQOS_VERSION Version, _Out_ PHANDLE QOSHandle); -typedef BOOL (WINAPI *qwaveQOSCloseHandleFuncT) (_In_ HANDLE QOSHandle); -typedef BOOL (WINAPI *qwaveQOSAddSocketToFlowFuncT) ( - _In_ HANDLE QOSHandle, - _In_ SOCKET Socket, - _In_opt_ PSOCKADDR DestAddr, - _In_ QOS_TRAFFIC_TYPE TrafficType, - _In_opt_ DWORD Flags, - _Inout_ PQOS_FLOWID FlowId -); -typedef BOOL (WINAPI *qwaveQOSSetFlowFuncT) ( - _In_ HANDLE QOSHandle, - _In_ QOS_FLOWID FlowId, - _In_ QOS_SET_FLOW Operation, - _In_ ULONG Size, - _In_ PVOID Buffer, - _Reserved_ DWORD Flags, - _Out_opt_ LPOVERLAPPED Overlapped -); - -static qwaveQOSCreateHandleFuncT qwaveQOSCreateHandleFunc; -static qwaveQOSCloseHandleFuncT qwaveQOSCloseHandleFunc; -static qwaveQOSAddSocketToFlowFuncT qwaveQOSAddSocketToFlowFunc; -static qwaveQOSSetFlowFuncT qwaveQOSSetFlowFunc; - -static HANDLE qwaveDLLModuleHandle = NULL; -static HANDLE qwaveDLLModuleLock = NULL; - -void -os_socketModuleInit() -{ - WORD wVersionRequested; - WSADATA wsaData; - int err; - - wVersionRequested = MAKEWORD (OS_SOCK_VERSION, OS_SOCK_REVISION); - - err = WSAStartup (wVersionRequested, &wsaData); - if (err != 0) { - DDS_FATAL("WSAStartup failed, no compatible socket implementation available\n"); - /* Tell the user that we could not find a usable */ - /* WinSock DLL. */ - return; - } - - /* Confirm that the WinSock DLL supports 2.0. */ - /* Note that if the DLL supports versions greater */ - /* than 2.0 in addition to 2.0, it will still return */ - /* 2.0 in wVersion since that is the version we */ - /* requested. */ - - if ((LOBYTE(wsaData.wVersion) != OS_SOCK_VERSION) || - (HIBYTE(wsaData.wVersion) != OS_SOCK_REVISION)) { - /* Tell the user that we could not find a usable */ - /* WinSock DLL. */ - DDS_FATAL("WSAStartup failed, no compatible socket implementation available\n"); - WSACleanup(); - return; - } - - qwaveDLLModuleLock = CreateMutex(NULL, FALSE, NULL); - if (qwaveDLLModuleLock == NULL) { - DDS_ERROR("Failed to create mutex\n"); - } -} - -void -os_socketModuleExit(void) -{ - if (qwaveDLLModuleHandle) { - FreeLibrary(qwaveDLLModuleHandle); - } - - if (qwaveDLLModuleLock) { - CloseHandle(qwaveDLLModuleLock); - } - - WSACleanup(); - return; -} - -os_socket -os_sockNew( - int domain, - int type) -{ - return socket(domain, type, 0); -} - -os_result -os_sockBind( - os_socket s, - const struct sockaddr *name, - uint32_t namelen) -{ - os_result result = os_resultSuccess; - - if (bind(s, (struct sockaddr *)name, namelen) == SOCKET_ERROR) { - result = os_resultFail; - } - return result; -} - -os_result -os_sockGetsockname( - os_socket s, - const struct sockaddr *name, - uint32_t namelen) -{ - os_result result = os_resultSuccess; - int len = namelen; - - if (getsockname(s, (struct sockaddr *)name, &len) == SOCKET_ERROR) { - result = os_resultFail; - } - return result; -} - -os_result -os_sockSendto( - os_socket s, - const void *msg, - size_t len, - const struct sockaddr *to, - size_t tolen, - size_t *bytesSent) -{ - int res = sendto(s, msg, (int)len, 0, to, (int)tolen); /* The parameter len with type of size_t causes the possible loss of data. So type casting done */ - if (res < 0) - { - *bytesSent = 0; - return os_resultFail; - } - else - { - *bytesSent = res; - return os_resultSuccess; - } -} - -os_result -os_sockRecvfrom( - os_socket s, - void *buf, - size_t len, - struct sockaddr *from, - size_t *fromlen, - size_t *bytesRead) -{ - int res; - res = recvfrom(s, buf, (int)len, 0, from, (int *)fromlen); - if (res == SOCKET_ERROR) - { - *bytesRead = 0; - return os_resultFail; - } - else - { - *bytesRead = (size_t)res; - return os_resultSuccess; - } -} - -os_result -os_sockGetsockopt( - os_socket s, - int32_t level, - int32_t optname, - void *optval, - uint32_t *optlen) -{ - os_result result = os_resultSuccess; - - /* On win32 IP_MULTICAST_TTL and IP_MULTICAST_LOOP take DWORD * param - rather than char * */ - if ( level == IPPROTO_IP - && ( optname == IP_MULTICAST_TTL - || optname == IP_MULTICAST_LOOP ) ) - { - int dwoptlen = sizeof( DWORD ); - DWORD dwoptval = *((unsigned char *)optval); - if (getsockopt(s, level, optname, (char *)&dwoptval, &dwoptlen) == SOCKET_ERROR) - { - result = os_resultFail; - } - - assert( dwoptlen == sizeof( DWORD ) ); - *((unsigned char *)optval) = (unsigned char)dwoptval; - *optlen = sizeof( unsigned char ); - } - else - { - if (getsockopt(s, level, optname, optval, (int *)optlen) == SOCKET_ERROR) - { - result = os_resultFail; - } - } - - return result; -} - - -static os_result -os_sockSetDscpValueWithTos( - os_socket sock, - DWORD value) -{ - os_result result = os_resultSuccess; - - if (setsockopt(sock, IPPROTO_IP, IP_TOS, (char *)&value, (int)sizeof(value)) == SOCKET_ERROR) { - char errmsg[1024]; - int errNo = os_getErrno(); - (void) os_strerror_r(errNo, errmsg, sizeof errmsg); - DDS_WARNING("Failed to set diffserv value to %lu: %d %s\n", value, errNo, errmsg); - result = os_resultFail; - } - - return result; -} - - -static os_result -os_sockLoadQwaveLibrary(void) -{ - if (qwaveDLLModuleLock == NULL) { - DDS_WARNING("Failed to load QWAVE.DLL for using diffserv on outgoing IP packets\n"); - goto err_lock; - } - - WaitForSingleObject(qwaveDLLModuleLock, INFINITE); - if (qwaveDLLModuleHandle == NULL) { - if ((qwaveDLLModuleHandle = LoadLibrary("QWAVE.DLL")) == NULL) { - DDS_WARNING("Failed to load QWAVE.DLL for using diffserv on outgoing IP packets\n"); - goto err_load_lib; - } - - qwaveQOSCreateHandleFunc = (qwaveQOSCreateHandleFuncT) GetProcAddress(qwaveDLLModuleHandle, "QOSCreateHandle"); - qwaveQOSCloseHandleFunc = (qwaveQOSCloseHandleFuncT) GetProcAddress(qwaveDLLModuleHandle, "QOSCloseHandle"); - qwaveQOSAddSocketToFlowFunc = (qwaveQOSAddSocketToFlowFuncT) GetProcAddress(qwaveDLLModuleHandle, "QOSAddSocketToFlow"); - qwaveQOSSetFlowFunc = (qwaveQOSSetFlowFuncT) GetProcAddress(qwaveDLLModuleHandle, "QOSSetFlow"); - - if ((qwaveQOSCreateHandleFunc == 0) || (qwaveQOSCloseHandleFunc == 0) || - (qwaveQOSAddSocketToFlowFunc == 0) || (qwaveQOSSetFlowFunc == 0)) { - DDS_WARNING("Failed to resolve entry points for using diffserv on outgoing IP packets\n"); - goto err_find_func; - } - } - ReleaseMutex(qwaveDLLModuleLock); - - return os_resultSuccess; - -err_find_func: -err_load_lib: - ReleaseMutex(qwaveDLLModuleLock); -err_lock: - return os_resultFail; -} - -/* To set the DSCP value on Windows 7 or higher the following functions are used. - * - * - BOOL QOSCreateHandle(PQOS_VERSION Version, PHANDLE QOSHandle) - * - BOOL QOSCloseHandle(HANDLE QOSHandle) - * - BOOL WINAPI QOSAddSocketToFlow(HANDLE QOSHandle, SOCKET Socket, - * PSOCKADDR DestAddr, QOS_TRAFFIC_TYPE TrafficType, - * DWORD Flags, PQOS_FLOWID FlowId) - * - BOOL WINAPI QOSSetFlow(HANDLE QOSHandle, QOS_FLOWID FlowId, - * QOS_SET_FLOW Operation, ULONG Size, PVOID Buffer, - * DWORD Flags, LPOVERLAPPED Overlapped) - */ - - -/* QOS_TRAFFIC_TYPE - * - QOSTrafficTypeBestEffort = 0 - * - QOSTrafficTypeBackground = 1 - * - QOSTrafficTypeExcellentEffort = 2 - * - QOSTrafficTypeAudioVideo = 3 - * - QOSTrafficTypeVoice = 4 - * - QOSTrafficTypeControl = 5 - */ -#define OS_SOCK_QOS_TRAFFIC_TYPE_BEST_EFFORT 0 -#define OS_SOCK_QOS_TRAFFIC_TYPE_BACKGROUND 1 -#define OS_SOCK_QOS_TRAFFIC_TYPE_EXCELLENT_EFFORT 2 -#define OS_SOCK_QOS_TRAFFIC_TYPE_AUDIO_VIDEO 3 -#define OS_SOCK_QOS_TRAFFIC_TYPE_VOICE 4 -#define OS_SOCK_QOS_TRAFFIC_TYPE_CONTROL 5 - -/* Default DSCP values set by QOSAddSocketToFlow - * 0 : QOSTrafficTypeBestEffort dscp 0 - * 1 - 8 : QOSTrafficTypeBackground dscp 8 - * 9 - 40 : QOSTrafficTypeExcellentEffort dscp 40 - * 41 - 55 : QOSTrafficTypeAudioVideo dscp 40 - * 56 : QOSTrafficTypeVoice dscp 56 - * 57 - 63 : QOSTrafficTypeControl dscp 56 - */ -#define OS_SOCK_BESTEFFORT_DSCP_VALUE 0 -#define OS_SOCK_BACKGROUND_DSCP_VALUE 8 -#define OS_SOCK_EXCELLENT_EFFORT_DSCP_VALUE 40 -#define OS_SOCK_VOICE_DSCP_VALUE 56 - -/* QOS_NON_ADAPTIVE_FLOW */ -#define OS_SOCK_QOS_NON_ADAPTIVE_FLOW 0x00000002 -/* QOSSetOutgoingDSCPValue */ -#define OS_SOCK_QOS_SET_OUTGOING_DSCP_VALUE 2 - -static void -os_sockGetTrafficType( - DWORD value, - PLONG trafficType, - PLONG defaultValue) -{ - if (value == 0) { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_BEST_EFFORT; - *defaultValue = OS_SOCK_BESTEFFORT_DSCP_VALUE; - } else if (value <= OS_SOCK_BACKGROUND_DSCP_VALUE) { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_BACKGROUND; - *defaultValue = OS_SOCK_BACKGROUND_DSCP_VALUE; - } else if (value <= OS_SOCK_EXCELLENT_EFFORT_DSCP_VALUE) { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_EXCELLENT_EFFORT; - *defaultValue = OS_SOCK_EXCELLENT_EFFORT_DSCP_VALUE; - } else if (value < OS_SOCK_VOICE_DSCP_VALUE) { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_AUDIO_VIDEO; - *defaultValue = OS_SOCK_EXCELLENT_EFFORT_DSCP_VALUE; - } else if (value == OS_SOCK_VOICE_DSCP_VALUE) { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_VOICE; - *defaultValue = OS_SOCK_VOICE_DSCP_VALUE; - } else { - *trafficType = OS_SOCK_QOS_TRAFFIC_TYPE_CONTROL; - *defaultValue = OS_SOCK_VOICE_DSCP_VALUE; - } -} - - -static os_result -os_sockSetDscpValueWithQos( - os_socket sock, - DWORD value, - BOOL setDscpSupported) -{ - os_result result = os_resultSuccess; - QOS_VERSION version; - HANDLE qosHandle = NULL; - ULONG qosFlowId = 0; /* Flow Id must be 0. */ - BOOL qosResult; - LONG trafficType; - LONG defaultDscp; - int errNo; - SOCKADDR_IN sin; - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - - /* version must be 1.0 */ - version.MajorVersion = 1; - version.MinorVersion = 0; - - /* Get a handle to the QoS subsystem. */ - qosResult = qwaveQOSCreateHandleFunc(&version, &qosHandle); - if (!qosResult) { - char errmsg[1024]; - errNo = os_getErrno(); - (void)os_strerror_r(errNo, errmsg, sizeof errmsg); - DDS_ERROR("QOSCreateHandle failed: %d %s\n", errNo, errmsg); - goto err_create_handle; - } - - os_sockGetTrafficType(value, &trafficType, &defaultDscp); - - /* Add socket to flow. */ - qosResult = qwaveQOSAddSocketToFlowFunc(qosHandle, sock, (PSOCKADDR)&sin, - trafficType, OS_SOCK_QOS_NON_ADAPTIVE_FLOW, &qosFlowId); - if (!qosResult) { - char errmsg[1024]; - errNo = os_getErrno(); - (void)os_strerror_r(errNo, errmsg, sizeof errmsg); - DDS_ERROR("QOSAddSocketToFlow failed: %d %s\n", errNo, errmsg); - qwaveQOSCloseHandleFunc(qosHandle); - goto err_add_flow; - } - - if (value != defaultDscp) { - - if (!setDscpSupported) { - DDS_WARNING("Failed to set diffserv value to %lu value used is %d, not supported on this platform\n", - value, defaultDscp); - goto err_set_flow; - } - - /* Try to set DSCP value. Requires administrative rights to succeed */ - qosResult = qwaveQOSSetFlowFunc(qosHandle, qosFlowId, OS_SOCK_QOS_SET_OUTGOING_DSCP_VALUE, - sizeof(value), &value, 0, NULL); - if (!qosResult) { - errNo = os_getErrno(); - if ((errNo == ERROR_ACCESS_DENIED) || (errNo == ERROR_ACCESS_DISABLED_BY_POLICY)) { - DDS_WARNING("Failed to set diffserv value to %lu value used is %d, not enough privileges\n", - value, defaultDscp); - } else { - char errmsg[1024]; - errNo = os_getErrno(); - (void)os_strerror_r(errNo, errmsg, sizeof errmsg); - DDS_ERROR("QOSSetFlow failed: %d %s\n", errNo, errmsg); - } - goto err_set_flow; - } - } - - return result; - -err_set_flow: -err_add_flow: -err_create_handle: - return result; -} - - -static os_result -os_sockSetDscpValue( - os_socket sock, - DWORD value) -{ - os_result result; - - if (IsWindowsVistaOrGreater() && (os_sockLoadQwaveLibrary() == os_resultSuccess)) { - result = os_sockSetDscpValueWithQos(sock, value, IsWindows7OrGreater()); - } else { - result = os_sockSetDscpValueWithTos(sock, value); - } - - return result; -} - - -os_result -os_sockSetsockopt( - os_socket s, - int32_t level, - int32_t optname, - const void *optval, - uint32_t optlen) -{ - os_result result = os_resultSuccess; - DWORD dwoptval; - - if ((level == IPPROTO_IP) && (optname == IP_TOS)) { - dwoptval = *((unsigned char *)optval); - if (dwoptval != 0) { - result = os_sockSetDscpValue(s, dwoptval); - } - } else if ((optname == IP_MULTICAST_TTL) || (optname == IP_MULTICAST_LOOP)) { - /* On win32 IP_MULTICAST_TTL and IP_MULTICAST_LOOP take DWORD * param - rather than char * */ - dwoptval = *((unsigned char *)optval); - optval = &dwoptval; - optlen = sizeof( DWORD ); - if (setsockopt(s, level, optname, optval, (int)optlen) == SOCKET_ERROR) { - result = os_resultFail; - } - } else { - if (setsockopt(s, level, optname, optval, (int)optlen) == SOCKET_ERROR) { - result = os_resultFail; - } - } - - return result; -} - -os_result -os_sockSetNonBlocking( - os_socket s, - bool nonblock) -{ - int result; - u_long mode; - os_result r; - - /* If mode = 0, blocking is enabled, - * if mode != 0, non-blocking is enabled. */ - mode = nonblock ? 1 : 0; - - result = ioctlsocket(s, FIONBIO, &mode); - if (result != SOCKET_ERROR){ - r = os_resultSuccess; - } else { - switch(os_getErrno()){ - case WSAEINPROGRESS: - r = os_resultBusy; - break; - case WSAENOTSOCK: - r = os_resultInvalid; - break; - case WSANOTINITIALISED: - DDS_FATAL("Socket-module not initialised; ensure os_socketModuleInit is performed before using the socket module\n"); - default: - r = os_resultFail; - break; - } - } - - return r; -} - -os_result -os_sockFree( - os_socket s) -{ - os_result result = os_resultSuccess; - - if (closesocket(s) == -1) { - result = os_resultFail; - } - return result; -} - -int32_t -os__sockSelect( - fd_set *readfds, - fd_set *writefds, - fd_set *errorfds, - os_time *timeout) -{ - struct timeval t; - int r; - - t.tv_sec = (long)timeout->tv_sec; - t.tv_usec = (long)(timeout->tv_nsec / 1000); - r = select(-1, readfds, writefds, errorfds, &t); - - return r; -} - -ssize_t recvmsg (os_socket fd, struct msghdr *message, int flags) -{ - ssize_t ret; - - assert (message->msg_iovlen == 1); - assert (message->msg_controllen == 0); - - message->msg_flags = 0; - - 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*/ - - /* 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 && GetLastError () == WSAEMSGSIZE) { - ret = message->msg_iov[0].iov_len + 1; - message->msg_flags |= MSG_TRUNC; - } - - return ret; -} - -#define ASSERT_IOVEC_MATCHES_WSABUF do { \ - struct iovec_matches_WSABUF { \ - char sizeof_matches[sizeof(struct os_iovec) == sizeof(WSABUF) ? 1 : -1]; \ - char base_off_matches[offsetof(struct os_iovec, iov_base) == offsetof(WSABUF, buf) ? 1 : -1]; \ - char base_size_matches[sizeof(((struct os_iovec *)8)->iov_base) == sizeof(((WSABUF *)8)->buf) ? 1 : -1]; \ - char len_off_matches[offsetof(struct os_iovec, iov_len) == offsetof(WSABUF, len) ? 1 : -1]; \ - char len_size_matches[sizeof(((struct os_iovec *)8)->iov_len) == sizeof(((WSABUF *)8)->len) ? 1 : -1]; \ - }; } while (0) - -ssize_t sendmsg (os_socket fd, const struct msghdr *message, int flags) -{ - DWORD sent; - ssize_t ret; - - ASSERT_IOVEC_MATCHES_WSABUF; - - assert(message->msg_controllen == 0); - - 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; -} diff --git a/src/os/src/windows/os_platform_stdlib.c b/src/os/src/windows/os_platform_stdlib.c deleted file mode 100644 index 3de5b40..0000000 --- a/src/os/src/windows/os_platform_stdlib.c +++ /dev/null @@ -1,197 +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 - */ -#include - -#include "os/os.h" - -#include "../snippets/code/os_stdlib_getopt.c" -#include "../snippets/code/os_stdlib_bsearch.c" -#include "../snippets/code/os_stdlib_strtod.c" -#include "../snippets/code/os_stdlib_strtol.c" -#include "../snippets/code/os_stdlib_strtok_r.c" -#include "../snippets/code/os_stdlib_strsep.c" -#include "../snippets/code/os_stdlib_strdup.c" -#include "../snippets/code/os_stdlib_memdup.c" -#include "../snippets/code/os_stdlib_asprintf.c" -#include "../snippets/code/os_stdlib_rindex.c" -#include "../snippets/code/os_stdlib_strcasecmp.c" -#include "../snippets/code/os_stdlib_strncasecmp.c" - -os_result -os_gethostname( - char *hostname, - size_t buffersize) -{ - os_result result; - char hostnamebuf[MAXHOSTNAMELEN]; - WORD wVersionRequested; - WSADATA wsaData; - int err; - - wVersionRequested = MAKEWORD(OS_SOCK_VERSION, OS_SOCK_REVISION); - - err = WSAStartup(wVersionRequested, &wsaData); - if (err != 0) { - DDS_FATAL("WSAStartup failed, no compatible socket implementation available\n"); - /* Tell the user that we could not find a usable */ - /* WinSock DLL. */ - return os_resultFail; - } - if (gethostname(hostnamebuf, MAXHOSTNAMELEN) == 0) { - if ((strlen(hostnamebuf) + 1) > (size_t)buffersize) { - result = os_resultFail; - } - else { - strcpy(hostname, hostnamebuf); - result = os_resultSuccess; - } - } - else { - result = os_resultFail; - } - return result; -} - -#pragma warning( disable : 4996 ) -_Ret_opt_z_ const char * -os_getenv( - _In_z_ const char *variable) -{ - const char * result; - result = getenv(variable); - - return result; -} -#pragma warning( default : 4996 ) - -os_result -os_putenv( - char *variable_definition) -{ - os_result result; - - if (_putenv(variable_definition) == 0) { - result = os_resultSuccess; - } - else { - result = os_resultFail; - } - return result; -} - -#pragma warning( disable : 4996 ) -int -os_vsnprintf( - char *str, - size_t size, - const char *format, - va_list args) -{ - int result; - - /* Return-values of _vsnprintf don't match the output on posix platforms, - * so this extra code is needed to bring it in accordance. It is made to - * behave as follows (copied from printf man-pages): - * Upon successful return, this function returns the number of characters - * printed (not including the trailing '\0' used to end output to strings). - * The function does not write more than size bytes (including the trailing - * '\0'). If the output was truncated due to this limit then the return - * value is the number of characters (not including the trailing '\0') which - * would have been written to the final string if enough space had been - * available. Thus, a return value of size or more means that the output was - * truncated. If an output error is encountered, a negative value is - * returned. */ - - result = _vsnprintf(str, size, format, args); - - if (result == -1) { - /* vsnprintf will return the length that would be written for the given - * formatting arguments if invoked with NULL and 0 as the first two arguments. - */ - result = _vsnprintf(NULL, 0, format, args); - } - - /* Truncation occurred, so we need to guarantee that the string is NULL- - * terminated. */ - if ((size_t)result >= size) { - str[size - 1] = '\0'; - } - return result; -} -#pragma warning( default : 4996 ) - -#if _MSC_VER < 1900 -int -snprintf( - char *s, - size_t size, - const char *format, - ...) -{ - int result; - va_list args; - - va_start(args, format); - - result = os_vsnprintf(s, size, format, args); - - va_end(args); - - return result; -} -#endif - -ssize_t os_write( - _In_ int fd, - _In_reads_bytes_(count) void const* buf, - _In_ size_t count) -{ - return _write(fd, buf, (unsigned int)count); /* Type casting is done for the warning of conversion from 'size_t' to 'unsigned int', which may cause possible loss of data */ -} - -int os_getopt( - _In_range_(0, INT_MAX) int argc, - _In_reads_z_(argc) char **argv, - _In_z_ const char *opts) -{ - return getopt(argc, argv, opts); -} - -void os_set_opterr(_In_range_(0, INT_MAX) int err) -{ - opterr = err; -} - -int os_get_opterr(void) -{ - return opterr; -} - -void os_set_optind(_In_range_(0, INT_MAX) int index) -{ - optind = index; -} - -int os_get_optind(void) -{ - return optind; -} - -int os_get_optopt(void) -{ - return optopt; -} - -char * os_get_optarg(void) -{ - return optarg; -} diff --git a/src/os/src/windows/os_platform_sync.c b/src/os/src/windows/os_platform_sync.c deleted file mode 100644 index 1c36511..0000000 --- a/src/os/src/windows/os_platform_sync.c +++ /dev/null @@ -1,221 +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 - */ -#include -#include "os/os.h" - -void os_mutexInit( - _Out_ os_mutex *mutex) -{ - assert(mutex != NULL); - - InitializeSRWLock(&mutex->lock); -} - -void os_mutexDestroy( - _Inout_ _Post_invalid_ os_mutex *mutex) -{ - assert(mutex != NULL); -} - -_Acquires_nonreentrant_lock_(&mutex->lock) -void os_mutexLock( - _Inout_ os_mutex *mutex) -{ - assert(mutex != NULL); - - AcquireSRWLockExclusive(&mutex->lock); -} - -_Check_return_ -_When_(return == os_resultSuccess, _Acquires_nonreentrant_lock_(&mutex->lock)) -os_result os_mutexLock_s( - _Inout_ os_mutex *mutex) -{ - os_mutexLock(mutex); - return os_resultSuccess; -} - -_Check_return_ -_When_(return == os_resultSuccess, _Acquires_nonreentrant_lock_(&mutex->lock)) -os_result -os_mutexTryLock( - _Inout_ os_mutex *mutex) -{ - assert(mutex != NULL); - - return TryAcquireSRWLockExclusive(&mutex->lock) ? os_resultSuccess : os_resultBusy; -} - -_Releases_nonreentrant_lock_(&mutex->lock) -void os_mutexUnlock( - _Inout_ os_mutex *mutex) -{ - assert(mutex != NULL); - - ReleaseSRWLockExclusive(&mutex->lock); -} - -void os_condInit( - _Out_ os_cond *cond, - _In_ os_mutex *dummymtx) -{ - assert(cond != NULL); - assert(dummymtx != NULL); - - (void)dummymtx; - InitializeConditionVariable(&cond->cond); -} - -void os_condDestroy( - _Inout_ _Post_invalid_ os_cond *cond) -{ - assert(cond != NULL); -} - -void os_condWait(os_cond *cond, os_mutex *mutex) -{ - assert(cond != NULL); - assert(mutex != NULL); - - if (!SleepConditionVariableSRW(&cond->cond, &mutex->lock, INFINITE, 0)) { - abort(); - } -} - -os_result os_condTimedWait(os_cond *cond, os_mutex *mutex, const os_time *time) -{ - DWORD timems; - assert(cond != NULL); - assert(mutex != NULL); - - timems = time->tv_sec * 1000 + (time->tv_nsec + 999999) / 1000000; - if (SleepConditionVariableSRW(&cond->cond, &mutex->lock, timems, 0)) { - return os_resultSuccess; - } else if (GetLastError() != ERROR_TIMEOUT) { - abort(); - } else if (timems != INFINITE) { - return os_resultTimeout; - } else { - return os_resultSuccess; - } -} - -void os_condSignal(os_cond *cond) -{ - assert(cond != NULL); - - WakeConditionVariable(&cond->cond); -} - -void os_condBroadcast(os_cond *cond) -{ - assert(cond != NULL); - - WakeAllConditionVariable(&cond->cond); -} - -void os_rwlockInit(_Out_ os_rwlock *rwlock) -{ - assert(rwlock); - - InitializeSRWLock(&rwlock->lock); - rwlock->state = 0; -} - -void os_rwlockDestroy(_Inout_ _Post_invalid_ os_rwlock *rwlock) -{ - assert(rwlock); -} - -void os_rwlockRead(os_rwlock *rwlock) -{ - assert(rwlock); - - AcquireSRWLockShared(&rwlock->lock); - rwlock->state = 1; -} - -void os_rwlockWrite(os_rwlock *rwlock) -{ - assert(rwlock); - - AcquireSRWLockExclusive(&rwlock->lock); - rwlock->state = -1; -} - -os_result os_rwlockTryRead(os_rwlock *rwlock) -{ - assert(rwlock); - - if (TryAcquireSRWLockShared(&rwlock->lock)) { - rwlock->state = 1; - return os_resultSuccess; - } - - return os_resultBusy; -} - -os_result os_rwlockTryWrite(os_rwlock *rwlock) -{ - assert(rwlock); - - if (TryAcquireSRWLockExclusive(&rwlock->lock)) { - rwlock->state = -1; - return os_resultSuccess; - } - - return os_resultBusy; -} - -void os_rwlockUnlock(os_rwlock *rwlock) -{ - assert(rwlock); - - assert(rwlock->state != 0); - if (rwlock->state > 0) { - ReleaseSRWLockShared(&rwlock->lock); - } else { - ReleaseSRWLockExclusive(&rwlock->lock); - } -} - -struct os__onceWrapper { - os_once_fn init_fn; -}; - -static BOOL WINAPI -os__onceWrapper( - _Inout_ PINIT_ONCE InitOnce, - _Inout_opt_ PVOID Parameter, - _Outptr_opt_result_maybenull_ PVOID *Context) -{ - struct os__onceWrapper *wrap = (struct os__onceWrapper *) Parameter; - - /* Only to be invoked from os_once, so assume inputs to be as - * expected instead of implementing checks officially needed to - * fulfill SAL. */ - _Analysis_assume_(wrap); - _Analysis_assume_(Context == NULL); - - wrap->init_fn(); - - return TRUE; -} - -void -os_once( - _Inout_ os_once_t *control, - _In_ os_once_fn init_fn) -{ - struct os__onceWrapper wrap = { .init_fn = init_fn }; - (void) InitOnceExecuteOnce(control, &os__onceWrapper, &wrap, NULL); -} diff --git a/src/os/src/windows/os_platform_thread.c b/src/os/src/windows/os_platform_thread.c deleted file mode 100644 index 943e93f..0000000 --- a/src/os/src/windows/os_platform_thread.c +++ /dev/null @@ -1,580 +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 - */ -/** \file os/win32/code/os_thread.c - * \brief WIN32 thread management - * - * Implements thread management for WIN32 - */ - -#include "os/os.h" - -#include - -typedef struct { - char *threadName; - void *arguments; - os_threadRoutine startRoutine; -} os_threadContext; - -static DWORD tlsIndex; - -static os_result -os_threadMemInit(void) -{ - void **tlsMemArray; - BOOL result; - - tlsMemArray = os_malloc (sizeof(void *) * OS_THREAD_MEM_ARRAY_SIZE); - memset(tlsMemArray, 0, sizeof(void *) * OS_THREAD_MEM_ARRAY_SIZE); - result = TlsSetValue(tlsIndex, tlsMemArray); - if (!result) { - //OS_INIT_FAIL("os_threadMemInit: failed to set TLS"); - goto err_setTls; - } - return os_resultSuccess; - -err_setTls: - os_free(tlsMemArray); - return os_resultFail; -} - -static void -os_threadMemExit(void) -{ - void **tlsMemArray; - int i; - - tlsMemArray = (void **)TlsGetValue(tlsIndex); - if (tlsMemArray != NULL) { -/*The compiler doesn't realize that tlsMemArray has always size OS_THREAD_MEM_ARRAY_SIZE. */ -#pragma warning(push) -#pragma warning(disable: 6001) - for (i = 0; i < OS_THREAD_MEM_ARRAY_SIZE; i++) { - if (tlsMemArray[i] != NULL) { - os_free(tlsMemArray[i]); - } - } -#pragma warning(pop) - os_free(tlsMemArray); - TlsSetValue(tlsIndex, NULL); - } -} - -/** \brief Initialize the thread module - * - * \b os_threadModuleInit initializes the thread module for the - * calling process - */ -os_result -os_threadModuleInit(void) -{ - if ((tlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) { - //OS_INIT_FAIL("os_threadModuleInit: could not allocate thread-local memory (System Error Code: %i)", os_getErrno()); - goto err_tlsAllocFail; - } - - return os_resultSuccess; - -err_tlsAllocFail: - return os_resultFail; -} - -/** \brief Deinitialize the thread module - * - * \b os_threadModuleExit deinitializes the thread module for the - * calling process - */ -void -os_threadModuleExit(void) -{ - void **tlsMemArray = TlsGetValue(tlsIndex); - - if (tlsMemArray != NULL) { - os_free(tlsMemArray); - } - - TlsFree(tlsIndex); -} - -const DWORD MS_VC_EXCEPTION=0x406D1388; - -#pragma pack(push,8) -typedef struct tagTHREADNAME_INFO -{ - /** Must be 0x1000. */ - DWORD dwType; - /** Pointer to name (in user addr space). */ - LPCSTR szName; - /** Thread ID (-1=caller thread). */ - DWORD dwThreadID; - /** Reserved for future use, must be zero. */ - DWORD dwFlags; -} THREADNAME_INFO; -#pragma pack(pop) - -/** -* Usage: os_threadSetThreadName (-1, "MainThread"); -* @pre :: -* @see http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx -* @param dwThreadID The thread ID that is to be named, -1 for 'self' -* @param threadName The name to apply. -*/ -void os_threadSetThreadName( DWORD dwThreadID, char* threadName) -{ - char* tssThreadName; -#ifndef WINCE /* When we merge the code, this first bit won't work there */ - THREADNAME_INFO info; - info.dwType = 0x1000; - info.szName = threadName; - info.dwThreadID = dwThreadID; - info.dwFlags = 0; - -/* Empty try/except that catches everything is done on purpose to set the - * thread name. This code equals the official example on msdn, including - * the warning suppressions. */ -#pragma warning(push) -#pragma warning(disable: 6320 6322) - __try - { - RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - } -#pragma warning(pop) -#endif /* No reason why the restshouldn't though */ - - tssThreadName = (char *)os_threadMemGet(OS_THREAD_NAME); - if (tssThreadName == NULL) - { - tssThreadName = (char *)os_threadMemMalloc(OS_THREAD_NAME, (strlen(threadName) + 1)); - strcpy(tssThreadName, threadName); - } -} - -/** \brief Wrap thread start routine - * - * \b os_startRoutineWrapper wraps a threads starting routine. - * before calling the user routine. It tries to set a thread name - * that will be visible if the process is running under the MS - * debugger. - */ -static uint32_t -os_startRoutineWrapper( - _In_ _Post_invalid_ void *threadContext) -{ - os_threadContext *context = threadContext; - uint32_t resultValue = 0; - os_threadId id; - - /* allocate an array to store thread private memory references */ - os_threadMemInit(); - - /* Set a thread name that will take effect if the process is running under a debugger */ - os_threadSetThreadName(-1, context->threadName); - - id.threadId = GetCurrentThreadId(); - id.handle = GetCurrentThread(); - - /* Call the user routine */ - resultValue = context->startRoutine(context->arguments); - - /* Free the thread context resources, arguments is responsibility */ - /* for the caller of os_threadCreate */ - os_free (context->threadName); - os_free (context); - - /* deallocate the array to store thread private memory references */ - os_threadMemExit (); - - /* return the result of the user routine */ - return resultValue; -} - -/** \brief Create a new thread - * - * \b os_threadCreate creates a thread by calling \b CreateThread. - */ -os_result -os_threadCreate( - _Out_ os_threadId *threadId, - _In_z_ const char *name, - _In_ const os_threadAttr *threadAttr, - _In_ os_threadRoutine start_routine, - _In_opt_ void *arg) -{ - HANDLE threadHandle; - DWORD threadIdent; - os_threadContext *threadContext; - - int32_t effective_priority; - - assert(threadId != NULL); - assert(name != NULL); - assert(threadAttr != NULL); - assert(start_routine != NULL); - - /* Take over the thread context: name, start routine and argument */ - threadContext = os_malloc(sizeof (*threadContext)); - threadContext->threadName = os_strdup(name); - threadContext->startRoutine = start_routine; - threadContext->arguments = arg; - threadHandle = CreateThread(NULL, - (SIZE_T)threadAttr->stackSize, - (LPTHREAD_START_ROUTINE)os_startRoutineWrapper, - (LPVOID)threadContext, - (DWORD)0, &threadIdent); - if (threadHandle == 0) { - DDS_WARNING("Failed with System Error Code: %i\n", os_getErrno ()); - return os_resultFail; - } - - fflush(stdout); - - threadId->handle = threadHandle; - threadId->threadId = threadIdent; - - /* #642 fix (JCM) - * Windows thread priorities are in the range below : - -15 : THREAD_PRIORITY_IDLE - -2 : THREAD_PRIORITY_LOWEST - -1 : THREAD_PRIORITY_BELOW_NORMAL - 0 : THREAD_PRIORITY_NORMAL - 1 : THREAD_PRIORITY_ABOVE_NORMAL - 2 : THREAD_PRIORITY_HIGHEST - 15 : THREAD_PRIORITY_TIME_CRITICAL - For realtime threads additional values are allowed : */ - - /* PROCESS_QUERY_INFORMATION rights required - * to call GetPriorityClass - * Ensure that priorities are effectively in the allowed range depending - * on GetPriorityClass result */ - effective_priority = threadAttr->schedPriority; - if (GetPriorityClass(GetCurrentProcess()) == REALTIME_PRIORITY_CLASS) { - if (threadAttr->schedPriority < -7) { - effective_priority = THREAD_PRIORITY_IDLE; - } - if (threadAttr->schedPriority > 6) { - effective_priority = THREAD_PRIORITY_TIME_CRITICAL; - } - } else { - if (threadAttr->schedPriority < THREAD_PRIORITY_LOWEST) { - effective_priority = THREAD_PRIORITY_IDLE; - } - if (threadAttr->schedPriority > THREAD_PRIORITY_HIGHEST) { - effective_priority = THREAD_PRIORITY_TIME_CRITICAL; - } - } - if (SetThreadPriority (threadHandle, effective_priority) == 0) { - DDS_INFO("SetThreadPriority failed with %i\n", os_getErrno()); - } - - /* ES: dds2086: Close handle should not be performed here. Instead the handle - * should not be closed until the os_threadWaitExit(...) call is called. - * CloseHandle (threadHandle); - */ - return os_resultSuccess; -} - -/** \brief Return the integer representation of the given thread ID - * - * Possible Results: - * - returns the integer representation of the given thread ID - */ -uintmax_t -os_threadIdToInteger(os_threadId id) -{ - return id.threadId; -} - -/** \brief Return the thread ID of the calling thread - * - * \b os_threadIdSelf determines the own thread ID by - * calling \b GetCurrentThreadId (). - */ -os_threadId -os_threadIdSelf( - void) -{ - os_threadId id; - id.threadId = GetCurrentThreadId(); - id.handle = GetCurrentThread(); /* pseudo HANDLE, no need to close it */ - - return id; -} - -/** \brief Wait for the termination of the identified thread - * - * \b os_threadWaitExit wait for the termination of the - * thread \b threadId by calling \b pthread_join. The return - * value of the thread is passed via \b thread_result. - */ -os_result -os_threadWaitExit( - _In_ os_threadId threadId, - _Out_opt_ uint32_t *thread_result) -{ - DWORD tr; - DWORD err; - DWORD waitres; - BOOL status; - - if(threadId.handle == NULL){ - //OS_DEBUG("os_threadWaitExit", "Parameter threadId is null"); - return os_resultFail; - } - - waitres = WaitForSingleObject(threadId.handle, INFINITE); - if (waitres != WAIT_OBJECT_0) { - err = os_getErrno(); - //OS_DEBUG_1("os_threadWaitExit", "WaitForSingleObject Failed %d", err); - return os_resultFail; - } - - status = GetExitCodeThread(threadId.handle, &tr); - if (!status) { - err = os_getErrno(); - //OS_DEBUG_1("os_threadWaitExit", "GetExitCodeThread Failed %d", err); - return os_resultFail; - } - - assert(tr != STILL_ACTIVE); - if (thread_result) { - *thread_result = tr; - } - CloseHandle(threadId.handle); - - return os_resultSuccess; -} - -int -os_threadGetThreadName( - char *buffer, - uint32_t length) -{ - char *name; - - assert (buffer != NULL); - - if ((name = os_threadMemGet(OS_THREAD_NAME)) == NULL) { - name = ""; - } - - return snprintf (buffer, length, "%s", name); -} - -/** \brief Allocate thread private memory - * - * Allocate heap memory of the specified \b size and - * relate it to the thread by storing the memory - * reference in an thread specific reference array - * indexed by \b index. If the indexed thread reference - * array location already contains a reference, no - * memory will be allocated and NULL is returned. - * - * Possible Results: - * - returns NULL if - * index < 0 || index >= OS_THREAD_MEM_ARRAY_SIZE - * - returns NULL if - * no sufficient memory is available on heap - * - returns NULL if - * os_threadMemGet (index) returns != NULL - * - returns reference to allocated heap memory - * of the requested size if - * memory is successfully allocated - */ -void * -os_threadMemMalloc( - int32_t index, - size_t size) -{ - void **tlsMemArray; - void *threadMemLoc = NULL; - - if ((0 <= index) && (index < OS_THREAD_MEM_ARRAY_SIZE)) { - tlsMemArray = (void **)TlsGetValue(tlsIndex); - if (tlsMemArray == NULL) { - os_threadMemInit (); - tlsMemArray = (void **)TlsGetValue(tlsIndex); - } - if (tlsMemArray != NULL) { - if (tlsMemArray[index] == NULL) { - threadMemLoc = os_malloc(size); - tlsMemArray[index] = threadMemLoc; - } - } - } - return threadMemLoc; -} - -/** \brief Free thread private memory - * - * Free the memory referenced by the thread reference - * array indexed location. If this reference is NULL, - * or index is invalid, no action is taken. - * The reference is set to NULL after freeing the - * heap memory. - * - * Postcondition: - * - os_threadMemGet (index) = NULL and allocated - * heap memory is freed - */ -void -os_threadMemFree( - int32_t index) -{ - void **tlsMemArray; - void *threadMemLoc = NULL; - - if ((0 <= index) && (index < OS_THREAD_MEM_ARRAY_SIZE)) { - tlsMemArray = (void **)TlsGetValue(tlsIndex); - if (tlsMemArray != NULL) { - threadMemLoc = tlsMemArray[index]; - if (threadMemLoc != NULL) { - tlsMemArray[index] = NULL; - os_free(threadMemLoc); - } - } - } -} - -/** \brief Get thread private memory - * - * Possible Results: - * - returns NULL if - * No heap memory is related to the thread for - * the specified index - * - returns a reference to the allocated memory - */ -void * -os_threadMemGet( - int32_t index) -{ - void **tlsMemArray; - void *data; - - data = NULL; - if ((0 <= index) && (index < OS_THREAD_MEM_ARRAY_SIZE)) { - tlsMemArray = TlsGetValue(tlsIndex); - if (tlsMemArray != NULL) { - data = tlsMemArray[index]; - } - } - - return data; -} - - -static os_threadLocal os_iter *cleanup_funcs; - -/* executed before dllmain within the context of the thread itself */ -void NTAPI -os_threadCleanupFini( - PVOID handle, - DWORD reason, - PVOID reserved) -{ - os_threadCleanup *obj; - - switch(reason) { - case DLL_PROCESS_DETACH: /* specified when main thread exits */ - case DLL_THREAD_DETACH: /* specified when thread exits */ - if (cleanup_funcs != NULL) { - for (obj = (os_threadCleanup *)os_iterTake(cleanup_funcs, -1); - obj != NULL; - obj = (os_threadCleanup *)os_iterTake(cleanup_funcs, -1)) - { - assert(obj->func != NULL); - obj->func(obj->data); - os_free(obj); - } - os_iterFree(cleanup_funcs, NULL); - } - cleanup_funcs = NULL; - break; - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - default: - /* do nothing */ - break; - } - - (void)handle; - (void)reserved; -} - -/* These instructions are very specific to the Windows platform. They register - a function (or multiple) as a TLS initialization function. TLS initializers - are executed when a thread (or program) attaches or detaches. In contrast to - DllMain, a TLS initializer is also executed when the library is linked - statically. TLS initializers are always executed before DllMain (both when - the library is attached and detached). See http://www.nynaeve.net/?p=190, - for a detailed explanation on TLS initializers. Boost and/or POSIX Threads - for Windows code bases may also form good sources of information on this - subject. - - These instructions could theoretically be hidden in the build system, but - doing so would be going a bit overboard as only Windows offers (and - requires) this type of functionality/initialization. Apart from that the - logic isn't exactly as trivial as for example determining the endianness of - a platform, so keeping this close to the implementation is probably wise. */ -#ifdef _WIN64 - #pragma comment (linker, "/INCLUDE:_tls_used") - #pragma comment (linker, "/INCLUDE:tls_callback_func") - #pragma const_seg(".CRT$XLZ") - EXTERN_C const PIMAGE_TLS_CALLBACK tls_callback_func = os_threadCleanupFini; - #pragma const_seg() -#else - #pragma comment (linker, "/INCLUDE:__tls_used") - #pragma comment (linker, "/INCLUDE:_tls_callback_func") - #pragma data_seg(".CRT$XLZ") - EXTERN_C PIMAGE_TLS_CALLBACK tls_callback_func = os_threadCleanupFini; - #pragma data_seg() -#endif - -void -os_threadCleanupPush( - void (*func)(void *), - void *data) -{ - os_threadCleanup *obj; - - assert(func != NULL); - - if (cleanup_funcs == NULL) { - cleanup_funcs = os_iterNew(); - assert(cleanup_funcs != NULL); - } - - obj = os_malloc(sizeof(*obj)); - assert(obj != NULL); - obj->func = func; - obj->data = data; - (void)os_iterAppend(cleanup_funcs, obj); -} - -void -os_threadCleanupPop( - int execute) -{ - os_threadCleanup *obj; - - if (cleanup_funcs != NULL) { - obj = os_iterTake(cleanup_funcs, -1); - if (obj != NULL) { - if (execute) { - obj->func(obj->data); - } - os_free(obj); - } - } -} diff --git a/src/os/src/windows/os_platform_time.c b/src/os/src/windows/os_platform_time.c deleted file mode 100644 index 8de7cf3..0000000 --- a/src/os/src/windows/os_platform_time.c +++ /dev/null @@ -1,210 +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 - */ -/** \file os/mingw3.2.0/code/os_time.c - * \brief WIN32 time management - * - * Implements time management for WIN32 by - * including the common services - * and implementing WIN32 specific - * os_timeGet and os_nanoSleep - */ -#include -#include - -#include "os/os.h" - -#include - -/* GetSystemTimePreciseAsFileTime was introduced with Windows 8, so - starting from _WIN32_WINNET = 0x0602. When building for an older - version we can still check dynamically. */ - -#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 -#define UseGetSystemTimePreciseAsFileTime -#else -static VOID (WINAPI *GetSystemTimeAsFileTimeFunc) (_Out_ LPFILTETIME) = GetSystemTimeAsFileTime; -static HANDLE Kernel32ModuleHandle; -#endif - -/* GetSystemTimeAsFileTime returns the number of 100ns intervals that have elapsed - * since January 1, 1601 (UTC). There are 11,644,473,600 seconds between 1601 and - * the Unix epoch (January 1, 1970 (UTC)), which is the reference that is used for - * os_time. */ -#define OS_TIME_FILETIME_UNIXEPOCH_OFFSET_SECS (11644473600) - -os_time -os__timeDefaultTimeGet(void) -{ - FILETIME ft; - ULARGE_INTEGER ns100; - os_time current_time; - - /* GetSystemTime(Precise)AsFileTime returns the number of 100-nanosecond - * intervals since January 1, 1601 (UTC). - * GetSystemTimeAsFileTime has a resolution of approximately the - * TimerResolution (~15.6ms) on Windows XP. On Windows 7 it appears to have - * sub-millisecond resolution. GetSystemTimePreciseAsFileTime (available on - * Windows 8) has sub-microsecond resolution. - * - * This call appears to be significantly (factor 8) cheaper than the - * QueryPerformanceCounter (on the systems performance was measured on). - * - * TODO: When the API is extended to support retrieval of clock-properties, - * then the actual resolution of this clock can be retrieved using the - * GetSystemTimeAdjustment. See for example OSPL-4394. - */ -#ifdef UseGetSystemTimePreciseAsFileTime - GetSystemTimePreciseAsFileTime(&ft); -#else - GetSystemTimeAsFileTimeFunc(&ft); -#endif - ns100.LowPart = ft.dwLowDateTime; - ns100.HighPart = ft.dwHighDateTime; - current_time.tv_sec = (os_timeSec)((ns100.QuadPart / 10000000) - OS_TIME_FILETIME_UNIXEPOCH_OFFSET_SECS); - current_time.tv_nsec = (int32_t)((ns100.QuadPart % 10000000) * 100); - - return current_time; -} - -void -os_timeModuleInit(void) -{ -#ifndef UseGetSystemTimePreciseAsFileTime - /* Resolve the time-functions from the Kernel32-library. */ - VOID (WINAPI *f) (_Out_ LPFILTETIME); - - /* This os_timeModuleInit is currently called from DllMain. This means - * we're not allowed to do LoadLibrary. One exception is "Kernel32.DLL", - * since that library is per definition loaded (LoadLibrary itself - * lives there). And since we're only resolving stuff, not actually - * invoking, this is considered safe. */ - Kernel32ModuleHandle = LoadLibrary("Kernel32.DLL"); - assert(Kernel32ModuleHandle); - - f = GetProcAddress(Kernel32ModuleHandle, "GetSystemTimePreciseAsFileTime"); - if (f != 0) { - GetSystemTimeAsFileTimeFunc = f; - } -#endif -} - -void -os_timeModuleExit(void) -{ -#ifndef UseGetSystemTimePreciseAsFileTime - if (Kernel32ModuleHandle) { - GetSystemTimeAsFileTimeFunc = GetSystemTimeAsFileTime; - FreeLibrary(Kernel32ModuleHandle); - Kernel32ModuleHandle = NULL; - } -#endif -} - -/** \brief Suspend the execution of the calling thread for the specified time - * - * \b os_nanoSleep suspends the calling thread for the required - * time by calling \b nanosleep. First it converts the \b delay in - * \b os_time definition into a time in \b struct \b timeval definition. - * In case the \b nanosleep is interrupted, the call is re-enterred with - * the remaining time. - */ -os_result -os_nanoSleep ( - _In_ os_time delay) -{ - os_result result = os_resultSuccess; - DWORD dt; - - assert (delay.tv_nsec >= 0); - assert (delay.tv_nsec < 1000000000); - - if (delay.tv_sec >= 0 ) { - dt = (DWORD)delay.tv_sec * 1000 + delay.tv_nsec / 1000000; - Sleep(dt); - } else { - /* Negative time-interval should return illegal param error */ - result = os_resultFail; - } - - return result; -} - -/** \brief Get high resolution, monotonic time. - * - */ -os_time -os_timeGetMonotonic(void) -{ - os_time current_time; - ULONGLONG ubit; - - (void) QueryUnbiasedInterruptTime(&ubit); /* 100ns ticks */ - - current_time.tv_sec = (os_timeSec)(ubit / 10000000); - current_time.tv_nsec = (int32_t)((ubit % 10000000) * 100); - - return current_time; -} - -/** \brief Get high resolution, elapsed time. - * - */ -os_time -os_timeGetElapsed(void) -{ - os_time current_time; - LARGE_INTEGER qpc; - static LONGLONG qpc_freq; - - /* The QueryPerformanceCounter has a bad reputation, since it didn't behave - * very well on older hardware. On recent OS's (Windows XP SP2 and later) - * things have become much better, especially when combined with new hard- - * ware. - * - * There is currently one bug which is not fixed, which may cause forward - * jumps. This is currently not really important, since a forward jump may - * be observed anyway due to the system going to standby. There is a work- - * around available (comparing the progress with the progress made by - * GetTickCount), but for now we live with a risk of a forward jump on buggy - * hardware. Since Microsoft does maintain a list of hardware which exhibits - * the behaviour, it is possible to only have the workaround in place only - * on the faulty hardware (see KB274323 for a list and more info). - * - * TODO: When the API is extended to support retrieval of clock-properties, - * then the discontinuous nature (when sleeping/hibernating) of this - * clock and the drift tendency should be reported. See for example - * OSPL-4394. */ - - if (qpc_freq == 0){ - /* This block is idempotent, so don't bother with synchronisation */ - LARGE_INTEGER frequency; - - if(QueryPerformanceFrequency(&frequency)){ - qpc_freq = frequency.QuadPart; - } - /* Since Windows XP SP2 the QueryPerformanceCounter is abstracted, - * so QueryPerformanceFrequency is not expected to ever return 0. - * That't why there is no fall-back for the case when no - * QueryPerformanceCounter is available. */ - } - assert(qpc_freq); - - /* The QueryPerformanceCounter tends to drift quite a bit, so in order to - * accurately measure longer periods with it, there may be a need to sync - * the time progression to actual time progression (with a PLL for example - * as done by EB for CAE). */ - QueryPerformanceCounter(&qpc); - current_time.tv_sec = (os_timeSec)(qpc.QuadPart / qpc_freq); - current_time.tv_nsec = (int32_t)(((qpc.QuadPart % qpc_freq) * 1000000000) / qpc_freq); - - return current_time; -} diff --git a/src/os/tests/CMakeLists.txt b/src/os/tests/CMakeLists.txt deleted file mode 100644 index 76ecc26..0000000 --- a/src/os/tests/CMakeLists.txt +++ /dev/null @@ -1,34 +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 -# -include(CUnit) - -set(sources - "atomics.c" - "error_no.c" - "heap.c" - "ifaddrs.c" - "iter.c" - "mutex.c" - "once.c" - "rwlock.c" - "stdlib.c" - "strtoll.c" - "thread.c" - "thread_cleanup.c" - "strcasecmp.c" - "log.c" - "strlcpy.c" - "socket.c") - -add_cunit_executable(cunit_abstraction ${sources}) -target_link_libraries(cunit_abstraction OSAPI) - diff --git a/src/os/tests/atomics.c b/src/os/tests/atomics.c deleted file mode 100644 index 2683e68..0000000 --- a/src/os/tests/atomics.c +++ /dev/null @@ -1,467 +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 - */ -#include "os/os.h" -#include "CUnit/Test.h" - -uint32_t _osuint32 = 0; -uint64_t _osuint64 = 0; -// os_address is uintptr_t -uintptr_t _osaddress = 0; -ptrdiff_t _ptrdiff = 0; -void * _osvoidp = (uintptr_t *)0; - -CU_Test(os_atomics, load_store) -{ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(5); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(5); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(5); - volatile os_atomic_voidp_t voidp = OS_ATOMIC_VOIDP_INIT((uintptr_t)5); - - /* Test uint32 LD-ST */ - printf ("Starting os_atomics_load_store_001\n"); - CU_ASSERT (os_atomic_ld32 (&uint32) == 5); /* Returns contents of uint32 */ - os_atomic_st32 (&uint32, _osuint32); /* Writes os_uint32 into uint32 */ - CU_ASSERT (os_atomic_ld32 (&uint32) == _osuint32); - - /* Test uint64 LD-ST */ - printf ("Starting os_atomics_load_store_002\n"); -#if OS_ATOMIC64_SUPPORT - CU_ASSERT (os_atomic_ld64 (&uint64) == 5); - os_atomic_st64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == _osuint64); -#endif - - /* Test uintptr LD-ST */ - printf ("Starting os_atomics_load_store_003\n"); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 5); - os_atomic_stptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_ldptr (&uintptr) == _osaddress); - - /* Test uintvoidp LD-ST */ - printf ("Starting os_atomics_load_store_004\n"); - CU_ASSERT (os_atomic_ldvoidp (&voidp) == (uintptr_t*)5); - os_atomic_stvoidp (&voidp, _osvoidp); - CU_ASSERT (os_atomic_ldvoidp (&voidp) == (uintptr_t*)_osvoidp); - - printf ("Ending atomics_load_store\n"); -} - -CU_Test(os_atomics, compare_and_swap) -{ - /* Compare and Swap - * if (ptr == expected) { ptr = newval; } - */ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(0); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(0); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(0); - volatile os_atomic_voidp_t uintvoidp = OS_ATOMIC_VOIDP_INIT((uintptr_t)0); - _osuint32 = 1; - _osuint64 = 1; - _osaddress = 1; - _osvoidp = (uintptr_t *)1; - uint32_t expected = 0, newval = 5; - uintptr_t addr_expected = 0, addr_newval = 5; - void *void_expected = (uintptr_t*)0; - void *void_newval = (uintptr_t*)5; - int ret = 0; - - /* Test os_atomic_cas32 */ - printf ("Starting os_atomics_compare_and_swap_001\n"); - ret = os_atomic_cas32 (&uint32, expected, newval); - CU_ASSERT (os_atomic_ld32 (&uint32) == newval && ret == 1); - os_atomic_st32 (&uint32, _osuint32); - ret = os_atomic_cas32 (&uint32, expected, newval); - CU_ASSERT (os_atomic_ld32 (&uint32) != newval && ret == 0); - - /* Test os_atomic_cas64 */ - printf ("Starting os_atomics_compare_and_swap_002\n"); -#if OS_ATOMIC64_SUPPORT - ret = os_atomic_cas64 (&uint64, expected, newval); - CU_ASSERT (os_atomic_ld64 (&uint64) == newval && ret == 1); - os_atomic_st64 (&uint64, _osuint64); - ret = os_atomic_cas64 (&uint64, expected, newval); - CU_ASSERT (os_atomic_ld64 (&uint64) != newval && ret == 0); -#endif - - /* Test os_atomic_casptr */ - printf ("Starting os_atomics_compare_and_swap_003\n"); - ret = os_atomic_casptr (&uintptr, addr_expected, addr_newval); - CU_ASSERT (os_atomic_ldptr (&uintptr) == addr_newval && ret == 1); - os_atomic_stptr (&uintptr, _osaddress); - ret = os_atomic_casptr (&uintptr, addr_expected, addr_newval); - CU_ASSERT (os_atomic_ldptr (&uintptr) != addr_newval && ret == 0); - - /* Test os_atomic_casvoidp */ - printf ("Starting os_atomics_compare_and_swap_003\n"); - ret = os_atomic_casvoidp (&uintvoidp, void_expected, void_newval); - CU_ASSERT (os_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)void_newval && ret == 1); - os_atomic_stvoidp (&uintvoidp, _osvoidp); - ret = os_atomic_casvoidp (&uintvoidp, void_expected, void_newval); - CU_ASSERT (os_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)1 && ret == 0); - - printf ("Ending atomics_compare_and_swap\n"); -} - -CU_Test(os_atomics, increment) -{ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(0); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(0); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(0); - _osuint32 = 0; - _osuint64 = 0; - _osaddress = 0; - _osvoidp = (uintptr_t *)0; - - /* Test os_inc32 */ - printf ("Starting os_atomics_increment_001\n"); - os_atomic_inc32 (&uint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 1); - - /* Test os_inc64 */ - printf ("Starting os_atomics_increment_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_inc64 (&uint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 1); -#endif - - /* Test os_incptr */ - printf ("Starting os_atomics_increment_003\n"); - os_atomic_incptr (&uintptr); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 1); - - /* Test os_atomic_inc32_nv */ - printf ("Starting os_atomics_increment_004\n"); - os_atomic_st32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_inc32_nv (&uint32) == 1); - - /* Test os_atomic_inc64_nv */ - printf ("Starting os_atomics_increment_005\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_st64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_inc64_nv (&uint64) == 1); -#endif - - /* Test os_atomic_incptr_nv */ - printf ("Starting os_atomics_increment_006\n"); - os_atomic_stptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_incptr_nv(&uintptr) == 1); - - printf ("Ending atomics_increment\n"); -} - -CU_Test(os_atomics, decrement) -{ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(1); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(1); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(1); - _osuint32 = 1; - _osuint64 = 1; - _osaddress = 1; - _osvoidp = (uintptr_t *)1; - - /* Test os_atomic_dec32 */ - printf ("Starting os_atomics_decrement_001\n"); - os_atomic_dec32 (&uint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 0); - - /* Test os_atomic_dec64 */ - printf ("Starting os_atomics_decrement_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_dec64 (&uint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 0); -#endif - - /* Test os_atomic_decptr */ - printf ("Starting os_atomics_decrement_003\n"); - os_atomic_decptr (&uintptr); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 0); - - /* Test os_atomic_dec32_nv */ - printf ("Starting os_atomics_decrement_004\n"); - os_atomic_st32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_dec32_nv (&uint32) == 0); - - /* Test os_atomic_dec64_nv */ - printf ("Starting os_atomics_decrement_005\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_st64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_dec64_nv (&uint64) == 0); -#endif - - /* Test os_atomic_decptr_nv */ - printf ("Starting os_atomics_decrement_006\n"); - os_atomic_stptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_decptr_nv(&uintptr) == 0); - - printf ("Ending atomics_decrement\n"); -} - -CU_Test(os_atomics, add) -{ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(1); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(1); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(1); - volatile os_atomic_voidp_t uintvoidp = OS_ATOMIC_VOIDP_INIT((uintptr_t)1); - _osuint32 = 2; - _osuint64 = 2; - _osaddress = 2; - _ptrdiff = 2; - - /* Test os_atomic_add32 */ - printf ("Starting os_atomics_add_001\n"); - os_atomic_add32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 3); - - /* Test os_atomic_add64 */ - printf ("Starting os_atomics_add_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_add64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 3); -#endif - - /* Test os_atomic_addptr */ - printf ("Starting os_atomics_add_003\n"); - os_atomic_addptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 3); - - /* Test os_atomic_addvoidp */ - printf ("Starting os_atomics_add_004\n"); - os_atomic_addvoidp (&uintvoidp, _ptrdiff); - CU_ASSERT (os_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)3); - - /* Test os_atomic_add32_nv */ - printf ("Starting os_atomics_add_005\n"); - os_atomic_st32 (&uint32, 1); - CU_ASSERT (os_atomic_add32_nv (&uint32, _osuint32) == 3); - - /* Test os_atomic_add64_nv */ - printf ("Starting os_atomics_add_006\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_st64 (&uint64, 1); - CU_ASSERT (os_atomic_add64_nv (&uint64, _osuint64) == 3); -#endif - - /* Test os_atomic_addptr_nv */ - printf ("Starting os_atomics_add_007\n"); - os_atomic_stptr (&uintptr, 1); - CU_ASSERT (os_atomic_addptr_nv (&uintptr, _osaddress) == 3); - - /* Test os_atomic_addvoidp_nv */ - printf ("Starting os_atomics_add_008\n"); - os_atomic_stvoidp (&uintvoidp, (uintptr_t*)1); - CU_ASSERT (os_atomic_addvoidp_nv (&uintvoidp, _ptrdiff) == (uintptr_t*)3); - - printf ("Ending atomics_add\n"); -} - -CU_Test(os_atomics, subtract) -{ - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(5); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(5); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(5); - volatile os_atomic_voidp_t uintvoidp = OS_ATOMIC_VOIDP_INIT((uintptr_t)5); - _osuint32 = 2; - _osuint64 = 2; - _osaddress = 2; - _ptrdiff = 2; - - /* Test os_atomic_sub32 */ - printf ("Starting os_atomics_subtract_001\n"); - os_atomic_sub32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 3); - - /* Test os_atomic_sub64 */ - printf ("Starting os_atomics_subtract_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_sub64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 3); -#endif - - /* Test os_atomic_subptr */ - printf ("Starting os_atomics_subtract_003\n"); - os_atomic_subptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 3); - - /* Test os_atomic_subvoidp */ - printf ("Starting os_atomics_subtract_004\n"); - os_atomic_subvoidp (&uintvoidp, _ptrdiff); - CU_ASSERT (os_atomic_ldvoidp (&uintvoidp) == (uintptr_t*)3); - - /* Test os_atomic_sub32_nv */ - printf ("Starting os_atomics_subtract_005\n"); - os_atomic_st32 (&uint32, 5); - CU_ASSERT (os_atomic_sub32_nv (&uint32, _osuint32) == 3); - - /* Test os_atomic_sub64_nv */ - printf ("Starting os_atomics_subtract_006\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_st64 (&uint64, 5); - CU_ASSERT (os_atomic_sub64_nv (&uint64, _osuint64) == 3); -#endif - - /* Test os_atomic_subptr_nv */ - printf ("Starting os_atomics_subtract_007\n"); - os_atomic_stptr (&uintptr, 5); - CU_ASSERT (os_atomic_subptr_nv (&uintptr, _osaddress) == 3); - - /* Test os_atomic_subvoidp_nv */ - printf ("Starting os_atomics_subtract_008\n"); - os_atomic_stvoidp (&uintvoidp, (uintptr_t*)5); - CU_ASSERT (os_atomic_subvoidp_nv (&uintvoidp, _ptrdiff) == (void *)3); - - printf ("Ending atomics_subtract\n"); -} - -CU_Test(os_atomics, and) -{ - /* AND Operation: - - 150 010010110 - 500 111110100 - - 148 010010100 */ - - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(150); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(150); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(150); - _osuint32 = 500; - _osuint64 = 500; - _osaddress = 500; - - /* Test os_atomic_and32 */ - printf ("Starting os_atomics_and_001\n"); - os_atomic_and32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 148); - - /* Test os_atomic_and64 */ - printf ("Starting os_atomics_and_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_and64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 148); -#endif - - /* Test os_atomic_andptr */ - printf ("Starting os_atomics_and_003\n"); - os_atomic_andptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 148); - - /* Test os_atomic_and32_ov */ - printf ("Starting os_atomics_and_004\n"); - CU_ASSERT (os_atomic_and32_ov (&uint32, _osuint32) == 148); - - /* Test os_atomic_and64_ov */ - printf ("Starting os_atomics_and_005\n"); -#if OS_ATOMIC64_SUPPORT - CU_ASSERT (os_atomic_and64_ov (&uint64, _osuint64) == 148); -#endif - - /* Test os_atomic_andptr_ov */ - printf ("Starting os_atomics_and_006\n"); - CU_ASSERT (os_atomic_andptr_ov (&uintptr, _osaddress) == 148); - - /* Test os_atomic_and32_nv */ - printf ("Starting os_atomics_and_007\n"); - CU_ASSERT (os_atomic_and32_nv (&uint32, _osuint32) == 148); - - /* Test os_atomic_and64_nv */ - printf ("Starting os_atomics_and_008\n"); -#if OS_ATOMIC64_SUPPORT - CU_ASSERT (os_atomic_and64_nv (&uint64, _osuint64) == 148); - #endif - - /* Test os_atomic_andptr_nv */ - printf ("Starting os_atomics_and_009\n"); - CU_ASSERT (os_atomic_andptr_nv (&uintptr, _osaddress) == 148); - - printf ("Ending atomics_and\n"); -} - -CU_Test(os_atomics, or) -{ - /* OR Operation: - - 150 010010110 - 500 111110100 - - 502 111110110 */ - - volatile os_atomic_uint32_t uint32 = OS_ATOMIC_UINT32_INIT(150); -#if OS_ATOMIC64_SUPPORT - volatile os_atomic_uint64_t uint64 = OS_ATOMIC_UINT64_INIT(150); -#endif - volatile os_atomic_uintptr_t uintptr = OS_ATOMIC_UINTPTR_INIT(150); - _osuint32 = 500; - _osuint64 = 500; - _osaddress = 500; - - /* Test os_atomic_or32 */ - printf ("Starting os_atomics_or_001\n"); - os_atomic_or32 (&uint32, _osuint32); - CU_ASSERT (os_atomic_ld32 (&uint32) == 502); - - /* Test os_atomic_or64 */ - printf ("Starting os_atomics_or_002\n"); -#if OS_ATOMIC64_SUPPORT - os_atomic_or64 (&uint64, _osuint64); - CU_ASSERT (os_atomic_ld64 (&uint64) == 502); -#endif - - /* Test os_atomic_orptr */ - printf ("Starting os_atomics_or_003\n"); - os_atomic_orptr (&uintptr, _osaddress); - CU_ASSERT (os_atomic_ldptr (&uintptr) == 502); - - /* Test os_atomic_or32_ov */ - printf ("Starting os_atomics_or_004\n"); - CU_ASSERT (os_atomic_or32_ov (&uint32, _osuint32) == 502); - - /* Test os_atomic_or64_ov */ - printf ("Starting os_atomics_or_005\n"); -#if OS_ATOMIC64_SUPPORT - CU_ASSERT (os_atomic_or64_ov (&uint64, _osuint64) == 502); -#endif - - /* Test os_atomic_orptr_ov */ - printf ("Starting os_atomics_or_006\n"); - CU_ASSERT (os_atomic_orptr_ov (&uintptr, _osaddress) == 502); - - /* Test os_atomic_or32_nv */ - printf ("Starting os_atomics_or_007\n"); - CU_ASSERT (os_atomic_or32_nv (&uint32, _osuint32) == 502); - - /* Test os_atomic_or64_nv */ - printf ("Starting os_atomics_or_008\n"); -#if OS_ATOMIC64_SUPPORT - CU_ASSERT (os_atomic_or64_nv (&uint64, _osuint64) == 502); -#endif - - /* Test os_atomic_orptr_nv */ - printf ("Starting os_atomics_or_009\n"); - CU_ASSERT (os_atomic_orptr_nv (&uintptr, _osaddress) == 502); - - printf ("Ending atomics_or\n"); -} - diff --git a/src/os/tests/error_no.c b/src/os/tests/error_no.c deleted file mode 100644 index 1a1833d..0000000 --- a/src/os/tests/error_no.c +++ /dev/null @@ -1,67 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - - -CU_Init(os_errno) -{ - int result = 0; - os_osInit(); - printf("Run os_errno_Initialize\n"); - - return result; -} - -CU_Clean(os_errno) -{ - int result = 0; - os_osExit(); - printf("Run os_errno_Cleanup\n"); - - return result; -} - -CU_Test(os_errno, get_and_set) -{ - printf ("Starting os_errno_get_and_set_001\n"); - os_setErrno (0); - CU_ASSERT (os_getErrno () == 0); - - printf ("Starting os_errno_get_and_set_002\n"); - os_setErrno (0); - /* Call strtol with an invalid format on purpose. */ - (void)strtol ("1000000000000000000000000000000000000000000000000", NULL, 10); - CU_ASSERT (os_getErrno () != 0); - - printf ("Ending tc_os_errno\n"); -} - -CU_Test(os_errstr, no_space) -{ - int err; - char buf[1] = { 0 }; - err = os_errstr(OS_HOST_NOT_FOUND, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, ERANGE); -} - -/* os_errstr only provides string representations for internal error codes. */ -CU_Test(os_errstr, bad_errno) -{ - int err; - char buf[128]; - buf[0] = '\0'; - err = os_errstr(OS_ERRBASE, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, EINVAL); - err = os_errstr(EINVAL, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, EINVAL); -} diff --git a/src/os/tests/heap.c b/src/os/tests/heap.c deleted file mode 100644 index 0468f1b..0000000 --- a/src/os/tests/heap.c +++ /dev/null @@ -1,197 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - - -CU_Init(os_heap) -{ - int result = 0; - os_osInit(); - printf("Run os_heap_Initialize\n"); - - return result; -} - -CU_Clean(os_heap) -{ - int result = 0; - os_osExit(); - printf("Run os_heap_Cleanup\n"); - - return result; -} - -static const size_t allocsizes[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024}; -static const size_t nof_allocsizes = sizeof allocsizes / sizeof *allocsizes; - -CU_Test(os_heap, os_malloc) -{ - for(size_t i = 0; i < nof_allocsizes; i++) { - for(size_t j = 0; j < nof_allocsizes; j++) { - size_t s = allocsizes[i] * allocsizes[j]; /* Allocates up to 1MB */ - void *ptr = os_malloc(s); - CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* os_malloc is supposed to abort on failure */ - memset(ptr, 0, s); /* This potentially segfaults if the actual allocated block is too small */ - os_free(ptr); - } - } - CU_PASS("os_malloc"); -} - -CU_Test(os_heap, os_malloc_0) -{ - for(size_t i = 0; i < nof_allocsizes; i++) { - for(size_t j = 0; j < nof_allocsizes; j++) { - size_t s = allocsizes[i] * allocsizes[j]; /* Allocates up to 1MB */ - char *ptr = os_malloc_0(s); - CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* os_malloc_0 is supposed to abort on failure */ - if(s) { - CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, s - 1)); /* malloc_0 should memset properly */ - } - os_free(ptr); - } - } - CU_PASS("os_malloc_0"); -} - -CU_Test(os_heap, os_calloc) -{ - for(size_t i = 0; i < nof_allocsizes; i++) { - for(size_t j = 0; j < nof_allocsizes; j++) { - char *ptr = os_calloc(allocsizes[i], allocsizes[j]); - CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* os_calloc is supposed to abort on failure */ - if(allocsizes[i] * allocsizes[j] > 0) { - CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, (allocsizes[i] * allocsizes[j]) - 1)); /* os_calloc should memset properly */ - } - os_free(ptr); - } - } - CU_PASS("os_calloc"); -} - -CU_Test(os_heap, os_realloc) -{ - char *ptr = NULL; - size_t unchanged, s, prevs = 0; - - for(size_t i = 0; i < nof_allocsizes; i++) { - for(size_t j = 0; j < nof_allocsizes; j++) { - s = allocsizes[i] * allocsizes[j]; /* Allocates up to 1MB */ - printf("os_realloc(%p) %zu -> %zu\n", ptr, prevs, s); - ptr = os_realloc(ptr, s); - CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL); /* os_realloc is supposed to abort on failure */ - unchanged = (prevs < s) ? prevs : s; - if(unchanged) { - CU_ASSERT (ptr[0] == 1 && !memcmp(ptr, ptr + 1, unchanged - 1)); /* os_realloc shouldn't change memory */ - } - memset(ptr, 1, s); /* This potentially segfaults if the actual allocated block is too small */ - prevs = s; - } - } - os_free(ptr); - CU_PASS("os_realloc"); -} - -static const size_t allocsizes_s[] = {0, 1, 2, 3, 4, 5, 10, 20, 257, 1024, 8192}; -static const size_t nof_allocsizes_s = sizeof allocsizes_s / sizeof *allocsizes_s; - -CU_Test(os_heap, os_malloc_s) -{ - for(size_t i = 0; i < nof_allocsizes_s; i++) { - for(size_t j = 0; j < nof_allocsizes_s; j++) { - size_t s = allocsizes_s[i] * allocsizes_s[j]; /* Allocates up to 8MB */ - void *ptr = os_malloc_s(s); /* If s == 0, os_malloc_s should still return a pointer */ - if(ptr) { - memset(ptr, 0, s); /* This potentially segfaults if the actual allocated block is too small */ - } else if (s <= 16) { - /* Failure to allocate can't be considered a test fault really, - * except that a malloc(<=16) would fail is unlikely. */ - CU_FAIL("os_malloc_0_s(<=16) returned NULL"); - } - os_free(ptr); - } - } - CU_PASS("os_malloc_s"); -} - -CU_Test(os_heap, os_malloc_0_s) -{ - for(size_t i = 0; i < nof_allocsizes_s; i++) { - for(size_t j = 0; j < nof_allocsizes_s; j++) { - size_t s = allocsizes_s[i] * allocsizes_s[j]; /* Allocates up to 8MB */ - char *ptr = os_malloc_0_s(s); /* If s == 0, os_malloc_0_s should still return a pointer */ - if(ptr) { - if(s) { - CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, s - 1)); /* malloc_0_s should memset properly */ - } - } else if (s <= 16) { - /* Failure to allocate can't be considered a test fault really, - * except that a malloc(<=16) would fail is unlikely. */ - CU_FAIL("os_malloc_0_s(<=16) returned NULL"); - } - os_free(ptr); - } - } - CU_PASS("os_malloc_0_s"); -} - -CU_Test(os_heap, os_calloc_s) -{ - for(size_t i = 0; i < nof_allocsizes_s; i++) { - for(size_t j = 0; j < nof_allocsizes_s; j++) { - size_t s = allocsizes_s[i] * allocsizes_s[j]; - char *ptr = os_calloc_s(allocsizes_s[i], allocsizes_s[j]); /* If either one is 0, os_calloc_s should still return a pointer */ - if(ptr) { - if(s) { - CU_ASSERT (ptr[0] == 0 && !memcmp(ptr, ptr + 1, s - 1)); /* malloc_0_s should memset properly */ - } - } else if (s <= 16) { - /* Failure to allocate can't be considered a test fault really, - * except that a calloc(<=16) would fail is unlikely. */ - CU_FAIL("os_calloc_s(<=16) returned NULL"); - } - os_free(ptr); - } - } - CU_PASS("os_calloc_s"); -} - -CU_Test(os_heap, os_realloc_s) -{ - char *newptr, *ptr = NULL; - size_t unchanged, s, prevs = 0; - - for(size_t i = 0; i < nof_allocsizes_s; i++) { - for(size_t j = 0; j < nof_allocsizes_s; j++) { - s = allocsizes_s[i] * allocsizes_s[j]; /* Allocates up to 8MB */ - newptr = os_realloc_s(ptr, s); - printf("%p = os_realloc_s(%p) %zu -> %zu\n", newptr, ptr, prevs, s); - if (s <= 16) { - /* Failure to allocate can't be considered a test fault really, - * except that a os_realloc_s(0 < s <=16) would fail is unlikely. */ - CU_ASSERT_PTR_NOT_EQUAL(newptr, NULL); - } - if(newptr){ - unchanged = (prevs < s) ? prevs : s; - if(unchanged) { - CU_ASSERT (newptr[0] == 1 && !memcmp(newptr, newptr + 1, unchanged - 1)); /* os_realloc_s shouldn't change memory */ - } - memset(newptr, 1, s); /* This potentially segfaults if the actual allocated block is too small */ - } - prevs = s; - ptr = newptr; - } - } - os_free(ptr); - CU_PASS("os_realloc_s"); -} diff --git a/src/os/tests/ifaddrs.c b/src/os/tests/ifaddrs.c deleted file mode 100644 index e871aaf..0000000 --- a/src/os/tests/ifaddrs.c +++ /dev/null @@ -1,192 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -/* FIXME: It's not possible to predict what network interfaces are available - on a given host. To properly test all combinations the abstracted - operating system functions must be mocked. */ - -/* FIXME: It's possible that IPv6 is available in the network stack, but - disabled in the kernel. Travis CI for example has build environments - that do not have IPv6 enabled. */ - -#ifdef OS_SOCKET_HAS_IPV6 -static int ipv6_enabled = 1; -#endif - -CU_Init(os_getifaddrs) -{ - os_osInit(); - -#ifdef OS_SOCKET_HAS_IPV6 -#ifdef __linux - FILE *fh; - const char *const *path; - static const char *const paths[] = { - "/proc/sys/net/ipv6/conf/all/disable_ipv6", - "/proc/sys/net/ipv6/conf/default/disable_ipv6", - NULL - }; - - for (path = paths; ipv6_enabled == 1 && *path != NULL; path++) { - if ((fh = fopen(*path, "r")) != NULL) { - ipv6_enabled = (fgetc(fh) == '0'); - fclose(fh); - fh = NULL; - } - } -#endif /* __linux */ -#endif /* OS_SOCKET_HAS_IPV6 */ - - return 0; -} - -CU_Clean(os_getifaddrs) -{ - os_osExit(); - return 0; -} - -/* Assume every test machine has at least one IPv4 enabled interface. This - simple test verifies an interface can at least be found and that the - IFF_LOOPBACK flags are properly set. */ -CU_Test(os_getifaddrs, ipv4) -{ - int err; - int seen = 0; - os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET, OS_AF_NULL }; - - err = os_getifaddrs(&ifa_root, afs); - CU_ASSERT_EQUAL_FATAL(err, 0); - for (ifa = ifa_root; ifa; ifa = ifa->next) { - CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET); - if (ifa->addr->sa_family == AF_INET) { - if (ifa->flags & IFF_LOOPBACK) { - CU_ASSERT(os_sockaddr_is_loopback(ifa->addr)); - } else { - CU_ASSERT(!os_sockaddr_is_loopback(ifa->addr)); - } - seen = 1; - } - } - - CU_ASSERT_EQUAL(seen, 1); - - os_freeifaddrs(ifa_root); -} - -CU_Test(os_getifaddrs, null_filter) -{ - int err; - int cnt = 0; - os_ifaddrs_t *ifa_root, *ifa; - - err = os_getifaddrs(&ifa_root, NULL); - CU_ASSERT_EQUAL_FATAL(err, 0); - for (ifa = ifa_root; ifa; ifa = ifa->next) { - CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - cnt++; - } - - CU_ASSERT(cnt > 0); - - os_freeifaddrs(ifa_root); -} - -CU_Test(os_getifaddrs, empty_filter) -{ - int err; - os_ifaddrs_t *ifa_root; - const int afs[] = { OS_AF_NULL }; - - err = os_getifaddrs(&ifa_root, afs); - CU_ASSERT_EQUAL_FATAL(err, 0); - CU_ASSERT_PTR_EQUAL(ifa_root, NULL); - - os_freeifaddrs(ifa_root); -} - -#ifdef OS_SOCKET_HAS_IPV6 -CU_Test(os_getifaddrs, ipv6) -{ - if (ipv6_enabled == 1) { - int err; - int have_ipv6 = 0; - os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET6, OS_AF_NULL }; - - err = os_getifaddrs(&ifa_root, afs); - CU_ASSERT_EQUAL_FATAL(err, 0); - for (ifa = ifa_root; ifa; ifa = ifa->next) { - CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6); - if (ifa->addr->sa_family == AF_INET6) { - have_ipv6 = 1; - /* macOS assigns a link-local address to the loopback - interface, so the loopback address must be assigned to the - loopback interface, but the loopback interface can have - addresses other than the loopback address assigned. */ - if (os_sockaddr_is_loopback(ifa->addr)) { - CU_ASSERT(ifa->flags & IFF_LOOPBACK); - } - } - } - - CU_ASSERT_EQUAL(have_ipv6, 1); - - os_freeifaddrs(ifa_root); - - CU_PASS("IPv6 enabled in test environment"); - } else { - CU_PASS("IPv6 disabled in test environment"); - } -} - -/* Assume at least one IPv4 and one IPv6 interface are available when IPv6 is - available on the platform. */ -CU_Test(os_getifaddrs, ipv4_n_ipv6) -{ - if (ipv6_enabled == 1) { - int err; - int have_ipv4 = 0; - int have_ipv6 = 0; - os_ifaddrs_t *ifa_root, *ifa; - const int afs[] = { AF_INET, AF_INET6, OS_AF_NULL }; - - err = os_getifaddrs(&ifa_root, afs); - CU_ASSERT_EQUAL_FATAL(err, 0); - for (ifa = ifa_root; ifa; ifa = ifa->next) { - CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); - CU_ASSERT(ifa->addr->sa_family == AF_INET || - ifa->addr->sa_family == AF_INET6); - if (ifa->addr->sa_family == AF_INET) { - have_ipv4 = 1; - } else if (ifa->addr->sa_family == AF_INET6) { - have_ipv6 = 1; - } - } - - CU_ASSERT_EQUAL(have_ipv4, 1); - CU_ASSERT_EQUAL(have_ipv6, 1); - - os_freeifaddrs(ifa_root); - - CU_PASS("IPv6 enabled in test environment"); - } else { - CU_PASS("IPv6 disabled in test environment"); - } -} - -#endif /* OS_SOCKET_HAS_IPV6 */ diff --git a/src/os/tests/iter.c b/src/os/tests/iter.c deleted file mode 100644 index c58287f..0000000 --- a/src/os/tests/iter.c +++ /dev/null @@ -1,239 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" -#include "assert.h" - -static int32_t one = 1; -static int32_t two = 2; -static int32_t three = 3; -static int32_t four = 4; -static int32_t five = 5; - -CU_Test(os_iter, create) -{ - os_iter *iter; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - CU_ASSERT_EQUAL(os_iterLength(iter), 0); - CU_ASSERT_PTR_NULL(os_iterObject(iter, 0)); - CU_ASSERT_PTR_NULL(os_iterTake(iter, 0)); - os_iterFree(iter, NULL); -} - -CU_Test(os_iter, prepend) -{ - os_iter *iter; - int32_t idx; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - idx = os_iterInsert(iter, &one, 0); - CU_ASSERT_EQUAL(idx, 0); - idx = os_iterInsert(iter, &two, 0); - CU_ASSERT_EQUAL(idx, 0); - idx = os_iterInsert(iter, &three, 0); - CU_ASSERT_EQUAL(idx, 0); - CU_ASSERT_EQUAL(os_iterLength(iter), 3); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 0), 3); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 1), 2); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 2), 1); - os_iterFree(iter, NULL); -} - -CU_Test(os_iter, append) -{ - os_iter *iter; - int32_t idx; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - idx = os_iterInsert(iter, &one, OS_ITER_LENGTH); - CU_ASSERT_EQUAL(idx, 0); - idx = os_iterInsert(iter, &two, OS_ITER_LENGTH); - CU_ASSERT_EQUAL(idx, 1); - idx = os_iterInsert(iter, &three, OS_ITER_LENGTH); - CU_ASSERT_EQUAL(idx, 2); - CU_ASSERT_EQUAL(os_iterLength(iter), 3); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 0), 1); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 1), 2); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 2), 3); - os_iterFree(iter, NULL); -} - -CU_Test(os_iter, insert) -{ - os_iter *iter; - int32_t idx; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - idx = os_iterInsert(iter, &one, 0); - CU_ASSERT_EQUAL(idx, 0); - idx = os_iterInsert(iter, &three, OS_ITER_LENGTH); - CU_ASSERT_EQUAL(idx, 1); - idx = os_iterInsert(iter, &two, idx); - CU_ASSERT_EQUAL(idx, 1); - idx = os_iterInsert(iter, &four, -2); - CU_ASSERT_EQUAL(idx, 1); - idx = os_iterInsert(iter, &five, -2); - CU_ASSERT_EQUAL(idx, 2); - CU_ASSERT_EQUAL(os_iterLength(iter), 5); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 0), 1); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 1), 4); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 2), 5); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 3), 2); - CU_ASSERT_EQUAL(*(int32_t *)os_iterObject(iter, 4), 3); - os_iterFree(iter, NULL); -} - -static void -iter_free_callback( - void *ptr) -{ - (*(int32_t *)ptr)++; -} - -CU_Test(os_iter, free) -{ - os_iter *iter; - int32_t cnt = 0; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - os_iterFree(iter, &iter_free_callback); - CU_ASSERT_EQUAL(cnt, 3); -} - -static void -iter_walk_callback( - void *ptr, void *arg) -{ - (*(int32_t *)ptr)++; - (*(int32_t *)arg)++; -} - -CU_Test(os_iter, walk) -{ - os_iter *iter; - int32_t cnt = 0; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - (void)os_iterInsert(iter, &cnt, OS_ITER_LENGTH); - os_iterWalk(iter, &iter_walk_callback, &cnt); - CU_ASSERT_EQUAL(cnt, 6); - os_iterFree(iter, &iter_free_callback); - CU_ASSERT_EQUAL(cnt, 9); -} - -static os_iter * -iter_new( - void) -{ - os_iter *iter; - int32_t idx; - - iter = os_iterNew(); - CU_ASSERT_PTR_NOT_NULL_FATAL(iter); - idx = os_iterInsert(iter, &one, OS_ITER_LENGTH); - CU_ASSERT_EQUAL_FATAL(idx, 0); - idx = os_iterInsert(iter, &two, OS_ITER_LENGTH); - CU_ASSERT_EQUAL_FATAL(idx, 1); - idx = os_iterInsert(iter, &three, OS_ITER_LENGTH); - CU_ASSERT_EQUAL_FATAL(idx, 2); - idx = os_iterInsert(iter, &four, OS_ITER_LENGTH); - CU_ASSERT_EQUAL_FATAL(idx, 3); - idx = os_iterInsert(iter, &five, OS_ITER_LENGTH); - CU_ASSERT_EQUAL_FATAL(idx, 4); - CU_ASSERT_EQUAL_FATAL(os_iterLength(iter), 5); - - return iter; -} - -CU_Test(os_iter, object_indices) -{ - os_iter *iter; - int32_t *num; - - iter = iter_new(); - - /* index out of range on purpose */ - OS_WARNING_MSVC_OFF(28020); - num = os_iterObject(iter, OS_ITER_LENGTH); - OS_WARNING_MSVC_ON(28020); - - CU_ASSERT_PTR_NULL(num); - num = os_iterObject(iter, (int32_t)os_iterLength(iter)); - CU_ASSERT_PTR_NULL(num); - num = os_iterObject(iter, -6); - CU_ASSERT_PTR_NULL(num); - num = os_iterObject(iter, 0); - CU_ASSERT_PTR_EQUAL(num, &one); - num = os_iterObject(iter, -5); - CU_ASSERT_PTR_EQUAL(num, &one); - num = os_iterObject(iter, (int32_t)os_iterLength(iter) - 1); - CU_ASSERT_PTR_EQUAL(num, &five); - num = os_iterObject(iter, -1); - CU_ASSERT_PTR_EQUAL(num, &five); - num = os_iterObject(iter, 2); - CU_ASSERT_PTR_EQUAL(num, &three); - num = os_iterObject(iter, -3); - CU_ASSERT_PTR_EQUAL(num, &three); - os_iterFree(iter, NULL); -} - -CU_Test(os_iter, take_indices) -{ - os_iter *iter; - int32_t *num, cnt = 0; - - iter = iter_new(); - - /* index out of range on purpose */ - OS_WARNING_MSVC_OFF(28020); - num = os_iterTake(iter, OS_ITER_LENGTH); - OS_WARNING_MSVC_ON(28020); - CU_ASSERT_PTR_NULL(num); - num = os_iterTake(iter, (int32_t)os_iterLength(iter)); - CU_ASSERT_PTR_NULL(num); - num = os_iterTake(iter, -6); - CU_ASSERT_PTR_NULL(num); - num = os_iterTake(iter, -5); - CU_ASSERT_PTR_EQUAL(num, &one); - CU_ASSERT_EQUAL(os_iterLength(iter), 4); - num = os_iterTake(iter, -3); - CU_ASSERT_PTR_EQUAL(num, &three); - CU_ASSERT_EQUAL(os_iterLength(iter), 3); - num = os_iterTake(iter, -1); - CU_ASSERT_PTR_EQUAL(num, &five); - CU_ASSERT_EQUAL(os_iterLength(iter), 2); - num = os_iterTake(iter, 1); - CU_ASSERT_PTR_EQUAL(num, &four); - CU_ASSERT_EQUAL(os_iterLength(iter), 1); - num = os_iterTake(iter, 1); - CU_ASSERT_PTR_NULL(num); - num = os_iterTake(iter, -2); - CU_ASSERT_PTR_NULL(num); - num = os_iterTake(iter, -1); - CU_ASSERT_PTR_EQUAL(num, &two); - CU_ASSERT_EQUAL(os_iterLength(iter), 0); - os_iterWalk(iter, &iter_walk_callback, &cnt); - CU_ASSERT_EQUAL(cnt, 0); - os_iterFree(iter, NULL); -} diff --git a/src/os/tests/log.c b/src/os/tests/log.c deleted file mode 100644 index dd52d1a..0000000 --- a/src/os/tests/log.c +++ /dev/null @@ -1,362 +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 - */ -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#endif /* __APPLE__ */ - -#include "CUnit/Test.h" -#include "os/os.h" - -static FILE *fh = NULL; - -#ifdef _WIN32 -#include -#include - -/* Windows does not support opening a stream to a buffer like fmemopen on - * Linux does. A temporary file that will never be flushed to disk is created - * instead. See the link below for more detail. - * - * https://blogs.msdn.microsoft.com/larryosterman/2004/04/19/its-only-temporary/ - */ - -FILE *fmemopen(void *buf, size_t size, const char *mode) -{ - int err = 0; - int fd = -1; - DWORD ret; - FILE *fh = NULL; - HANDLE hdl = INVALID_HANDLE_VALUE; - /* GetTempFileName will fail if the directory is be longer than MAX_PATH-14 - characters */ - char tmpdir[(MAX_PATH + 1) - 14]; - char tmpfile[MAX_PATH + 1]; - static const int max = 1000; - static const char pfx[] = "cyclone"; /* Up to first three are used. */ - - (void)buf; - (void)size; - - ret = GetTempPath(sizeof(tmpdir), tmpdir); - if (ret == 0) { - err = GetLastError(); - } else if (ret > sizeof(tmpdir)) { - err = ENOMEM; - } - - if (GetTempFileName(tmpdir, pfx, 0, tmpfile) == 0) { - err = GetLastError(); - assert(err != ERROR_BUFFER_OVERFLOW); - } else { - /* The combination of FILE_ATTRIBUTE_TEMPORARY and - FILE_FLAG_DELETE_ON_CLOSE hints to the filesystem that the file - should never be flushed to disk. */ - hdl = CreateFile( - tmpfile, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - CREATE_ALWAYS, - FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY, - NULL); - if (hdl == INVALID_HANDLE_VALUE) { - err = GetLastError(); - } - } - - if (err) { - errno = err; - } else { - OS_WARNING_MSVC_OFF(4996); - if ((fd = _open_osfhandle((intptr_t)hdl, _O_APPEND)) == -1) { - /* errno set by _open_osfhandle. */ - CloseHandle(hdl); - } else if ((fh = fdopen(fd, mode)) == NULL) { - /* errno set by fdopen. */ - _close(fd); /* Automatically closes underlying handle. */ - } else { - return fh; - } - OS_WARNING_MSVC_ON(4996); - } - - return NULL; -} -#endif /* _WIN32 */ - -static void count(void *ptr, const dds_log_data_t *data) -{ - (void)data; - *(int *)ptr += 1; -} - -static void copy(void *ptr, const dds_log_data_t *data) -{ - *(char **)ptr = os_strdup(data->message); -} - -static void setup(void) -{ - fh = fmemopen(NULL, 1024, "wb+"); - CU_ASSERT_PTR_NOT_NULL_FATAL(fh); -} - -static void teardown(void) -{ - (void)fclose(fh); -} - -/* By default only DDS_LC_FATAL and DDS_LC_ERROR are set. This means setting a - trace sink should not have any effect, because no trace categories are - enabled. The message should end up in the log file. */ -CU_Test(dds_log, only_log_file, .init=setup, .fini=teardown) -{ - char buf[1024], *ptr; - int cnt = 0; - size_t nbytes; - - dds_set_log_file(fh); - dds_set_trace_sink(&count, &cnt); - DDS_ERROR("foo%s\n", "bar"); - (void)fseek(fh, 0L, SEEK_SET); - nbytes = fread(buf, 1, sizeof(buf) - 1, fh); - /* At least foobar should have been printed to the log file. */ - CU_ASSERT_FATAL(nbytes > 6); - buf[nbytes] = '\0'; - ptr = strstr(buf, "foobar\n"); - CU_ASSERT_PTR_NOT_NULL(ptr); - /* No trace categories are enabled by default, verify trace callback was - not invoked. */ - CU_ASSERT_EQUAL(cnt, 0); -} - -/* Messages must be printed to the trace file if at least one trace category - is enabled. Messages must not be written twice if the trace file is the - same as the log file. */ -CU_Test(dds_log, same_file, .init=setup, .fini=teardown) -{ - char buf[1024], *ptr; - size_t nbytes; - - dds_set_log_mask(DDS_LC_ALL); - dds_set_log_file(fh); - dds_set_trace_file(fh); - DDS_ERROR("foo%s\n", "bar"); - (void)fseek(fh, 0L, SEEK_SET); - nbytes = fread(buf, 1, sizeof(buf) - 1, fh); - /* At least foobar should have been written to the trace file. */ - CU_ASSERT_FATAL(nbytes > 6); - buf[nbytes] = '\0'; - ptr = strstr(buf, "foobar\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); - /* The message should only have been printed once, verify foobar does not - occur again. */ - ptr = strstr(ptr + 1, "foobar\n"); - CU_ASSERT_PTR_NULL(ptr); -} - -/* The sinks are considered to be the same only if the callback and userdata - both are an exact match. If the userdata is different, the function should - be called twice for log messages. */ -CU_Test(dds_log, same_sink_function) -{ - int log_cnt = 0, trace_cnt = 0; - - dds_set_log_mask(DDS_LC_ALL); - dds_set_log_sink(&count, &log_cnt); - dds_set_trace_sink(&count, &trace_cnt); - DDS_ERROR("foo%s\n", "bar"); - CU_ASSERT_EQUAL(log_cnt, 1); - CU_ASSERT_EQUAL(trace_cnt, 1); -} - -CU_Test(dds_log, exact_same_sink) -{ - int cnt = 0; - - dds_set_log_mask(DDS_LC_ALL); - dds_set_log_sink(&count, &cnt); - dds_set_trace_sink(&count, &cnt); - DDS_ERROR("foo%s\n", "bar"); - CU_ASSERT_EQUAL(cnt, 1); -} - -/* The log file must be restored if the sink is unregistered, verify the log - file is not used while the sink is registered. Verify use of the log file is - restored again when the sink is unregistered. */ -CU_Test(dds_log, no_sink, .init=setup, .fini=teardown) -{ - int ret; - char buf[1024], *ptr = NULL; - size_t cnt[2] = {0, 0}; - - /* Set the destination log file and verify the message is written. */ - dds_set_log_file(fh); - DDS_ERROR("foobar\n"); - ret = fseek(fh, 0L, SEEK_SET); - CU_ASSERT_EQUAL_FATAL(ret, 0); - buf[0] = '\0'; - cnt[0] = fread(buf, 1, sizeof(buf) - 1, fh); - buf[cnt[0]] = '\0'; - ptr = strstr(buf, "foobar\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); - - /* Register a custom sink and verify it receives the message. */ - ptr = NULL; - dds_set_log_sink(©, &ptr); - DDS_ERROR("foobaz\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); - CU_ASSERT(strcmp(ptr, "foobaz\n") == 0); - os_free(ptr); - ptr = NULL; - /* Verify it has not been written to the stream. */ - ret = fseek(fh, 0L, SEEK_SET); - CU_ASSERT_EQUAL_FATAL(ret, 0); - buf[0] = '\0'; - cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh); - buf[cnt[1]] = '\0'; - ptr = strstr(buf, "foobaz\n"); - CU_ASSERT_PTR_NULL_FATAL(ptr); - - /* Unregister the custom sink and verify the default is restored. */ - dds_set_log_sink(0, NULL); - ret = fseek(fh, 0, SEEK_SET); - CU_ASSERT_EQUAL_FATAL(ret, 0); - ptr = NULL; - DDS_ERROR("foobaz\n"); - ret = fseek(fh, 0, SEEK_SET); - CU_ASSERT_PTR_NULL(ptr); - if (ptr != NULL) { - os_free(ptr); - ptr = NULL; - } - buf[0]= '\0'; - cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh); -#ifdef _WIN32 - /* Write on Windows appends. */ - CU_ASSERT_EQUAL(cnt[1], cnt[0] * 2); -#else - CU_ASSERT_EQUAL(cnt[1], cnt[0]); -#endif - buf[cnt[1]] = '\0'; - ptr = strstr(buf, "foobaz\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(ptr); -} - -/* A newline terminates the message. Until that a newline is encountered, the - messages must be concatenated in the buffer. The newline is replaced by a - NULL byte if it is flushed to a sink. */ -CU_Test(dds_log, newline_terminates) -{ - char *msg = NULL; - - dds_set_log_sink(©, &msg); - DDS_ERROR("foo"); - CU_ASSERT_PTR_NULL_FATAL(msg); - DDS_ERROR("bar"); - CU_ASSERT_PTR_NULL_FATAL(msg); - DDS_ERROR("baz\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(msg); - CU_ASSERT(strcmp(msg, "foobarbaz\n") == 0); - os_free(msg); -} - -/* Nothing must be written unless a category is enabled. */ -CU_Test(dds_log, disabled_categories_discarded) -{ - char *msg = NULL; - - dds_set_log_sink(©, &msg); - DDS_INFO("foobar\n"); - CU_ASSERT_PTR_NULL_FATAL(msg); - dds_set_log_mask(DDS_LC_FATAL | DDS_LC_ERROR | DDS_LC_INFO); - DDS_INFO("foobar\n"); - CU_ASSERT_PTR_NOT_NULL_FATAL(msg); - CU_ASSERT(strcmp(msg, "foobar\n") == 0); - os_free(msg); -} - - -static os_cond cond; -static os_mutex mutex; - -struct arg { - os_cond *cond; - os_mutex *mutex; - os_time stamp; - os_time pause; -}; - -static void dummy(void *ptr, const dds_log_data_t *data) -{ - (void)ptr; - (void)data; -} - -static void block(void *ptr, const dds_log_data_t *data) -{ - (void)data; - struct arg *arg = (struct arg *)ptr; - os_mutexLock(arg->mutex); - arg->stamp = os_timeGet(); - os_condBroadcast(arg->cond); - os_mutexUnlock(arg->mutex); - - os_nanoSleep(arg->pause); -} - -static uint32_t run(void *ptr) -{ - (void)ptr; - - DDS_ERROR("foobar\n"); - - return 0; -} - -/* Log and trace sinks can be changed at runtime. However, the operation must - be synchronous! Verify the dds_set_log_sink blocks while other threads - reside in the log or trace sinks. */ -CU_Test(dds_log, synchronous_sink_changes) -{ - struct arg arg; - os_time diff, stamp; - os_threadId tid; - os_threadAttr tattr; - os_result res; - - os_mutexInit(&mutex); - os_condInit(&cond, &mutex); - (void)memset(&arg, 0, sizeof(arg)); - arg.mutex = &mutex; - arg.cond = &cond; - arg.pause.tv_sec = 0; - arg.pause.tv_nsec = 1000000; - - os_mutexLock(&mutex); - dds_set_log_sink(&block, &arg); - os_threadAttrInit(&tattr); - res = os_threadCreate(&tid, "foobar", &tattr, &run, &arg); - CU_ASSERT_EQUAL_FATAL(res, os_resultSuccess); - os_condWait(&cond, &mutex); - dds_set_log_sink(dummy, NULL); - stamp = os_timeGet(); - - CU_ASSERT(os_timeCompare(arg.stamp, stamp) == -1); - diff = os_timeSub(stamp, arg.stamp); - CU_ASSERT(os_timeCompare(arg.pause, diff) == -1); -} diff --git a/src/os/tests/mutex.c b/src/os/tests/mutex.c deleted file mode 100644 index 6a03be1..0000000 --- a/src/os/tests/mutex.c +++ /dev/null @@ -1,300 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -#ifdef __VXWORKS__ -# ifdef _WRS_KERNEL -# define FORCE_SCHEDULING() taskDelay(1) -# else -# define FORCE_SCHEDULING() sched_yield() -# endif -#else -# define FORCE_SCHEDULING() -#endif - -#define BUSYLOOP (100000) -#define MAX_LOOPS (20) - -typedef struct { - os_mutex global_mutex; - os_threadId global_data; - int nolock_corrupt_count; - int nolock_loop_count; - int lock_corrupt_count; - int lock_loop_count; - int trylock_corrupt_count; - int trylock_loop_count; - int trylock_busy_count; - int stop; -} shared_data; - -os_threadAttr mutex_os_threadAttr; -os_threadId mutex_os_threadId[4]; -os_time delay1 = { 5, 0 }; -os_time pdelay = { 1, 0 }; -char buffer[512]; -int supported_resultBusy; -int loop; -static shared_data *sd; -char filePath[255]; - -uint32_t concurrent_lock_thread (_In_opt_ void *arg) -{ - int j; - int loopc = 0; - int printed = 0; - - while (!sd->stop) - { - if (arg) os_mutexLock (&sd->global_mutex); - sd->global_data = os_threadIdSelf(); - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP; j++); - if (os_threadIdToInteger(sd->global_data) != - os_threadIdToInteger(os_threadIdSelf())) - { - if (arg) - { - sd->lock_corrupt_count++; - } - else - { - sd->nolock_corrupt_count++; - } - if (!printed) { - printed++; - } - } - if (arg) - { - sd->lock_loop_count++; - os_mutexUnlock (&sd->global_mutex); - } - else - { - sd->nolock_loop_count++; - } - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP; j++); - loopc++; - } - return 0; -} - -uint32_t concurrent_trylock_thread (_In_opt_ void *arg) -{ - int j; - int loopc = 0; - int printed = 0; - os_result result; - - while (!sd->stop) - { - if (arg) - { - while ((result = os_mutexTryLock (&sd->global_mutex)) - != os_resultSuccess) - { - if (result == os_resultBusy) - { - sd->trylock_busy_count++; - } - FORCE_SCHEDULING(); - } - } - sd->global_data = os_threadIdSelf(); - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP; j++); - if (os_threadIdToInteger(sd->global_data) != - os_threadIdToInteger(os_threadIdSelf())) - { - if (arg) - { - sd->trylock_corrupt_count++; - } - else - { - sd->nolock_corrupt_count++; - } - if (!printed) { - printed++; - } - } - if (arg) - { - sd->trylock_loop_count++; - os_mutexUnlock (&sd->global_mutex); - } - else - { - sd->nolock_loop_count++; - } - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP; j++); - loopc++; - } - return 0; -} - -CU_Init(os_mutex) -{ - printf ( "Run os_mutex_Initialize\n" ); - - os_osInit(); - - return 0; -} - -CU_Clean(os_mutex) -{ - printf("Run os_mutex_Cleanup\n"); - - os_osExit(); - - return 0; -} - -/* This test only checks a single-threaded use-case; just API availability.*/ -CU_Test(os_mutex, basic) -{ - os_mutex m; - os_result r; - - printf("Starting os_mutex_basic\n"); - - os_mutexInit(&m); - os_mutexLock(&m); - os_mutexUnlock(&m); - r = os_mutexLock_s(&m); - CU_ASSERT_EQUAL(r, os_resultSuccess); /* Failure can't be forced */ - os_mutexUnlock(&m); - os_mutexDestroy(&m); - printf("Ending os_mutex_basic\n"); -} - -CU_Test(os_mutex, lock, false) -{ - /* Test critical section access with locking and PRIVATE scope */ - printf ("Starting tc_os_mutex_lock_001\n"); - os_threadAttrInit (&mutex_os_threadAttr); - - FORCE_SCHEDULING(); - - delay1.tv_sec = 3; - printf ("Testing for %d.%9.9d seconds without lock\n", delay1.tv_sec, delay1.tv_nsec); - sd->stop = 0; - sd->nolock_corrupt_count = 0; - sd->nolock_loop_count = 0; - sd->lock_corrupt_count = 0; - sd->lock_loop_count = 0; - sd->trylock_corrupt_count = 0; - sd->trylock_loop_count = 0; - sd->trylock_busy_count = 0; - os_threadCreate (&mutex_os_threadId[0], "thr0", &mutex_os_threadAttr, &concurrent_lock_thread, NULL); - os_threadCreate (&mutex_os_threadId[1], "thr1", &mutex_os_threadAttr, &concurrent_lock_thread, NULL); - os_threadCreate (&mutex_os_threadId[2], "thr2", &mutex_os_threadAttr, &concurrent_trylock_thread, NULL); - os_threadCreate (&mutex_os_threadId[3], "thr3", &mutex_os_threadAttr, &concurrent_trylock_thread, NULL); - os_nanoSleep (delay1); - sd->stop = 1; - os_threadWaitExit (mutex_os_threadId[0], NULL); - os_threadWaitExit (mutex_os_threadId[1], NULL); - os_threadWaitExit (mutex_os_threadId[2], NULL); - os_threadWaitExit (mutex_os_threadId[3], NULL); - printf ("All threads stopped\n"); - - delay1.tv_sec = 3; - printf ("Testing for %d.%9.9d seconds with lock\n", delay1.tv_sec, delay1.tv_nsec); - sd->stop = 0; - sd->nolock_corrupt_count = 0; - sd->nolock_loop_count = 0; - sd->lock_corrupt_count = 0; - sd->lock_loop_count = 0; - sd->trylock_corrupt_count = 0; - sd->trylock_loop_count = 0; - sd->trylock_busy_count = 0; - os_threadCreate (&mutex_os_threadId[0], "thr0", &mutex_os_threadAttr, &concurrent_lock_thread, (void *)1); - os_threadCreate (&mutex_os_threadId[1], "thr1", &mutex_os_threadAttr, &concurrent_lock_thread, (void *)1); - os_threadCreate (&mutex_os_threadId[2], "thr2", &mutex_os_threadAttr, &concurrent_trylock_thread, (void *)1); - os_threadCreate (&mutex_os_threadId[3], "thr3", &mutex_os_threadAttr, &concurrent_trylock_thread, (void *)1); - os_nanoSleep (delay1); - sd->stop = 1; - os_threadWaitExit (mutex_os_threadId[0], NULL); - os_threadWaitExit (mutex_os_threadId[1], NULL); - os_threadWaitExit (mutex_os_threadId[2], NULL); - os_threadWaitExit (mutex_os_threadId[3], NULL); - printf ("All threads stopped\n"); - - CU_ASSERT (sd->lock_corrupt_count == 0 || sd->lock_loop_count > 0); - - /* Lock mutex with PRIVATE scope and Success result */ - printf ("Starting tc_os_mutex_lock_002\n"); - os_mutexLock (&sd->global_mutex); //Cannot be checked - os_mutexUnlock (&sd->global_mutex); - - /* Lock mutex with PRIVATE scope and Fail result */ - printf ("Starting tc_os_mutex_lock_003\n"); - printf ("N.A - Failure cannot be forced\n"); - - /* mutexLock_s with PRIVATE scope and Success result */ - printf ("Starting tc_os_mutex_lock_004\n"); - CU_ASSERT (os_mutexLock_s (&sd->global_mutex) == os_resultSuccess); - os_mutexUnlock (&sd->global_mutex); - - printf ("Ending os_mutex_lock\n"); -} - -CU_Test(os_mutex, trylock, false) -{ - os_result result; - - /* Test critical section access with trylocking and PRIVATE scope */ - printf ("Starting os_mutex_trylock_001\n"); - CU_ASSERT (sd->trylock_corrupt_count == 0 || sd->trylock_loop_count > 0); - - /* TryLock mutex with PRIVATE scope and Success result */ - printf ("Starting os_mutex_trylock_002\n"); - result = os_mutexTryLock (&sd->global_mutex); - CU_ASSERT (result == os_resultSuccess); - - /* TryLock mutex with PRIVATE scope and Busy result */ - printf ("Starting os_mutex_trylock_003\n"); - #if defined(__VXWORKS__) && !defined(_WRS_KERNEL) - printf ("N.A - Mutexes are recursive on VxWorks RTP so this test is disabled\n"); - #endif - - result = os_mutexTryLock (&sd->global_mutex); - CU_ASSERT (result == os_resultBusy); - - printf ("Ending os_mutex_trylock\n"); -} - -CU_Test(os_mutex, destroy, false) -{ - /* Deinitialize mutex with PRIVATE scope and Success result */ - printf ("Starting os_mutex_destroy_001\n"); - os_mutexDestroy(&sd->global_mutex); // Cannot be checked directly - Success is assumed - - /* Deinitialize mutex with PRIVATE scope and Fail result */ - printf ("Starting os_mutex_destroy_002\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending os_mutex_destroy\n"); -} diff --git a/src/os/tests/once.c b/src/os/tests/once.c deleted file mode 100644 index 7a04397..0000000 --- a/src/os/tests/once.c +++ /dev/null @@ -1,167 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -/* Suite os_once*/ -CU_Init(os_once) -{ - printf("Run os_once_Initialize\n"); - - os_osInit(); - - return 0; -} - -CU_Clean(os_once) -{ - printf("Run os_once_Cleanup\n"); - - os_osExit(); - - return 0; -} - -static uint32_t counter; - -static void once_func(void) -{ - counter++; - printf("Counter increased to %u\n", counter); -} - -/* This test only checks a single-threaded use-case; mostly API availability and mere basics.*/ -CU_Test(os_once, basic) -{ - static os_once_t init = OS_ONCE_T_STATIC_INIT; - - printf("Starting os_once_basic\n"); - - os_once(&init, &once_func); - CU_ASSERT(counter == 1); - os_once(&init, &once_func); - CU_ASSERT(counter == 1); - - printf("Ending os_once_basic\n"); -} - -/* Update atomically, so that a failing os_once can be detected and isn't potentially lost due to a race. */ -static os_atomic_uint32_t counter1 = OS_ATOMIC_UINT32_INIT(0); -static void once1_func(void) -{ - os_time delay = { .tv_sec = 0,.tv_nsec = 250000000 }; /* 250ms */ - os_nanoSleep(delay); - printf("%"PRIxMAX": Counter 1 increased to %u\n", os_threadIdToInteger(os_threadIdSelf()), os_atomic_inc32_nv(&counter1)); -} - -/* Update atomically, so that a failing os_once can be detected and isn't potentially lost due to a race. */ -static os_atomic_uint32_t counter2 = OS_ATOMIC_UINT32_INIT(0); -static void once2_func(void) -{ - os_time delay = { .tv_sec = 0, .tv_nsec = 500000000 }; /* 500ms */ - os_nanoSleep(delay); - printf("%"PRIxMAX": Counter 2 increased to %u\n", os_threadIdToInteger(os_threadIdSelf()), os_atomic_inc32_nv(&counter2)); -} - -#define OS_ONCE_NUM_THREADS (20) -#define OS_ONCE_STATE_STARTUP (0) -#define OS_ONCE_STATE_GO (1) - -struct os_once_parallel { - os_mutex m; - os_cond c; - os_atomic_uint32_t flag; - os_atomic_uint32_t started; - os_once_t init1; - os_once_t init2; -}; - -static uint32_t -os_once_parallel_thr( - void *args) -{ - const os_time sched_delay = { .tv_sec = 0,.tv_nsec = 25000000 }; /* 25ms */ - const os_time poll_delay = { .tv_sec = 0,.tv_nsec = 5000000 }; /* 5ms */ - struct os_once_parallel *state = (struct os_once_parallel *)args; - bool done = false; - bool started = false; - - while (!done) { - switch (os_atomic_ld32(&state->flag)) { - case OS_ONCE_STATE_STARTUP: - if (!started && (os_atomic_inc32_nv(&state->started) == OS_ONCE_NUM_THREADS)) { - printf("%"PRIxMAX": Started. Signalling GO.\n", os_threadIdToInteger(os_threadIdSelf())); - os_atomic_st32(&state->flag, OS_ONCE_STATE_GO); - os_mutexLock(&state->m); - os_condBroadcast(&state->c); - os_mutexUnlock(&state->m); - os_nanoSleep(sched_delay); - } - else { - if(!started ) printf("%"PRIxMAX": Started. Awaiting GO.\n", os_threadIdToInteger(os_threadIdSelf())); - os_mutexLock(&state->m); - (void) os_condTimedWait(&state->c, &state->m, &poll_delay); - os_mutexUnlock(&state->m); - } - started = true; - break; - case OS_ONCE_STATE_GO: - os_once(&state->init1, &once1_func); - os_once(&state->init2, &once2_func); - /* FALLS THROUGH */ - default: - done = true; - break; - } - } - - return 0; -} - -CU_Test(os_once, parallel) -{ - os_threadId threads[OS_ONCE_NUM_THREADS]; - struct os_once_parallel state = { - .init1 = OS_ONCE_T_STATIC_INIT, - .init2 = OS_ONCE_T_STATIC_INIT, - .started = OS_ATOMIC_UINT32_INIT(0), - .flag = OS_ATOMIC_UINT32_INIT(OS_ONCE_STATE_STARTUP) - }; - os_threadAttr tattr; - unsigned i; - - printf("Starting os_once_parallel\n"); - - os_mutexInit(&state.m); - os_condInit(&state.c, &state.m); - - os_threadAttrInit(&tattr); - for (i = 0; i < OS_ONCE_NUM_THREADS; i++) { - char thrname[16]; - (void) snprintf(thrname, sizeof thrname, "thr%u", i); - os_threadCreate(&threads[i], thrname, &tattr, &os_once_parallel_thr, &state); - printf("%"PRIxMAX": Started thread '%s' with thread-id %" PRIxMAX "\n", os_threadIdToInteger(os_threadIdSelf()), thrname, os_threadIdToInteger(threads[i])); - } - - for (; i != 0; i--) { - os_threadWaitExit(threads[i - 1], NULL); - printf("%"PRIxMAX": Thread with thread-id %" PRIxMAX " stopped.\n", os_threadIdToInteger(os_threadIdSelf()), os_threadIdToInteger(threads[i - 1])); - } - - CU_ASSERT(os_atomic_ld32(&counter1) == 1); - CU_ASSERT(os_atomic_ld32(&counter2) == 1); - - os_condDestroy(&state.c); - os_mutexDestroy(&state.m); - - printf("Ending os_once_parallel\n"); -} diff --git a/src/os/tests/rwlock.c b/src/os/tests/rwlock.c deleted file mode 100644 index b36d144..0000000 --- a/src/os/tests/rwlock.c +++ /dev/null @@ -1,576 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -#ifdef __VXWORKS__ -# ifdef _WRS_KERNEL -# define FORCE_SCHEDULING() taskDelay(1) -# else -# define FORCE_SCHEDULING() sched_yield() -# endif -#else -# define FORCE_SCHEDULING() -#endif - -#define ENABLE_TRACING 0 -#define BUSYLOOP (100000) -#define MAX_LOOPS (20) -#define RWLOCK_THREADS 12 - -os_time rwlock_delay = { 0, 500 }; - -typedef struct Par { - int lock; - int index; - int read_access; - int concurrent_read_access; -} Par; - -typedef struct { - os_rwlock global_rwlock; - os_threadId global_data; - os_threadId read_thread[RWLOCK_THREADS]; - int read_corrupt_count; - int write_corrupt_count; - int concurrent_read_access; - int concurrent_write_access; - int tryread_corrupt_count; - int trywrite_corrupt_count; - int concurrent_tryread_access; - int concurrent_trywrite_access; - int tryread_busy_count; - int trywrite_busy_count; - int stop; -} shared_data; - -os_threadAttr rwlock_os_threadAttr; -os_threadId rwlock_os_threadId[RWLOCK_THREADS]; -static int i; -char buffer[512]; -int supported_resultBusy; -int loop; -static shared_data sd; - -uint32_t concurrent_write_thread (_In_ void *arg) -{ - struct Par *par = (struct Par *)arg; - os_threadId myid = os_threadIdSelf(); - int printed = 0; - - while (!sd.stop) { - if (par->lock) { - os_rwlockWrite (&sd.global_rwlock); - } - sd.global_data = myid; - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - if (os_threadIdToInteger(sd.global_data) != os_threadIdToInteger(myid)) { - sd.write_corrupt_count++; - if (!printed) { - /* printf ("Critical section corrupted during write [%d]\n", par->index); */ - printed++; - } - } - sd.concurrent_write_access++; - if (par->lock) { - os_rwlockUnlock (&sd.global_rwlock); - } - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - } - return 0; -} - -uint32_t concurrent_read_thread (_In_ void *arg) -{ - int j; - os_threadId prevId; - struct Par *par = (struct Par *)arg; - int printed = 0; - - while (!sd.stop) { - if (par->lock) { - os_rwlockRead (&sd.global_rwlock); - } - sd.read_thread[par->index] = os_threadIdSelf(); - par->read_access++; - prevId = sd.global_data; - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP/2; j++) { - if (os_threadIdToInteger(sd.global_data) != - os_threadIdToInteger(prevId)) { - sd.read_corrupt_count++; - if (!printed) { - /* printf ("Critical section corrupted during read [%d]\n", par->index); */ - printed++; - } - prevId = sd.global_data; - } - - FORCE_SCHEDULING(); - } - if (os_threadIdToInteger(sd.read_thread[0]) || - os_threadIdToInteger(sd.read_thread[1]) || - os_threadIdToInteger(sd.read_thread[2]) || - os_threadIdToInteger(sd.read_thread[3]) || - os_threadIdToInteger(sd.read_thread[4]) || - os_threadIdToInteger(sd.read_thread[5]) || - os_threadIdToInteger(sd.read_thread[6]) || - os_threadIdToInteger(sd.read_thread[7]) || - os_threadIdToInteger(sd.read_thread[8]) || - os_threadIdToInteger(sd.read_thread[9]) || - os_threadIdToInteger(sd.read_thread[10]) || - os_threadIdToInteger(sd.read_thread[11])) { - par->concurrent_read_access++; - } - sd.concurrent_read_access++; - if (par->lock) { - os_rwlockUnlock (&sd.global_rwlock); - } - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - } - return 0; -} - -uint32_t concurrent_trywrite_thread (_In_ void *arg) -{ - struct Par *par = (struct Par *)arg; - os_result result; - os_threadId myid = os_threadIdSelf(); - int printed = 0; - - while (!sd.stop) { - if (par->lock) { - while ((result = os_rwlockTryWrite (&sd.global_rwlock)) != os_resultSuccess) { - if (result == os_resultBusy) { - sd.trywrite_busy_count++; - } - - FORCE_SCHEDULING(); - } - } - sd.global_data = os_threadIdSelf(); - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - if (os_threadIdToInteger(sd.global_data) != os_threadIdToInteger(myid)) { - sd.trywrite_corrupt_count++; - if (!printed) { - /* printf ("Critical section corrupted during trywrite [%d]\n", par->index); */ - printed++; - } - } - sd.concurrent_trywrite_access++; - if (par->lock) { - os_rwlockUnlock (&sd.global_rwlock); - } - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - } - return 0; -} - -uint32_t concurrent_tryread_thread (_In_ void *arg) -{ - int j; - os_threadId prevId; - struct Par *par = (struct Par *)arg; - os_result result; - int printed = 0; - - while (!sd.stop) { - if (par->lock) { - while ((result = os_rwlockTryRead (&sd.global_rwlock)) != os_resultSuccess) { - if (result == os_resultBusy) { - sd.tryread_busy_count++; - } - - FORCE_SCHEDULING(); - } - } - sd.read_thread[par->index] = os_threadIdSelf(); - par->read_access++; - prevId = sd.global_data; - - FORCE_SCHEDULING(); - - for (j = 0; j < BUSYLOOP/2; j++) { - if (os_threadIdToInteger(sd.global_data) != - os_threadIdToInteger(prevId)) { - sd.tryread_corrupt_count++; - if (!printed) { - /* printf ("Critical section corrupted during read [%d]\n", par->index); */ - printed++; - } - prevId = sd.global_data; - } - - FORCE_SCHEDULING(); - } - if (os_threadIdToInteger(sd.read_thread[0]) || - os_threadIdToInteger(sd.read_thread[1]) || - os_threadIdToInteger(sd.read_thread[2]) || - os_threadIdToInteger(sd.read_thread[3]) || - os_threadIdToInteger(sd.read_thread[4]) || - os_threadIdToInteger(sd.read_thread[5]) || - os_threadIdToInteger(sd.read_thread[6]) || - os_threadIdToInteger(sd.read_thread[7]) || - os_threadIdToInteger(sd.read_thread[8]) || - os_threadIdToInteger(sd.read_thread[9]) || - os_threadIdToInteger(sd.read_thread[10]) || - os_threadIdToInteger(sd.read_thread[11])) { - par->concurrent_read_access++; - } - sd.concurrent_tryread_access++; - if (par->lock) { - os_rwlockUnlock (&sd.global_rwlock); - } - - FORCE_SCHEDULING(); - - os_nanoSleep( rwlock_delay ); - } - return 0; -} - -CU_Init(os_rwlock) -{ - int result = 0; - os_osInit(); - printf("Run os_rwlock_Initialize\n"); - #ifdef OS_LINUX_RWLOCK_H149C - supported_resultBusy = 1; - #else - supported_resultBusy = 0; - #endif - - return result; -} - -CU_Clean(os_rwlock) -{ - int result = 0; - - printf("Run os_rwlock_Cleanup\n"); - os_osExit(); - return result; -} - -CU_Test(os_rwlock, init) -{ - /* Initilalize reader/writer lock with PRIVATE scope and Success result */ - printf ("Starting os_rwlock_init_001\n"); - os_rwlockInit (&sd.global_rwlock); - - /* Initilalize reader/writer lock with Fail result */ - printf ("Starting os_rwlock_init_001\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending os_rwlock_init\n"); -} - -CU_Test(os_rwlock, read, false) -{ - os_time rdelay = { 3, 0 }; - struct Par par[RWLOCK_THREADS]; - /* Test critical section access without locking to show problem */ - printf ("Starting os_rwlock_read_001\n"); - rdelay.tv_sec = 3; - printf ("Testing for %d.%9.9d seconds without lock\n", rdelay.tv_sec, rdelay.tv_nsec); - sd.read_corrupt_count = 0; - sd.write_corrupt_count = 0; - sd.concurrent_read_access = 0; - sd.concurrent_write_access = 0; - sd.tryread_corrupt_count = 0; - sd.trywrite_corrupt_count = 0; - sd.concurrent_tryread_access = 0; - sd.concurrent_trywrite_access = 0; - sd.tryread_busy_count = 0; - sd.trywrite_busy_count = 0; - sd.stop = 0; - for (i = 0; i < RWLOCK_THREADS; i++) { - par[i].concurrent_read_access = 0; - par[i].read_access = 0; - par[i].lock = 0; - par[i].index = i; - } - os_threadAttrInit (&rwlock_os_threadAttr); - os_threadCreate (&rwlock_os_threadId[0], "thr0", &rwlock_os_threadAttr, &concurrent_write_thread, (void *)&par[0]); - os_threadCreate (&rwlock_os_threadId[1], "thr1", &rwlock_os_threadAttr, &concurrent_write_thread, (void *)&par[1]); - os_threadCreate (&rwlock_os_threadId[2], "thr2", &rwlock_os_threadAttr, &concurrent_read_thread, (void *)&par[2]); - os_threadCreate (&rwlock_os_threadId[3], "thr3", &rwlock_os_threadAttr, &concurrent_read_thread, (void *)&par[3]); - os_threadCreate (&rwlock_os_threadId[4], "thr4", &rwlock_os_threadAttr, &concurrent_trywrite_thread, (void *)&par[4]); - os_threadCreate (&rwlock_os_threadId[5], "thr5", &rwlock_os_threadAttr, &concurrent_trywrite_thread, (void *)&par[5]); - os_threadCreate (&rwlock_os_threadId[6], "thr6", &rwlock_os_threadAttr, &concurrent_tryread_thread, (void *)&par[6]); - os_threadCreate (&rwlock_os_threadId[7], "thr7", &rwlock_os_threadAttr, &concurrent_tryread_thread, (void *)&par[7]); - os_nanoSleep (rdelay); - sd.stop = 1; - os_threadWaitExit (rwlock_os_threadId[0], NULL); - os_threadWaitExit (rwlock_os_threadId[1], NULL); - os_threadWaitExit (rwlock_os_threadId[2], NULL); - os_threadWaitExit (rwlock_os_threadId[3], NULL); - os_threadWaitExit (rwlock_os_threadId[4], NULL); - os_threadWaitExit (rwlock_os_threadId[5], NULL); - os_threadWaitExit (rwlock_os_threadId[6], NULL); - os_threadWaitExit (rwlock_os_threadId[7], NULL); - - printf ("All threads stopped\n"); - for (i = 2; i < 4; i++) { - printf ("total read access %d, concurrent read access %d for thread %d\n", - par[i].read_access, par[i].concurrent_read_access, i); - } - for (i = 6; i < 8; i++) { - printf ("total try read access %d, concurrent try read access %d for thread %d\n", - par[i].read_access, par[i].concurrent_read_access, i); - } - printf ("read_corrupt_count = %d\n", sd.read_corrupt_count); - printf ("write_corrupt_count = %d\n", sd.write_corrupt_count); - printf ("tryread_corrupt_count = %d\n", sd.tryread_corrupt_count); - printf ("trywrite_corrupt_count = %d\n", sd.trywrite_corrupt_count); - printf ("concurrent_read_access = %d\n", sd.concurrent_read_access); - printf ("concurrent_write_access = %d\n", sd.concurrent_write_access); - printf ("concurrent_tryread_access = %d\n", sd.concurrent_tryread_access); - printf ("concurrent_trywrite_access = %d\n", sd.concurrent_trywrite_access); - - snprintf (buffer, sizeof(buffer), "Corrupt counter = %d, Loop counter is %d", - sd.read_corrupt_count + sd.write_corrupt_count + sd.tryread_corrupt_count + sd.trywrite_corrupt_count, - sd.concurrent_read_access + sd.concurrent_write_access + sd.concurrent_tryread_access + sd.concurrent_trywrite_access); - - CU_ASSERT((sd.read_corrupt_count > 0 || - sd.write_corrupt_count > 0 || - sd.tryread_corrupt_count > 0 || - sd.trywrite_corrupt_count > 0) && - sd.concurrent_read_access > 0 && - sd.concurrent_write_access > 0 && - sd.concurrent_tryread_access > 0 && - sd.concurrent_trywrite_access > 0); - - /* Test critical section READ access with locking and PRIVATE scope */ - printf ("Starting os_rwlock_read_002\n"); - rdelay.tv_sec = 3; - printf ("Testing for %d.%9.9d seconds with lock\n", rdelay.tv_sec, rdelay.tv_nsec); - sd.read_corrupt_count = 0; - sd.write_corrupt_count = 0; - sd.concurrent_read_access = 0; - sd.concurrent_write_access = 0; - sd.tryread_corrupt_count = 0; - sd.trywrite_corrupt_count = 0; - sd.concurrent_tryread_access = 0; - sd.concurrent_trywrite_access = 0; - sd.tryread_busy_count = 0; - sd.trywrite_busy_count = 0; - sd.stop = 0; - for (i = 0; i < RWLOCK_THREADS; i++) { - par[i].concurrent_read_access = 0; - par[i].read_access = 0; - par[i].lock = 1; - par[i].index = i; - } - os_threadAttrInit (&rwlock_os_threadAttr); - os_threadCreate (&rwlock_os_threadId[0], "thr0", &rwlock_os_threadAttr, &concurrent_write_thread, (void *)&par[0]); - os_threadCreate (&rwlock_os_threadId[1], "thr1", &rwlock_os_threadAttr, &concurrent_write_thread, (void *)&par[1]); - os_threadCreate (&rwlock_os_threadId[2], "thr2", &rwlock_os_threadAttr, &concurrent_read_thread, (void *)&par[2]); - os_threadCreate (&rwlock_os_threadId[3], "thr3", &rwlock_os_threadAttr, &concurrent_read_thread, (void *)&par[3]); - os_threadCreate (&rwlock_os_threadId[4], "thr4", &rwlock_os_threadAttr, &concurrent_trywrite_thread, (void *)&par[4]); - os_threadCreate (&rwlock_os_threadId[5], "thr5", &rwlock_os_threadAttr, &concurrent_trywrite_thread, (void *)&par[5]); - os_threadCreate (&rwlock_os_threadId[6], "thr6", &rwlock_os_threadAttr, &concurrent_tryread_thread, (void *)&par[6]); - os_threadCreate (&rwlock_os_threadId[7], "thr7", &rwlock_os_threadAttr, &concurrent_tryread_thread, (void *)&par[7]); - os_nanoSleep (rdelay); - sd.stop = 1; - os_threadWaitExit (rwlock_os_threadId[0], NULL); - os_threadWaitExit (rwlock_os_threadId[1], NULL); - os_threadWaitExit (rwlock_os_threadId[2], NULL); - os_threadWaitExit (rwlock_os_threadId[3], NULL); - os_threadWaitExit (rwlock_os_threadId[4], NULL); - os_threadWaitExit (rwlock_os_threadId[5], NULL); - os_threadWaitExit (rwlock_os_threadId[6], NULL); - os_threadWaitExit (rwlock_os_threadId[7], NULL); - - printf ("All threads stopped\n"); - for (i = 2; i < 4; i++) { - printf ("total read access %d, concurrent read access %d for thread %d\n", - par[i].read_access, par[i].concurrent_read_access, i); - } - for (i = 6; i < 8; i++) { - printf ("total try read access %d, concurrent try read access %d for thread %d\n", - par[i].read_access, par[i].concurrent_read_access, i); - } - - snprintf (buffer, sizeof(buffer), "Corrupt read counter = %d, Read loop counter is %d", sd.read_corrupt_count, sd.concurrent_read_access); - CU_ASSERT (sd.read_corrupt_count == 0 && sd.concurrent_read_access > 0); - - /* Test read on rwlock with PRIVATE scope and Success result & not locked */ - printf ("Starting os_rwlock_read_003\n"); - os_rwlockRead (&sd.global_rwlock); // Cannot be checked - os_rwlockUnlock (&sd.global_rwlock); - - /* Test read on rwlock with PRIVATE scope and Success result & locked by read */ - printf ("Starting os_rwlock_read_004\n"); - printf ("N.A - Not implemented\n"); - - /* Test read on rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_read_005\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending os_rwlock_read\n"); -} - -CU_Test(os_rwlock, write, false) -{ - /* Test critical section WRITE access with locking and PRIVATE scope */ - printf ("Starting os_rwlock_write_001\n"); - - snprintf (buffer, sizeof(buffer), "Corrupt write counter = %d, Write loop counter is %d", sd.write_corrupt_count, sd.concurrent_write_access); - CU_ASSERT (sd.write_corrupt_count == 0 && sd.concurrent_write_access > 0); - - /* Test write on rwlock with PRIVATE scope and Success result */ - printf ("Starting os_rwlock_write_002\n"); - os_rwlockWrite (&sd.global_rwlock); //Cannot be checked - os_rwlockUnlock (&sd.global_rwlock); - - /* Test write on rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_write_003\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending tc_rwlockWrite\n"); -} - -CU_Test(rwlock, tryread, false) -{ - os_result result; - /* Test critical section READ access with trylocking and PRIVATE scope */ - printf ("Starting os_rwlock_tryread_001\n"); - - snprintf (buffer, sizeof(buffer), "Corrupt tryread counter = %d, Tryread loop counter is %d, Busy counter = %d", sd.tryread_corrupt_count, sd.concurrent_tryread_access, sd.tryread_busy_count); - CU_ASSERT (sd.tryread_corrupt_count == 0 && sd.concurrent_tryread_access > 0); - - /* Test try read on rwlock with PRIVATE scope and Success result & not locked */ - printf ("Starting os_rwlock_tryread_002\n"); - result = os_rwlockTryRead (&sd.global_rwlock); - CU_ASSERT (result == os_resultSuccess); - os_rwlockUnlock (&sd.global_rwlock); - - /* Test try read on rwlock with PRIVATE scope and Success result & locked by read */ - printf ("Starting os_rwlock_tryread_003\n"); - printf ("N.A - Not implemented\n"); - - /* Test try read on rwlock with PRIVATE scope and Busy result & locked by write */ - printf ("Starting os_rwlock_tryread_004\n"); - printf ("N.A - Not implemented\n"); - - /* Test try read on rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_tryread_005\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending os_rwlock_tryread\n"); -} - -CU_Test(os_rwlock, trywrite, false) -{ - os_result result; - /* Test critical section WRITE access with trylocking and PRIVATE scope */ - printf ("Starting os_rwlock_trywrite_001\n"); - - snprintf (buffer, sizeof(buffer), "Corrupt trywrite counter = %d, Trywrite loop counter is %d, Busy counter = %d", sd.trywrite_corrupt_count, sd.concurrent_trywrite_access, sd.trywrite_busy_count); - CU_ASSERT (sd.trywrite_corrupt_count == 0 && sd.concurrent_trywrite_access > 0); - - /* Test try write on rwlock with PRIVATE scope and Success result */ - printf ("Starting os_rwlock_trywrite_002\n"); - result = os_rwlockTryWrite (&sd.global_rwlock); - CU_ASSERT (result == os_resultSuccess); - os_rwlockUnlock (&sd.global_rwlock); - - /* Test try write on rwlock with PRIVATE scope and Busy result & locked by read */ - printf ("Starting os_rwlock_trywrite_003\n"); - printf ("N.A - Not implemented\n"); - - /* Test try write on rwlock with PRIVATE scope and Busy result & locked by write */ - printf ("Starting os_rwlock_trywrite_004\n"); - printf ("N.A - Not implemented\n"); - - /* Test try write on rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_trywrite_005\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending os_rwlock_trywrite\n"); -} - -CU_Test(os_rwlock, unlock, false) -{ - os_result result; - /* Unlock rwlock with PRIVATE scope and Success result and claimed with read */ - printf ("Starting os_rwlock_unlock_001\n"); - os_rwlockRead (&sd.global_rwlock); - os_rwlockUnlock (&sd.global_rwlock); //Cannot be checked - - /* Unlock rwlock with PRIVATE scope and Success result and claimed with try read */ - printf ("Starting os_rwlock_unlock_002\n"); - result = os_rwlockTryRead (&sd.global_rwlock); - CU_ASSERT (result == os_resultSuccess); - os_rwlockUnlock (&sd.global_rwlock); - - /* Unlock rwlock with PRIVATE scope and Success result and claimed with write */ - printf ("Starting os_rwlock_unlock_003\n"); - os_rwlockWrite (&sd.global_rwlock); - os_rwlockUnlock (&sd.global_rwlock); //Cannot be checked - - /* Unlock rwlock with PRIVATE scope and Success result and claimed with try write */ - printf ("Starting os_rwlock_unlock_004\n"); - result = os_rwlockTryWrite (&sd.global_rwlock); - CU_ASSERT (result == os_resultSuccess); - os_rwlockUnlock (&sd.global_rwlock); - - /* Unlock rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_unlock_005\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending tc_rwlockUnlock\n"); -} - -CU_Test(os_rwlock, destroy, false) -{ - /* Deinitialize rwlock with PRIVATE scope and Success result */ - printf ("Starting os_rwlock_destroy_001\n"); - os_rwlockDestroy (&sd.global_rwlock); //Cannot be checked - - /* Deinitialize rwlock with PRIVATE scope and Fail result */ - printf ("Starting os_rwlock_destroy_002\n"); - printf ("N.A - Failure cannot be forced\n"); - - printf ("Ending tc_rwlockDestroy\n"); -} - -CU_Test(os_rwlock, destroy_shared) -{ - os_rwlock mylock; - - os_rwlockInit(&mylock); - os_rwlockRead(&mylock); - os_rwlockUnlock(&mylock); - /* This test used to assert on a debug-build on Windows. Failure can't be forced, but if - * someone adds the naively sensible assert again, this test won't run on a debug-build. */ - os_rwlockDestroy(&mylock); - CU_PASS("os_rwlockDestroy succeeds after releasing a shared lock"); -} diff --git a/src/os/tests/socket.c b/src/os/tests/socket.c deleted file mode 100644 index 7fe52c7..0000000 --- a/src/os/tests/socket.c +++ /dev/null @@ -1,167 +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 - */ -#include -#include -#include -#include - -#include "CUnit/Theory.h" - -#include "os/os.h" - -OS_WARNING_MSVC_OFF(4305) -#if OS_ENDIANNESS == OS_BIG_ENDIAN -static const struct sockaddr_in ipv4_loopback = - { .sin_family = AF_INET, .sin_addr = { .s_addr = 0x7f000001 } }; -#else -static const struct sockaddr_in ipv4_loopback = - { .sin_family = AF_INET, .sin_addr = { .s_addr = 0x0100007f } }; -#endif /* OS_ENDIANNESS */ -OS_WARNING_MSVC_ON(4305) - -#if OS_SOCKET_HAS_IPV6 -static const struct sockaddr_in6 ipv6_loopback = - { .sin6_family = AF_INET6, .sin6_addr = IN6ADDR_LOOPBACK_INIT }; -#endif - -static void setup(void) -{ - os_osInit(); -} - -static void teardown(void) -{ - os_osExit(); -} - -CU_Test(os_sockaddrfromstr, bad_family) -{ - int err; - os_sockaddr_storage sa; - err = os_sockaddrfromstr(AF_UNSPEC, "127.0.0.1", &sa); - CU_ASSERT_EQUAL(err, EAFNOSUPPORT); -} - -static void sockaddrfromstr_test(char *str, int af, int ret) -{ - int err; - os_sockaddr_storage ss; - err = os_sockaddrfromstr(af, str, &ss); - CU_ASSERT_EQUAL(err, ret); - if (err == 0) { - CU_ASSERT_EQUAL(ss.ss_family, af); - } -} - -CU_TheoryDataPoints(os_sockaddrfromstr, ipv4) = { - CU_DataPoints(char *, "127.0.0.1", "0.0.0.0", "nip"), - CU_DataPoints(int, AF_INET, AF_INET, AF_INET), - CU_DataPoints(int, 0, 0, EINVAL) -}; - -CU_Theory((char *str, int af, int ret), os_sockaddrfromstr, ipv4, .init=setup, .fini=teardown) -{ - sockaddrfromstr_test(str, af, ret); -} - -#if OS_SOCKET_HAS_IPV6 -CU_TheoryDataPoints(os_sockaddrfromstr, ipv6) = { - CU_DataPoints(char *, "127.0.0.1", "::1", "::1", "::", "nip"), - CU_DataPoints(int, AF_INET6, AF_INET6, AF_INET, AF_INET6, AF_INET6), - CU_DataPoints(int, EINVAL, 0, EINVAL, 0, EINVAL) -}; - -CU_Theory((char *str, int af, int ret), os_sockaddrfromstr, ipv6, .init=setup, .fini=teardown) -{ - sockaddrfromstr_test(str, af, ret); -} -#endif /* OS_SOCKET_HAS_IPV6 */ - -CU_Test(os_sockaddrtostr, bad_sockaddr, .init=setup, .fini=teardown) -{ - int err; - char buf[128] = { 0 }; - os_sockaddr_in sa; - memcpy(&sa, &ipv4_loopback, sizeof(ipv4_loopback)); - sa.sin_family = AF_UNSPEC; - err = os_sockaddrtostr(&sa, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, EAFNOSUPPORT); -} - -CU_Test(os_sockaddrtostr, no_space, .init=setup, .fini=teardown) -{ - int err; - char buf[1] = { 0 }; - err = os_sockaddrtostr(&ipv4_loopback, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, ENOSPC); -} - -CU_Test(os_sockaddrtostr, ipv4) -{ - int err; - char buf[128] = { 0 }; - err = os_sockaddrtostr(&ipv4_loopback, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, 0); - CU_ASSERT_STRING_EQUAL(buf, "127.0.0.1"); -} - -CU_Test(os_sockaddrtostr, ipv6) -{ - int err; - char buf[128] = { 0 }; - err = os_sockaddrtostr(&ipv6_loopback, buf, sizeof(buf)); - CU_ASSERT_EQUAL(err, 0); - CU_ASSERT_STRING_EQUAL(buf, "::1"); -} - -#if OS_SOCKET_HAS_DNS -static void gethostbyname_test(char *name, int af, int ret) -{ - int err; - os_hostent_t *hent = NULL; - err = os_gethostbyname(name, af, &hent); - CU_ASSERT_EQUAL(err, ret); - if (err == 0) { - CU_ASSERT_FATAL(hent->naddrs > 0); - if (af != AF_UNSPEC) { - CU_ASSERT_EQUAL(hent->addrs[0].ss_family, af); - } - } - os_free(hent); -} - -CU_TheoryDataPoints(os_gethostbyname, ipv4) = { - CU_DataPoints(char *, "", "127.0.0.1", "127.0.0.1"), - CU_DataPoints(int, AF_UNSPEC, AF_INET, AF_UNSPEC), - CU_DataPoints(int, OS_HOST_NOT_FOUND, 0, 0) -}; - -CU_Theory((char *name, int af, int ret), os_gethostbyname, ipv4, .init=setup, .fini=teardown) -{ - gethostbyname_test(name, af, ret); -} - -#if OS_SOCKET_HAS_IPV6 -/* Lookup of IPv4 address and specifying AF_INET6 is not invalid as it may - return an IPV4-mapped IPv6 address. */ -CU_TheoryDataPoints(os_gethostbyname, ipv6) = { - CU_DataPoints(char *, "::1", "::1", "::1"), - CU_DataPoints(int, AF_INET, AF_INET6, AF_UNSPEC), - CU_DataPoints(int, OS_HOST_NOT_FOUND, 0, 0) -}; - -CU_Theory((char *name, int af, int ret), os_gethostbyname, ipv6, .init=setup, .fini=teardown) -{ - gethostbyname_test(name, af, ret); -} -#endif /* OS_SOCKET_HAS_IPV6 */ -#endif /* OS_SOCKET_HAS_DNS */ diff --git a/src/os/tests/stdlib.c b/src/os/tests/stdlib.c deleted file mode 100644 index 8125816..0000000 --- a/src/os/tests/stdlib.c +++ /dev/null @@ -1,230 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -#define ENABLE_TRACING 0 - -static int -vsnprintfTest( - const char *format, - ...) -{ - va_list varargs; - int result = 0; - char description[10]; - va_start(varargs, format); - memset(description, 0, sizeof(description)); - - result = os_vsnprintf(description, sizeof(description)-1, format, varargs); - va_end(varargs); - return result; -} - -CU_Init(os_stdlib) -{ - int result = 0; - os_osInit(); - return result; -} - -CU_Clean(os_stdlib) -{ - os_osExit(); - return 0; -} - -CU_Test(os_stdlib, gethostname) -{ - int res; - os_result os_res; - char os_cpu[200]; - char cpu[200]; - - printf ("Starting os_stdlib_gethostname_001\n"); - os_cpu[0] = '\0'; - os_res = os_gethostname (os_cpu, sizeof(os_cpu)); - CU_ASSERT (os_res == os_resultSuccess); - - cpu[0] = '\0'; - res = gethostname (cpu, sizeof(cpu)); - CU_ASSERT (res == 0); - - printf ("Starting os_stdlib_gethostname_002\n"); - os_res = os_gethostname (os_cpu, strlen(os_cpu)-1); - CU_ASSERT (os_res == os_resultFail); - printf ("Ending os_stdlib_gethostname\n"); -} - -CU_Test(os_stdlib, putenv) -{ - os_result os_res; - - printf ("Starting os_stdlib_putenv_001\n"); - os_res = os_putenv ("ABCDE=FGHIJ"); - CU_ASSERT (os_res == os_resultSuccess); - CU_ASSERT (strcmp (os_getenv("ABCDE"), "FGHIJ") == 0); - printf ("Ending os_stdlib_putenv\n"); -} - -CU_Test(os_stdlib, getenv) -{ - const char *env; - os_result res; - - printf ("Starting os_stdlib_getenv_001\n"); - - res = os_putenv("ABCDE=FGHIJ"); - CU_ASSERT(res == os_resultSuccess); - - env = os_getenv("ABCDE"); - CU_ASSERT(env != NULL); - if (env != NULL) { - CU_ASSERT(strcmp(env, "FGHIJ") == 0); - } - printf ("Starting os_stdlib_getenv_002\n"); - CU_ASSERT (os_getenv("XXABCDEXX") == NULL ); - printf ("Ending os_stdlib_getenv\n"); -} - -CU_Test(os_stdlib, vsnprintf) -{ - printf ("Starting os_stdlib_vsnprintf_001\n"); - CU_ASSERT (vsnprintfTest("%s","test") == 4); - CU_ASSERT (vsnprintfTest("%d",12) == 2); - CU_ASSERT (vsnprintfTest("hello %s","world") == 11); - - printf ("Ending os_stdlib_vsnprintf\n"); -} - -CU_Test(os_stdlib, strtok_r) -{ - char * res; - char *strtok_r_ts1; - char *saveptr; - - printf ("Starting os_stdlib_strtok_r_001\n"); - strtok_r_ts1= os_strdup("123,234"); - res = os_strtok_r( strtok_r_ts1, ",", &saveptr ); - CU_ASSERT (strcmp(res, "123") == 0); - - printf ("Starting os_stdlib_strtok_r_002\n"); - res = os_strtok_r( NULL, ",", &saveptr ); - CU_ASSERT (strcmp(res, "234") == 0); - - printf ("Starting os_stdlib_strtok_r_003\n"); - res = os_strtok_r( NULL, ",", &saveptr ); - CU_ASSERT (res == NULL); - os_free(strtok_r_ts1); - - printf ("Starting os_stdlib_strtok_r_004\n"); - strtok_r_ts1= os_strdup(",;,123abc,,456,:,"); - res = os_strtok_r( strtok_r_ts1, ",;", &saveptr ); - CU_ASSERT (strcmp(res, "123abc") == 0); - - printf ("Starting os_stdlib_strtok_r_005\n"); - res = os_strtok_r( NULL, ",", &saveptr ); - CU_ASSERT (strcmp(res, "456") == 0); - - printf ("Starting os_stdlib_strtok_r_006\n"); - res = os_strtok_r( NULL, ",:", &saveptr ); - CU_ASSERT (res == NULL); - free(strtok_r_ts1); - - printf ("Starting os_stdlib_strtok_r_007\n"); - strtok_r_ts1= os_strdup(",,,123,,456,789,,,"); - res = os_strtok_r( strtok_r_ts1, ",", &saveptr ); - CU_ASSERT (strcmp(res, "123") == 0); - - printf ("Starting os_stdlib_strtok_r_008\n"); - res = os_strtok_r( NULL, ",", &saveptr ); - CU_ASSERT (strcmp(res, "456") == 0); - - printf ("Starting os_stdlib_strtok_r_009\n"); - res = os_strtok_r( NULL, ",", &saveptr ); - CU_ASSERT (strcmp(res, "789") == 0); - - printf ("Starting os_stdlib_strtok_r_010\n"); - res = os_strtok_r( NULL, ",:", &saveptr ); - CU_ASSERT (res == NULL); - free(strtok_r_ts1); - - printf ("Ending os_stdlib_strtok_r\n"); -} - -CU_Test(os_stdlib, index) -{ - char * res; - char *index_ts1; - printf ("Starting os_stdlib_index_001\n"); - index_ts1 = "abc"; - res = os_index( index_ts1, 'a' ); - CU_ASSERT (res == index_ts1); - - printf ("Starting os_stdlib_index_002\n"); - res = os_index( index_ts1, 'c' ); - CU_ASSERT (res == &index_ts1[2]); - - printf ("Starting os_stdlib_index_003\n"); - index_ts1 = "abcdefghij"; - res = os_index( index_ts1, 'f' ); - CU_ASSERT (res == &index_ts1[5]); - - printf ("Starting os_stdlib_index_004\n"); - res = os_index( index_ts1, 'k' ); - CU_ASSERT (res == NULL); - - printf ("Ending os_stdlib_index\n"); -} - -CU_Test(os_stdlib, getopt) -{ - int c = 0; - int argc = 3; - char *argv001[] = {"", "-a", "-b"}; - char *argv002[] = {"", "-c", "foo"}; - char *argv003[] = {"", "-d"}; - - /* Check correct functioning of os_getopt */ - printf ("Starting os_stdlib_getopt_001\n"); - c = os_getopt(argc, argv001, "abc:"); - CU_ASSERT (c == 'a'); - c = os_getopt(argc, argv001, "abc:"); - CU_ASSERT (c == 'b'); - c = os_getopt(argc, argv001, "abc:"); - CU_ASSERT (c == -1); - - /* Check correct functioning of os_set_optind and os_get_optind */ - printf ("Starting os_stdlib_getopt_002\n"); - os_set_optind(1); - CU_ASSERT (os_get_optind() == 1); - - /* Check correct functioning of os_get_optarg */ - printf ("Starting os_stdlib_getopt_003\n"); - c = os_getopt (argc, argv002, "c:"); - CU_ASSERT (c == 'c'); - CU_ASSERT (strcmp(os_get_optarg(), "foo") == 0); - c = os_getopt(argc, argv002, "c:"); - CU_ASSERT (c == -1); - - /* Check correct functioning of os_set_opterr, os_get_opterr and os_get_optopt */ - printf ("Starting os_stdlib_getopt_004\n"); - argc = 2; - os_set_optind(1); - os_set_opterr(0); - CU_ASSERT(os_get_opterr() == 0) - c = os_getopt (argc, argv003, "c:"); - CU_ASSERT (c == '?'); - CU_ASSERT (os_get_optopt() == 'd'); - - printf ("Ending os_stdlib_getopt\n"); -} diff --git a/src/os/tests/strcasecmp.c b/src/os/tests/strcasecmp.c deleted file mode 100644 index a6f9035..0000000 --- a/src/os/tests/strcasecmp.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "os/os.h" -#include "CUnit/Theory.h" - -typedef enum { eq, lt, gt } eq_t; - -CU_TheoryDataPoints(os_strcasecmp, basic) = { - CU_DataPoints(const char *, "a", "aa", "a", "a", "A", "a", "b", "a", "B", "A", "", "a"), - CU_DataPoints(const char *, "a", "a", "aa", "A", "a", "b", "a", "b", "A", "B", "a", ""), - CU_DataPoints(eq_t, eq, gt, lt, eq, eq, lt, gt, lt, gt, lt, lt, gt) -}; - -CU_Theory((const char *s1, const char *s2, eq_t e), os_strcasecmp, basic) -{ - int r = os_strcasecmp(s1, s2); - CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); -} - -CU_TheoryDataPoints(os_strncasecmp, basic) = { - CU_DataPoints(const char *, "a", "aa", "a", "A", "a", "b", "a", "B", "A", "", "a"), - CU_DataPoints(const char *, "a", "a", "aa", "a", "A", "a", "b", "A", "B", "a", ""), - CU_DataPoints(size_t, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1), - CU_DataPoints(eq_t, eq, gt, lt, eq, eq, gt, lt, gt, lt, lt, gt) -}; - -CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, basic) -{ - int r = os_strncasecmp(s1, s2, n); - CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); -} - -CU_TheoryDataPoints(os_strncasecmp, empty) = { - CU_DataPoints(const char *, "a", "", "a", "", "a", ""), - CU_DataPoints(const char *, "", "a", "", "a", "", "a"), - CU_DataPoints(size_t, 1, 1, 0, 0, 2, 2), - CU_DataPoints(eq_t, gt, lt, eq, eq, gt, lt) -}; - -CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, empty) -{ - int r = os_strncasecmp(s1, s2, n); - CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); -} - -CU_TheoryDataPoints(os_strncasecmp, length) = { - CU_DataPoints(const char *, "aBcD", "AbCX", "aBcD", "AbCX", "aBcD"), - CU_DataPoints(const char *, "AbCX", "aBcD", "AbCX", "aBcD", "AbCd"), - CU_DataPoints(size_t, 3, 3, 4, 4, 5, 5), - CU_DataPoints(eq_t, eq, eq, lt, gt, eq, eq) -}; - -CU_Theory((const char *s1, const char *s2, size_t n, eq_t e), os_strncasecmp, length) -{ - int r = os_strncasecmp(s1, s2, n); - CU_ASSERT((e == eq && r == 0) || (e == lt && r < 0) || (e == gt && r > 0)); -} - diff --git a/src/os/tests/strlcpy.c b/src/os/tests/strlcpy.c deleted file mode 100644 index a2c8257..0000000 --- a/src/os/tests/strlcpy.c +++ /dev/null @@ -1,80 +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 - */ -#include -#include - -#include "os/os.h" -#include "CUnit/Theory.h" - -CU_TheoryDataPoints(os_strlcpy, dest_size) = { - CU_DataPoints(char *, "foo", "foo", "foo", "foo", "foo", "", "", ""), - CU_DataPoints(size_t, 0, 1, 3, 4, 5, 0, 1, 2) -}; - -CU_Theory((char *src, size_t size), os_strlcpy, dest_size) -{ - char dest[] = "................"; - size_t len, srclen; - - srclen = strlen(src); - len = os_strlcpy(dest, src, size); - CU_ASSERT_EQUAL(len, srclen); - if (size > 0) { - if ((size - 1) < len) { - len = size - 1; - } - CU_ASSERT_EQUAL(dest[len], '\0'); - CU_ASSERT_EQUAL(dest[len+1], '.'); - CU_ASSERT((strncmp(dest, src, len) == 0)); - } else { - CU_ASSERT_EQUAL(dest[0], '.'); - } -} - -CU_TheoryDataPoints(os_strlcat, dest_size) = { - CU_DataPoints(char *, "", "", "", "", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "", "", "foo", "foo", "foo"), - CU_DataPoints(char *, "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "bar", "", "", "", "", ""), - CU_DataPoints(size_t, 0, 1, 3, 4, 0, 1, 3, 4, 5, 6, 7, 0, 1, 3, 4, 5) -}; - -CU_Theory((char *seed, char *src, size_t size), os_strlcat, dest_size) -{ - char dest[] = "................"; - size_t len, seedlen, srclen; - seedlen = strlen(seed); - srclen = strlen(src); - memcpy(dest, seed, seedlen); - dest[seedlen] = '\0'; - - len = os_strlcat(dest, src, size); - CU_ASSERT_EQUAL(len, (seedlen + srclen)); - if (size > 0) { - char foobar[sizeof(dest)]; - - if ((size - 1) <= seedlen) { - len = seedlen; - } else if ((size - 1) <= len) { - len = size - 1; - } - - CU_ASSERT_EQUAL(dest[len], '\0'); - - if (seedlen < (size - 1)) { - CU_ASSERT_EQUAL(dest[len+1], '.'); - } - - (void)snprintf(foobar, len+1, "%s%s", seed, src); - CU_ASSERT((strncmp(dest, foobar, len) == 0)); - } else { - CU_ASSERT((strcmp(dest, seed) == 0)); - } -} diff --git a/src/os/tests/strtoll.c b/src/os/tests/strtoll.c deleted file mode 100644 index 3859ec3..0000000 --- a/src/os/tests/strtoll.c +++ /dev/null @@ -1,321 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" - -long long ll; -unsigned long long ull; -const char *str; -char *ptr; -char buf[100]; -char str_llmin[100]; -char str_llmax[100]; -char str_ullmax[100]; -char str_llrange[100]; -char str_ullrange[100]; - -char str_xllmin[99], str_xllmax[99]; - -/* Really test with the maximum values supported on a platform, not some - made up number. */ -long long llmin = OS_MIN_INTEGER(long long); -long long llmax = OS_MAX_INTEGER(long long); -unsigned long long ullmax = OS_MAX_INTEGER(unsigned long long); - -CU_Init(os_str_convert) -{ - int result = 0; - os_osInit(); - printf("Run os_str_convert_Initialize\n"); - - (void)snprintf (str_llmin, sizeof(str_llmin), "%lld", llmin); - (void)snprintf (str_llmax, sizeof(str_llmax), "%lld", llmax); - (void)snprintf (str_llrange, sizeof(str_llrange), "%lld1", llmax); - (void)snprintf (str_ullmax, sizeof(str_ullmax), "%llu", ullmax); - (void)snprintf (str_ullrange, sizeof(str_ullrange), "%llu1", ullmax); - (void)snprintf (str_xllmin, sizeof(str_xllmin), "-%llx", llmin); - (void)snprintf (str_xllmax, sizeof(str_xllmax), "+%llx", llmax); - - return result; -} - -CU_Clean(os_str_convert) -{ - int result = 0; - - printf("Run os_str_convert_Cleanup\n"); - os_osExit(); - return result; -} - -CU_Test(os_str_convert, strtoll) -{ - printf ("Starting os_strtoll_001a\n"); - str = "gibberish"; - ll = os_strtoll(str, &ptr, 0); - CU_ASSERT (ll == 0 && ptr == str); - - printf ("Starting os_strtoll_001b\n"); - str = "+gibberish"; - ll = os_strtoll(str, &ptr, 0); - CU_ASSERT (ll == 0 && ptr == str); - - printf ("Starting os_strtoll_001c\n"); - str = "-gibberish"; - ll = os_strtoll(str, &ptr, 0); - CU_ASSERT (ll == 0 && ptr == str); - - printf ("Starting os_strtoll_001d\n"); - str = "gibberish"; - ptr = NULL; - errno=0; - ll = os_strtoll(str, &ptr, 36); - CU_ASSERT (ll == 46572948005345 && errno == 0 && ptr && *ptr == '\0'); - - printf ("Starting os_strtoll_001e\n"); - str = "1050505055"; - ptr = NULL; - errno = 0; - ll = os_strtoll(str, &ptr, 37); - CU_ASSERT (ll == 0LL && errno == EINVAL && ptr == str); - - printf ("Starting os_strtoll_001f\n"); - str = " \t \n 1050505055"; - ll = os_strtoll(str, NULL, 10); - CU_ASSERT (ll == 1050505055LL); - - printf ("Starting os_strtoll_001g\n"); - str = " \t \n -1050505055"; - ptr = NULL; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == -1050505055LL); - - printf ("Starting os_strtoll_001h\n"); - str = " \t \n - \t \n 1050505055"; - ptr = NULL; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == 0LL && ptr == str); - - printf ("Starting os_strtoll_002a\n"); - str = "10x"; - ptr = NULL; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == 10LL && ptr && *ptr == 'x'); - - printf ("Starting os_strtoll_002b\n"); - str = "+10x"; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == 10LL && ptr && *ptr == 'x'); - - printf ("Starting os_strtoll_002c\n"); - str = "-10x"; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == -10LL && ptr && *ptr == 'x'); - - printf ("Starting os_strtoll_002d\n"); - str = (const char *)str_llmax; - ll = os_strtoll(str, NULL, 10); - CU_ASSERT (ll == llmax); - - printf ("Starting os_strtoll_002e\n"); - str = (const char *)str_llmin; - ll = os_strtoll(str, NULL, 10); - CU_ASSERT (ll == llmin); - - printf ("Starting os_strtoll_002f\n"); - str = (const char *)str_llrange; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == llmax && *ptr == '1'); - - printf ("Starting os_strtoll_003a\n"); - str = "0x100"; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == 0x100LL); - - printf ("Starting os_strtoll_003b\n"); - str = "0X100"; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == 0x100LL); - - printf ("Starting os_strtoll_003c\n"); - str = "0x1DEFCAB"; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == 0x1DEFCABLL); - - printf ("Starting os_strtoll_003d\n"); - str = "0x1defcab"; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == 0x1DEFCABLL); - - printf ("Starting os_strtoll_003e\n"); - str = (char *)str_xllmin; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == llmin); - - printf ("Starting os_strtoll_003f\n"); - str = (char *)str_xllmax; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == llmax); - - printf ("Starting os_strtoll_003g\n"); - str = "0x100"; - ll = os_strtoll(str, NULL, 0); - CU_ASSERT (ll == 0x100LL); - - printf ("Starting os_strtoll_003h\n"); - str = "100"; - ll = os_strtoll(str, NULL, 16); - CU_ASSERT (ll == 0x100LL); - - printf ("Starting os_strtoll_003i\n"); - /* calling os_strtoll with \"%s\" and base 10, expected result 0 */ - str = "0x100"; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT (ll == 0 && ptr && *ptr == 'x'); - - printf ("Starting os_strtoll_003j\n"); - /* calling os_strtoll with \"%s\" and base 0, expected result 256 */ - str = "0x100g"; - ll = os_strtoll(str, &ptr, 0); - CU_ASSERT (ll == 256 && ptr && *ptr == 'g'); - - printf ("Starting os_strtoll_004a\n"); - str = "0100"; - ll = os_strtoll(str, NULL, 0); - CU_ASSERT(ll == 64LL); - - printf ("Starting os_strtoll_004b\n"); - str = "0100"; - ll = os_strtoll(str, NULL, 8); - CU_ASSERT(ll == 64LL); - - printf ("Starting os_strtoll_004c\n"); - str = "100"; - ll = os_strtoll(str, NULL, 8); - CU_ASSERT(ll == 64LL); - - printf ("Starting os_strtoll_004d\n"); - /* calling os_strtoll with \"%s\" and base 10, expected result 100 */ - str = "0100"; - ll = os_strtoll(str, &ptr, 10); - CU_ASSERT(ll == 100); - - printf ("Starting os_strtoll_004e\n"); - /* calling os_strtoll with \"%s\" and base 0, expected result 64 */ - str = "01008"; - ll = os_strtoll(str, &ptr, 8); - CU_ASSERT(ll == 64LL && ptr && *ptr == '8'); - - printf ("Starting os_strtoll_004f\n"); - str = "00001010"; - ll = os_strtoll(str, NULL, 2); - CU_ASSERT(ll == 10LL); - - printf ("Ending os_strtoll\n"); -} - -CU_Test(os_str_convert, strtoull) -{ - printf ("Starting os_strtoull_001a\n"); - str = "0xffffffffffffffff"; - ull = os_strtoull(str, NULL, 0); - CU_ASSERT(ull == ullmax); - - printf ("Starting os_strtoull_001b\n"); - str = "-1"; - ull = os_strtoull(str, NULL, 0); - CU_ASSERT(ull == ullmax); - - printf ("Starting os_strtoull_001c\n"); - str = "-2"; - ull = os_strtoull(str, NULL, 0); - CU_ASSERT(ull == (ullmax - 1)); - - printf ("Ending os_strtoull\n"); -} - -CU_Test(os_str_convert, atoll) -{ - printf ("Starting os_atoll_001\n"); - str = "10"; - ll = os_atoll(str); - CU_ASSERT(ll == 10); - - printf ("Ending os_atoll\n"); -} - -CU_Test(os_str_convert, atoull) -{ - printf ("Starting os_atoull_001\n"); - str = "10"; - ull = os_atoull(str); - CU_ASSERT(ull == 10); - - printf ("Ending tc_os_atoull\n"); -} - -CU_Test(os_str_convert, lltostr) -{ - printf ("Starting os_lltostr_001\n"); - ll = llmax; - ptr = os_lltostr(ll, buf, 0, NULL); - CU_ASSERT(ptr == NULL); - - printf ("Starting os_lltostr_002\n"); - /* calling os_lltostr with %lld with buffer size of 5, expected result \"5432\" */ - ll = 54321; - ptr = os_lltostr(ll, buf, 5, NULL); - CU_ASSERT(strcmp(ptr, "5432") == 0); - - printf ("Starting os_lltostr_003a\n"); - ll = llmax; - ptr = os_lltostr(ll, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, str_llmax) == 0); - - printf ("Starting os_lltostr_003b\n"); - ll = llmin; - ptr = os_lltostr(ll, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, str_llmin) == 0); - - printf ("Starting os_lltostr_004\n"); - ll = 1; - ptr = os_lltostr(ll, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, "1") == 0); - - printf ("Starting os_lltostr_005\n"); - ll = 0; - ptr = os_lltostr(ll, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, "0") == 0); - - printf ("Starting os_lltostr_006\n"); - ll = -1; - ptr = os_lltostr(ll, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, "-1") == 0); - - printf ("Ending os_lltostr\n"); -} - -CU_Test(os_str_convert, ulltostr) -{ - printf ("Starting os_ulltostr_001\n"); - ull = ullmax; - ptr = os_ulltostr(ull, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, str_ullmax) == 0); - - printf ("Starting os_ulltostr_002\n"); - ull = 0ULL; - ptr = os_ulltostr(ull, buf, sizeof(buf), NULL); - CU_ASSERT(strcmp(ptr, "0") == 0); - - printf ("Ending os_ulltostr\n"); -} - diff --git a/src/os/tests/thread.c b/src/os/tests/thread.c deleted file mode 100644 index 471d273..0000000 --- a/src/os/tests/thread.c +++ /dev/null @@ -1,698 +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 - */ -#include "CUnit/Test.h" -#include "os/os.h" -#include "assert.h" - -#define ENABLE_TRACING 0 - -char arg_result[30]; -int threadCalled; -int startCallbackCount; -int stopCallbackCount; -void *returnval; - -static void -sleepMsec(int32_t msec) -{ - os_time delay; - - assert(msec > 0); - assert(msec < 1000); - - delay.tv_sec = 0; - delay.tv_nsec = msec*1000*1000; - - os_nanoSleep(delay); -} - -uint32_t new_thread (_In_ void *args) -{ - (void)snprintf (arg_result, sizeof (arg_result), "%s", (char *)args); - sleepMsec (500); - return 0; -} - -static uintmax_t thread_id_from_thread; - -uint32_t threadId_thread (_In_opt_ void *args) -{ - if (args != NULL) { - sleepMsec (500); - } - thread_id_from_thread = os_threadIdToInteger (os_threadIdSelf ()); - return (uint32_t)thread_id_from_thread; /* Truncates potentially; just used for checking passing a result-value. */ -} - -uint32_t get_threadExit_thread (void *args) -{ - os_threadId * threadId = args; - uint32_t id; - (void)os_threadWaitExit (*threadId, &id); - return id; -} - -uint32_t threadMemory_thread (_In_opt_ void *args) -{ - OS_UNUSED_ARG(args); - - /* Check os_threadMemMalloc with success result for child thread */ - printf("Starting os_threadMemMalloc_003\n"); - returnval = os_threadMemMalloc (3, 100); - CU_ASSERT (returnval != NULL); - - /* Check os_threadMemGet for child thread and non allocated index */ - printf("Starting os_threadMemGet_003\n"); - returnval = os_threadMemGet (OS_THREAD_WARNING); - CU_ASSERT (returnval == NULL); - - /* Check os_threadMemGet for child thread and allocated index */ - printf("Starting os_threadMemGet_004\n"); - returnval = os_threadMemGet (3); - CU_ASSERT (returnval != NULL); - - /* Check os_threadMemFree for child thread and non allocated index */ - printf("Starting os_threadMemFree_003\n"); - os_threadMemFree (OS_THREAD_WARNING); - returnval = os_threadMemGet (OS_THREAD_WARNING); - CU_ASSERT (returnval == NULL); - - /* Check os_threadMemFree for child thread and allocated index */ - printf("Starting os_threadMemFree_004\n"); - os_threadMemFree (3); - returnval = os_threadMemGet (3); - CU_ASSERT (returnval == NULL); - - return 0; -} - -CU_Init(os_thread) -{ - int result = 0; - os_osInit(); - printf("Run os_thread_Initialize\n"); - - return result; -} - -CU_Clean(os_thread) -{ - int result = 0; - - printf("Run os_thread_Cleanup\n"); - os_osExit(); - return result; -} - -CU_Test(os_thread, create) -{ - int result; - os_result osResult; - os_threadId thread_os_threadId; - os_threadAttr thread_os_threadAttr; -#ifndef WIN32 - int result_int; -#endif - - /* Check os_threadCreate with Success result\n\t\t - (check thread creation and check argument passing) */ - printf ("Starting os_thread_create_001\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate1", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - taskDelay(1 * sysClkRateGet()); -#endif - osResult = os_threadWaitExit (thread_os_threadId, NULL); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - result = strcmp (arg_result, "os_threadCreate"); - CU_ASSERT (result == 0); - if (result == 0) - printf("Thread created and argument correctly passed.\n"); - else - printf("Thread created but argument incorrectly passed.\n"); - } else { - printf("os_threadCreate success, failed os_threadWaitExit.\n"); - } - } - - /* Check os_threadCreate with Failed result */ - printf ("Starting os_thread_create_002\n"); - printf ("N.A - Failure cannot be forced\n"); - - /* Check os_threadCreate with scheduling class SCHED_DEFAULT */ - printf ("Starting s_thread_create_003\n"); - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_DEFAULT; - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate3", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - -#if !(defined _WRS_KERNEL || defined WIN32) - if (osResult == os_resultSuccess) { - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int != 0) { - printf ("pthread_getschedparam failed"); - } else { - CU_ASSERT (policy == SCHED_OTHER); - } - osResult = os_threadWaitExit (thread_os_threadId, NULL); - CU_ASSERT (osResult == os_resultSuccess); - } else { - printf ("os_threadCreate failed.\n"); - } -#endif - -/* SCHED_TIMESHARE not supported by vxworks kernel */ -#ifndef _WRS_KERNEL - /* Check os_threadCreate with scheduling class SCHED_TIMESHARE */ - printf ("Starting os_thread_create_004\n"); - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_TIMESHARE; - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate4", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - if (osResult == os_resultSuccess) { -#ifndef WIN32 - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int != 0) { - printf ("pthread_getschedparam failed"); - } else { - CU_ASSERT (policy == SCHED_OTHER); - } -#endif /* WIN32 */ - - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed.\n"); - } -#endif - - /* Check os_threadCreate with scheduling class SCHED_REALTIME */ - printf ("Starting tc_os_thread_create_005\n"); -#if ! defined WIN32 && ! defined _WRS_KERNEL -#ifndef VXWORKS_RTP - if (getuid() != 0 && geteuid() != 0) { - printf ("N.A - Need root privileges to do the test\n"); - } - else -#endif /* VXWORKS_RTP */ - { - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_REALTIME; - thread_os_threadAttr.schedPriority = sched_get_priority_min (SCHED_FIFO); - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate5", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - if (osResult == os_resultSuccess) { - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int == 0) { - CU_ASSERT (policy == SCHED_FIFO); - } else { - printf ("pthread_getschedparam failed\n"); - } - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed\n"); - } - } -#else /* WIN32 */ - printf ("N.A - Not tested on Windows or vxworks kernel\n"); -#endif - - /* Check os_threadCreate with scheduling class SCHED_TIMESHARE and min priority */ - printf ("Starting os_thread_create_006\n"); -#ifndef WIN32 - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_TIMESHARE; -#ifdef _WRS_KERNEL - thread_os_threadAttr.schedPriority = 250; -#else - thread_os_threadAttr.schedPriority = sched_get_priority_min (SCHED_OTHER); -#endif - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate6", &thread_os_threadAttr, &new_thread, "os_threadCreate"); -#ifdef _WRS_KERNEL - if (osResult == os_resultSuccess) - printf ("os_threadCreate failed - Expected failure from VXWORKS\n"); - else - printf ("OS_SCHED_TIMESHARE not supported\n"); -#else - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int == 0) { - CU_ASSERT (sched_param.sched_priority == sched_get_priority_min (SCHED_OTHER)); - } else { - printf ("pthread_getschedparam failed\n"); - } - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed.\n"); - } -#endif /* _WRS_KERNEL */ -#else - printf ("N.A - Not tested on Windows.\n"); -#endif /* WIN32 */ - - /* Check os_threadCreate with scheduling class SCHED_TIMESHARE and max priority */ - printf ("Starting os_thread_create_007\n"); -#ifndef WIN32 - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_TIMESHARE; -#ifdef _WRS_KERNEL - thread_os_threadAttr.schedPriority = 60; -#else - thread_os_threadAttr.schedPriority = sched_get_priority_max (SCHED_OTHER); -#endif - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate7", &thread_os_threadAttr, &new_thread, "os_threadCreate"); -#ifdef _WRS_KERNEL - if (osResult == os_resultSuccess) { - printf ("os_threadCreate failed - Expected failure from VXWORKS\n"); - } else { - printf ("OS_SCHED_TIMESHARE not supported\n"); - } -#else - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int == 0) { - CU_ASSERT (sched_param.sched_priority == sched_get_priority_max (SCHED_OTHER)); - } else { - printf ("pthread_getschedparam failed\n"); - } - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed.\n"); - } -#endif /* _WRS_KERNEL */ -#else - printf ("N.A - Not tested on Windows.\n"); -#endif /* WIN32 */ - - /* Check os_threadCreate with scheduling class SCHED_REALTIME and min priority */ - printf ("Starting os_thread_create_008\n"); -#ifndef WIN32 -#ifndef VXWORKS_RTP - if (getuid() != 0 && geteuid() != 0) - { - printf ("N.A - Need root privileges to do the test\n"); - } - else -#endif /* VXWORKS_RTP */ - { - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_REALTIME; -#ifdef _WRS_KERNEL - thread_os_threadAttr.schedPriority = 250; -#else - thread_os_threadAttr.schedPriority = sched_get_priority_min (SCHED_FIFO); -#endif - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate8", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - TASK_ID id; - int pri; - STATUS status; - sleepSeconds (2); - pri = 0; - id = taskNameToId("ThreadCreate8"); - status = taskPriorityGet(id,&pri); - CU_ASSERT (status == OK); - CU_ASSERT (pri == 250); -#else - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int == 0) { - CU_ASSERT (sched_param.sched_priority == sched_get_priority_min (SCHED_FIFO)); - } else { - printf ("pthread_getschedparam failed.\n"); - } -#endif /* _WRS_KERNEL */ - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed.\n"); - } - } -#else /* WIN32 */ - printf ("N.A - Not tested on Windows\n"); -#endif - - /* Check os_threadCreate with scheduling class SCHED_REALTIME and max priority */ - printf ("Starting os_thread_create_009\n"); -#ifndef WIN32 -#ifndef VXWORKS_RTP - if (getuid() != 0 && geteuid() != 0) - { - printf ("N.A - Need root privileges to do the test\n"); - } - else -#endif /* VXWORKS_RTP */ - { - os_threadAttrInit (&thread_os_threadAttr); - thread_os_threadAttr.schedClass = OS_SCHED_REALTIME; -#ifdef _WRS_KERNEL - thread_os_threadAttr.schedPriority = 250; -#else - thread_os_threadAttr.schedPriority = sched_get_priority_max (SCHED_FIFO); -#endif - osResult = os_threadCreate (&thread_os_threadId, "ThreadCreate9", &thread_os_threadAttr, &new_thread, "os_threadCreate"); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - int status; - sleepSeconds (2); - status = 0; - taskPriorityGet(taskNameToId("ThreadCreate9"),&status); - CU_ASSERT (status == 250); -#else - int policy; - struct sched_param sched_param; - - result_int = pthread_getschedparam (thread_os_threadId.v, &policy, &sched_param); - CU_ASSERT (result_int == 0); - - if (result_int == 0) { - CU_ASSERT (sched_param.sched_priority == sched_get_priority_max (SCHED_FIFO)); - } else { - printf ("pthread_getschedparam failed.\n"); - } -#endif - osResult = os_threadWaitExit (thread_os_threadId, NULL); - } else { - printf ("os_threadCreate failed.\n"); - } - } -#else /* WIN32 */ - printf ("N.A - Not tested on Windows\n"); -#endif - - /* Check os_threadCreate by checking scheduling scope PTHREAD_SCOPE_SYSTEM */ - printf ("Starting os_thread_create_010\n"); - printf ("N.A - No way to queuery scope from running thread"); - - /* Check os_threadCreate and stacksize sttribute */ - printf ("Starting os_thread_create_011\n"); - printf ("N.A - No way to queuery scope from running thread"); - - printf ("Ending os_thread_create\n"); -} - -CU_Test(os_thread, idself) -{ - os_threadId thread_os_threadId; - os_threadAttr thread_os_threadAttr; - os_result osResult; - uint32_t result_from_thread; - - /* Check if own thread ID is correctly provided */ - printf ("Starting tc_os_threadIdSelf_001\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "OwnThreadId", &thread_os_threadAttr, &threadId_thread, NULL); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult = os_threadWaitExit (thread_os_threadId, &result_from_thread); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - uintmax_t tmp_thread_os_threadId = os_threadIdToInteger(thread_os_threadId); - CU_ASSERT (thread_id_from_thread == tmp_thread_os_threadId); - CU_ASSERT (result_from_thread == (uint32_t)tmp_thread_os_threadId); - } else { - printf ("os_threadWaitExit failed.\n"); - } - } else { - printf ("os_threadCreate failed.\n"); - } - - printf ("Ending tc_threadIdSelf\n"); -} - -CU_Test(os_thread, join) -{ - os_threadId thread_os_threadId; - os_threadAttr thread_os_threadAttr; - os_result osResult; - uint32_t result_from_thread; - - /* Wait for thread to terminate and get the return value with Success result, - while thread is still running */ - printf("Starting os_thread_join_001\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "threadWaitExit", &thread_os_threadAttr, &threadId_thread, (void *)1); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult = os_threadWaitExit (thread_os_threadId, &result_from_thread); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - CU_ASSERT (thread_id_from_thread == os_threadIdToInteger(thread_os_threadId)); - CU_ASSERT (result_from_thread == (uint32_t)thread_id_from_thread); - } else { - printf ("os_threadWaitExit failed.\n"); - } - } else { - printf ("os_threadCreate failed.\n"); - } - - /* Wait for thread to terminate and get the return value with Success result, - while thread is already terminated */ - printf ("Starting os_thread_join_002\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "threadWaitExit", &thread_os_threadAttr, &threadId_thread, NULL); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult = os_threadWaitExit (thread_os_threadId, &result_from_thread); - CU_ASSERT(osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { - CU_ASSERT (thread_id_from_thread == os_threadIdToInteger(thread_os_threadId)); - CU_ASSERT (result_from_thread == (uint32_t)thread_id_from_thread); - } else { - printf ("os_threadWaitExit failed.\n"); - } - } else { - printf ("os_threadCreate failed.\n"); - } - - /* Get thread return value with Fail result because result is already read */ - printf ("Starting tc_os_thread_join_003\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "threadWaitExit", &thread_os_threadAttr, &threadId_thread, NULL); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult = os_threadWaitExit (thread_os_threadId, NULL); - CU_ASSERT (osResult == os_resultSuccess); - } else { - printf ("os_threadCreate failed.\n"); - } - - /* Wait for thread to terminate and get the return value by multiple threads, - one thread gets Success other Fail */ - printf ("Starting tc_os_thread_join_004\n"); -#ifndef WIN32 - os_threadAttrInit (&thread_os_threadAttr); - { - os_threadId threadWait1; - os_result osResult1; - - osResult = os_threadCreate (&thread_os_threadId, "threadToWaitFor", &thread_os_threadAttr, &threadId_thread, (void*) 1); - CU_ASSERT (osResult == os_resultSuccess); - osResult1 = os_threadCreate (&threadWait1, "waitingThread1", &thread_os_threadAttr, &get_threadExit_thread, &thread_os_threadId); - CU_ASSERT (osResult1 == os_resultSuccess); - - if (osResult == os_resultSuccess && osResult1 == os_resultSuccess) - { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult1 = os_threadWaitExit (threadWait1, NULL); - - if (osResult1 != os_resultSuccess) { - printf ("os_threadWaitExit 1 failed\n"); - CU_ASSERT (osResult1 == os_resultSuccess); - } - } else { - printf ("os_threadCreate failed.\n"); - } - } -#else /* WIN32 */ - printf ("N.A - Not tested on Windows.\n"); -#endif - - /* Wait for thread to terminate and pass NULL for the - return value address - not interrested */ - printf ("Starting tc_os_threadWaitExit_005\n"); - os_threadAttrInit (&thread_os_threadAttr); - osResult = os_threadCreate (&thread_os_threadId, "threadWaitExit", &thread_os_threadAttr, &threadId_thread, NULL); - CU_ASSERT (osResult == os_resultSuccess); - - if (osResult == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - osResult = os_threadWaitExit (thread_os_threadId, NULL); - CU_ASSERT (osResult == os_resultSuccess); - if (osResult != os_resultSuccess) - printf ("os_threadWaitExit failed.\n"); - } else { - printf ("os_threadCreate failed.\n"); - } - - printf ("Ending tc_threadWaitExit\n"); -} - -CU_Test(os_thread, attr_init) -{ - os_threadAttr thread_os_threadAttr; - /* Check default attributes: schedClass */ - printf ("Starting os_thread_attr_init_001\n"); - os_threadAttrInit (&thread_os_threadAttr); - CU_ASSERT (thread_os_threadAttr.schedClass == OS_SCHED_DEFAULT); - - /* Check default attributes: schedPriority */ - printf ("Starting os_thread_attr_init_002\n"); -#if !(defined _WRS_KERNEL || defined WIN32 || defined __APPLE__) - os_threadAttrInit (&thread_os_threadAttr); - CU_ASSERT (thread_os_threadAttr.schedPriority == ((sched_get_priority_min (SCHED_OTHER) + sched_get_priority_max (SCHED_OTHER)) / 2 )); -#else - /* OSX priorities are different (min=15 and max=47) */ - printf ("N.A - Not tested for VxWorks, Windows and OSX\n"); -#endif - - /* Check default attributes: stacksize */ - printf ("Starting os_thread_attr_init_003\n"); - os_threadAttrInit (&thread_os_threadAttr); - CU_ASSERT (thread_os_threadAttr.stackSize == 0); - - printf ("Ending os_thread_attr_init\n"); -} - -CU_Test(os_thread, memmalloc) -{ - /* Check os_threadMemMalloc with success result for main thread */ - printf ("Starting os_thread_memmalloc_001\n"); - returnval = os_threadMemMalloc (3, 100); - CU_ASSERT (returnval != NULL); - - printf ("Ending tc_thread_memmalloc\n"); -} - -CU_Test(os_thread, memget) -{ - /* Check os_threadMemGet for main thread and non allocated index */ - printf ("Starting os_thread_memget_001\n"); - returnval = os_threadMemGet (OS_THREAD_WARNING); - CU_ASSERT (returnval == NULL); - - /* Check os_threadMemGet for main thread and allocated index */ - printf ("Starting os_thread_memget_002\n"); - /* FIXME: This test is no good. Apart from the fact that a valid thread - memory index should be used (os_threadMemoryIndex), this also - does not work if the test is executed in a self-contained - manner using the CUnit runner. For now just work around it by - first doing a os_threadMemMalloc. */ - (void)os_threadMemMalloc(3, 100); - returnval = os_threadMemGet (3); - CU_ASSERT (returnval != NULL); - - printf ("Ending tc_thread_memget\n"); -} - -CU_Test(os_thread, memfree) -{ - /* Check os_threadMemFree for main thread and non allocated index */ - printf ("Starting os_thread_memfree_001\n"); - os_threadMemFree (OS_THREAD_WARNING); - returnval = os_threadMemGet (OS_THREAD_WARNING); - CU_ASSERT (returnval == NULL); - - /* Check os_threadMemFree for main thread and allocated index */ - printf ("Starting os_thread_memfree_002\n"); - /* FIXME: See comments on memget test. */ - (void)os_threadMemMalloc(3, 100); - returnval = os_threadMemGet(3); - CU_ASSERT(returnval != NULL); - os_threadMemFree (3); - returnval = os_threadMemGet (3); - CU_ASSERT (returnval == NULL); - - printf ("Ending os_thread_memfree\n"); -} - -CU_Test(os_thread, module) -{ - os_threadId tid; - os_threadAttr tattr; - os_result res; - - os_threadAttrInit (&tattr); - /* Run the following tests for child thread */ - res = os_threadCreate (&tid, "ThreadMemory", &tattr, &threadMemory_thread, NULL); - CU_ASSERT_EQUAL(res, os_resultSuccess); - if (res == os_resultSuccess) { -#ifdef _WRS_KERNEL - sleepSeconds(1); -#endif - res = os_threadWaitExit (tid, NULL); - CU_ASSERT_EQUAL(res, os_resultSuccess); - } -} diff --git a/src/os/tests/thread_cleanup.c b/src/os/tests/thread_cleanup.c deleted file mode 100644 index 9314361..0000000 --- a/src/os/tests/thread_cleanup.c +++ /dev/null @@ -1,283 +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 - */ -#include -#include - -#include "os/os.h" -#include "CUnit/Test.h" - -CU_Init(os_thread_cleanup) -{ - os_osInit(); - return 0; -} - -CU_Clean(os_thread_cleanup) -{ - os_osExit(); - return 0; -} - -#define THREAD_RESET_1 (1<<0) -#define THREAD_RESET_2 (1<<1) -#define THREAD_RUN_OFFSET (4) -#define THREAD_RUN_1 (1<<(THREAD_RUN_OFFSET)) -#define THREAD_RUN_2 (1<<(THREAD_RUN_OFFSET + 1)) - -struct thread_argument { - int flags; - int pop; - int one; - int two; - int executed; - int cancelled; - int block; - os_mutex *mutex; - os_threadId thread; -}; - -static struct thread_argument * -make_thread_argument( - int flags, int pop, int one, int two) -{ - struct thread_argument *targ = os_malloc(sizeof(*targ)); - memset(targ, 0, sizeof(*targ)); - targ->flags = flags; - targ->pop = pop; - targ->one = one; - targ->two = two; - - return targ; -} - -static void -reset_one( - void *arg) -{ - struct thread_argument *targ = (struct thread_argument *)arg; - targ->one = 0; - targ->executed++; -} - -static void -reset_two( - void *arg) -{ - struct thread_argument *targ = (struct thread_argument *)arg; - targ->two = 0; - targ->executed++; -} - -static uint32_t -thread_main( - void *arg) -{ - int pushed = 0; - int popped = 0; - int execute = 0; - struct thread_argument *targ = (struct thread_argument *)arg; - - if (targ->flags & THREAD_RESET_1) { - os_threadCleanupPush(&reset_one, arg); - pushed++; - } - if (targ->flags & THREAD_RESET_2) { - os_threadCleanupPush(&reset_two, arg); - pushed++; - } - - assert(targ->pop <= pushed); - - if (targ->block) { - os_mutexLock(targ->mutex); - } - - while (popped < targ->pop) { - execute = 1 << (THREAD_RUN_OFFSET + (targ->pop - (popped + 1))); - os_threadCleanupPop(targ->flags & execute); - targ->cancelled++; - popped++; - } - - if (targ->block) { - os_mutexUnlock(targ->mutex); - } - - return 0; -} - -static void -setup( - struct thread_argument *targ) -{ - os_result res; - os_threadId tid; - os_threadAttr tattr; - - uint32_t tres = 0; - - os_threadAttrInit(&tattr); - res = os_threadCreate(&tid, "", &tattr, &thread_main, (void *)targ); - CU_ASSERT_EQUAL_FATAL(res, os_resultSuccess); - - targ->thread = tid; - if (!targ->block) { - res = os_threadWaitExit(tid, &tres); - CU_ASSERT_EQUAL_FATAL(res, os_resultSuccess); - } -} - -/* verify the cleanup routine is called */ -CU_Test(os_thread_cleanup, push_one) -{ - int flags = THREAD_RESET_1; - struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 2); - CU_ASSERT_EQUAL(targ->executed, 1); - CU_ASSERT_EQUAL(targ->cancelled, 0); - - free(targ); -} - -/* verify all cleanup routines are called if multiple are registered */ -CU_Test(os_thread_cleanup, push_two) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2; - struct thread_argument *targ = make_thread_argument(flags, 0, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 0); - CU_ASSERT_EQUAL(targ->executed, 2); - CU_ASSERT_EQUAL(targ->cancelled, 0); - - free(targ); -} - -/* verify the first cleanup routine is still called if second got popped */ -CU_Test(os_thread_cleanup, push_two_pop_one_no_exec) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2; - struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 2); - CU_ASSERT_EQUAL(targ->executed, 1); - CU_ASSERT_EQUAL(targ->cancelled, 1); - - free(targ); -} - -CU_Test(os_thread_cleanup, push_two_pop_one_exec) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; - struct thread_argument *targ = make_thread_argument(flags, 1, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 0); - CU_ASSERT_EQUAL(targ->executed, 2); - CU_ASSERT_EQUAL(targ->cancelled, 1); - - free(targ); -} - -/* verify no cleanup routines are called if all got popped */ -CU_Test(os_thread_cleanup, push_two_pop_two_no_exec) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2; - struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 1); - CU_ASSERT_EQUAL(targ->two, 2); - CU_ASSERT_EQUAL(targ->executed, 0); - CU_ASSERT_EQUAL(targ->cancelled, 2); - - free(targ); -} - -CU_Test(os_thread_cleanup, push_two_pop_two_exec_one) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1; - struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 2); - CU_ASSERT_EQUAL(targ->executed, 1); - CU_ASSERT_EQUAL(targ->cancelled, 2); - - free(targ); -} - -CU_Test(os_thread_cleanup, push_two_pop_two_exec_both) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2 | THREAD_RUN_1 | THREAD_RUN_2; - struct thread_argument *targ = make_thread_argument(flags, 2, 1, 2); - setup(targ); - - CU_ASSERT_EQUAL(targ->one, 0); - CU_ASSERT_EQUAL(targ->two, 0); - CU_ASSERT_EQUAL(targ->executed, 2); - CU_ASSERT_EQUAL(targ->cancelled, 2); - - free(targ); -} - -CU_Test(os_thread_cleanup, no_interference) -{ - int flags = THREAD_RESET_1 | THREAD_RESET_2; - struct thread_argument *targ1 = make_thread_argument(flags, 0, 1, 2); - struct thread_argument *targ2 = make_thread_argument(flags, 2, 1, 2); - os_mutex mutex1, mutex2; - - os_mutexInit(&mutex1); - os_mutexInit(&mutex2); - os_mutexLock(&mutex1); - os_mutexLock(&mutex2); - - targ1->mutex = &mutex1; - targ1->block = 1; - targ2->mutex = &mutex2; - targ2->block = 1; - - setup(targ1); - setup(targ2); - - /* ensure thread 2 pops it's cleanup routines while thread 1 blocks */ - os_mutexUnlock(&mutex2); - os_threadWaitExit(targ2->thread, NULL); - - CU_ASSERT_EQUAL(targ2->one, 1); - CU_ASSERT_EQUAL(targ2->two, 2); - CU_ASSERT_EQUAL(targ2->executed, 0); - CU_ASSERT_EQUAL(targ2->cancelled, 2); - - /* instruct thread 1 to continue */ - os_mutexUnlock(&mutex1); - os_threadWaitExit(targ1->thread, NULL); - - CU_ASSERT_EQUAL(targ1->one, 0); - CU_ASSERT_EQUAL(targ1->two, 0); - CU_ASSERT_EQUAL(targ1->executed, 2); - CU_ASSERT_EQUAL(targ1->cancelled, 0); - - os_mutexDestroy(&mutex1); - os_mutexDestroy(&mutex2); - free(targ1); - free(targ2); -} diff --git a/src/tools/ddsls/CMakeLists.txt b/src/tools/ddsls/CMakeLists.txt index 3c519e3..35985a7 100644 --- a/src/tools/ddsls/CMakeLists.txt +++ b/src/tools/ddsls/CMakeLists.txt @@ -10,10 +10,7 @@ # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # add_executable(ddsls ddsls.c) -target_link_libraries(ddsls ddsc OSAPI) -if(WIN32) - target_compile_definitions(ddsls PRIVATE _CRT_SECURE_NO_WARNINGS) -endif() +target_link_libraries(ddsls ddsc) install( TARGETS ddsls diff --git a/src/tools/ddsls/ddsls.c b/src/tools/ddsls/ddsls.c index d6accb8..bd53700 100644 --- a/src/tools/ddsls/ddsls.c +++ b/src/tools/ddsls/ddsls.c @@ -9,11 +9,16 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" -#include "ddsc/dds.h" +#include +#include +#include + +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/string.h" +#include "dds/dds.h" // FIXME Temporary workaround for lack of wait_for_historical implementation. Remove this on completion of CHAM-268. -#define dds_reader_wait_for_historical_data(a,b) DDS_SUCCESS; dds_sleepfor(DDS_MSECS(200)); +#define dds_reader_wait_for_historical_data(a,b) DDS_RETCODE_OK; dds_sleepfor(DDS_MSECS(200)); // FIXME should fix read/take interface to allow simple unlimited take #define MAX_SAMPLES 10 @@ -517,13 +522,15 @@ int main (int argc, char **argv) int flags = 0; dds_entity_t pp; int opt; - while ((opt = os_getopt (argc, argv, "f:a")) != EOF) + while ((opt = getopt (argc, argv, "f:a")) != EOF) { switch (opt) { case 'f': { - char *fname = os_get_optarg (); + char *fname = optarg; + DDSRT_WARNING_MSVC_OFF(4996) fp = fopen (fname, "w"); + DDSRT_WARNING_MSVC_ON(4996) if (fp == NULL) { fprintf (stderr, "%s: can't open for writing\n", fname); @@ -545,12 +552,12 @@ int main (int argc, char **argv) usage(); } - for (int i = os_get_optind (); i < argc; i++) + for (int i = optind; i < argc; i++) { size_t k; for (k = 0; k < TOPICTAB_SIZE; k++) { - if (os_strcasecmp (argv[i], topictab[k].name) == 0) + if (ddsrt_strcasecmp (argv[i], topictab[k].name) == 0) { flags |= topictab[k].flag; break; @@ -565,7 +572,7 @@ int main (int argc, char **argv) if ((pp = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL)) < 0) { - fprintf (stderr, "failed to create participant: %s\n", dds_err_str (pp)); + fprintf (stderr, "failed to create participant: %s\n", dds_strretcode (pp)); exit (1); } diff --git a/src/tools/pubsub/CMakeLists.txt b/src/tools/pubsub/CMakeLists.txt index 230364e..f7244c7 100644 --- a/src/tools/pubsub/CMakeLists.txt +++ b/src/tools/pubsub/CMakeLists.txt @@ -10,7 +10,7 @@ # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # add_executable(pubsub pubsub.c common.c testtype.c porting.c) -target_link_libraries(pubsub ddsc OSAPI) +target_link_libraries(pubsub ddsc) if(WIN32) target_compile_definitions(pubsub PRIVATE _CRT_SECURE_NO_WARNINGS) endif() diff --git a/src/tools/pubsub/common.c b/src/tools/pubsub/common.c index fac48d9..a24abaf 100644 --- a/src/tools/pubsub/common.c +++ b/src/tools/pubsub/common.c @@ -18,9 +18,10 @@ #include #include +#include "dds/ddsrt/string.h" + #include "testtype.h" #include "common.h" -#include "os/os.h" dds_entity_t dp = 0; dds_entity_t qosprov = 0; @@ -122,7 +123,7 @@ static void xsnprintf(char *buf, size_t bufsz, size_t *p, const char *fmt, ...) int n; va_list ap; va_start(ap, fmt); - n = os_vsnprintf(buf + *p, bufsz - *p, fmt, ap); + n = vsnprintf(buf + *p, bufsz - *p, fmt, ap); va_end(ap); *p += (size_t)n; } @@ -259,7 +260,7 @@ int change_publisher_partitions(dds_entity_t pub, unsigned npartitions, const ch qos = dds_create_qos(); rc = dds_get_qos(pub, qos); - if (rc == DDS_SUCCESS) { + if (rc == DDS_RETCODE_OK) { dds_qset_partition(qos, npartitions, partitions); rc = dds_set_qos(pub, qos); } @@ -273,7 +274,7 @@ int change_subscriber_partitions(dds_entity_t sub, unsigned npartitions, const c qos = dds_create_qos(); rc = dds_get_qos(sub, qos); - if (rc == DDS_SUCCESS) { + if (rc == DDS_RETCODE_OK) { dds_qset_partition(qos, npartitions, partitions); rc = dds_set_qos(sub, qos); } @@ -883,7 +884,7 @@ void setqos_from_args(dds_entity_kind_t qt, dds_qos_t *q, int n, const char *arg for (i = 0; i < n; i++) { char *args_copy = dds_string_dup(args[i]), *cursor = args_copy; const char *arg; - while ((arg = os_strsep(&cursor, ",")) != NULL) { + while ((arg = ddsrt_strsep(&cursor, ",")) != NULL) { if (arg[0] && arg[1] == '=') { const char *a = arg + 2; switch (arg[0]) { @@ -940,3 +941,37 @@ void setqos_from_args(dds_entity_kind_t qt, dds_qos_t *q, int n, const char *arg dds_free(args_copy); } } + +#define DDS_ERR_MSG_MAX 128 + +void dds_fail (const char * msg, const char * where) +{ + fprintf (stderr, "Aborting Failure: %s %s\n", where, msg); + abort (); +} + +bool dds_err_check (dds_return_t err, unsigned flags, const char * where) +{ + if (err < 0) + { + if (flags & (DDS_CHECK_REPORT | DDS_CHECK_FAIL)) + { + char msg[DDS_ERR_MSG_MAX]; + (void) snprintf (msg, DDS_ERR_MSG_MAX, "Error %d:M%d:%s", dds_err_file_id(err), dds_err_line(err), dds_err_str(err)); + if (flags & DDS_CHECK_REPORT) + { + printf ("%s: %s\n", where, msg); + } + if (flags & DDS_CHECK_FAIL) + { + dds_fail (msg, where); + } + } + if (flags & DDS_CHECK_EXIT) + { + exit (-1); + } + } + return (err >= 0); +} + diff --git a/src/tools/pubsub/common.h b/src/tools/pubsub/common.h index e176867..e4a0b5f 100644 --- a/src/tools/pubsub/common.h +++ b/src/tools/pubsub/common.h @@ -12,7 +12,7 @@ #ifndef COMMON_H #define COMMON_H -#include "ddsc/dds.h" +#include "dds/dds.h" #include #define DDS_USERDATA_QOS_POLICY_NAME "UserData" @@ -74,11 +74,11 @@ void hist_record(struct hist *h, uint64_t x, unsigned weight); void hist_print(struct hist *h, dds_time_t dt, int reset); void error(const char *fmt, ...); -#define error_abort(rc, ...) if (rc < DDS_SUCCESS) { error(__VA_ARGS__); DDS_ERR_CHECK(rc, DDS_CHECK_FAIL); } -#define error_report(rc, ...) if (rc < DDS_SUCCESS) { error(__VA_ARGS__); DDS_ERR_CHECK(rc, DDS_CHECK_REPORT); } -#define error_return(rc, ...) if (rc < DDS_SUCCESS) { error_report(rc, __VA_ARGS__); return; } +#define error_abort(rc, ...) if (rc < DDS_RETCODE_OK) { error(__VA_ARGS__); DDS_ERR_CHECK(rc, DDS_CHECK_FAIL); } +#define error_report(rc, ...) if (rc < DDS_RETCODE_OK) { error(__VA_ARGS__); DDS_ERR_CHECK(rc, DDS_CHECK_REPORT); } +#define error_return(rc, ...) if (rc < DDS_RETCODE_OK) { error_report(rc, __VA_ARGS__); return; } #define error_exit(...) { error(__VA_ARGS__); exit(2); } -#define os_error_exit(osres, ...) if (osres != os_resultSuccess) { error(__VA_ARGS__); exit(2); } +#define os_error_exit(osres, ...) if (osres != DDS_RETCODE_OK) { error(__VA_ARGS__); exit(2); } void save_argv0(const char *argv0); int common_init(const char *argv0); @@ -113,4 +113,16 @@ void qos_autodispose_unregistered_instances(dds_entity_kind_t qt, dds_qos_t *q, void set_qosprovider(const char *arg); void setqos_from_args(dds_entity_kind_t qt, dds_qos_t *q, int n, const char *args[]); +bool dds_err_check (dds_return_t err, unsigned flags, const char *where); + +#define DDS_CHECK_REPORT 0x01 +#define DDS_CHECK_FAIL 0x02 +#define DDS_CHECK_EXIT 0x04 + +#define dds_err_str(x) (dds_strretcode(dds_err_nr(x))) + +#define DDS_TO_STRING(n) #n +#define DDS_INT_TO_STRING(n) DDS_TO_STRING(n) +#define DDS_ERR_CHECK(e, f) (dds_err_check ((e), (f), __FILE__ ":" DDS_INT_TO_STRING(__LINE__))) + #endif diff --git a/src/tools/pubsub/pubsub.c b/src/tools/pubsub/pubsub.c index 1b460c2..187a2de 100644 --- a/src/tools/pubsub/pubsub.c +++ b/src/tools/pubsub/pubsub.c @@ -9,10 +9,6 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#ifndef MAIN -#define MAIN main -#endif - #ifdef __APPLE__ #define USE_EDITLINE 0 #endif @@ -27,6 +23,8 @@ #include #include #include +#include +#include #if USE_EDITLINE #include @@ -36,7 +34,13 @@ #include "testtype.h" #include "tglib.h" #include "porting.h" -#include "os/os.h" + +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/process.h" +#include "dds/ddsrt/string.h" +#include "dds/ddsrt/strtol.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" //#define NUMSTR "0123456789" //#define HOSTNAMESTR "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-." NUMSTR @@ -146,7 +150,7 @@ struct wrspeclist { struct wrspeclist *prev, *next; /* circular */ }; -static os_mutex output_mutex; +static ddsrt_mutex_t output_mutex; static void terminate(void) { // const char c = 0; @@ -272,8 +276,10 @@ static void expand_append(char **dst, size_t *sz,size_t *pos, char c) { static char *expand_envvars(const char *src0); +// FIXME: This is the same as the expand function in util. Merge. static char *expand_env(const char *name, char op, const char *alt) { - const char *env = os_getenv(name); + char *env = NULL; + ddsrt_getenv(name, &env); switch (op) { case 0: return dds_string_dup(env ? env : ""); @@ -812,7 +818,7 @@ static void print_sampleinfo(dds_time_t *tstart, dds_time_t tnow, const dds_samp n += printf ("%s", tag); } if (print_metadata & PM_TIME) { - n += printf ("%s%lld.%09lld", n > 0 ? " " : "", (relt / DDS_NSECS_IN_SEC), (relt % DDS_NSECS_IN_SEC)); + n += printf ("%s%"PRId64".%09"PRId64, n > 0 ? " " : "", (relt / DDS_NSECS_IN_SEC), (relt % DDS_NSECS_IN_SEC)); } sep = " : "; if (print_metadata & PM_PHANDLE) { @@ -824,7 +830,7 @@ static void print_sampleinfo(dds_time_t *tstart, dds_time_t tnow, const dds_samp } sep = " : "; if (print_metadata & PM_STIME) { - n += printf ("%s%lld.%09lld", n > 0 ? sep : "", (si->source_timestamp/DDS_NSECS_IN_SEC), (si->source_timestamp%DDS_NSECS_IN_SEC)); + n += printf ("%s%"PRId64".%09"PRId64, n > 0 ? sep : "", (si->source_timestamp/DDS_NSECS_IN_SEC), (si->source_timestamp%DDS_NSECS_IN_SEC)); } sep = " : "; if (print_metadata & PM_DGEN) { @@ -849,7 +855,7 @@ static void print_sampleinfo(dds_time_t *tstart, dds_time_t tnow, const dds_samp static void print_K(dds_time_t *tstart, dds_time_t tnow, dds_entity_t rd, const char *tag, const dds_sample_info_t *si, int32_t keyval, uint32_t seq, int (*getkeyval) (dds_entity_t rd, int32_t *key, dds_instance_handle_t ih)) { int result; - os_mutexLock(&output_mutex); + ddsrt_mutex_lock(&output_mutex); print_sampleinfo(tstart, tnow, si, tag); if (si->valid_data) { if(printmode == TGPM_MULTILINE) { @@ -879,7 +885,7 @@ static void print_K(dds_time_t *tstart, dds_time_t tnow, dds_entity_t rd, const } else printf ("get_key_value: error (%s)\n", dds_err_str(result)); } - os_mutexUnlock(&output_mutex); + ddsrt_mutex_unlock(&output_mutex); } static void print_seq_KS(dds_time_t *tstart, dds_time_t tnow, dds_entity_t rd, const char *tag, const dds_sample_info_t *iseq, KeyedSeq **mseq, int count) { @@ -916,7 +922,7 @@ static void print_seq_OU(dds_time_t *tstart, dds_time_t tnow, dds_entity_t rd __ int i; for (i = 0; i < count; i++) { - os_mutexLock(&output_mutex); + ddsrt_mutex_lock(&output_mutex); print_sampleinfo(tstart, tnow, si, tag); if (si->valid_data) { if(printmode == TGPM_MULTILINE) { @@ -929,7 +935,7 @@ static void print_seq_OU(dds_time_t *tstart, dds_time_t tnow, dds_entity_t rd __ } else { printf ("NA\n"); } - os_mutexUnlock(&output_mutex); + ddsrt_mutex_unlock(&output_mutex); } } @@ -1715,7 +1721,7 @@ static uint32_t subthread(void *vspec) { dds_subscription_matched_status_t status; rc = dds_get_subscription_matched_status(rd, &status); error_report(rc, "dds_get_subscription_matched_status failed"); - if (rc == DDS_SUCCESS) { + if (rc == DDS_RETCODE_OK) { printf("[pre-read: subscription-matched: total=(%"PRIu32" change %d) current=(%"PRIu32" change %d) handle=%"PRIu64"]\n", status.total_count, status.total_count_change, status.current_count, @@ -1852,7 +1858,7 @@ static uint32_t subthread(void *vspec) { printf ("-- final take: data reader empty --\n"); else exitcode = 1; - } else if (nread < DDS_SUCCESS) { + } else if (nread < DDS_RETCODE_OK) { if (!once_mode) { error_report(rc, "-- final take --\n"); } else { @@ -1976,7 +1982,7 @@ static char *read_line_from_textfile(FILE *fp) { if (n == sz) str = dds_realloc(str, sz += 1); str[n] = 0; } else if (ferror(fp)) { - error_exit("error reading file, errno = %d (%s)\n", os_getErrno(), os_strerror(os_getErrno())); + error_exit("error reading file, errno = %d\n", errno); } return str; } @@ -2069,8 +2075,8 @@ struct spec { dds_duration_t findtopic_timeout; struct readerspec rd; struct writerspec wr; - os_threadId rdtid; - os_threadId wrtid; + ddsrt_thread_t rdtid; + ddsrt_thread_t wrtid; }; static void addspec(unsigned whatfor, unsigned *specsofar, unsigned *specidx, struct spec **spec, int want_reader) { @@ -2103,7 +2109,7 @@ static void addspec(unsigned whatfor, unsigned *specsofar, unsigned *specidx, st static void set_print_mode(const char *modestr) { char *copy = dds_string_dup(modestr), *cursor = copy, *tok; - while ((tok = os_strsep(&cursor, ",")) != NULL) { + while ((tok = ddsrt_strsep(&cursor, ",")) != NULL) { int enable; if (strncmp(tok, "no", 2) == 0) { enable = 0; tok += 2; @@ -2154,7 +2160,7 @@ static void set_print_mode(const char *modestr) { dds_free(copy); } -int MAIN(int argc, char *argv[]) { +int main(int argc, char *argv[]) { dds_entity_t sub = 0; dds_entity_t pub = 0; dds_listener_t *rdlistener = dds_create_listener(NULL); @@ -2174,9 +2180,9 @@ int MAIN(int argc, char *argv[]) { int want_writer = 1; bool isWriterListenerSet = false; // int disable_signal_handlers = 0; // TODO signal handler support - unsigned sleep_at_end = 0; - os_threadId sigtid; - os_threadId inptid; + long long sleep_at_end = 0; + ddsrt_thread_t sigtid; + ddsrt_thread_t inptid; #define SPEC_TOPICSEL 1 #define SPEC_TOPICNAME 2 unsigned spec_sofar = 0; @@ -2188,15 +2194,15 @@ int MAIN(int argc, char *argv[]) { struct wrspeclist *wrspecs = NULL; memset (&sigtid, 0, sizeof(sigtid)); memset (&inptid, 0, sizeof(inptid)); - os_mutexInit(&output_mutex); + ddsrt_mutex_init(&output_mutex); - if (os_strcasecmp(execname(argc, argv), "sub") == 0) + if (ddsrt_strcasecmp(execname(argc, argv), "sub") == 0) want_writer = 0; - else if(os_strcasecmp(execname(argc, argv), "pub") == 0) + else if(ddsrt_strcasecmp(execname(argc, argv), "pub") == 0) want_reader = 0; save_argv0 (argv[0]); - pid = (int) os_getpid(); + pid = (int) ddsrt_getpid(); qreader[0] = "k=all"; qreader[1] = "R=10000/inf/inf"; @@ -2212,7 +2218,7 @@ int MAIN(int argc, char *argv[]) { spec_sofar = 0; assert(specidx == 0); - while ((opt = os_getopt(argc, argv, "!@*:FK:T:D:q:m:M:n:OP:rRs:S:U:W:w:z:")) != EOF) { + while ((opt = getopt(argc, argv, "!@*:FK:T:D:q:m:M:n:OP:rRs:S:U:W:w:z:")) != EOF) { switch (opt) { case '!': // disable_signal_handlers = 1; // TODO signal handler support @@ -2221,45 +2227,48 @@ int MAIN(int argc, char *argv[]) { spec[specidx].wr.duplicate_writer_flag = 1; break; case '*': - sleep_at_end = (unsigned) os_atoll(os_get_optarg()); + { + sleep_at_end = 0; + (void)ddsrt_atoll(optarg, &sleep_at_end); + } break; case 'M': - if (sscanf(os_get_optarg(), "%lf:%n", &wait_for_matching_reader_timeout, &pos) != 1) { - fprintf (stderr, "-M %s: invalid timeout\n", os_get_optarg()); + if (sscanf(optarg, "%lf:%n", &wait_for_matching_reader_timeout, &pos) != 1) { + fprintf (stderr, "-M %s: invalid timeout\n", optarg); exit(2); } - wait_for_matching_reader_arg = os_get_optarg() + pos; + wait_for_matching_reader_arg = optarg + pos; break; case 'F': setvbuf(stdout, (char *) NULL, _IOLBF, 0); break; case 'K': addspec(SPEC_TOPICSEL, &spec_sofar, &specidx, &spec, want_reader); - if (os_strcasecmp(os_get_optarg(), "KS") == 0) + if (ddsrt_strcasecmp(optarg, "KS") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = KS; - else if (os_strcasecmp(os_get_optarg(), "K32") == 0) + else if (ddsrt_strcasecmp(optarg, "K32") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = K32; - else if (os_strcasecmp(os_get_optarg(), "K64") == 0) + else if (ddsrt_strcasecmp(optarg, "K64") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = K64; - else if (os_strcasecmp(os_get_optarg(), "K128") == 0) + else if (ddsrt_strcasecmp(optarg, "K128") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = K128; - else if (os_strcasecmp(os_get_optarg(), "K256") == 0) + else if (ddsrt_strcasecmp(optarg, "K256") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = K256; - else if (os_strcasecmp(os_get_optarg(), "OU") == 0) + else if (ddsrt_strcasecmp(optarg, "OU") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = OU; - else if (os_strcasecmp(os_get_optarg(), "ARB") == 0) + else if (ddsrt_strcasecmp(optarg, "ARB") == 0) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = ARB; - else if (get_metadata(&spec[specidx].metadata, &spec[specidx].typename, &spec[specidx].keylist, os_get_optarg())) + else if (get_metadata(&spec[specidx].metadata, &spec[specidx].typename, &spec[specidx].keylist, optarg)) spec[specidx].rd.topicsel = spec[specidx].wr.topicsel = ARB; else { - fprintf (stderr, "-K %s: unknown type\n", os_get_optarg()); + fprintf (stderr, "-K %s: unknown type\n", optarg); exit(2); } break; case 'T': { char *p; addspec(SPEC_TOPICNAME, &spec_sofar, &specidx, &spec, want_reader); - spec[specidx].topicname = (const char *) dds_string_dup(os_get_optarg()); + spec[specidx].topicname = (const char *) dds_string_dup(optarg); if ((p = strchr(spec[specidx].topicname, ':')) != NULL) { double d; int dpos, have_to = 0; @@ -2269,7 +2278,7 @@ int MAIN(int argc, char *argv[]) { set_infinite_dds_duration(&spec[specidx].findtopic_timeout); } else if (sscanf(p, "%lf%n", &d, &dpos) == 1 && (p[dpos] == 0 || p[dpos] == ':')) { if (double_to_dds_duration(&spec[specidx].findtopic_timeout, d) < 0) - error_exit("-T %s: %s: duration invalid\n", os_get_optarg(), p); + error_exit("-T %s: %s: duration invalid\n", optarg, p); have_to = 1; } else { /* assume content filter */ @@ -2284,17 +2293,17 @@ int MAIN(int argc, char *argv[]) { break; } case 'q': - if (strncmp(os_get_optarg(), "provider=", 9) == 0) { - set_qosprovider(os_get_optarg()+9); + if (strncmp(optarg, "provider=", 9) == 0) { + set_qosprovider(optarg+9); } else { - size_t n = strspn(os_get_optarg(), "atrwps"); - const char *colon = strchr(os_get_optarg(), ':'); - if (colon == NULL || n == 0 || n != (size_t) (colon - os_get_optarg())) { - fprintf (stderr, "-q %s: flags indicating to which entities QoS's apply must match regex \"[^atrwps]+:\"\n", os_get_optarg()); + size_t n = strspn(optarg, "atrwps"); + const char *colon = strchr(optarg, ':'); + if (colon == NULL || n == 0 || n != (size_t) (colon - optarg)) { + fprintf (stderr, "-q %s: flags indicating to which entities QoS's apply must match regex \"[^atrwps]+:\"\n", optarg); exit(2); } else { const char *q = colon+1; - for (const char *flag = os_get_optarg(); flag != colon; flag++) + for (const char *flag = optarg; flag != colon; flag++) switch (*flag) { case 't': qtopic[nqtopic++] = q; break; case 'r': qreader[nqreader++] = q; break; @@ -2315,32 +2324,32 @@ int MAIN(int argc, char *argv[]) { } break; case 'D': - dur = atof(os_get_optarg()); + dur = atof(optarg); break; case 'm': spec[specidx].rd.polling = 0; - if (strcmp(os_get_optarg(), "0") == 0) { + if (strcmp(optarg, "0") == 0) { spec[specidx].rd.mode = MODE_NONE; - } else if (strcmp(os_get_optarg(), "p") == 0) { + } else if (strcmp(optarg, "p") == 0) { spec[specidx].rd.mode = MODE_PRINT; - } else if (strcmp(os_get_optarg(), "pp") == 0) { + } else if (strcmp(optarg, "pp") == 0) { spec[specidx].rd.mode = MODE_PRINT; spec[specidx].rd.polling = 1; - } else if (strcmp(os_get_optarg(), "c") == 0) { + } else if (strcmp(optarg, "c") == 0) { spec[specidx].rd.mode = MODE_CHECK; - } else if (sscanf(os_get_optarg(), "c:%u%n", &nkeyvals, &pos) == 1 && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, "c:%u%n", &nkeyvals, &pos) == 1 && optarg[pos] == 0) { spec[specidx].rd.mode = MODE_CHECK; - } else if (strcmp(os_get_optarg(), "cp") == 0) { + } else if (strcmp(optarg, "cp") == 0) { spec[specidx].rd.mode = MODE_CHECK; spec[specidx].rd.polling = 1; - } else if (sscanf(os_get_optarg(), "cp:%u%n", &nkeyvals, &pos) == 1 && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, "cp:%u%n", &nkeyvals, &pos) == 1 && optarg[pos] == 0) { spec[specidx].rd.mode = MODE_CHECK; spec[specidx].rd.polling = 1; - } else if (strcmp(os_get_optarg(), "z") == 0) { + } else if (strcmp(optarg, "z") == 0) { spec[specidx].rd.mode = MODE_ZEROLOAD; - } else if (strcmp(os_get_optarg(), "d") == 0) { + } else if (strcmp(optarg, "d") == 0) { spec[specidx].rd.mode = MODE_DUMP; - } else if (strcmp(os_get_optarg(), "dp") == 0) { + } else if (strcmp(optarg, "dp") == 0) { spec[specidx].rd.mode = MODE_DUMP; spec[specidx].rd.polling = 1; } else { - fprintf (stderr, "-m %s: invalid mode\n", os_get_optarg()); + fprintf (stderr, "-m %s: invalid mode\n", optarg); exit(2); } break; @@ -2348,34 +2357,34 @@ int MAIN(int argc, char *argv[]) { int port; spec[specidx].wr.writerate = 0.0; spec[specidx].wr.burstsize = 1; - if (strcmp(os_get_optarg(), "-") == 0) { + if (strcmp(optarg, "-") == 0) { spec[specidx].wr.mode = WRM_INPUT; - } else if (sscanf(os_get_optarg(), "%u%n", &nkeyvals, &pos) == 1 && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, "%u%n", &nkeyvals, &pos) == 1 && optarg[pos] == 0) { spec[specidx].wr.mode = (nkeyvals == 0) ? WRM_NONE : WRM_AUTO; - } else if (sscanf(os_get_optarg(), "%u:%lf*%u%n", &nkeyvals, &spec[specidx].wr.writerate, &spec[specidx].wr.burstsize, &pos) == 3 - && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, "%u:%lf*%u%n", &nkeyvals, &spec[specidx].wr.writerate, &spec[specidx].wr.burstsize, &pos) == 3 + && optarg[pos] == 0) { spec[specidx].wr.mode = (nkeyvals == 0) ? WRM_NONE : WRM_AUTO; - } else if (sscanf(os_get_optarg(), "%u:%lf%n", &nkeyvals, &spec[specidx].wr.writerate, &pos) == 2 - && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, "%u:%lf%n", &nkeyvals, &spec[specidx].wr.writerate, &pos) == 2 + && optarg[pos] == 0) { spec[specidx].wr.mode = (nkeyvals == 0) ? WRM_NONE : WRM_AUTO; - } else if (sscanf(os_get_optarg(), ":%d%n", &port, &pos) == 1 && os_get_optarg()[pos] == 0) { + } else if (sscanf(optarg, ":%d%n", &port, &pos) == 1 && optarg[pos] == 0) { fprintf (stderr, "listen on TCP port P: not supported\n"); exit(1); } else { spec[specidx].wr.mode = WRM_INPUT; - fprintf (stderr, "%s: can't open\n", os_get_optarg()); + fprintf (stderr, "%s: can't open\n", optarg); exit(1); } break; } case 'n': - spec[specidx].rd.read_maxsamples = (uint32_t)atoi(os_get_optarg()); + spec[specidx].rd.read_maxsamples = (uint32_t)atoi(optarg); break; case 'O': once_mode = 1; break; case 'P': - set_print_mode(os_get_optarg()); + set_print_mode(optarg); break; case 'R': spec[specidx].rd.use_take = 0; @@ -2384,26 +2393,26 @@ int MAIN(int argc, char *argv[]) { spec[specidx].wr.register_instances = 1; break; case 's': - spec[specidx].rd.sleep_ns = DDS_MSECS((int64_t) atoi(os_get_optarg())); + spec[specidx].rd.sleep_ns = DDS_MSECS((int64_t) atoi(optarg)); break; case 'W': { double t; wait_hist_data = 1; - if (strcmp(os_get_optarg(), "inf") == 0) + if (strcmp(optarg, "inf") == 0) set_infinite_dds_duration(&wait_hist_data_timeout); - else if (sscanf(os_get_optarg(), "%lf%n", &t, &pos) == 1 && os_get_optarg()[pos] == 0 && t >= 0) + else if (sscanf(optarg, "%lf%n", &t, &pos) == 1 && optarg[pos] == 0 && t >= 0) double_to_dds_duration(&wait_hist_data_timeout, t); else { - fprintf (stderr, "-W %s: invalid duration\n", os_get_optarg()); + fprintf (stderr, "-W %s: invalid duration\n", optarg); exit(2); } } break; case 'S': { - char *copy = dds_string_dup(os_get_optarg()), *tok, *lasts; + char *copy = dds_string_dup(optarg), *tok, *lasts; if (copy == NULL) abort(); - tok = os_strtok_r(copy, ",", &lasts); + tok = ddsrt_strtok_r(copy, ",", &lasts); while (tok) { if (strcmp(tok, "pr") == 0 || strcmp(tok, "pre-read") == 0) spec[specidx].rd.print_match_pre_read = 1; @@ -2435,7 +2444,7 @@ int MAIN(int argc, char *argv[]) { fprintf (stderr, "-S %s: invalid event\n", tok); exit(2); } - tok = os_strtok_r(NULL, ",", &lasts); + tok = ddsrt_strtok_r(NULL, ",", &lasts); } dds_free(copy); } @@ -2443,9 +2452,9 @@ int MAIN(int argc, char *argv[]) { case 'z': { /* payload is int32 int32 seq, which we count as 16+N, for a 4 byte sequence length */ - int tmp = atoi(os_get_optarg()); + int tmp = atoi(optarg); if (tmp != 0 && tmp < 12) { - fprintf (stderr, "-z %s: minimum is 12\n", os_get_optarg()); + fprintf (stderr, "-z %s: minimum is 12\n", optarg); exit(1); } else if (tmp == 0) spec[specidx].wr.baggagesize = 0; @@ -2458,7 +2467,7 @@ int MAIN(int argc, char *argv[]) { } } - if (argc - os_get_optind() < 1) { + if (argc - optind < 1) { usage(argv[0]); } @@ -2528,22 +2537,22 @@ int MAIN(int argc, char *argv[]) { dds_write_set_batch(true); // FIXME: hack (the global batching flag is a hack anyway) { - char **ps = (char **) dds_alloc(sizeof(char *) * (uint32_t)(argc - os_get_optind())); - for (i = 0; i < (unsigned) (argc - os_get_optind()); i++) - ps[i] = expand_envvars(argv[(unsigned) os_get_optind() + i]); + char **ps = (char **) dds_alloc(sizeof(char *) * (uint32_t)(argc - optind)); + for (i = 0; i < (unsigned) (argc - optind); i++) + ps[i] = expand_envvars(argv[(unsigned) optind + i]); if (want_reader) { qos = dds_create_qos(); setqos_from_args(DDS_KIND_SUBSCRIBER, qos, nqsubscriber, qsubscriber); - sub = new_subscriber(qos, (unsigned) (argc - os_get_optind()), (const char **) ps); + sub = new_subscriber(qos, (unsigned) (argc - optind), (const char **) ps); dds_delete_qos(qos); } if (want_writer) { qos = dds_create_qos(); setqos_from_args(DDS_KIND_PUBLISHER, qos, nqpublisher, qpublisher); - pub = new_publisher(qos, (unsigned) (argc - os_get_optind()), (const char **) ps); + pub = new_publisher(qos, (unsigned) (argc - optind), (const char **) ps); dds_delete_qos(qos); } - for (i = 0; i < (unsigned) (argc - os_get_optind()); i++) + for (i = 0; i < (unsigned) (argc - optind); i++) dds_free(ps[i]); dds_free(ps); } @@ -2678,9 +2687,9 @@ int MAIN(int argc, char *argv[]) { termcond = dds_create_waitset(dp); // Waitset serves as GuardCondition here. error_abort(termcond, "dds_create_waitset failed"); - os_threadAttr attr; - os_threadAttrInit(&attr); - os_result osres; + ddsrt_threadattr_t attr; + ddsrt_threadattr_init(&attr); + dds_retcode_t osres; if (want_writer) { for (i = 0; i <= specidx; i++) { @@ -2689,7 +2698,7 @@ int MAIN(int argc, char *argv[]) { case WRM_NONE: break; case WRM_AUTO: - osres = os_threadCreate(&spec[i].wrtid, "pubthread_auto", &attr, pubthread_auto, &spec[i].wr); + osres = ddsrt_thread_create(&spec[i].wrtid, "pubthread_auto", &attr, pubthread_auto, &spec[i].wr); os_error_exit(osres, "Error: cannot create thread pubthread_auto"); break; case WRM_INPUT: @@ -2708,18 +2717,18 @@ int MAIN(int argc, char *argv[]) { } if (wrspecs) { /* start with first wrspec */ wrspecs = wrspecs->next; - osres = os_threadCreate(&inptid, "pubthread", &attr, pubthread, wrspecs); + osres = ddsrt_thread_create(&inptid, "pubthread", &attr, pubthread, wrspecs); os_error_exit(osres, "Error: cannot create thread pubthread"); } } else if (dur > 0) { /* note: abusing inptid */ - osres = os_threadCreate(&inptid, "autotermthread", &attr, autotermthread, NULL); + osres = ddsrt_thread_create(&inptid, "autotermthread", &attr, autotermthread, NULL); os_error_exit(osres, "Error: cannot create thread autotermthread"); } for (i = 0; i <= specidx; i++) { if (spec[i].rd.mode != MODE_NONE) { spec[i].rd.idx = i; - osres = os_threadCreate(&spec[i].rdtid, "subthread", &attr, subthread, &spec[i].rd); + osres = ddsrt_thread_create(&spec[i].rdtid, "subthread", &attr, subthread, &spec[i].rd); os_error_exit(osres, "Error: cannot create thread subthread"); } } @@ -2727,13 +2736,13 @@ int MAIN(int argc, char *argv[]) { if (want_writer || dur > 0) { int term_called = 0; if (!want_writer || wrspecs) { - (void)os_threadWaitExit(inptid, NULL); + (void)ddsrt_thread_join(inptid, NULL); term_called = 1; terminate(); } for (i = 0; i <= specidx; i++) { if (spec[i].wr.mode == WRM_AUTO) - (void)os_threadWaitExit(spec[i].wrtid, NULL); + (void)ddsrt_thread_join(spec[i].wrtid, NULL); } if (!term_called) terminate(); @@ -2744,7 +2753,7 @@ int MAIN(int argc, char *argv[]) { exitcode = 0; for (i = 0; i <= specidx; i++) { if (spec[i].rd.mode != MODE_NONE) { - (void)os_threadWaitExit(spec[i].rdtid, &ret); + (void)ddsrt_thread_join(spec[i].rdtid, &ret); if ((uintptr_t) ret > exitcode) exitcode = (uintptr_t) ret; } @@ -2793,6 +2802,6 @@ int MAIN(int argc, char *argv[]) { if (sleep_at_end) { dds_sleepfor(DDS_SECS(sleep_at_end)); } - os_mutexDestroy(&output_mutex); + ddsrt_mutex_destroy(&output_mutex); return (int) exitcode; } diff --git a/src/tools/pubsub/testtype.h b/src/tools/pubsub/testtype.h index 76bb54b..dd34d93 100644 --- a/src/tools/pubsub/testtype.h +++ b/src/tools/pubsub/testtype.h @@ -18,8 +18,8 @@ Vortex Lite: V2.1.0 *****************************************************************/ - -#include "ddsc/dds.h" +#include +#include "dds/dds.h" #ifndef _DDSL_TESTTYPE_H_ #define _DDSL_TESTTYPE_H_ diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 109a2db..00bc5ac 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -11,22 +11,27 @@ # include (GenerateExportHeader) -#PREPEND(srcs_platform ${platform} os_platform_errno.c os_platform_heap.c os_platform_init.c os_platform_process.c os_platform_socket.c os_platform_stdlib.c os_platform_sync.c os_platform_thread.c os_platform_time.c) -#add_library(util ut_avl.c ut_crc.c ut_expand_envvars.c ut_fibheap.c ut_handleserver.c ut_hopscotch.c ut_thread_pool.c ut_xmlparser.c) - PREPEND(srcs_util "${CMAKE_CURRENT_SOURCE_DIR}/src" ut_avl.c ut_crc.c ut_expand_envvars.c ut_fibheap.c ut_handleserver.c ut_hopscotch.c ut_thread_pool.c ut_xmlparser.c) -add_library(util ${srcs_util}) -generate_export_header(util EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/exports/util/ut_export.h") -target_link_libraries(util PUBLIC OSAPI) +add_library(util ${srcs_util}) set_property(TARGET util PROPERTY POSITION_INDEPENDENT_CODE TRUE) +generate_export_header( + util + BASE_NAME + dds + EXPORT_FILE_NAME + "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h") + +# util must NOT link with ddsrt to avoid duplicate symbols in ddsc! +# ddsrt include directories are required though. target_include_directories( - util PUBLIC - "$" - "$" - "$" - "$") + util + PUBLIC + "$" + PRIVATE + "$" + "$>") # TODO: improve test inclusion. if((BUILD_TESTING) AND ((NOT DEFINED MSVC_VERSION) OR (MSVC_VERSION GREATER "1800"))) diff --git a/src/util/include/dds/util/ut_avl.h b/src/util/include/dds/util/ut_avl.h new file mode 100644 index 0000000..8d3b76b --- /dev/null +++ b/src/util/include/dds/util/ut_avl.h @@ -0,0 +1,359 @@ +/* + * 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 UT_AVL_H +#define UT_AVL_H + +/* The tree library never performs memory allocations or deallocations internally. + + - Treedef_t: defines the properties of the tree, offsets, + comparison functions, augmented structures, flags -- these are + related to the code/data structure in which the tree is embedded, + and in nearly all cases known at compile time. + - avlTree_t: represents the tree, i.e., pointer to the root. + - avlNode_t: contains the administrative data for a single node in + the tree. + + For a tree node: + struct T { + avlNode_t avlnode; + int key; + }; + by definition, avlnodeoffset == offsetof(struct T, avlnode) and + keyoffset = offsetof(struct T, key). The user of the library only + ever deals in pointers to (in this case) struct T, never with + pointers to the avlNode_t, and the compare function operations on + pointers to keys, in this case pointers to "int"s. If you wish, you + can also do: keyoffset = 0, in which case the compare function + would be operating on struct T's. + + The compare function is assumed to behave just like all compare + functions in the C library: < 0, =0, >0 for left argument less + than, equal to or greater than the right argument. + + The "augment" function is automatically called whenever some of the + children of a node change, as well as when the "augment" function + has been called on some of the children. It allows you to maintain + a "summary" of the subtree -- currently only used in ddsi2e, in one + spot. + + Trees come in various "variants", configured through "treedef" + flags: + - direct/indirect key: direct meaning the key value is embedded in + the structure containing the avlNode_t, indirect meaning a + pointer to the key value is. The compare function doesn't deal + with tree nodes, but with key values. + - re-entrant: in the style of the C library, meaning, the + comparison function gets a user-supplied 3rd argument (in + particular used by mmstat). + - unique keys/duplicate keys: when keys must be unique, some + optimizations apply; it is up to the caller to ensure one doesn't + violate the uniqueness of the keys (it'll happily crash in insert + if you don't); when duplicate keys are allowed, a forward scan of + the tree will visit them in the order of insertion. + + For a tree node: + struct T { + avlnode_t avlnode; + char *key; + }; + you could set the "indirect" flag, and then you simply use + strcmp(), avoiding the need for passing templates in looking up key + values. Much nicer. + + There is also an orthogonal variant that is enforced through the + type system -- note that would be possible for all of the above as + well, but the number of cases simply explodes and none of the above + flags affects the dynamically changing data structures (just the + tree definition), unlike this one. + + - the "C" variant keeps track of the number of nodes in the tree to + support a "count" operation in O(1) time, but is otherwise + identical. + + The various initializer macros and TreedefInit functions should + make sense with this. + + All functions for looking up nodes return NULL if there is no node + satisfying the requirements. + + - Init: initializes a tree (really just: root = NULL, perhaps count = 0) + - Free: calls "freefun" on each node, which may free the node + - FreeArg: as "Free", but with an extra, user-supplied, argument + - Root: returns the root node + - Lookup: returns a node with key value "key" (ref allowdups flag) + - LookupIPath: like Lookup, but also filling an IPath_t structure + for efficient insertion in case of a failed lookup (or inserting + duplicates) + - LookupDPath: like Lookup, but also filling a DPath_t structure + that helps with deleting a node + - LookupPredEq: locates the node with the greatest key value <= "key" + - LookupSuccEq: similar, but smallest key value >= "key" + - LookupPred: similar, < "key" + - LookupSucc: similar, > "key" + - Insert: convenience function: LookupIPath ; InsertIPath + - Delete: convenience function: LookupDPath ; DeleteDPath + - InsertIPath: insert node based on the "path" obtained from LookupIPath + - DeleteDPath: delete node, using information in "path" to do so efficiently + - SwapNode: replace "oldn" by "newn" without modifying the tree + structure (the key need not be equal, but must be + FindPred(oldn).key < newn.key < FindSucc(oldn).key, where a + non-existing predecessor has key -inf and a non-existing + successor has key +inf, and where it is understood that the < + operator becomes <= if allowdups is set + - AugmentUpdate: to be called when something in "node" changes that + affects the subtree "summary" computed by the configured + "augment" function + - IsEmpty: returns 1 if tree is empty, 0 if not + - IsSingleton: returns 1 if tree contains exactly one node, 0 if not + - FindMin: returns the node with the smallest key value in the tree + - FindMax: similar, largest key value + - FindPred: preceding node in in-order treewalk + - FindSucc: similar, following node + + - Walk: calls "f" with user-supplied argument "a" once for each + node, starting at FindMin and ending at FindMax + - ConstWalk: same, but with a const tree + - WalkRange: like Walk, but only visiting nodes with key values in + range [min,max] (that's inclusive) + - ConstWalkRange: same, but with a const tree + - WalkRangeReverse: like WalkRange, but in the reverse direction + - ConstWalkRangeReverse: same, but with a const tree + - IterFirst: starts forward iteration, starting at (and returning) FindMin + - IterSuccEq: similar, starting at LookupSuccEq + - IterSucc: similar, starting at LookupSucc + - IterNext: returns FindSucc(last returned node); may not be called + if preceding IterXXX call on same "iter" returned NULL + + That's all there is to it. + + Note that all calls to Walk(f,a) can be rewritten as: + for(n=IterFirst(&it); n; n=IterNext(&it)) { f(n,a) } + or as + for(n=FindMin(); n; n=FindSucc(n)) { f(n,a) } + + The walk functions and iterators may not alter the tree + structure. If that is desired, the latter can easily be rewritten + as: + n=FindMin() ; while(n) { nn=FindSucc(n); f(n,a); n=nn } + because FindMin/FindSucc doesn't store any information to allow + fast processing. That'll allow every operation, with the obvious + exception of f(n) calling Delete(FindSucc(n)). + + Currently, all trees maintain parent pointers, but it may be worth + doing a separate set without it, as it reduces the size of + avlNode_t. But in that case, the FindMin/FindSucc option would no + longer be a reasonable option because it would be prohibitively + expensive, whereas the IterFirst/IterNext option are alway + efficiently. If one were to do a threaded tree variant, the + implemetantion of IterFirst/IterNext would become absolute trivial + and faster still, but at the cost of significantly more overhead in + memory and updates. */ + +#include +#include + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +#define UT_AVL_MAX_TREEHEIGHT (12 * sizeof (void *)) + +typedef int (*ut_avlCompare_t) (const void *a, const void *b); +typedef int (*ut_avlCompare_r_t) (const void *a, const void *b, void *arg); +typedef void (*ut_avlAugment_t) (void *node, const void *left, const void *right); +typedef void (*ut_avlWalk_t) (void *node, void *arg); +typedef void (*ut_avlConstWalk_t) (const void *node, void *arg); + +typedef struct ut_avlNode { + struct ut_avlNode *cs[2]; /* 0 = left, 1 = right */ + struct ut_avlNode *parent; + int height; +} ut_avlNode_t; + +#define UT_AVL_TREEDEF_FLAG_INDKEY 1 +#define UT_AVL_TREEDEF_FLAG_R 2 +#define UT_AVL_TREEDEF_FLAG_ALLOWDUPS 4 + +typedef struct ut_avlTreedef { +#if defined (__cplusplus) + ut_avlTreedef() {} +#endif + size_t avlnodeoffset; + size_t keyoffset; + union { + ut_avlCompare_t comparekk; + ut_avlCompare_r_t comparekk_r; + } u; + ut_avlAugment_t augment; + uint32_t flags; + void *cmp_arg; /* for _r variant */ +} ut_avlTreedef_t; + +typedef struct ut_avlCTreedef { + ut_avlTreedef_t t; +} ut_avlCTreedef_t; + +typedef struct ut_avlTree { + ut_avlNode_t *root; +} ut_avlTree_t; + +typedef struct ut_avlCTree { + ut_avlTree_t t; + size_t count; +} ut_avlCTree_t; + +typedef struct ut_avlPath { + int depth; /* total depth of path */ + int pnodeidx; + ut_avlNode_t *parent; /* (nodeidx == 0 ? NULL : *(path[nodeidx-1])) */ + ut_avlNode_t **pnode[UT_AVL_MAX_TREEHEIGHT]; +} ut_avlPath_t; + +typedef struct ut_avlIPath { + ut_avlPath_t p; +} ut_avlIPath_t; + +typedef struct ut_avlDPath { + ut_avlPath_t p; +} ut_avlDPath_t; + +typedef struct ut_avlIter { + const ut_avlTreedef_t *td; + ut_avlNode_t *right; + ut_avlNode_t **todop; + ut_avlNode_t *todo[1+UT_AVL_MAX_TREEHEIGHT]; +} ut_avlIter_t; + +typedef struct ut_avlCIter { + ut_avlIter_t t; +} ut_avlCIter_t; + +/* avlnodeoffset and keyoffset must both be in [0,2**31-1] */ +#define UT_AVL_TREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), 0, 0 } +#define UT_AVL_TREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY, 0 } +#define UT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 } +#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 } +#define UT_AVL_TREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_R, (cmparg) } +#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_R, (cmparg) } +#define UT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_R|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) } +#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_R|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) } + +/* Not maintaining # nodes */ + +DDS_EXPORT void ut_avlTreedefInit (ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_t comparekk, ut_avlAugment_t augment, uint32_t flags) ddsrt_nonnull((1,4)); +DDS_EXPORT void ut_avlTreedefInit_r (ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_r_t comparekk_r, void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) ddsrt_nonnull((1,4)); + +DDS_EXPORT void ut_avlInit (const ut_avlTreedef_t *td, ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlFree (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void (*freefun) (void *node)) ddsrt_nonnull((1,2)); +DDS_EXPORT void ut_avlFreeArg (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void (*freefun) (void *node, void *arg), void *arg) ddsrt_nonnull((1,2)); + +DDS_EXPORT void *ut_avlRoot (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlRootNonEmpty (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookup (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupIPath (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlIPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupDPath (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlDPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupPredEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupSuccEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupPred (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlLookupSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) ddsrt_nonnull_all; + +DDS_EXPORT void ut_avlInsert (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *node) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlDelete (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *node) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlInsertIPath (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *node, ut_avlIPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlDeleteDPath (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *node, ut_avlDPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlSwapNode (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *oldn, void *newn) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlAugmentUpdate (const ut_avlTreedef_t *td, void *node) ddsrt_nonnull_all; + +DDS_EXPORT int ut_avlIsEmpty (const ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT int ut_avlIsSingleton (const ut_avlTree_t *tree) ddsrt_nonnull_all; + +DDS_EXPORT void *ut_avlFindMin (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlFindMax (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlFindPred (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *vnode) ddsrt_nonnull((1,2)); +DDS_EXPORT void *ut_avlFindSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *vnode) ddsrt_nonnull((1,2)); + +DDS_EXPORT void ut_avlWalk (const ut_avlTreedef_t *td, ut_avlTree_t *tree, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3)); +DDS_EXPORT void ut_avlConstWalk (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3)); +DDS_EXPORT void ut_avlWalkRange (const ut_avlTreedef_t *td, ut_avlTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); +DDS_EXPORT void ut_avlConstWalkRange (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); +DDS_EXPORT void ut_avlWalkRangeReverse (const ut_avlTreedef_t *td, ut_avlTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3)); +DDS_EXPORT void ut_avlConstWalkRangeReverse (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3)); + +DDS_EXPORT void *ut_avlIterFirst (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlIterSuccEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlIterSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlIterNext (ut_avlIter_t *iter) ddsrt_nonnull_all; + +/* Maintaining # nodes */ + +#define UT_AVL_CTREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER (avlnodeoffset, keyoffset, comparekk, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY (avlnodeoffset, keyoffset, comparekk, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } +#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } + +DDS_EXPORT void ut_avlCTreedefInit (ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_t comparekk, ut_avlAugment_t augment, uint32_t flags) ddsrt_nonnull((1,4)); +DDS_EXPORT void ut_avlCTreedefInit_r (ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_r_t comparekk_r, void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) ddsrt_nonnull((1,4)); + +DDS_EXPORT void ut_avlCInit (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCFree (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void (*freefun) (void *node)) ddsrt_nonnull((1,2)); +DDS_EXPORT void ut_avlCFreeArg (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void (*freefun) (void *node, void *arg), void *arg) ddsrt_nonnull((1,2)); + +DDS_EXPORT void *ut_avlCRoot (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCRootNonEmpty (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookup (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupIPath (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key, ut_avlIPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupDPath (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key, ut_avlDPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupPredEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupSuccEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupPred (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCLookupSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) ddsrt_nonnull_all; + +DDS_EXPORT void ut_avlCInsert (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCDelete (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCInsertIPath (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node, ut_avlIPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCDeleteDPath (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node, ut_avlDPath_t *path) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCSwapNode (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *oldn, void *newn) ddsrt_nonnull_all; +DDS_EXPORT void ut_avlCAugmentUpdate (const ut_avlCTreedef_t *td, void *node) ddsrt_nonnull_all; + +DDS_EXPORT int ut_avlCIsEmpty (const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT int ut_avlCIsSingleton (const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT size_t ut_avlCCount (const ut_avlCTree_t *tree) ddsrt_nonnull_all; + +DDS_EXPORT void *ut_avlCFindMin (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCFindMax (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCFindPred (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *vnode) ddsrt_nonnull((1,2)); +DDS_EXPORT void *ut_avlCFindSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *vnode) ddsrt_nonnull((1,2)); + +DDS_EXPORT void ut_avlCWalk (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3)); +DDS_EXPORT void ut_avlCConstWalk (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3)); +DDS_EXPORT void ut_avlCWalkRange (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); +DDS_EXPORT void ut_avlCConstWalkRange (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); +DDS_EXPORT void ut_avlCWalkRangeReverse (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); +DDS_EXPORT void ut_avlCConstWalkRangeReverse (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) ddsrt_nonnull((1,2,3,4,5)); + +DDS_EXPORT void *ut_avlCIterFirst (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCIterSuccEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCIterSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter, const void *key) ddsrt_nonnull_all; +DDS_EXPORT void *ut_avlCIterNext (ut_avlCIter_t *iter) ddsrt_nonnull_all; + +#if defined (__cplusplus) +} +#endif + +#endif /* UT_AVL_H */ diff --git a/src/util/include/util/ut_crc.h b/src/util/include/dds/util/ut_crc.h similarity index 72% rename from src/util/include/util/ut_crc.h rename to src/util/include/dds/util/ut_crc.h index 4f97c13..144009f 100644 --- a/src/util/include/util/ut_crc.h +++ b/src/util/include/dds/util/ut_crc.h @@ -12,16 +12,17 @@ #ifndef UT_CRC_H #define UT_CRC_H -#include "os/os.h" -#include "util/ut_export.h" +#include +#include + +#include "dds/export.h" +#include "dds/ddsrt/attributes.h" #if defined (__cplusplus) extern "C" { #endif -/* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - -UTIL_EXPORT uint32_t ut_crcCalculate (const void *buf, size_t length) __nonnull_all__ __attribute_pure__; +DDS_EXPORT uint32_t ut_crcCalculate (const void *buf, size_t length) ddsrt_nonnull_all ddsrt_attribute_pure; #if defined (__cplusplus) } diff --git a/src/util/include/util/ut_expand_envvars.h b/src/util/include/dds/util/ut_expand_envvars.h similarity index 81% rename from src/util/include/util/ut_expand_envvars.h rename to src/util/include/dds/util/ut_expand_envvars.h index 78f4618..c101679 100644 --- a/src/util/include/util/ut_expand_envvars.h +++ b/src/util/include/dds/util/ut_expand_envvars.h @@ -12,18 +12,17 @@ #ifndef UT_EXPAND_ENVVARS_H #define UT_EXPAND_ENVVARS_H -#include "os/os.h" -#include "util/ut_export.h" +#include "dds/export.h" #if defined (__cplusplus) extern "C" { #endif /* Expands ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms, but not $X */ - UTIL_EXPORT char *ut_expand_envvars(const char *string); + DDS_EXPORT char *ut_expand_envvars(const char *string); /* Expands $X, ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms, $ and \ can be escaped with \ */ - UTIL_EXPORT char *ut_expand_envvars_sh(const char *string); + DDS_EXPORT char *ut_expand_envvars_sh(const char *string); #if defined (__cplusplus) } diff --git a/src/util/include/util/ut_fibheap.h b/src/util/include/dds/util/ut_fibheap.h similarity index 54% rename from src/util/include/util/ut_fibheap.h rename to src/util/include/dds/util/ut_fibheap.h index 7d24a41..d02b9c8 100644 --- a/src/util/include/util/ut_fibheap.h +++ b/src/util/include/dds/util/ut_fibheap.h @@ -12,8 +12,9 @@ #ifndef UT_FIBHEAP_H #define UT_FIBHEAP_H -#include "os/os.h" -#include "util/ut_export.h" +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -37,14 +38,14 @@ typedef struct ut_fibheap { #define UT_FIBHEAPDEF_INITIALIZER(offset, cmp) { (offset), (cmp) } -UTIL_EXPORT void ut_fibheapDefInit (ut_fibheapDef_t *fhdef, uintptr_t offset, int (*cmp) (const void *va, const void *vb)); -UTIL_EXPORT void ut_fibheapInit (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh); -UTIL_EXPORT void *ut_fibheapMin (const ut_fibheapDef_t *fhdef, const ut_fibheap_t *fh); -UTIL_EXPORT void ut_fibheapMerge (const ut_fibheapDef_t *fhdef, ut_fibheap_t *a, ut_fibheap_t *b); -UTIL_EXPORT void ut_fibheapInsert (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); -UTIL_EXPORT void ut_fibheapDelete (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); -UTIL_EXPORT void *ut_fibheapExtractMin (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh); -UTIL_EXPORT void ut_fibheapDecreaseKey (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); /* to be called AFTER decreasing the key */ +DDS_EXPORT void ut_fibheapDefInit (ut_fibheapDef_t *fhdef, uintptr_t offset, int (*cmp) (const void *va, const void *vb)); +DDS_EXPORT void ut_fibheapInit (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh); +DDS_EXPORT void *ut_fibheapMin (const ut_fibheapDef_t *fhdef, const ut_fibheap_t *fh); +DDS_EXPORT void ut_fibheapMerge (const ut_fibheapDef_t *fhdef, ut_fibheap_t *a, ut_fibheap_t *b); +DDS_EXPORT void ut_fibheapInsert (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); +DDS_EXPORT void ut_fibheapDelete (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); +DDS_EXPORT void *ut_fibheapExtractMin (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh); +DDS_EXPORT void ut_fibheapDecreaseKey (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh, const void *vnode); /* to be called AFTER decreasing the key */ #if defined (__cplusplus) } diff --git a/src/util/include/util/ut_handleserver.h b/src/util/include/dds/util/ut_handleserver.h similarity index 79% rename from src/util/include/util/ut_handleserver.h rename to src/util/include/dds/util/ut_handleserver.h index ad43f7e..f0a91e0 100644 --- a/src/util/include/util/ut_handleserver.h +++ b/src/util/include/dds/util/ut_handleserver.h @@ -12,8 +12,11 @@ #ifndef UT_HANDLESERVER_H #define UT_HANDLESERVER_H -#include "os/os.h" -#include "util/ut_export.h" +#include +#include + +#include "dds/export.h" +#include "dds/ddsrt/time.h" #if defined (__cplusplus) extern "C" { @@ -51,7 +54,7 @@ extern "C" { /* * Some error return values. */ -typedef _Return_type_success_(return == 0) enum ut_handle_retcode_t { +typedef enum ut_handle_retcode_t { UT_HANDLE_OK = 0, UT_HANDLE_ERROR = -1, /* General error. */ UT_HANDLE_CLOSED = -2, /* Handle has been previously close. */ @@ -76,7 +79,7 @@ typedef _Return_type_success_(return == 0) enum ut_handle_retcode_t { * * FYI: the entity id within DDSI is also 24 bits... */ -typedef _Return_type_success_(return > 0) int32_t ut_handle_t; +typedef int32_t ut_handle_t; /* * Handle bits @@ -103,13 +106,13 @@ typedef _Return_type_success_(return > 0) int32_t ut_handle_t; * This handlelink is invalid after the related handle is deleted and should * never be used afterwards. */ -_Return_type_success_(return != NULL) struct ut_handlelink; +struct ut_handlelink; /* * Initialize handleserver singleton. */ -_Check_return_ UTIL_EXPORT ut_handle_retcode_t +DDS_EXPORT ut_handle_retcode_t ut_handleserver_init(void); @@ -117,7 +120,7 @@ ut_handleserver_init(void); * Destroy handleserver singleton. * The handleserver is destroyed when fini() is called as often as init(). */ -UTIL_EXPORT void +DDS_EXPORT void ut_handleserver_fini(void); @@ -139,12 +142,8 @@ ut_handleserver_fini(void); * Valid handle when returned value is positive. * Otherwise negative handle is returned. */ -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Post_satisfies_((return & UT_HANDLE_KIND_MASK) == kind) -_Must_inspect_result_ UTIL_EXPORT ut_handle_t -ut_handle_create( - _In_ int32_t kind, - _In_ void *arg); +DDS_EXPORT ut_handle_t +ut_handle_create(int32_t kind, void *arg); /* @@ -153,10 +152,8 @@ ut_handle_create( * * This is a noop on an already closed handle. */ -UTIL_EXPORT void -ut_handle_close( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link); +DDS_EXPORT void +ut_handle_close(ut_handle_t hdl, struct ut_handlelink *link); /* @@ -168,11 +165,11 @@ ut_handle_close( * It will delete the information when there are no more active claims. It'll * block when necessary to wait for all possible claims to be released. */ -_Check_return_ UTIL_EXPORT ut_handle_retcode_t +DDS_EXPORT ut_handle_retcode_t ut_handle_delete( - _In_ ut_handle_t hdl, - _Inout_opt_ _Post_invalid_ struct ut_handlelink *link, - _In_ os_time timeout); + ut_handle_t hdl, + struct ut_handlelink *link, + dds_time_t timeout); /* @@ -180,12 +177,11 @@ ut_handle_delete( * * Returns OK when valid. */ -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Check_return_ ut_handle_retcode_t +ut_handle_retcode_t ut_handle_status( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link, - _In_ int32_t kind); + ut_handle_t hdl, + struct ut_handlelink *link, + int32_t kind); /* @@ -194,22 +190,21 @@ ut_handle_status( * * Returns OK when succeeded. */ -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Check_return_ UTIL_EXPORT ut_handle_retcode_t +DDS_EXPORT ut_handle_retcode_t ut_handle_claim( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link, - _In_ int32_t kind, - _Out_opt_ void **arg); + ut_handle_t hdl, + struct ut_handlelink *link, + int32_t kind, + void **arg); /* * The active claims count is decreased. */ -UTIL_EXPORT void +DDS_EXPORT void ut_handle_release( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link); + ut_handle_t hdl, + struct ut_handlelink *link); /* @@ -221,19 +216,19 @@ ut_handle_release( * break of your process and release the handle, making the deletion * possible. */ -_Check_return_ UTIL_EXPORT bool +DDS_EXPORT bool ut_handle_is_closed( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link); + ut_handle_t hdl, + struct ut_handlelink *link); /* * This will get the link of the handle, which can be used for performance * increase. */ -_Must_inspect_result_ UTIL_EXPORT struct ut_handlelink* +DDS_EXPORT struct ut_handlelink* ut_handle_get_link( - _In_ ut_handle_t hdl); + ut_handle_t hdl); #if defined (__cplusplus) } diff --git a/src/util/include/dds/util/ut_hopscotch.h b/src/util/include/dds/util/ut_hopscotch.h new file mode 100644 index 0000000..9c632a8 --- /dev/null +++ b/src/util/include/dds/util/ut_hopscotch.h @@ -0,0 +1,110 @@ +/* + * 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 UT_HOPSCOTCH_H +#define UT_HOPSCOTCH_H + +#include + +#include "dds/export.h" + +#if defined (__cplusplus) +extern "C" { +#endif + +#if __STDC_VERSION__ >= 199901L +#define UT_HH_RESTRICT restrict +#else +#define UT_HH_RESTRICT +#endif + +/* Concurrent version */ +struct ut_chh; +struct ut_chhBucket; +struct ut_chhIter { + struct ut_chhBucket *bs; + uint32_t size; + uint32_t cursor; +}; + +/* + * The hopscotch hash table is dependent on a proper functioning hash. + * If the hash function generates a lot of hash collisions, then it will + * not be able to handle that by design. + * It is capable of handling some collisions, but not more than 32 per + * bucket (less, when other hash values are clustered around the + * collision value). + * When proper distributed hash values are generated, then hopscotch + * works nice and quickly. + */ +typedef uint32_t (*ut_hhHash_fn) (const void *); + +/* + * Hopscotch needs to be able to compare two elements. + * Returns 0 when not equal. + */ +typedef int (*ut_hhEquals_fn) (const void *, const void *); + +/* + * Hopscotch is will resize its internal buckets list when needed. It will + * call this garbage collection function with the old buckets list. The + * caller has to delete the list when it deems it safe to do so. + */ +typedef void (*ut_hhBucketsGc_fn) (void *); + +DDS_EXPORT struct ut_chh *ut_chhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals, ut_hhBucketsGc_fn gc_buckets); +DDS_EXPORT void ut_chhFree (struct ut_chh * UT_HH_RESTRICT hh); +DDS_EXPORT void *ut_chhLookup (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); +DDS_EXPORT int ut_chhRemove (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT void ut_chhEnumUnsafe (struct ut_chh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ +void *ut_chhIterFirst (struct ut_chh * UT_HH_RESTRICT rt, struct ut_chhIter *it); +void *ut_chhIterNext (struct ut_chhIter *it); + +/* Sequential version */ +struct ut_hh; + +struct ut_hhIter { + struct ut_hh *hh; + uint32_t cursor; +}; + +DDS_EXPORT struct ut_hh *ut_hhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals); +DDS_EXPORT void ut_hhFree (struct ut_hh * UT_HH_RESTRICT hh); +DDS_EXPORT void *ut_hhLookup (const struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT int ut_hhAdd (struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); +DDS_EXPORT int ut_hhRemove (struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT void ut_hhEnum (struct ut_hh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ +DDS_EXPORT void *ut_hhIterFirst (struct ut_hh * UT_HH_RESTRICT rt, struct ut_hhIter * UT_HH_RESTRICT iter); /* may delete nodes */ +DDS_EXPORT void *ut_hhIterNext (struct ut_hhIter * UT_HH_RESTRICT iter); + +/* Sequential version, embedded data */ +struct ut_ehh; + +struct ut_ehhIter { + struct ut_ehh *hh; + uint32_t cursor; +}; + +DDS_EXPORT struct ut_ehh *ut_ehhNew (size_t elemsz, uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals); +DDS_EXPORT void ut_ehhFree (struct ut_ehh * UT_HH_RESTRICT hh); +DDS_EXPORT void *ut_ehhLookup (const struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT int ut_ehhAdd (struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); +DDS_EXPORT int ut_ehhRemove (struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); +DDS_EXPORT void ut_ehhEnum (struct ut_ehh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ +DDS_EXPORT void *ut_ehhIterFirst (struct ut_ehh * UT_HH_RESTRICT rt, struct ut_ehhIter * UT_HH_RESTRICT iter); /* may delete nodes */ +DDS_EXPORT void *ut_ehhIterNext (struct ut_ehhIter * UT_HH_RESTRICT iter); + +#if defined (__cplusplus) +} +#endif + +#endif diff --git a/src/util/include/util/ut_thread_pool.h b/src/util/include/dds/util/ut_thread_pool.h similarity index 78% rename from src/util/include/util/ut_thread_pool.h rename to src/util/include/dds/util/ut_thread_pool.h index cd093c5..50863a9 100644 --- a/src/util/include/util/ut_thread_pool.h +++ b/src/util/include/dds/util/ut_thread_pool.h @@ -12,15 +12,16 @@ #ifndef UT_THREAD_POOL_H #define UT_THREAD_POOL_H -#include "os/os.h" -#include "util/ut_export.h" +#include + +#include "dds/export.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" #if defined (__cplusplus) extern "C" { #endif -/* !!!!!!!!NOTE From here no more includes are allowed!!!!!!! */ - typedef struct ut_thread_pool_s *ut_thread_pool; /* @@ -30,31 +31,31 @@ typedef struct ut_thread_pool_s *ut_thread_pool; on demand up to max_threads. */ -UTIL_EXPORT ut_thread_pool ut_thread_pool_new +DDS_EXPORT ut_thread_pool ut_thread_pool_new ( uint32_t threads, /* Initial number of threads in pool (can be 0) */ uint32_t max_threads, /* Maximum number of threads in pool (0 == infinite) */ uint32_t max_queue, /* Maximum number of queued requests (0 == infinite) */ - os_threadAttr * attr /* Attributes used to create pool threads (can be NULL) */ + ddsrt_threadattr_t * attr /* Attributes used to create pool threads (can be NULL) */ ); /* ut_thread_pool_free: Frees pool, destroying threads. */ -UTIL_EXPORT void ut_thread_pool_free (ut_thread_pool pool); +DDS_EXPORT void ut_thread_pool_free (ut_thread_pool pool); /* ut_thread_pool_purge: Purge threads from pool back to initial set. */ -UTIL_EXPORT void ut_thread_pool_purge (ut_thread_pool pool); +DDS_EXPORT void ut_thread_pool_purge (ut_thread_pool pool); /* ut_thread_pool_submit: Submit a thread function and associated argument to be invoked by a thread from the pool. If no threads are available a new thread will be created on demand to handle the function unless the pool thread maximum has been reached, in which case the function is queued. - Note that if the pool queue has reached it's maximum os_resultBusy is returned. + Note that if the pool queue has reached it's maximum DDS_RETCODE_TRY_AGAIN is returned. */ -UTIL_EXPORT os_result ut_thread_pool_submit +DDS_EXPORT dds_retcode_t ut_thread_pool_submit ( ut_thread_pool pool, /* Thread pool instance */ void (*fn) (void *arg), /* Function to be invoked by thread from pool */ diff --git a/src/util/include/util/ut_xmlparser.h b/src/util/include/dds/util/ut_xmlparser.h similarity index 73% rename from src/util/include/util/ut_xmlparser.h rename to src/util/include/dds/util/ut_xmlparser.h index 3a3a3f7..2b9c7be 100644 --- a/src/util/include/util/ut_xmlparser.h +++ b/src/util/include/dds/util/ut_xmlparser.h @@ -12,8 +12,9 @@ #ifndef UT_XMLPARSER_H #define UT_XMLPARSER_H -#include "os/os.h" -#include "util/ut_export.h" +#include + +#include "dds/export.h" #if defined (__cplusplus) extern "C" { @@ -35,12 +36,12 @@ extern "C" { struct ut_xmlpState; - UTIL_EXPORT struct ut_xmlpState *ut_xmlpNewFile (FILE *fp, void *varg, const struct ut_xmlpCallbacks *cb); - UTIL_EXPORT struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const struct ut_xmlpCallbacks *cb); - UTIL_EXPORT void ut_xmlpFree (struct ut_xmlpState *st); - UTIL_EXPORT int ut_xmlpParse (struct ut_xmlpState *st); + DDS_EXPORT struct ut_xmlpState *ut_xmlpNewFile (FILE *fp, void *varg, const struct ut_xmlpCallbacks *cb); + DDS_EXPORT struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const struct ut_xmlpCallbacks *cb); + DDS_EXPORT void ut_xmlpFree (struct ut_xmlpState *st); + DDS_EXPORT int ut_xmlpParse (struct ut_xmlpState *st); - UTIL_EXPORT int ut_xmlUnescapeInsitu (char *buffer, size_t *n); + DDS_EXPORT int ut_xmlUnescapeInsitu (char *buffer, size_t *n); #if defined (__cplusplus) } diff --git a/src/util/include/util/ut_avl.h b/src/util/include/util/ut_avl.h deleted file mode 100644 index fec0107..0000000 --- a/src/util/include/util/ut_avl.h +++ /dev/null @@ -1,356 +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 UT_AVL_H -#define UT_AVL_H - -/* The tree library never performs memory allocations or deallocations internally. - - - Treedef_t: defines the properties of the tree, offsets, - comparison functions, augmented structures, flags -- these are - related to the code/data structure in which the tree is embedded, - and in nearly all cases known at compile time. - - avlTree_t: represents the tree, i.e., pointer to the root. - - avlNode_t: contains the administrative data for a single node in - the tree. - - For a tree node: - struct T { - avlNode_t avlnode; - int key; - }; - by definition, avlnodeoffset == offsetof(struct T, avlnode) and - keyoffset = offsetof(struct T, key). The user of the library only - ever deals in pointers to (in this case) struct T, never with - pointers to the avlNode_t, and the compare function operations on - pointers to keys, in this case pointers to "int"s. If you wish, you - can also do: keyoffset = 0, in which case the compare function - would be operating on struct T's. - - The compare function is assumed to behave just like all compare - functions in the C library: < 0, =0, >0 for left argument less - than, equal to or greater than the right argument. - - The "augment" function is automatically called whenever some of the - children of a node change, as well as when the "augment" function - has been called on some of the children. It allows you to maintain - a "summary" of the subtree -- currently only used in ddsi2e, in one - spot. - - Trees come in various "variants", configured through "treedef" - flags: - - direct/indirect key: direct meaning the key value is embedded in - the structure containing the avlNode_t, indirect meaning a - pointer to the key value is. The compare function doesn't deal - with tree nodes, but with key values. - - re-entrant: in the style of the C library, meaning, the - comparison function gets a user-supplied 3rd argument (in - particular used by mmstat). - - unique keys/duplicate keys: when keys must be unique, some - optimizations apply; it is up to the caller to ensure one doesn't - violate the uniqueness of the keys (it'll happily crash in insert - if you don't); when duplicate keys are allowed, a forward scan of - the tree will visit them in the order of insertion. - - For a tree node: - struct T { - avlnode_t avlnode; - char *key; - }; - you could set the "indirect" flag, and then you simply use - strcmp(), avoiding the need for passing templates in looking up key - values. Much nicer. - - There is also an orthogonal variant that is enforced through the - type system -- note that would be possible for all of the above as - well, but the number of cases simply explodes and none of the above - flags affects the dynamically changing data structures (just the - tree definition), unlike this one. - - - the "C" variant keeps track of the number of nodes in the tree to - support a "count" operation in O(1) time, but is otherwise - identical. - - The various initializer macros and TreedefInit functions should - make sense with this. - - All functions for looking up nodes return NULL if there is no node - satisfying the requirements. - - - Init: initializes a tree (really just: root = NULL, perhaps count = 0) - - Free: calls "freefun" on each node, which may free the node - - FreeArg: as "Free", but with an extra, user-supplied, argument - - Root: returns the root node - - Lookup: returns a node with key value "key" (ref allowdups flag) - - LookupIPath: like Lookup, but also filling an IPath_t structure - for efficient insertion in case of a failed lookup (or inserting - duplicates) - - LookupDPath: like Lookup, but also filling a DPath_t structure - that helps with deleting a node - - LookupPredEq: locates the node with the greatest key value <= "key" - - LookupSuccEq: similar, but smallest key value >= "key" - - LookupPred: similar, < "key" - - LookupSucc: similar, > "key" - - Insert: convenience function: LookupIPath ; InsertIPath - - Delete: convenience function: LookupDPath ; DeleteDPath - - InsertIPath: insert node based on the "path" obtained from LookupIPath - - DeleteDPath: delete node, using information in "path" to do so efficiently - - SwapNode: replace "oldn" by "newn" without modifying the tree - structure (the key need not be equal, but must be - FindPred(oldn).key < newn.key < FindSucc(oldn).key, where a - non-existing predecessor has key -inf and a non-existing - successor has key +inf, and where it is understood that the < - operator becomes <= if allowdups is set - - AugmentUpdate: to be called when something in "node" changes that - affects the subtree "summary" computed by the configured - "augment" function - - IsEmpty: returns 1 if tree is empty, 0 if not - - IsSingleton: returns 1 if tree contains exactly one node, 0 if not - - FindMin: returns the node with the smallest key value in the tree - - FindMax: similar, largest key value - - FindPred: preceding node in in-order treewalk - - FindSucc: similar, following node - - - Walk: calls "f" with user-supplied argument "a" once for each - node, starting at FindMin and ending at FindMax - - ConstWalk: same, but with a const tree - - WalkRange: like Walk, but only visiting nodes with key values in - range [min,max] (that's inclusive) - - ConstWalkRange: same, but with a const tree - - WalkRangeReverse: like WalkRange, but in the reverse direction - - ConstWalkRangeReverse: same, but with a const tree - - IterFirst: starts forward iteration, starting at (and returning) FindMin - - IterSuccEq: similar, starting at LookupSuccEq - - IterSucc: similar, starting at LookupSucc - - IterNext: returns FindSucc(last returned node); may not be called - if preceding IterXXX call on same "iter" returned NULL - - That's all there is to it. - - Note that all calls to Walk(f,a) can be rewritten as: - for(n=IterFirst(&it); n; n=IterNext(&it)) { f(n,a) } - or as - for(n=FindMin(); n; n=FindSucc(n)) { f(n,a) } - - The walk functions and iterators may not alter the tree - structure. If that is desired, the latter can easily be rewritten - as: - n=FindMin() ; while(n) { nn=FindSucc(n); f(n,a); n=nn } - because FindMin/FindSucc doesn't store any information to allow - fast processing. That'll allow every operation, with the obvious - exception of f(n) calling Delete(FindSucc(n)). - - Currently, all trees maintain parent pointers, but it may be worth - doing a separate set without it, as it reduces the size of - avlNode_t. But in that case, the FindMin/FindSucc option would no - longer be a reasonable option because it would be prohibitively - expensive, whereas the IterFirst/IterNext option are alway - efficiently. If one were to do a threaded tree variant, the - implemetantion of IterFirst/IterNext would become absolute trivial - and faster still, but at the cost of significantly more overhead in - memory and updates. */ - -#include "os/os.h" -#include "util/ut_export.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -#define UT_AVL_MAX_TREEHEIGHT (12 * sizeof (void *)) - -typedef int (*ut_avlCompare_t) (_In_ const void *a, _In_ const void *b); -typedef int (*ut_avlCompare_r_t) (_In_ const void *a, _In_ const void *b, _In_opt_ void *arg); -typedef void (*ut_avlAugment_t) (_Inout_ void *node, _In_opt_ const void *left, _In_opt_ const void *right); -typedef void (*ut_avlWalk_t) (_Inout_ void *node, _Inout_opt_ void *arg); -typedef void (*ut_avlConstWalk_t) (_In_ const void *node, _Inout_opt_ void *arg); - -typedef struct ut_avlNode { - struct ut_avlNode *cs[2]; /* 0 = left, 1 = right */ - struct ut_avlNode *parent; - int height; -} ut_avlNode_t; - -#define UT_AVL_TREEDEF_FLAG_INDKEY 1 -#define UT_AVL_TREEDEF_FLAG_R 2 -#define UT_AVL_TREEDEF_FLAG_ALLOWDUPS 4 - -typedef struct ut_avlTreedef { -#if defined (__cplusplus) - ut_avlTreedef() {} -#endif - size_t avlnodeoffset; - size_t keyoffset; - union { - ut_avlCompare_t comparekk; - ut_avlCompare_r_t comparekk_r; - } u; - ut_avlAugment_t augment; - uint32_t flags; - void *cmp_arg; /* for _r variant */ -} ut_avlTreedef_t; - -typedef struct ut_avlCTreedef { - ut_avlTreedef_t t; -} ut_avlCTreedef_t; - -typedef struct ut_avlTree { - ut_avlNode_t *root; -} ut_avlTree_t; - -typedef struct ut_avlCTree { - ut_avlTree_t t; - size_t count; -} ut_avlCTree_t; - -typedef struct ut_avlPath { - int depth; /* total depth of path */ - int pnodeidx; - ut_avlNode_t *parent; /* (nodeidx == 0 ? NULL : *(path[nodeidx-1])) */ - ut_avlNode_t **pnode[UT_AVL_MAX_TREEHEIGHT]; -} ut_avlPath_t; - -typedef struct ut_avlIPath { - ut_avlPath_t p; -} ut_avlIPath_t; - -typedef struct ut_avlDPath { - ut_avlPath_t p; -} ut_avlDPath_t; - -typedef struct ut_avlIter { - const ut_avlTreedef_t *td; - ut_avlNode_t *right; - ut_avlNode_t **todop; - ut_avlNode_t *todo[1+UT_AVL_MAX_TREEHEIGHT]; -} ut_avlIter_t; - -typedef struct ut_avlCIter { - ut_avlIter_t t; -} ut_avlCIter_t; - -/* avlnodeoffset and keyoffset must both be in [0,2**31-1] */ -#define UT_AVL_TREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), 0, 0 } -#define UT_AVL_TREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY, 0 } -#define UT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 } -#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, augment) { (avlnodeoffset), (keyoffset), { .comparekk = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, 0 } -#define UT_AVL_TREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_R, (cmparg) } -#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_R, (cmparg) } -#define UT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_R|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) } -#define UT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk_, cmparg, augment) { (avlnodeoffset), (keyoffset), { .comparekk_r = (comparekk_) }, (augment), UT_AVL_TREEDEF_FLAG_INDKEY|UT_AVL_TREEDEF_FLAG_R|UT_AVL_TREEDEF_FLAG_ALLOWDUPS, (cmparg) } - -/* Not maintaining # nodes */ - -UTIL_EXPORT void ut_avlTreedefInit (_Out_ ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_t comparekk, _In_opt_ ut_avlAugment_t augment, uint32_t flags) __nonnull((1,4)); -UTIL_EXPORT void ut_avlTreedefInit_r (_Out_ ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_r_t comparekk_r, _Inout_opt_ void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) __nonnull((1,4)); - -UTIL_EXPORT void ut_avlInit (_In_ const ut_avlTreedef_t *td, _Out_ ut_avlTree_t *tree) __nonnull_all__; -UTIL_EXPORT void ut_avlFree (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_avlTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node)) __nonnull((1,2)); -UTIL_EXPORT void ut_avlFreeArg (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_avlTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node, _Inout_opt_ void *arg), _Inout_opt_ void *arg) __nonnull((1,2)); - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlRoot (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) __nonnull_all__; -_Ret_notnull_ UTIL_EXPORT void *ut_avlRootNonEmpty (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookup (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) __nonnull_all__; - _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupIPath (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key, _Out_ ut_avlIPath_t *path) __nonnull_all__; - _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupDPath (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key, _Out_ ut_avlDPath_t *path) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupPredEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupSuccEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupPred (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlLookupSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) __nonnull_all__; - -UTIL_EXPORT void ut_avlInsert (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *node) __nonnull_all__; -UTIL_EXPORT void ut_avlDelete (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *node) __nonnull_all__; -UTIL_EXPORT void ut_avlInsertIPath (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlIPath_t *path) __nonnull_all__; -UTIL_EXPORT void ut_avlDeleteDPath (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlDPath_t *path) __nonnull_all__; -UTIL_EXPORT void ut_avlSwapNode (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *oldn, _Inout_ void *newn) __nonnull_all__; -UTIL_EXPORT void ut_avlAugmentUpdate (_In_ const ut_avlTreedef_t *td, _Inout_ void *node) __nonnull_all__; - -UTIL_EXPORT int ut_avlIsEmpty (_In_ const ut_avlTree_t *tree) __nonnull_all__; -UTIL_EXPORT int ut_avlIsSingleton (_In_ const ut_avlTree_t *tree) __nonnull_all__; - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlFindMin (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlFindMax (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlFindPred (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_opt_ const void *vnode) __nonnull((1,2)); -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlFindSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_opt_ const void *vnode) __nonnull((1,2)); - -UTIL_EXPORT void ut_avlWalk (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); -UTIL_EXPORT void ut_avlConstWalk (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); -UTIL_EXPORT void ut_avlWalkRange (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); -UTIL_EXPORT void ut_avlConstWalkRange (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); -UTIL_EXPORT void ut_avlWalkRangeReverse (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); -UTIL_EXPORT void ut_avlConstWalkRangeReverse (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlIterFirst (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlIterSuccEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlIterSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlIterNext (_Inout_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter) __nonnull_all__; - -/* Maintaining # nodes */ - -#define UT_AVL_CTREEDEF_INITIALIZER(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER (avlnodeoffset, keyoffset, comparekk, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY (avlnodeoffset, keyoffset, comparekk, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_R(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_R (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } -#define UT_AVL_CTREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS(avlnodeoffset, keyoffset, comparekk, cmparg, augment) { UT_AVL_TREEDEF_INITIALIZER_INDKEY_R_ALLOWDUPS (avlnodeoffset, keyoffset, comparekk, cmparg, augment) } - -UTIL_EXPORT void ut_avlCTreedefInit (_Out_ ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_t comparekk, _In_opt_ ut_avlAugment_t augment, uint32_t flags) __nonnull((1,4)); -UTIL_EXPORT void ut_avlCTreedefInit_r (_Out_ ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_r_t comparekk_r, _Inout_opt_ void *cmp_arg, _In_opt_ ut_avlAugment_t augment, uint32_t flags) __nonnull((1,4)); - -UTIL_EXPORT void ut_avlCInit (_In_ const ut_avlCTreedef_t *td, _Out_ ut_avlCTree_t *tree) __nonnull_all__; -UTIL_EXPORT void ut_avlCFree (_In_ const ut_avlCTreedef_t *td, _Inout_ _Post_invalid_ ut_avlCTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node)) __nonnull((1,2)); -UTIL_EXPORT void ut_avlCFreeArg (_In_ const ut_avlCTreedef_t *td, _Inout_ _Post_invalid_ ut_avlCTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node, _Inout_opt_ void *arg), _Inout_opt_ void *arg) __nonnull((1,2)); - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCRoot (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) __nonnull_all__; -_Ret_notnull_ UTIL_EXPORT void *ut_avlCRootNonEmpty (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookup (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) __nonnull_all__; - _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupIPath (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key, _Out_ ut_avlIPath_t *path) __nonnull_all__; - _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupDPath (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key, _Out_ ut_avlDPath_t *path) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupPredEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupSuccEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupPred (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCLookupSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) __nonnull_all__; - -UTIL_EXPORT void ut_avlCInsert (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node) __nonnull_all__; -UTIL_EXPORT void ut_avlCDelete (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node) __nonnull_all__; -UTIL_EXPORT void ut_avlCInsertIPath (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlIPath_t *path) __nonnull_all__; -UTIL_EXPORT void ut_avlCDeleteDPath (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlDPath_t *path) __nonnull_all__; -UTIL_EXPORT void ut_avlCSwapNode (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *oldn, _Inout_ void *newn) __nonnull_all__; -UTIL_EXPORT void ut_avlCAugmentUpdate (_In_ const ut_avlCTreedef_t *td, _Inout_ void *node) __nonnull_all__; - -UTIL_EXPORT int ut_avlCIsEmpty (_In_ const ut_avlCTree_t *tree) __nonnull_all__; -UTIL_EXPORT int ut_avlCIsSingleton (_In_ const ut_avlCTree_t *tree) __nonnull_all__; -UTIL_EXPORT size_t ut_avlCCount (_In_ const ut_avlCTree_t *tree) __nonnull_all__; - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCFindMin (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCFindMax (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCFindPred (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *vnode) __nonnull((1,2)); -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCFindSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *vnode) __nonnull((1,2)); - -UTIL_EXPORT void ut_avlCWalk (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); -UTIL_EXPORT void ut_avlCConstWalk (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3)); -UTIL_EXPORT void ut_avlCWalkRange (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); -UTIL_EXPORT void ut_avlCConstWalkRange (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); -UTIL_EXPORT void ut_avlCWalkRangeReverse (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); -UTIL_EXPORT void ut_avlCConstWalkRangeReverse (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) __nonnull((1,2,3,4,5)); - -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCIterFirst (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCIterSuccEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCIterSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter, _In_ const void *key) __nonnull_all__; -_Check_return_ _Ret_maybenull_ UTIL_EXPORT void *ut_avlCIterNext (_Inout_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter) __nonnull_all__; - -#if defined (__cplusplus) -} -#endif - -#endif /* UT_AVL_H */ diff --git a/src/util/include/util/ut_hopscotch.h b/src/util/include/util/ut_hopscotch.h deleted file mode 100644 index 126a614..0000000 --- a/src/util/include/util/ut_hopscotch.h +++ /dev/null @@ -1,109 +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 UT_HOPSCOTCH_H -#define UT_HOPSCOTCH_H - -#include "os/os.h" -#include "util/ut_export.h" - -#if defined (__cplusplus) -extern "C" { -#endif - -#if __STDC_VERSION__ >= 199901L -#define UT_HH_RESTRICT restrict -#else -#define UT_HH_RESTRICT -#endif - -/* Concurrent version */ -struct ut_chh; -struct ut_chhBucket; -struct ut_chhIter { - struct ut_chhBucket *bs; - uint32_t size; - uint32_t cursor; -}; - -/* - * The hopscotch hash table is dependent on a proper functioning hash. - * If the hash function generates a lot of hash collisions, then it will - * not be able to handle that by design. - * It is capable of handling some collisions, but not more than 32 per - * bucket (less, when other hash values are clustered around the - * collision value). - * When proper distributed hash values are generated, then hopscotch - * works nice and quickly. - */ -typedef uint32_t (*ut_hhHash_fn) (const void *); - -/* - * Hopscotch needs to be able to compare two elements. - * Returns 0 when not equal. - */ -typedef int (*ut_hhEquals_fn) (const void *, const void *); - -/* - * Hopscotch is will resize its internal buckets list when needed. It will - * call this garbage collection function with the old buckets list. The - * caller has to delete the list when it deems it safe to do so. - */ -typedef void (*ut_hhBucketsGc_fn) (void *); - -UTIL_EXPORT struct ut_chh *ut_chhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals, ut_hhBucketsGc_fn gc_buckets); -UTIL_EXPORT void ut_chhFree (struct ut_chh * UT_HH_RESTRICT hh); -UTIL_EXPORT void *ut_chhLookup (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); -UTIL_EXPORT int ut_chhRemove (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT void ut_chhEnumUnsafe (struct ut_chh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ -void *ut_chhIterFirst (struct ut_chh * UT_HH_RESTRICT rt, struct ut_chhIter *it); -void *ut_chhIterNext (struct ut_chhIter *it); - -/* Sequential version */ -struct ut_hh; - -struct ut_hhIter { - struct ut_hh *hh; - uint32_t cursor; -}; - -UTIL_EXPORT struct ut_hh *ut_hhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals); -UTIL_EXPORT void ut_hhFree (struct ut_hh * UT_HH_RESTRICT hh); -UTIL_EXPORT void *ut_hhLookup (const struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT int ut_hhAdd (struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); -UTIL_EXPORT int ut_hhRemove (struct ut_hh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT void ut_hhEnum (struct ut_hh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ -UTIL_EXPORT void *ut_hhIterFirst (struct ut_hh * UT_HH_RESTRICT rt, struct ut_hhIter * UT_HH_RESTRICT iter); /* may delete nodes */ -UTIL_EXPORT void *ut_hhIterNext (struct ut_hhIter * UT_HH_RESTRICT iter); - -/* Sequential version, embedded data */ -struct ut_ehh; - -struct ut_ehhIter { - struct ut_ehh *hh; - uint32_t cursor; -}; - -UTIL_EXPORT struct ut_ehh *ut_ehhNew (size_t elemsz, uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals); -UTIL_EXPORT void ut_ehhFree (struct ut_ehh * UT_HH_RESTRICT hh); -UTIL_EXPORT void *ut_ehhLookup (const struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT int ut_ehhAdd (struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT data); -UTIL_EXPORT int ut_ehhRemove (struct ut_ehh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template); -UTIL_EXPORT void ut_ehhEnum (struct ut_ehh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg); /* may delete a */ -UTIL_EXPORT void *ut_ehhIterFirst (struct ut_ehh * UT_HH_RESTRICT rt, struct ut_ehhIter * UT_HH_RESTRICT iter); /* may delete nodes */ -UTIL_EXPORT void *ut_ehhIterNext (struct ut_ehhIter * UT_HH_RESTRICT iter); - -#if defined (__cplusplus) -} -#endif - -#endif diff --git a/src/util/src/ut_avl.c b/src/util/src/ut_avl.c index 01598fc..3dc05e3 100644 --- a/src/util/src/ut_avl.c +++ b/src/util/src/ut_avl.c @@ -11,10 +11,11 @@ */ #include #include +#include #include -#include "os/os.h" -#include "util/ut_avl.h" +#include "dds/ddsrt/attributes.h" +#include "dds/util/ut_avl.h" #define LOAD_DIRKEY(avlnode, tree) (((char *) (avlnode)) - (tree)->avlnodeoffset + (tree)->keyoffset) #define LOAD_INDKEY(avlnode, tree) (*((char **) (((char *) (avlnode)) - (tree)->avlnodeoffset + (tree)->keyoffset))) @@ -101,20 +102,20 @@ static void treedef_init_common (ut_avlTreedef_t *td, size_t avlnodeoffset, size td->flags = flags; } -void ut_avlTreedefInit (_Out_ ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_t comparekk, _In_opt_ ut_avlAugment_t augment, uint32_t flags) +void ut_avlTreedefInit (ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_t comparekk, ut_avlAugment_t augment, uint32_t flags) { treedef_init_common (td, avlnodeoffset, keyoffset, augment, flags); td->u.comparekk = comparekk; } -void ut_avlTreedefInit_r (_Out_ ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_r_t comparekk_r, _Inout_opt_ void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) +void ut_avlTreedefInit_r (ut_avlTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_r_t comparekk_r, void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) { treedef_init_common (td, avlnodeoffset, keyoffset, augment, flags | UT_AVL_TREEDEF_FLAG_R); td->cmp_arg = cmp_arg; td->u.comparekk_r = comparekk_r; } -void ut_avlInit (_In_ const ut_avlTreedef_t *td, _Out_ ut_avlTree_t *tree) +void ut_avlInit (const ut_avlTreedef_t *td, ut_avlTree_t *tree) { tree->root = NULL; (void) td; @@ -144,7 +145,7 @@ static void treedestroy_arg (const ut_avlTreedef_t *td, ut_avlNode_t *n, void (* } } -void ut_avlFree (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_avlTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node)) +void ut_avlFree (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void (*freefun) (void *node)) { ut_avlNode_t *n = tree->root; tree->root = NULL; @@ -153,7 +154,7 @@ void ut_avlFree (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_avlTr } } -void ut_avlFreeArg (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_avlTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node, _Inout_opt_ void *arg), _Inout_opt_ void *arg) +void ut_avlFreeArg (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void (*freefun) (void *node, void *arg), void *arg) { ut_avlNode_t *n = tree->root; tree->root = NULL; @@ -162,7 +163,7 @@ void ut_avlFreeArg (_In_ const ut_avlTreedef_t *td, _Inout_ _Post_invalid_ ut_av } } -static void augment (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlNode_t *n) +static void augment (const ut_avlTreedef_t *td, ut_avlNode_t *n) { td->augment (onode_from_node (td, n), conode_from_node (td, n->cs[0]), conode_from_node (td, n->cs[1])); } @@ -325,7 +326,7 @@ static void rebalance_nopath (const ut_avlTreedef_t *td, ut_avlTree_t *tree, ut_ } } -_Check_return_ _Ret_maybenull_ void *ut_avlLookup (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) +void *ut_avlLookup (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { const ut_avlNode_t *cursor = tree->root; int c; @@ -336,7 +337,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlLookup (_In_ const ut_avlTreedef_t *t return (void *) conode_from_node (td, cursor); } -static const ut_avlNode_t *lookup_path (_In_ const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlPath_t *path) +static const ut_avlNode_t *lookup_path (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlPath_t *path) { const ut_avlNode_t *cursor = tree->root; const ut_avlNode_t *prev = NULL; @@ -354,13 +355,13 @@ static const ut_avlNode_t *lookup_path (_In_ const ut_avlTreedef_t *td, const ut return cursor; } -_Ret_maybenull_ void *ut_avlLookupDPath (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key, _Out_ ut_avlDPath_t *path) +void *ut_avlLookupDPath (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlDPath_t *path) { const ut_avlNode_t *node = lookup_path (td, tree, key, &path->p); return (void *) conode_from_node (td, node); } -_Ret_maybenull_ void *ut_avlLookupIPath (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key, _Out_ ut_avlIPath_t *path) +void *ut_avlLookupIPath (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key, ut_avlIPath_t *path) { const ut_avlNode_t *node = lookup_path (td, tree, key, &path->p); /* If no duplicates allowed, path may not be used for insertion, @@ -386,7 +387,7 @@ _Ret_maybenull_ void *ut_avlLookupIPath (_In_ const ut_avlTreedef_t *td, _In_ co return (void *) conode_from_node (td, node); } -void ut_avlInsertIPath (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, _Inout_ void *vnode, _Inout_ _Post_invalid_ ut_avlIPath_t *path) +void ut_avlInsertIPath (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode, ut_avlIPath_t *path) { ut_avlNode_t *node = node_from_onode (td, vnode); (void) tree; @@ -404,7 +405,7 @@ void ut_avlInsertIPath (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, _Ino rebalance_path (td, &path->p, node->parent); } -void ut_avlInsert (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *vnode) +void ut_avlInsert (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode) { const void *node = cnode_from_onode (td, vnode); const void *key; @@ -418,7 +419,7 @@ void ut_avlInsert (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _ ut_avlInsertIPath (td, tree, vnode, &path); } -static void delete_generic (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode, ut_avlDPath_t *path) +static void delete_generic (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode, ut_avlDPath_t *path) { ut_avlNode_t *node = node_from_onode (td, vnode); ut_avlNode_t **pnode; @@ -501,18 +502,18 @@ static void delete_generic (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, } } -void ut_avlDeleteDPath (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *vnode, _Inout_ _Post_invalid_ ut_avlDPath_t *path) +void ut_avlDeleteDPath (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode, ut_avlDPath_t *path) { (void) tree; delete_generic (td, NULL, vnode, path); } -void ut_avlDelete (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *vnode) +void ut_avlDelete (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vnode) { delete_generic (td, tree, vnode, NULL); } -void ut_avlSwapNode (_In_ const ut_avlTreedef_t *td, _Inout_ ut_avlTree_t *tree, _Inout_ void *vold, _Inout_ void *vnew) +void ut_avlSwapNode (const ut_avlTreedef_t *td, ut_avlTree_t *tree, void *vold, void *vnew) { ut_avlNode_t *old = node_from_onode (td, vold); ut_avlNode_t *new = node_from_onode (td, vnew); @@ -562,17 +563,17 @@ static ut_avlNode_t *find_extremum (const ut_avlTree_t *tree, int dir) return (ut_avlNode_t *) n; } -_Check_return_ _Ret_maybenull_ void *ut_avlFindMin (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) +void *ut_avlFindMin (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) { return (void *) conode_from_node (td, find_extremum (tree, 0)); } -_Check_return_ _Ret_maybenull_ void *ut_avlFindMax (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) +void *ut_avlFindMax (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) { return (void *) conode_from_node (td, find_extremum (tree, 1)); } -_Check_return_ _Ret_maybenull_ void *ut_avlFindPred (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_opt_ const void *vnode) +void *ut_avlFindPred (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *vnode) { const ut_avlNode_t *n = cnode_from_onode (td, vnode); if (n == NULL) { @@ -582,7 +583,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlFindPred (_In_ const ut_avlTreedef_t } } -_Check_return_ _Ret_maybenull_ void *ut_avlFindSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_opt_ const void *vnode) +void *ut_avlFindSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *vnode) { const ut_avlNode_t *n = cnode_from_onode (td, vnode); if (n == NULL) { @@ -606,7 +607,7 @@ static void avl_iter_downleft (ut_avlIter_t *iter) } } -_Check_return_ _Ret_maybenull_ void *ut_avlIterFirst (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter) +void *ut_avlIterFirst (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter) { iter->td = td; iter->todop = iter->todo+1; @@ -615,7 +616,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlIterFirst (_In_ const ut_avlTreedef_t return onode_from_node (td, *iter->todop); } -_Check_return_ _Ret_maybenull_ void *ut_avlIterNext (_Inout_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter) +void *ut_avlIterNext (ut_avlIter_t *iter) { if (iter->todop-- > iter->todo+1 && iter->right == NULL) { iter->right = (*iter->todop)->cs[1]; @@ -627,7 +628,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlIterNext (_Inout_ _When_ (return == 0 return onode_from_node (iter->td, *iter->todop); } -void ut_avlWalk (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlWalk (const ut_avlTreedef_t *td, ut_avlTree_t *tree, ut_avlWalk_t f, void *a) { const ut_avlNode_t *todo[1+UT_AVL_MAX_TREEHEIGHT]; const ut_avlNode_t **todop = todo+1; @@ -653,24 +654,24 @@ void ut_avlWalk (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _In_ u } } -void ut_avlConstWalk (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlConstWalk (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlConstWalk_t f, void *a) { ut_avlWalk (td, (ut_avlTree_t *) tree, (ut_avlWalk_t) f, a); } -int ut_avlIsEmpty (_In_ const ut_avlTree_t *tree) +int ut_avlIsEmpty (const ut_avlTree_t *tree) { return tree->root == NULL; } -int ut_avlIsSingleton (_In_ const ut_avlTree_t *tree) +int ut_avlIsSingleton (const ut_avlTree_t *tree) { int r = (tree->root && tree->root->height == 1); assert (!r || (tree->root->cs[0] == NULL && tree->root->cs[1] == NULL)); return r; } -void ut_avlAugmentUpdate (_In_ const ut_avlTreedef_t *td, _Inout_ void *vnode) +void ut_avlAugmentUpdate (const ut_avlTreedef_t *td, void *vnode) { if (td->augment) { ut_avlNode_t *node = node_from_onode (td, vnode); @@ -681,7 +682,7 @@ void ut_avlAugmentUpdate (_In_ const ut_avlTreedef_t *td, _Inout_ void *vnode) } } -static const ut_avlNode_t *fixup_predsucceq (_In_ const ut_avlTreedef_t *td, const void *key, const ut_avlNode_t *tmp, const ut_avlNode_t *cand, int dir) +static const ut_avlNode_t *fixup_predsucceq (const ut_avlTreedef_t *td, const void *key, const ut_avlNode_t *tmp, const ut_avlNode_t *cand, int dir) { if (tmp == NULL) { return cand; @@ -704,7 +705,7 @@ static const ut_avlNode_t *fixup_predsucceq (_In_ const ut_avlTreedef_t *td, con } } -static const ut_avlNode_t *lookup_predeq (_In_ const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) +static const ut_avlNode_t *lookup_predeq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { const ut_avlNode_t *tmp = tree->root; const ut_avlNode_t *cand = NULL; @@ -720,7 +721,7 @@ static const ut_avlNode_t *lookup_predeq (_In_ const ut_avlTreedef_t *td, const return fixup_predsucceq (td, key, tmp, cand, 0); } -static const ut_avlNode_t *lookup_succeq (_In_ const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) +static const ut_avlNode_t *lookup_succeq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { const ut_avlNode_t *tmp = tree->root; const ut_avlNode_t *cand = NULL; @@ -736,7 +737,7 @@ static const ut_avlNode_t *lookup_succeq (_In_ const ut_avlTreedef_t *td, const return fixup_predsucceq (td, key, tmp, cand, 1); } -static const ut_avlNode_t *fixup_predsucc (_In_ const ut_avlTreedef_t *td, const void *key, const ut_avlNode_t *tmp, const ut_avlNode_t *cand, int dir) +static const ut_avlNode_t *fixup_predsucc (const ut_avlTreedef_t *td, const void *key, const ut_avlNode_t *tmp, const ut_avlNode_t *cand, int dir) { /* dir=0: pred, dir=1: succ */ if (tmp == NULL || tmp->cs[dir] == NULL) { @@ -765,7 +766,7 @@ static const ut_avlNode_t *fixup_predsucc (_In_ const ut_avlTreedef_t *td, const } } -static const ut_avlNode_t *lookup_pred (_In_ const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) +static const ut_avlNode_t *lookup_pred (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { const ut_avlNode_t *tmp = tree->root; const ut_avlNode_t *cand = NULL; @@ -781,7 +782,7 @@ static const ut_avlNode_t *lookup_pred (_In_ const ut_avlTreedef_t *td, const ut return fixup_predsucc (td, key, tmp, cand, 0); } -static const ut_avlNode_t *lookup_succ (_In_ const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) +static const ut_avlNode_t *lookup_succ (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { const ut_avlNode_t *tmp = tree->root; const ut_avlNode_t *cand = NULL; @@ -797,27 +798,27 @@ static const ut_avlNode_t *lookup_succ (_In_ const ut_avlTreedef_t *td, const ut return fixup_predsucc (td, key, tmp, cand, 1); } -_Check_return_ _Ret_maybenull_ void *ut_avlLookupSuccEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) +void *ut_avlLookupSuccEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { return (void *) conode_from_node (td, lookup_succeq (td, tree, key)); } -_Check_return_ _Ret_maybenull_ void *ut_avlLookupPredEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) +void *ut_avlLookupPredEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { return (void *) conode_from_node (td, lookup_predeq (td, tree, key)); } -_Check_return_ _Ret_maybenull_ void *ut_avlLookupSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) +void *ut_avlLookupSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { return (void *) conode_from_node (td, lookup_succ (td, tree, key)); } -_Check_return_ _Ret_maybenull_ void *ut_avlLookupPred (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *key) +void *ut_avlLookupPred (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *key) { return (void *) conode_from_node (td, lookup_pred (td, tree, key)); } -_Check_return_ _Ret_maybenull_ void *ut_avlIterSuccEq (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter, _In_ const void *key) +void *ut_avlIterSuccEq (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter, const void *key) { const ut_avlNode_t *tmp = tree->root; int c; @@ -855,7 +856,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlIterSuccEq (_In_ const ut_avlTreedef_ } } -_Check_return_ _Ret_maybenull_ void *ut_avlIterSucc (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlIter_t *iter, _In_ const void *key) +void *ut_avlIterSucc (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, ut_avlIter_t *iter, const void *key) { const ut_avlNode_t *tmp = tree->root; int c; @@ -898,7 +899,7 @@ _Check_return_ _Ret_maybenull_ void *ut_avlIterSucc (_In_ const ut_avlTreedef_t } } -void ut_avlWalkRange (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlWalkRange (const ut_avlTreedef_t *td, ut_avlTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) { ut_avlNode_t *n, *nn; n = (ut_avlNode_t *) lookup_succeq (td, tree, min); @@ -909,12 +910,12 @@ void ut_avlWalkRange (_In_ const ut_avlTreedef_t *td, _In_ ut_avlTree_t *tree, _ } } -void ut_avlConstWalkRange (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlConstWalkRange (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) { ut_avlWalkRange (td, (ut_avlTree_t *) tree, min, max, (ut_avlWalk_t) f, a); } -void ut_avlWalkRangeReverse (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlWalkRangeReverse (const ut_avlTreedef_t *td, ut_avlTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) { ut_avlNode_t *n, *nn; n = (ut_avlNode_t *) lookup_predeq (td, tree, max); @@ -925,17 +926,17 @@ void ut_avlWalkRangeReverse (_In_ const ut_avlTreedef_t *td, ut_avlTree_t *tree, } } -void ut_avlConstWalkRangeReverse (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlConstWalkRangeReverse (const ut_avlTreedef_t *td, const ut_avlTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) { ut_avlWalkRangeReverse (td, (ut_avlTree_t *) tree, min, max, (ut_avlWalk_t) f, a); } -_Check_return_ _Ret_maybenull_ void *ut_avlRoot (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) +void *ut_avlRoot (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) { return (void *) conode_from_node (td, tree->root); } -_Ret_notnull_ void *ut_avlRootNonEmpty (_In_ const ut_avlTreedef_t *td, _In_ const ut_avlTree_t *tree) +void *ut_avlRootNonEmpty (const ut_avlTreedef_t *td, const ut_avlTree_t *tree) { assert (tree->root); return (void *) conode_from_node (td, tree->root); @@ -947,199 +948,199 @@ _Ret_notnull_ void *ut_avlRootNonEmpty (_In_ const ut_avlTreedef_t *td, _In_ con **** **************************************************************************************/ -void ut_avlCTreedefInit (_Out_ ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_t comparekk, _In_opt_ ut_avlAugment_t augment, uint32_t flags) +void ut_avlCTreedefInit (ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_t comparekk, ut_avlAugment_t augment, uint32_t flags) { treedef_init_common (&td->t, avlnodeoffset, keyoffset, augment, flags); td->t.u.comparekk = comparekk; } -void ut_avlCTreedefInit_r (_Out_ ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, _In_ ut_avlCompare_r_t comparekk_r, _Inout_opt_ void *cmp_arg, _In_opt_ ut_avlAugment_t augment, uint32_t flags) +void ut_avlCTreedefInit_r (ut_avlCTreedef_t *td, size_t avlnodeoffset, size_t keyoffset, ut_avlCompare_r_t comparekk_r, void *cmp_arg, ut_avlAugment_t augment, uint32_t flags) { treedef_init_common (&td->t, avlnodeoffset, keyoffset, augment, flags | UT_AVL_TREEDEF_FLAG_R); td->t.cmp_arg = cmp_arg; td->t.u.comparekk_r = comparekk_r; } -void ut_avlCInit (_In_ const ut_avlCTreedef_t *td, _Out_ ut_avlCTree_t *tree) +void ut_avlCInit (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree) { ut_avlInit (&td->t, &tree->t); tree->count = 0; } -void ut_avlCFree (_In_ const ut_avlCTreedef_t *td, _Inout_ _Post_invalid_ ut_avlCTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node)) +void ut_avlCFree (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void (*freefun) (void *node)) { tree->count = 0; ut_avlFree (&td->t, &tree->t, freefun); } -void ut_avlCFreeArg (_In_ const ut_avlCTreedef_t *td, _Inout_ _Post_invalid_ ut_avlCTree_t *tree, _In_opt_ void (*freefun) (_Inout_ void *node, _Inout_opt_ void *arg), _Inout_opt_ void *arg) +void ut_avlCFreeArg (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void (*freefun) (void *node, void *arg), void *arg) { tree->count = 0; ut_avlFreeArg (&td->t, &tree->t, freefun, arg); } -_Check_return_ _Ret_maybenull_ void *ut_avlCRoot (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) +void *ut_avlCRoot (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) { return ut_avlRoot (&td->t, &tree->t); } -_Ret_notnull_ void *ut_avlCRootNonEmpty (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) +void *ut_avlCRootNonEmpty (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) { return ut_avlRootNonEmpty (&td->t, &tree->t); } -_Check_return_ _Ret_maybenull_ void *ut_avlCLookup (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) +void *ut_avlCLookup (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) { return ut_avlLookup (&td->t, &tree->t, key); } -_Ret_maybenull_ void *ut_avlCLookupIPath (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key, _Out_ ut_avlIPath_t *path) +void *ut_avlCLookupIPath (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key, ut_avlIPath_t *path) { return ut_avlLookupIPath (&td->t, &tree->t, key, path); } -_Ret_maybenull_ void *ut_avlCLookupDPath (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key, _Out_ ut_avlDPath_t *path) +void *ut_avlCLookupDPath (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key, ut_avlDPath_t *path) { return ut_avlLookupDPath (&td->t, &tree->t, key, path); } -_Check_return_ _Ret_maybenull_ void *ut_avlCLookupPredEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) +void *ut_avlCLookupPredEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) { return ut_avlLookupPredEq (&td->t, &tree->t, key); } -_Check_return_ _Ret_maybenull_ void *ut_avlCLookupSuccEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) +void *ut_avlCLookupSuccEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) { return ut_avlLookupSuccEq (&td->t, &tree->t, key); } -_Check_return_ _Ret_maybenull_ void *ut_avlCLookupPred (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) +void *ut_avlCLookupPred (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) { return ut_avlLookupPred (&td->t, &tree->t, key); } -_Check_return_ _Ret_maybenull_ void *ut_avlCLookupSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *key) +void *ut_avlCLookupSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *key) { return ut_avlLookupSucc (&td->t, &tree->t, key); } -void ut_avlCInsert (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node) +void ut_avlCInsert (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node) { tree->count++; ut_avlInsert (&td->t, &tree->t, node); } -void ut_avlCDelete (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node) +void ut_avlCDelete (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node) { assert (tree->count > 0); tree->count--; ut_avlDelete (&td->t, &tree->t, node); } -void ut_avlCInsertIPath (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlIPath_t *path) +void ut_avlCInsertIPath (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node, ut_avlIPath_t *path) { tree->count++; ut_avlInsertIPath (&td->t, &tree->t, node, path); } -void ut_avlCDeleteDPath (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *node, _Inout_ _Post_invalid_ ut_avlDPath_t *path) +void ut_avlCDeleteDPath (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *node, ut_avlDPath_t *path) { assert (tree->count > 0); tree->count--; ut_avlDeleteDPath (&td->t, &tree->t, node, path); } -void ut_avlCSwapNode (_In_ const ut_avlCTreedef_t *td, _Inout_ ut_avlCTree_t *tree, _Inout_ void *old, _Inout_ void *new) +void ut_avlCSwapNode (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, void *old, void *new) { ut_avlSwapNode (&td->t, &tree->t, old, new); } -void ut_avlCAugmentUpdate (_In_ const ut_avlCTreedef_t *td, _Inout_ void *node) +void ut_avlCAugmentUpdate (const ut_avlCTreedef_t *td, void *node) { ut_avlAugmentUpdate (&td->t, node); } -int ut_avlCIsEmpty (_In_ const ut_avlCTree_t *tree) +int ut_avlCIsEmpty (const ut_avlCTree_t *tree) { return ut_avlIsEmpty (&tree->t); } -int ut_avlCIsSingleton (_In_ const ut_avlCTree_t *tree) +int ut_avlCIsSingleton (const ut_avlCTree_t *tree) { return ut_avlIsSingleton (&tree->t); } -size_t ut_avlCCount (_In_ const ut_avlCTree_t *tree) +size_t ut_avlCCount (const ut_avlCTree_t *tree) { return tree->count; } -_Check_return_ _Ret_maybenull_ void *ut_avlCFindMin (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) +void *ut_avlCFindMin (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) { return ut_avlFindMin (&td->t, &tree->t); } -_Check_return_ _Ret_maybenull_ void *ut_avlCFindMax (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree) +void *ut_avlCFindMax (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree) { return ut_avlFindMax (&td->t, &tree->t); } -_Check_return_ _Ret_maybenull_ void *ut_avlCFindPred (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *vnode) +void *ut_avlCFindPred (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *vnode) { return ut_avlFindPred (&td->t, &tree->t, vnode); } -_Check_return_ _Ret_maybenull_ void *ut_avlCFindSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *vnode) +void *ut_avlCFindSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *vnode) { return ut_avlFindSucc (&td->t, &tree->t, vnode); } -void ut_avlCWalk (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlCWalk (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, ut_avlWalk_t f, void *a) { ut_avlWalk (&td->t, &tree->t, f, a); } -void ut_avlCConstWalk (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlCConstWalk (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlConstWalk_t f, void *a) { ut_avlConstWalk (&td->t, &tree->t, f, a); } -void ut_avlCWalkRange (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlCWalkRange (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) { ut_avlWalkRange (&td->t, &tree->t, min, max, f, a); } -void ut_avlCConstWalkRange (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlCConstWalkRange (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) { ut_avlConstWalkRange (&td->t, &tree->t, min, max, f, a); } -void ut_avlCWalkRangeReverse (_In_ const ut_avlCTreedef_t *td, _In_ ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlWalk_t f, _Inout_opt_ void *a) +void ut_avlCWalkRangeReverse (const ut_avlCTreedef_t *td, ut_avlCTree_t *tree, const void *min, const void *max, ut_avlWalk_t f, void *a) { ut_avlWalkRangeReverse (&td->t, &tree->t, min, max, f, a); } -void ut_avlCConstWalkRangeReverse (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _In_ const void *min, _In_ const void *max, _In_ ut_avlConstWalk_t f, _Inout_opt_ void *a) +void ut_avlCConstWalkRangeReverse (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, const void *min, const void *max, ut_avlConstWalk_t f, void *a) { ut_avlConstWalkRangeReverse (&td->t, &tree->t, min, max, f, a); } -_Check_return_ _Ret_maybenull_ void *ut_avlCIterFirst (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter) +void *ut_avlCIterFirst (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter) { return ut_avlIterFirst (&td->t, &tree->t, &iter->t); } -_Check_return_ _Ret_maybenull_ void *ut_avlCIterSuccEq (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter, _In_ const void *key) +void *ut_avlCIterSuccEq (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter, const void *key) { return ut_avlIterSuccEq (&td->t, &tree->t, &iter->t, key); } -_Check_return_ _Ret_maybenull_ void *ut_avlCIterSucc (_In_ const ut_avlCTreedef_t *td, _In_ const ut_avlCTree_t *tree, _Out_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter, _In_ const void *key) +void *ut_avlCIterSucc (const ut_avlCTreedef_t *td, const ut_avlCTree_t *tree, ut_avlCIter_t *iter, const void *key) { return ut_avlIterSucc (&td->t, &tree->t, &iter->t, key); } -_Check_return_ _Ret_maybenull_ void *ut_avlCIterNext (_Inout_ _When_ (return == 0, _Post_invalid_) ut_avlCIter_t *iter) +void *ut_avlCIterNext (ut_avlCIter_t *iter) { /* Added this in-between t variable to satisfy SAL. */ ut_avlIter_t *t = &(iter->t); diff --git a/src/util/src/ut_crc.c b/src/util/src/ut_crc.c index c9a07d4..87778a9 100644 --- a/src/util/src/ut_crc.c +++ b/src/util/src/ut_crc.c @@ -9,8 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "util/ut_crc.h" -#include "os/os.h" +#include "dds/util/ut_crc.h" static const uint32_t crc32_table[] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, diff --git a/src/util/src/ut_expand_envvars.c b/src/util/src/ut_expand_envvars.c index 2297a47..3b2b999 100644 --- a/src/util/src/ut_expand_envvars.c +++ b/src/util/src/ut_expand_envvars.c @@ -15,8 +15,11 @@ #include #include -#include "os/os.h" -#include "util/ut_expand_envvars.h" +#include "dds/ddsrt/environ.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/log.h" +#include "dds/ddsrt/string.h" +#include "dds/util/ut_expand_envvars.h" typedef char * (*expand_fn)(const char *src0); @@ -24,7 +27,7 @@ static void expand_append (char **dst, size_t *sz, size_t *pos, char c) { if (*pos == *sz) { *sz += 1024; - *dst = os_realloc (*dst, *sz); + *dst = ddsrt_realloc (*dst, *sz); } (*dst)[*pos] = c; (*pos)++; @@ -32,24 +35,25 @@ static void expand_append (char **dst, size_t *sz, size_t *pos, char c) static char *expand_env (const char *name, char op, const char *alt, expand_fn expand) { - const char *env = os_getenv (name); + char *env = NULL; + (void)ddsrt_getenv (name, &env); switch (op) { case 0: - return os_strdup (env ? env : ""); + return ddsrt_strdup (env ? env : ""); case '-': - return env && *env ? os_strdup (env) : expand (alt); + return env && *env ? ddsrt_strdup (env) : expand (alt); case '?': if (env && *env) { - return os_strdup (env); + return ddsrt_strdup (env); } else { char *altx = expand (alt); DDS_ERROR("%s: %s\n", name, altx); - os_free (altx); + ddsrt_free (altx); return NULL; } case '+': - return env && *env ? expand (alt) : os_strdup (""); + return env && *env ? expand (alt) : ddsrt_strdup (""); default: abort (); return NULL; @@ -68,13 +72,13 @@ static char *expand_envbrace (const char **src, expand_fn expand) if (**src == 0) { goto err; } - name = os_malloc ((size_t) (*src - start) + 1); + name = ddsrt_malloc ((size_t) (*src - start) + 1); memcpy (name, start, (size_t) (*src - start)); name[*src - start] = 0; if (**src == '}') { (*src)++; x = expand_env (name, 0, NULL, expand); - os_free (name); + ddsrt_free (name); return x; } else { const char *altstart; @@ -89,7 +93,7 @@ static char *expand_envbrace (const char **src, expand_fn expand) (*src)++; break; default: - os_free(name); + ddsrt_free(name); goto err; } altstart = *src; @@ -102,24 +106,24 @@ static char *expand_envbrace (const char **src, expand_fn expand) } else if (**src == '\\') { (*src)++; if (**src == 0) { - os_free(name); + ddsrt_free(name); goto err; } } (*src)++; } if (**src == 0) { - os_free(name); + ddsrt_free(name); goto err; } assert (**src == '}'); - alt = os_malloc ((size_t) (*src - altstart) + 1); + alt = ddsrt_malloc ((size_t) (*src - altstart) + 1); memcpy (alt, altstart, (size_t) (*src - altstart)); alt[*src - altstart] = 0; (*src)++; x = expand_env (name, op, alt, expand); - os_free (alt); - os_free (name); + ddsrt_free (alt); + ddsrt_free (name); return x; } err: @@ -135,11 +139,11 @@ static char *expand_envsimple (const char **src, expand_fn expand) (*src)++; } assert (*src > start); - name = os_malloc ((size_t) (*src - start) + 1); + name = ddsrt_malloc ((size_t) (*src - start) + 1); memcpy (name, start, (size_t) (*src - start)); name[*src - start] = 0; x = expand_env (name, 0, NULL, expand); - os_free (name); + ddsrt_free (name); return x; } @@ -158,13 +162,13 @@ char *ut_expand_envvars_sh (const char *src0) /* Expands $X, ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms; $ and \ can be escaped with \ */ const char *src = src0; size_t sz = strlen (src) + 1, pos = 0; - char *dst = os_malloc (sz); + char *dst = ddsrt_malloc (sz); while (*src) { if (*src == '\\') { src++; if (*src == 0) { DDS_ERROR("%s: incomplete escape at end of string\n", src0); - os_free(dst); + ddsrt_free(dst); return NULL; } expand_append (&dst, &sz, &pos, *src++); @@ -173,7 +177,7 @@ char *ut_expand_envvars_sh (const char *src0) src++; if (*src == 0) { DDS_ERROR("%s: incomplete variable expansion at end of string\n", src0); - os_free(dst); + ddsrt_free(dst); return NULL; } else if (*src == '{') { x = expand_envbrace (&src, &ut_expand_envvars_sh); @@ -183,14 +187,14 @@ char *ut_expand_envvars_sh (const char *src0) x = expand_envchar (&src, &ut_expand_envvars_sh); } if (x == NULL) { - os_free(dst); + ddsrt_free(dst); return NULL; } xp = x; while (*xp) { expand_append (&dst, &sz, &pos, *xp++); } - os_free (x); + ddsrt_free (x); } else { expand_append (&dst, &sz, &pos, *src++); } @@ -204,21 +208,21 @@ char *ut_expand_envvars (const char *src0) /* Expands ${X}, ${X:-Y}, ${X:+Y}, ${X:?Y} forms, but not $X */ const char *src = src0; size_t sz = strlen (src) + 1, pos = 0; - char *dst = os_malloc (sz); + char *dst = ddsrt_malloc (sz); while (*src) { if (*src == '$' && *(src + 1) == '{') { char *x, *xp; src++; x = expand_envbrace (&src, &ut_expand_envvars); if (x == NULL) { - os_free(dst); + ddsrt_free(dst); return NULL; } xp = x; while (*xp) { expand_append (&dst, &sz, &pos, *xp++); } - os_free (x); + ddsrt_free (x); } else { expand_append (&dst, &sz, &pos, *src++); } diff --git a/src/util/src/ut_fibheap.c b/src/util/src/ut_fibheap.c index e597004..a92d186 100644 --- a/src/util/src/ut_fibheap.c +++ b/src/util/src/ut_fibheap.c @@ -13,7 +13,8 @@ #include #include -#include "util/ut_fibheap.h" +#include "dds/ddsrt/misc.h" +#include "dds/util/ut_fibheap.h" /* max degree: n >= F_{d+2} >= \phi^d ==> d <= log_\phi n, where \phi (as usual) is the golden ratio ~= 1.618. We know n <= (size of @@ -35,7 +36,7 @@ void ut_fibheapDefInit (ut_fibheapDef_t *fhdef, uintptr_t offset, int (*cmp) (co void ut_fibheapInit (const ut_fibheapDef_t *fhdef, ut_fibheap_t *fh) { - OS_UNUSED_ARG(fhdef); + DDSRT_UNUSED_ARG(fhdef); fh->roots = NULL; } diff --git a/src/util/src/ut_handleserver.c b/src/util/src/ut_handleserver.c index 22c2233..657f05e 100644 --- a/src/util/src/ut_handleserver.c +++ b/src/util/src/ut_handleserver.c @@ -11,8 +11,11 @@ */ #include #include -#include "os/os.h" -#include "util/ut_handleserver.h" + +#include "dds/ddsrt/cdtors.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/util/ut_handleserver.h" /* Arbitrarily number of max handles. Should be enough for the mock. */ #define MAX_NR_OF_HANDLES (1000) @@ -30,7 +33,7 @@ typedef struct ut_handlelink { typedef struct ut_handleserver { ut_handlelink *hdls[MAX_NR_OF_HANDLES]; int32_t last; - os_mutex mutex; + ddsrt_mutex_t mutex; } ut_handleserver; @@ -38,25 +41,25 @@ typedef struct ut_handleserver { static ut_handleserver *hs = NULL; -_Check_return_ static ut_handle_retcode_t -lookup_handle(_In_ ut_handle_t hdl, _In_ int32_t kind, _Out_ ut_handlelink **link); +static ut_handle_retcode_t +lookup_handle(ut_handle_t hdl, int32_t kind, ut_handlelink **link); -_Check_return_ static ut_handle_t -check_handle(_In_ ut_handle_t hdl, _In_ int32_t kind); +static ut_handle_t +check_handle(ut_handle_t hdl, int32_t kind); static void -delete_handle(_In_ int32_t idx); +delete_handle(int32_t idx); -_Check_return_ ut_handle_retcode_t +ut_handle_retcode_t ut_handleserver_init(void) { - os_osInit(); - /* TODO CHAM-138: Allow re-entry (something like os_osInit()). */ + ddsrt_init(); + /* TODO Allow re-entry (something like ddsrt_init()). */ assert(hs == NULL); - hs = os_malloc(sizeof(ut_handleserver)); + hs = ddsrt_malloc(sizeof(ut_handleserver)); hs->last = 0; - os_mutexInit(&hs->mutex); + ddsrt_mutex_init(&hs->mutex); return UT_HANDLE_OK; } @@ -66,29 +69,27 @@ ut_handleserver_fini(void) { int32_t i; - /* TODO CHAM-138: Only destroy when this is the last fini (something like os_osExit()). */ + /* TODO Only destroy when this is the last fini (something like ddsrt_fini()). */ assert(hs); /* Every handle should have been deleted, but make sure. */ for (i = 0; i < hs->last; i++) { if (hs->hdls[i] != NULL) { /* TODO CHAM-138: Print warning. */ - os_free(hs->hdls[i]); + ddsrt_free(hs->hdls[i]); } } - os_mutexDestroy(&hs->mutex); - os_free(hs); + ddsrt_mutex_destroy(&hs->mutex); + ddsrt_free(hs); hs = NULL; - os_osExit(); + ddsrt_fini(); } -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Post_satisfies_((return & UT_HANDLE_KIND_MASK) == kind) -_Must_inspect_result_ ut_handle_t +ut_handle_t ut_handle_create( - _In_ int32_t kind, - _In_ void *arg) + int32_t kind, + void *arg) { ut_handle_t hdl = (ut_handle_t)UT_HANDLE_OUT_OF_RESOURCES; @@ -101,13 +102,13 @@ ut_handle_create( return (ut_handle_t)UT_HANDLE_NOT_INITALIZED; } - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); /* TODO CHAM-138: Improve the creation and management of handles. */ if (hs->last < MAX_NR_OF_HANDLES) { hdl = hs->last; hdl |= kind; - hs->hdls[hs->last] = os_malloc(sizeof(ut_handlelink)); + hs->hdls[hs->last] = ddsrt_malloc(sizeof(ut_handlelink)); hs->hdls[hs->last]->cnt = 0; hs->hdls[hs->last]->arg = arg; hs->hdls[hs->last]->hdl = hdl; @@ -115,23 +116,22 @@ ut_handle_create( hs->last++; } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); return hdl; } - void ut_handle_close( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link) + ut_handle_t hdl, + struct ut_handlelink *link) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; assert(hs); - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, UT_HANDLE_DONTCARE_KIND, &info); } @@ -140,22 +140,21 @@ ut_handle_close( assert(hdl == info->hdl); info->flags |= HDL_FLAG_CLOSED; } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); } - -_Check_return_ ut_handle_retcode_t +ut_handle_retcode_t ut_handle_delete( - _In_ ut_handle_t hdl, - _Inout_opt_ _Post_invalid_ struct ut_handlelink *link, - _In_ os_time timeout) + ut_handle_t hdl, + struct ut_handlelink *link, + dds_time_t timeout) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; assert(hs); - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, UT_HANDLE_DONTCARE_KIND, &info); } @@ -164,17 +163,16 @@ ut_handle_delete( assert(hdl == info->hdl); info->flags |= HDL_FLAG_CLOSED; - /* TODO CHAM-138: Replace this polling with conditional wait. */ - os_mutexUnlock(&hs->mutex); + /* FIXME: Replace this polling with conditional wait. */ + ddsrt_mutex_unlock(&hs->mutex); { - const os_time zero = { 0, 0 }; - const os_time delay = { 0, 10000000 }; - while ((info->cnt != 0) && (os_timeCompare(timeout, zero) > 0)) { - os_nanoSleep(delay); - timeout = os_timeSub(timeout, delay); + dds_duration_t delay = DDS_MSECS(10); + while ((info->cnt != 0) && timeout > 0) { + dds_sleepfor(delay); + timeout = (delay < timeout ? timeout - delay : 0); } } - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info->cnt == 0) { delete_handle(hdl & UT_HANDLE_IDX_MASK); @@ -182,18 +180,16 @@ ut_handle_delete( ret = UT_HANDLE_TIMEOUT; } } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); return ret; } - -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Check_return_ ut_handle_retcode_t +ut_handle_retcode_t ut_handle_status( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link, - _In_ int32_t kind) + ut_handle_t hdl, + struct ut_handlelink *link, + int32_t kind) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; @@ -202,7 +198,7 @@ ut_handle_status( return (ut_handle_t)UT_HANDLE_INVALID; } - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, kind, &info); } @@ -213,19 +209,17 @@ ut_handle_status( ret = UT_HANDLE_CLOSED; } } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); return ret; } - -_Pre_satisfies_((kind & UT_HANDLE_KIND_MASK) && !(kind & ~UT_HANDLE_KIND_MASK)) -_Check_return_ ut_handle_retcode_t +ut_handle_retcode_t ut_handle_claim( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link, - _In_ int32_t kind, - _Out_opt_ void **arg) + ut_handle_t hdl, + struct ut_handlelink *link, + int32_t kind, + void **arg) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; @@ -238,7 +232,7 @@ ut_handle_claim( return (ut_handle_t)UT_HANDLE_INVALID; } - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, kind, &info); } @@ -255,7 +249,7 @@ ut_handle_claim( *arg = info->arg; } } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); return ret; } @@ -263,15 +257,15 @@ ut_handle_claim( void ut_handle_release( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link) + ut_handle_t hdl, + struct ut_handlelink *link) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; assert(hs); - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, UT_HANDLE_DONTCARE_KIND, &info); } @@ -281,21 +275,20 @@ ut_handle_release( assert(info->cnt > 0); info->cnt--; } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); } - -_Check_return_ bool +bool ut_handle_is_closed( - _In_ ut_handle_t hdl, - _Inout_opt_ struct ut_handlelink *link) + ut_handle_t hdl, + struct ut_handlelink *link) { struct ut_handlelink *info = link; ut_handle_retcode_t ret = UT_HANDLE_OK; assert(hs); - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); if (info == NULL) { ret = lookup_handle(hdl, UT_HANDLE_DONTCARE_KIND, &info); } @@ -306,38 +299,37 @@ ut_handle_is_closed( ret = UT_HANDLE_CLOSED; } } - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); /* Simulate closed for every error. */ return (ret != UT_HANDLE_OK); } - -_Must_inspect_result_ struct ut_handlelink* +struct ut_handlelink* ut_handle_get_link( - _In_ ut_handle_t hdl) + ut_handle_t hdl) { struct ut_handlelink *info; ut_handle_retcode_t ret; assert(hs); - os_mutexLock(&hs->mutex); + ddsrt_mutex_lock(&hs->mutex); ret = lookup_handle(hdl, UT_HANDLE_DONTCARE_KIND, &info); assert(((ret == UT_HANDLE_OK) && (info != NULL)) || ((ret != UT_HANDLE_OK) && (info == NULL)) ); (void)ret; - os_mutexUnlock(&hs->mutex); + ddsrt_mutex_unlock(&hs->mutex); return info; } -_Check_return_ static ut_handle_retcode_t +static ut_handle_retcode_t lookup_handle( - _In_ ut_handle_t hdl, - _In_ int32_t kind, - _Out_ ut_handlelink **link) + ut_handle_t hdl, + int32_t kind, + ut_handlelink **link) { ut_handle_retcode_t ret; *link = NULL; @@ -350,10 +342,10 @@ lookup_handle( return ret; } -_Check_return_ static ut_handle_t +static ut_handle_t check_handle( - _In_ ut_handle_t hdl, - _In_ int32_t kind) + ut_handle_t hdl, + int32_t kind) { /* When handle is negative, it contains a retcode. */ ut_handle_retcode_t ret = UT_HANDLE_OK; @@ -392,10 +384,10 @@ check_handle( } static void -delete_handle(_In_ int32_t idx) +delete_handle(int32_t idx) { assert(hs); assert(idx < MAX_NR_OF_HANDLES); - os_free(hs->hdls[idx]); + ddsrt_free(hs->hdls[idx]); hs->hdls[idx] = NULL; } diff --git a/src/util/src/ut_hopscotch.c b/src/util/src/ut_hopscotch.c index 4528e23..276c9cb 100644 --- a/src/util/src/ut_hopscotch.c +++ b/src/util/src/ut_hopscotch.c @@ -12,8 +12,10 @@ #include #include -#include "os/os.h" -#include "util/ut_hopscotch.h" +#include "dds/ddsrt/atomics.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/util/ut_hopscotch.h" #define HH_HOP_RANGE 32 #define HH_ADD_RANGE 64 @@ -26,28 +28,28 @@ #define N_RESIZE_LOCKS 8 struct ut_chhBucket { - os_atomic_uint32_t hopinfo; - os_atomic_uint32_t timestamp; - os_atomic_uint32_t lock; - os_atomic_voidp_t data; + ddsrt_atomic_uint32_t hopinfo; + ddsrt_atomic_uint32_t timestamp; + ddsrt_atomic_uint32_t lock; + ddsrt_atomic_voidp_t data; }; -struct _Struct_size_bytes_(size) ut_chhBucketArray { +struct ut_chhBucketArray { uint32_t size; /* power of 2 */ struct ut_chhBucket bs[]; }; struct ut_chhBackingLock { - os_mutex lock; - os_cond cv; + ddsrt_mutex_t lock; + ddsrt_cond_t cv; }; struct ut_chh { - os_atomic_voidp_t buckets; /* struct ut_chhBucketArray * */ + ddsrt_atomic_voidp_t buckets; /* struct ut_chhBucketArray * */ struct ut_chhBackingLock backingLocks[N_BACKING_LOCKS]; ut_hhHash_fn hash; ut_hhEquals_fn equals; - os_rwlock resize_locks[N_RESIZE_LOCKS]; + ddsrt_rwlock_t resize_locks[N_RESIZE_LOCKS]; ut_hhBucketsGc_fn gc_buckets; }; @@ -72,25 +74,25 @@ static int ut_chhInit (struct ut_chh *rt, uint32_t init_size, ut_hhHash_fn hash, rt->hash = hash; rt->equals = equals; rt->gc_buckets = gc_buckets; - _Analysis_assume_(size >= HH_HOP_RANGE); - buckets = os_malloc (offsetof (struct ut_chhBucketArray, bs) + size * sizeof (*buckets->bs)); - os_atomic_stvoidp (&rt->buckets, buckets); + + buckets = ddsrt_malloc (offsetof (struct ut_chhBucketArray, bs) + size * sizeof (*buckets->bs)); + ddsrt_atomic_stvoidp (&rt->buckets, buckets); buckets->size = size; for (i = 0; i < size; i++) { struct ut_chhBucket *b = &buckets->bs[i]; - os_atomic_st32 (&b->hopinfo, 0); - os_atomic_st32 (&b->timestamp, 0); - os_atomic_st32 (&b->lock, 0); - os_atomic_stvoidp (&b->data, NULL); + ddsrt_atomic_st32 (&b->hopinfo, 0); + ddsrt_atomic_st32 (&b->timestamp, 0); + ddsrt_atomic_st32 (&b->lock, 0); + ddsrt_atomic_stvoidp (&b->data, NULL); } for (i = 0; i < N_BACKING_LOCKS; i++) { struct ut_chhBackingLock *s = &rt->backingLocks[i]; - os_mutexInit (&s->lock); - os_condInit (&s->cv, &s->lock); + ddsrt_mutex_init (&s->lock); + ddsrt_cond_init (&s->cv); } for (i = 0; i < N_RESIZE_LOCKS; i++) { - os_rwlockInit (&rt->resize_locks[i]); + ddsrt_rwlock_init (&rt->resize_locks[i]); } return 0; } @@ -98,22 +100,22 @@ static int ut_chhInit (struct ut_chh *rt, uint32_t init_size, ut_hhHash_fn hash, static void ut_chhFini (struct ut_chh *rt) { int i; - os_free (os_atomic_ldvoidp (&rt->buckets)); + ddsrt_free (ddsrt_atomic_ldvoidp (&rt->buckets)); for (i = 0; i < N_BACKING_LOCKS; i++) { struct ut_chhBackingLock *s = &rt->backingLocks[i]; - os_condDestroy (&s->cv); - os_mutexDestroy (&s->lock); + ddsrt_cond_destroy (&s->cv); + ddsrt_mutex_destroy (&s->lock); } for (i = 0; i < N_RESIZE_LOCKS; i++) { - os_rwlockDestroy (&rt->resize_locks[i]); + ddsrt_rwlock_destroy (&rt->resize_locks[i]); } } struct ut_chh *ut_chhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals, ut_hhBucketsGc_fn gc_buckets) { - struct ut_chh *hh = os_malloc (sizeof (*hh)); + struct ut_chh *hh = ddsrt_malloc (sizeof (*hh)); if (ut_chhInit (hh, init_size, hash, equals, gc_buckets) < 0) { - os_free (hh); + ddsrt_free (hh); return NULL; } else { return hh; @@ -123,7 +125,7 @@ struct ut_chh *ut_chhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn void ut_chhFree (struct ut_chh * UT_HH_RESTRICT hh) { ut_chhFini (hh); - os_free (hh); + ddsrt_free (hh); } #define LOCKBIT ((uint32_t)1 << 31) @@ -133,58 +135,58 @@ static void ut_chhLockBucket (struct ut_chh *rt, uint32_t bidx) /* Lock: MSB <=> LOCKBIT, LSBs <=> wait count; note that (o&LOCKBIT)==0 means a thread can sneak in when there are already waiters, changing it to o==0 would avoid that. */ - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const b = &bsary->bs[bidx]; struct ut_chhBackingLock * const s = &rt->backingLocks[bidx % N_BACKING_LOCKS]; uint32_t o, n; fastpath_retry: - o = os_atomic_ld32 (&b->lock); + o = ddsrt_atomic_ld32 (&b->lock); if ((o & LOCKBIT) == 0) { n = o | LOCKBIT; } else { n = o + 1; } - if (!os_atomic_cas32 (&b->lock, o, n)) { + if (!ddsrt_atomic_cas32 (&b->lock, o, n)) { goto fastpath_retry; } if ((o & LOCKBIT) == 0) { - os_atomic_fence (); + ddsrt_atomic_fence (); } else { - os_mutexLock (&s->lock); + ddsrt_mutex_lock (&s->lock); do { - while ((o = os_atomic_ld32 (&b->lock)) & LOCKBIT) { - os_condWait (&s->cv, &s->lock); + while ((o = ddsrt_atomic_ld32 (&b->lock)) & LOCKBIT) { + ddsrt_cond_wait (&s->cv, &s->lock); } - } while (!os_atomic_cas32 (&b->lock, o, (o - 1) | LOCKBIT)); - os_mutexUnlock (&s->lock); + } while (!ddsrt_atomic_cas32 (&b->lock, o, (o - 1) | LOCKBIT)); + ddsrt_mutex_unlock (&s->lock); } } static void ut_chhUnlockBucket (struct ut_chh *rt, uint32_t bidx) { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const b = &bsary->bs[bidx]; struct ut_chhBackingLock * const s = &rt->backingLocks[bidx % N_BACKING_LOCKS]; uint32_t o, n; retry: - o = os_atomic_ld32 (&b->lock); + o = ddsrt_atomic_ld32 (&b->lock); assert (o & LOCKBIT); n = o & ~LOCKBIT; - if (!os_atomic_cas32 (&b->lock, o, n)) { + if (!ddsrt_atomic_cas32 (&b->lock, o, n)) { goto retry; } if (n == 0) { - os_atomic_fence (); + ddsrt_atomic_fence (); } else { - os_mutexLock (&s->lock); + ddsrt_mutex_lock (&s->lock); /* Need to broadcast because the CV is shared by multiple buckets and the kernel wakes an arbitrary thread, it may be a thread waiting for another bucket's lock that gets woken up, and that can result in all threads waiting with all locks unlocked. Broadcast avoids that, and with significantly more CVs than cores, it shouldn't happen often. */ - os_condBroadcast (&s->cv); - os_mutexUnlock (&s->lock); + ddsrt_cond_broadcast (&s->cv); + ddsrt_mutex_unlock (&s->lock); } } @@ -197,25 +199,25 @@ static void *ut_chhLookupInternal (struct ut_chhBucketArray const * const bsary, uint32_t idx; do { uint32_t hopinfo; - timestamp = os_atomic_ld32 (&bs[bucket].timestamp); - os_atomic_fence_ldld (); - hopinfo = os_atomic_ld32 (&bs[bucket].hopinfo); + timestamp = ddsrt_atomic_ld32 (&bs[bucket].timestamp); + ddsrt_atomic_fence_ldld (); + hopinfo = ddsrt_atomic_ld32 (&bs[bucket].hopinfo); for (idx = 0; hopinfo != 0; hopinfo >>= 1, idx++) { const uint32_t bidx = (bucket + idx) & idxmask; - void *data = os_atomic_ldvoidp (&bs[bidx].data); + void *data = ddsrt_atomic_ldvoidp (&bs[bidx].data); if (ut_chhDataValid_p (data) && equals (data, template)) { return data; } } - os_atomic_fence_ldld (); - } while (timestamp != os_atomic_ld32 (&bs[bucket].timestamp) && ++try_counter < CHH_MAX_TRIES); + ddsrt_atomic_fence_ldld (); + } while (timestamp != ddsrt_atomic_ld32 (&bs[bucket].timestamp) && ++try_counter < CHH_MAX_TRIES); if (try_counter == CHH_MAX_TRIES) { /* Note: try_counter would not have been incremented to CHH_MAX_TRIES if we ended the loop because the two timestamps were equal, but this avoids loading the timestamp again */ for (idx = 0; idx < HH_HOP_RANGE; idx++) { const uint32_t bidx = (bucket + idx) & idxmask; - void *data = os_atomic_ldvoidp (&bs[bidx].data); + void *data = ddsrt_atomic_ldvoidp (&bs[bidx].data); if (ut_chhDataValid_p (data) && equals (data, template)) { return data; } @@ -224,15 +226,15 @@ static void *ut_chhLookupInternal (struct ut_chhBucketArray const * const bsary, return NULL; } -#define os_atomic_rmw32_nonatomic(var_, tmp_, expr_) do { \ - os_atomic_uint32_t *var__ = (var_); \ - uint32_t tmp_ = os_atomic_ld32 (var__); \ - os_atomic_st32 (var__, (expr_)); \ +#define ddsrt_atomic_rmw32_nonatomic(var_, tmp_, expr_) do { \ + ddsrt_atomic_uint32_t *var__ = (var_); \ + uint32_t tmp_ = ddsrt_atomic_ld32 (var__); \ + ddsrt_atomic_st32 (var__, (expr_)); \ } while (0) void *ut_chhLookup (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template) { - struct ut_chhBucketArray const * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray const * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); const uint32_t hash = rt->hash (template); const uint32_t idxmask = bsary->size - 1; const uint32_t bucket = hash & idxmask; @@ -241,13 +243,13 @@ void *ut_chhLookup (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRI static uint32_t ut_chhFindCloserFreeBucket (struct ut_chh *rt, uint32_t free_bucket, uint32_t *free_distance) { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const bs = bsary->bs; const uint32_t idxmask = bsary->size - 1; uint32_t move_bucket, free_dist; move_bucket = (free_bucket - (HH_HOP_RANGE - 1)) & idxmask; for (free_dist = HH_HOP_RANGE - 1; free_dist > 0; free_dist--) { - uint32_t start_hop_info = os_atomic_ld32 (&bs[move_bucket].hopinfo); + uint32_t start_hop_info = ddsrt_atomic_ld32 (&bs[move_bucket].hopinfo); uint32_t move_free_distance = NOT_A_BUCKET; uint32_t mask = 1; uint32_t i; @@ -259,15 +261,15 @@ static uint32_t ut_chhFindCloserFreeBucket (struct ut_chh *rt, uint32_t free_buc } if (move_free_distance != NOT_A_BUCKET) { ut_chhLockBucket (rt, move_bucket); - if (start_hop_info == os_atomic_ld32 (&bs[move_bucket].hopinfo)) + if (start_hop_info == ddsrt_atomic_ld32 (&bs[move_bucket].hopinfo)) { uint32_t new_free_bucket = (move_bucket + move_free_distance) & idxmask; - os_atomic_rmw32_nonatomic (&bs[move_bucket].hopinfo, x, x | (1u << free_dist)); - os_atomic_stvoidp (&bs[free_bucket].data, os_atomic_ldvoidp (&bs[new_free_bucket].data)); - os_atomic_rmw32_nonatomic (&bs[move_bucket].timestamp, x, x + 1); - os_atomic_fence (); - os_atomic_stvoidp (&bs[new_free_bucket].data, CHH_BUSY); - os_atomic_rmw32_nonatomic (&bs[move_bucket].hopinfo, x, x & ~(1u << move_free_distance)); + ddsrt_atomic_rmw32_nonatomic (&bs[move_bucket].hopinfo, x, x | (1u << free_dist)); + ddsrt_atomic_stvoidp (&bs[free_bucket].data, ddsrt_atomic_ldvoidp (&bs[new_free_bucket].data)); + ddsrt_atomic_rmw32_nonatomic (&bs[move_bucket].timestamp, x, x + 1); + ddsrt_atomic_fence (); + ddsrt_atomic_stvoidp (&bs[new_free_bucket].data, CHH_BUSY); + ddsrt_atomic_rmw32_nonatomic (&bs[move_bucket].hopinfo, x, x & ~(1u << move_free_distance)); *free_distance -= free_dist - move_free_distance; ut_chhUnlockBucket (rt, move_bucket); @@ -287,27 +289,27 @@ static void ut_chhResize (struct ut_chh *rt) => those for which the (new) msb is 0 are guaranteed to fit, and so are those for which the (new) msb is 1 => never have to resize recursively */ - struct ut_chhBucketArray * const bsary0 = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary0 = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const bs0 = bsary0->bs; struct ut_chhBucketArray *bsary1; struct ut_chhBucket *bs1; uint32_t i, idxmask0, idxmask1; assert (bsary0->size > 0); - bsary1 = os_malloc (offsetof (struct ut_chhBucketArray, bs) + 2 * bsary0->size * sizeof (*bsary1->bs)); + bsary1 = ddsrt_malloc (offsetof (struct ut_chhBucketArray, bs) + 2 * bsary0->size * sizeof (*bsary1->bs)); bsary1->size = 2 * bsary0->size; bs1 = bsary1->bs; for (i = 0; i < bsary1->size; i++) { - os_atomic_st32 (&bs1[i].hopinfo, 0); - os_atomic_st32 (&bs1[i].timestamp, 0); - os_atomic_st32 (&bs1[i].lock, 0); - os_atomic_stvoidp (&bs1[i].data, NULL); + ddsrt_atomic_st32 (&bs1[i].hopinfo, 0); + ddsrt_atomic_st32 (&bs1[i].timestamp, 0); + ddsrt_atomic_st32 (&bs1[i].lock, 0); + ddsrt_atomic_stvoidp (&bs1[i].data, NULL); } idxmask0 = bsary0->size - 1; idxmask1 = bsary1->size - 1; for (i = 0; i < bsary0->size; i++) { - void *data = os_atomic_ldvoidp (&bs0[i].data); + void *data = ddsrt_atomic_ldvoidp (&bs0[i].data); if (data && data != CHH_BUSY) { const uint32_t hash = rt->hash (data); const uint32_t old_start_bucket = hash & idxmask0; @@ -315,13 +317,13 @@ static void ut_chhResize (struct ut_chh *rt) const uint32_t dist = (i >= old_start_bucket) ? (i - old_start_bucket) : (bsary0->size + i - old_start_bucket); const uint32_t newb = (new_start_bucket + dist) & idxmask1; assert (dist < HH_HOP_RANGE); - os_atomic_rmw32_nonatomic (&bs1[new_start_bucket].hopinfo, x, x | (1u << dist)); - os_atomic_stvoidp (&bs1[newb].data, data); + ddsrt_atomic_rmw32_nonatomic (&bs1[new_start_bucket].hopinfo, x, x | (1u << dist)); + ddsrt_atomic_stvoidp (&bs1[newb].data, data); } } - os_atomic_fence (); - os_atomic_stvoidp (&rt->buckets, bsary1); + ddsrt_atomic_fence (); + ddsrt_atomic_stvoidp (&rt->buckets, bsary1); rt->gc_buckets (bsary0); } @@ -329,10 +331,10 @@ int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT da { const uint32_t hash = rt->hash (data); uint32_t size; - os_rwlockRead (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_read (&rt->resize_locks[hash % N_RESIZE_LOCKS]); { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const bs = bsary->bs; uint32_t idxmask; uint32_t start_bucket, free_distance, free_bucket; @@ -344,14 +346,14 @@ int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT da ut_chhLockBucket (rt, start_bucket); if (ut_chhLookupInternal (bsary, rt->equals, start_bucket, data)) { ut_chhUnlockBucket (rt, start_bucket); - os_rwlockUnlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_unlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); return 0; } free_bucket = start_bucket; for (free_distance = 0; free_distance < HH_ADD_RANGE; free_distance++) { - if (os_atomic_ldvoidp (&bs[free_bucket].data) == NULL && - os_atomic_casvoidp (&bs[free_bucket].data, NULL, CHH_BUSY)) { + if (ddsrt_atomic_ldvoidp (&bs[free_bucket].data) == NULL && + ddsrt_atomic_casvoidp (&bs[free_bucket].data, NULL, CHH_BUSY)) { break; } free_bucket = (free_bucket + 1) & idxmask; @@ -360,11 +362,11 @@ int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT da do { if (free_distance < HH_HOP_RANGE) { assert (free_bucket == ((start_bucket + free_distance) & idxmask)); - os_atomic_rmw32_nonatomic (&bs[start_bucket].hopinfo, x, x | (1u << free_distance)); - os_atomic_fence (); - os_atomic_stvoidp (&bs[free_bucket].data, (void *) data); + ddsrt_atomic_rmw32_nonatomic (&bs[start_bucket].hopinfo, x, x | (1u << free_distance)); + ddsrt_atomic_fence (); + ddsrt_atomic_stvoidp (&bs[free_bucket].data, (void *) data); ut_chhUnlockBucket (rt, start_bucket); - os_rwlockUnlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_unlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); return 1; } free_bucket = ut_chhFindCloserFreeBucket (rt, free_bucket, &free_distance); @@ -374,21 +376,21 @@ int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT da ut_chhUnlockBucket (rt, start_bucket); } - os_rwlockUnlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_unlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); { int i; struct ut_chhBucketArray *bsary1; for (i = 0; i < N_RESIZE_LOCKS; i++) { - os_rwlockWrite (&rt->resize_locks[i]); + ddsrt_rwlock_write (&rt->resize_locks[i]); } /* another thread may have sneaked past and grown the hash table */ - bsary1 = os_atomic_ldvoidp (&rt->buckets); + bsary1 = ddsrt_atomic_ldvoidp (&rt->buckets); if (bsary1->size == size) { ut_chhResize (rt); } for (i = 0; i < N_RESIZE_LOCKS; i++) { - os_rwlockUnlock (&rt->resize_locks[i]); + ddsrt_rwlock_unlock (&rt->resize_locks[i]); } } @@ -398,10 +400,10 @@ int ut_chhAdd (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT da int ut_chhRemove (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT template) { const uint32_t hash = rt->hash (template); - os_rwlockRead (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_read (&rt->resize_locks[hash % N_RESIZE_LOCKS]); { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const bs = bsary->bs; const uint32_t size = bsary->size; const uint32_t idxmask = size - 1; @@ -409,16 +411,16 @@ int ut_chhRemove (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT uint32_t hopinfo; uint32_t idx; ut_chhLockBucket (rt, bucket); - hopinfo = os_atomic_ld32 (&bs[bucket].hopinfo); + hopinfo = ddsrt_atomic_ld32 (&bs[bucket].hopinfo); for (idx = 0; hopinfo != 0; hopinfo >>= 1, idx++) { if (hopinfo & 1) { const uint32_t bidx = (bucket + idx) & idxmask; - void *data = os_atomic_ldvoidp (&bs[bidx].data); + void *data = ddsrt_atomic_ldvoidp (&bs[bidx].data); if (ut_chhDataValid_p (data) && rt->equals (data, template)) { - os_atomic_stvoidp (&bs[bidx].data, NULL); - os_atomic_rmw32_nonatomic (&bs[bucket].hopinfo, x, x & ~(1u << idx)); + ddsrt_atomic_stvoidp (&bs[bidx].data, NULL); + ddsrt_atomic_rmw32_nonatomic (&bs[bucket].hopinfo, x, x & ~(1u << idx)); ut_chhUnlockBucket (rt, bucket); - os_rwlockUnlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_unlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); return 1; } } @@ -426,17 +428,17 @@ int ut_chhRemove (struct ut_chh * UT_HH_RESTRICT rt, const void * UT_HH_RESTRICT ut_chhUnlockBucket (rt, bucket); } - os_rwlockUnlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); + ddsrt_rwlock_unlock (&rt->resize_locks[hash % N_RESIZE_LOCKS]); return 0; } void ut_chhEnumUnsafe (struct ut_chh * UT_HH_RESTRICT rt, void (*f) (void *a, void *f_arg), void *f_arg) { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); struct ut_chhBucket * const bs = bsary->bs; uint32_t i; for (i = 0; i < bsary->size; i++) { - void *data = os_atomic_ldvoidp (&bs[i].data); + void *data = ddsrt_atomic_ldvoidp (&bs[i].data); if (data && data != CHH_BUSY) { f (data, f_arg); } @@ -447,7 +449,7 @@ void *ut_chhIterNext (struct ut_chhIter *it) { uint32_t i; for (i = it->cursor; i < it->size; i++) { - void *data = os_atomic_ldvoidp (&it->bs[i].data); + void *data = ddsrt_atomic_ldvoidp (&it->bs[i].data); if (data && data != CHH_BUSY) { it->cursor = i+1; return data; @@ -458,7 +460,7 @@ void *ut_chhIterNext (struct ut_chhIter *it) void *ut_chhIterFirst (struct ut_chh * UT_HH_RESTRICT rt, struct ut_chhIter *it) { - struct ut_chhBucketArray * const bsary = os_atomic_ldvoidp (&rt->buckets); + struct ut_chhBucketArray * const bsary = ddsrt_atomic_ldvoidp (&rt->buckets); it->bs = bsary->bs; it->size = bsary->size; it->cursor = 0; @@ -489,8 +491,7 @@ static void ut_hhInit (struct ut_hh *rt, uint32_t init_size, ut_hhHash_fn hash, rt->hash = hash; rt->equals = equals; rt->size = size; - _Analysis_assume_(size >= HH_HOP_RANGE); - rt->buckets = os_malloc (size * sizeof (*rt->buckets)); + rt->buckets = ddsrt_malloc (size * sizeof (*rt->buckets)); for (i = 0; i < size; i++) { rt->buckets[i].hopinfo = 0; rt->buckets[i].data = NULL; @@ -499,12 +500,12 @@ static void ut_hhInit (struct ut_hh *rt, uint32_t init_size, ut_hhHash_fn hash, static void ut_hhFini (struct ut_hh *rt) { - os_free (rt->buckets); + ddsrt_free (rt->buckets); } struct ut_hh *ut_hhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals) { - struct ut_hh *hh = os_malloc (sizeof (*hh)); + struct ut_hh *hh = ddsrt_malloc (sizeof (*hh)); ut_hhInit (hh, init_size, hash, equals); return hh; } @@ -512,7 +513,7 @@ struct ut_hh *ut_hhNew (uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn eq void ut_hhFree (struct ut_hh * UT_HH_RESTRICT hh) { ut_hhFini (hh); - os_free (hh); + ddsrt_free (hh); } static void *ut_hhLookupInternal (const struct ut_hh *rt, const uint32_t bucket, const void *template) @@ -571,8 +572,7 @@ static void ut_hhResize (struct ut_hh *rt) struct ut_hhBucket *bs1; uint32_t i, idxmask0, idxmask1; - _Analysis_assume_(rt->size >= HH_HOP_RANGE); - bs1 = os_malloc (2 * rt->size * sizeof (*rt->buckets)); + bs1 = ddsrt_malloc (2 * rt->size * sizeof (*rt->buckets)); for (i = 0; i < 2 * rt->size; i++) { bs1[i].hopinfo = 0; @@ -594,7 +594,7 @@ static void ut_hhResize (struct ut_hh *rt) } } - os_free (rt->buckets); + ddsrt_free (rt->buckets); rt->size *= 2; rt->buckets = bs1; } @@ -715,8 +715,7 @@ static void ut_ehhInit (struct ut_ehh *rt, size_t elemsz, uint32_t init_size, ut rt->size = size; rt->elemsz = elemsz; rt->bucketsz = sizeof (struct ut_ehhBucket) + ((elemsz+7) & ~(size_t)7); - _Analysis_assume_(size >= HH_HOP_RANGE); - rt->buckets = os_malloc (size * rt->bucketsz); + rt->buckets = ddsrt_malloc (size * rt->bucketsz); for (i = 0; i < size; i++) { struct ut_ehhBucket *b = (struct ut_ehhBucket *) (rt->buckets + i * rt->bucketsz); b->hopinfo = 0; @@ -726,12 +725,12 @@ static void ut_ehhInit (struct ut_ehh *rt, size_t elemsz, uint32_t init_size, ut static void ut_ehhFini (struct ut_ehh *rt) { - os_free (rt->buckets); + ddsrt_free (rt->buckets); } struct ut_ehh *ut_ehhNew (size_t elemsz, uint32_t init_size, ut_hhHash_fn hash, ut_hhEquals_fn equals) { - struct ut_ehh *hh = os_malloc (sizeof (*hh)); + struct ut_ehh *hh = ddsrt_malloc (sizeof (*hh)); ut_ehhInit (hh, elemsz, init_size, hash, equals); return hh; } @@ -739,7 +738,7 @@ struct ut_ehh *ut_ehhNew (size_t elemsz, uint32_t init_size, ut_hhHash_fn hash, void ut_ehhFree (struct ut_ehh * UT_HH_RESTRICT hh) { ut_ehhFini (hh); - os_free (hh); + ddsrt_free (hh); } static void *ut_ehhLookupInternal (const struct ut_ehh *rt, uint32_t bucket, const void *template) @@ -814,7 +813,7 @@ static void ut_ehhResize (struct ut_ehh *rt) char *bs1; uint32_t i, idxmask0, idxmask1; - bs1 = os_malloc (2 * rt->size * rt->bucketsz); + bs1 = ddsrt_malloc (2 * rt->size * rt->bucketsz); for (i = 0; i < 2 * rt->size; i++) { struct ut_ehhBucket *b = (struct ut_ehhBucket *) (bs1 + i * rt->bucketsz); @@ -841,7 +840,7 @@ static void ut_ehhResize (struct ut_ehh *rt) } } - os_free (rt->buckets); + ddsrt_free (rt->buckets); rt->size *= 2; rt->buckets = bs1; } diff --git a/src/util/src/ut_thread_pool.c b/src/util/src/ut_thread_pool.c index 35d374b..acc4258 100644 --- a/src/util/src/ut_thread_pool.c +++ b/src/util/src/ut_thread_pool.c @@ -10,8 +10,12 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include -#include "os/os.h" -#include "util/ut_thread_pool.h" + +#include "dds/ddsrt/io.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/sync.h" +#include "dds/ddsrt/threads.h" +#include "dds/util/ut_thread_pool.h" typedef struct ddsi_work_queue_job { @@ -33,23 +37,23 @@ struct ut_thread_pool_s uint32_t m_job_count; /* Number of queued jobs */ uint32_t m_job_max; /* Maximum number of jobs to queue */ unsigned short m_count; /* Counter for thread name */ - os_threadAttr m_attr; /* Thread creation attribute */ - os_cond m_cv; /* Thread wait semaphore */ - os_mutex m_mutex; /* Pool guard mutex */ + ddsrt_threadattr_t m_attr; /* Thread creation attribute */ + ddsrt_cond_t m_cv; /* Thread wait semaphore */ + ddsrt_mutex_t m_mutex; /* Pool guard mutex */ }; -static uint32_t ut_thread_start_fn (_In_ void * arg) +static uint32_t ut_thread_start_fn (void * arg) { ddsi_work_queue_job_t job; ut_thread_pool pool = (ut_thread_pool) arg; /* Thread loops, pulling jobs from queue */ - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); while (pool->m_jobs != NULL) { /* Wait for job */ - os_condWait (&pool->m_cv, &pool->m_mutex); + ddsrt_cond_wait (&pool->m_cv, &pool->m_mutex); /* Check if pool deleted or being purged */ @@ -61,7 +65,7 @@ static uint32_t ut_thread_start_fn (_In_ void * arg) pool->m_jobs = job->m_next_job; pool->m_job_count--; - os_mutexUnlock (&pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); /* Do job */ @@ -69,7 +73,7 @@ static uint32_t ut_thread_start_fn (_In_ void * arg) /* Put job back on free list */ - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); pool->m_waiting++; job->m_next_job = pool->m_free; pool->m_free = job; @@ -78,35 +82,35 @@ static uint32_t ut_thread_start_fn (_In_ void * arg) if (--pool->m_threads) { /* last to leave triggers thread_pool_free */ - os_condBroadcast (&pool->m_cv); + ddsrt_cond_broadcast (&pool->m_cv); } - os_mutexUnlock (&pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); return 0; } -static os_result ut_thread_pool_new_thread (ut_thread_pool pool) +static dds_retcode_t ut_thread_pool_new_thread (ut_thread_pool pool) { static unsigned char pools = 0; /* Pool counter - TODO make atomic */ char name [64]; - os_threadId id; - os_result res; + ddsrt_thread_t id; + dds_retcode_t res; (void) snprintf (name, sizeof (name), "OSPL-%u-%u", pools++, pool->m_count++); - res = os_threadCreate (&id, name, &pool->m_attr, &ut_thread_start_fn, pool); + res = ddsrt_thread_create (&id, name, &pool->m_attr, &ut_thread_start_fn, pool); - if (res == os_resultSuccess) + if (res == DDS_RETCODE_OK) { - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); pool->m_threads++; pool->m_waiting++; - os_mutexUnlock (&pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); } return res; } -ut_thread_pool ut_thread_pool_new (uint32_t threads, uint32_t max_threads, uint32_t max_queue, os_threadAttr * attr) +ut_thread_pool ut_thread_pool_new (uint32_t threads, uint32_t max_threads, uint32_t max_queue, ddsrt_threadattr_t * attr) { ut_thread_pool pool; ddsi_work_queue_job_t job; @@ -122,14 +126,14 @@ ut_thread_pool ut_thread_pool_new (uint32_t threads, uint32_t max_threads, uint3 max_queue = threads; } - pool = os_malloc (sizeof (*pool)); + pool = ddsrt_malloc (sizeof (*pool)); memset (pool, 0, sizeof (*pool)); pool->m_thread_min = threads; pool->m_thread_max = max_threads; pool->m_job_max = max_queue; - os_threadAttrInit (&pool->m_attr); - os_mutexInit (&pool->m_mutex); - os_condInit (&pool->m_cv, &pool->m_mutex); + ddsrt_threadattr_init (&pool->m_attr); + ddsrt_mutex_init (&pool->m_mutex); + ddsrt_cond_init (&pool->m_cv); if (attr) { @@ -140,13 +144,13 @@ ut_thread_pool ut_thread_pool_new (uint32_t threads, uint32_t max_threads, uint3 while (threads--) { - if (ut_thread_pool_new_thread (pool) != os_resultSuccess) + if (ut_thread_pool_new_thread (pool) != DDS_RETCODE_OK) { ut_thread_pool_free (pool); pool = NULL; break; } - job = os_malloc (sizeof (*job)); + job = ddsrt_malloc (sizeof (*job)); job->m_next_job = pool->m_free; pool->m_free = job; } @@ -163,7 +167,7 @@ void ut_thread_pool_free (ut_thread_pool pool) return; } - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); /* Delete all pending jobs from queue */ @@ -171,21 +175,21 @@ void ut_thread_pool_free (ut_thread_pool pool) { job = pool->m_jobs; pool->m_jobs = job->m_next_job; - os_free (job); + ddsrt_free (job); } /* Wake all waiting threads */ - os_condBroadcast (&pool->m_cv); + ddsrt_cond_broadcast (&pool->m_cv); - os_mutexUnlock (&pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); /* Wait for threads to complete */ - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); while (pool->m_threads != 0) - os_condWait (&pool->m_cv, &pool->m_mutex); - os_mutexUnlock (&pool->m_mutex); + ddsrt_cond_wait (&pool->m_cv, &pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); /* Delete all free jobs from queue */ @@ -193,26 +197,26 @@ void ut_thread_pool_free (ut_thread_pool pool) { job = pool->m_free; pool->m_free = job->m_next_job; - os_free (job); + ddsrt_free (job); } - os_condDestroy (&pool->m_cv); - os_mutexDestroy (&pool->m_mutex); - os_free (pool); + ddsrt_cond_destroy (&pool->m_cv); + ddsrt_mutex_destroy (&pool->m_mutex); + ddsrt_free (pool); } -os_result ut_thread_pool_submit (ut_thread_pool pool, void (*fn) (void *arg), void * arg) +dds_retcode_t ut_thread_pool_submit (ut_thread_pool pool, void (*fn) (void *arg), void * arg) { - os_result res = os_resultSuccess; + dds_retcode_t res = DDS_RETCODE_OK; ddsi_work_queue_job_t job; - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); if (pool->m_job_max && pool->m_job_count >= pool->m_job_max) { /* Maximum number of jobs reached */ - res = os_resultBusy; + res = DDS_RETCODE_TRY_AGAIN; } else { @@ -225,7 +229,7 @@ os_result ut_thread_pool_submit (ut_thread_pool pool, void (*fn) (void *arg), vo } else { - job = os_malloc (sizeof (*job)); + job = ddsrt_malloc (sizeof (*job)); } job->m_next_job = NULL; job->m_fn = fn; @@ -257,10 +261,10 @@ os_result ut_thread_pool_submit (ut_thread_pool pool, void (*fn) (void *arg), vo /* Wakeup processing thread */ - os_condSignal (&pool->m_cv); + ddsrt_cond_signal (&pool->m_cv); } - os_mutexUnlock (&pool->m_mutex); + ddsrt_mutex_unlock (&pool->m_mutex); return res; } @@ -269,13 +273,13 @@ void ut_thread_pool_purge (ut_thread_pool pool) { uint32_t total; - os_mutexLock (&pool->m_mutex); + ddsrt_mutex_lock (&pool->m_mutex); total = pool->m_threads; while (pool->m_waiting && (total > pool->m_thread_min)) { pool->m_waiting--; total--; } - os_condBroadcast (&pool->m_cv); - os_mutexUnlock (&pool->m_mutex); + ddsrt_cond_broadcast (&pool->m_cv); + ddsrt_mutex_unlock (&pool->m_mutex); } diff --git a/src/util/src/ut_xmlparser.c b/src/util/src/ut_xmlparser.c index e59d367..92f8676 100644 --- a/src/util/src/ut_xmlparser.c +++ b/src/util/src/ut_xmlparser.c @@ -15,8 +15,10 @@ #include #include -#include "os/os.h" -#include "util/ut_xmlparser.h" +#include "dds/ddsrt/heap.h" +#include "dds/ddsrt/misc.h" +#include "dds/ddsrt/string.h" +#include "dds/util/ut_xmlparser.h" #define TOK_EOF -1 #define TOK_OPEN_TAG -2 @@ -52,42 +54,42 @@ struct ut_xmlpState { static int cb_null_elem_open (void *varg, uintptr_t parentinfo, uintptr_t *eleminfo, const char *name) { - OS_UNUSED_ARG (varg); - OS_UNUSED_ARG (parentinfo); - OS_UNUSED_ARG (eleminfo); - OS_UNUSED_ARG (name); + DDSRT_UNUSED_ARG (varg); + DDSRT_UNUSED_ARG (parentinfo); + DDSRT_UNUSED_ARG (eleminfo); + DDSRT_UNUSED_ARG (name); return 0; } static int cb_null_attr (void *varg, uintptr_t eleminfo, const char *name, const char *value) { - OS_UNUSED_ARG (varg); - OS_UNUSED_ARG (eleminfo); - OS_UNUSED_ARG (name); - OS_UNUSED_ARG (value); + DDSRT_UNUSED_ARG (varg); + DDSRT_UNUSED_ARG (eleminfo); + DDSRT_UNUSED_ARG (name); + DDSRT_UNUSED_ARG (value); return 0; } static int cb_null_elem_data (void *varg, uintptr_t eleminfo, const char *data) { - OS_UNUSED_ARG (varg); - OS_UNUSED_ARG (eleminfo); - OS_UNUSED_ARG (data); + DDSRT_UNUSED_ARG (varg); + DDSRT_UNUSED_ARG (eleminfo); + DDSRT_UNUSED_ARG (data); return 0; } static int cb_null_elem_close (void *varg, uintptr_t eleminfo) { - OS_UNUSED_ARG (varg); - OS_UNUSED_ARG (eleminfo); + DDSRT_UNUSED_ARG (varg); + DDSRT_UNUSED_ARG (eleminfo); return 0; } static void cb_null_error (void *varg, const char *msg, int line) { - OS_UNUSED_ARG (varg); - OS_UNUSED_ARG (msg); - OS_UNUSED_ARG (line); + DDSRT_UNUSED_ARG (varg); + DDSRT_UNUSED_ARG (msg); + DDSRT_UNUSED_ARG (line); } static void ut_xmlpNewCommon (struct ut_xmlpState *st) @@ -97,7 +99,7 @@ static void ut_xmlpNewCommon (struct ut_xmlpState *st) st->tpp = 0; st->tpescp = 0; st->tpsz = 1024; - st->tp = os_malloc (st->tpsz); + st->tp = ddsrt_malloc (st->tpsz); st->line = 1; st->prevline = 1; st->linemark = 0; @@ -121,10 +123,10 @@ static void ut_xmlpNewSetCB (struct ut_xmlpState *st, void *varg, const struct u struct ut_xmlpState *ut_xmlpNewFile (FILE *fp, void *varg, const struct ut_xmlpCallbacks *cb) { struct ut_xmlpState *st; - st = os_malloc (sizeof (*st)); + st = ddsrt_malloc (sizeof (*st)); st->cbufn = 0; st->cbufmax = 8192; - st->cbuf = os_malloc (st->cbufmax); + st->cbuf = ddsrt_malloc (st->cbufmax); st->fp = fp; ut_xmlpNewCommon (st); ut_xmlpNewSetCB (st, varg, cb); @@ -134,7 +136,7 @@ struct ut_xmlpState *ut_xmlpNewFile (FILE *fp, void *varg, const struct ut_xmlpC struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const struct ut_xmlpCallbacks *cb) { struct ut_xmlpState *st; - st = os_malloc (sizeof (*st)); + st = ddsrt_malloc (sizeof (*st)); st->cbufn = strlen (string); st->cbufmax = st->cbufn; st->cbuf = (char *) string; @@ -147,10 +149,10 @@ struct ut_xmlpState *ut_xmlpNewString (const char *string, void *varg, const str void ut_xmlpFree (struct ut_xmlpState *st) { if (st->fp != NULL) { - os_free (st->cbuf); + ddsrt_free (st->cbuf); } - os_free (st->tp); - os_free (st); + ddsrt_free (st->tp); + ddsrt_free (st); } static int make_chars_available (struct ut_xmlpState *st, size_t nmin) @@ -176,7 +178,7 @@ static int make_chars_available (struct ut_xmlpState *st, size_t nmin) /* buffer is owned by caller if fp = NULL, and by us if fp != NULL */ if (st->cbufp + st->cbufmax < nmin && st->fp != NULL) { st->cbufmax = st->cbufp + nmin; - st->cbuf = os_realloc (st->cbuf, st->cbufmax); + st->cbuf = ddsrt_realloc (st->cbuf, st->cbufmax); } /* try to refill buffer if a backing file is present; eof (or end-of-string) is reached when this doesn't add any bytes to the buffer */ @@ -281,7 +283,7 @@ static char *unescape_into_utf8 (char *dst, unsigned cp) return dst; } -OS_WARNING_MSVC_OFF(4996); +DDSRT_WARNING_MSVC_OFF(4996); static int unescape_insitu (char *buffer, size_t *n) { const char *src = buffer; @@ -338,7 +340,7 @@ static int unescape_insitu (char *buffer, size_t *n) *n = (size_t) (dst - buffer); return 0; } -OS_WARNING_MSVC_ON(4996); +DDSRT_WARNING_MSVC_ON(4996); static void discard_payload (struct ut_xmlpState *st) { @@ -364,7 +366,7 @@ static int append_to_payload (struct ut_xmlpState *st, int c, int islit) } if (st->tpp == st->tpsz) { st->tpsz += 1024; - st->tp = os_realloc (st->tp, st->tpsz); + st->tp = ddsrt_realloc (st->tp, st->tpsz); } return 0; } @@ -383,7 +385,7 @@ static int save_payload (char **payload, struct ut_xmlpState *st, int trim) if (payload == NULL) { p = NULL; } else if (st->tpp == 0) { - p = os_strdup(""); + p = ddsrt_strdup(""); } else { size_t first = 0, last = st->tpp - 1; if (trim) { @@ -395,9 +397,9 @@ static int save_payload (char **payload, struct ut_xmlpState *st, int trim) } } if (first > last) { - p = os_strdup(""); + p = ddsrt_strdup(""); } else { - p = os_malloc (last - first + 2); + p = ddsrt_malloc (last - first + 2); /* Could be improved, parser error will be "invalid char sequence" if malloc fails. */ memcpy (p, st->tp + first, last - first + 1); p[last - first + 1] = 0; @@ -491,7 +493,7 @@ static void drop_peek_token (struct ut_xmlpState *st) { st->peektok = 0; if (st->peekpayload) { - os_free (st->peekpayload); + ddsrt_free (st->peekpayload); st->peekpayload = NULL; } } @@ -511,7 +513,7 @@ static int next_token (struct ut_xmlpState *st, char **payload) if (payload) { *payload = st->peekpayload; } else if (st->peekpayload) { - os_free (st->peekpayload); + ddsrt_free (st->peekpayload); st->peekpayload = NULL; } return tok; @@ -587,15 +589,15 @@ static int parse_element (struct ut_xmlpState *st, uintptr_t parentinfo) PE_LOCAL_ERROR ("expecting '=' following attribute name", aname); } if (next_token (st, &content) != TOK_STRING) { - os_free (content); + ddsrt_free (content); PE_LOCAL_ERROR ("expecting string value for attribute", aname); } ret = st->cb.attr (st->varg, eleminfo, aname, content); - os_free (content); + ddsrt_free (content); if (ret < 0) { PE_ERROR2 ("failed in attribute callback", name, aname); } - os_free (aname); + ddsrt_free (aname); aname = NULL; } @@ -650,12 +652,12 @@ static int parse_element (struct ut_xmlpState *st, uintptr_t parentinfo) } else if (content != NULL) { if(*content != '\0') { ret = st->cb.elem_data (st->varg, eleminfo, content); - os_free (content); + ddsrt_free (content); if (ret < 0) { PE_ERROR ("failed in data callback", 0); } } else { - os_free (content); + ddsrt_free (content); } } } @@ -680,9 +682,9 @@ err: st->error = 1; } ok: - os_free (name); - os_free (aname); - os_free (ename); + ddsrt_free (name); + ddsrt_free (aname); + ddsrt_free (ename); return ret; #undef PE_LOCAL_ERROR #undef PE_ERROR diff --git a/src/util/tests/CMakeLists.txt b/src/util/tests/CMakeLists.txt index f3e7655..0d88ea0 100644 --- a/src/util/tests/CMakeLists.txt +++ b/src/util/tests/CMakeLists.txt @@ -11,5 +11,19 @@ # include(CUnit) -add_cunit_executable(CUnit_util "handleserver.c") -target_link_libraries(CUnit_util util) \ No newline at end of file +add_cunit_executable(cunit_util "handleserver.c") +target_link_libraries(cunit_util PRIVATE util) +target_link_libraries(cunit_util PRIVATE ddsrt) + +# Create a dummy export header. generate_export_header can only be used with +# library targets, but since the targets are linked statically, +# __declspec(dllimport) is not required anyway. +set(export_dir "${CMAKE_CURRENT_BINARY_DIR}/include/dds") +set(export_header "${export_dir}/export.h") +if(NOT EXISTS "${export_header}") + file(MAKE_DIRECTORY "${export_dir}") + file(WRITE "${export_header}" "#define DDS_EXPORT\n") +endif() + +target_include_directories( + cunit_util PRIVATE "$") diff --git a/src/util/tests/handleserver.c b/src/util/tests/handleserver.c index c009c25..ced5832 100644 --- a/src/util/tests/handleserver.c +++ b/src/util/tests/handleserver.c @@ -9,14 +9,15 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ -#include "os/os.h" -#include "util/ut_handleserver.h" +#include "dds/util/ut_handleserver.h" #include "CUnit/Test.h" +#include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/threads.h" +#include "dds/ddsrt/time.h" /*****************************************************************************************/ CU_Test(util_handleserver, basic) { - const os_time zero = { 0, 0 }; int32_t kind = 0x10000000; ut_handle_retcode_t ret; ut_handle_t hdl; @@ -35,7 +36,7 @@ CU_Test(util_handleserver, basic) ut_handle_release(hdl, NULL); - ret = ut_handle_delete(hdl, NULL, zero); + ret = ut_handle_delete(hdl, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); ret = ut_handle_claim(hdl, NULL, kind, &argx); @@ -48,7 +49,6 @@ CU_Test(util_handleserver, basic) /*****************************************************************************************/ CU_Test(util_handleserver, close) { - const os_time zero = { 0, 0 }; int32_t kind = 0x10000000; ut_handle_retcode_t ret; ut_handle_t hdl; @@ -73,7 +73,7 @@ CU_Test(util_handleserver, close) ret = ut_handle_claim(hdl, NULL, kind, &argx); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_CLOSED); - ret = ut_handle_delete(hdl, NULL, zero); + ret = ut_handle_delete(hdl, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); ret = ut_handle_claim(hdl, NULL, kind, &argx); @@ -85,7 +85,6 @@ CU_Test(util_handleserver, close) /*****************************************************************************************/ CU_Test(util_handleserver, link) { - const os_time zero = { 0, 0 }; int32_t kind = 0x10000000; ut_handle_retcode_t ret; struct ut_handlelink *link; @@ -108,7 +107,7 @@ CU_Test(util_handleserver, link) ut_handle_release(hdl, link); - ret = ut_handle_delete(hdl, link, zero); + ret = ut_handle_delete(hdl, link, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); link = ut_handle_get_link(hdl); @@ -121,7 +120,6 @@ CU_Test(util_handleserver, link) /*****************************************************************************************/ CU_Test(util_handleserver, types) { - const os_time zero = { 0, 0 }; int32_t kind1 = 0x10000000; int32_t kind2 = 0x20000000; ut_handle_retcode_t ret; @@ -170,11 +168,11 @@ CU_Test(util_handleserver, types) ut_handle_release(hdl1b, NULL); ut_handle_release(hdl2, NULL); - ret = ut_handle_delete(hdl1a, NULL, zero); + ret = ut_handle_delete(hdl1a, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); - ret = ut_handle_delete(hdl1b, NULL, zero); + ret = ut_handle_delete(hdl1b, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); - ret = ut_handle_delete(hdl2, NULL, zero); + ret = ut_handle_delete(hdl2, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); ut_handleserver_fini(); @@ -184,7 +182,6 @@ CU_Test(util_handleserver, types) /*****************************************************************************************/ CU_Test(util_handleserver, timeout) { - const os_time zero = { 0, 0 }; int32_t kind = 0x10000000; ut_handle_retcode_t ret; ut_handle_t hdl; @@ -201,12 +198,12 @@ CU_Test(util_handleserver, timeout) CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); CU_ASSERT_EQUAL_FATAL(argx, &arg); - ret = ut_handle_delete(hdl, NULL, zero); + ret = ut_handle_delete(hdl, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_TIMEOUT); ut_handle_release(hdl, NULL); - ret = ut_handle_delete(hdl, NULL, zero); + ret = ut_handle_delete(hdl, NULL, 0); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); ut_handleserver_fini(); @@ -229,7 +226,7 @@ static uint32_t deleting_thread(void *a) { thread_arg_t *arg = (thread_arg_t*)a; - const os_time ten = { 10, 0 }; + const dds_time_t ten = DDS_SECS(10); ut_handle_t ret; arg->state = DELETING; @@ -241,16 +238,16 @@ deleting_thread(void *a) return 0; } -os_result +dds_retcode_t thread_reached_state(thread_state_t *actual, thread_state_t expected, int32_t msec) { /* Convenience function. */ - os_time msec10 = { 0, 10000000 }; + dds_time_t msec10 = DDS_MSECS(10); while ((msec > 0) && (*actual != expected)) { - os_nanoSleep(msec10); + dds_sleepfor(msec10); msec -= 10; } - return (*actual == expected) ? os_resultSuccess : os_resultTimeout; + return (*actual == expected) ? DDS_RETCODE_OK : DDS_RETCODE_TIMEOUT; } CU_Test(util_handleserver, wakeup) @@ -261,10 +258,10 @@ CU_Test(util_handleserver, wakeup) int arg = 1; void *argx; - os_threadId thread_id; + ddsrt_thread_t thread_id; thread_arg_t thread_arg; - os_threadAttr thread_attr; - os_result osr; + ddsrt_threadattr_t thread_attr; + dds_retcode_t rc; ret = ut_handleserver_init(); CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK); @@ -281,26 +278,27 @@ CU_Test(util_handleserver, wakeup) /* Try deleting in other thread, which should block. */ thread_arg.hdl = hdl; thread_arg.state = STARTING; - os_threadAttrInit(&thread_attr); - osr = os_threadCreate(&thread_id, "deleting_thread", &thread_attr, deleting_thread, (void*)&thread_arg); - CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess); - osr = thread_reached_state(&thread_arg.state, DELETING, 1000); - CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess); - osr = thread_reached_state(&thread_arg.state, STOPPED, 500); - CU_ASSERT_EQUAL_FATAL(osr, os_resultTimeout); + ddsrt_threadattr_init(&thread_attr); + rc = ddsrt_thread_create(&thread_id, "deleting_thread", &thread_attr, deleting_thread, (void*)&thread_arg); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = thread_reached_state(&thread_arg.state, DELETING, 1000); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + rc = thread_reached_state(&thread_arg.state, STOPPED, 500); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_TIMEOUT); /* First release of the hdl should not unblock the thread. */ ut_handle_release(hdl, NULL); - osr = thread_reached_state(&thread_arg.state, STOPPED, 500); - CU_ASSERT_EQUAL_FATAL(osr, os_resultTimeout); + rc = thread_reached_state(&thread_arg.state, STOPPED, 500); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_TIMEOUT); /* Second release of the hdl should unblock the thread. */ ut_handle_release(hdl, NULL); - osr = thread_reached_state(&thread_arg.state, STOPPED, 500); - CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess); - os_threadWaitExit(thread_id, NULL); + rc = thread_reached_state(&thread_arg.state, STOPPED, 500); + CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK); + ddsrt_thread_join(thread_id, NULL); /* The handle is deleted within the thread. */ ut_handleserver_fini(); } +