[kaffe] CVS kaffe (dalibor): Replaced ATOMIC_EXCHANGE with COMPARE_AND_SWAP from glibc on ARM

Kaffe CVS cvs-commits at kaffe.org
Thu Mar 11 08:54:02 PST 2004


PatchSet 4509 
Date: 2004/03/11 16:22:50
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Replaced ATOMIC_EXCHANGE with COMPARE_AND_SWAP from glibc on ARM

2004-03-11  Dalibor Topic <robilad at kaffe.org>

        * config/arm/common.h
        (COMPARE_AND_EXCHANGE) Call compare_and_swap inline function
        from atomicity.h.

        * config/arm/atomicity.h: New file from GNU libc.

        * THIRDPARTY: Updated.

Members: 
	ChangeLog:1.2088->1.2089 
	THIRDPARTY:1.8->1.9 
	config/arm/atomicity.h:INITIAL->1.1 
	config/arm/common.h:1.9->1.10 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2088 kaffe/ChangeLog:1.2089
--- kaffe/ChangeLog:1.2088	Thu Mar 11 16:00:05 2004
+++ kaffe/ChangeLog	Thu Mar 11 16:22:50 2004
@@ -1,3 +1,13 @@
+2004-03-11  Dalibor Topic <robilad at kaffe.org>
+
+	* config/arm/common.h
+        (COMPARE_AND_EXCHANGE) Call compare_and_swap inline function
+        from atomicity.h.
+
+        * config/arm/atomicity.h: New file from GNU libc.
+
+	* THIRDPARTY: Updated.
+
 2004-03-11  Jon Nall <nall at themountaingoats.net>
 
 	* kaffe/jvmpi/Makefile.am:
Index: kaffe/THIRDPARTY
diff -u kaffe/THIRDPARTY:1.8 kaffe/THIRDPARTY:1.9
--- kaffe/THIRDPARTY:1.8	Mon Jan 12 08:08:16 2004
+++ kaffe/THIRDPARTY	Thu Mar 11 16:22:51 2004
@@ -167,7 +167,7 @@
 
 At the time of writing, Kaffe uses getaddrinfo 1.6.1.
 
-* M68k atomic compare_and_swap
+* M68k and ARM atomic compare_and_swap
 
 Taken from GNU libc 2.3.2, which is licensed under the GNU Lesser General 
 Public License. See file license-lesser.terms for details.
===================================================================
Checking out kaffe/config/arm/atomicity.h
RCS:  /home/cvs/kaffe/kaffe/config/arm/atomicity.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/config/arm/atomicity.h	Thu Mar 11 16:25:36 2004
@@ -0,0 +1,46 @@
+/* Low-level functions for atomic operations.  ARM version.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _ATOMICITY_H
+#define _ATOMICITY_H    1
+
+static inline int
+__attribute__ ((unused))
+compare_and_swap (volatile long int *p, long int oldval, long int newval)
+{
+  int result, tmp;
+  __asm__ ("\n"
+           "0:\tldr\t%1,[%2]\n\t"
+           "mov\t%0,#0\n\t"
+           "cmp\t%1,%4\n\t"
+           "bne\t1f\n\t"
+           "swp\t%0,%3,[%2]\n\t"
+           "cmp\t%1,%0\n\t"
+           "swpne\t%1,%0,[%2]\n\t"
+           "bne\t0b\n\t"
+           "mov\t%0,#1\n"
+           "1:"
+           : "=&r" (result), "=&r" (tmp)
+           : "r" (p), "r" (newval), "r" (oldval)
+           : "cc", "memory");
+  return result;
+}
+
+#endif /* atomicity.h */
+
Index: kaffe/config/arm/common.h
diff -u kaffe/config/arm/common.h:1.9 kaffe/config/arm/common.h:1.10
--- kaffe/config/arm/common.h:1.9	Thu Dec 11 16:43:33 2003
+++ kaffe/config/arm/common.h	Thu Mar 11 16:22:51 2004
@@ -17,14 +17,18 @@
 #ifndef __arm_common_h
 #define __arm_common_h
 
+#include "atomicity.h"
+
 /* The arm never aligns to more than a 4 byte boundary. */
 #define	ALIGNMENT_OF_SIZE(S)	((S) < 4 ? (S) : 4)
 
 /*
- * Do an atomic exchange.  The contents of address 'A' is exchanged
- * with value 'N'.
+ * Do an atomic compare and exchange.  The address 'A' is checked against
+ * value 'O' and if they match it's exchanged with value 'N'.
+ * We return '1' if the exchange is successful, otherwise 0.
  */
-#define ATOMIC_EXCHANGE(A,N) \
-	asm volatile("swp       %0, %0, [%2]" : "=r" (N) : "0" (N), "r" (A) : "cc", "memory" );
+
+
+#define COMPARE_AND_EXCHANGE(A, O, N)  (compare_and_swap((long int*) A, (long int) O, (long int) N))
 
 #endif




More information about the kaffe mailing list