Patchwork [Ada] As we use the default behavior, no need to allocate a cond attribute

login
register
mail settings
Submitter Arnaud Charlet
Date Nov. 21, 2011, 11:40 a.m.
Message ID <20111121114040.GA19784@adacore.com>
Download mbox | patch
Permalink /patch/126759/
State New
Headers show

Comments

Arnaud Charlet - Nov. 21, 2011, 11:40 a.m.
Passing a null pointer to pthread_cond_init for the attribute specify
that the default attribute should be used. This is exactly what was done
previously by using a cond attribute with default value.

This is just a code clean-up, no change in behavior but we avoid some
system calls and furthermore the cond attribute was not destroyed
properly which could cause resource/memory leaks.

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

2011-11-21  Pascal Obry  <obry@adacore.com>

	* s-taprop-linux.adb (Initialize_Lock): Do not allocate a cond
	attribute as not needed.

Patch

Index: s-taprop-linux.adb
===================================================================
--- s-taprop-linux.adb	(revision 181564)
+++ s-taprop-linux.adb	(working copy)
@@ -1069,8 +1069,7 @@ 
    ----------------
 
    procedure Initialize (S : in out Suspension_Object) is
-      Cond_Attr : aliased pthread_condattr_t;
-      Result    : Interfaces.C.int;
+      Result : Interfaces.C.int;
 
    begin
       --  Initialize internal state (always to False (RM D.10(6)))
@@ -1090,11 +1089,8 @@ 
 
       --  Initialize internal condition variable
 
-      Result := pthread_condattr_init (Cond_Attr'Access);
-      pragma Assert (Result = 0);
+      Result := pthread_cond_init (S.CV'Access, null);
 
-      Result := pthread_cond_init (S.CV'Access, Cond_Attr'Access);
-
       pragma Assert (Result = 0 or else Result = ENOMEM);
 
       if Result /= 0 then