1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#ifndef APR_THREAD_RWLOCK_H
18
#define APR_THREAD_RWLOCK_H
21
* @file apr_thread_rwlock.h
22
* @brief APR Reader/Writer Lock Routines
26
#include "apr_pools.h"
27
#include "apr_errno.h"
31
#endif /* __cplusplus */
36
* @defgroup apr_thread_rwlock Reader/Writer Lock Routines
41
/** Opaque read-write thread-safe lock. */
42
typedef struct apr_thread_rwlock_t apr_thread_rwlock_t;
45
* Note: The following operations have undefined results: unlocking a
46
* read-write lock which is not locked in the calling thread; write
47
* locking a read-write lock which is already locked by the calling
48
* thread; destroying a read-write lock more than once; clearing or
49
* destroying the pool from which a <b>locked</b> read-write lock is
54
* Create and initialize a read-write lock that can be used to synchronize
56
* @param rwlock the memory address where the newly created readwrite lock
58
* @param pool the pool from which to allocate the mutex.
60
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
63
* Acquire a shared-read lock on the given read-write lock. This will allow
64
* multiple threads to enter the same critical section while they have acquired
66
* @param rwlock the read-write lock on which to acquire the shared read.
68
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock);
71
* Attempt to acquire the shared-read lock on the given read-write lock. This
72
* is the same as apr_thread_rwlock_rdlock(), only that the function fails
73
* if there is another thread holding the write lock, or if there are any
74
* write threads blocking on the lock. If the function fails for this case,
75
* APR_EBUSY will be returned. Note: it is important that the
76
* APR_STATUS_IS_EBUSY(s) macro be used to determine if the return value was
77
* APR_EBUSY, for portability reasons.
78
* @param rwlock the rwlock on which to attempt the shared read.
80
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock);
83
* Acquire an exclusive-write lock on the given read-write lock. This will
84
* allow only one single thread to enter the critical sections. If there
85
* are any threads currently holding the read-lock, this thread is put to
86
* sleep until it can have exclusive access to the lock.
87
* @param rwlock the read-write lock on which to acquire the exclusive write.
89
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock);
92
* Attempt to acquire the exclusive-write lock on the given read-write lock.
93
* This is the same as apr_thread_rwlock_wrlock(), only that the function fails
94
* if there is any other thread holding the lock (for reading or writing),
95
* in which case the function will return APR_EBUSY. Note: it is important
96
* that the APR_STATUS_IS_EBUSY(s) macro be used to determine if the return
97
* value was APR_EBUSY, for portability reasons.
98
* @param rwlock the rwlock on which to attempt the exclusive write.
100
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock);
103
* Release either the read or write lock currently held by the calling thread
104
* associated with the given read-write lock.
105
* @param rwlock the read-write lock to be released (unlocked).
107
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock);
110
* Destroy the read-write lock and free the associated memory.
111
* @param rwlock the rwlock to destroy.
113
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock);
116
* Get the pool used by this thread_rwlock.
117
* @return apr_pool_t the pool
119
APR_POOL_DECLARE_ACCESSOR(thread_rwlock);
121
#endif /* APR_HAS_THREADS */
129
#endif /* ! APR_THREAD_RWLOCK_H */