proc_mutex.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "apr.h"
  17. #include "apr_private.h"
  18. #include "apr_portable.h"
  19. #include "apr_arch_proc_mutex.h"
  20. #include "apr_arch_thread_mutex.h"
  21. APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
  22. const char *fname,
  23. apr_lockmech_e mech,
  24. apr_pool_t *pool)
  25. {
  26. apr_status_t ret;
  27. apr_proc_mutex_t *new_mutex = NULL;
  28. new_mutex = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
  29. if(new_mutex ==NULL) {
  30. return APR_ENOMEM;
  31. }
  32. new_mutex->pool = pool;
  33. ret = apr_thread_mutex_create(&(new_mutex->mutex), APR_THREAD_MUTEX_DEFAULT, pool);
  34. if (ret == APR_SUCCESS)
  35. *mutex = new_mutex;
  36. return ret;
  37. }
  38. APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
  39. const char *fname,
  40. apr_pool_t *pool)
  41. {
  42. return APR_SUCCESS;
  43. }
  44. APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
  45. {
  46. if (mutex)
  47. return apr_thread_mutex_lock(mutex->mutex);
  48. return APR_ENOLOCK;
  49. }
  50. APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
  51. {
  52. if (mutex)
  53. return apr_thread_mutex_trylock(mutex->mutex);
  54. return APR_ENOLOCK;
  55. }
  56. APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
  57. {
  58. if (mutex)
  59. return apr_thread_mutex_unlock(mutex->mutex);
  60. return APR_ENOLOCK;
  61. }
  62. APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
  63. {
  64. return apr_proc_mutex_destroy(mutex);
  65. }
  66. APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
  67. {
  68. if (mutex)
  69. return apr_thread_mutex_destroy(mutex->mutex);
  70. return APR_ENOLOCK;
  71. }
  72. APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
  73. {
  74. return NULL;
  75. }
  76. APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
  77. {
  78. return "netwarethread";
  79. }
  80. APR_DECLARE(const char *) apr_proc_mutex_defname(void)
  81. {
  82. return "netwarethread";
  83. }
  84. APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
  85. /* Implement OS-specific accessors defined in apr_portable.h */
  86. apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
  87. apr_proc_mutex_t *pmutex)
  88. {
  89. if (pmutex)
  90. ospmutex = pmutex->mutex->mutex;
  91. return APR_ENOLOCK;
  92. }
  93. apr_status_t apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
  94. apr_os_proc_mutex_t *ospmutex,
  95. apr_pool_t *pool)
  96. {
  97. return APR_ENOTIMPL;
  98. }