From patchwork Mon Oct 24 09:25:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 121308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1540B1007D1 for ; Mon, 24 Oct 2011 20:25:44 +1100 (EST) Received: (qmail 24448 invoked by alias); 24 Oct 2011 09:25:37 -0000 Received: (qmail 24090 invoked by uid 22791); 24 Oct 2011 09:25:35 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Oct 2011 09:25:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1B1492BB2E4; Mon, 24 Oct 2011 05:25:15 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id EN0hOtcDtX8Q; Mon, 24 Oct 2011 05:25:15 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id F2C4C2BB2DB; Mon, 24 Oct 2011 05:25:14 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id F349F3FEE8; Mon, 24 Oct 2011 05:25:14 -0400 (EDT) Date: Mon, 24 Oct 2011 05:25:14 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Matthew Heaney Subject: [Ada] Change sense of predicate when dequeuing high priority element Message-ID: <20111024092514.GA19024@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The predicate that decides whether to dequeue a high priority item included a negation operator, but this reversed the correct sense. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-24 Matthew Heaney * a-cuprqu.adb, a-cbprqu.adb (Dequeue_Only_High_Priority): Predicate had wrong sense. Index: a-cbprqu.adb =================================================================== --- a-cbprqu.adb (revision 180365) +++ a-cbprqu.adb (working copy) @@ -51,8 +51,31 @@ Success : out Boolean) is begin + -- This operation dequeues a high priority item if it exists in the + -- queue. By "high priority" we mean an item whose priority is equal + -- or greater than the value At_Least. The generic formal operation + -- Before has the meaning "has higher priority than". To dequeue an + -- item (meaning that we return True as our Success value), we need + -- as our predicate the equivalent of "has equal or higher priority + -- than", but we cannot say that directly, so we require some logical + -- gymnastics to make it so. + + -- If E is the element at the head of the queue, and symbol ">" + -- refers to the "is higher priority than" function Before, then we + -- derive our predicate as follows: + + -- original: P(E) >= At_Least + -- same as: not (P(E) < At_Least) + -- same as: not (At_Least > P(E)) + -- same as: not Before (At_Least, P(E)) + + -- But that predicate needs to be true in order to successfully + -- dequeue an item. If it's false, it means no item is dequeued, and + -- we return False as the Success value. + if List.Length = 0 - or else not Before (At_Least, Get_Priority (List.First_Element)) + or else Before (At_Least, + Get_Priority (List.Container.First_Element)) then Success := False; return; Index: a-cuprqu.adb =================================================================== --- a-cuprqu.adb (revision 180365) +++ a-cuprqu.adb (working copy) @@ -72,8 +72,29 @@ Success : out Boolean) is begin + -- This operation dequeues a high priority item if it exists in the + -- queue. By "high priority" we mean an item whose priority is equal + -- or greater than the value At_Least. The generic formal operation + -- Before has the meaning "has higher priority than". To dequeue an + -- item (meaning that we return True as our Success value), we need + -- as our predicate the equivalent of "has equal or higher priority + -- than", but we cannot say that directly, so we require some logical + -- gymnastics to make it so. + + -- If E is the element at the head of the queue, and symbol ">" + -- refers to the "is higher priority than" function Before, then we + -- derive our predicate as follows: + -- original: P(E) >= At_Least + -- same as: not (P(E) < At_Least) + -- same as: not (At_Least > P(E)) + -- same as: not Before (At_Least, P(E)) + + -- But that predicate needs to be true in order to successfully + -- dequeue an item. If it's false, it means no item is dequeued, and + -- we return False as the Success value. + if List.Length = 0 - or else not Before (At_Least, Get_Priority (List.First.Element)) + or else Before (At_Least, Get_Priority (List.First.Element)) then Success := False; return;