Commit graph

83 commits

Author SHA1 Message Date
Takashi Iwai
54931e5a54 pcm: Add thread-safety to PCM API
Traditionally, many of ALSA library functions are supposed to be
thread-unsafe, and applications are required to take care of thread
safety by themselves.  However, people never be careful enough, and
almost all applications fail in this regard.

This patch is an attempt to harden the thread safety in exported PCM
functions in a simplistic way: just wrap some of exported functions
with the pthread mutex of each PCM object.  Not all API functions are
wrapped by the mutex since it doesn't make sense.  Instead, the
patchset covers only the functions that may be likely called
concurrently.  The supposedly thread-safe API functions are marked in
the document.

For achieving the feature, two new fields are added snd_pcm_t when the
option is enabled: thread_safe and lock.  The former indicates that
the plugin is thread-safe that doesn't need this workaround and the
latter is the pthread mutex.  Currently only hw plugin have
thread_safe=1.  So, the most of real-time sensitive apps won't be
influenced by this patchset.

Although the patch covers most of PCM ops, a few snd_pcm_fast_ops are
left without the extra mutex locking: namely, the ones that may have
blocking behavior, i.e. resume, drain, readi, writei, readn and
writen.  These are supposed to handle own locking in the callbacks.

Also, if anyone wants to disable this new thread-safe API feature, it
can be still turned off via --disable-thread-safety configure option.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-07-11 15:25:30 +02:00
Mike Frysinger
561df6fda0 support building w/out System V shared memory
Some systems, like Android/Bionic, do not support SysV at all.
Let the configure script detect if the header is available, and
if not, automatically disable the pieces that require it.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-05 14:37:11 +01:00
Mike Frysinger
5a24987575 move page helpers to common code
If you build with --disable-pcm, the rawmidi code fails to link because
it uses the page_size helper declared in local.h, but the page_* funcs
are in the pcm mmap module.  Move these funcs into conf.c so that they
are always available to the rest of the system.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-11-05 14:37:10 +01:00
Antonio Borneo
b7334b1a81 pcm: add missing "break" in "switch"
A missing "break" in procedure snd_pcm_write_mmap() causes
execution of "case SND_PCM_ACCESS_MMAP_NONINTERLEAVED" to
fall through next "default" case of the "switch" statement.
Since "default" handles error cases, the procedure returns
error.

The error fixed by this patch blocks transfer of capture
data from kernel to application. Execution get stuck in
alsa-lib, that discards all received data.

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-05-14 16:55:39 +02:00
Julia Lawall
fef6e6fd58 src/pcm/pcm_mmap.c: add missing free
The mmap_channels and running_areas fields are allocated using calloc, but
are not freed on an error path.

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Suman Saha <sumsaha@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-22 14:11:10 +02:00
Takashi Iwai
67399e35ff Fix wrong offset calculation in snd_pcm_{read|write}_mmap()
The offset used in snd_pcm_{read|write}_mmap() is not the linear offset
but the offset in a ring buffer.  It has to be rounded.
2007-09-20 13:20:03 +02:00
Takashi Iwai
4cdb17c601 Split mmap-emulation code from hw layer
Move out mmap-emulation code from hw layer to its own plugin.
This cleans up the mess in pcm_hw.c.
2007-07-11 17:44:09 +02:00
Jaroslav Kysela
b08e01ca9e pcm - fix the buffer allocation for NONINTERLEAVED mmap access
The previous code did not allocated a separate buffer for all channels
when a NONINTERLEAVED access was used. The result was that only one
"shared" buffer was incorrectly allocated.

Also, the code was a bit cleaned (cosmetic change only).
2006-01-02 12:16:59 +00:00
Takashi Iwai
3ffeaf4cb1 Minor optimization on mmap
Minor optimization on mmap.
2005-11-30 11:39:21 +00:00
Takashi Iwai
ffdb04c3ea Fix buffer allocation and mmap with plugins
Fixed the bug producing silent tones with some combinations of plugins.
The internal buffer handling is now better (cleaner) integrated with
snd_pcm_generic_*().
2005-09-02 16:36:40 +00:00
Takashi Iwai
6e1bc68070 Minor clean up
Minor clean up.
2005-05-23 09:04:15 +00:00
Takashi Iwai
4d7c53d280 Add snd_pcm_hw_params_get/set_export_buffer()
Add snd_pcm_hw_params_get/set_export_buffer() API functions.
They control to ensure the buffer export to other processes.
If this flag is set, the local buffer of a plugin is exported over IPC shm.
Otherwise the buffer can be handled only locally (no shm).

Also fixed Version file for 1.0.9.
2005-05-19 16:59:04 +00:00
Takashi Iwai
2b54677fdb Change error message handling
Change the handling of non-fatal errors.  Now the non-fatal error
messages are not shown in stderr and no assert() as default.  The
behavior can be changed with LIBASOUND_DEBUG environment variable.
2004-12-21 14:11:00 +00:00
Jaroslav Kysela
131d6610fc Fixed file plugin - mmap access was broken and revents were not handled correctly 2004-02-08 10:19:52 +00:00
Jaroslav Kysela
b798d89c0f <atlka@pg.gda.pl>
- shm memory patch
- optimized a bit sample mixing routines in c and x_86 asm
2004-01-24 16:34:35 +00:00
Jaroslav Kysela
852b0c6129 Adam Tla/lka <atlka@pg.gda.pl>
SHM memory leak fix
2004-01-20 12:47:05 +00:00
Jaroslav Kysela
63c19961b9 Takashi: added shadow pcm to avoid problem with plug plugin and mmaped access 2003-08-08 09:06:41 +00:00
Jaroslav Kysela
b004a9d791 Added snd_pcm_munmap() call to snd_pcm_close() - free all resources 2003-06-22 09:59:03 +00:00
Jaroslav Kysela
573f85dc1d - added shm area manager code
- fixed parsing of period_size/buffer_size options for dmix, dsnoop and
  dshare plugins
