From patchwork Mon Nov 21 11:38:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 126757 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 3E8E6B720F for ; Mon, 21 Nov 2011 22:39:21 +1100 (EST) Received: (qmail 5970 invoked by alias); 21 Nov 2011 11:39:19 -0000 Received: (qmail 5961 invoked by uid 22791); 21 Nov 2011 11:39:18 -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, 21 Nov 2011 11:38:55 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 280422BAFB9; Mon, 21 Nov 2011 06:38:55 -0500 (EST) 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 v8aECVXC4a5N; Mon, 21 Nov 2011 06:38:55 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 0B4062BAFA8; Mon, 21 Nov 2011 06:38:55 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 0B20D3FEE8; Mon, 21 Nov 2011 06:38:55 -0500 (EST) Date: Mon, 21 Nov 2011 06:38:55 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Pascal Obry Subject: [Ada] As we use the default behavior, no need to allocate a mutex attribute Message-ID: <20111121113855.GA18100@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 Passing a null pointer to pthread_mutex_init for the attribute specify that the default attribute should be used. This is exactly what was done previously by using a mutex attribute with default value. This is just a code clean-up, no change in behavior but we avoid some system calls and furthermore the mutex attributes were not destroyed properly which could cause resource/memory leaks. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-11-21 Pascal Obry * s-taprop-linux.adb (Initialize_Lock): Do not allocate a mutex attribute as not needed. (Initialize_TCB): Likewise. (Initialize): Likewise. Index: s-taprop-linux.adb =================================================================== --- s-taprop-linux.adb (revision 181556) +++ s-taprop-linux.adb (working copy) @@ -291,15 +291,11 @@ else declare - Mutex_Attr : aliased pthread_mutexattr_t; - Result : Interfaces.C.int; + Result : Interfaces.C.int; begin - Result := pthread_mutexattr_init (Mutex_Attr'Access); - pragma Assert (Result = 0); + Result := pthread_mutex_init (L.WO'Access, null); - Result := pthread_mutex_init (L.WO'Access, Mutex_Attr'Access); - pragma Assert (Result = 0 or else Result = ENOMEM); if Result = ENOMEM then @@ -315,15 +311,11 @@ is pragma Unreferenced (Level); - Mutex_Attr : aliased pthread_mutexattr_t; - Result : Interfaces.C.int; + Result : Interfaces.C.int; begin - Result := pthread_mutexattr_init (Mutex_Attr'Access); - pragma Assert (Result = 0); + Result := pthread_mutex_init (L, null); - Result := pthread_mutex_init (L, Mutex_Attr'Access); - pragma Assert (Result = 0 or else Result = ENOMEM); if Result = ENOMEM then @@ -817,9 +809,8 @@ -------------------- procedure Initialize_TCB (Self_ID : Task_Id; Succeeded : out Boolean) is - Mutex_Attr : aliased pthread_mutexattr_t; - Cond_Attr : aliased pthread_condattr_t; - Result : Interfaces.C.int; + Cond_Attr : aliased pthread_condattr_t; + Result : Interfaces.C.int; begin -- Give the task a unique serial number @@ -831,11 +822,8 @@ Self_ID.Common.LL.Thread := Null_Thread_Id; if not Single_Lock then - Result := pthread_mutexattr_init (Mutex_Attr'Access); - pragma Assert (Result = 0); - Result := - pthread_mutex_init (Self_ID.Common.LL.L'Access, Mutex_Attr'Access); + pthread_mutex_init (Self_ID.Common.LL.L'Access, null); pragma Assert (Result = 0 or else Result = ENOMEM); if Result /= 0 then @@ -1081,9 +1069,8 @@ ---------------- procedure Initialize (S : in out Suspension_Object) is - Mutex_Attr : aliased pthread_mutexattr_t; - Cond_Attr : aliased pthread_condattr_t; - Result : Interfaces.C.int; + Cond_Attr : aliased pthread_condattr_t; + Result : Interfaces.C.int; begin -- Initialize internal state (always to False (RM D.10(6))) @@ -1093,11 +1080,8 @@ -- Initialize internal mutex - Result := pthread_mutexattr_init (Mutex_Attr'Access); - pragma Assert (Result = 0); + Result := pthread_mutex_init (S.L'Access, null); - Result := pthread_mutex_init (S.L'Access, Mutex_Attr'Access); - pragma Assert (Result = 0 or else Result = ENOMEM); if Result = ENOMEM then