001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.tomcat.jni;
019:
020: import java.nio.ByteBuffer;
021:
022: /** Shm
023: *
024: * @author Mladen Turk
025: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
026: */
027:
028: public class Shm {
029:
030: /**
031: * Create and make accessable a shared memory segment.
032: * <br />
033: * A note about Anonymous vs. Named shared memory segments:<br />
034: * Not all plaforms support anonymous shared memory segments, but in
035: * some cases it is prefered over other types of shared memory
036: * implementations. Passing a NULL 'file' parameter to this function
037: * will cause the subsystem to use anonymous shared memory segments.
038: * If such a system is not available, APR_ENOTIMPL is returned.
039: * <br />
040: * A note about allocation sizes:<br />
041: * On some platforms it is necessary to store some metainformation
042: * about the segment within the actual segment. In order to supply
043: * the caller with the requested size it may be necessary for the
044: * implementation to request a slightly greater segment length
045: * from the subsystem. In all cases, the apr_shm_baseaddr_get()
046: * function will return the first usable byte of memory.
047: * @param reqsize The desired size of the segment.
048: * @param filename The file to use for shared memory on platforms that
049: * require it.
050: * @param pool the pool from which to allocate the shared memory
051: * structure.
052: * @return The created shared memory structure.
053: *
054: */
055: public static native long create(long reqsize, String filename,
056: long pool) throws Error;
057:
058: /**
059: * Remove shared memory segment associated with a filename.
060: * <br />
061: * This function is only supported on platforms which support
062: * name-based shared memory segments, and will return APR_ENOTIMPL on
063: * platforms without such support.
064: * @param filename The filename associated with shared-memory segment which
065: * needs to be removed
066: * @param pool The pool used for file operations
067: */
068: public static native int remove(String filename, long pool);
069:
070: /**
071: * Destroy a shared memory segment and associated memory.
072: * @param m The shared memory segment structure to destroy.
073: */
074: public static native int destroy(long m);
075:
076: /**
077: * Attach to a shared memory segment that was created
078: * by another process.
079: * @param filename The file used to create the original segment.
080: * (This MUST match the original filename.)
081: * @param pool the pool from which to allocate the shared memory
082: * structure for this process.
083: * @return The created shared memory structure.
084: */
085: public static native long attach(String filename, long pool)
086: throws Error;
087:
088: /**
089: * Detach from a shared memory segment without destroying it.
090: * @param m The shared memory structure representing the segment
091: * to detach from.
092: */
093: public static native int detach(long m);
094:
095: /**
096: * Retrieve the base address of the shared memory segment.
097: * NOTE: This address is only usable within the callers address
098: * space, since this API does not guarantee that other attaching
099: * processes will maintain the same address mapping.
100: * @param m The shared memory segment from which to retrieve
101: * the base address.
102: * @return address, aligned by APR_ALIGN_DEFAULT.
103: */
104: public static native long baseaddr(long m);
105:
106: /**
107: * Retrieve the length of a shared memory segment in bytes.
108: * @param m The shared memory segment from which to retrieve
109: * the segment length.
110: */
111: public static native long size(long m);
112:
113: /**
114: * Retrieve new ByteBuffer base address of the shared memory segment.
115: * NOTE: This address is only usable within the callers address
116: * space, since this API does not guarantee that other attaching
117: * processes will maintain the same address mapping.
118: * @param m The shared memory segment from which to retrieve
119: * the base address.
120: * @return address, aligned by APR_ALIGN_DEFAULT.
121: */
122: public static native ByteBuffer buffer(long m);
123:
124: }
|