This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Implement Atomic_Synchronization pragmas


This patch implements the front end work for atomic synchronization.
Previously GNAT has not issued the necessary memory barriers to ensure
that references to atomic variables can be used to synchronize tasks
in a multi-processor environment.

This patch implements the front end work for fixing this problem

References to atomic variables (identifiers or expanded names)
have a flag Atomic_Sync_Required to flag to the back end that
appropriate memory barriers are to be generated.

Pragmas Disable/Enable_Atomic_Synchronization allow turning this
on and off, they have the same form and semantics as pragmas
Suppress/Unsuppress (and are implemented internally using this
mechanism).

A new warning flag -gnatd.n enables information messages showing
where synchronization is enabled.

Atomic synchronization is on by default, but the initial
default (overridable with pragma Enable_Atomic_Synchronization)
can be set to suppress such synchronization using -gnated.

Debug flags -gnatd.d and -gnatd.e can be used to unconditionally
disable and enable atomic synchronization for all references,
ignoring pragmas and -gnated.

The following test is compiled using -gnatw.n -gnatld7

     1. pragma Disable_Atomic_Synchronization;
     2. procedure AtSync is
     3.    X : Integer := 1;
     4.    Y : Integer := 1;
     5.    pragma Atomic (X);
     6.    pragma Atomic (Y);
     7.
     8.    pragma Enable_Atomic_Synchronization (X);
     9.
    10. begin
    11.    X := Y;
           |
        >>> info: atomic synchronization set for "X"

    12.    AtSync.Y := AtSync.X;
                              |
        >>> info: atomic synchronization set for "X"

    13.
    14.    declare
    15.       pragma Enable_Atomic_Synchronization (Y);
    16.       pragma Disable_Atomic_Synchronization (X);
    17.    begin
    18.       X := Y;
                   |
        >>> info: atomic synchronization set for "Y"

    19.    end;
    20.
    21.    X := Y;
           |
        >>> info: atomic synchronization set for "X"

    22. end;

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

2011-10-24  Robert Dewar  <dewar@adacore.com>

	* checks.ads, checks.adb: Add handling of Synchronization_Check
	* debug.adb: Add doc for -gnatd.d and -gnatd.e (disable/enable
	atomic sync).
	* exp_ch2.adb (Expand_Entity_Reference): Set Atomic_Sync_Required
	flag Minor code reorganization.
	* opt.ads (Warn_On_Atomic_Synchronization): New switch.
	* par-prag.adb: Add dummy entries for pragma
	Disable/Enable_Atomic_Synchronization.
	* sem_prag.adb (Process_Suppress_Unsuppress): Handle
	case of Atomic_Synchronization specially (not suppressed
	by All_Checks, cannot be set from Source).
	(Pragma Disable/Enable_Atomic_Synchronization): Add processing.
	* sinfo.ads, sinfo.adb: Add Atomic_Sync_Required flag
	* snames.ads-tmpl: Add entry for Atomic_Synchronization Add
	entry for pragma Disable/Enable_Atomic_Synchronization
	* switch-c.adb: The -gnatp switch does not disable
	Atomic_Synchronization Add -gnatep switch to disable
	Atomic_Synchronization.
	* types.ads: Add entry for Synchronization_Check
	* usage.adb: Add line for -gnated switch
	* warnsw.adb: Settings for Warn_On_Atomic_Synchronization

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]