fspr_arch_proc_mutex.h 3.1 KB

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