libcaf_shmem doesn't currently build on Solaris.  Previously this went
unnoticed because the AX_PTHREADS autoconf macro erroneously didn't
detect pthreads support.  Once this is fixed, compilation fails:

In file included from caf/shmem/supervisor.h:35,
                 from caf/shmem/alloc.c:31:
caf/shmem/sync.h:46:25: error: conflicting types for ‘lock_t’; have 
‘caf_shmem_mutex’ {aka ‘struct _pthread_mutex’}
   46 | typedef caf_shmem_mutex lock_t;
      |                         ^~~~~~
In file included from /usr/include/sys/machtypes.h:12,
                 from /usr/include/sys/types.h:17,
                 from caf/shmem/thread_support.h:33,
                 from caf/shmem/shared_memory.h:28,
                 from caf/shmem/allocator.h:31,
                 from caf/shmem/alloc.h:28,
                 from caf/shmem/alloc.c:29:
/usr/include/ia32/sys/machtypes.h:50:25: note: previous declaration of ‘lock_t’ 
with type ‘lock_t’ {aka ‘unsigned int’}

The lock_t definition in <ia32/sys/machtypes.h> is benign: POSIX.1
reserves the _t suffix for the implementation.  At the very least the
code should use a properly prefixed type instead, which this patch does
by changing the code to use caf_shmem_lock_t instead.

Bootstrapped without regressions on i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.

Ok for trunk?

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2026-05-14  Rainer Orth  <[email protected]>

        libgfortran:
        * caf/shmem/sync.h (lock_t): Rename to caf_shmem_lock_t.
        * caf/shmem.c: Adapt uses.

# HG changeset patch
# Parent  98529dae212c7f9ba3b576186504620b82e63d3c
libgfortran: Fix libcaf_shmem build on Solaris

diff --git a/libgfortran/caf/shmem.c b/libgfortran/caf/shmem.c
--- a/libgfortran/caf/shmem.c
+++ b/libgfortran/caf/shmem.c
@@ -273,7 +273,7 @@ _gfortran_caf_register (size_t size, caf
     case CAF_REGTYPE_LOCK_ALLOC:
     case CAF_REGTYPE_CRITICAL:
       {
-	lock_t *addr;
+	caf_shmem_lock_t *addr;
 	bool created;
 	size_t alloc_size;
 
@@ -286,7 +286,7 @@ _gfortran_caf_register (size_t size, caf
 	alloc_size = size;
 #endif
 	addr = alloc_get_memory_by_id_created (&local->ai,
-					       alloc_size * sizeof (lock_t),
+					       alloc_size * sizeof (caf_shmem_lock_t),
 					       next_memid, &created);
 
 	if (created)
@@ -296,7 +296,7 @@ _gfortran_caf_register (size_t size, caf
 	    for (size_t c = 0; c < alloc_size; ++c)
 	      initialize_shared_errorcheck_mutex (&addr[c]);
 	  }
-	size *= sizeof (lock_t);
+	size *= sizeof (caf_shmem_lock_t);
 
 	allocator_unlock (&local->ai.alloc);
 	mem = addr;
@@ -1503,7 +1503,7 @@ _gfortran_caf_lock (caf_token_t token, s
   const size_t lock_index = index;
   (void) image_index; // Prevent unused warnings.
 #endif
-  lock_t *lock = &((lock_t *) MEMTOK (token))[lock_index];
+  caf_shmem_lock_t *lock = &((caf_shmem_lock_t *) MEMTOK (token))[lock_index];
   int res;
 
   res = acquired_lock ? caf_shmem_mutex_trylock (lock)
@@ -1547,7 +1547,7 @@ _gfortran_caf_unlock (caf_token_t token,
   const size_t lock_index = index;
   (void) image_index; // Prevent unused warnings.
 #endif
-  lock_t *lock = &((lock_t *) MEMTOK (token))[lock_index];
+  caf_shmem_lock_t *lock = &((caf_shmem_lock_t *) MEMTOK (token))[lock_index];
   int res;
 
   res = caf_shmem_mutex_unlock (lock);
diff --git a/libgfortran/caf/shmem/sync.h b/libgfortran/caf/shmem/sync.h
--- a/libgfortran/caf/shmem/sync.h
+++ b/libgfortran/caf/shmem/sync.h
@@ -43,7 +43,7 @@ typedef struct {
   caf_shmem_condvar *triggers;
 } sync_t;
 
-typedef caf_shmem_mutex lock_t;
+typedef caf_shmem_mutex caf_shmem_lock_t;
 
 typedef int event_t;
 

Reply via email to