Both types and corresponding routines are defined for GNU/Linux.

Those definitions are made aliases for pthread_mutex_t and
pthread_mutexattr_t on platforms where read/write lock is
not supported by the GNAT runtime.

Still work in progress, more changes to follow.

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

2011-09-27  Pascal Obry  <o...@adacore.com>

        * s-osinte-aix.ads, s-osinte-darwin.ads, s-osinte-freebsd.ads,
        s-osinte-hpux.ads, s-osinte-irix.ads,
        s-osinte-solaris-posix.ads (pthread_rwlock_t): New definition alias of
        pthread_mutex_t.
        (pthread_rwlockattr_t): New definition alias of pthread_mutexattr_t.
        * s-osinte-linux.ads (pthread_rwlock_t, pthread_rwlockattr_t,
        pthread_rwlockattr_init, pthread_rwlockattr_destroy,
        pthread_rwlockattr_setkind_np, pthread_rwlock_init,
        pthread_rwlock_destroy, pthread_rwlock_rdlock,
        pthread_rwlock_wrlock, pthread_rwlock_unlock): New.

Index: s-osinte-aix.ads
===================================================================
--- s-osinte-aix.ads    (revision 179247)
+++ s-osinte-aix.ads    (working copy)
@@ -276,6 +276,14 @@
    PTHREAD_SCOPE_PROCESS : constant := 1;
    PTHREAD_SCOPE_SYSTEM  : constant := 0;
 
+   --  Read/Write lock not supported on AIX. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    -----------
    -- Stack --
    -----------
Index: s-osinte-darwin.ads
===================================================================
--- s-osinte-darwin.ads (revision 179247)
+++ s-osinte-darwin.ads (working copy)
@@ -256,6 +256,14 @@
    PTHREAD_SCOPE_PROCESS : constant := 2;
    PTHREAD_SCOPE_SYSTEM  : constant := 1;
 
+   --  Read/Write lock not supported on Darwin. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    -----------
    -- Stack --
    -----------
Index: s-osinte-freebsd.ads
===================================================================
--- s-osinte-freebsd.ads        (revision 179247)
+++ s-osinte-freebsd.ads        (working copy)
@@ -289,6 +289,14 @@
    PTHREAD_SCOPE_PROCESS : constant := 0;
    PTHREAD_SCOPE_SYSTEM  : constant := 2;
 
+   --  Read/Write lock not supported on freebsd. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    -----------
    -- Stack --
    -----------
Index: s-osinte-hpux.ads
===================================================================
--- s-osinte-hpux.ads   (revision 179247)
+++ s-osinte-hpux.ads   (working copy)
@@ -265,6 +265,14 @@
    PTHREAD_SCOPE_PROCESS : constant := 2;
    PTHREAD_SCOPE_SYSTEM  : constant := 1;
 
+   --  Read/Write lock not supported on HPUX. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    -----------
    -- Stack --
    -----------
Index: s-osinte-irix.ads
===================================================================
--- s-osinte-irix.ads   (revision 179247)
+++ s-osinte-irix.ads   (working copy)
@@ -7,7 +7,7 @@
 --                                  S p e c                                 --
 --                                                                          --
 --             Copyright (C) 1991-1994, Florida State University            --
---          Copyright (C) 1995-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1995-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT 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- --
@@ -250,6 +250,14 @@
 
    PTHREAD_CREATE_DETACHED : constant := 1;
 
+   --  Read/Write lock not supported on SGI. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    -----------
    -- Stack --
    -----------
Index: s-osinte-linux.ads
===================================================================
--- s-osinte-linux.ads  (revision 179247)
+++ s-osinte-linux.ads  (working copy)
@@ -272,12 +272,14 @@
    function To_pthread_t is
      new Ada.Unchecked_Conversion (unsigned_long, pthread_t);
 
