Blame include/util_mutex.h

Packit 90a5c9
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 90a5c9
 * contributor license agreements.  See the NOTICE file distributed with
Packit 90a5c9
 * this work for additional information regarding copyright ownership.
Packit 90a5c9
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 90a5c9
 * (the "License"); you may not use this file except in compliance with
Packit 90a5c9
 * the License.  You may obtain a copy of the License at
Packit 90a5c9
 *
Packit 90a5c9
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 90a5c9
 *
Packit 90a5c9
 * Unless required by applicable law or agreed to in writing, software
Packit 90a5c9
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 90a5c9
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 90a5c9
 * See the License for the specific language governing permissions and
Packit 90a5c9
 * limitations under the License.
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * @file  util_mutex.h
Packit 90a5c9
 * @brief Apache Mutex support library
Packit 90a5c9
 *
Packit 90a5c9
 * @defgroup APACHE_CORE_MUTEX Mutex Library
Packit 90a5c9
 * @ingroup  APACHE_CORE
Packit 90a5c9
 * @{
Packit 90a5c9
 */
Packit 90a5c9
Packit 90a5c9
#ifndef UTIL_MUTEX_H
Packit 90a5c9
#define UTIL_MUTEX_H
Packit 90a5c9
Packit 90a5c9
#include "httpd.h"
Packit 90a5c9
#include "http_config.h"
Packit 90a5c9
#include "apr_global_mutex.h"
Packit 90a5c9
Packit 90a5c9
#if APR_HAS_FLOCK_SERIALIZE
Packit 90a5c9
# define AP_LIST_FLOCK_SERIALIZE ", 'flock:/path/to/file'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_FLOCK_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_FCNTL_SERIALIZE
Packit 90a5c9
# define AP_LIST_FCNTL_SERIALIZE ", 'fcntl:/path/to/file'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_FCNTL_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_SYSVSEM_SERIALIZE
Packit 90a5c9
# define AP_LIST_SYSVSEM_SERIALIZE ", 'sysvsem'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_SYSVSEM_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_POSIXSEM_SERIALIZE
Packit 90a5c9
# define AP_LIST_POSIXSEM_SERIALIZE ", 'posixsem'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_POSIXSEM_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_PROC_PTHREAD_SERIALIZE
Packit 90a5c9
# define AP_LIST_PTHREAD_SERIALIZE ", 'pthread'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_PTHREAD_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE
Packit 90a5c9
# define AP_LIST_FILE_SERIALIZE ", 'file:/path/to/file'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_FILE_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
Packit 90a5c9
# define AP_LIST_SEM_SERIALIZE ", 'sem'"
Packit 90a5c9
#else
Packit 90a5c9
# define AP_LIST_SEM_SERIALIZE
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#define AP_ALL_AVAILABLE_MUTEXES_STRING                  \
Packit 90a5c9
    "Mutex mechanisms are: 'none', 'default'"            \
Packit 90a5c9
    AP_LIST_FLOCK_SERIALIZE   AP_LIST_FCNTL_SERIALIZE    \
Packit 90a5c9
    AP_LIST_FILE_SERIALIZE    AP_LIST_PTHREAD_SERIALIZE  \
Packit 90a5c9
    AP_LIST_SYSVSEM_SERIALIZE AP_LIST_POSIXSEM_SERIALIZE \
Packit 90a5c9
    AP_LIST_SEM_SERIALIZE
Packit 90a5c9
Packit 90a5c9
#define AP_AVAILABLE_MUTEXES_STRING                      \
Packit 90a5c9
    "Mutex mechanisms are: 'default'"                    \
Packit 90a5c9
    AP_LIST_FLOCK_SERIALIZE   AP_LIST_FCNTL_SERIALIZE    \
Packit 90a5c9
    AP_LIST_FILE_SERIALIZE    AP_LIST_PTHREAD_SERIALIZE  \
Packit 90a5c9
    AP_LIST_SYSVSEM_SERIALIZE AP_LIST_POSIXSEM_SERIALIZE \
Packit 90a5c9
    AP_LIST_SEM_SERIALIZE
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
extern "C" {
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Get Mutex config data and parse it
Packit 90a5c9
 * @param arg The mutex config string
Packit 90a5c9
 * @param pool The allocation pool
Packit 90a5c9
 * @param mutexmech The APR mutex locking mechanism
Packit 90a5c9
 * @param mutexfile The lockfile to use as required
Packit 90a5c9
 * @return APR status code
Packit 90a5c9
 * @fn apr_status_t ap_parse_mutex(const char *arg, apr_pool_t *pool,
Packit 90a5c9
                                        apr_lockmech_e *mutexmech,
Packit 90a5c9
                                        const char **mutexfile)
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool,
Packit 90a5c9
                                        apr_lockmech_e *mutexmech,
Packit 90a5c9
                                        const char **mutexfile);
Packit 90a5c9
Packit 90a5c9
/* private function to process the Mutex directive */
Packit 90a5c9
AP_DECLARE_NONSTD(const char *) ap_set_mutex(cmd_parms *cmd, void *dummy,
Packit 90a5c9
                                             const char *arg);
Packit 90a5c9
Packit 90a5c9
/* private function to initialize Mutex infrastructure */
Packit 90a5c9
AP_DECLARE_NONSTD(void) ap_mutex_init(apr_pool_t *p);
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * option flags for ap_mutex_register(), ap_global_mutex_create(), and
Packit 90a5c9
 * ap_proc_mutex_create()
Packit 90a5c9
 */
Packit 90a5c9
#define AP_MUTEX_ALLOW_NONE    1 /* allow "none" as mutex implementation;
Packit 90a5c9
                                  * respected only on ap_mutex_register()
Packit 90a5c9
                                  */
Packit 90a5c9
#define AP_MUTEX_DEFAULT_NONE  2 /* default to "none" for this mutex;
Packit 90a5c9
                                  * respected only on ap_mutex_register()
Packit 90a5c9
                                  */
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Register a module's mutex type with core to allow configuration
Packit 90a5c9
 * with the Mutex directive.  This must be called in the pre_config
Packit 90a5c9
 * hook; otherwise, configuration directives referencing this mutex
Packit 90a5c9
 * type will be rejected.
Packit 90a5c9
 *
Packit 90a5c9
 * The default_dir and default_mech parameters allow a module to set
Packit 90a5c9
 * defaults for the lock file directory and mechanism.  These could
Packit 90a5c9
 * be based on compile-time settings.  These aren't required except
Packit 90a5c9
 * in special circumstances.
Packit 90a5c9
 *
Packit 90a5c9
 * The order of precedence for the choice of mechanism and lock file
Packit 90a5c9
 * directory is:
Packit 90a5c9
 *
Packit 90a5c9
 *   1. Mutex directive specifically for this mutex
Packit 90a5c9
 *      e.g., Mutex mpm-default flock:/tmp/mpmlocks
Packit 90a5c9
 *   2. Mutex directive for global default
Packit 90a5c9
 *      e.g., Mutex default flock:/tmp/httpdlocks
Packit 90a5c9
 *   3. Defaults for this mutex provided on the ap_mutex_register()
Packit 90a5c9
 *   4. Built-in defaults for all mutexes, which are
Packit 90a5c9
 *      APR_LOCK_DEFAULT and DEFAULT_REL_RUNTIMEDIR.
Packit 90a5c9
 *
Packit 90a5c9
 * @param pconf The pconf pool
Packit 90a5c9
 * @param type The type name of the mutex, used as the basename of the
Packit 90a5c9
 * file associated with the mutex, if any.  This must be unique among
Packit 90a5c9
 * all mutex types (mutex creation accommodates multi-instance mutex
Packit 90a5c9
 * types); mod_foo might have mutex  types "foo-pipe" and "foo-shm"
Packit 90a5c9
 * @param default_dir Default dir for any lock file required for this
Packit 90a5c9
 * lock, to override built-in defaults; should be NULL for most
Packit 90a5c9
 * modules, to respect built-in defaults
Packit 90a5c9
 * @param default_mech Default mechanism for this lock, to override
Packit 90a5c9
 * built-in defaults; should be APR_LOCK_DEFAULT for most modules, to
Packit 90a5c9
 * respect built-in defaults
Packit 90a5c9
 * or NULL if there are no defaults for this mutex.
Packit 90a5c9
 * @param options combination of AP_MUTEX_* constants, or 0 for defaults
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_mutex_register(apr_pool_t *pconf,
Packit 90a5c9
                                           const char *type,
Packit 90a5c9
                                           const char *default_dir,
Packit 90a5c9
                                           apr_lockmech_e default_mech,
Packit 90a5c9
                                           apr_int32_t options);
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Create an APR global mutex that has been registered previously with
Packit 90a5c9
 * ap_mutex_register().  Mutex files, permissions, and error logging will
Packit 90a5c9
 * be handled internally.
Packit 90a5c9
 * @param mutex The memory address where the newly created mutex will be
Packit 90a5c9
 * stored.  If this mutex is disabled, mutex will be set to NULL on
Packit 90a5c9
 * output.  (That is allowed only if the AP_MUTEX_ALLOW_NONE flag is
Packit 90a5c9
 * passed to ap_mutex_register().)
Packit 90a5c9
 * @param name The generated filename of the created mutex, or NULL if
Packit 90a5c9
 * no file was created.  Pass NULL if this result is not needed.
Packit 90a5c9
 * @param type The type name of the mutex, matching the type name passed
Packit 90a5c9
 * to ap_mutex_register().
Packit 90a5c9
 * @param instance_id A unique string to be used in the lock filename IFF
Packit 90a5c9
 * this mutex type is multi-instance, NULL otherwise.
Packit 90a5c9
 * @param server server_rec of main server
Packit 90a5c9
 * @param pool pool lifetime of the mutex
Packit 90a5c9
 * @param options combination of AP_MUTEX_* constants, or 0 for defaults
Packit 90a5c9
 * (currently none are defined for this function)
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_global_mutex_create(apr_global_mutex_t **mutex,
Packit 90a5c9
                                                const char **name,
Packit 90a5c9
                                                const char *type,
Packit 90a5c9
                                                const char *instance_id,
Packit 90a5c9
                                                server_rec *server,
Packit 90a5c9
                                                apr_pool_t *pool,
Packit 90a5c9
                                                apr_int32_t options);
Packit 90a5c9
Packit 90a5c9
/**
Packit 90a5c9
 * Create an APR proc mutex that has been registered previously with
Packit 90a5c9
 * ap_mutex_register().  Mutex files, permissions, and error logging will
Packit 90a5c9
 * be handled internally.
Packit 90a5c9
 * @param mutex The memory address where the newly created mutex will be
Packit 90a5c9
 * stored.  If this mutex is disabled, mutex will be set to NULL on
Packit 90a5c9
 * output.  (That is allowed only if the AP_MUTEX_ALLOW_NONE flag is
Packit 90a5c9
 * passed to ap_mutex_register().)
Packit 90a5c9
 * @param name The generated filename of the created mutex, or NULL if
Packit 90a5c9
 * no file was created.  Pass NULL if this result is not needed.
Packit 90a5c9
 * @param type The type name of the mutex, matching the type name passed
Packit 90a5c9
 * to ap_mutex_register().
Packit 90a5c9
 * @param instance_id A unique string to be used in the lock filename IFF
Packit 90a5c9
 * this mutex type is multi-instance, NULL otherwise.
Packit 90a5c9
 * @param server server_rec of main server
Packit 90a5c9
 * @param pool pool lifetime of the mutex
Packit 90a5c9
 * @param options combination of AP_MUTEX_* constants, or 0 for defaults
Packit 90a5c9
 * (currently none are defined for this function)
Packit 90a5c9
 */
Packit 90a5c9
AP_DECLARE(apr_status_t) ap_proc_mutex_create(apr_proc_mutex_t **mutex,
Packit 90a5c9
                                              const char **name,
Packit 90a5c9
                                              const char *type,
Packit 90a5c9
                                              const char *instance_id,
Packit 90a5c9
                                              server_rec *server,
Packit 90a5c9
                                              apr_pool_t *pool,
Packit 90a5c9
                                              apr_int32_t options);
Packit 90a5c9
Packit 90a5c9
AP_CORE_DECLARE(void) ap_dump_mutexes(apr_pool_t *p, server_rec *s, apr_file_t *out);
Packit 90a5c9
Packit 90a5c9
#ifdef __cplusplus
Packit 90a5c9
}
Packit 90a5c9
#endif
Packit 90a5c9
Packit 90a5c9
#endif /* UTIL_MUTEX_H */
Packit 90a5c9
/** @} */