You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/20 06:58:54 UTC
svn commit: r1095269 - in /commons/sandbox/runtime/trunk: ./
src/main/java/org/apache/commons/runtime/
src/main/java/org/apache/commons/runtime/platform/unix/
src/main/native/os/unix/ src/main/test/org/apache/commons/runtime/
Author: mturk
Date: Wed Apr 20 04:58:54 2011
New Revision: 1095269
URL: http://svn.apache.org/viewvc?rev=1095269&view=rev
Log:
Implement posix shared memory
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java (with props)
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java (with props)
Modified:
commons/sandbox/runtime/trunk/build.xml
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java
commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=1095269&r1=1095268&r2=1095269&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Wed Apr 20 04:58:54 2011
@@ -419,6 +419,17 @@ The Apache Software Foundation (http://w
</sequential>
</parallel>
</target>
+ <target name="testshmem" depends="tests">
+ <parallel>
+ <sequential>
+ <runtest groups="init,shmem.parent" name="shmem.parent"/>
+ </sequential>
+ <sequential>
+ <sleep milliseconds="100" />
+ <runtest groups="init,shmem.child" name="shmem.child"/>
+ </sequential>
+ </parallel>
+ </target>
<!-- =================================================================== -->
<!-- Run Example -->
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties?rev=1095269&r1=1095268&r2=1095269&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/LocalStrings.properties Wed Apr 20 04:58:54 2011
@@ -16,4 +16,6 @@
os.ENOTIMPL=Apache Commons Runtime does not support this operating system
os.EVERSION=Apache Commons Runtime does not support this operating system version
mutextype.EINVAL=Invalid MutexType enum initializer ({0})
+mutex.ENOTIMPL=Apache Commons Runtime does not support mutexes on this platform
+sharedmem.ENOTIMPL=Apache Commons Runtime does not support shared memory on this platform
semaphore.ENOTIMPL=Apache Commons Runtime does not support semaphores on this platform
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java?rev=1095269&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java Wed Apr 20 04:58:54 2011
@@ -0,0 +1,131 @@
+/* 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.
+ */
+package org.apache.commons.runtime;
+
+/**
+ * Shm class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public abstract class Shm
+{
+
+ protected Shm()
+ {
+ // No Instance
+ }
+
+ private static final ShmImpl impl;
+
+ static {
+ impl = ShmImpl.get();
+ }
+
+ protected String name;
+ protected boolean owner;
+ protected long size;
+
+ public static Shm create(String name, long size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ AlreadyExistsException,
+ UnsupportedOperationException,
+ SystemException
+ {
+ if (impl == null)
+ throw new UnsupportedOperationException(Local.sm.get("sharedmem.ENOTIMPL"));
+ return impl.create(name, size);
+ }
+
+ public static Shm open(String name)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ NoSuchObjectException,
+ UnsupportedOperationException,
+ SystemException
+ {
+ if (impl == null)
+ throw new UnsupportedOperationException(Local.sm.get("sharedmem.ENOTIMPL"));
+ return impl.open(name);
+ }
+
+ /**
+ * Attaches the shared memory segment to the address
+ * space of the calling process.
+ * If {@code address} is NULL, the system chooses a
+ * suitable (unused) address at which to attach the segment.
+ */
+ public abstract Pointer attach(long address, boolean readOnly)
+ throws SystemException;
+
+ /**
+ * Attaches the shared memory segment to the address
+ * space of the calling process.
+ * If {@code address} is NULL, the system chooses a
+ * suitable (unused) address at which to attach the segment.
+ */
+ public Pointer attach(boolean readOnly)
+ throws SystemException
+ {
+ return attach(0L, readOnly);
+ }
+
+ /**
+ * Detaches the shared memory segment located at the address
+ * specified by {@code address} from the address space ofthe
+ * calling process.
+ * The to-be-detached segment must be currently attached with
+ * {@code address} equal to the value returned by the attaching
+ * attach() call.
+ */
+ public abstract void detach(Pointer addr)
+ throws SystemException;
+
+ /**
+ * Returns the shared memory size.
+ *
+ */
+ public long size()
+ {
+ return size;
+ }
+
+ /**
+ * Closes the sharedmem.
+ *
+ */
+ public abstract void close()
+ throws SystemException;
+
+ /**
+ * Get Shm name.
+ */
+ public String getCanonicalName()
+ {
+ return name;
+ }
+
+ /**
+ * Check if this is Shm owner.
+ */
+ public boolean isOwner()
+ {
+ return owner;
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Shm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java?rev=1095269&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java Wed Apr 20 04:58:54 2011
@@ -0,0 +1,62 @@
+/* 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.
+ */
+package org.apache.commons.runtime;
+
+/**
+ * ShmImpl class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public abstract class ShmImpl
+{
+ private static final ShmImpl impl;
+ private static native ShmImpl init0()
+ throws OutOfMemoryError;
+
+ static {
+ impl = init0();
+ }
+
+ protected ShmImpl()
+ {
+ // No Instance
+ }
+
+ public static final ShmImpl get()
+ throws UnsupportedOperationException
+ {
+ if (impl == null)
+ throw new UnsupportedOperationException(Local.sm.get("sharedmem.ENOTIMPL"));
+ return impl;
+ }
+
+
+ public abstract Shm create(String name, long size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ AlreadyExistsException,
+ SystemException;
+
+ public abstract Shm open(String name)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ NoSuchObjectException,
+ SystemException;
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ShmImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java?rev=1095269&r1=1095268&r2=1095269&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java Wed Apr 20 04:58:54 2011
@@ -24,9 +24,6 @@ package org.apache.commons.runtime;
final class SlicePointer extends Pointer
{
- private static native void free0(long p)
- throws Throwable;
-
private SlicePointer()
{
// No instance
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java?rev=1095269&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java Wed Apr 20 04:58:54 2011
@@ -0,0 +1,148 @@
+/* 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.
+ */
+package org.apache.commons.runtime.platform.unix;
+
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.Shm;
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.AlreadyExistsException;
+import org.apache.commons.runtime.NoSuchObjectException;
+import org.apache.commons.runtime.ClosedDescriptorException;
+import org.apache.commons.runtime.SystemException;
+
+/**
+ * PosixShm class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class PosixShm extends Shm
+{
+
+ private PosixShm()
+ {
+ // No Instance
+ }
+
+ private static native int create0(String name, long size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ AlreadyExistsException,
+ SystemException;
+ private static native int open0(String name, long[] size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ NoSuchObjectException,
+ SystemException;
+
+ private static native Pointer shmat0(long addr, long size, int fd, int flags);
+ private static native int shmdt0(long addr);
+ private static native int unlink0(int fd, String name);
+
+ private static final int RDONLY = 1;
+
+ // OS shmem descriptor
+ private int fd;
+ private Pointer base;
+
+ public PosixShm(final String name, long size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ AlreadyExistsException,
+ SystemException
+ {
+ if (name == null)
+ throw new NullPointerException();
+ this.name = name;
+ this.size = size;
+ fd = create0(this.name, this.size);
+ owner = true;
+ }
+
+ public PosixShm(final String name)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ NoSuchObjectException,
+ SystemException
+ {
+ if (name == null)
+ throw new NullPointerException();
+ this.name = name;
+ long[] sa = new long[1];
+ fd = open0(this.name, sa);
+ this.size = sa[0];
+ owner = false;
+ }
+
+ public Pointer attach(long address, boolean readOnly)
+ throws SystemException
+ {
+ if (fd == -1)
+ throw new ClosedDescriptorException();
+ int flags = readOnly ? RDONLY : 0;
+ Pointer p = shmat0(address, size, fd, flags);
+ if (base == null)
+ base = p;
+ return p;
+ }
+
+ public void detach(Pointer addr)
+ throws SystemException
+ {
+ if (fd == -1)
+ throw new ClosedDescriptorException();
+ int rc = shmdt0(addr.address());
+ if (rc != 0)
+ throw new SystemException(Status.describe(rc));
+ if (addr.equals(base))
+ base = null;
+ }
+
+ public void close()
+ throws SystemException
+ {
+ int rc = 0;
+ if (fd == -1)
+ throw new ClosedDescriptorException();
+ if (base != null)
+ rc = shmdt0(base.address());
+ if (owner)
+ rc = unlink0(fd, name);
+ if (rc != 0)
+ throw new SystemException(Status.describe(rc));
+ fd = -1;
+ }
+
+ /**
+ * Called by the garbage collector when the object is destroyed.
+ * The class will free internal resources allocated by the Operating system.
+ * @see Object#finalize()
+ * @throws Throwable the {@code Exception} raised by this method.
+ */
+ @Override
+ protected final void finalize()
+ throws Throwable
+ {
+ if (fd != -1) {
+ if (base != null)
+ shmdt0(base.address());
+ if (owner)
+ unlink0(fd, name);
+ }
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShm.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java?rev=1095269&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java Wed Apr 20 04:58:54 2011
@@ -0,0 +1,58 @@
+/* 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.
+ */
+package org.apache.commons.runtime.platform.unix;
+
+import org.apache.commons.runtime.Shm;
+import org.apache.commons.runtime.ShmImpl;
+import org.apache.commons.runtime.AlreadyExistsException;
+import org.apache.commons.runtime.NoSuchObjectException;
+import org.apache.commons.runtime.SystemException;
+
+/**
+ * ShmImpl class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class PosixShmImpl extends ShmImpl
+{
+
+ public PosixShmImpl()
+ {
+ // No Instance
+ }
+
+ public Shm create(String name, long size)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ AlreadyExistsException,
+ SystemException
+ {
+ return new PosixShm(name, size);
+ }
+
+ public Shm open(String name)
+ throws IllegalAccessException,
+ IllegalArgumentException,
+ NoSuchObjectException,
+ SystemException
+ {
+ return new PosixShm(name);
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixShmImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c?rev=1095269&r1=1095268&r2=1095269&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/shmem.c Wed Apr 20 04:58:54 2011
@@ -17,6 +17,7 @@
#include "acr/string.h"
#include "acr/clazz.h"
#include "acr/jniapi.h"
+#include "acr/pointer.h"
#include "acr/port.h"
#include "arch_opts.h"
@@ -113,7 +114,7 @@ cleanup:
return sd;
}
-ACR_UNX_EXPORT(jint, PosixShm, open0)(JNI_STDARGS, jstring name)
+ACR_UNX_EXPORT(jint, PosixShm, open0)(JNI_STDARGS, jstring name, jlongArray rs)
{
int sd = -1;
key_t skey;
@@ -140,7 +141,12 @@ ACR_UNX_EXPORT(jint, PosixShm, open0)(JN
/* Not created by us or corrupted */
ACR_THROW(ACR_EX_ESYS, EBADF);
goto cleanup;
- }
+ }
+ else {
+ jlong *pa = (*env)->GetPrimitiveArrayCritical(env, rs, 0);
+ *pa = hdr.length;
+ (*env)->ReleasePrimitiveArrayCritical(env, rs, pa, 0);
+ }
skey = ftok(J2S(name), 'a');
if (skey == (key_t)-1) {
ACR_THROW_BY_ERRNO();
@@ -158,52 +164,26 @@ cleanup:
return sd;
}
-ACR_UNX_EXPORT(jlong, PosixShm, ssize0)(JNI_STDARGS, jstring name)
-{
- jlong sz = 0;
-
- WITH_CSTR(name) {
- int fd = -1;
- shmblock_t hdr;
- ssize_t rd, nbytes;
-
- fd = open(J2S(name), O_RDONLY);
- if (fd == -1) {
- ACR_THROW_BY_ERRNO();
- goto cleanup;
- }
- nbytes = sizeof(shmblock_t);
-
- rd = r_read(fd, (void *)&hdr, nbytes);
- if (rd != nbytes) {
- /* Wrong format */
- ACR_THROW(ACR_EX_ESYS, EBADF);
- goto cleanup;
- }
- if (hdr.magic != ACR_SHM_MAGIC) {
- /* Not created by us or corrupted */
- ACR_THROW(ACR_EX_ESYS, EBADF);
- goto cleanup;
- }
- sz = (jlong)hdr.length;
-cleanup:
- if (fd != -1)
- close(fd);
- } DONE_WITH_STR(name);
-
- return sz;
-}
-
-ACR_UNX_EXPORT(jlong, PosixShm, shmat0)(JNI_STDARGS, jlong addr, jint fd, jint flags)
+ACR_UNX_EXPORT(jobject, PosixShm, shmat0)(JNI_STDARGS, jlong addr, jlong size,
+ jint fd, jint flags)
{
void *sa = J2P(addr, void *);
void *sm;
+ if (flags == 1)
+ flags = SHM_RDONLY;
if ((sm = shmat(fd, sa, flags)) == (void *)-1) {
ACR_SAVE_OS_ERROR();
sm = 0;
}
- return P2J(sm);
+ if (sm != 0) {
+ size_t len = (size_t)size;
+ if (flags)
+ return AcrNewConstPointer(env, sm, len);
+ else
+ return AcrNewSlicePointer(env, sm, len);
+ }
+ return 0;
}
ACR_UNX_EXPORT(jint, PosixShm, shmdt0)(JNI_STDARGS, jlong addr)
Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java?rev=1095269&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java Wed Apr 20 04:58:54 2011
@@ -0,0 +1,86 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime;
+
+import java.io.IOException;
+import java.io.File;
+import org.testng.annotations.*;
+import org.testng.Assert;
+
+public class TestShm extends Assert
+{
+
+ private static final String semname = "acrSemop23";
+ private static final String shmname = "acrShmem23";
+ private static final long shmsize = 65536;
+
+ @Test(groups = { "shmem.parent" })
+ public void createShm()
+ throws Exception
+ {
+ try {
+ Semaphore.remove(semname);
+ } catch (Exception x) {
+ // Ignore
+ }
+ Semaphore s = Semaphore.create(semname, 0);
+ assertNotNull(s);
+ Shm m = Shm.create(shmname, shmsize);
+ assertNotNull(m);
+ assertNotNull(m.attach(0, false));
+ System.out.println("[parent] Waiting for a child to attach");
+ System.out.flush();
+ s.acquire();
+ System.out.println("[parent] Child attached.");
+ System.out.flush();
+ m.close();
+ s.close();
+ System.out.println("[parent] Done.");
+ System.out.flush();
+ }
+
+ @Test(groups = { "shmem.child" })
+ public void openShm()
+ throws Exception
+ {
+ System.out.println("[child] Attaching child shared memory");
+ System.out.flush();
+ Semaphore s = null;
+ int step = 125;
+ while (step <= 2000) {
+ try {
+ s = Semaphore.open(semname);
+ break;
+ } catch (Exception x) {
+
+ }
+ Thread.sleep(step);
+ step *= 2;
+ }
+ assertNotNull(s);
+ Shm m = Shm.open(shmname);
+ assertNotNull(m);
+ assertEquals(m.size(), shmsize);
+ assertNotNull(m.attach(0, false));
+ m.close();
+ System.out.println("[child] Done.");
+ System.out.flush();
+ s.release();
+ s.close();
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestShm.java
------------------------------------------------------------------------------
svn:eol-style = native