The volatile constraints are excess when compiler barriers are present.
It generates unnecessary `mov` instructions when pointers aren't going
to be updated.
This patch addresses the thread safety problem of `jack_ringbuffer_t`
mentioned in #715 and #388. The overbound read bug caused by this problem
is impossible to reproduce on x86 due to its strong memory ordering, but
it is a problem on ARM and other weakly ordered architectures.
Basically, the main problem is that, on a weakly ordered architecture,
it is possible that the pointer increment after `memcpy` becomes visible
to the other thread before `memcpy` finishes:
memcpy (&(rb->buf[rb->write_ptr]), src, n1);
// vvv can be visible to reading thread before memcpy finishes
rb->write_ptr = (rb->write_ptr + n1) & rb->size_mask;
If this happens, the other thread can read the remaining garbage values
in `rb->buf` due to be overwritten by the unfinished `memcpy`.
To fix this, an explicit pair of release/acquire memory fences [1] is
used to ensure the copy on the other thread *happens after* the `memcpy`
finishes so no garbage values can be read.
[1]: https://preshing.com/20130922/acquire-and-release-fences/
* Add flake8 configuration
.flake8:
Add flake8 configuration that limits the line length to 120 chars and
outputs to flake8.txt
* Add flake8.txt to gitignore
.gitignore:
Add flake8.txt (flake8 output file) to ignore.
* Syntax fixes and cleanup for top-level wscript
wscript:
Fix syntax of wscript according to pep8 (but do not break long lines).
Remove unused imports and move all module level imports to the top of
the file.
Fix broken build target of IIO driver (source argument to
`create_driver_obj()` supplied an uninitialized variable).
Break lines at 120 chars.
* Fix common/wscript syntax
common/wscript:
Fix syntax problems, unneeded imports and break lines at 120 chars.
* Fix compat/alloca/wscript syntax
compat/alloca/wscript:
Fix compat/alloca/wscript syntax
* Fix compat/wscript syntax
compat/wscript:
Fix compat/wscript syntax
* Fix dbus/wscript syntax
dbus/wscript:
Fix syntax and break lintes at 120 chars.
* Fix example-clients/wscript syntax
example-clients/wscript:
Fix syntax and remove commented code.
* Fix tests/wscript syntax
tests/wscript:
Fix syntax and commented code.
* Fix tools/wscript syntax
tools/wscript:
Fix tools/wscript syntax.
* Add github workflow for linting wscripts
.github/workflows/lint.yml:
Add github workflow for linting wscripts using findutils and flake8.
* Fix project version extraction in CI
.github/workflows/build.yml:
Adapt the project version extraction in CI to the syntax changes in
the top-level wscript.
* JackWeakAPI: fix DLL loading on Windows
LoadLibrary takes a LPCWSTR (UTF16). LoadLibraryA is needed to
work with ASCII C string literals.
* JackWeakAPI: call tryload_libjack if it hasn't been called already
On non-Windows tryload_libjack is loaded on startup with
__attribute__((constructor)) but with MSVC, Microsoft documentation
says to not load libraries in a DLL's initialization function:
https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
* JackWeakAPI: add debugging message for Windows
Unbreak the build with Clang on architectures where JACK uses non-packed
data structures, like arm64 or powerpc. The alignment errors are exposed
there because:
* The non-packed data structures require 8 byte alignment.
* alignas() is not allowed to weaken alignment requirements to 4 bytes.
* Clang enforces this according to standard, GCC ignores it.
Use an additional alignas() specifier to let the compiler choose between
minimum alignment (packed) and "natural" alignment (non-packed). This is
both standard c++11 and compatible with older GCC, which does not
propagate alignment requirements of packed substructures properly.
The function pointers jack_error_callback and jack_info_callback are
offered by the jack.h header as non-weak API members, but they were not
exported to the jack library, only to the jackserver library.
This broke the Jack backend of the OpenAl Soft library when switching
from Jack1 to Jack2.
* apply changes without whitespace
* remove neon intrinsics and fix indentation
* update float_32 macro and fix misspellings
* check msbits to determine number of bits in alsa driver
* add better error messages and support for SND_PCM_FORMAT_S32_BE
* log when sample format is not equal to bits
Co-authored-by: Claudio Cabral <clca@bang-olufsen.dk>
Co-authored-by: Claudio Cabral <cl@udio.co>
Since doxygen 1.8.16, opening and closing a group must not be done as
C comment but as doxygen command. In other words, not one but two
asterisk characters are required so that doxygen finds a group.
* macOS: Pass JackMachSemaphore send right via mach_msg IPC
Previously, JackMachSemaphore would communicate the send right for the
semaphore object from the server to a client via a named service
registered via `bootstrap_register`. However, to do this, it would
register the semaphore's port as the service port directly.
In theory this ought to be fine, however in practice, macOS `launchd`,
which provides the `bootstrap_register` interface, does not correctly
detect when such a port becomes dead, and incorrectly believes that the
service that it provides is forever alive, even past the end of the
`jackd` process' (and therefore the semaphore's) existence. This seems
to be *specific* to semaphore ports, as `launchd` is expecting a
standard IPC port, owned by the task, not the kernel. This prevents
`jackd` from later registering another service with the same name, as
`launchd` rejects the registration as conflicting with an active service.
To get around this, `jackd` previously added a counter to the end of the
named service registrations, allowing old services to remain in the
system until the end of the session. To prevent things getting out of
hand, this was capped at 98 service registrations for a given semaphore
name. This led to #784, in which running a client for the 99th time
resulted in the semaphore creation failing and the client failing to
connect.
As `launchd` outlives multiple runs of `jackd`, this situation persisted
across restarts of `jackd`, requiring a restart of the user's session
(i.e. a reboot) to fix.
An initial attempt at fixing this (see #785) tried passing the port
rights directly via shared memory, however mach is too clever for us and
foils that plan by having port names be looked up in a per-task table
(sensible when you think about it).
In this commit, we use mach IPC messages to transfer the send right for
the semaphore from the server to the client. By registering a standard
IPC port with the bootstrap server, the service registrations are
correctly torn down when the ports are destroyed.
It works something like this:
* Server creates IPC port and registers it globally via `bootstrap_register`
* Server listens on IPC port for messages
* Client looks up IPC port via `bootstrap_look_up`
* Client sends it a message
* Server replies with a message containing a send right to the
semaphore's port
* Client is then free to use the semaphore port as before.
This resolves#784.
* Improve error handling
* Add myself to Authors
* Add jack_position_t::tick_double, and flags around it
Signed-off-by: falkTX <falktx@falktx.com>
* s/precision/resolution/
Signed-off-by: falkTX <falktx@falktx.com>
* Assert alignment is suitable for atomic accesses
* Move fields and pad to meet alignment constraints
* Add padding to JackEngineControl to account for inherited data
* Parenthesise padding length for clarity
* Revert "Parenthesise padding length for clarity"
This reverts commit 1f757b9ece5e3b032743c6c5ac49e83c3928e3de.
* Revert "Add padding to JackEngineControl to account for inherited data"
This reverts commit 3d8c7d83ad9483280f623171af7e40ccc76cef38.
* Revert "Move fields and pad to meet alignment constraints"
This reverts commit ff631bbbdc2279df05f3a18dd44e8fd68be2e04d.
* Assure alignment by using 'alignas' on fields
FUTEX_WAIT may be interrupted by a signal and return EINTR. If a client
process takes a signal while on the futex, the jack client may error out
with no way to recover despite the signal being safe. Instead, retry if
errno is set to EINTR.
jack_port_get_latency_range only returns meaningful values after ports get
connected, and that is signalled via the latency callback. Saying that it's
normally used in callbacks is too soft, the docs should make it clear that the
function is not very useful outside of the callback, because you don't know
whether the port is connected / whether the latency values changed.
to ensure that it is not modified by any client.
const have internal linkage unless marked by extern
Change-Id: Ife1def2feb43aead32164f479e39ee3fd71b2ba0
Signed-off-by: Adam Miartus <external.Adam.Miartus@de.bosch.com>
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Change-Id: I66e0960c9ab1a097de3098d4f51e0fff4d064186
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
(cherry picked from commit 12f6a01bcb23be1f859990675a20f980dab55ac8)
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
(cherry picked from commit 733c147c23dc90a8330521c49e5fd76340bcb381)
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Change-Id: I63a7330408d75f21e25426e42260133669a0db0e
(cherry picked from commit 41b58edf09236db477bc1d56308a2b6e71515963)
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Change-Id: I88003f8c55184b141ffd4e068eba889776ce9b14
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
(cherry picked from commit 742dc38a0d549338a4296ec39edba580f93d40b7)
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Change-Id: I5f5b4a2d0a52ef12ac4e396f40002e8dec916cfb
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
(cherry picked from commit c438633cccfb327219cd28fbfdecc79fb18cdb3b)
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
* Add guide for compiling on MinGW using waf
* Update wscripts and guide for MinGW
* Fix README_MINGW typos
* Add instructions for ASIO support
* Update jackd example
* Patch for metadata support on Windows
* Update VS project for building JackRouter
* JackRouter/VS: add int redefinition fix to all build configurations
* VS: ignore Visual Studio build files and user settings
* Revise and extend README_MINGW
* Fix typos in README_MINGW
* Update MinGW build guide
* Replace MAX_PATH with PATH_MAX (win32)
* Include limits.h in JackMetadata.h
Co-authored-by: Schrödinger's Cat <6382400+Schroedingers-Cat@users.noreply.github.com>
* Set MIDI port pretty names on macOS
* Set MIDI port pretty names on Windows
* Set MIDI port pretty names on Linux/alsarawmidi
* Update alsarawmidi port naming to match CoreMIDI and WinMME
* Rename PortSetPrettyNameProperty to PortSetDeviceName
* Set hardware property to MIDI port names
aften v0.0.8 is latest released tarball.
https://downloads.sourceforge.net/aften/aften-0.0.8.tar.bz2
Travis builds for OSX use aften v0.0.8 (brew).
More recent aften code has introduced an additional parameter to aften_encode_frame().
The check in wscript compiles a small test program to see if the additional parameter is understood.
If additional parameter 'count' is available, set HAVE_AFTEN_NEW_API.
HAVE_AFTEN_NEW_API is used in common/JackAC3Encoder.cpp to call aften_encode_frame()
either with or without 'count' param.
Problem:
int res = aften_encode_frame(&fAftenContext, fAC3Buffer + SPDIF_HEADER_SIZE, fSampleBuffer);
Fails, because API is
AFTEN_API int aften_encode_frame(AftenContext *s, unsigned char *frame_buffer,const void *samples, int count)
The additional parameter 'count' was added to libaften function aften_encode_frame() here:
e1cbb66628 (diff-d4868af7d235a914aef2ec4f979fcb9fR87)
Solves https://github.com/jackaudio/jack2/issues/455