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 #ifndef PROC_MUTEX_H 18 #define PROC_MUTEX_H 19 20 #include "apr.h" 21 #include "apr_private.h" 22 #include "apr_general.h" 23 #include "apr_lib.h" 24 #include "apr_proc_mutex.h" 25 #include "apr_pools.h" 26 #include "apr_portable.h" 27 #include "apr_file_io.h" 28 #include "apr_arch_file_io.h" 29 30 /* System headers required by Locks library */ 31 #if APR_HAVE_SYS_TYPES_H 32 #include <sys/types.h> 33 #endif 34 #if APR_HAVE_STDIO_H 35 #include <stdio.h> 36 #endif 37 #if APR_HAVE_FCNTL_H 38 #include <fcntl.h> 39 #endif 40 41 #ifdef HAVE_SYS_IPC_H 42 #include <sys/ipc.h> 43 #endif 44 #ifdef HAVE_SYS_SEM_H 45 #include <sys/sem.h> 46 #endif 47 #ifdef HAVE_SYS_FILE_H 48 #include <sys/file.h> 49 #endif 50 #if APR_HAVE_STDLIB_H 51 #include <stdlib.h> 52 #endif 53 #if APR_HAVE_UNISTD_H 54 #include <unistd.h> 55 #endif 56 #if APR_HAVE_STRING_H 57 #include <string.h> 58 #endif 59 #ifdef HAVE_SYS_MMAN_H 60 #include <sys/mman.h> 61 #endif 62 #if APR_HAVE_PTHREAD_H 63 #include <pthread.h> 64 #endif 65 #if APR_HAVE_SEMAPHORE_H 66 #include <semaphore.h> 67 #endif 68 /* End System Headers */ 69 70 struct apr_proc_mutex_unix_lock_methods_t { 71 unsigned int flags; 72 apr_status_t (*create)(apr_proc_mutex_t *, const char *); 73 apr_status_t (*acquire)(apr_proc_mutex_t *); 74 apr_status_t (*tryacquire)(apr_proc_mutex_t *); 75 apr_status_t (*release)(apr_proc_mutex_t *); 76 apr_status_t (*cleanup)(void *); 77 apr_status_t (*child_init)(apr_proc_mutex_t **, apr_pool_t *, const char *); 78 const char *name; 79 }; 80 typedef struct apr_proc_mutex_unix_lock_methods_t apr_proc_mutex_unix_lock_methods_t; 81 82 /* bit values for flags field in apr_unix_lock_methods_t */ 83 #define APR_PROCESS_LOCK_MECH_IS_GLOBAL 1 84 85 #if !APR_HAVE_UNION_SEMUN && defined(APR_HAS_SYSVSEM_SERIALIZE) 86 union semun { 87 int val; 88 struct semid_ds *buf; 89 unsigned short *array; 90 }; 91 #endif 92 93 struct apr_proc_mutex_t { 94 apr_pool_t *pool; 95 const apr_proc_mutex_unix_lock_methods_t *meth; 96 const apr_proc_mutex_unix_lock_methods_t *inter_meth; 97 int curr_locked; 98 char *fname; 99 #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE 100 apr_file_t *interproc; 101 #endif 102 #if APR_HAS_POSIXSEM_SERIALIZE 103 sem_t *psem_interproc; 104 #endif 105 #if APR_HAS_PROC_PTHREAD_SERIALIZE 106 pthread_mutex_t *pthread_interproc; 107 #endif 108 }; 109 110 void apr_proc_mutex_unix_setup_lock(void); 111 112 #endif /* PROC_MUTEX_H */ 113 114