[newlib-cygwin/main] Cygwin: testsuite: Fix compilation for arm64

Jon Turney via Cygwin-cvs <[email protected]>
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6c5537c0298e9135ff27119c6a18dcc6f94459f5

commit 6c5537c0298e9135ff27119c6a18dcc6f94459f5
Author: Thirumalai Nagalingam <thirumalai.nagalingam-ftNtnR/FhrXEC4y91aVriVaTQe2KTcn/@public.gmane.org>
Date:   Fri Mar 28 16:51:05 2025 +0000

    Cygwin: testsuite: Fix compilation for arm64
    
    Introduce a cpu_relax.h header to provide architecture-specific
    processor idling instructions for the`cancel3` and `cancel5` tests.

Diff:
---
 winsup/testsuite/winsup.api/pthread/cancel3.c   |  3 ++-
 winsup/testsuite/winsup.api/pthread/cancel5.c   | 15 ++++++++-------
 winsup/testsuite/winsup.api/pthread/cpu_relax.h | 12 ++++++++++++
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/winsup/testsuite/winsup.api/pthread/cancel3.c b/winsup/testsuite/winsup.api/pthread/cancel3.c
index 8ed7d529b..18caf2360 100644
--- a/winsup/testsuite/winsup.api/pthread/cancel3.c
+++ b/winsup/testsuite/winsup.api/pthread/cancel3.c
@@ -40,6 +40,7 @@
  */
 
 #include "test.h"
+#include "cpu_relax.h"
 
 /*
  * Create NUMTHREADS threads in addition to the Main thread.
@@ -88,7 +89,7 @@ mythread(void * arg)
 	{
 	  int i;
 	  for (i = 0; i < 1E7; i++)
-	    __asm__ volatile ("pause":::);
+	    CPU_RELAX();
 	}
     }
 
diff --git a/winsup/testsuite/winsup.api/pthread/cancel5.c b/winsup/testsuite/winsup.api/pthread/cancel5.c
index dd5be7bea..05b8ef9a3 100644
--- a/winsup/testsuite/winsup.api/pthread/cancel5.c
+++ b/winsup/testsuite/winsup.api/pthread/cancel5.c
@@ -38,12 +38,13 @@
  *
  * Fail Criteria:
  * - Process returns non-zero exit status.
- */
-
-#include "test.h"
-
-/*
- * Create NUMTHREADS threads in addition to the Main thread.
+ */
+
+#include "test.h"
+#include "cpu_relax.h"
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
  */
 enum {
   NUMTHREADS = 10
@@ -89,7 +90,7 @@ mythread(void * arg)
 	{
 	  int i;
 	  for (i = 0; i < 1E7; i++)
-	    __asm__ volatile ("pause":::);
+	    CPU_RELAX();
 	}
     }
 
diff --git a/winsup/testsuite/winsup.api/pthread/cpu_relax.h b/winsup/testsuite/winsup.api/pthread/cpu_relax.h
new file mode 100644
index 000000000..1936dc5f4
--- /dev/null
+++ b/winsup/testsuite/winsup.api/pthread/cpu_relax.h
@@ -0,0 +1,12 @@
+#ifndef CPU_RELAX_H
+#define CPU_RELAX_H
+
+#if defined(__x86_64__) || defined(__i386__)  // Check for x86 architectures
+   #define CPU_RELAX() __asm__ volatile ("pause" :::)
+#elif defined(__aarch64__) || defined(__arm__)  // Check for ARM architectures
+   #define CPU_RELAX() __asm__ volatile ("yield" :::)
+#else
+   #error unimplemented for this target
+#endif
+
+#endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.