commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r825927 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ native/ native/include/ native/os/darwin/ native/os/hpux/ native/os/linux/ native/os/solaris/ native/os/win32/
Date Fri, 16 Oct 2009 15:14:13 GMT
Author: mturk
Date: Fri Oct 16 15:14:10 2009
New Revision: 825927

URL: http://svn.apache.org/viewvc?rev=825927&view=rev
Log:
Add native atomics

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/configure

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java?rev=825927&r1=825926&r2=825927&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
Fri Oct 16 15:14:10 2009
@@ -93,13 +93,13 @@
      * <p>
      * FileInstance returned can be used by applications that need to
      * read from or write to the console. If the standard handle is redirected
-     * the returned {@code FileInstance} is pointer to that redirected file.
+     * the returned {@code FileStream} is pointer to that redirected file.
      * </p>
      * <p>
      * If the application doesn't have standard handles (e.g. daemon applicaton)
-     * and the handles are not redirected, the returned {@code FileInstance}
+     * and the handles are not redirected, the returned {@code FileStream}
      * contains invalid file {@code Descriptor}. Any further operation on such
-     * {@code FileInstance} will fail with {@link ClosedDescriptorException}.
+     * {@code FileStream} will fail with {@link ClosedDescriptorException}.
      * </p>
      * <p>
      * Parameter {@code which} determines which one of the stadard streams to
@@ -112,7 +112,7 @@
      * </pre>
      * @param which standard stream to open.
      *
-     * @return new {@code FileInstance} connected to standard stream.
+     * @return new {@code FileStream} connected to standard stream.
      *
      */
     public static FileStream createStdStream(int which,
@@ -127,11 +127,11 @@
     }
 
     /**
-     * Create new temporary file inide {@code path}.
+     * Create new temporary file inside {@code directory}.
      *
      * @param prefix temporary file prefix.
      *
-     * @return new temporary {@code FileInstance}.
+     * @return new temporary file {@code Descriptor}.
      */
     public static Descriptor createTemp(String prefix, String suffix,
                                         File directory, boolean preserve)
@@ -148,7 +148,7 @@
      *
      * @param prefix file prefix.
      *
-     * @return new temporary {@code FileInstance}.
+     * @return new temporary file {@code Descriptor}.
      */
     public static Descriptor createTemp(String prefix, String suffix,
                                         boolean preserve)

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=825927&r1=825926&r2=825927&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Fri Oct 16 15:14:10 2009
@@ -140,6 +140,7 @@
 	$(SRCDIR)/os/unix/time.$(OBJ) \
 	$(SRCDIR)/os/unix/uuid.$(OBJ) \
 	$(SRCDIR)/os/unix/uutils.$(OBJ) \
+	$(SRCDIR)/os/linux/atomics.$(OBJ) \
 	$(SRCDIR)/os/linux/cpu.$(OBJ) \
 	$(SRCDIR)/os/linux/env.$(OBJ) \
 	$(SRCDIR)/os/linux/execmem.$(OBJ) \
@@ -175,6 +176,7 @@
 	$(SRCDIR)/os/unix/time.$(OBJ) \
 	$(SRCDIR)/os/unix/uuid.$(OBJ) \
 	$(SRCDIR)/os/unix/uutils.$(OBJ) \
+	$(SRCDIR)/os/solaris/atomics.$(OBJ) \
 	$(SRCDIR)/os/solaris/cpu.$(OBJ) \
 	$(SRCDIR)/os/solaris/env.$(OBJ) \
 	$(SRCDIR)/os/solaris/module.$(OBJ) \
@@ -207,6 +209,7 @@
 	$(SRCDIR)/os/unix/time.$(OBJ) \
 	$(SRCDIR)/os/unix/uuid.$(OBJ) \
 	$(SRCDIR)/os/unix/uutils.$(OBJ) \
+	$(SRCDIR)/os/darwin/atomics.$(OBJ) \
 	$(SRCDIR)/os/darwin/cpu.$(OBJ) \
 	$(SRCDIR)/os/darwin/env.$(OBJ) \
 	$(SRCDIR)/os/darwin/platform.$(OBJ) \
@@ -240,6 +243,7 @@
 	$(SRCDIR)/os/unix/time.$(OBJ) \
 	$(SRCDIR)/os/unix/uuid.$(OBJ) \
 	$(SRCDIR)/os/unix/uutils.$(OBJ) \
+	$(SRCDIR)/os/hpux/atomics.$(OBJ) \
 	$(SRCDIR)/os/hpux/cpu.$(OBJ) \
 	$(SRCDIR)/os/hpux/env.$(OBJ) \
 	$(SRCDIR)/os/hpux/group.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=825927&r1=825926&r2=825927&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Oct 16 15:14:10 2009
@@ -106,6 +106,7 @@
 	$(SRCDIR)/shared/version.$(OBJ)
 
 WINDOWS_OBJS= \
+	$(SRCDIR)/os/win32/atomics.$(OBJ) \
 	$(SRCDIR)/os/win32/cpu.$(OBJ) \
 	$(SRCDIR)/os/win32/dhtml.$(OBJ) \
 	$(SRCDIR)/os/win32/dir.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=825927&r1=825926&r2=825927&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Fri Oct 16 15:14:10 2009
