1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251875Speter * contributor license agreements.  See the NOTICE file distributed with
3251875Speter * this work for additional information regarding copyright ownership.
4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251875Speter * (the "License"); you may not use this file except in compliance with
6251875Speter * the License.  You may obtain a copy of the License at
7251875Speter *
8251875Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251875Speter *
10251875Speter * Unless required by applicable law or agreed to in writing, software
11251875Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251875Speter * See the License for the specific language governing permissions and
14251875Speter * limitations under the License.
15251875Speter */
16251875Speter
17251875Speter#ifndef PROC_MUTEX_H
18251875Speter#define PROC_MUTEX_H
19251875Speter
20251875Speter#include "apr.h"
21251875Speter#include "apr_private.h"
22251875Speter#include "apr_general.h"
23251875Speter#include "apr_lib.h"
24251875Speter#include "apr_proc_mutex.h"
25251875Speter#include "apr_pools.h"
26251875Speter#include "apr_portable.h"
27251875Speter#include "apr_file_io.h"
28251875Speter#include "apr_arch_file_io.h"
29251875Speter
30251875Speter/* System headers required by Locks library */
31251875Speter#if APR_HAVE_SYS_TYPES_H
32251875Speter#include <sys/types.h>
33251875Speter#endif
34251875Speter#if APR_HAVE_STDIO_H
35251875Speter#include <stdio.h>
36251875Speter#endif
37251875Speter#if APR_HAVE_FCNTL_H
38251875Speter#include <fcntl.h>
39251875Speter#endif
40251875Speter
41251875Speter#ifdef HAVE_SYS_IPC_H
42251875Speter#include <sys/ipc.h>
43251875Speter#endif
44251875Speter#ifdef HAVE_SYS_SEM_H
45251875Speter#include <sys/sem.h>
46251875Speter#endif
47251875Speter#ifdef HAVE_SYS_FILE_H
48251875Speter#include <sys/file.h>
49251875Speter#endif
50251875Speter#if APR_HAVE_STDLIB_H
51251875Speter#include <stdlib.h>
52251875Speter#endif
53251875Speter#if APR_HAVE_UNISTD_H
54251875Speter#include <unistd.h>
55251875Speter#endif
56251875Speter#if APR_HAVE_STRING_H
57251875Speter#include <string.h>
58251875Speter#endif
59251875Speter#ifdef HAVE_SYS_MMAN_H
60251875Speter#include <sys/mman.h>
61251875Speter#endif
62251875Speter#if APR_HAVE_PTHREAD_H
63251875Speter#include <pthread.h>
64251875Speter#endif
65251875Speter#if APR_HAVE_SEMAPHORE_H
66251875Speter#include <semaphore.h>
67251875Speter#endif
68251875Speter/* End System Headers */
69251875Speter
70251875Speterstruct apr_proc_mutex_unix_lock_methods_t {
71251875Speter    unsigned int flags;
72251875Speter    apr_status_t (*create)(apr_proc_mutex_t *, const char *);
73251875Speter    apr_status_t (*acquire)(apr_proc_mutex_t *);
74251875Speter    apr_status_t (*tryacquire)(apr_proc_mutex_t *);
75251875Speter    apr_status_t (*release)(apr_proc_mutex_t *);
76251875Speter    apr_status_t (*cleanup)(void *);
77251875Speter    apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *);
78251875Speter    const char *name;
79251875Speter};
80251875Spetertypedef struct apr_proc_mutex_unix_lock_methods_t apr_proc_mutex_unix_lock_methods_t;
81251875Speter
82251875Speter/* bit values for flags field in apr_unix_lock_methods_t */
83251875Speter#define APR_PROCESS_LOCK_MECH_IS_GLOBAL          1
84251875Speter
85251875Speter#if !APR_HAVE_UNION_SEMUN && defined(APR_HAS_SYSVSEM_SERIALIZE)
86251875Speterunion semun {
87251875Speter    int val;
88251875Speter    struct semid_ds *buf;
89251875Speter    unsigned short *array;
90251875Speter};
91251875Speter#endif
92251875Speter
93251875Speterstruct apr_proc_mutex_t {
94251875Speter    apr_pool_t *pool;
95251875Speter    const apr_proc_mutex_unix_lock_methods_t *meth;
96251875Speter    const apr_proc_mutex_unix_lock_methods_t *inter_meth;
97251875Speter    int curr_locked;
98251875Speter    char *fname;
99251875Speter#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE
100251875Speter    apr_file_t *interproc;
101251875Speter#endif
102251875Speter#if APR_HAS_POSIXSEM_SERIALIZE
103251875Speter    sem_t *psem_interproc;
104251875Speter#endif
105251875Speter#if APR_HAS_PROC_PTHREAD_SERIALIZE
106251875Speter    pthread_mutex_t *pthread_interproc;
107251875Speter#endif
108251875Speter};
109251875Speter
110251875Spetervoid apr_proc_mutex_unix_setup_lock(void);
111251875Speter
112251875Speter#endif  /* PROC_MUTEX_H */
113251875Speter
114