+2015-09-03 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * config/gthr-rtems.h (__GTHREADS_CXX0X): New.
+ (__GTHREAD_HAS_COND): Likewise.
+ (__gthread_t): Likewise.
+ (__gthread_cond_t): Likewise.
+ (__gthread_time_t): Likewise.
+ (__GTHREAD_MUTEX_INIT): Likewise.
+ (__GTHREAD_RECURSIVE_MUTEX_INIT): Likewise.
+ (__GTHREAD_COND_INIT): Likewise.
+ (__GTHREAD_COND_INIT_FUNCTION): Likewise.
+ (__GTHREAD_TIME_INIT): Likewise.
+ (__gthread_create): Likewise.
+ (__gthread_join): Likewise.
+ (__gthread_detach): Likewise.
+ (__gthread_equal): Likewise.
+ (__gthread_self): Likewise.
+ (__gthread_yield): Likewise.
+ (__gthread_cond_broadcast): Likewise.
+ (__gthread_cond_signal): Likewise.
+ (__gthread_cond_wait): Likewise.
+ (__gthread_cond_timedwait): Likewise.
+ (__gthread_cond_wait_recursive): Likewise.
+ (__gthread_cond_destroy): Likewise.
+ (rtems_gxx_once): Delete.
+ (rtems_gxx_key_create): Likewise.
+ (rtems_gxx_key_delete): Likewise.
+ (rtems_gxx_getspecific): Likewise.
+ (rtems_gxx_setspecific): Likewise.
+ (rtems_gxx_mutex_init): Likewise.
+ (rtems_gxx_mutex_destroy): Likewise.
+ (rtems_gxx_mutex_lock): Likewise.
+ (rtems_gxx_mutex_trylock): Likewise.
+ (rtems_gxx_mutex_unlock): Likewise.
+ (rtems_gxx_recursive_mutex_init): Likewise.
+ (rtems_gxx_recursive_mutex_lock): Likewise.
+ (rtems_gxx_recursive_mutex_trylock): Likewise.
+ (rtems_gxx_recursive_mutex_unlock): Likewise.
+ (__GTHREAD_ONCE_INIT): Use <pthread.h> initializer.
+ (__GTHREAD_MUTEX_INIT_FUNCTION): Use <pthread.h> function.
+ (__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION): Likewise.
+ (__gthread_once): Likewise.
+ (__gthread_key_create): Likewise.
+ (__gthread_key_delete): Likewise.
+ (__gthread_getspecific): Likewise.
+ (__gthread_setspecific): Likewise.
+ (__gthread_key_t): Use <pthread.h> type.
+ (__gthread_once_t): Likewise
+ (__gthread_mutex_t): Use <sys/lock.h> type.
+ (__gthread_recursive_mutex_t): Likewise
+ (__gthread_mutex_lock): Use <sys/lock.h> function.
+ (__gthread_mutex_trylock): Likewise.
+ (__gthread_mutex_timedlock): Likewise.
+ (__gthread_mutex_unlock): Likewise.
+ (__gthread_mutex_destroy): Likewise.
+ (__gthread_recursive_mutex_lock): Likewise.
+ (__gthread_recursive_mutex_trylock): Likewise.
+ (__gthread_recursive_mutex_timedlock): Likewise.
+ (__gthread_recursive_mutex_unlock): Likewise.
+ (__gthread_recursive_mutex_destroy): Likewise.
+
2015-08-18 Max Filippov <jcmvbkbc@gmail.com>
* config/xtensa/unwind-dw2-xtensa.c (_Unwind_GetCFA): Return
#ifndef GCC_GTHR_RTEMS_H
#define GCC_GTHR_RTEMS_H
+#include <sys/lock.h>
+#include <pthread.h>
+#include <sched.h>
+
#ifdef __cplusplus
extern "C" {
#endif
#define __GTHREADS 1
+#define __GTHREADS_CXX0X 1
+#define __GTHREAD_HAS_COND 1
+
+typedef pthread_t __gthread_t;
+typedef pthread_key_t __gthread_key_t;
+typedef pthread_once_t __gthread_once_t;
+typedef struct _Mutex_Control __gthread_mutex_t;
+typedef struct _Mutex_recursive_Control __gthread_recursive_mutex_t;
+typedef struct _Condition_Control __gthread_cond_t;
+typedef struct timespec __gthread_time_t;
+
+#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
+#define __GTHREAD_MUTEX_INIT _MUTEX_INITIALIZER
+#define __GTHREAD_MUTEX_INIT_FUNCTION _Mutex_Initialize
+#define __GTHREAD_RECURSIVE_MUTEX_INIT _MUTEX_RECURSIVE_INITIALIZER
+#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION _Mutex_recursive_Initialize
+#define __GTHREAD_COND_INIT _CONDITION_INITIALIZER
+#define __GTHREAD_COND_INIT_FUNCTION _Condition_Initialize
+#define __GTHREAD_TIME_INIT {0, 0}
-#define __GTHREAD_ONCE_INIT 0
-#define __GTHREAD_MUTEX_INIT_FUNCTION rtems_gxx_mutex_init
-#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION rtems_gxx_recursive_mutex_init
-
-/* Avoid dependency on rtems specific headers. */
-typedef void *__gthread_key_t;
-typedef int __gthread_once_t;
-typedef void *__gthread_mutex_t;
-typedef void *__gthread_recursive_mutex_t;
-
-/*
- * External functions provided by RTEMS. They are very similar to their POSIX
- * counterparts. A "Wrapper API" is being use to avoid dependency on any RTEMS
- * header files.
- */
-
-/* generic per task variables */
-extern int rtems_gxx_once (__gthread_once_t *__once, void (*__func) (void));
-extern int rtems_gxx_key_create (__gthread_key_t *__key, void (*__dtor) (void *));
-extern int rtems_gxx_key_delete (__gthread_key_t __key);
-extern void *rtems_gxx_getspecific (__gthread_key_t __key);
-extern int rtems_gxx_setspecific (__gthread_key_t __key, const void *__ptr);
-
-/* mutex support */
-extern void rtems_gxx_mutex_init (__gthread_mutex_t *__mutex);
-extern int rtems_gxx_mutex_destroy (__gthread_mutex_t *__mutex);
-extern int rtems_gxx_mutex_lock (__gthread_mutex_t *__mutex);
-extern int rtems_gxx_mutex_trylock (__gthread_mutex_t *__mutex);
-extern int rtems_gxx_mutex_unlock (__gthread_mutex_t *__mutex);
-
-/* recursive mutex support */
-extern void rtems_gxx_recursive_mutex_init (__gthread_recursive_mutex_t *__mutex);
-extern int rtems_gxx_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex);
-extern int rtems_gxx_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex);
-extern int rtems_gxx_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex);
-
-/* RTEMS threading is always active */
static inline int
__gthread_active_p (void)
{
return 1;
}
-/* Wrapper calls */
+static inline int
+__gthread_create (__gthread_t *__threadid, void *(*__func) (void *),
+ void *__args)
+{
+ return pthread_create (__threadid, NULL, __func, __args);
+}
+
+static inline int
+__gthread_join (__gthread_t __threadid, void **__value_ptr)
+{
+ return pthread_join (__threadid, __value_ptr);
+}
+
+static inline int
+__gthread_detach (__gthread_t __threadid)
+{
+ return pthread_detach (__threadid);
+}
+
+static inline int
+__gthread_equal (__gthread_t __t1, __gthread_t __t2)
+{
+ return pthread_equal (__t1, __t2);
+}
+
+static inline __gthread_t
+__gthread_self (void)
+{
+ return pthread_self ();
+}
+
+static inline int
+__gthread_yield (void)
+{
+ return sched_yield ();
+}
+
static inline int
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
{
- return rtems_gxx_once( __once, __func );
+ return pthread_once (__once, __func);
}
static inline int
__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
{
- return rtems_gxx_key_create( __key, __dtor );
+ return pthread_key_create (__key, __dtor);
}
static inline int
__gthread_key_delete (__gthread_key_t __key)
{
- return rtems_gxx_key_delete (__key);
+ return pthread_key_delete (__key);
}
static inline void *
__gthread_getspecific (__gthread_key_t __key)
{
- return rtems_gxx_getspecific (__key);
+ return pthread_getspecific (__key);
}
static inline int
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
{
- return rtems_gxx_setspecific (__key, __ptr);
+ return pthread_setspecific (__key, __ptr);
}
static inline int
-__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
+__gthread_mutex_lock (__gthread_mutex_t *__mutex)
{
- return rtems_gxx_mutex_destroy (__mutex);
+ _Mutex_Acquire (__mutex);
+ return 0;
}
static inline int
-__gthread_mutex_lock (__gthread_mutex_t *__mutex)
+__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
{
- return rtems_gxx_mutex_lock (__mutex);
+ return _Mutex_Try_acquire (__mutex);
}
static inline int
-__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
+__gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
+ const __gthread_time_t *__abs_timeout)
{
- return rtems_gxx_mutex_trylock (__mutex);
+ return _Mutex_Acquire_timed (__mutex, __abs_timeout);
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
{
- return rtems_gxx_mutex_unlock( __mutex );
+ _Mutex_Release (__mutex);
+ return 0;
+}
+
+static inline int
+__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
+{
+ _Mutex_Destroy (__mutex);
+ return 0;
}
static inline int
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
{
- return rtems_gxx_recursive_mutex_lock (__mutex);
+ _Mutex_recursive_Acquire (__mutex);
+ return 0;
}
static inline int
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
{
- return rtems_gxx_recursive_mutex_trylock (__mutex);
+ return _Mutex_recursive_Try_acquire (__mutex);
+}
+
+static inline int
+__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
+ const __gthread_time_t *__abs_timeout)
+{
+ return _Mutex_recursive_Acquire_timed (__mutex, __abs_timeout);
}
static inline int
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
{
- return rtems_gxx_recursive_mutex_unlock( __mutex );
+ _Mutex_recursive_Release (__mutex);
+ return 0;
}
static inline int
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
{
- /* This requires that recursive and non-recursive mutexes have the same
- representation. */
- return rtems_gxx_mutex_destroy (__mutex );
+ _Mutex_recursive_Destroy (__mutex);
+ return 0;
+}
+
+static inline int
+__gthread_cond_broadcast (__gthread_cond_t *__cond)
+{
+ _Condition_Broadcast (__cond);
+ return 0;
+}
+
+static inline int
+__gthread_cond_signal (__gthread_cond_t *__cond)
+{
+ _Condition_Signal (__cond);
+ return 0;
+}
+
+static inline int
+__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
+{
+ _Condition_Wait (__cond, __mutex);
+ return 0;
+}
+
+static inline int
+__gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
+ const __gthread_time_t *__abs_timeout)
+{
+ return _Condition_Wait_timed (__cond, __mutex, __abs_timeout);
+}
+
+static inline int
+__gthread_cond_wait_recursive (__gthread_cond_t *__cond,
+ __gthread_recursive_mutex_t *__mutex)
+{
+ _Condition_Wait_recursive (__cond, __mutex);
+ return 0;
+}
+
+static inline int
+__gthread_cond_destroy (__gthread_cond_t *__cond)
+{
+ _Condition_Destroy (__cond);
+ return 0;
}
#ifdef __cplusplus