Apache HTTPD
sdbm_lock.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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#include "apr_file_info.h"
18#include "apr_file_io.h"
19#include "apr_sdbm.h"
20
21#include "sdbm_private.h"
22#include "sdbm_tune.h"
23
24/* NOTE: this function may block until it acquires the lock */
26{
29
31 return APR_EINVAL;
32
33 if (db->flags & SDBM_EXCLUSIVE_LOCK) {
34 ++db->lckcnt;
35 return APR_SUCCESS;
36 }
37 else if (db->flags & SDBM_SHARED_LOCK) {
38 /*
39 * Cannot promote a shared lock to an exlusive lock
40 * in a cross-platform compatibile manner.
41 */
43 return APR_EINVAL;
44 ++db->lckcnt;
45 return APR_SUCCESS;
46 }
47 /*
48 * zero size: either a fresh database, or one with a single,
49 * unsplit data page: dirpage is all zeros.
50 */
51 if ((status = apr_file_lock(db->dirf, type)) == APR_SUCCESS)
52 {
53 apr_finfo_t finfo;
54 if ((status = apr_file_info_get(&finfo, APR_FINFO_SIZE, db->dirf))
55 != APR_SUCCESS) {
56 (void) apr_file_unlock(db->dirf);
57 return status;
58 }
59
60 SDBM_INVALIDATE_CACHE(db, finfo);
61
62 ++db->lckcnt;
65 else if (type == APR_FLOCK_EXCLUSIVE)
67 }
68 return status;
69}
70
72{
74 return APR_EINVAL;
75 if (--db->lckcnt > 0)
76 return APR_SUCCESS;
78 return apr_file_unlock(db->dirf);
79}
APR File Information.
APR File I/O Handling.
apr-util SDBM library
APU_DECLARE(void)
Computes SipHash-2-4, producing a 64bit (APR_SIPHASH_DSIZE) hash from a message and a 128bit (APR_SIP...
Definition apr_sha1.c:206
#define APR_EINVAL
Definition apr_errno.h:711
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
int type
#define APR_FLOCK_TYPEMASK
#define APR_FLOCK_SHARED
#define APR_FLOCK_EXCLUSIVE
#define APR_FINFO_SIZE
int int status
apr_status_t apr_file_lock(apr_file_t *thefile, int type)
Definition flock.c:21
apr_status_t apr_file_unlock(apr_file_t *thefile)
Definition flock.c:33
#define SDBM_SHARED_LOCK
#define SDBM_INVALIDATE_CACHE(db, finfo)
#define SDBM_EXCLUSIVE_LOCK
apr_file_t * dirf
apr_int32_t flags