2
0

fspr_atomic.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 APR_ATOMIC_H
  17. #define APR_ATOMIC_H
  18. /**
  19. * @file fspr_atomic.h
  20. * @brief APR Atomic Operations
  21. */
  22. #include "fspr.h"
  23. #include "fspr_pools.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @defgroup fspr_atomic Atomic Operations
  29. * @ingroup APR
  30. * @{
  31. */
  32. /**
  33. * this function is required on some platforms to initialize the
  34. * atomic operation's internal structures
  35. * @param p pool
  36. * @return APR_SUCCESS on successful completion
  37. */
  38. APR_DECLARE(fspr_status_t) fspr_atomic_init(fspr_pool_t *p);
  39. /*
  40. * Atomic operations on 32-bit values
  41. * Note: Each of these functions internally implements a memory barrier
  42. * on platforms that require it
  43. */
  44. /**
  45. * atomically read an fspr_uint32_t from memory
  46. * @param mem the pointer
  47. */
  48. APR_DECLARE(fspr_uint32_t) fspr_atomic_read32(volatile fspr_uint32_t *mem);
  49. /**
  50. * atomically set an fspr_uint32_t in memory
  51. * @param mem pointer to the object
  52. * @param val value that the object will assume
  53. */
  54. APR_DECLARE(void) fspr_atomic_set32(volatile fspr_uint32_t *mem, fspr_uint32_t val);
  55. /**
  56. * atomically add 'val' to an fspr_uint32_t
  57. * @param mem pointer to the object
  58. * @param val amount to add
  59. * @return old value pointed to by mem
  60. */
  61. APR_DECLARE(fspr_uint32_t) fspr_atomic_add32(volatile fspr_uint32_t *mem, fspr_uint32_t val);
  62. /**
  63. * atomically subtract 'val' from an fspr_uint32_t
  64. * @param mem pointer to the object
  65. * @param val amount to subtract
  66. */
  67. APR_DECLARE(void) fspr_atomic_sub32(volatile fspr_uint32_t *mem, fspr_uint32_t val);
  68. /**
  69. * atomically increment an fspr_uint32_t by 1
  70. * @param mem pointer to the object
  71. * @return old value pointed to by mem
  72. */
  73. APR_DECLARE(fspr_uint32_t) fspr_atomic_inc32(volatile fspr_uint32_t *mem);
  74. /**
  75. * atomically decrement an fspr_uint32_t by 1
  76. * @param mem pointer to the atomic value
  77. * @return zero if the value becomes zero on decrement, otherwise non-zero
  78. */
  79. APR_DECLARE(int) fspr_atomic_dec32(volatile fspr_uint32_t *mem);
  80. /**
  81. * compare an fspr_uint32_t's value with 'cmp'.
  82. * If they are the same swap the value with 'with'
  83. * @param mem pointer to the value
  84. * @param with what to swap it with
  85. * @param cmp the value to compare it to
  86. * @return the old value of *mem
  87. */
  88. APR_DECLARE(fspr_uint32_t) fspr_atomic_cas32(volatile fspr_uint32_t *mem, fspr_uint32_t with,
  89. fspr_uint32_t cmp);
  90. /**
  91. * exchange an fspr_uint32_t's value with 'val'.
  92. * @param mem pointer to the value
  93. * @param val what to swap it with
  94. * @return the old value of *mem
  95. */
  96. APR_DECLARE(fspr_uint32_t) fspr_atomic_xchg32(volatile fspr_uint32_t *mem, fspr_uint32_t val);
  97. /**
  98. * compare the pointer's value with cmp.
  99. * If they are the same swap the value with 'with'
  100. * @param mem pointer to the pointer
  101. * @param with what to swap it with
  102. * @param cmp the value to compare it to
  103. * @return the old value of the pointer
  104. */
  105. APR_DECLARE(void*) fspr_atomic_casptr(volatile void **mem, void *with, const void *cmp);
  106. /** @} */
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* !APR_ATOMIC_H */