From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Patrick Bernardi <bernardi@adacore.com>
Subject: [Ada] Do not assume a priority value of zero is a valid priority
Date: Wed, 10 Nov 2021 08:58:41 +0000 [thread overview]
Message-ID: <20211110085841.GA2811161@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 918 bytes --]
While a priority value of zero is typically valid on most systems, there
are some targets where zero may be reserved for OS purposes (for
example: RTEMS where zero is reserved for use by the idle thread and
should not be used by applications). This patch removes one occurrence
in GNARL where a Priority object was initialized to zero instead of
Priority'First, and adjusts the Priority type on RTEMS to prevent the
use of priority level zero. By contrast,
System.Tasking.Unspecified_Priority is hardcoded as -1 since it is used
in init.c, which does not have access to the Priority type.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnarl/s-taskin.adb (Initialize_ATCB): Initialize
T.Common.Current_Priority to Priority'First.
* libgnarl/s-taskin.ads (Unspecified_Priority): Redefined as -1.
* libgnat/system-rtems.ads: Start priority range from 1, as 0 is
reserved by the operating system.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2405 bytes --]
diff --git a/gcc/ada/libgnarl/s-taskin.adb b/gcc/ada/libgnarl/s-taskin.adb
--- a/gcc/ada/libgnarl/s-taskin.adb
+++ b/gcc/ada/libgnarl/s-taskin.adb
@@ -127,7 +127,7 @@ package body System.Tasking is
end if;
pragma Assert (T.Common.Domain /= null);
- T.Common.Current_Priority := 0;
+ T.Common.Current_Priority := Priority'First;
T.Common.Protected_Action_Nesting := 0;
T.Common.Call := null;
T.Common.Task_Arg := Task_Arg;
diff --git a/gcc/ada/libgnarl/s-taskin.ads b/gcc/ada/libgnarl/s-taskin.ads
--- a/gcc/ada/libgnarl/s-taskin.ads
+++ b/gcc/ada/libgnarl/s-taskin.ads
@@ -773,7 +773,10 @@ package System.Tasking is
-- Priority info --
-------------------
- Unspecified_Priority : constant Integer := System.Priority'First - 1;
+ Unspecified_Priority : constant Integer := -1;
+ -- Indicates that a task has an unspecified priority. This is hardcoded as
+ -- -1 rather than System.Priority'First - 1 as the value needs to be used
+ -- in init.c to specify that the main task has no specified priority.
Priority_Not_Boosted : constant Integer := System.Priority'First - 1;
-- Definition of Priority actually has to come from the RTS configuration
diff --git a/gcc/ada/libgnat/system-rtems.ads b/gcc/ada/libgnat/system-rtems.ads
--- a/gcc/ada/libgnat/system-rtems.ads
+++ b/gcc/ada/libgnat/system-rtems.ads
@@ -109,15 +109,13 @@ package System is
-- hardware priority levels. Protected Object ceilings can
-- override these values.
-- 245 is used by the Interrupt_Manager task
- -- 0 is reserved for the RTEMS IDLE task and really should not
- -- be accessible from Ada but GNAT initializes
- -- Current_Priority to 0 so it must be valid
+ -- 0 is reserved for the RTEMS IDLE task
Max_Priority : constant Positive := 244;
Max_Interrupt_Priority : constant Positive := 254;
- subtype Any_Priority is Integer range 0 .. 254;
- subtype Priority is Any_Priority range 0 .. 244;
+ subtype Any_Priority is Integer range 1 .. 254;
+ subtype Priority is Any_Priority range 1 .. 244;
subtype Interrupt_Priority is Any_Priority range 245 .. 254;
Default_Priority : constant Priority := 122;
reply other threads:[~2021-11-10 8:58 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=20211110085841.GA2811161@adacore.com \
--to=derodat@adacore.com \
--cc=bernardi@adacore.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).