~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/include/apr_global_mutex.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef APR_GLOBAL_MUTEX_H
 
18
#define APR_GLOBAL_MUTEX_H
 
19
 
 
20
/**
 
21
 * @file apr_global_mutex.h
 
22
 * @brief APR Global Locking Routines
 
23
 */
 
24
 
 
25
#include "apr.h"
 
26
#include "apr_proc_mutex.h"    /* only for apr_lockmech_e */
 
27
#include "apr_pools.h"
 
28
#include "apr_errno.h"
 
29
#if APR_PROC_MUTEX_IS_GLOBAL
 
30
#include "apr_proc_mutex.h"
 
31
#endif
 
32
 
 
33
#ifdef __cplusplus
 
34
extern "C" {
 
35
#endif /* __cplusplus */
 
36
 
 
37
/**
 
38
 * @defgroup APR_GlobalMutex Global Locking Routines
 
39
 * @ingroup APR 
 
40
 * @{
 
41
 */
 
42
 
 
43
#if !APR_PROC_MUTEX_IS_GLOBAL || defined(DOXYGEN)
 
44
 
 
45
/** Opaque global mutex structure. */
 
46
typedef struct apr_global_mutex_t apr_global_mutex_t;
 
47
 
 
48
/*   Function definitions */
 
49
 
 
50
/**
 
51
 * Create and initialize a mutex that can be used to synchronize both
 
52
 * processes and threads. Note: There is considerable overhead in using
 
53
 * this API if only cross-process or cross-thread mutual exclusion is
 
54
 * required. See apr_proc_mutex.h and apr_thread_mutex.h for more
 
55
 * specialized lock routines.
 
56
 * @param mutex the memory address where the newly created mutex will be
 
57
 *        stored.
 
58
 * @param fname A file name to use if the lock mechanism requires one.  This
 
59
 *        argument should always be provided.  The lock code itself will
 
60
 *        determine if it should be used.
 
61
 * @param mech The mechanism to use for the interprocess lock, if any; one of
 
62
 * <PRE>
 
63
 *            APR_LOCK_FCNTL
 
64
 *            APR_LOCK_FLOCK
 
65
 *            APR_LOCK_SYSVSEM
 
66
 *            APR_LOCK_POSIXSEM
 
67
 *            APR_LOCK_PROC_PTHREAD
 
68
 *            APR_LOCK_DEFAULT     pick the default mechanism for the platform
 
69
 * </PRE>
 
70
 * @param pool the pool from which to allocate the mutex.
 
71
 * @warning Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
 
72
 *          APR_LOCK_foo.  Only APR_LOCK_DEFAULT is portable.
 
73
 */
 
74
APR_DECLARE(apr_status_t) apr_global_mutex_create(apr_global_mutex_t **mutex,
 
75
                                                  const char *fname,
 
76
                                                  apr_lockmech_e mech,
 
77
                                                  apr_pool_t *pool);
 
78
 
 
79
/**
 
80
 * Re-open a mutex in a child process.
 
81
 * @param mutex The newly re-opened mutex structure.
 
82
 * @param fname A file name to use if the mutex mechanism requires one.  This
 
83
 *              argument should always be provided.  The mutex code itself will
 
84
 *              determine if it should be used.  This filename should be the 
 
85
 *              same one that was passed to apr_global_mutex_create().
 
86
 * @param pool The pool to operate on.
 
87
 * @remark This function must be called to maintain portability, even
 
88
 *         if the underlying lock mechanism does not require it.
 
89
 */
 
90
APR_DECLARE(apr_status_t) apr_global_mutex_child_init(
 
91
                              apr_global_mutex_t **mutex,
 
92
                              const char *fname,
 
93
                              apr_pool_t *pool);
 
94
 
 
95
/**
 
96
 * Acquire the lock for the given mutex. If the mutex is already locked,
 
97
 * the current thread will be put to sleep until the lock becomes available.
 
98
 * @param mutex the mutex on which to acquire the lock.
 
99
 */
 
100
APR_DECLARE(apr_status_t) apr_global_mutex_lock(apr_global_mutex_t *mutex);
 
101
 
 
102
/**
 
103
 * Attempt to acquire the lock for the given mutex. If the mutex has already
 
104
 * been acquired, the call returns immediately with APR_EBUSY. Note: it
 
105
 * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
 
106
 * if the return value was APR_EBUSY, for portability reasons.
 
107
 * @param mutex the mutex on which to attempt the lock acquiring.
 
108
 */
 
109
APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex);
 
110
 
 
111
/**
 
112
 * Release the lock for the given mutex.
 
113
 * @param mutex the mutex from which to release the lock.
 
114
 */
 
115
APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex);
 
116
 
 
117
/**
 
118
 * Destroy the mutex and free the memory associated with the lock.
 
119
 * @param mutex the mutex to destroy.
 
120
 */
 
121
APR_DECLARE(apr_status_t) apr_global_mutex_destroy(apr_global_mutex_t *mutex);
 
122
 
 
123
/**
 
124
 * Get the pool used by this global_mutex.
 
125
 * @return apr_pool_t the pool
 
126
 */
 
127
APR_POOL_DECLARE_ACCESSOR(global_mutex);
 
128
 
 
129
#else /* APR_PROC_MUTEX_IS_GLOBAL */
 
130
 
 
131
/* Some platforms [e.g. Win32] have cross process locks that are truly
 
132
 * global locks, since there isn't the concept of cross-process locks.
 
133
 * Define these platforms in terms of an apr_proc_mutex_t.
 
134
 */
 
135
 
 
136
#define apr_global_mutex_t          apr_proc_mutex_t
 
137
#define apr_global_mutex_create     apr_proc_mutex_create
 
138
#define apr_global_mutex_child_init apr_proc_mutex_child_init
 
139
#define apr_global_mutex_lock       apr_proc_mutex_lock
 
140
#define apr_global_mutex_trylock    apr_proc_mutex_trylock
 
141
#define apr_global_mutex_unlock     apr_proc_mutex_unlock
 
142
#define apr_global_mutex_destroy    apr_proc_mutex_destroy
 
143
#define apr_global_mutex_pool_get   apr_proc_mutex_pool_get
 
144
 
 
145
#endif
 
146
 
 
147
/** @} */
 
148
 
 
149
#ifdef __cplusplus
 
150
}
 
151
#endif
 
152
 
 
153
#endif  /* ndef APR_GLOBAL_MUTEX_H */