-   type pthread_mutex_t     is limited private;
-   type pthread_cond_t      is limited private;
-   type pthread_attr_t      is limited private;
-   type pthread_mutexattr_t is limited private;
-   type pthread_condattr_t  is limited private;
-   type pthread_key_t       is private;
+   type pthread_mutex_t      is limited private;
+   type pthread_rwlock_t     is limited private;
+   type pthread_cond_t       is limited private;
+   type pthread_attr_t       is limited private;
+   type pthread_mutexattr_t  is limited private;
+   type pthread_rwlockattr_t is limited private;
+   type pthread_condattr_t   is limited private;
+   type pthread_key_t        is private;
 
    PTHREAD_CREATE_DETACHED : constant := 1;
 
@@ -358,6 +360,42 @@
    function pthread_mutex_unlock (mutex : access pthread_mutex_t) return int;
    pragma Import (C, pthread_mutex_unlock, "pthread_mutex_unlock");
 
+   function pthread_rwlockattr_init
+     (attr : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlockattr_init, "pthread_rwlockattr_init");
+
+   function pthread_rwlockattr_destroy
+     (attr : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlockattr_destroy, "pthread_rwlockattr_destroy");
+
+   PTHREAD_RWLOCK_PREFER_READER_NP              : constant := 0;
+   PTHREAD_RWLOCK_PREFER_WRITER_NP              : constant := 1;
+   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2;
+
+   function pthread_rwlockattr_setkind_np
+     (attr : access pthread_rwlockattr_t;
+      pref : int) return int;
+   pragma Import
+     (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np");
+
+   function pthread_rwlock_init
+     (mutex : access pthread_rwlock_t;
+      attr  : access pthread_rwlockattr_t) return int;
+   pragma Import (C, pthread_rwlock_init, "pthread_rwlock_init");
+
+   function pthread_rwlock_destroy
+     (mutex : access pthread_rwlock_t) return int;
+   pragma Import (C, pthread_rwlock_destroy, "pthread_rwlock_destroy");
+
+   function pthread_rwlock_rdlock (mutex : access pthread_rwlock_t) return int;
+   pragma Import (C, pthread_rwlock_rdlock, "pthread_rwlock_rdlock");
+
+   function pthread_rwlock_wrlock (mutex : access pthread_rwlock_t) return int;
+   pragma Import (C, pthread_rwlock_wrlock, "pthread_rwlock_wrlock");
+
+   function pthread_rwlock_unlock (mutex : access pthread_rwlock_t) return int;
+   pragma Import (C, pthread_rwlock_unlock, "pthread_rwlock_unlock");
+
    function pthread_condattr_init
      (attr : access pthread_condattr_t) return int;
    pragma Import (C, pthread_condattr_init, "pthread_condattr_init");
@@ -588,6 +626,18 @@
    pragma Convention (C, pthread_mutex_t);
    for pthread_mutex_t'Alignment use Interfaces.C.unsigned_long'Alignment;
 
+   type pthread_rwlockattr_t is record
+      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
+   end record;
+   pragma Convention (C, pthread_rwlockattr_t);
+   for pthread_rwlockattr_t'Alignment use Interfaces.C.unsigned_long'Alignment;
+
+   type pthread_rwlock_t is record
+      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE);
+   end record;
+   pragma Convention (C, pthread_rwlock_t);
+   for pthread_rwlock_t'Alignment use Interfaces.C.unsigned_long'Alignment;
+
    type pthread_cond_t is record
       Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE);
    end record;
Index: s-osinte-solaris-posix.ads
===================================================================
--- s-osinte-solaris-posix.ads  (revision 179247)
+++ s-osinte-solaris-posix.ads  (working copy)
@@ -255,6 +255,14 @@
    type pthread_condattr_t  is limited private;
    type pthread_key_t       is private;
 
+   --  Read/Write lock not supported on Solaris. To add support both types
+   --  pthread_rwlock_t and pthread_rwlockattr_t must properly be defined
+   --  with the associated routines pthread_rwlock_[init/destroy] and
+   --  pthread_rwlock_[rdlock/wrlock/unlock].
+
+   subtype pthread_rwlock_t     is pthread_mutex_t;
+   subtype pthread_rwlockattr_t is pthread_mutexattr_t;
+
    PTHREAD_CREATE_DETACHED : constant := 16#40#;
 
    PTHREAD_SCOPE_PROCESS : constant := 0;

Reply via email to