Takashi Iwai
cd5dd1370c
- Backport a few fix patches from upstream, mostly for fixing crashes in multi-thread programs: 0044-configure-do-not-detect-incorrect-cross-compiler.patch 0045-ucm-Set-uc_mgr-ctl-to-NULL-after-closing-it.patch 0046-snd_pcm_direct_parse_open_conf-use-thread-safe-getgr.patch 0047-Add-snd_lib_error_set_local-to-install-a-thread-loca.patch 0048-snd_device_name_hint-do-not-change-the-global-error-.patch 0049-snd_device_name_hint-do-not-use-global-snd_config.patch 0050-conf-Fix-a-memory-access-violation-resulting-from-im.patch OBS-URL: https://build.opensuse.org/request/show/150679 OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=123
99 lines
3.1 KiB
Diff
99 lines
3.1 KiB
Diff
From 44c1a623dd1fc9e831616b663bebc54ca98df994 Mon Sep 17 00:00:00 2001
|
|
From: Jerome Forissier <jerome@taodyne.com>
|
|
Date: Thu, 31 Jan 2013 15:47:23 +0100
|
|
Subject: [PATCH 47/50] Add snd_lib_error_set_local() to install a thread-local
|
|
error handler.
|
|
|
|
This is required so we can make other functions reentrant (such as
|
|
snd_device_name_hint()).
|
|
The default error handling function snd_lib_error_default() now checks
|
|
if a local handler exists, and if so, calls it. Otherwise, the previous
|
|
behavior is unchanged.
|
|
|
|
Signed-off-by: Jerome Forissier <jerome@taodyne.com>
|
|
Signed-off-by: Takashi Iwai <tiwai@suse.de>
|
|
---
|
|
configure.in | 10 ++++++++++
|
|
include/error.h | 6 ++++++
|
|
src/error.c | 24 +++++++++++++++++++++++-
|
|
3 files changed, 39 insertions(+), 1 deletion(-)
|
|
|
|
--- a/configure.in
|
|
+++ b/configure.in
|
|
@@ -281,6 +281,16 @@ else
|
|
AC_MSG_RESULT(no)
|
|
fi
|
|
|
|
+dnl Check for __thread
|
|
+AC_MSG_CHECKING([for __thread])
|
|
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) || (__GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ < 2))
|
|
+#error gcc has this bug: http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
|
|
+#endif], [static __thread int p = 0])],
|
|
+[AC_DEFINE(HAVE___THREAD, 1,
|
|
+Define to 1 if compiler supports __thread)
|
|
+AC_MSG_RESULT([yes])],
|
|
+[AC_MSG_RESULT([no])])
|
|
+
|
|
dnl Check for librt
|
|
AC_MSG_CHECKING(for librt)
|
|
AC_ARG_WITH(librt,
|
|
--- a/include/error.h
|
|
+++ b/include/error.h
|
|
@@ -74,5 +74,11 @@ extern int snd_lib_error_set_handler(snd
|
|
}
|
|
#endif
|
|
|
|
+typedef void (*snd_local_error_handler_t)(const char *file, int line,
|
|
+ const char *func, int err,
|
|
+ const char *fmt, va_list arg);
|
|
+
|
|
+snd_local_error_handler_t snd_lib_error_set_local(snd_local_error_handler_t func);
|
|
+
|
|
#endif /* __ALSA_ERROR_H */
|
|
|
|
--- a/src/error.c
|
|
+++ b/src/error.c
|
|
@@ -60,6 +60,21 @@ const char *snd_strerror(int errnum)
|
|
return snd_error_codes[errnum];
|
|
}
|
|
|
|
+#ifdef HAVE___THREAD
|
|
+#define TLS_PFX __thread
|
|
+#else
|
|
+#define TLS_PFX /* NOP */
|
|
+#endif
|
|
+
|
|
+static TLS_PFX snd_local_error_handler_t local_error = NULL;
|
|
+
|
|
+snd_local_error_handler_t snd_lib_error_set_local(snd_local_error_handler_t func)
|
|
+{
|
|
+ snd_local_error_handler_t old = local_error;
|
|
+ local_error = func;
|
|
+ return old;
|
|
+}
|
|
+
|
|
/**
|
|
* \brief The default error handler function.
|
|
* \param file The filename where the error was hit.
|
|
@@ -69,12 +84,19 @@ const char *snd_strerror(int errnum)
|
|
* \param fmt The message (including the format characters).
|
|
* \param ... Optional arguments.
|
|
*
|
|
- * Prints the error message including location to \c stderr.
|
|
+ * If a local error function has been installed for the current thread by
|
|
+ * \ref snd_lib_error_set_local, it is called. Otherwise, prints the error
|
|
+ * message including location to \c stderr.
|
|
*/
|
|
static void snd_lib_error_default(const char *file, int line, const char *function, int err, const char *fmt, ...)
|
|
{
|
|
va_list arg;
|
|
va_start(arg, fmt);
|
|
+ if (local_error) {
|
|
+ local_error(file, line, function, err, fmt, arg);
|
|
+ va_end(arg);
|
|
+ return;
|
|
+ }
|
|
fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
|
|
vfprintf(stderr, fmt, arg);
|
|
if (err)
|