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: /** Lock
021: *
022: * @author Mladen Turk
023: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
024: */
025:
026: public class Lock {
027:
028: /**
029: * Enumerated potential types for APR process locking methods
030: * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
031: * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
032: */
033:
034: public static final int APR_LOCK_FCNTL = 0;
035: /** fcntl() */
036: public static final int APR_LOCK_FLOCK = 1;
037: /** flock() */
038: public static final int APR_LOCK_SYSVSEM = 2;
039: /** System V Semaphores */
040: public static final int APR_LOCK_PROC_PTHREAD = 3;
041: /** POSIX pthread process-based locking */
042: public static final int APR_LOCK_POSIXSEM = 4;
043: /** POSIX semaphore process-based locking */
044: public static final int APR_LOCK_DEFAULT = 5;
045:
046: /** Use the default process lock */
047:
048: /**
049: * Create and initialize a mutex that can be used to synchronize processes.
050: * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
051: * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
052: * @param fname A file name to use if the lock mechanism requires one. This
053: * argument should always be provided. The lock code itself will
054: * determine if it should be used.
055: * @param mech The mechanism to use for the interprocess lock, if any; one of
056: * <PRE>
057: * APR_LOCK_FCNTL
058: * APR_LOCK_FLOCK
059: * APR_LOCK_SYSVSEM
060: * APR_LOCK_POSIXSEM
061: * APR_LOCK_PROC_PTHREAD
062: * APR_LOCK_DEFAULT pick the default mechanism for the platform
063: * </PRE>
064: * @param pool the pool from which to allocate the mutex.
065: * @return Newly created mutex.
066: */
067: public static native long create(String fname, int mech, long pool)
068: throws Error;
069:
070: /**
071: * Re-open a mutex in a child process.
072: * This function must be called to maintain portability, even
073: * if the underlying lock mechanism does not require it.
074: * @param fname A file name to use if the mutex mechanism requires one. This
075: * argument should always be provided. The mutex code itself will
076: * determine if it should be used. This filename should be the
077: * same one that was passed to apr_proc_mutex_create().
078: * @param pool The pool to operate on.
079: * @return Newly opened mutex.
080: */
081: public static native long childInit(String fname, long pool)
082: throws Error;
083:
084: /**
085: * Acquire the lock for the given mutex. If the mutex is already locked,
086: * the current thread will be put to sleep until the lock becomes available.
087: * @param mutex the mutex on which to acquire the lock.
088: */
089: public static native int lock(long mutex);
090:
091: /**
092: * Attempt to acquire the lock for the given mutex. If the mutex has already
093: * been acquired, the call returns immediately with APR_EBUSY. Note: it
094: * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
095: * if the return value was APR_EBUSY, for portability reasons.
096: * @param mutex the mutex on which to attempt the lock acquiring.
097: */
098: public static native int trylock(long mutex);
099:
100: /**
101: * Release the lock for the given mutex.
102: * @param mutex the mutex from which to release the lock.
103: */
104: public static native int unlock(long mutex);
105:
106: /**
107: * Destroy the mutex and free the memory associated with the lock.
108: * @param mutex the mutex to destroy.
109: */
110: public static native int destroy(long mutex);
111:
112: /**
113: * Return the name of the lockfile for the mutex, or NULL
114: * if the mutex doesn't use a lock file
115: */
116: public static native String lockfile(long mutex);
117:
118: /**
119: * Display the name of the mutex, as it relates to the actual method used.
120: * This matches the valid options for Apache's AcceptMutex directive
121: * @param mutex the name of the mutex
122: */
123: public static native String name(long mutex);
124:
125: /**
126: * Display the name of the default mutex: APR_LOCK_DEFAULT
127: */
128: public static native String defname();
129:
130: }
|