2003-04-23 12:41:55 +00:00
Jaroslav Kysela
8faee9967f Fixed nasty bug when we used more ipc buffers for interleaved access 2003-02-28 20:32:07 +00:00
Jaroslav Kysela
8720faaccb Cleanups in IPC stuff.
Cleanups in snd_pcm_close().
Added initial code for dmix plugin:
  - only skeleton, but all major problems should be solved
2003-02-04 14:48:51 +00:00
Takashi Iwai
12e89c5307 fixed compile warning (conversion between signed and unsigned). 2002-06-18 16:06:14 +00:00
Jaroslav Kysela
c941c548f8 Moved ring buffer pointers and added a mechanism to transfer them via shm 2002-04-23 15:51:29 +00:00
Jaroslav Kysela
853304bbf4 Corrections by Kevin Conder <kconder@interaccess.com> 2002-03-12 20:14:33 +00:00
Jaroslav Kysela
e128bf856e Cleaned the mmap_commit implementations in plugins.
Added undo callbacks for snd_pcm_plugin based plugins.
  - helpers when mmap_commit proceed only a partial transfer
Fixes to avail_update implementation in pcm_hw.c.
2002-02-21 15:01:34 +00:00
Jaroslav Kysela
3e3df2d32b Updated GNU GPL license (address).
Changed GNU LGPL licence from 2.0 to 2.1.
2001-12-30 09:22:54 +00:00
Jaroslav Kysela
6113d83e08 Fixed munmap sizes (SIGSEGV) 2001-12-15 17:22:31 +00:00
Jaroslav Kysela
b63e44aab0 Synchronized snd_pcm_write_areas and snd_pcm_read_areas with the kernel
write/read functions.
Changed snd_pcm_xfer_areas_func_t to return snd_pcm_sframes_t (pass errors).
2001-12-09 12:32:42 +00:00
Jaroslav Kysela
8ca451f0e1 Improved mmap_write and mmap_read functions 2001-12-08 21:00:51 +00:00
Jaroslav Kysela
78f86ed011 Added mmap_write & mmap_readi functions to include/pcm.h. 2001-10-18 18:05:41 +00:00
Jaroslav Kysela
c20c954f3d Added documentation for instrument and midi event functions.
Removed snd_enum_() macros.
Documentation changes in asoundlib.h.
2001-07-11 14:09:01 +00:00
Jaroslav Kysela
00c749f080 Reverted back the previous read/write_areas code 2001-05-14 15:21:18 +00:00
Jaroslav Kysela
808fb82d1f Enhanced snd_pcm_mmap_read/write_areas to support the blocking behaviour.
Removed wrong asserts.
2001-05-14 14:31:45 +00:00
Abramo Bagnara
6a3b962d06 Better PCM mmap API. Fixed pcm_multi 2001-04-13 15:40:53 +00:00
Abramo Bagnara
5b50ec848a Lot of cleanings with the help of gcc3 2001-03-29 17:50:28 +00:00
Abramo Bagnara
ddc9a186cf Completed PCM documentation 2001-03-24 16:14:44 +00:00
Abramo Bagnara
5e2c5cab92 Removed obsolete code 2001-03-08 14:21:15 +00:00
Abramo Bagnara
3830b168ef Improved plugin code (simpler, faster and multithread ready) 2001-02-27 13:42:12 +00:00
Abramo Bagnara
c663f4f4f7 Transformed PAGE_SIZE in sysconf(_SC_PAGE_SIZE) 2001-02-21 21:59:35 +00:00
Abramo Bagnara
a2d3434961 Completed mixer API. Improved iterators. Renamed control values struct. Rewritten simple elements implementation 2001-02-11 15:45:35 +00:00
Abramo Bagnara
8f0cb26fdf Control API encapsulation. Better names for kernel API. Simpler PCM hw_params API. Added missing const. 2001-02-06 23:48:10 +00:00
Abramo Bagnara
4ecd9eaa46 Fixed some typos 2001-02-04 22:59:24 +00:00
Abramo Bagnara
a7561a9c7e Corrected and completed encapsulation for PCM and rawmidi. Remove SND_PCM_HW_PARAM_* and use functions. Separated rawmidi info between streams 2001-02-04 17:03:17 +00:00
Abramo Bagnara
de19407578 Removed card type from devices info. Added card number to devices info. Completed encapsulation of PCM API. Removed snd_pcm_card(). All copy functions now have the form copy(dst, src). 2001-01-31 17:26:56 +00:00
Abramo Bagnara
b4e80abc53 Rewritten mmap_{read,write} following alsa-driver current code 2001-01-20 12:56:30 +00:00
Abramo Bagnara
aa813e1f39 Uniformed some internal names. Bug fixes 2001-01-15 15:15:24 +00:00
Abramo Bagnara
cc90e32557 New PCM model with fragment concept removal and two interrupt sources
Renamed size_t/ssize_t to snd_pcm_sframes_t/snd_pcm_uframes_t
2001-01-15 11:06:53 +00:00
Abramo Bagnara
e618ef6f00 Fixed a bug in interval printing. Added missing mmap functions. Added _try hw_params variant. 2000-12-30 17:20:23 +00:00
Abramo Bagnara
6425734d82 Fixes to mmap size computing 2000-12-23 16:46:17 +00:00
Abramo Bagnara
5860beac69 Some cleaning to mmap 2000-12-11 15:54:55 +00:00