Simplify s-linux*.ads files by using s-oscons-tmplt.c to generate proper definition of pthread_mutex_t.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-06 Pascal Obry <o...@adacore.com> * s-linux.ads, s-linux-alpha.ads, s-linux-hppa.ads, s-linux-mipsel.ads, s-linux-sparc.ads: Remove hard coded and now wrong definitions. * s-oscons-tmplt.c: Add support for generating pthread related types size on GNU/Linux as done for Darwin. * s-osinte-linux.ads: Use s-oscons to define the pthread types.
Index: s-osinte-linux.ads =================================================================== --- s-osinte-linux.ads (revision 178565) +++ s-osinte-linux.ads (working copy) @@ -41,6 +41,7 @@ with Ada.Unchecked_Conversion; with Interfaces.C; with System.Linux; +with System.OS_Constants; package System.OS_Interface is pragma Preelaborate; @@ -557,35 +558,31 @@ end record; pragma Convention (C, timespec); - type pthread_attr_t is record - detachstate : int; - schedpolicy : int; - schedparam : struct_sched_param; - inheritsched : int; - scope : int; - guardsize : size_t; - stackaddr_set : int; - stackaddr : System.Address; - stacksize : size_t; - end record; + type unsigned_long_long_t is mod 2 ** 64; + -- Local type only used to get it's 'Alignment below + + type pthread_attr_t is + array (1 .. OS_Constants.PTHREAD_ATTR_SIZE) of unsigned_char; pragma Convention (C, pthread_attr_t); + for pthread_attr_t'Alignment use Interfaces.C.unsigned_long'Alignment; - type pthread_condattr_t is record - dummy : int; - end record; + type pthread_condattr_t is + array (1 .. OS_Constants.PTHREAD_CONDATTR_SIZE) of unsigned_char; pragma Convention (C, pthread_condattr_t); + for pthread_condattr_t'Alignment use Interfaces.C.int'Alignment; - type pthread_mutexattr_t is record - mutexkind : int; - end record; + type pthread_mutexattr_t is + array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE) of unsigned_char; pragma Convention (C, pthread_mutexattr_t); + for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment; - type pthread_mutex_t is new System.Linux.pthread_mutex_t; + type pthread_mutex_t is + array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE) of unsigned_char; + pragma Convention (C, pthread_mutex_t); + for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment; - type unsigned_long_long_t is mod 2 ** 64; - -- Local type only used to get it's 'Alignment below - - type pthread_cond_t is array (0 .. 47) of unsigned_char; + type pthread_cond_t is + array (1 .. OS_Constants.PTHREAD_COND_SIZE) of unsigned_char; pragma Convention (C, pthread_cond_t); for pthread_cond_t'Alignment use unsigned_long_long_t'Alignment; Index: s-linux.ads =================================================================== --- s-linux.ads (revision 178565) +++ s-linux.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2008-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -101,19 +101,4 @@ SA_SIGINFO : constant := 16#04#; SA_ONSTACK : constant := 16#08000000#; - type struct_pthread_fast_lock is record - status : Long_Integer; - spinlock : Integer; - end record; - pragma Convention (C, struct_pthread_fast_lock); - - type pthread_mutex_t is record - m_reserved : Integer; - m_count : Integer; - m_owner : System.Address; - m_kind : Integer; - m_lock : struct_pthread_fast_lock; - end record; - pragma Convention (C, pthread_mutex_t); - end System.Linux; Index: s-linux-alpha.ads =================================================================== --- s-linux-alpha.ads (revision 178565) +++ s-linux-alpha.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2009-2011, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -111,9 +111,4 @@ SA_SIGINFO : constant := 16#40#; SA_ONSTACK : constant := 16#01#; - type pthread_mutex_t is record - dum0, dum1, dum2, dum3, dum4 : Interfaces.C.unsigned_long; - end record; - pragma Convention (C, pthread_mutex_t); - end System.Linux; Index: s-linux-hppa.ads =================================================================== --- s-linux-hppa.ads (revision 178565) +++ s-linux-hppa.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2008-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2011, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -103,26 +103,4 @@ SA_SIGINFO : constant := 16#10#; SA_ONSTACK : constant := 16#01#; - type lock_array is array (1 .. 4) of Integer; - type atomic_lock_t is record - lock : lock_array; - end record; - pragma Convention (C, atomic_lock_t); - for atomic_lock_t'Alignment use 16; - - type struct_pthread_fast_lock is record - spinlock : atomic_lock_t; - status : Long_Integer; - end record; - pragma Convention (C, struct_pthread_fast_lock); - - type pthread_mutex_t is record - m_reserved : Integer; - m_count : Integer; - m_owner : System.Address; - m_kind : Integer; - m_lock : struct_pthread_fast_lock; - end record; - pragma Convention (C, pthread_mutex_t); - end System.Linux; Index: s-linux-mipsel.ads =================================================================== --- s-linux-mipsel.ads (revision 178565) +++ s-linux-mipsel.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2009-2011, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -100,19 +100,4 @@ SA_SIGINFO : constant := 16#04#; SA_ONSTACK : constant := 16#08000000#; - type struct_pthread_fast_lock is record - status : Long_Integer; - spinlock : Integer; - end record; - pragma Convention (C, struct_pthread_fast_lock); - - type pthread_mutex_t is record - m_reserved : Integer; - m_count : Integer; - m_owner : System.Address; - m_kind : Integer; - m_lock : struct_pthread_fast_lock; - end record; - pragma Convention (C, pthread_mutex_t); - end System.Linux; Index: s-linux-sparc.ads =================================================================== --- s-linux-sparc.ads (revision 178565) +++ s-linux-sparc.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2009-2011, Free Software Foundation, Inc. -- -- -- -- GNARL is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -109,11 +109,4 @@ SA_SIGINFO : constant := 16#200#; SA_ONSTACK : constant := 16#001#; - type pthread_mutex_t is record - L1, L2, L3, L4 : Interfaces.C.long; - I1, I2 : Interfaces.C.int; - end record; - pragma Convention (C, pthread_mutex_t); - -- 24 bytes for 32-bit and 40 bytes for 64-bit, aligned like 'long' - end System.Linux; Index: s-oscons-tmplt.c =================================================================== --- s-oscons-tmplt.c (revision 178565) +++ s-oscons-tmplt.c (working copy) @@ -163,6 +163,10 @@ # include <_types.h> #endif +#ifdef __linux__ +# include <pthread.h> +#endif + #ifdef NATIVE #include <stdio.h> @@ -1351,42 +1355,50 @@ putchar ('\n'); #endif -#if defined (__APPLE__) || defined (DUMMY) +#if defined (__APPLE__) || defined (__linux__) || defined (DUMMY) /* - ------------------------------- - -- Darwin-specific constants -- - ------------------------------- - - -- These constants may be used only within the Darwin version of the GNAT - -- runtime library. + -- Sizes of pthread data types */ -#define PTHREAD_SIZE __PTHREAD_SIZE__ +#if defined (__APPLE__) || defined (DUMMY) +#define PTHREAD_SIZE __PTHREAD_SIZE__ +#define PTHREAD_ATTR_SIZE __PTHREAD_ATTR_SIZE__ +#define PTHREAD_MUTEXATTR_SIZE __PTHREAD_MUTEXATTR_SIZE__ +#define PTHREAD_MUTEX_SIZE __PTHREAD_MUTEX_SIZE__ +#define PTHREAD_CONDATTR_SIZE __PTHREAD_CONDATTR_SIZE__ +#define PTHREAD_COND_SIZE __PTHREAD_COND_SIZE__ +#define PTHREAD_RWLOCKATTR_SIZE __PTHREAD_RWLOCKATTR_SIZE__ +#define PTHREAD_RWLOCK_SIZE __PTHREAD_RWLOCK_SIZE__ +#define PTHREAD_ONCE_SIZE __PTHREAD_ONCE_SIZE__ +#else +#define PTHREAD_SIZE (sizeof (pthread_t)) +#define PTHREAD_ATTR_SIZE __SIZEOF_PTHREAD_ATTR_T +#define PTHREAD_MUTEXATTR_SIZE __SIZEOF_PTHREAD_MUTEXATTR_T +#define PTHREAD_MUTEX_SIZE __SIZEOF_PTHREAD_MUTEX_T +#define PTHREAD_CONDATTR_SIZE __SIZEOF_PTHREAD_CONDATTR_T +#define PTHREAD_COND_SIZE __SIZEOF_PTHREAD_COND_T +#define PTHREAD_RWLOCKATTR_SIZE __SIZEOF_PTHREAD_RWLOCKATTR_T +#define PTHREAD_RWLOCK_SIZE __SIZEOF_PTHREAD_RWLOCK_T +#define PTHREAD_ONCE_SIZE (sizeof (pthread_once_t)) +#endif + CND(PTHREAD_SIZE, "Pad in pthread_t") -#define PTHREAD_ATTR_SIZE __PTHREAD_ATTR_SIZE__ CND(PTHREAD_ATTR_SIZE, "Pad in pthread_attr_t") -#define PTHREAD_MUTEXATTR_SIZE __PTHREAD_MUTEXATTR_SIZE__ CND(PTHREAD_MUTEXATTR_SIZE, "Pad in pthread_mutexattr_t") -#define PTHREAD_MUTEX_SIZE __PTHREAD_MUTEX_SIZE__ CND(PTHREAD_MUTEX_SIZE, "Pad in pthread_mutex_t") -#define PTHREAD_CONDATTR_SIZE __PTHREAD_CONDATTR_SIZE__ CND(PTHREAD_CONDATTR_SIZE, "Pad in pthread_condattr_t") -#define PTHREAD_COND_SIZE __PTHREAD_COND_SIZE__ CND(PTHREAD_COND_SIZE, "Pad in pthread_cond_t") -#define PTHREAD_RWLOCKATTR_SIZE __PTHREAD_RWLOCKATTR_SIZE__ CND(PTHREAD_RWLOCKATTR_SIZE, "Pad in pthread_rwlockattr_t") -#define PTHREAD_RWLOCK_SIZE __PTHREAD_RWLOCK_SIZE__ CND(PTHREAD_RWLOCK_SIZE, "Pad in pthread_rwlock_t") -#define PTHREAD_ONCE_SIZE __PTHREAD_ONCE_SIZE__ CND(PTHREAD_ONCE_SIZE, "Pad in pthread_once_t") #endif