[Ada] vxworks: auto-registration of foreign threads

Message ID 20170913103544.GA129683@adacore.com
State New
Headers show
Series
  • [Ada] vxworks: auto-registration of foreign threads
Related show

Commit Message

Pierre-Marie de Rodat Sept. 13, 2017, 10:35 a.m.
To make Ada tasks and C threads interoperate better, we have added some
functionality to Self. Suppose a C main program (with threads) calls an
Ada procedure and the Ada procedure calls the tasking runtime system.
Eventually, a call will be made to self. Since the call is not coming
from an Ada task, there will be no corresponding ATCB.

What we do in Self is to catch references that do not come from
recognized Ada tasks, and create an ATCB for the calling thread.

The new ATCB will be "detached" from the normal Ada task master
hierarchy, much like the existing implicitly created signal-server
tasks.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-09-13  Jerome Guitton  <guitton@adacore.com>

	* libgnarl/s-tpopsp__vxworks-tls.adb,
	libgnarl/s-tpopsp__vxworks-rtp.adb, libgnarl/s-tpopsp__vxworks.adb
	(Self): Register thread if task id is null.

Patch

Index: libgnarl/s-tpopsp__vxworks-tls.adb
===================================================================
--- libgnarl/s-tpopsp__vxworks-tls.adb	(revision 252075)
+++ libgnarl/s-tpopsp__vxworks-tls.adb	(working copy)
@@ -71,9 +71,29 @@ 
    -- Self --
    ----------
 
+   --  To make Ada tasks and C threads interoperate better, we have added some
+   --  functionality to Self. Suppose a C main program (with threads) calls an
+   --  Ada procedure and the Ada procedure calls the tasking runtime system.
+   --  Eventually, a call will be made to self. Since the call is not coming
+   --  from an Ada task, there will be no corresponding ATCB.
+
+   --  What we do in Self is to catch references that do not come from
+   --  recognized Ada tasks, and create an ATCB for the calling thread.
+
+   --  The new ATCB will be "detached" from the normal Ada task master
+   --  hierarchy, much like the existing implicitly created signal-server
+   --  tasks.
+
    function Self return Task_Id is
+      Result : constant Task_Id := ATCB;
    begin
-      return ATCB;
+      if Result /= null then
+         return Result;
+      else
+         --  If the value is Null then it is a non-Ada task
+
+         return Register_Foreign_Thread;
+      end if;
    end Self;
 
 end Specific;
Index: libgnarl/s-tpopsp__vxworks-rtp.adb
===================================================================
--- libgnarl/s-tpopsp__vxworks-rtp.adb	(revision 252075)
+++ libgnarl/s-tpopsp__vxworks-rtp.adb	(working copy)
@@ -72,9 +72,29 @@ 
    -- Self --
    ----------
 
+   --  To make Ada tasks and C threads interoperate better, we have added some
+   --  functionality to Self. Suppose a C main program (with threads) calls an
+   --  Ada procedure and the Ada procedure calls the tasking runtime system.
+   --  Eventually, a call will be made to self. Since the call is not coming
+   --  from an Ada task, there will be no corresponding ATCB.
+
+   --  What we do in Self is to catch references that do not come from
+   --  recognized Ada tasks, and create an ATCB for the calling thread.
+
+   --  The new ATCB will be "detached" from the normal Ada task master
+   --  hierarchy, much like the existing implicitly created signal-server
+   --  tasks.
+
    function Self return Task_Id is
+      Result : constant Task_Id := To_Task_Id (tlsValueGet (ATCB_Key));
    begin
-      return To_Task_Id (tlsValueGet (ATCB_Key));
+      if Result /= null then
+         return Result;
+      else
+         --  If the value is Null then it is a non-Ada task
+
+         return Register_Foreign_Thread;
+      end if;
    end Self;
 
 end Specific;
Index: libgnarl/s-tpopsp__vxworks.adb
===================================================================
--- libgnarl/s-tpopsp__vxworks.adb	(revision 252075)
+++ libgnarl/s-tpopsp__vxworks.adb	(working copy)
@@ -121,9 +121,29 @@ 
    -- Self --
    ----------
 
+   --  To make Ada tasks and C threads interoperate better, we have added some
+   --  functionality to Self. Suppose a C main program (with threads) calls an
+   --  Ada procedure and the Ada procedure calls the tasking runtime system.
+   --  Eventually, a call will be made to self. Since the call is not coming
+   --  from an Ada task, there will be no corresponding ATCB.
+
+   --  What we do in Self is to catch references that do not come from
+   --  recognized Ada tasks, and create an ATCB for the calling thread.
+
+   --  The new ATCB will be "detached" from the normal Ada task master
+   --  hierarchy, much like the existing implicitly created signal-server
+   --  tasks.
+
    function Self return Task_Id is
+      Result : constant Task_Id := To_Task_Id (ATCB_Key);
    begin
-      return To_Task_Id (ATCB_Key);
+      if Result /= null then
+         return Result;
+      else
+         --  If the value is Null then it is a non-Ada task
+
+         return Register_Foreign_Thread;
+      end if;
    end Self;
 
 end Specific;