@@ -533,7 +533,7 @@
         cc_ver_major=${v[0]}
         cc_ver_minor=${v[1]}
         if [ ".$has_maintainer_mode" != .yes ]; then
-            varadds ccflags -fno-stack-protector
+            varadds cppopts -fno-stack-protector
         fi
     ;;
     windows-cl )
@@ -942,6 +942,12 @@
     have_openssl=0
 fi
 
+if [ ".$cc" = .gcc ]; then
+    if [ ${cc_ver_major}${cc_ver_minor}0 -gt 410 ]; then
+        varadds cppopts -DUSE_ATOMICS_BUILTINS
+    fi
+fi
+
 # Generate configuration header file
 #
 cat > $topdir/include/acr_config.h << EOF

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h Fri Oct 16 15:14:10
2009
@@ -0,0 +1,68 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_ATOMICS_H
+#define _ACR_ATOMICS_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_atomics.h
+ * @brief
+ *
+ * ACR atomic functions
+ *
+ */
+
+#if defined(WIN32)
+typedef volatile long           acr_atomic32_t;
+#else
+typedef volatile acr_uint32_t   acr_atomic32_t;
+#endif
+
+/**
+ * atomically add 'val' to an acr_atomic32_t
+ * @param mem pointer to the object
+ * @param val amount to add
+ * @return old value pointed to by mem
+ */
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val);
+
+/**
+ * atomically increment an acr_uint32_t by 1
+ * @param mem pointer to the object
+ * @return old value pointed to by mem
+ */
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem);
+
+/**
+ * atomically decrement an acr_uint32_t by 1
+ * @param mem pointer to the atomic value
+ * @return zero if the value becomes zero on decrement, otherwise non-zero
+ */
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_ATOMICS_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_atomics.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c Fri Oct 16 15:14:10
2009
@@ -0,0 +1,73 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_atomics.h"
+
+#if defined(USE_ATOMICS_BUILTINS)
+/* Use GCC builtin atomics
+ */
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val)
+{
+    return __sync_fetch_and_add(mem, val);
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return __sync_fetch_and_add(mem, 1);
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    return __sync_sub_and_fetch(mem, 1);
+}
+
+#else
+#if defined(__ppc__)
+
+#else
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val)
+{
+    asm volatile ("lock; xaddl %0,%1"
+                  : "=r" (val), "=m" (*mem)
+                  : "0" (val), "m" (*mem)
+                  : "memory", "cc");
+    return val;
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return ACR_AtomicAdd32(mem, 1);
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    unsigned char prev;
+
+    asm volatile ("lock; decl %0; setnz %1"
+                  : "=m" (*mem), "=qm" (prev)
+                  : "m" (*mem)
+                  : "memory");
+
+    return prev;
+}
+
+#endif
+#endif

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/darwin/atomics.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c Fri Oct 16 15:14:10 2009
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+
+/* TODO: Implementation
+ */
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val)
+{
+    *mem += val;
+    return *mem;
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return *mem++;
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    return *mem--;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/hpux/atomics.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c Fri Oct 16 15:14:10 2009
@@ -0,0 +1,74 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_atomics.h"
+
+#if defined(USE_ATOMICS_BUILTINS)
+/* Use GCC builtin atomics
+ */
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val)
+{
+    return __sync_fetch_and_add(mem, val);
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return __sync_fetch_and_add(mem, 1);
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    return __sync_sub_and_fetch(mem, 1);
+}
+
+#else
+#if defined(__ppc__)
+
+#else
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem, acr_uint32_t val)
+{
+    asm volatile ("lock; xaddl %0,%1"
+                  : "=r" (val), "=m" (*mem)
+                  : "0" (val), "m" (*mem)
+                  : "memory", "cc");
+    return val;
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return ACR_AtomicAdd32(mem, 1);
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    unsigned char prev;
+
+    asm volatile ("lock; decl %0; setnz %1"
+                  : "=m" (*mem), "=qm" (prev)
+                  : "m" (*mem)
+                  : "memory");
+
+    return prev;
+}
+
+#endif
+#endif
+

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/linux/atomics.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c Fri Oct 16 15:14:10
2009
@@ -0,0 +1,37 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_atomics.h"
+
+#include <atomic.h>
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val)
+{
+    return atomic_add_32_nv(mem, val) - val;
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return atomic_inc_32_nv(mem) - 1;
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    return atomic_dec_32_nv(mem);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/solaris/atomics.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c?rev=825927&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c Fri Oct 16 15:14:10 2009
@@ -0,0 +1,35 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicAdd32(acr_atomic32_t *mem,
+                                          acr_uint32_t val)
+{
+    return InterlockedExchangeAdd(mem, val);
+}
+
+ACR_DECLARE(acr_uint32_t) ACR_AtomicInc32(acr_atomic32_t *mem)
+{
+    return InterlockedIncrement(mem) - 1;
+}
+
+ACR_DECLARE(int) ACR_AtomicDec32(acr_atomic32_t *mem)
+{
+    return InterlockedDecrement(mem);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/atomics.c
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message