diff options
author | Nicolas Roche <roche@adacore.com> | 2017-09-08 13:14:59 +0000 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2017-09-08 15:14:59 +0200 |
commit | cfc29a96f8909d8112d7b3e81984801eb3bb505e (patch) | |
tree | 3e9c6ec1fbc4195a607da1653bfdc70783dcc0a4 /gcc/ada/libgnarl/g-thread.adb | |
parent | 4bd3809078fee7f16cefac724db4439c75c2b74f (diff) | |
download | gcc-cfc29a96f8909d8112d7b3e81984801eb3bb505e.zip gcc-cfc29a96f8909d8112d7b3e81984801eb3bb505e.tar.gz gcc-cfc29a96f8909d8112d7b3e81984801eb3bb505e.tar.bz2 |
Makefile.in, [...]: Move libgnarl sources to libgnarl subdir.
2017-09-08 Nicolas Roche <roche@adacore.com>
* gcc-interface/Makefile.in, a-extiti.ads, s-taprop-linux.adb,
s-osinte-solaris.adb, a-intnam.ads, s-osinte-solaris.ads,
s-tpobop.adb, s-intman-android.adb, s-tasinf.adb, s-tpobop.ads,
s-tasinf.ads, i-vxinco.adb, a-exetim-posix.adb, i-vxinco.ads,
a-astaco.adb, a-astaco.ads, s-tporft.adb, s-tpoaal.adb, a-taside.adb,
a-taside.ads, s-tpopsp-posix.adb, s-tasdeb.adb, s-tasdeb.ads,
s-tpoben.adb, a-dinopr.ads, s-inmaop-vxworks.adb, s-tpoben.ads,
s-interr-vxworks.adb, s-interr-dummy.adb, s-tassta.adb,
a-intnam-mingw.ads, s-tassta.ads, s-taasde.adb, a-stcoed.ads,
s-taasde.ads, s-osinte-darwin.adb, s-proinf.adb, s-taprop-dummy.adb,
s-osinte-darwin.ads, s-proinf.ads, s-linux.ads, a-intnam-linux.ads,
s-tasren.adb, s-tasren.ads, s-mudido.adb, g-semaph.adb, s-mudido.ads,
s-taprop-posix.adb, g-semaph.ads, s-osinte-mingw.ads, s-vxwork-x86.ads,
s-tposen.adb, s-linux-sparc.ads, s-taprop-vxworks.adb, s-tasini.adb,
s-tposen.ads, s-tasini.ads, a-etgrbu.ads, s-interr-hwint.adb,
s-osinte-linux.ads, s-taprop.ads, s-tasque.adb, s-tasque.ads,
s-taenca.adb, s-taspri-vxworks.ads, s-taenca.ads, a-dynpri.adb,
s-tpopsp-solaris.adb, a-dynpri.ads, s-taprop-hpux-dce.adb,
a-interr.adb, a-intnam-freebsd.ads, s-tarest.adb, a-interr.ads,
s-intman-susv3.adb, a-synbar.adb, a-intnam-dummy.ads, s-tadeca.adb,
s-osinte-vxworks.adb, s-tarest.ads, s-taskin.adb, a-synbar.ads,
s-taspri-hpux-dce.ads, s-tadeca.ads, s-osinte-vxworks.ads,
s-taskin.ads, s-intman-solaris.adb, a-sytaco.adb, s-vxwext-kernel.adb,
s-mudido-affinity.adb, a-sytaco.ads, s-vxwext-kernel.ads, s-taprob.adb,
s-intman-mingw.adb, s-taprob.ads, s-osinte-kfreebsd-gnu.ads,
s-osinte-dummy.ads, s-osinte-gnu.adb, s-osinte-rtems.adb, s-interr.adb,
s-inmaop.ads, s-vxwext-rtp.adb, s-osinte-gnu.ads, s-osinte-rtems.ads,
a-synbar-posix.adb, s-interr.ads, s-taspri-posix-noaltstack.ads,
s-vxwext-rtp.ads, a-synbar-posix.ads, a-extiin.ads, s-osinte-posix.adb,
s-tpinop.adb, s-tasres.ads, s-tpinop.ads, a-disedf.ads, a-diroro.ads,
s-linux-alpha.ads, a-tasatt.adb, s-solita.adb, a-intnam-solaris.ads,
a-tasatt.ads, s-solita.ads, s-tasinf-solaris.adb, s-tasinf-solaris.ads,
s-vxwork-arm.ads, s-tpopsp-posix-foreign.adb, s-intman-dummy.adb,
s-intman.ads, s-stusta.adb, s-stusta.ads, s-intman-posix.adb,
s-tpopsp-vxworks.adb, s-inmaop-dummy.adb, s-taspri-mingw.ads,
a-intnam-darwin.ads, s-osinte-aix.adb, s-osinte-dragonfly.adb,
s-osinte-aix.ads, s-tasinf-mingw.adb, s-osinte-dragonfly.ads,
s-linux-hppa.ads, s-osinte-x32.adb, s-inmaop-posix.adb,
s-tasinf-mingw.ads, s-intman-vxworks.adb, s-linux-mips.ads,
s-intman-vxworks.ads, s-osinte-android.adb, s-tasinf-linux.adb,
s-osinte-android.ads, s-vxwork-ppc.ads, s-tasinf-linux.ads,
a-dispat.adb, a-dispat.ads, s-tadert.adb, g-thread.adb, s-tadert.ads,
g-thread.ads, a-intnam-hpux.ads, s-linux-android.ads, s-tataat.adb,
a-exetim.ads, s-tataat.ads, a-reatim.adb, a-reatim.ads, thread.c,
g-boubuf.adb, s-osinte-freebsd.adb, g-boubuf.ads, s-osinte-freebsd.ads,
s-tasuti.adb, s-taspri-dummy.ads, a-exetim-mingw.adb, s-linux-x32.ads,
s-tasuti.ads, g-signal.adb, a-exetim-mingw.ads, s-interr-sigaction.adb,
g-signal.ads, s-osinte-hpux.ads, a-intnam-vxworks.ads,
s-osinte-hpux-dce.adb, s-taspri-posix.ads, s-osinte-hpux-dce.ads,
s-tasinf-vxworks.ads, g-tastus.ads, s-tpopsp-tls.adb,
s-taprop-solaris.adb, a-retide.adb, a-exetim-darwin.adb, a-retide.ads,
s-vxwext.adb, s-vxwext.ads, a-rttiev.adb, a-rttiev.ads, g-boumai.ads,
a-exetim-default.ads, s-taprop-mingw.adb, s-taspri-solaris.ads,
a-intnam-aix.ads: Move libgnarl sources to libgnarl subdir.
From-SVN: r251891
Diffstat (limited to 'gcc/ada/libgnarl/g-thread.adb')
-rw-r--r-- | gcc/ada/libgnarl/g-thread.adb | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/gcc/ada/libgnarl/g-thread.adb b/gcc/ada/libgnarl/g-thread.adb new file mode 100644 index 0000000..90d51af --- /dev/null +++ b/gcc/ada/libgnarl/g-thread.adb @@ -0,0 +1,186 @@ +------------------------------------------------------------------------------ +-- -- +-- GNAT RUN-TIME COMPONENTS -- +-- -- +-- G N A T . T H R E A D S -- +-- -- +-- B o d y -- +-- -- +-- Copyright (C) 1998-2017, AdaCore -- +-- -- +-- GNAT is free software; you can redistribute it and/or modify it under -- +-- terms of the GNU General Public License as published by the Free Soft- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- +-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- +-- or FITNESS FOR A PARTICULAR PURPOSE. -- +-- -- +-- As a special exception under Section 7 of GPL version 3, you are granted -- +-- additional permissions described in the GCC Runtime Library Exception, -- +-- version 3.1, as published by the Free Software Foundation. -- +-- -- +-- You should have received a copy of the GNU General Public License and -- +-- a copy of the GCC Runtime Library Exception along with this program; -- +-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- +-- <http://www.gnu.org/licenses/>. -- +-- -- +-- GNAT was originally developed by the GNAT team at New York University. -- +-- Extensive contributions were provided by Ada Core Technologies Inc. -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Task_Identification; use Ada.Task_Identification; +with System.Task_Primitives.Operations; +with System.Tasking; +with System.Tasking.Stages; use System.Tasking.Stages; +with System.OS_Interface; use System.OS_Interface; +with System.Soft_Links; use System.Soft_Links; +with Ada.Unchecked_Conversion; + +package body GNAT.Threads is + + use System; + + package STPO renames System.Task_Primitives.Operations; + + type Thread_Id_Ptr is access all Thread_Id; + + pragma Warnings (Off); + -- The following unchecked conversions are aliasing safe, since they + -- are never used to create pointers to improperly aliased data. + + function To_Addr is new Ada.Unchecked_Conversion (Task_Id, Address); + function To_Id is new Ada.Unchecked_Conversion (Address, Task_Id); + function To_Id is new Ada.Unchecked_Conversion (Address, Tasking.Task_Id); + function To_Tid is new Ada.Unchecked_Conversion + (Address, Ada.Task_Identification.Task_Id); + function To_Thread is new Ada.Unchecked_Conversion (Address, Thread_Id_Ptr); + + pragma Warnings (On); + + type Code_Proc is access procedure (Id : Address; Parm : Void_Ptr); + + task type Thread + (Stsz : Natural; + Prio : Any_Priority; + Parm : Void_Ptr; + Code : Code_Proc) + is + pragma Priority (Prio); + pragma Storage_Size (Stsz); + end Thread; + + task body Thread is + begin + Code.all (To_Addr (Current_Task), Parm); + end Thread; + + type Tptr is access Thread; + + ------------------- + -- Create_Thread -- + ------------------- + + function Create_Thread + (Code : Address; + Parm : Void_Ptr; + Size : Natural; + Prio : Integer) return System.Address + is + TP : Tptr; + + function To_CP is new Ada.Unchecked_Conversion (Address, Code_Proc); + + begin + TP := new Thread (Size, Prio, Parm, To_CP (Code)); + return To_Addr (TP'Identity); + end Create_Thread; + + --------------------- + -- Register_Thread -- + --------------------- + + function Register_Thread return System.Address is + begin + return Task_Primitives.Operations.Register_Foreign_Thread.all'Address; + end Register_Thread; + + ----------------------- + -- Unregister_Thread -- + ----------------------- + + procedure Unregister_Thread is + Self_Id : constant Tasking.Task_Id := Task_Primitives.Operations.Self; + begin + Self_Id.Common.State := Tasking.Terminated; + Destroy_TSD (Self_Id.Common.Compiler_Data); + Free_Task (Self_Id); + end Unregister_Thread; + + -------------------------- + -- Unregister_Thread_Id -- + -------------------------- + + procedure Unregister_Thread_Id (Thread : System.Address) is + Thr : constant Thread_Id := To_Thread (Thread).all; + T : Tasking.Task_Id; + + use type Tasking.Task_Id; + -- This use clause should be removed once a visibility problem + -- with the MaRTE run time has been fixed. ??? + + pragma Warnings (Off); + use type System.OS_Interface.Thread_Id; + pragma Warnings (On); + + begin + STPO.Lock_RTS; + + T := Tasking.All_Tasks_List; + loop + exit when T = null or else STPO.Get_Thread_Id (T) = Thr; + + T := T.Common.All_Tasks_Link; + end loop; + + STPO.Unlock_RTS; + + if T /= null then + T.Common.State := Tasking.Terminated; + Destroy_TSD (T.Common.Compiler_Data); + Free_Task (T); + end if; + end Unregister_Thread_Id; + + -------------------- + -- Destroy_Thread -- + -------------------- + + procedure Destroy_Thread (Id : Address) is + Tid : constant Task_Id := To_Id (Id); + begin + Abort_Task (Tid); + end Destroy_Thread; + + ---------------- + -- Get_Thread -- + ---------------- + + procedure Get_Thread (Id : Address; Thread : Address) is + Thr : constant Thread_Id_Ptr := To_Thread (Thread); + begin + Thr.all := Task_Primitives.Operations.Get_Thread_Id (To_Id (Id)); + end Get_Thread; + + ---------------- + -- To_Task_Id -- + ---------------- + + function To_Task_Id + (Id : System.Address) return Ada.Task_Identification.Task_Id + is + begin + return To_Tid (Id); + end To_Task_Id; + +end GNAT.Threads; |