diff mbox

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

Message ID 20111121113855.GA18100@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Nov. 21, 2011, 11:38 a.m. UTC
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  <obry@adacore.com>

	* s-taprop-linux.adb (Initialize_Lock): Do not allocate a
	mutex attribute as not needed.
	(Initialize_TCB): Likewise.
	(Initialize): Likewise.
diff mbox

Patch

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