Patchwork [Ada] Implement task barriers in Ada

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 29, 2011, 10:58 a.m.
Message ID <20110829105849.GA28019@adacore.com>
Download mbox | patch
Permalink /patch/112020/
State New
Headers show

Comments

Arnaud Charlet - Aug. 29, 2011, 10:58 a.m.
Ada 2012 added a Synchronous_Barrier type to allow many tasks to be blocked
and be released at once, similar to the functionality provided by POSIX
barriers. See AI-0174 for details.

The following test case should compile quietly in Ada2012 mode and execute
without any output message:

pragma Task_Dispatching_Policy (FIFO_Within_Priorities);

with System;

with Ada.Synchronous_Barriers;
with Ada.Synchronous_Task_Control;

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Barriers is
   Number_Of_Tasks : constant := 1_000;

   Barrier : Ada.Synchronous_Barriers.Synchronous_Barrier (Number_Of_Tasks);

   protected type Task_Ctrl is
      entry Wait;
      procedure Notify;
      function Is_Notified return Boolean;
   private
      Barrier : Boolean := False;
   end Task_Ctrl;

   protected body Task_Ctrl is
      entry Wait when Barrier is
      begin
         null;
      end Wait;

      procedure Notify is
      begin
         Barrier := True;
      end Notify;

      function Is_Notified return Boolean is
      begin
         return Barrier;
      end Is_Notified;
   end Task_Ctrl;

   type Container;

   task type Worker (Wrapper : not null access Container) is
      pragma Priority (System.Priority'Last);
   end Worker;

   type Container is limited
      record
         Who        : Worker (Container'Access);
         Started    : Task_Ctrl;
         Finished   : Task_Ctrl;
         The_Chosen : Boolean;
      end record;

   task body Worker is
   begin
      --  Task started
      Wrapper.Started.Notify;

      --  Wait to synchronize with the others
      Ada.Synchronous_Barriers.Wait_For_Release (Barrier, Wrapper.The_Chosen);

      --  Task finishing
      Wrapper.Finished.Notify;
   end Worker;

   Worker_Array : array (1 .. Number_Of_Tasks - 1) of Container;

   Environment_Chosen : Boolean := False;
   Chosen_Found : Boolean := False;

begin
   --  Make sure that all tasks are started
   for Element of Worker_Array loop
      Element.Started.Wait;
   end loop;

   --  All tasks have started execution, and they should all be waiting
   --  on the barrier.

   for Element of Worker_Array loop
      if Element.Finished.Is_Notified then
         Put_Line ("A task passed through the barrier");
      end if;
   end loop;

   Ada.Synchronous_Barriers.Wait_For_Release (Barrier, Environment_Chosen);

   --  Make sure that all tasks are finished
   for Element of Worker_Array loop
      Element.Finished.Wait;
   end loop;

   --  Verify that just task was chosen to carry the notification of the
   --  open barrier.
   for Element of Worker_Array loop
      if Chosen_Found and then Element.The_Chosen then
         Put_Line ("More than one task chosen to carry notification");
      else
         Chosen_Found := Chosen_Found or else Element.The_Chosen;
      end if;
   end loop;

   --  Verify whether the environment task should carry the token
   if Environment_Chosen = Chosen_Found then
      Put_Line ("Problem with notifications");
   end if;
end Test_Barriers;

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

2011-08-29  Jose Ruiz  <ruiz@adacore.com>

	* impunit.adb (Non_Imp_File_Names_12): Add a-synbar for new Ada 2012
	package Ada.Synchronous_Barriers.
	* a-synbar.ads, a-synbar.adb, a-synbar-posix.ads, a-synbar-posix.adb:
	Add new specs and bodies for Ada.Synchronous_Barriers. There is a
	default implementation using protected objects and another one
	a-synbar-posix using POSIX barriers as the underlying support.
	* gcc-interface/Makefile.in (LIBGNAT_TARGET_PAIRS for Linux (x86,
	x86_64, ia64) and MIPS IRIX): Use the a-synbar-posix implementation of
	Ada.Synchronous_Barriers which uses POSIX barriers (more efficient).
	Clean up dependencies .
	* Makefile.rtl (GNATRTL_TASKING_OBJS): Add a-synbar.o

Patch

Index: impunit.adb
===================================================================
--- impunit.adb	(revision 178183)
+++ impunit.adb	(working copy)
@@ -111,7 +111,6 @@ 
      "a-titest",    -- Ada.Text_IO.Text_Streams
      "a-unccon",    -- Ada.Unchecked_Conversion
      "a-uncdea",    -- Ada.Unchecked_Deallocation
-     "a-undesu",    -- Ada.Unchecked_Deallocate_Subpool
      "a-witeio",    -- Ada.Wide_Text_IO
      "a-wtcoio",    -- Ada.Wide_Text_IO.Complex_IO
      "a-wtedit",    -- Ada.Wide_Text_IO.Editing
@@ -340,7 +339,6 @@ 
      "s-rpc   ",    -- System.Rpc
      "s-stoele",    -- System.Storage_Elements
      "s-stopoo",    -- System.Storage_Pools
-     "s-stposu",    -- System.Storage_Pools.Subpools
 
    --------------------------------------
    -- GNAT Defined Additions to System --
@@ -522,6 +520,7 @@ 
      "a-cbmutr",    -- Ada.Containers.Bounded_Multiway_Trees
      "a-extiin",    -- Ada.Execution_Time.Interrupts
      "a-iteint",    -- Ada.Iterator_Interfaces
+     "a-synbar",    -- Ada.Synchronous_Barriers
 
    -----------------------------------------
    -- GNAT Defined Additions to Ada 20012 --
Index: a-synbar-posix.adb
===================================================================
--- a-synbar-posix.adb	(revision 0)
+++ a-synbar-posix.adb	(revision 0)
@@ -0,0 +1,112 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
+--                                                                          --
+--             A D A . S Y N C H R O N O U S _ B A R R I E R S              --
+--                                                                          --
+--                                  B o d y                                 --
+--                                                                          --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- 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.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This is the body of this package using POSIX barriers
+
+with Interfaces.C; use Interfaces.C;
+
+package body Ada.Synchronous_Barriers is
+
+   --------------------
+   -- POSIX barriers --
+   --------------------
+
+   function pthread_barrier_init
+     (barrier : not null access pthread_barrier_t;
+      attr    : System.Address := System.Null_Address;
+      count   : unsigned)
+     return int;
+   pragma Import (C, pthread_barrier_init, "pthread_barrier_init");
+   --  Initialize barrier with the attributes in attr. The barrier is opened
+   --  when count waiters arrived. If attr is null the default barrier
+   --  attributes shall be used.
+
+   --  Destroy a previously dynamically initialized barrier
+   function pthread_barrier_destroy
+     (barrier : not null access pthread_barrier_t) return int;
+   pragma Import (C, pthread_barrier_destroy, "pthread_barrier_destroy");
+   --  Destroy a previously dynamically initialized barrier
+
+   function pthread_barrier_wait
+     (barrier : not null access pthread_barrier_t) return int;
+   pragma Import (C, pthread_barrier_wait, "pthread_barrier_wait");
+   --  Wait on barrier
+
+   --------------
+   -- Finalize --
+   --------------
+
+   overriding procedure Finalize (Barrier : in out Synchronous_Barrier) is
+      Result : int;
+
+   begin
+      Result := pthread_barrier_destroy (Barrier.POSIX_Barrier'Access);
+      pragma Assert (Result = 0);
+   end Finalize;
+
+   overriding procedure Initialize (Barrier : in out Synchronous_Barrier) is
+      Result : int;
+
+   begin
+      Result := pthread_barrier_init
+        (barrier => Barrier.POSIX_Barrier'Access,
+         attr    => System.Null_Address,
+         count   => unsigned (Barrier.Release_Threshold));
+      pragma Assert (Result = 0);
+   end Initialize;
+
+   ----------------------
+   -- Wait_For_Release --
+   ----------------------
+
+   procedure Wait_For_Release
+     (The_Barrier : in out Synchronous_Barrier;
+      Notified    : out    Boolean)
+   is
+      Result : int;
+
+      PTHREAD_BARRIER_SERIAL_THREAD : constant := -1;
+      --  Value used to indicate the task which receives the notification for
+      --  the barrier open.
+
+   begin
+      Result := pthread_barrier_wait
+        (barrier => The_Barrier.POSIX_Barrier'Access);
+      pragma Assert
+        (Result = 0 or else Result = PTHREAD_BARRIER_SERIAL_THREAD);
+
+      Notified := (Result = PTHREAD_BARRIER_SERIAL_THREAD);
+   end Wait_For_Release;
+end Ada.Synchronous_Barriers;
Index: a-synbar-posix.ads
===================================================================
--- a-synbar-posix.ads	(revision 0)
+++ a-synbar-posix.ads	(revision 0)
@@ -0,0 +1,83 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
+--                                                                          --
+--             A D A . S Y N C H R O N O U S _ B A R R I E R S              --
+--                                                                          --
+--                                  S p e c                                 --
+--                                                                          --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- 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.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  This is the spec of this package using POSIX barriers
+
+with System;
+private with Ada.Finalization;
+private with Interfaces.C;
+
+package Ada.Synchronous_Barriers is
+   pragma Preelaborate (Synchronous_Barriers);
+
+   subtype Barrier_Limit is Positive range 1 .. Positive'Last;
+
+   type Synchronous_Barrier (Release_Threshold : Barrier_Limit) is
+      limited private;
+
+   procedure Wait_For_Release (The_Barrier : in out Synchronous_Barrier;
+                               Notified    :    out Boolean);
+
+private
+   --  POSIX barrier data type
+
+   SIZEOF_PTHREAD_BARRIER_T : constant :=
+     (if System.Word_Size = 64 then 32 else 20);
+   --  Value defined according to the linux definition in pthreadtypes.h. On
+   --  other system, MIPS IRIX, the object is smaller, so it works correctly
+   --  although we are wasting some space.
+
+   type pthread_barrier_t_view is (size_based, align_based);
+
+   type pthread_barrier_t (Kind : pthread_barrier_t_view := size_based) is
+      record
+         case Kind is
+            when size_based =>
+               size : Interfaces.C.char_array (1 .. SIZEOF_PTHREAD_BARRIER_T);
+            when align_based =>
+               align : Interfaces.C.long;
+         end case;
+      end record;
+   pragma Unchecked_Union (pthread_barrier_t);
+
+   type Synchronous_Barrier (Release_Threshold : Barrier_Limit) is
+     new Ada.Finalization.Limited_Controlled with
+      record
+         POSIX_Barrier : aliased pthread_barrier_t;
+      end record;
+
+   overriding procedure Initialize (Barrier : in out Synchronous_Barrier);
+   overriding procedure Finalize   (Barrier : in out Synchronous_Barrier);
+end Ada.Synchronous_Barriers;
Index: a-synbar.adb
===================================================================
--- a-synbar.adb	(revision 0)
+++ a-synbar.adb	(revision 0)
@@ -0,0 +1,71 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
+--                                                                          --
+--             A D A . S Y N C H R O N O U S _ B A R R I E R S              --
+--                                                                          --
+--                                  B o d y                                 --
+--                                                                          --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- 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.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+package body Ada.Synchronous_Barriers is
+
+   protected body Synchronous_Barrier is
+      --  The condition "Wait'Count = Release_Threshold" opens the barrier when
+      --  the required number of tasks is reached. The condition "Keep_Open"
+      --  leaves the barrier open while there are queued tasks. While there are
+      --  tasks in the queue no new task will be queued, guaranteeing that the
+      --  barrier will remain open only for those tasks already inside.
+
+      entry Wait (Notified : out Boolean)
+        when Wait'Count = Release_Threshold or else Keep_Open is
+      begin
+         --  If we are executing the entry it means that the required number
+         --  of tasks have been queued in the entry. Keep_Open barrier will
+         --  remain true until all queued tasks are out.
+
+         Keep_Open := Wait'Count > 0;
+
+         --  The last released task will close the barrier and get the
+         --  Notified token.
+
+         Notified := Wait'Count = 0;
+      end Wait;
+   end Synchronous_Barrier;
+
+   ----------------------
+   -- Wait_For_Release --
+   ----------------------
+
+   procedure Wait_For_Release
+     (The_Barrier : in out Synchronous_Barrier;
+      Notified    : out    Boolean) is
+   begin
+      The_Barrier.Wait (Notified);
+   end Wait_For_Release;
+end Ada.Synchronous_Barriers;
Index: a-synbar.ads
===================================================================
--- a-synbar.ads	(revision 0)
+++ a-synbar.ads	(revision 0)
@@ -0,0 +1,53 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
+--                                                                          --
+--             A D A . S Y N C H R O N O U S _ B A R R I E R S              --
+--                                                                          --
+--                                  S p e c                                 --
+--                                                                          --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--                                                                          --
+-- This specification is derived from the Ada Reference Manual for use with --
+-- GNAT. The copyright notice above, and the license provisions that follow --
+-- apply solely to the  contents of the part following the private keyword. --
+--                                                                          --
+-- 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.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+package Ada.Synchronous_Barriers is
+   pragma Preelaborate (Synchronous_Barriers);
+
+   subtype Barrier_Limit is Positive range 1 .. Positive'Last;
+
+   type Synchronous_Barrier (Release_Threshold : Barrier_Limit) is
+      limited private;
+
+   procedure Wait_For_Release (The_Barrier : in out Synchronous_Barrier;
+                               Notified    :    out Boolean);
+
+private
+   protected type Synchronous_Barrier (Release_Threshold : Barrier_Limit) is
+      entry Wait (Notified : out Boolean);
+   private
+      Keep_Open : Boolean := False;
+   end Synchronous_Barrier;
+end Ada.Synchronous_Barriers;
Index: Makefile.rtl
===================================================================
--- Makefile.rtl	(revision 178183)
+++ Makefile.rtl	(working copy)
@@ -33,6 +33,7 @@ 
   a-reatim$(objext) \
   a-retide$(objext) \
   a-rttiev$(objext) \
+  a-synbar$(objext) \
   a-sytaco$(objext) \
   a-tasatt$(objext) \
   a-taside$(objext) \
@@ -154,6 +155,7 @@ 
   a-envvar$(objext) \
   a-except$(objext) \
   a-exctra$(objext) \
+  a-fihema$(objext) \
   a-finali$(objext) \
   a-flteio$(objext) \
   a-fwteio$(objext) \
@@ -289,7 +291,6 @@ 
   a-tiunio$(objext) \
   a-unccon$(objext) \
   a-uncdea$(objext) \
-  a-undesu$(objext) \
   a-wichha$(objext) \
   a-wichun$(objext) \
   a-widcha$(objext) \
@@ -495,7 +496,6 @@ 
   s-ficobl$(objext) \
   s-fileio$(objext) \
   s-filofl$(objext) \
-  s-finmas$(objext) \
   s-finroo$(objext) \
   s-fishfl$(objext) \
   s-flocon$(objext) \
@@ -612,7 +612,6 @@ 
   s-stchop$(objext) \
   s-stoele$(objext) \
   s-stopoo$(objext) \
-  s-stposu$(objext) \
   s-stratt$(objext) \
   s-strhas$(objext) \
   s-string$(objext) \
Index: gcc-interface/Makefile.in
===================================================================
--- gcc-interface/Makefile.in	(revision 178176)
+++ gcc-interface/Makefile.in	(working copy)
@@ -420,9 +420,28 @@ 
   a-stzunb.adb<a-stzunb-shared.adb \
   a-stzunb.ads<a-stzunb-shared.ads \
   a-szunau.adb<a-szunau-shared.adb \
-  a-szuzti.adb<a-szuzti-shared.adb \
+  a-szuzti.adb<a-szuzti-shared.adb
+
+ATOMICS_BUILTINS_TARGET_PAIRS += \
   s-atocou.adb<s-atocou-builtin.adb
 
+ATOMICS_X86_TARGET_PAIRS += \
+  s-atocou.adb<s-atocou-x86.adb
+
+# Special version of units for x86 and x86-64 platforms.
+
+X86_TARGET_PAIRS = \
+  a-numaux.ads<a-numaux-x86.ads \
+  a-numaux.adb<a-numaux-x86.adb \
+  g-bytswa.adb<g-bytswa-x86.adb \
+  s-atocou.adb<s-atocou-x86.adb
+
+X86_64_TARGET_PAIRS = \
+  a-numaux.ads<a-numaux-x86.ads \
+  a-numaux.adb<a-numaux-x86.adb \
+  g-bytswa.adb<g-bytswa-x86.adb \
+  s-atocou.adb<s-atocou-builtin.adb
+
 LIB_VERSION = $(strip $(shell grep ' Library_Version :' $(fsrcpfx)ada/gnatvsn.ads | sed -e 's/.*"\(.*\)".*/\1/'))
 
 # $(filter-out PATTERN...,TEXT) removes all PATTERN words from TEXT.
@@ -497,7 +516,8 @@ 
   g-stsifd.adb<g-stsifd-sockets.adb \
   g-trasym.ads<g-trasym-unimplemented.ads \
   g-trasym.adb<g-trasym-unimplemented.adb \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=\
   mlib-tgt-specific.adb<mlib-tgt-specific-vxworks.adb \
@@ -597,7 +617,8 @@ 
   g-trasym.ads<g-trasym-unimplemented.ads \
   g-trasym.adb<g-trasym-unimplemented.adb \
   system.ads<system-vxworks-ppc-vthread.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=\
   mlib-tgt-specific.adb<mlib-tgt-specific-vxworks.adb \
@@ -661,6 +682,7 @@ 
   g-trasym.adb<g-trasym-unimplemented.adb \
   system.ads<system-vxworks-ppc.ads \
   $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS) \
   $(DUMMY_SOCKETS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=\
@@ -716,7 +738,7 @@ 
   g-trasym.adb<g-trasym-unimplemented.adb \
   system.ads<system-vxworks-x86.ads \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=\
   mlib-tgt-specific.adb<mlib-tgt-specific-vxworks.adb \
@@ -815,7 +837,7 @@ 
   g-trasym.ads<g-trasym-unimplemented.ads \
   g-trasym.adb<g-trasym-unimplemented.adb \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=\
   mlib-tgt-specific.adb<mlib-tgt-specific-vxworks.adb \
@@ -980,7 +1002,8 @@ 
 
   LIBGNAT_TARGET_PAIRS_64 = \
   system.ads<system-solaris-sparcv9.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   ifeq ($(strip $(filter-out sparc sun solaris%,$(targ))),)
     ifeq ($(strip $(MULTISUBDIR)),/sparcv9)
@@ -1050,30 +1073,14 @@ 
   g-soliop.ads<g-soliop-solaris.ads \
   $(ATOMICS_TARGET_PAIRS)
 
-  LIBGNAT_TARGET_PAIRS_32 = \
-  g-bytswa.adb<g-bytswa-x86.adb \
-  s-atocou.adb<s-atocou-x86.adb \
-  system.ads<system-solaris-x86.ads
-
-  LIBGNAT_TARGET_PAIRS_64 = \
-  system.ads<system-solaris-x86_64.ads
-
-  ifeq ($(strip $(filter-out %86 solaris2%,$(arch) $(osys))),)
-    ifeq ($(strip $(MULTISUBDIR)),/amd64)
-      LIBGNAT_TARGET_PAIRS = \
-      $(LIBGNAT_TARGET_PAIRS_COMMON) $(LIBGNAT_TARGET_PAIRS_64)
-    else
-      LIBGNAT_TARGET_PAIRS = \
-      $(LIBGNAT_TARGET_PAIRS_COMMON) $(LIBGNAT_TARGET_PAIRS_32)
-    endif
+  ifeq ($(strip $(MULTISUBDIR)),/amd64)
+    LIBGNAT_TARGET_PAIRS += \
+    $(X86_64_TARGET_PAIRS) \
+    system.ads<system-solaris-x86_64.ads
   else
-    ifeq ($(strip $(MULTISUBDIR)),/32)
-      LIBGNAT_TARGET_PAIRS = \
-      $(LIBGNAT_TARGET_PAIRS_COMMON) $(LIBGNAT_TARGET_PAIRS_32)
-    else
-      LIBGNAT_TARGET_PAIRS = \
-      $(LIBGNAT_TARGET_PAIRS_COMMON) $(LIBGNAT_TARGET_PAIRS_64)
-    endif
+    LIBGNAT_TARGET_PAIRS += \
+    $(X86_TARGET_PAIRS) \
+    system.ads<system-solaris-x86.ads
   endif
 
   TOOLS_TARGET_PAIRS=mlib-tgt-specific.adb<mlib-tgt-specific-solaris.adb
@@ -1092,13 +1099,15 @@ 
   a-intnam.ads<a-intnam-linux.ads \
   a-numaux.adb<a-numaux-x86.adb \
   a-numaux.ads<a-numaux-x86.ads \
+  a-synbar.adb<a-synbar-posix.adb \
+  a-synbar.ads<a-synbar-posix.ads \
   g-bytswa.adb<g-bytswa-x86.adb \
   s-inmaop.adb<s-inmaop-posix.adb \
   s-intman.adb<s-intman-posix.adb \
   s-tpopsp.adb<s-tpopsp-tls.adb \
   g-sercom.adb<g-sercom-linux.adb \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   ifeq ($(strip $(filter-out marte,$(THREAD_KIND))),)
     LIBGNAT_TARGET_PAIRS += \
@@ -1178,7 +1187,7 @@ 
   s-tpopsp.adb<s-tpopsp-posix-foreign.adb \
   system.ads<system-freebsd-x86.ads \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS =  \
     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
@@ -1235,7 +1244,7 @@ 
   s-tpopsp.adb<s-tpopsp-posix.adb \
   system.ads<system-freebsd-x86.ads \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS = \
   mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb
@@ -1297,6 +1306,8 @@ 
 ifeq ($(strip $(filter-out mips sgi irix6%,$(targ))),)
   LIBGNAT_TARGET_PAIRS = \
   a-intnam.ads<a-intnam-irix.ads \
+  a-synbar.adb<a-synbar-posix.adb \
+  a-synbar.ads<a-synbar-posix.ads \
   s-inmaop.adb<s-inmaop-posix.adb \
   s-intman.adb<s-intman-irix.adb \
   s-mastop.adb<s-mastop-irix.adb \
@@ -1391,7 +1402,8 @@ 
   s-taprop.adb<s-taprop-posix.adb \
   s-taspri.ads<s-taspri-posix.ads \
   s-tpopsp.adb<s-tpopsp-posix.adb \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   LIBGNAT_TARGET_PAIRS_32 = \
   system.ads<system-aix.ads
@@ -1453,7 +1465,8 @@ 
   s-tpopsp.adb<s-tpopsp-posix-foreign.adb \
   s-traceb.adb<s-traceb-mastop.adb \
   system.ads<system-tru64.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS=mlib-tgt-specific.adb<mlib-tgt-specific-tru64.adb
 
@@ -1520,7 +1533,8 @@ 
       s-vaflop.adb<s-vaflop-vms-ia64.adb \
       system.ads<system-vms-ia64.ads \
       s-parame.ads<s-parame-vms-ia64.ads \
-      $(ATOMICS_TARGET_PAIRS)
+      $(ATOMICS_TARGET_PAIRS) \
+      $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
     TOOLS_TARGET_PAIRS= \
       mlib-tgt-specific.adb<mlib-tgt-specific-vms-ia64.adb \
@@ -1540,7 +1554,8 @@ 
         s-vaflop.adb<s-vaflop-vms-alpha.adb \
         system.ads<system-vms_64.ads \
 	s-parame.ads<s-parame-vms-alpha.ads \
-        $(ATOMICS_TARGET_PAIRS)
+        $(ATOMICS_TARGET_PAIRS) \
+        $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
     TOOLS_TARGET_PAIRS= \
       mlib-tgt-specific.adb<mlib-tgt-specific-vms-alpha.adb \
@@ -1593,7 +1608,7 @@ 
   g-stsifd.adb<g-stsifd-sockets.adb \
   g-soliop.ads<g-soliop-mingw.ads \
   $(ATOMICS_TARGET_PAIRS) \
-  s-atocou.adb<s-atocou-x86.adb
+  $(ATOMICS_X86_TARGET_PAIRS)
 
   ifeq ($(strip $(filter-out rtx_w32 rtx_rtss,$(THREAD_KIND))),)
     LIBGNAT_TARGET_PAIRS += \
@@ -1786,13 +1801,16 @@ 
   a-exetim.adb<a-exetim-posix.adb \
   a-exetim.ads<a-exetim-default.ads \
   a-intnam.ads<a-intnam-linux.ads \
+  a-synbar.adb<a-synbar-posix.adb \
+  a-synbar.ads<a-synbar-posix.ads \
   s-inmaop.adb<s-inmaop-posix.adb \
   s-intman.adb<s-intman-posix.adb \
   s-linux.ads<s-linux.ads \
   s-osinte.adb<s-osinte-posix.adb \
   s-tpopsp.adb<s-tpopsp-tls.adb \
   g-sercom.adb<g-sercom-linux.adb \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   ifeq ($(strip $(filter-out xenomai,$(THREAD_KIND))),)
     LIBGNAT_TARGET_PAIRS = \
@@ -1983,6 +2001,8 @@ 
   a-exetim.ads<a-exetim-default.ads \
   a-intnam.ads<a-intnam-linux.ads \
   a-numaux.ads<a-numaux-libc-x86.ads \
+  a-synbar.adb<a-synbar-posix.adb \
+  a-synbar.ads<a-synbar-posix.ads \
   s-inmaop.adb<s-inmaop-posix.adb \
   s-intman.adb<s-intman-posix.adb \
   s-linux.ads<s-linux.ads \
@@ -1996,7 +2016,8 @@ 
   s-taspri.ads<s-taspri-posix-noaltstack.ads \
   g-sercom.adb<g-sercom-linux.adb \
   system.ads<system-linux-ia64.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS =  \
     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
@@ -2023,7 +2044,8 @@ 
   s-taspri.ads<s-taspri-posix-noaltstack.ads \
   s-tpopsp.adb<s-tpopsp-posix-foreign.adb \
   system.ads<system-hpux-ia64.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS = \
   mlib-tgt-specific.adb<mlib-tgt-specific-ia64-hpux.adb
@@ -2054,7 +2076,8 @@ 
   g-trasym.ads<g-trasym-unimplemented.ads \
   g-trasym.adb<g-trasym-unimplemented.adb \
   system.ads<system-linux-alpha.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS =  \
     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
@@ -2075,6 +2098,8 @@ 
   a-intnam.ads<a-intnam-linux.ads \
   a-numaux.adb<a-numaux-x86.adb \
   a-numaux.ads<a-numaux-x86.ads \
+  a-synbar.adb<a-synbar-posix.adb \
+  a-synbar.ads<a-synbar-posix.ads \
   s-inmaop.adb<s-inmaop-posix.adb \
   s-intman.adb<s-intman-posix.adb \
   s-linux.ads<s-linux.ads \
@@ -2088,7 +2113,8 @@ 
   s-taspri.ads<s-taspri-posix.ads \
   g-sercom.adb<g-sercom-linux.adb \
   system.ads<system-linux-x86_64.ads \
-  $(ATOMICS_TARGET_PAIRS)
+  $(ATOMICS_TARGET_PAIRS) \
+  $(ATOMICS_BUILTINS_TARGET_PAIRS)
 
   TOOLS_TARGET_PAIRS =  \
     mlib-tgt-specific.adb<mlib-tgt-specific-linux.adb \
@@ -2145,7 +2171,8 @@ 
     g-trasym.adb<g-trasym-unimplemented.adb \
     a-numaux.ads<a-numaux-x86.ads \
     a-numaux.adb<a-numaux-x86.adb \
-    $(ATOMICS_TARGET_PAIRS)
+    $(ATOMICS_TARGET_PAIRS) \
+    $(ATOMICS_BUILTINS_TARGET_PAIRS)
     ifeq ($(strip $(MULTISUBDIR)),/i386)
       LIBGNAT_TARGET_PAIRS += \
       system.ads<system-darwin-x86.ads