From patchwork Fri Jul 2 14:19:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [gccgo] Use RTEMS task variables in libgo Date: Fri, 02 Jul 2010 04:19:50 -0000 From: Ian Taylor X-Patchwork-Id: 57665 Message-Id: To: gcc-patches@gcc.gnu.org RTEMS does not support __thread, but it does permit task-specific variables. This patch from Vinu Rajashekhar makes RTEMS use task-specific variables in libgo. Committed to gccgo branch. Ian diff -r d8befecc4907 libgo/Makefile.am --- a/libgo/Makefile.am Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/Makefile.am Fri Jul 02 07:07:59 2010 -0700 @@ -263,6 +263,12 @@ runtime_mem_file = runtime/mem_posix_memalign.c endif +if LIBGO_IS_RTEMS +rtems_task_variable_add_file = runtime/rtems-task-variable-add.c +else +rtems_task_variable_add_file = +endif + runtime_files = \ runtime/go-bad-index.c \ runtime/go-byte-array-to-string.c \ @@ -351,6 +357,7 @@ runtime/msize.c \ runtime/proc.c \ runtime/thread.c \ + $(rtems_task_variable_add_file) \ chan.c \ iface.c \ malloc.c \ diff -r d8befecc4907 libgo/runtime/go-go.c --- a/libgo/runtime/go-go.c Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/runtime/go-go.c Fri Jul 02 07:07:59 2010 -0700 @@ -10,6 +10,7 @@ #include #include "config.h" +#include "go-panic.h" #include "go-alloc.h" #include "runtime.h" @@ -33,6 +34,11 @@ void (*pfn) (void *); void *arg; +#ifdef __rtems__ + __wrap_rtems_task_variable_add ((void **) &m); + __wrap_rtems_task_variable_add ((void **) &__go_panic_defer); +#endif + pfn = pc->pfn; arg = pc->arg; m = pc->m; diff -r d8befecc4907 libgo/runtime/go-panic-defer.c --- a/libgo/runtime/go-panic-defer.c Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/runtime/go-panic-defer.c Fri Jul 02 07:07:59 2010 -0700 @@ -6,4 +6,8 @@ #include "go-panic.h" +#ifdef __rtems__ +#define __thread +#endif + __thread struct __go_panic_defer_struct *__go_panic_defer; diff -r d8befecc4907 libgo/runtime/go-panic.h --- a/libgo/runtime/go-panic.h Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/runtime/go-panic.h Fri Jul 02 07:07:59 2010 -0700 @@ -50,8 +50,16 @@ _Bool __is_foreign; }; +#ifdef __rtems__ +#define __thread +#endif + extern __thread struct __go_panic_defer_struct *__go_panic_defer; +#ifdef __rtems__ +#undef __thread +#endif + extern void __go_panic (struct __go_interface *) __attribute__ ((noreturn)); diff -r d8befecc4907 libgo/runtime/proc.c --- a/libgo/runtime/proc.c Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/runtime/proc.c Fri Jul 02 07:07:59 2010 -0700 @@ -9,4 +9,8 @@ M m0; +#ifdef __rtems__ +#define __thread +#endif + __thread M *m = &m0; diff -r d8befecc4907 libgo/runtime/rtems-task-variable-add.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgo/runtime/rtems-task-variable-add.c Fri Jul 02 07:07:59 2010 -0700 @@ -0,0 +1,21 @@ +/* rtems-task-variable-add.c -- adding a task specific variable in RTEMS OS. + + Copyright 2010 The Go Authors. All rights reserved. + Use of this source code is governed by a BSD-style + license that can be found in the LICENSE file. */ + +#include +#include +#include + +/* RTEMS does not support GNU TLS extension __thread. */ +void +__wrap_rtems_task_variable_add (void **var) +{ + rtems_status_code sc = rtems_task_variable_add (RTEMS_SELF, var, NULL); + if (sc != RTEMS_SUCCESSFUL) + { + rtems_error (sc, "rtems_task_variable_add failed"); + } +} + diff -r d8befecc4907 libgo/runtime/runtime.h --- a/libgo/runtime/runtime.h Thu Jul 01 12:38:25 2010 -0700 +++ b/libgo/runtime/runtime.h Fri Jul 02 07:07:59 2010 -0700 @@ -66,8 +66,16 @@ /* Per CPU declarations. */ +#ifdef __rtems__ +#define __thread +#endif + extern __thread M* m; +#ifdef __rtems__ +#undef __thread +#endif + /* Constants. */ enum @@ -131,3 +139,7 @@ void addfinalizer(void*, void(*fn)(void*), int32); #define runtime_mmap mmap #define cas(pval, old, new) __sync_bool_compare_and_swap (pval, old, new) + +#ifdef __rtems__ +void __wrap_rtems_task_variable_add(void **); +#endif