This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] Disable thread cancellation support for RTEMS
- From: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- To: newlib at sourceware dot org
- Cc: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- Date: Fri, 22 Mar 2013 15:47:01 +0100
- Subject: [PATCH] Disable thread cancellation support for RTEMS
Use a define to manage the stdio thread cancellation support. Disable
the thread cancellation support for RTEMS. In RTEMS the availability of
POSIX threads is optional and depends on a configuration option. To
support all RTEMS configurations we have to drop the thread cancellation
support. A long term solution has to be developed in RTEMS to deal with
this. Once this is done, we can enable the support in Newlib again.
It seems that the Newlib locks are missing in general on RTEMS:
https://www.rtems.org/bugzilla/show_bug.cgi?id=1247
newlib/ChangeLog
2013-03-22 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libc/stdio/local.h (_STDIO_WITH_THREAD_CANCELLATION_SUPPORT):
New define.
* libc/stdio/fclose.c: Use
_STDIO_WITH_THREAD_CANCELLATION_SUPPORT.
* libc/stdio/freopen.c: Likewise.
* libc/stdio64/freopen64.c: Likewise.
---
newlib/libc/stdio/fclose.c | 6 +++---
newlib/libc/stdio/freopen.c | 8 ++++----
newlib/libc/stdio/local.h | 11 ++++++++---
newlib/libc/stdio64/freopen64.c | 4 ++--
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/newlib/libc/stdio/fclose.c b/newlib/libc/stdio/fclose.c
index 7904964..fd054fe 100644
--- a/newlib/libc/stdio/fclose.c
+++ b/newlib/libc/stdio/fclose.c
@@ -78,7 +78,7 @@ _DEFUN(_fclose_r, (rptr, fp),
/* We can't use the _newlib_flockfile_XXX macros here due to the
interlocked locking with the sfp_lock. */
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
int __oldcancel;
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel);
#endif
@@ -87,7 +87,7 @@ _DEFUN(_fclose_r, (rptr, fp),
if (fp->_flags == 0) /* not open! */
{
_funlockfile (fp);
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
return (0);
@@ -112,7 +112,7 @@ _DEFUN(_fclose_r, (rptr, fp),
#endif
__sfp_lock_release ();
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index b33eb1e..884e561 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -102,7 +102,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
/* We can't use the _newlib_flockfile_XXX macros here due to the
interlocked locking with the sfp_lock. */
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
int __oldcancel;
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel);
#endif
@@ -111,7 +111,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile (fp);
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
_fclose_r (ptr, fp);
@@ -222,7 +222,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
__lock_close_recursive (fp->_lock);
#endif
__sfp_lock_release ();
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
return NULL;
@@ -242,7 +242,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
#endif
_funlockfile (fp);
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
return fp;
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index b4bc5e0..58a16bd 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -45,7 +45,12 @@
section before reaching the end of the critical section's code end, use
the appropriate _newlib_XXX_exit macro. */
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS) \
+ && !defined (__rtems__)
+#define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
+#endif
+
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
#include <pthread.h>
/* Start a stream oriented critical section: */
@@ -84,7 +89,7 @@
pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \
}
-#else /* __SINGLE_THREAD__ || !_POSIX_THREADS */
+#else /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */
# define _newlib_flockfile_start(_fp) \
{ \
@@ -108,7 +113,7 @@
__sfp_lock_release (); \
}
-#endif /* !__SINGLE_THREAD__ && _POSIX_THREADS */
+#endif /* _STDIO_WITH_THREAD_CANCELLATION_SUPPORT */
extern u_char *_EXFUN(__sccl, (char *, u_char *fmt));
extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
diff --git a/newlib/libc/stdio64/freopen64.c b/newlib/libc/stdio64/freopen64.c
index db0e1ee..dfe36ea 100644
--- a/newlib/libc/stdio64/freopen64.c
+++ b/newlib/libc/stdio64/freopen64.c
@@ -102,7 +102,7 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
/* We can't use the _newlib_flockfile_XXX macros here due to the
interlocked locking with the sfp_lock. */
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
int __oldcancel;
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel);
#endif
@@ -111,7 +111,7 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile (fp);
-#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
+#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
_fclose_r (ptr, fp);
--
1.7.7