public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: gcc-patches@gcc.gnu.org
Subject: [gccgo] Use RTEMS task variables in libgo
Date: Fri, 02 Jul 2010 14:20:00 -0000	[thread overview]
Message-ID: <mcr39w2m0e1.fsf@google.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: task --]
[-- Type: text/x-diff, Size: 3640 bytes --]

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 <pthread.h>
 
 #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 <rtems/error.h>
+#include <rtems/system.h>
+#include <rtems/rtems/tasks.h>
+
+/* 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

                 reply	other threads:[~2010-07-02 14:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mcr39w2m0e1.fsf@google.com \
    --to=iant@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).