[Cbe-oss-dev] [PATCH 2/3] libspe2: Fix deadlock in C99 freopen handler
Kazunori Asayama
asayama at sm.sony.co.jp
Tue Apr 10 23:45:19 EST 2007
The current implementation of C99 freopen handler in libspe2 causes
deadlock because of a recursive lock. Here is a patch to fix the
problem.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
Index: libspe2-2.1.0/spebase/default_c99_handler.c
===================================================================
--- libspe2-2.1.0.orig/spebase/default_c99_handler.c
+++ libspe2-2.1.0/spebase/default_c99_handler.c
@@ -318,11 +318,10 @@ static void __copy_va_temp(struct __va_t
#define __copy_va_temp(vtemps) /* do nothing */
#endif /* __powerpc64__ */
-static inline FILE *get_FILE(int nr)
+static inline FILE *get_FILE_nolock(int nr)
{
FILE *ret;
- pthread_mutex_lock(&spe_c99_file_mutex);
if (nr <= 0) {
ret = NULL;
} else if (nr >= SPE_FOPEN_MAX) {
@@ -343,6 +342,15 @@ static inline FILE *get_FILE(int nr)
break;
}
}
+ return ret;
+}
+
+static inline FILE *get_FILE(int nr)
+{
+ FILE *ret;
+
+ pthread_mutex_lock(&spe_c99_file_mutex);
+ ret = get_FILE_nolock(nr);
pthread_mutex_unlock(&spe_c99_file_mutex);
return ret;
}
@@ -997,7 +1005,7 @@ int default_c99_handler_freopen(char *ls
path = GET_LS_PTR(arg0->slot[0]);
mode = GET_LS_PTR(arg1->slot[0]);
pthread_mutex_lock(&spe_c99_file_mutex);
- spe_FILE_ptrs[i] = freopen(path, mode, get_FILE(i));
+ spe_FILE_ptrs[i] = freopen(path, mode, get_FILE_nolock(i));
if (spe_FILE_ptrs[i]) {
PUT_LS_RC(i, 0, 0, 0);
} else {
More information about the cbe-oss-dev
mailing list