Fix int32_t-vs-int portability; align CThread assignment with std::thread#3329
Fix int32_t-vs-int portability; align CThread assignment with std::thread#3329aklofas wants to merge 3 commits into
Conversation
|
I'd have different changes in mind.
|
…read On targets where int32_t is a distinct type from int (e.g. the newlib arm-none-eabi bare-metal toolchain, where int32_t is long int): - CSrtConfig::iMSS is now int32_t, matching the wire field CHandShake::m_iMSS it is clamped against, so the std::min in acceptAndRespond() deduces its template argument. The two SRTO_UDP_SNDBUF/RCVBUF setters that std::max against iMSS read the option value as int32_t for the same reason. - EventVariant grows a no-argument constructor (type = UNDEFINED) for events that pass no argument; TEV_SYNC uses it instead of the ambiguous EventVariant(0) (int32_t vs const CPacket* overloads). - CThread::operator= on the POSIX backend now matches std::thread semantics: assigning to a joinable thread is std::terminate(), not pthread_cancel(). This removes the only pthread_cancel() call, so pthread backends without thread cancellation (Android, OHOS, RTOS pthread layers such as FreeRTOS-Plus-POSIX) need no special-casing. No-ops on platforms where int32_t == int, except the assign-to-joinable IPE path, which now aborts like the ENABLE_STDCXX_SYNC backend instead of cancelling the live thread.
Upstream PR Haivision/srt#3329 review (ethouris): type CSrtConfig::iMSS as int32_t (the wire type) instead of pinning std::min; give EventVariant a no-arg UNDEFINED constructor for TEV_SYNC instead of int32_t(0); make POSIX CThread assign-to-joinable std::terminate() like std::thread, removing libsrt's only pthread_cancel call. The SRT_NO_PTHREAD_CANCEL opt-out define no longer exists, so drop it from the substrate flags. All five freertos-srt QEMU gates green with the regenerated patch.
a2210eb to
ac88ce2
Compare
|
Reworked along the lines you suggested — all three points, and the branch is updated:
Re-verified on both ends: desktop Release build with the full |
Summary
Three small portability fixes that let
libsrtcompile and run on toolchains whereint32_tis a distinct type fromint(e.g. the newlibarm-none-eabibare-metal toolchain, whereint32_tislong int) and on pthread backends without thread cancellation.Reworked per review (see comments): the config field is typed to match the wire,
TEV_SYNCpasses no argument, andCThreadassignment matchesstd::thread— no opt-out define needed anymore.Changes
1.
CSrtConfig::iMSSis nowint32_tMatching the handshake wire field
CHandShake::m_iMSSit is clamped against, sostd::min(m_config.iMSS, w_hs.m_iMSS)inacceptAndRespond()deduces its template argument. TheSRTO_UDP_SNDBUF/SRTO_UDP_RCVBUFsetters thatstd::maxthe option value againstiMSSread it withcast_optval<int32_t>for the same reason. Whereint32_t == intthis is a pure no-op.2.
common.h/core.h—EventVariant()no-argument constructorEventVariant(0)at theTEV_SYNCcall site was ambiguous betweenEventVariant(int32_t)andEventVariant(const CPacket*)onceint32_tis notint.TEV_SYNCpasses no argument (no slot is connected to it, andupdateCCnever reads the arg for it), soEventVariantnow has a no-argument constructor producingUNDEFINED, used at that call site.3.
sync_posix.cpp—CThreadassign-to-joinable matchesstd::threadCThread::operator=calledpthread_cancel()on a still-joinable thread — guarded out on Android/OHOS (#1476 / #1484) and missing on some RTOS pthread backends (e.g. FreeRTOS-Plus-POSIX). Perstd::threadsemantics ([thread.thread.assign]) and theENABLE_STDCXX_SYNCbackend, this is nowstd::terminate()after the existing IPE log line. This removes the onlypthread_cancelcall in the codebase, so no platform special-casing is needed at all.Testing
Built and run on bare-metal
arm-none-eabi(Cortex-M4F) under QEMU on a FreeRTOS + lwIP substrate (pthread sync backend,ENABLE_STDCXX_SYNC=OFF):libsrtcross-compiles cleanly; ansrt_startup→srt_create_socket→srt_getsockstate→srt_close→srt_cleanupsmoke test and a caller↔listener loopback transfer over a lossy link (plain and AES-128 via mbedTLS) pass. Desktop Release build withENABLE_UNITTESTS=ONcompiles unchanged and the fulltest-srtsuite passes (275/275).Behavior note: the only behavior change on existing platforms is the assign-to-joinable IPE path, which now terminates — as
std::threadand theENABLE_STDCXX_SYNCbuild already do — instead of cancelling the live thread.